//
// sub_B65844 from 0xb65844 to 0xb661c0 (2428 bytes)
//
// 4 xrefs:
// > sub_B661C0 @ 0xb661dc
// > sub_B661C0 @ 0xb66244
// > sub_B66308 @ 0xb6633c
// > sub_B66308 @ 0xb66470
//
// 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
//
_BYTE *__fastcall sub_B65844(__int64 a1, __int64 a2)
{
int v4; // w0
int v5; // w21
char v6; // w27
unsigned __int8 **v7; // x22
char v8; // w24
_BYTE *v9; // x1
__int64 *v10; // x2
size_t v11; // x25
__int64 v12; // x21
unsigned __int64 v13; // x26
__int64 v14; // x3
void *v15; // x21
void *v16; // x19
__int64 *v17; // x21
__int64 v18; // x0
__int64 v19; // x2
__int64 v20; // x0
_QWORD *v21; // x25
_QWORD *v22; // x21
int v23; // w0
_QWORD *v24; // x0
_QWORD *v25; // x0
__int64 *v26; // x27
_QWORD *v27; // x28
__int64 v28; // x0
__int64 v29; // x4
__int64 v30; // x0
_QWORD *v31; // x19
int v32; // w0
_BYTE *result; // x0
unsigned __int64 v34; // x0
__int64 *v35; // x0
__int64 *v36; // x0
__int64 *v37; // x0
_BYTE **v38; // x24
_BYTE *v39; // x3
int v40; // w0
_BYTE *v41; // x1
char v42; // w2
__int64 v43; // x27
__int64 v44; // x2
__int64 v45; // x27
__int64 v46; // x1
__int64 v47; // x27
__int64 v48; // x3
__int64 v49; // x27
__int64 v50; // x2
__int64 v51; // x27
__int64 v52; // x1
__int64 v53; // x3
__int64 v54; // x27
__int64 v55; // x1
__int64 v56; // x3
__int64 v57; // x27
__int64 v58; // x1
__int64 v59; // x27
__int64 v60; // x3
__int64 v61; // x27
__int64 v62; // x2
int v63; // w0
_BYTE *v64; // x3
int v65; // w7
__int64 v66; // x2
__int64 v67; // x0
_BYTE *v68; // x3
int v69; // w0
__int64 *v70; // [xsp+68h] [xbp+68h]
_BYTE *v71; // [xsp+78h] [xbp+78h] BYREF
_BYTE *v72; // [xsp+80h] [xbp+80h]
if ( a2 && *(_BYTE *)(a2 + 1) != 1 )
sub_B4AD00(a1, (__int64)"Step has to be applied to node set");
v4 = *(_DWORD *)(a1 + 40);
if ( v4 != 22 )
{
if ( v4 == 23 )
{
sub_B4A57C((unsigned __int8 **)(a1 + 8));
result = (_BYTE *)sub_B4B9F4(a1);
v41 = result;
if ( result )
{
*result = 57;
result[1] = 1;
v42 = 12;
LABEL_43:
v41[2] = v42;
*((_QWORD *)v41 + 1) = a2;
v41[3] = 2;
*((_QWORD *)v41 + 2) = 0;
*((_QWORD *)v41 + 3) = 0;
*((_QWORD *)v41 + 4) = 0;
return result;
}
}
else
{
if ( v4 != 24 )
{
v71 = nullptr;
v72 = nullptr;
v5 = 0;
v6 = 3;
if ( v4 != 20 )
goto LABEL_8;
goto LABEL_34;
}
sub_B4A57C((unsigned __int8 **)(a1 + 8));
result = (_BYTE *)sub_B4B9F4(a1);
v41 = result;
if ( result )
{
*result = 57;
result[1] = 1;
v42 = 9;
goto LABEL_43;
}
}
return nullptr;
}
v5 = 1;
v6 = 2;
sub_B4A57C((unsigned __int8 **)(a1 + 8));
v71 = nullptr;
v4 = *(_DWORD *)(a1 + 40);
v72 = nullptr;
if ( v4 != 20 )
{
LABEL_8:
if ( v4 == 9 )
{
v7 = (unsigned __int8 **)(a1 + 8);
v8 = 7;
sub_B4A57C((unsigned __int8 **)(a1 + 8));
v9 = v71;
goto LABEL_10;
}
LABEL_137:
sub_B4AD00(a1, (__int64)"Unrecognized node test");
}
LABEL_34:
v38 = (_BYTE **)(a1 + 24);
v7 = (unsigned __int8 **)(a1 + 8);
v39 = *(_BYTE **)(a1 + 32);
v71 = *(_BYTE **)(a1 + 24);
v72 = v39;
sub_B4A57C((unsigned __int8 **)(a1 + 8));
v40 = *(_DWORD *)(a1 + 40);
if ( v40 == 25 )
{
if ( v5 )
sub_B4AD00(a1, (__int64)"Two axis specifiers in one step");
switch ( *v71 )
{
case 'a':
v57 = 0;
v58 = v72 - v71;
if ( v72 == v71 )
goto LABEL_111;
while ( v58 != ++v57 )
{
if ( aAncestor[v57] != v71[v57] )
goto LABEL_104;
}
v6 = 0;
if ( !aAncestor[v58] )
goto LABEL_118;
LABEL_104:
v59 = 0;
while ( v58 != ++v59 )
{
if ( aAncestorOrSelf[v59] != v71[v59] )
goto LABEL_108;
}
v6 = 1;
if ( !aAncestorOrSelf[v58] )
goto LABEL_118;
LABEL_108:
v60 = 0;
while ( v58 != ++v60 )
{
if ( aAttribute[v60] != v71[v60] )
goto LABEL_50;
}
LABEL_111:
if ( aAttribute[v58] )
goto LABEL_50;
v6 = 2;
goto LABEL_118;
case 'c':
v61 = 0;
v62 = v72 - v71;
if ( v72 == v71 )
goto LABEL_117;
while ( v62 != ++v61 )
{
if ( aChild[v61] != v71[v61] )
goto LABEL_50;
}
LABEL_117:
v6 = 3;
if ( !aChild[v62] )
goto LABEL_118;
goto LABEL_50;
case 'd':
v54 = 0;
v55 = v72 - v71;
if ( v72 == v71 )
goto LABEL_97;
while ( v55 != ++v54 )
{
if ( aDescendant[v54] != v71[v54] )
goto LABEL_94;
}
v6 = 4;
if ( !aDescendant[v55] )
goto LABEL_118;
LABEL_94:
v56 = 0;
while ( v55 != ++v56 )
{
if ( aDescendantOrSe[v56] != v71[v56] )
goto LABEL_50;
}
LABEL_97:
if ( aDescendantOrSe[v55] )
goto LABEL_50;
v6 = 5;
goto LABEL_118;
case 'f':
v51 = 0;
v52 = v72 - v71;
if ( v72 == v71 )
goto LABEL_87;
while ( v52 != ++v51 )
{
if ( aFollowing[v51] != v71[v51] )
goto LABEL_84;
}
v6 = 6;
if ( !aFollowing[v52] )
goto LABEL_118;
LABEL_84:
v53 = 0;
while ( v52 != ++v53 )
{
if ( aFollowingSibli[v53] != v71[v53] )
goto LABEL_50;
}
LABEL_87:
if ( aFollowingSibli[v52] )
goto LABEL_50;
v6 = 7;
goto LABEL_118;
case 'n':
v49 = 0;
v50 = v72 - v71;
if ( v72 == v71 )
goto LABEL_77;
while ( v50 != ++v49 )
{
if ( aNamespace[v49] != v71[v49] )
goto LABEL_50;
}
LABEL_77:
v6 = 8;
if ( aNamespace[v50] )
goto LABEL_50;
goto LABEL_118;
case 'p':
v45 = 0;
v46 = v72 - v71;
if ( v72 == v71 )
goto LABEL_71;
while ( v46 != ++v45 )
{
if ( aParent[v45] != v71[v45] )
goto LABEL_64;
}
v6 = 9;
if ( !aParent[v46] )
goto LABEL_118;
LABEL_64:
v47 = 0;
while ( v46 != ++v47 )
{
if ( aPreceding[v47] != v71[v47] )
goto LABEL_68;
}
v6 = 10;
if ( !aPreceding[v46] )
goto LABEL_118;
LABEL_68:
v48 = 0;
while ( v46 != ++v48 )
{
if ( aPrecedingSibli[v48] != v71[v48] )
goto LABEL_50;
}
LABEL_71:
if ( aPrecedingSibli[v46] )
goto LABEL_50;
v6 = 11;
goto LABEL_118;
case 's':
v43 = 0;
v44 = v72 - v71;
if ( v72 == v71 )
goto LABEL_57;
break;
default:
goto LABEL_50;
}
while ( v44 != ++v43 )
{
if ( aSelf[v43] != v71[v43] )
goto LABEL_50;
}
LABEL_57:
v6 = 12;
if ( aSelf[v44] )
LABEL_50:
sub_B4AD00(a1, (__int64)"Unknown axis");
LABEL_118:
sub_B4A57C((unsigned __int8 **)(a1 + 8));
v63 = *(_DWORD *)(a1 + 40);
if ( v63 == 9 )
{
v71 = nullptr;
v72 = nullptr;
v8 = 7;
sub_B4A57C((unsigned __int8 **)(a1 + 8));
v9 = nullptr;
goto LABEL_10;
}
if ( v63 != 20 )
goto LABEL_137;
v64 = *(_BYTE **)(a1 + 32);
v71 = *v38;
v72 = v64;
sub_B4A57C((unsigned __int8 **)(a1 + 8));
v40 = *(_DWORD *)(a1 + 40);
}
if ( v40 != 12 )
{
v9 = v71;
if ( v72 - v71 > 2 && *(v72 - 2) == 58 && *(v72 - 1) == 42 )
{
v8 = 8;
--v72;
}
else
{
v8 = 1;
}
goto LABEL_10;
}
sub_B4A57C((unsigned __int8 **)(a1 + 8));
v65 = *(_DWORD *)(a1 + 40);
if ( v65 != 13 )
{
v66 = v72 - v71;
if ( v72 != v71 )
{
if ( *v71 != 112 )
goto LABEL_138;
v67 = 0;
while ( v66 != ++v67 )
{
if ( aProcessingInst[v67] != v71[v67] )
goto LABEL_138;
}
}
if ( !aProcessingInst[v66] )
{
if ( v65 != 14 )
sub_B4AD00(a1, (__int64)"Only literals are allowed as arguments to processing-instruction()");
v68 = *(_BYTE **)(a1 + 32);
v71 = *v38;
v72 = v68;
sub_B4A57C((unsigned __int8 **)(a1 + 8));
if ( *(_DWORD *)(a1 + 40) != 13 )
sub_B4AD00(a1, (__int64)"Unmatched brace near processing-instruction()");
v8 = 6;
sub_B4A57C((unsigned __int8 **)(a1 + 8));
v9 = v71;
LABEL_10:
if ( v9 )
{
v10 = *(__int64 **)a1;
v11 = v72 - v9;
v12 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
v13 = (v72 - v9 + 8) & 0xFFFFFFFFFFFFFFF8LL;
if ( v13 + v12 > 0x1000 )
{
v34 = 4096;
v70 = *(__int64 **)a1;
if ( v13 >= 0x1000 )
v34 = (v11 + 8) & 0xFFFFFFFFFFFFFFF8LL;
v35 = (__int64 *)off_1230F88(v34 + 8);
if ( !v35 )
goto LABEL_40;
v15 = v35 + 1;
*v35 = *v70;
*v70 = (__int64)v35;
v70[1] = v13;
v9 = v71;
}
else
{
v14 = *v10;
v10[1] = v13 + v12;
v15 = (void *)(v14 + v12 + 8);
if ( !v15 )
goto LABEL_40;
}
v16 = v15;
memcpy(v15, v9, v11);
*((_BYTE *)v15 + v11) = 0;
}
else
{
v16 = nullptr;
}
goto LABEL_14;
}
LABEL_138:
sub_B4AD00(a1, (__int64)"Unmatched brace near node type test");
}
sub_B4A57C((unsigned __int8 **)(a1 + 8));
v69 = sub_B4AE0C(&v71);
v8 = v69;
if ( !v69 )
sub_B4AD00(a1, (__int64)"Unrecognized node type");
v71 = nullptr;
v16 = nullptr;
v72 = nullptr;
LABEL_14:
v17 = *(__int64 **)a1;
v18 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( (unsigned __int64)(v18 + 40) > 0x1000 )
{
v37 = (__int64 *)off_1230F88(0x1008u);
if ( v37 )
{
v21 = v37 + 1;
*v37 = *v17;
*v17 = (__int64)v37;
v17[1] = 40;
goto LABEL_16;
}
LABEL_40:
sub_4DDE68(a1);
}
v19 = *v17;
v17[1] = v18 + 40;
v20 = v19 + v18;
v21 = (_QWORD *)(v20 + 8);
if ( v20 == -8 )
goto LABEL_40;
LABEL_16:
*((_BYTE *)v21 + 3) = v8;
*((_BYTE *)v21 + 1) = 1;
*((_BYTE *)v21 + 2) = v6;
v22 = nullptr;
*(_BYTE *)v21 = 57;
v21[4] = v16;
v21[1] = a2;
v23 = *(_DWORD *)(a1 + 40);
v21[2] = 0;
v21[3] = 0;
if ( v23 == 18 )
{
do
{
sub_B4A57C(v7);
v24 = (_QWORD *)sub_B63D0C(a1);
v25 = sub_B653E4(a1, v24, 0);
v26 = *(__int64 **)a1;
v27 = v25;
v28 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( (unsigned __int64)(v28 + 40) > 0x1000 )
{
v36 = (__int64 *)off_1230F88(0x1008u);
if ( !v36 )
goto LABEL_40;
v31 = v36 + 1;
*v36 = *v26;
*v26 = (__int64)v36;
v26[1] = 40;
}
else
{
v29 = *v26;
v26[1] = v28 + 40;
v30 = v29 + v28;
v31 = (_QWORD *)(v30 + 8);
if ( v30 == -8 )
goto LABEL_40;
}
*(_BYTE *)v31 = 16;
*(_WORD *)((char *)v31 + 1) = 1;
*((_BYTE *)v31 + 3) = 0;
v31[1] = v27;
v32 = *(_DWORD *)(a1 + 40);
v31[2] = 0;
v31[3] = 0;
if ( v32 != 19 )
sub_B4AD00(a1, (__int64)"Unmatched square brace");
sub_B4A57C(v7);
if ( v22 )
v22[3] = v31;
else
v21[2] = v31;
v22 = v31;
}
while ( *(_DWORD *)(a1 + 40) == 18 );
}
return v21;
}