//
// dtls1_get_timeout from 0xd5d0f0 to 0xd5d1c8 (216 bytes)
//
// 3 xrefs:
// > dtls1_is_timer_expired @ 0xd5d1d4
// > dtls1_ctrl @ 0xd5d3d8
// > ??> @ 0xa1f58
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
_QWORD *__fastcall dtls1_get_timeout(__int64 a1, _QWORD *a2)
{
__int64 v2; // x2
__int64 v5; // x0
__time_t tv_sec; // x2
__time_t v7; // x1
__suseconds_t v8; // x1
__int64 v9; // x0
__time_t v10; // x2
_QWORD *result; // x0
__time_t v12; // x2
struct timeval tv; // [xsp+20h] [xbp+20h] BYREF
v2 = *(_QWORD *)(a1 + 152);
if ( !*(_QWORD *)(v2 + 488) && !*(_QWORD *)(v2 + 496) )
return nullptr;
gettimeofday(&tv, nullptr);
v5 = *(_QWORD *)(a1 + 152);
tv_sec = tv.tv_sec;
v7 = *(_QWORD *)(v5 + 488);
if ( v7 < tv.tv_sec || v7 == tv.tv_sec && *(_QWORD *)(v5 + 496) <= tv.tv_usec )
goto LABEL_10;
v8 = *(_QWORD *)(v5 + 496) - tv.tv_usec;
v9 = *(_QWORD *)(v5 + 488);
a2[1] = v8;
v10 = v9 - tv_sec;
*a2 = v10;
if ( v8 < 0 )
{
v12 = v10 - 1;
v8 += 1000000LL;
*a2 = v12;
a2[1] = v8;
result = a2;
if ( v12 )
return result;
}
else
{
result = a2;
if ( v10 )
return result;
}
if ( v8 <= 14999 )
{
LABEL_10:
*a2 = 0;
a2[1] = 0;
return a2;
}
return result;
}