//
// sub_776A9C from 0x776a9c to 0x776baa (270 bytes)
//
// 1 xrefs:
// > sub_5ABA18 @ 0x5aba70
//
// 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
//
int __fastcall sub_776A9C(pthread_t *newthread, void **a2)
{
void *v2; // r4
unsigned int *v3; // r6
unsigned int *v6; // r5
unsigned int *v7; // r3
unsigned int v8; // r2
unsigned int *v9; // r3
unsigned int v10; // r2
int result; // r0
int v12; // r4
unsigned int *v13; // r3
unsigned int v14; // r2
_DWORD *exception; // r5
_DWORD *v16; // r3
_DWORD *v17; // r0
unsigned int *v18; // [sp+Ch] [bp-Ch] BYREF
int v19; // [sp+10h] [bp-8h]
_UNKNOWN ***v20; // [sp+14h] [bp-4h]
if ( !&pthread_create )
{
exception = _cxa_allocate_exception(0x10u);
v19 = 1;
v20 = sub_77671C();
sub_776584((void **)&v18, "Enable multithreading to use std::thread");
sub_77673C(exception, v19, (int)v20, (char **)&v18);
if ( v18 - 3 != (unsigned int *)&dword_ACDD9C )
sub_2B445C(v18 - 3);
_cxa_throw(exception, (struct type_info *)&`typeinfo for'std::system_error, (void (*)(void *))sub_7766C8);
}
v2 = *a2;
v3 = (unsigned int *)a2[1];
v6 = *((unsigned int **)*a2 + 2);
*((_DWORD *)*a2 + 1) = *a2;
if ( v3 != v6 )
{
if ( v3 )
{
v7 = v3 + 1;
__dmb(0xFu);
do
v8 = __ldrex(v7);
while ( __strex(v8 + 1, v7) );
__dmb(0xFu);
v6 = *((unsigned int **)v2 + 2);
}
if ( v6 )
{
v9 = v6 + 1;
__dmb(0xFu);
do
v10 = __ldrex(v9);
while ( __strex(v10 - 1, v9) );
__dmb(0xFu);
if ( v10 == 1 )
{
(*(void (__fastcall **)(unsigned int *))(*v6 + 8))(v6);
v13 = v6 + 2;
__dmb(0xFu);
do
v14 = __ldrex(v13);
while ( __strex(v14 - 1, v13) );
__dmb(0xFu);
if ( v14 == 1 )
(*(void (__fastcall **)(unsigned int *))(*v6 + 12))(v6);
}
}
*((_DWORD *)v2 + 2) = v3;
}
result = pthread_create(newthread, nullptr, (void *(*)(void *))sub_7769EC, *a2);
v12 = result;
if ( result )
{
v16 = *a2;
v17 = *((_DWORD **)*a2 + 2);
v16[1] = 0;
v16[2] = 0;
if ( v17 )
sub_776974(v17);
sub_7735D4(v12);
}
return result;
}