decompiled_code:
__int64 __fastcall parse_process(__int64 a1, const void *a2, int a3)
{
int v5; // eax
void *v6; // rdi
char *v7; // rax
int v8; // eax
int v9; // eax
const char *v10; // rbx
char *v11; // rax
int v12; // edx
int v13; // er13
int v14; // edx
__int64 v15; // rdx
void (__fastcall *v16)(const void *, _QWORD, __int64, _QWORD); // rax
int v17; // ebx
void (__fastcall *v18)(_QWORD); // rax
char *v19; // rdi
void (__fastcall *v20)(char *, _QWORD); // rax
char *v21; // rax
char *v22; // r15
char *v23; // rax
char *v24; // rbx
void (__fastcall *v25)(char *, _QWORD); // rax
void (__fastcall *v26)(char *, _QWORD); // rax
char *v27; // rdi
void (__fastcall *v28)(char *, _QWORD); // rax
const char *v29; // r12
__int64 v30; // rax
__int64 v31; // rax
const char *v32; // rdx
const char *v33; // rax
const char *v34; // rbx
int v35; // eax
int v36; // edx
void (__fastcall *v37)(const char *, _QWORD, _QWORD, _QWORD); // rax
int v38; // ebx
int v39; // eax
void (__fastcall *v40)(_QWORD); // rax
void (__fastcall *v41)(char *, _QWORD); // rax
void (__fastcall *v42)(_QWORD); // rax
char *v43; // rax
char *v44; // rax
const char *v45; // r15
char v46; // al
void (__fastcall *v47)(const char *, const char *, _QWORD); // rax
unsigned int v48; // eax
__int64 v49; // rdi
void (__fastcall *v50)(__int64, _QWORD); // rax
unsigned int v51; // ebx
char *v52; // rax
char *stringp[8]; // [rsp+8h] [rbp-40h] BYREF

if ( !a1 )
__assert_fail("parse", "libparsehttp.c", 0x7Cu, "parse_process");
if ( !a2 )
__assert_fail("data", "libparsehttp.c", 0x7Du, "parse_process");
if ( a3 <= 0 )
__assert_fail("length > 0", "libparsehttp.c", 0x7Eu, "parse_process");
v5 = *(_DWORD *)(a1 + 20);
if ( v5 == 3 )
__assert_fail("parse->state != state_done", "libparsehttp.c", 0x80u, "parse_process");
if ( v5 != 2 || *(_QWORD *)(a1 + 64) )
{
v6 = *(void **)a1;
if ( *(_QWORD *)a1 )
{
if ( *(int *)(a1 + 8) > 0 )
{
LABEL_8:
v7 = (char *)realloc(v6, *(_DWORD *)(a1 + 8) + a3 + 1);
*(_QWORD *)a1 = v7;
if ( !v7 )
__assert_fail("parse->buffer", "libparsehttp.c", 0xA0u, "parse_process");
memcpy(&v7[*(int *)(a1 + 8)], a2, a3);
v8 = *(_DWORD *)(a1 + 8) + a3;
*(_DWORD *)(a1 + 8) = v8;
*(_BYTE *)(*(_QWORD *)a1 + v8) = 0;
v9 = *(_DWORD *)(a1 + 12);
if ( v9 >= a3 || v9 < 0 )
__assert_fail("parse->pos >= 0 && parse->pos < length", "libparsehttp.c", 0xA9u, "parse_process");
v10 = (const char *)(*(_QWORD *)a1 + v9);
v11 = index(v10, 10);
if ( !v11 )
goto LABEL_28;
if ( v10 == v11 )
LABEL_38:
__assert_fail("next != current", "libparsehttp.c", 0xAFu, "parse_process");
v12 = (_DWORD)v11 - (_DWORD)v10;
if ( (int)v11 - (int)v10 <= 0 )
LABEL_39:
__assert_fail("len > 0", "libparsehttp.c", 0xB1u, "parse_process");
v13 = 0;
while ( 1 )
{
if ( *v11 != 10 )
__assert_fail("*next == '\\n'", "libparsehttp.c", 0xB4u, "parse_process");
v29 = v11 + 1;
v30 = (__int64)&v11[-*(_QWORD *)a1 + 1];
*(_DWORD *)(a1 + 12) = v30;
if ( (int)v30 > *(_DWORD *)(a1 + 8) )
__assert_fail("parse->pos <= parse->length", "libparsehttp.c", 0xB9u, "parse_process");
v31 = v12;
v32 = &v10[v12];
if ( *v32 != 10 )
__assert_fail("current[len] == '\\n'", "libparsehttp.c", 0xBCu, "parse_process");
*v32 = 0;
v33 = &v10[v31 - 1];
if ( *v33 == 13 )
*v33 = 0;
if ( v29 <= v10 )
__assert_fail("current < next", "libparsehttp.c", 0xC7u, "parse_process");
v34 = &v10[*v10 == 13];
v35 = *(_DWORD *)(a1 + 20);
if ( v35 )
{
if ( v35 != 1 )
__assert_fail("0", "libparsehttp.c", 0x14Au, "parse_process");
if ( *v34 )
{
v43 = index(v34, 58) - 1;
if ( v34 < v43 )
{
do
{
if ( *v43 != 32 && *v43 != 9 )
break;
*v43-- = 0;
}
while ( v34 != v43 );
}
v44 = index(v34, 58);
*v44 = 0;
v45 = v44 + 1;
v46 = v44[1];
if ( v46 == 32 || v46 == 9 )
{
do
{
do
++v45;
while ( *v45 == 32 );
}
while ( *v45 == 9 );
}
v47 = *(void (__fastcall **)(const char *, const char *, _QWORD))(a1 + 56);
if ( v47 )
v47(v34, v45, *(_QWORD *)(a1 + 112));
if ( !strcasecmp(v34, "content-length") )
{
if ( *(_DWORD *)(a1 + 16) )
__assert_fail("parse->dataleft == 0", "libparsehttp.c", 0x131u, "parse_process");
v48 = atoi(v45);
v49 = v48;
*(_DWORD *)(a1 + 16) = v48;
v50 = *(void (__fastcall **)(__int64, _QWORD))(a1 + 88);
if ( v50 )
v50(v49, *(_QWORD *)(a1 + 112));
}
else if ( *(_QWORD *)(a1 + 80) )
{
v51 = strcasecmp(v34, "host");
if ( !v51 )
{
v52 = index(v45, 58);
if ( v52 )
{
*v52 = 0;
v51 = atoi(v52 + 1);
}
(*(void (__fastcall **)(const char *, _QWORD, _QWORD))(a1 + 80))(v45, v51, *(_QWORD *)(a1 + 112));
}
}
}
else
{
v36 = *(_DWORD *)(a1 + 16);
if ( v36 <= 0 )
{
if ( *(_DWORD *)(a1 + 12) != *(_DWORD *)(a1 + 8) )
__assert_fail("parse->pos == parse->length", "libparsehttp.c", 0x114u, "parse_process");
v42 = *(void (__fastcall **)(_QWORD))(a1 + 104);
if ( v42 )
v42(*(_QWORD *)(a1 + 112));
*(_DWORD *)(a1 + 20) = 3;
if ( v13 )
__assert_fail("expecting == 0", "libparsehttp.c", 0x117u, "parse_process");
}
else
{
*(_DWORD *)(a1 + 20) = 2;
v37 = *(void (__fastcall **)(const char *, _QWORD, _QWORD, _QWORD))(a1 + 96);
if ( v37 )
{
v38 = *(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 12);
if ( v36 < v38 )
__assert_fail("l <= parse->dataleft", "libparsehttp.c", 0xFFu, "parse_process");
v37(v29, (unsigned int)v38, (unsigned int)(v36 - v38), *(_QWORD *)(a1 + 112));
v39 = *(_DWORD *)(a1 + 16) - v38;
*(_DWORD *)(a1 + 16) = v39;
if ( *(_QWORD *)(a1 + 64) )
LABEL_93:
__assert_fail("0", "libparsehttp.c", 0x106u, "parse_process");
if ( v39 < 0 )
__assert_fail("parse->dataleft >= 0", "libparsehttp.c", 0x109u, "parse_process");
if ( v39 )
{
v13 = 1;
}
else
{
v40 = *(void (__fastcall **)(_QWORD))(a1 + 104);
if ( v40 )
v40(*(_QWORD *)(a1 + 112));
*(_DWORD *)(a1 + 20) = 3;
if ( v13 )
__assert_fail("expecting == 0", "libparsehttp.c", 0x10Du, "parse_process");
}
}
else
{
if ( *(_QWORD *)(a1 + 64) )
goto LABEL_93;
v13 = 1;
}
}
}
}
else
{
stringp[0] = (char *)v34;
v19 = strsep(stringp, " ");
if ( !v19 )
__assert_fail("word", "libparsehttp.c", 0xD6u, "parse_process");
v20 = *(void (__fastcall **)(char *, _QWORD))(a1 + 24);
if ( v20 )
v20(v19, *(_QWORD *)(a1 + 112));
if ( !stringp[0] )
__assert_fail("rest", "libparsehttp.c", 0xDAu, "parse_process");
v21 = strsep(stringp, " ");
v22 = v21;
if ( !v21 )
__assert_fail("word", "libparsehttp.c", 0xDCu, "parse_process");
v23 = index(v21, 63);
v24 = v23;
if ( v23 )
{
*v23 = 0;
if ( !v23[1] )
__assert_fail("*params != 0", "libparsehttp.c", 0xE3u, "parse_process");
v25 = *(void (__fastcall **)(char *, _QWORD))(a1 + 32);
if ( v25 )
v25(v22, *(_QWORD *)(a1 + 112));
v26 = *(void (__fastcall **)(char *, _QWORD))(a1 + 40);
if ( v26 )
v26(v24 + 1, *(_QWORD *)(a1 + 112));
if ( *(_QWORD *)(a1 + 64) )
__assert_fail("0", "libparsehttp.c", 0xE8u, "parse_process");
}
else
{
v41 = *(void (__fastcall **)(char *, _QWORD))(a1 + 32);
if ( v41 )
v41(v22, *(_QWORD *)(a1 + 112));
}
v27 = strsep(stringp, " ");
if ( !v27 )
__assert_fail("word", "libparsehttp.c", 0xF1u, "parse_process");
v28 = *(void (__fastcall **)(char *, _QWORD))(a1 + 48);
if ( v28 )
v28(v27, *(_QWORD *)(a1 + 112));
*(_DWORD *)(a1 + 20) = 1;
}
if ( *(_DWORD *)(a1 + 12) >= *(_DWORD *)(a1 + 8) )
break;
v11 = index(v29, 10);
if ( !v11 )
break;
if ( v29 == v11 )
goto LABEL_38;
v12 = (_DWORD)v11 - (_DWORD)v29;
if ( (int)v11 - (int)v29 <= 0 )
goto LABEL_39;
v10 = v29;
}
if ( !v13 )
goto LABEL_28;
goto LABEL_125;
}
}
else if ( !*(_DWORD *)(a1 + 8) )
{
goto LABEL_8;
}
__assert_fail(
"(parse->buffer == NULL && parse->length == 0) || (parse->buffer && parse->length > 0)",
"libparsehttp.c",
0x9Du,
"parse_process");
}
v14 = *(_DWORD *)(a1 + 16);
if ( v14 < a3 )
__assert_fail("length <= parse->dataleft", "libparsehttp.c", 0x87u, "parse_process");
v15 = (unsigned int)(v14 - a3);
*(_DWORD *)(a1 + 16) = v15;
if ( (int)v15 < 0 )
__assert_fail("parse->dataleft >= 0", "libparsehttp.c", 0x89u, "parse_process");
v16 = *(void (__fastcall **)(const void *, _QWORD, __int64, _QWORD))(a1 + 96);
if ( !v16 )
__assert_fail("parse->cb_data", "libparsehttp.c", 0x8Au, "parse_process");
v16(a2, (unsigned int)a3, v15, *(_QWORD *)(a1 + 112));
v17 = *(_DWORD *)(a1 + 12) + a3;
*(_DWORD *)(a1 + 12) = v17;
if ( v17 <= 0 )
__assert_fail("parse->pos > 0", "libparsehttp.c", 0x8Du, "parse_process");
if ( !*(_DWORD *)(a1 + 16) )
{
v18 = *(void (__fastcall **)(_QWORD))(a1 + 104);
if ( v18 )
v18(*(_QWORD *)(a1 + 112));
*(_DWORD *)(a1 + 20) = 3;
LABEL_28:
if ( *(_QWORD *)(a1 + 16) != 0x300000000LL )
goto LABEL_29;
return 0LL;
}
LABEL_125:
if ( *(_DWORD *)(a1 + 20) > 2u )
LABEL_29:
__assert_fail(
"(expecting == 0 && parse->state == state_done && parse->dataleft == 0) || (expecting == 1 && parse->state < state_done)",
"libparsehttp.c",
0x15Bu,
"parse_process");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const void *a2, int a3)
{
int v5; // eax
void *v6; // rdi
char *v7; // rax
int v8; // eax
int v9; // eax
const char *v10; // rbx
char *v11; // rax
int v12; // edx
int v13; // er13
int v14; // edx
__int64 v15; // rdx
void (__fastcall *v16)(const void *, _QWORD, __int64, _QWORD); // rax
int v17; // ebx
void (__fastcall *v18)(_QWORD); // rax
char *v19; // rdi
void (__fastcall *v20)(char *, _QWORD); // rax
char *v21; // rax
char *v22; // r15
char *v23; // rax
char *v24; // rbx
void (__fastcall *v25)(char *, _QWORD); // rax
void (__fastcall *v26)(char *, _QWORD); // rax
char *v27; // rdi
void (__fastcall *v28)(char *, _QWORD); // rax
const char *v29; // r12
__int64 v30; // rax
__int64 v31; // rax
const char *v32; // rdx
const char *v33; // rax
const char *v34; // rbx
int v35; // eax
int v36; // edx
void (__fastcall *v37)(const char *, _QWORD, _QWORD, _QWORD); // rax
int v38; // ebx
int v39; // eax
void (__fastcall *v40)(_QWORD); // rax
void (__fastcall *v41)(char *, _QWORD); // rax
void (__fastcall *v42)(_QWORD); // rax
char *v43; // rax
char *v44; // rax
const char *v45; // r15
char v46; // al
void (__fastcall *v47)(const char *, const char *, _QWORD); // rax
unsigned int v48; // eax
__int64 v49; // rdi
void (__fastcall *v50)(__int64, _QWORD); // rax
unsigned int v51; // ebx
char *v52; // rax
char *stringp[8]; // [rsp+8h] [rbp-40h] BYREF

if ( !a1 )
__assert_fail("parse", "libparsehttp.c", 0x7Cu, "parse_process");
if ( !a2 )
__assert_fail("data", "libparsehttp.c", 0x7Du, "parse_process");
if ( a3 <= 0 )
__assert_fail("length > 0", "libparsehttp.c", 0x7Eu, "parse_process");
v5 = *(_DWORD *)(a1 + 20);
if ( v5 == 3 )
__assert_fail("parse->state != state_done", "libparsehttp.c", 0x80u, "parse_process");
if ( v5 != 2 || *(_QWORD *)(a1 + 64) )
{
v6 = *(void **)a1;
if ( *(_QWORD *)a1 )
{
if ( *(int *)(a1 + 8) > 0 )
{
LABEL_8:
v7 = (char *)realloc(v6, *(_DWORD *)(a1 + 8) + a3 + 1);
*(_QWORD *)a1 = v7;
if ( !v7 )
__assert_fail("parse->buffer", "libparsehttp.c", 0xA0u, "parse_process");
memcpy(&v7[*(int *)(a1 + 8)], a2, a3);
v8 = *(_DWORD *)(a1 + 8) + a3;
*(_DWORD *)(a1 + 8) = v8;
*(_BYTE *)(*(_QWORD *)a1 + v8) = 0;
v9 = *(_DWORD *)(a1 + 12);
if ( v9 >= a3 || v9 < 0 )
__assert_fail("parse->pos >= 0 && parse->pos < length", "libparsehttp.c", 0xA9u, "parse_process");
v10 = (const char *)(*(_QWORD *)a1 + v9);
v11 = index(v10, 10);
if ( !v11 )
goto LABEL_28;
if ( v10 == v11 )
LABEL_38:
__assert_fail("next != current", "libparsehttp.c", 0xAFu, "parse_process");
v12 = (_DWORD)v11 - (_DWORD)v10;
if ( (int)v11 - (int)v10 <= 0 )
LABEL_39:
__assert_fail("len > 0", "libparsehttp.c", 0xB1u, "parse_process");
v13 = 0;
while ( 1 )
{
if ( *v11 != 10 )
__assert_fail("*next == '\\n'", "libparsehttp.c", 0xB4u, "parse_process");
v29 = v11 + 1;
v30 = (__int64)&v11[-*(_QWORD *)a1 + 1];
*(_DWORD *)(a1 + 12) = v30;
if ( (int)v30 > *(_DWORD *)(a1 + 8) )
__assert_fail("parse->pos <= parse->length", "libparsehttp.c", 0xB9u, "parse_process");
v31 = v12;
v32 = &v10[v12];
if ( *v32 != 10 )
__assert_fail("current[len] == '\\n'", "libparsehttp.c", 0xBCu, "parse_process");
*v32 = 0;
v33 = &v10[v31 - 1];
if ( *v33 == 13 )
*v33 = 0;
if ( v29 <= v10 )
__assert_fail("current < next", "libparsehttp.c", 0xC7u, "parse_process");
v34 = &v10[*v10 == 13];
v35 = *(_DWORD *)(a1 + 20);
if ( v35 )
{
if ( v35 != 1 )
__assert_fail("0", "libparsehttp.c", 0x14Au, "parse_process");
if ( *v34 )
{
v43 = index(v34, 58) - 1;
if ( v34 < v43 )
{
do
{
if ( *v43 != 32 && *v43 != 9 )
break;
*v43-- = 0;
}
while ( v34 != v43 );
}
v44 = index(v34, 58);
*v44 = 0;
v45 = v44 + 1;
v46 = v44[1];
if ( v46 == 32 || v46 == 9 )
{
do
{
do
++v45;
while ( *v45 == 32 );
}
while ( *v45 == 9 );
}
v47 = *(void (__fastcall **)(const char *, const char *, _QWORD))(a1 + 56);
if ( v47 )
v47(v34, v45, *(_QWORD *)(a1 + 112));
if ( !strcasecmp(v34, "content-length") )
{
if ( *(_DWORD *)(a1 + 16) )
__assert_fail("parse->dataleft == 0", "libparsehttp.c", 0x131u, "parse_process");
v48 = atoi(v45);
v49 = v48;
*(_DWORD *)(a1 + 16) = v48;
v50 = *(void (__fastcall **)(__int64, _QWORD))(a1 + 88);
if ( v50 )
v50(v49, *(_QWORD *)(a1 + 112));
}
else if ( *(_QWORD *)(a1 + 80) )
{
v51 = strcasecmp(v34, "host");
if ( !v51 )
{
v52 = index(v45, 58);
if ( v52 )
{
*v52 = 0;
v51 = atoi(v52 + 1);
}
(*(void (__fastcall **)(const char *, _QWORD, _QWORD))(a1 + 80))(v45, v51, *(_QWORD *)(a1 + 112));
}
}
}
else
{
v36 = *(_DWORD *)(a1 + 16);
if ( v36 <= 0 )
{
if ( *(_DWORD *)(a1 + 12) != *(_DWORD *)(a1 + 8) )
__assert_fail("parse->pos == parse->length", "libparsehttp.c", 0x114u, "parse_process");
v42 = *(void (__fastcall **)(_QWORD))(a1 + 104);
if ( v42 )
v42(*(_QWORD *)(a1 + 112));
*(_DWORD *)(a1 + 20) = 3;
if ( v13 )
__assert_fail("expecting == 0", "libparsehttp.c", 0x117u, "parse_process");
}
else
{
*(_DWORD *)(a1 + 20) = 2;
v37 = *(void (__fastcall **)(const char *, _QWORD, _QWORD, _QWORD))(a1 + 96);
if ( v37 )
{
v38 = *(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 12);
if ( v36 < v38 )
__assert_fail("l <= parse->dataleft", "libparsehttp.c", 0xFFu, "parse_process");
v37(v29, (unsigned int)v38, (unsigned int)(v36 - v38), *(_QWORD *)(a1 + 112));
v39 = *(_DWORD *)(a1 + 16) - v38;
*(_DWORD *)(a1 + 16) = v39;
if ( *(_QWORD *)(a1 + 64) )
LABEL_93:
__assert_fail("0", "libparsehttp.c", 0x106u, "parse_process");
if ( v39 < 0 )
__assert_fail("parse->dataleft >= 0", "libparsehttp.c", 0x109u, "parse_process");
if ( v39 )
{
v13 = 1;
}
else
{
v40 = *(void (__fastcall **)(_QWORD))(a1 + 104);
if ( v40 )
v40(*(_QWORD *)(a1 + 112));
*(_DWORD *)(a1 + 20) = 3;
if ( v13 )
__assert_fail("expecting == 0", "libparsehttp.c", 0x10Du, "parse_process");
}
}
else
{
if ( *(_QWORD *)(a1 + 64) )
goto LABEL_93;
v13 = 1;
}
}
}
}
else
{
stringp[0] = (char *)v34;
v19 = strsep(stringp, " ");
if ( !v19 )
__assert_fail("word", "libparsehttp.c", 0xD6u, "parse_process");
v20 = *(void (__fastcall **)(char *, _QWORD))(a1 + 24);
if ( v20 )
v20(v19, *(_QWORD *)(a1 + 112));
if ( !stringp[0] )
__assert_fail("rest", "libparsehttp.c", 0xDAu, "parse_process");
v21 = strsep(stringp, " ");
v22 = v21;
if ( !v21 )
__assert_fail("word", "libparsehttp.c", 0xDCu, "parse_process");
v23 = index(v21, 63);
v24 = v23;
if ( v23 )
{
*v23 = 0;
if ( !v23[1] )
__assert_fail("*params != 0", "libparsehttp.c", 0xE3u, "parse_process");
v25 = *(void (__fastcall **)(char *, _QWORD))(a1 + 32);
if ( v25 )
v25(v22, *(_QWORD *)(a1 + 112));
v26 = *(void (__fastcall **)(char *, _QWORD))(a1 + 40);
if ( v26 )
v26(v24 + 1, *(_QWORD *)(a1 + 112));
if ( *(_QWORD *)(a1 + 64) )
__assert_fail("0", "libparsehttp.c", 0xE8u, "parse_process");
}
else
{
v41 = *(void (__fastcall **)(char *, _QWORD))(a1 + 32);
if ( v41 )
v41(v22, *(_QWORD *)(a1 + 112));
}
v27 = strsep(stringp, " ");
if ( !v27 )
__assert_fail("word", "libparsehttp.c", 0xF1u, "parse_process");
v28 = *(void (__fastcall **)(char *, _QWORD))(a1 + 48);
if ( v28 )
v28(v27, *(_QWORD *)(a1 + 112));
*(_DWORD *)(a1 + 20) = 1;
}
if ( *(_DWORD *)(a1 + 12) >= *(_DWORD *)(a1 + 8) )
break;
v11 = index(v29, 10);
if ( !v11 )
break;
if ( v29 == v11 )
goto LABEL_38;
v12 = (_DWORD)v11 - (_DWORD)v29;
if ( (int)v11 - (int)v29 <= 0 )
goto LABEL_39;
v10 = v29;
}
if ( !v13 )
goto LABEL_28;
goto LABEL_125;
}
}
else if ( !*(_DWORD *)(a1 + 8) )
{
goto LABEL_8;
}
__assert_fail(
"(parse->buffer == NULL && parse->length == 0) || (parse->buffer && parse->length > 0)",
"libparsehttp.c",
0x9Du,
"parse_process");
}
v14 = *(_DWORD *)(a1 + 16);
if ( v14 < a3 )
__assert_fail("length <= parse->dataleft", "libparsehttp.c", 0x87u, "parse_process");
v15 = (unsigned int)(v14 - a3);
*(_DWORD *)(a1 + 16) = v15;
if ( (int)v15 < 0 )
__assert_fail("parse->dataleft >= 0", "libparsehttp.c", 0x89u, "parse_process");
v16 = *(void (__fastcall **)(const void *, _QWORD, __int64, _QWORD))(a1 + 96);
if ( !v16 )
__assert_fail("parse->cb_data", "libparsehttp.c", 0x8Au, "parse_process");
v16(a2, (unsigned int)a3, v15, *(_QWORD *)(a1 + 112));
v17 = *(_DWORD *)(a1 + 12) + a3;
*(_DWORD *)(a1 + 12) = v17;
if ( v17 <= 0 )
__assert_fail("parse->pos > 0", "libparsehttp.c", 0x8Du, "parse_process");
if ( !*(_DWORD *)(a1 + 16) )
{
v18 = *(void (__fastcall **)(_QWORD))(a1 + 104);
if ( v18 )
v18(*(_QWORD *)(a1 + 112));
*(_DWORD *)(a1 + 20) = 3;
LABEL_28:
if ( *(_QWORD *)(a1 + 16) != 0x300000000LL )
goto LABEL_29;
return 0LL;
}
LABEL_125:
if ( *(_DWORD *)(a1 + 20) > 2u )
LABEL_29:
__assert_fail(
"(expecting == 0 && parse->state == state_done && parse->dataleft == 0) || (expecting == 1 && parse->state < state_done)",
"libparsehttp.c",
0x15Bu,
"parse_process");
return 1LL;
}

original_code:
int parse_process(parsehttp_t *parse, char *data, int length)
{
 int expecting = 0;
 ((void) sizeof ((parse) ? 1 : 0), __extension__ ({ if (parse) ; else __assert_fail ("parse", "libparsehttp.c", 124, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((data) ? 1 : 0), __extension__ ({ if (data) ; else __assert_fail ("data", "libparsehttp.c", 125, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((length > 0) ? 1 : 0), __extension__ ({ if (length > 0) ; else __assert_fail ("length > 0", "libparsehttp.c", 126, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((parse->state != state_done) ? 1 : 0), __extension__ ({ if (parse->state != state_done) ; else __assert_fail ("parse->state != state_done", "libparsehttp.c", 128, __extension__ __PRETTY_FUNCTION__); }));
 if (parse->state == state_data && parse->cb_formdata == ((void *)0)) {
  ((void) sizeof ((length <= parse->dataleft) ? 1 : 0), __extension__ ({ if (length <= parse->dataleft) ; else __assert_fail ("length <= parse->dataleft", "libparsehttp.c", 135, __extension__ __PRETTY_FUNCTION__); }));
  parse->dataleft -= length;
  ((void) sizeof ((parse->dataleft >= 0) ? 1 : 0), __extension__ ({ if (parse->dataleft >= 0) ; else __assert_fail ("parse->dataleft >= 0", "libparsehttp.c", 137, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((parse->cb_data) ? 1 : 0), __extension__ ({ if (parse->cb_data) ; else __assert_fail ("parse->cb_data", "libparsehttp.c", 138, __extension__ __PRETTY_FUNCTION__); }));
  parse->cb_data(data, length, parse->dataleft, parse->arg);
  parse->pos += length;
  ((void) sizeof ((parse->pos > 0) ? 1 : 0), __extension__ ({ if (parse->pos > 0) ; else __assert_fail ("parse->pos > 0", "libparsehttp.c", 141, __extension__ __PRETTY_FUNCTION__); }));
  if (parse->dataleft == 0) {
   if (parse->cb_complete) { parse->cb_complete(parse->arg); }
   ((void) sizeof ((expecting == 0) ? 1 : 0), __extension__ ({ if (expecting == 0) ; else __assert_fail ("expecting == 0", "libparsehttp.c", 146, __extension__ __PRETTY_FUNCTION__); }));
   parse->state = state_done;
  }
  else {
   expecting = 1;
  }
 }
 else {
  ((void) sizeof (((parse->buffer == ((void *)0) && parse->length == 0) || (parse->buffer && parse->length > 0)) ? 1 : 0), __extension__ ({ if ((parse->buffer == ((void *)0) && parse->length == 0) || (parse->buffer && parse->length > 0)) ; else __assert_fail ("(parse->buffer == NULL && parse->length == 0) || (parse->buffer && parse->length > 0)", "libparsehttp.c", 157, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((length > 0) ? 1 : 0), __extension__ ({ if (length > 0) ; else __assert_fail ("length > 0", "libparsehttp.c", 158, __extension__ __PRETTY_FUNCTION__); }));
  parse->buffer = (char *) realloc(parse->buffer, parse->length + length + 1);
  ((void) sizeof ((parse->buffer) ? 1 : 0), __extension__ ({ if (parse->buffer) ; else __assert_fail ("parse->buffer", "libparsehttp.c", 160, __extension__ __PRETTY_FUNCTION__); }));
  memcpy(parse->buffer + parse->length, data, length);
  parse->length += length;
  parse->buffer[parse->length] = 0;
  char *current;
  char *next;
  int len;
  ((void) sizeof ((parse->pos >= 0 && parse->pos < length) ? 1 : 0), __extension__ ({ if (parse->pos >= 0 && parse->pos < length) ; else __assert_fail ("parse->pos >= 0 && parse->pos < length", "libparsehttp.c", 169, __extension__ __PRETTY_FUNCTION__); }));
  current = parse->buffer + parse->pos;
  next = index(current, '\n');
  while (next != ((void *)0)) {
   ((void) sizeof ((next != current) ? 1 : 0), __extension__ ({ if (next != current) ; else __assert_fail ("next != current", "libparsehttp.c", 175, __extension__ __PRETTY_FUNCTION__); }));
   len = next - current;
   ((void) sizeof ((len > 0) ? 1 : 0), __extension__ ({ if (len > 0) ; else __assert_fail ("len > 0", "libparsehttp.c", 177, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((*next == '\n') ? 1 : 0), __extension__ ({ if (*next == '\n') ; else __assert_fail ("*next == '\\n'", "libparsehttp.c", 180, __extension__ __PRETTY_FUNCTION__); }));
   next ++;
   parse->pos = next - parse->buffer;
   ((void) sizeof ((parse->pos <= parse->length) ? 1 : 0), __extension__ ({ if (parse->pos <= parse->length) ; else __assert_fail ("parse->pos <= parse->length", "libparsehttp.c", 185, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((current[len] == '\n') ? 1 : 0), __extension__ ({ if (current[len] == '\n') ; else __assert_fail ("current[len] == '\\n'", "libparsehttp.c", 188, __extension__ __PRETTY_FUNCTION__); }));
   current[len] = 0;
   ((void) sizeof ((len > 0) ? 1 : 0), __extension__ ({ if (len > 0) ; else __assert_fail ("len > 0", "libparsehttp.c", 192, __extension__ __PRETTY_FUNCTION__); }));
   if (current[len-1] == '\r') {
    current[len-1] = 0;
    len --;
   }
   ((void) sizeof ((current < next) ? 1 : 0), __extension__ ({ if (current < next) ; else __assert_fail ("current < next", "libparsehttp.c", 199, __extension__ __PRETTY_FUNCTION__); }));
   if (*current == '\r') {
    current ++;
    len --;
   }
   if (parse->state == state_request) {
    char *word;
    char *rest;
    char *params;
    rest = current;
    word = strsep(&rest, " ");
    ((void) sizeof ((word) ? 1 : 0), __extension__ ({ if (word) ; else __assert_fail ("word", "libparsehttp.c", 214, __extension__ __PRETTY_FUNCTION__); }));
    if (parse->cb_method) { parse->cb_method(word, parse->arg); }
    ((void) sizeof ((rest) ? 1 : 0), __extension__ ({ if (rest) ; else __assert_fail ("rest", "libparsehttp.c", 218, __extension__ __PRETTY_FUNCTION__); }));
    word = strsep(&rest, " ");
    ((void) sizeof ((word) ? 1 : 0), __extension__ ({ if (word) ; else __assert_fail ("word", "libparsehttp.c", 220, __extension__ __PRETTY_FUNCTION__); }));
    params = index(word, '?');
    if (params) {
     *params = 0;
     params++;
     ((void) sizeof ((*params != 0) ? 1 : 0), __extension__ ({ if (*params != 0) ; else __assert_fail ("*params != 0", "libparsehttp.c", 227, __extension__ __PRETTY_FUNCTION__); }));
     if (parse->cb_path) { parse->cb_path(word, parse->arg); }
     if (parse->cb_params) { parse->cb_params(params, parse->arg); }
     if (parse->cb_formdata) {
      ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "libparsehttp.c", 232, __extension__ __PRETTY_FUNCTION__); }));
     }
    }
    else {
     if (parse->cb_path) { parse->cb_path(word, parse->arg); }
    }
    word = strsep(&rest, " ");
    ((void) sizeof ((word) ? 1 : 0), __extension__ ({ if (word) ; else __assert_fail ("word", "libparsehttp.c", 241, __extension__ __PRETTY_FUNCTION__); }));
    if (parse->cb_version) { parse->cb_version(word, parse->arg); }
    parse->state = state_headers;
   }
   else if (parse->state == state_headers && *current == 0) {
    if (parse->dataleft > 0) {
     parse->state = state_data;
     if (parse->cb_data) {
      int l = parse->length - parse->pos;
      ((void) sizeof ((l <= parse->dataleft) ? 1 : 0), __extension__ ({ if (l <= parse->dataleft) ; else __assert_fail ("l <= parse->dataleft", "libparsehttp.c", 255, __extension__ __PRETTY_FUNCTION__); }));
      parse->cb_data(next, l, parse->dataleft - l, parse->arg);
      parse->dataleft -= l;
     }
     if (parse->cb_formdata) {
      ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "libparsehttp.c", 262, __extension__ __PRETTY_FUNCTION__); }));
     }
     ((void) sizeof ((parse->dataleft >= 0) ? 1 : 0), __extension__ ({ if (parse->dataleft >= 0) ; else __assert_fail ("parse->dataleft >= 0", "libparsehttp.c", 265, __extension__ __PRETTY_FUNCTION__); }));
     if (parse->dataleft == 0) {
      if (parse->cb_complete) { parse->cb_complete(parse->arg); }
      parse->state = state_done;
      ((void) sizeof ((expecting == 0) ? 1 : 0), __extension__ ({ if (expecting == 0) ; else __assert_fail ("expecting == 0", "libparsehttp.c", 269, __extension__ __PRETTY_FUNCTION__); }));
     }
     else {
      expecting = 1;
     }
    }
    else {
     ((void) sizeof ((parse->pos == parse->length) ? 1 : 0), __extension__ ({ if (parse->pos == parse->length) ; else __assert_fail ("parse->pos == parse->length", "libparsehttp.c", 276, __extension__ __PRETTY_FUNCTION__); }));
     if (parse->cb_complete) parse->cb_complete(parse->arg);
     parse->state = state_done;
     ((void) sizeof ((expecting == 0) ? 1 : 0), __extension__ ({ if (expecting == 0) ; else __assert_fail ("expecting == 0", "libparsehttp.c", 279, __extension__ __PRETTY_FUNCTION__); }));
    }
   }
   else if (parse->state == state_headers) {
    char *key;
    char *value;
    key = current;
    value = index(current, ':');
    value --;
    while (value > key && (*value == ' ' || *value == '\t')) { *value = 0; value --; }
    value = index(current, ':');
    *value = 0;
    value++;
    while (*value == ' ' || *value == '\t') { value ++; }
    if (parse->cb_header) { parse->cb_header(key, value, parse->arg); }
    if (strcasecmp(key, "content-length") == 0) {
     ((void) sizeof ((parse->dataleft == 0) ? 1 : 0), __extension__ ({ if (parse->dataleft == 0) ; else __assert_fail ("parse->dataleft == 0", "libparsehttp.c", 305, __extension__ __PRETTY_FUNCTION__); }));
     parse->dataleft = atoi(value);
     if (parse->cb_datalength) { parse->cb_datalength(parse->dataleft, parse->arg); }
    }
    else if (parse->cb_host && strcasecmp(key, "host") == 0) {
     char *port = index(value, ':');
     int portnum = 0;
     if (port) {
      *port = 0;
      port++;
      portnum = atoi(port);
     }
     parse->cb_host(value, portnum, parse->arg);
    }
   }
   else if (parse->state < state_data) {
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "libparsehttp.c", 325, __extension__ __PRETTY_FUNCTION__); }));
   }
   else {
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "libparsehttp.c", 330, __extension__ __PRETTY_FUNCTION__); }));
   }
   if (parse->pos >= parse->length) {
    next = ((void *)0);
   }
   else {
    current = next;
    next = index(current, '\n');
   }
  }
 }
 ((void) sizeof (((expecting == 0 && parse->state == state_done && parse->dataleft == 0) || (expecting == 1 && parse->state < state_done)) ? 1 : 0), __extension__ ({ if ((expecting == 0 && parse->state == state_done && parse->dataleft == 0) || (expecting == 1 && parse->state < state_done)) ; else __assert_fail ("(expecting == 0 && parse->state == state_done && parse->dataleft == 0) || (expecting == 1 && parse->state < state_done)", "libparsehttp.c", 347, __extension__ __PRETTY_FUNCTION__); }));
 return(expecting);
}

canonical_original_code:
int parse_process(struct parsehttp_t *parse, char *data, int length)
{
 int expecting = 0;
 ((void) sizeof ((parse) ? 1 : 0), __extension__ ({ if (parse) ; else __assert_fail ("parse", "libparsehttp.c", 124, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((data) ? 1 : 0), __extension__ ({ if (data) ; else __assert_fail ("data", "libparsehttp.c", 125, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((length > 0) ? 1 : 0), __extension__ ({ if (length > 0) ; else __assert_fail ("length > 0", "libparsehttp.c", 126, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((parse->state != state_done) ? 1 : 0), __extension__ ({ if (parse->state != state_done) ; else __assert_fail ("parse->state != state_done", "libparsehttp.c", 128, __extension__ __PRETTY_FUNCTION__); }));
 if (parse->state == state_data && parse->cb_formdata == ((void *)0)) {
  ((void) sizeof ((length <= parse->dataleft) ? 1 : 0), __extension__ ({ if (length <= parse->dataleft) ; else __assert_fail ("length <= parse->dataleft", "libparsehttp.c", 135, __extension__ __PRETTY_FUNCTION__); }));
  parse->dataleft -= length;
  ((void) sizeof ((parse->dataleft >= 0) ? 1 : 0), __extension__ ({ if (parse->dataleft >= 0) ; else __assert_fail ("parse->dataleft >= 0", "libparsehttp.c", 137, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((parse->cb_data) ? 1 : 0), __extension__ ({ if (parse->cb_data) ; else __assert_fail ("parse->cb_data", "libparsehttp.c", 138, __extension__ __PRETTY_FUNCTION__); }));
  parse->cb_data(data, length, parse->dataleft, parse->arg);
  parse->pos += length;
  ((void) sizeof ((parse->pos > 0) ? 1 : 0), __extension__ ({ if (parse->pos > 0) ; else __assert_fail ("parse->pos > 0", "libparsehttp.c", 141, __extension__ __PRETTY_FUNCTION__); }));
  if (parse->dataleft == 0) {
   if (parse->cb_complete) { parse->cb_complete(parse->arg); }
   ((void) sizeof ((expecting == 0) ? 1 : 0), __extension__ ({ if (expecting == 0) ; else __assert_fail ("expecting == 0", "libparsehttp.c", 146, __extension__ __PRETTY_FUNCTION__); }));
   parse->state = state_done;
  }
  else {
   expecting = 1;
  }
 }
 else {
  ((void) sizeof (((parse->buffer == ((void *)0) && parse->length == 0) || (parse->buffer && parse->length > 0)) ? 1 : 0), __extension__ ({ if ((parse->buffer == ((void *)0) && parse->length == 0) || (parse->buffer && parse->length > 0)) ; else __assert_fail ("(parse->buffer == NULL && parse->length == 0) || (parse->buffer && parse->length > 0)", "libparsehttp.c", 157, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((length > 0) ? 1 : 0), __extension__ ({ if (length > 0) ; else __assert_fail ("length > 0", "libparsehttp.c", 158, __extension__ __PRETTY_FUNCTION__); }));
  parse->buffer = (char *) realloc(parse->buffer, parse->length + length + 1);
  ((void) sizeof ((parse->buffer) ? 1 : 0), __extension__ ({ if (parse->buffer) ; else __assert_fail ("parse->buffer", "libparsehttp.c", 160, __extension__ __PRETTY_FUNCTION__); }));
  memcpy(parse->buffer + parse->length, data, length);
  parse->length += length;
  parse->buffer[parse->length] = 0;
  char *current;
  char *next;
  int len;
  ((void) sizeof ((parse->pos >= 0 && parse->pos < length) ? 1 : 0), __extension__ ({ if (parse->pos >= 0 && parse->pos < length) ; else __assert_fail ("parse->pos >= 0 && parse->pos < length", "libparsehttp.c", 169, __extension__ __PRETTY_FUNCTION__); }));
  current = parse->buffer + parse->pos;
  next = index(current, '\n');
  while (next != ((void *)0)) {
   ((void) sizeof ((next != current) ? 1 : 0), __extension__ ({ if (next != current) ; else __assert_fail ("next != current", "libparsehttp.c", 175, __extension__ __PRETTY_FUNCTION__); }));
   len = next - current;
   ((void) sizeof ((len > 0) ? 1 : 0), __extension__ ({ if (len > 0) ; else __assert_fail ("len > 0", "libparsehttp.c", 177, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((*next == '\n') ? 1 : 0), __extension__ ({ if (*next == '\n') ; else __assert_fail ("*next == '\\n'", "libparsehttp.c", 180, __extension__ __PRETTY_FUNCTION__); }));
   next ++;
   parse->pos = next - parse->buffer;
   ((void) sizeof ((parse->pos <= parse->length) ? 1 : 0), __extension__ ({ if (parse->pos <= parse->length) ; else __assert_fail ("parse->pos <= parse->length", "libparsehttp.c", 185, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((current[len] == '\n') ? 1 : 0), __extension__ ({ if (current[len] == '\n') ; else __assert_fail ("current[len] == '\\n'", "libparsehttp.c", 188, __extension__ __PRETTY_FUNCTION__); }));
   current[len] = 0;
   ((void) sizeof ((len > 0) ? 1 : 0), __extension__ ({ if (len > 0) ; else __assert_fail ("len > 0", "libparsehttp.c", 192, __extension__ __PRETTY_FUNCTION__); }));
   if (current[len-1] == '\r') {
    current[len-1] = 0;
    len --;
   }
   ((void) sizeof ((current < next) ? 1 : 0), __extension__ ({ if (current < next) ; else __assert_fail ("current < next", "libparsehttp.c", 199, __extension__ __PRETTY_FUNCTION__); }));
   if (*current == '\r') {
    current ++;
    len --;
   }
   if (parse->state == state_request) {
    char *word;
    char *rest;
    char *params;
    rest = current;
    word = strsep(&rest, " ");
    ((void) sizeof ((word) ? 1 : 0), __extension__ ({ if (word) ; else __assert_fail ("word", "libparsehttp.c", 214, __extension__ __PRETTY_FUNCTION__); }));
    if (parse->cb_method) { parse->cb_method(word, parse->arg); }
    ((void) sizeof ((rest) ? 1 : 0), __extension__ ({ if (rest) ; else __assert_fail ("rest", "libparsehttp.c", 218, __extension__ __PRETTY_FUNCTION__); }));
    word = strsep(&rest, " ");
    ((void) sizeof ((word) ? 1 : 0), __extension__ ({ if (word) ; else __assert_fail ("word", "libparsehttp.c", 220, __extension__ __PRETTY_FUNCTION__); }));
    params = index(word, '?');
    if (params) {
     *params = 0;
     params++;
     ((void) sizeof ((*params != 0) ? 1 : 0), __extension__ ({ if (*params != 0) ; else __assert_fail ("*params != 0", "libparsehttp.c", 227, __extension__ __PRETTY_FUNCTION__); }));
     if (parse->cb_path) { parse->cb_path(word, parse->arg); }
     if (parse->cb_params) { parse->cb_params(params, parse->arg); }
     if (parse->cb_formdata) {
      ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "libparsehttp.c", 232, __extension__ __PRETTY_FUNCTION__); }));
     }
    }
    else {
     if (parse->cb_path) { parse->cb_path(word, parse->arg); }
    }
    word = strsep(&rest, " ");
    ((void) sizeof ((word) ? 1 : 0), __extension__ ({ if (word) ; else __assert_fail ("word", "libparsehttp.c", 241, __extension__ __PRETTY_FUNCTION__); }));
    if (parse->cb_version) { parse->cb_version(word, parse->arg); }
    parse->state = state_headers;
   }
   else if (parse->state == state_headers && *current == 0) {
    if (parse->dataleft > 0) {
     parse->state = state_data;
     if (parse->cb_data) {
      int l = parse->length - parse->pos;
      ((void) sizeof ((l <= parse->dataleft) ? 1 : 0), __extension__ ({ if (l <= parse->dataleft) ; else __assert_fail ("l <= parse->dataleft", "libparsehttp.c", 255, __extension__ __PRETTY_FUNCTION__); }));
      parse->cb_data(next, l, parse->dataleft - l, parse->arg);
      parse->dataleft -= l;
     }
     if (parse->cb_formdata) {
      ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "libparsehttp.c", 262, __extension__ __PRETTY_FUNCTION__); }));
     }
     ((void) sizeof ((parse->dataleft >= 0) ? 1 : 0), __extension__ ({ if (parse->dataleft >= 0) ; else __assert_fail ("parse->dataleft >= 0", "libparsehttp.c", 265, __extension__ __PRETTY_FUNCTION__); }));
     if (parse->dataleft == 0) {
      if (parse->cb_complete) { parse->cb_complete(parse->arg); }
      parse->state = state_done;
      ((void) sizeof ((expecting == 0) ? 1 : 0), __extension__ ({ if (expecting == 0) ; else __assert_fail ("expecting == 0", "libparsehttp.c", 269, __extension__ __PRETTY_FUNCTION__); }));
     }
     else {
      expecting = 1;
     }
    }
    else {
     ((void) sizeof ((parse->pos == parse->length) ? 1 : 0), __extension__ ({ if (parse->pos == parse->length) ; else __assert_fail ("parse->pos == parse->length", "libparsehttp.c", 276, __extension__ __PRETTY_FUNCTION__); }));
     if (parse->cb_complete) parse->cb_complete(parse->arg);
     parse->state = state_done;
     ((void) sizeof ((expecting == 0) ? 1 : 0), __extension__ ({ if (expecting == 0) ; else __assert_fail ("expecting == 0", "libparsehttp.c", 279, __extension__ __PRETTY_FUNCTION__); }));
    }
   }
   else if (parse->state == state_headers) {
    char *key;
    char *value;
    key = current;
    value = index(current, ':');
    value --;
    while (value > key && (*value == ' ' || *value == '\t')) { *value = 0; value --; }
    value = index(current, ':');
    *value = 0;
    value++;
    while (*value == ' ' || *value == '\t') { value ++; }
    if (parse->cb_header) { parse->cb_header(key, value, parse->arg); }
    if (strcasecmp(key, "content-length") == 0) {
     ((void) sizeof ((parse->dataleft == 0) ? 1 : 0), __extension__ ({ if (parse->dataleft == 0) ; else __assert_fail ("parse->dataleft == 0", "libparsehttp.c", 305, __extension__ __PRETTY_FUNCTION__); }));
     parse->dataleft = atoi(value);
     if (parse->cb_datalength) { parse->cb_datalength(parse->dataleft, parse->arg); }
    }
    else if (parse->cb_host && strcasecmp(key, "host") == 0) {
     char *port = index(value, ':');
     int portnum = 0;
     if (port) {
      *port = 0;
      port++;
      portnum = atoi(port);
     }
     parse->cb_host(value, portnum, parse->arg);
    }
   }
   else if (parse->state < state_data) {
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "libparsehttp.c", 325, __extension__ __PRETTY_FUNCTION__); }));
   }
   else {
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "libparsehttp.c", 330, __extension__ __PRETTY_FUNCTION__); }));
   }
   if (parse->pos >= parse->length) {
    next = ((void *)0);
   }
   else {
    current = next;
    next = index(current, '\n');
   }
  }
 }
 ((void) sizeof (((expecting == 0 && parse->state == state_done && parse->dataleft == 0) || (expecting == 1 && parse->state < state_done)) ? 1 : 0), __extension__ ({ if ((expecting == 0 && parse->state == state_done && parse->dataleft == 0) || (expecting == 1 && parse->state < state_done)) ; else __assert_fail ("(expecting == 0 && parse->state == state_done && parse->dataleft == 0) || (expecting == 1 && parse->state < state_done)", "libparsehttp.c", 347, __extension__ __PRETTY_FUNCTION__); }));
 return(expecting);
}

variable_types:
data
char *

variable_types: length int

variable_types: expecting int

variable_types:
current
char *

variable_types:
next
char *

variable_types: len int

variable_types:
word
char *

variable_types:
rest
char *

variable_types:
params
char *

variable_types: l int

variable_types:
key
char *

variable_types:
value
char *

variable_types:
port
char *

variable_types: portnum int


repo: hyper/libparsehttp

decompiled_code:
char *__fastcall parse_params(char *s, __int64 (__fastcall *a2)(char *, char *, __int64), __int64 a3)
{
char *v3; // rbp
char *v5; // r14
char *result; // rax
char *v7; // rbx
char *v8; // rax

if ( !s )
__assert_fail("params", "libparsehttp.c", 0x169u, "parse_params");
v3 = s;
if ( !a2 )
__assert_fail("handler", "libparsehttp.c", 0x16Au, "parse_params");
while ( 1 )
{
result = index(v3, 61);
if ( !result )
break;
*result = 0;
v7 = result + 1;
v8 = index(result + 1, 38);
if ( !v8 )
return (char *)a2(v3, v7, a3);
*v8 = 0;
v5 = v8 + 1;
a2(v3, v7, a3);
v3 = v5;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func10(char *s, __int64 (__fastcall *a2)(char *, char *, __int64), __int64 a3)
{
char *v3; // rbp
char *v5; // r14
char *result; // rax
char *v7; // rbx
char *v8; // rax

if ( !s )
__assert_fail("params", "libparsehttp.c", 0x169u, "parse_params");
v3 = s;
if ( !a2 )
__assert_fail("handler", "libparsehttp.c", 0x16Au, "parse_params");
while ( 1 )
{
result = index(v3, 61);
if ( !result )
break;
*result = 0;
v7 = result + 1;
v8 = index(result + 1, 38);
if ( !v8 )
return (char *)a2(v3, v7, a3);
*v8 = 0;
v5 = v8 + 1;
a2(v3, v7, a3);
v3 = v5;
}
return result;
}

original_code:
void parse_params(char *params, void (*handler)(const char *key, const char *value, void *arg), void *arg)
{
 char *next;
 char *key;
 char *value;
 ((void) sizeof ((params) ? 1 : 0), __extension__ ({ if (params) ; else __assert_fail ("params", "libparsehttp.c", 361, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((handler) ? 1 : 0), __extension__ ({ if (handler) ; else __assert_fail ("handler", "libparsehttp.c", 362, __extension__ __PRETTY_FUNCTION__); }));
 next = params;
 while (next) {
  key = next;
  value = index(next, '=');
  if (value) {
   *value = 0;
   value++;
   next = index(value, '&');
   if (next) {
    *next = 0;
    next++;
   }
   handler(key, value, arg);
  }
  else { next = ((void *)0); }
 }
}

canonical_original_code:
void parse_params(char *params, void (*handler)(char *key, char *value, void *arg), void *arg)
{
 char *next;
 char *key;
 char *value;
 ((void) sizeof ((params) ? 1 : 0), __extension__ ({ if (params) ; else __assert_fail ("params", "libparsehttp.c", 361, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((handler) ? 1 : 0), __extension__ ({ if (handler) ; else __assert_fail ("handler", "libparsehttp.c", 362, __extension__ __PRETTY_FUNCTION__); }));
 next = params;
 while (next) {
  key = next;
  value = index(next, '=');
  if (value) {
   *value = 0;
   value++;
   next = index(value, '&');
   if (next) {
    *next = 0;
    next++;
   }
   handler(key, value, arg);
  }
  else { next = ((void *)0); }
 }
}

variable_types: void (*)(char *key, char *value, void *arg)

variable_types:
arg
void *

return_type: void


mul

repo: ilart/Yarrow

decompiled_code:
__int64 __fastcall mul(unsigned __int16 a1, unsigned __int16 a2)
{
__int64 result; // rax

if ( !a1 )
return 65537 - (unsigned int)a2;
if ( !a2 )
return 65537 - (unsigned int)a1;
result = (unsigned __int16)(a2 * a1) - ((a2 * (unsigned int)a1) >> 16);
if ( (int)result < 0 )
result = (unsigned int)(result + 65537);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1, unsigned __int16 a2)
{
__int64 result; // rax

if ( !a1 )
return 65537 - (unsigned int)a2;
if ( !a2 )
return 65537 - (unsigned int)a1;
result = (unsigned __int16)(a2 * a1) - ((a2 * (unsigned int)a1) >> 16);
if ( (int)result < 0 )
result = (unsigned int)(result + 65537);
return result;
}

canonical_original_code:
static inline unsigned int mul(unsigned int a, unsigned int b)
{
 unsigned int c;
 int r;
 if(a==0){
  r = 0x10001 - b;
 }else if(b==0){
  r = 0x10001 - a;
 }else{
  c = a * b;
  r = (c & 0xffff) - (c>>16);
  if (r<0){
   r += 0x10001;
  }
 }
 return r & 0xffff;
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types: r int

return_type: unsigned int


sum

decompiled_code:
__int64 __fastcall sum(int a1, int a2)
{
return (unsigned int)(a2 + a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
return (unsigned int)(a2 + a1);
}

original_code:
static inline u_int16_t sum(u_int16_t a, u_int16_t b)
{
 u_int16_t r;
 r = (a + b) & 0xffff;
 return r;
}

canonical_original_code:
static inline unsigned int sum(unsigned int a, unsigned int b)
{
 unsigned int r;
 r = (a + b) & 0xffff;
 return r;
}

variable_types:
r
unsigned int


original_code:
static void
idea_scrambling(struct idea_context *ctx, u_int16_t *block)
{
 { if (!(ctx != ((void *)0))) { fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 138, __FUNCTION__, "ctx != NULL"); return; } };
 int k;
 u_int16_t tmp[3], a=0;
 u_int16_t *enc_key = ctx->tabl_key;
 for(k=0; k<8; k++){
  block[0] = mul(block[0], *(enc_key++));
  block[1] = sum(block[1], *(enc_key++));
  block[2] = sum(block[2], *(enc_key++));
  block[3] = mul(block[3], *(enc_key++));
  tmp[0] = block[0] ^ block[2];
  tmp[0] = mul(*(enc_key++), tmp[0]);
  tmp[1] = (block[1] ^ block[3]);
  tmp[1] = sum(tmp[0], tmp[1]);
  tmp[1] = mul(*(enc_key++), tmp[1]);
  tmp[2] = sum(tmp[0], tmp[1]);
  block[0] = block[0] ^ tmp[1];
  block[3] = block[3] ^ tmp[2];
  a = block[1] ^ tmp[2];
  block[1] = block[2] ^ tmp[1];
  block[2] = a;
 }
 block[0] = mul(block[0], *(enc_key++));
 a = block[1];
 block[1] = sum(block[2], *(enc_key++));
 block[2] = sum(a, *(enc_key++));
 block[3] = mul(block[3], *(enc_key++));
}

canonical_original_code:
static void idea_scrambling(struct idea_context *ctx, unsigned int *block)
{
 { if (!(ctx != ((void *)0))) { fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 138, __FUNCTION__, "ctx != NULL"); return; } };
 int k;
 unsigned int tmp[3]; unsigned int a = 0;
 unsigned int *enc_key = ctx->tabl_key;
 for(k=0; k<8; k++){
  block[0] = mul(block[0], *(enc_key++));
  block[1] = sum(block[1], *(enc_key++));
  block[2] = sum(block[2], *(enc_key++));
  block[3] = mul(block[3], *(enc_key++));
  tmp[0] = block[0] ^ block[2];
  tmp[0] = mul(*(enc_key++), tmp[0]);
  tmp[1] = (block[1] ^ block[3]);
  tmp[1] = sum(tmp[0], tmp[1]);
  tmp[1] = mul(*(enc_key++), tmp[1]);
  tmp[2] = sum(tmp[0], tmp[1]);
  block[0] = block[0] ^ tmp[1];
  block[3] = block[3] ^ tmp[2];
  a = block[1] ^ tmp[2];
  block[1] = block[2] ^ tmp[1];
  block[2] = a;
 }
 block[0] = mul(block[0], *(enc_key++));
 a = block[1];
 block[1] = sum(block[2], *(enc_key++));
 block[2] = sum(a, *(enc_key++));
 block[3] = mul(block[3], *(enc_key++));
}

variable_types: struct idea_context { unsigned int tabl_key[52]; unsigned int key[8]; } *

variable_types:
block
unsigned int *

variable_types: k int

variable_types:
tmp
unsigned int [3]


decompiled_code:
void *idea_context_new()
{
void *v0; // rdx

v0 = malloc(0x78uLL);
if ( v0 )
memset(v0, 0, 0x78uLL);
return v0;
}

canonical_decompiled_code:
void *func3()
{
void *v0; // rdx

v0 = malloc(0x78uLL);
if ( v0 )
memset(v0, 0, 0x78uLL);
return v0;
}

original_code:
struct idea_context *
idea_context_new()
{
 struct idea_context *ctx;
 ctx = malloc(sizeof(*ctx));
 if(ctx == ((void *)0))
  return ((void *)0);
 memset(ctx, 0, sizeof(*ctx));
 return ctx;
}

canonical_original_code:
struct idea_context *idea_context_new()
{
 struct idea_context *ctx;
 ctx = malloc(sizeof(*ctx));
 if(ctx == ((void *)0))
  return ((void *)0);
 memset(ctx, 0, sizeof(*ctx));
 return ctx;
}

return_type: struct idea_context { unsigned int tabl_key[52]; unsigned int key[8]; } *


decompiled_code:
int __fastcall idea_encrypt(unsigned __int16 *a1, unsigned __int16 *a2)
{
return idea_scrambling(a1, a2);
}

canonical_decompiled_code:
int __fastcall func4(unsigned __int16 *a1, unsigned __int16 *a2)
{
return func2(a1, a2);
}

original_code:
void
idea_encrypt(struct idea_context *enc, u_int16_t *block)
{
 idea_scrambling(enc, block);
}

canonical_original_code:
void idea_encrypt(struct idea_context *enc, unsigned int *block)
{
 idea_scrambling(enc, block);
}

user_defined_types: struct idea_context { unsigned int tabl_key[52]; unsigned int key[8]; }


decompiled_code:
void __fastcall idea_context_free(void **a1)
{
_QWORD *v1; // rcx

if ( a1 )
{
v1 = *a1;
if ( *a1 )
{
*v1 = 0LL;
v1[14] = 0LL;
memset(
(void *)((unsigned __int64)(v1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v1 - (((_DWORD)v1 + 8) & 0xFFFFFFF8) + 120) >> 3));
free(*a1);
*a1 = 0LL;
}
else
{
fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 52LL, "idea_context_free", "*ctx != NULL");
}
}
else
{
fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 51LL, "idea_context_free", "ctx != NULL");
}
}

canonical_decompiled_code:
void __fastcall func5(void **a1)
{
_QWORD *v1; // rcx

if ( a1 )
{
v1 = *a1;
if ( *a1 )
{
*v1 = 0LL;
v1[14] = 0LL;
memset(
(void *)((unsigned __int64)(v1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v1 - (((_DWORD)v1 + 8) & 0xFFFFFFF8) + 120) >> 3));
free(*a1);
*a1 = 0LL;
}
else
{
fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 52LL, "idea_context_free", "*ctx != NULL");
}
}
else
{
fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 51LL, "idea_context_free", "ctx != NULL");
}
}

original_code:
void
idea_context_free(struct idea_context **ctx)
{
 { if (!(ctx != ((void *)0))) { fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 51, __FUNCTION__, "ctx != NULL"); return; } };
 { if (!(*ctx != ((void *)0))) { fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 52, __FUNCTION__, "*ctx != NULL"); return; } };
 { if (!(*ctx!=((void *)0))) { fprintf(stderr, "%s:%d:%s(): Assertion (%s) failed\n", "idea.c", 54, __FUNCTION__, "*ctx!=NULL"); abort(); } };
 memset(*ctx, 0, sizeof(**ctx));
 free(*ctx);
 *ctx = ((void *)0);
}

variable_types: struct idea_context { unsigned int tabl_key[52]; unsigned int key[8]; } **


original_code:
void
idea_set_key(struct idea_context *ctx, u_int16_t *key)
{
 { if (!(ctx != ((void *)0))) { fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 63, __FUNCTION__, "ctx != NULL"); return; } };
 { if (!(key != ((void *)0))) { fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 64, __FUNCTION__, "key != NULL"); return; } };
 int i;
 u_int16_t *enc_key = ctx->tabl_key;
 memcpy(enc_key, key, 8 * sizeof(u_int16_t));
 for (i=8; i<52; i++) {
  if ((i & 7) < 6)
   enc_key[i]=(enc_key[i-7] & 127) << 9 | enc_key[i-6] >> 7;
  else if ((i & 7) == 6)
   enc_key[i]=(enc_key[i-7] & 127) << 9 | enc_key[i-14] >> 7;
  else
   enc_key[i]=(enc_key[i-15] & 127) << 9 | enc_key[i-14] >> 7;
 }
}

canonical_original_code:
void idea_set_key(struct idea_context *ctx, unsigned int *key)
{
 { if (!(ctx != ((void *)0))) { fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 63, __FUNCTION__, "ctx != NULL"); return; } };
 { if (!(key != ((void *)0))) { fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 64, __FUNCTION__, "key != NULL"); return; } };
 int i;
 unsigned int *enc_key = ctx->tabl_key;
 memcpy(enc_key, key, 8 * sizeof(u_int16_t));
 for (i=8; i<52; i++) {
  if ((i & 7) < 6)
   enc_key[i]=(enc_key[i-7] & 127) << 9 | enc_key[i-6] >> 7;
  else if ((i & 7) == 6)
   enc_key[i]=(enc_key[i-7] & 127) << 9 | enc_key[i-14] >> 7;
  else
   enc_key[i]=(enc_key[i-15] & 127) << 9 | enc_key[i-14] >> 7;
 }
}

variable_types:
key
unsigned int *

variable_types: i int


addinv

decompiled_code:
__int64 __fastcall addinv(int a1)
{
return (unsigned int)-a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return (unsigned int)-a1;
}

original_code:
u_int16_t
addinv(u_int16_t x)
{
 x = 0x10000-x;
 return x;
}

canonical_original_code:
unsigned int addinv(unsigned int x)
{
 x = 0x10000-x;
 return x;
}

variable_types:
x
unsigned int


mulinv

decompiled_code:
__int64 __fastcall mulinv(unsigned int a1)
{
int v1; // ecx
__int64 result; // rax
int v3; // edi
int v4; // er8
int v5; // esi
int v6; // eax
int v7; // edx
int v8; // er9

v1 = (unsigned __int16)a1;
result = a1;
if ( (unsigned __int16)a1 > 1u )
{
v3 = 1;
v4 = 0;
v5 = 65537;
while ( 1 )
{
v6 = v5 / v1;
v7 = v5 - v5 / v1 * v1;
v5 = v1;
v1 = v7;
v8 = v4 - v3 * v6;
v4 = v3;
if ( v7 <= 0 )
break;
v3 = v8;
}
result = (unsigned int)(v3 + 65537);
if ( v3 >= 0 )
result = (unsigned int)v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
int v1; // ecx
__int64 result; // rax
int v3; // edi
int v4; // er8
int v5; // esi
int v6; // eax
int v7; // edx
int v8; // er9

v1 = (unsigned __int16)a1;
result = a1;
if ( (unsigned __int16)a1 > 1u )
{
v3 = 1;
v4 = 0;
v5 = 65537;
while ( 1 )
{
v6 = v5 / v1;
v7 = v5 - v5 / v1 * v1;
v5 = v1;
v1 = v7;
v8 = v4 - v3 * v6;
v4 = v3;
if ( v7 <= 0 )
break;
v3 = v8;
}
result = (unsigned int)(v3 + 65537);
if ( v3 >= 0 )
result = (unsigned int)v3;
}
return result;
}

canonical_original_code:
unsigned int mulinv(unsigned int x)
{
 int r1; int r; int r2;
 int t1; int t; int t2;
 unsigned int q;
 r2 = x;
 r1 = 0x10001;
 t1 = 0;
 t2 = 1;
 if(r2 < 2) {
  return r2;
 }
 while (r2 > 0) {
  q = r1 / r2;
  r = r1 - q*r2;
  r1 = r2;
  r2 = r;
  t = t1 - q*t2;
  t1 = t2;
  t2 = t;
 }
 if(t1<0)
  t1 = 0x10001+t1;
 return t1;
}

variable_types: t int

variable_types:
q
unsigned int


original_code:
static void
idea_invertkey(struct idea_context *ctx)
{
 { if (!(ctx != ((void *)0))) { fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 86, __FUNCTION__, "ctx != NULL"); return; } };
 int t1, t2, t3, t4, round;
 u_int16_t *enc_key = ctx->tabl_key;
 u_int16_t tmp[52];
 int i = 51;
 t1 = mulinv(*(enc_key++));
 t2 = addinv(*(enc_key++));
 t3 = addinv(*(enc_key++));
 t4 = mulinv(*(enc_key++));
 tmp[i--] = t4;
 tmp[i--] = t3;
 tmp[i--] = t2;
 tmp[i--] = t1;
 for (round = 0; round < 7; round++) {
  t1 = *(enc_key++);
  t2 = *(enc_key++);
  tmp[i--] = t2;
  tmp[i--] = t1;
  t1 = mulinv(*(enc_key++));
  t2 = addinv(*(enc_key++));
  t3 = addinv(*(enc_key++));
  t4 = mulinv(*(enc_key++));
  tmp[i--] = t4;
  tmp[i--] = t2;
  tmp[i--] = t3;
  tmp[i--] = t1;
 }
 t1 = *(enc_key++);
 t2 = *(enc_key++);
 tmp[i--] = t2;
 tmp[i--] = t1;
 t1 = mulinv(*(enc_key++));
 t2 = addinv(*(enc_key++));
 t3 = addinv(*(enc_key++));
 t4 = mulinv(*(enc_key++));
 tmp[i--] = t4;
 tmp[i--] = t3;
 tmp[i--] = t2;
 tmp[i--] = t1;
 memcpy(ctx->tabl_key, tmp, 52 * sizeof(u_int16_t));
}

canonical_original_code:
static void idea_invertkey(struct idea_context *ctx)
{
 { if (!(ctx != ((void *)0))) { fprintf(stderr, "%s:%d:%s(): expression `%s' failed\n", "idea.c", 86, __FUNCTION__, "ctx != NULL"); return; } };
 int t1; int t2; int t3; int t4; int round;
 unsigned int *enc_key = ctx->tabl_key;
 unsigned int tmp[52];
 int i = 51;
 t1 = mulinv(*(enc_key++));
 t2 = addinv(*(enc_key++));
 t3 = addinv(*(enc_key++));
 t4 = mulinv(*(enc_key++));
 tmp[i--] = t4;
 tmp[i--] = t3;
 tmp[i--] = t2;
 tmp[i--] = t1;
 for (round = 0; round < 7; round++) {
  t1 = *(enc_key++);
  t2 = *(enc_key++);
  tmp[i--] = t2;
  tmp[i--] = t1;
  t1 = mulinv(*(enc_key++));
  t2 = addinv(*(enc_key++));
  t3 = addinv(*(enc_key++));
  t4 = mulinv(*(enc_key++));
  tmp[i--] = t4;
  tmp[i--] = t2;
  tmp[i--] = t3;
  tmp[i--] = t1;
 }
 t1 = *(enc_key++);
 t2 = *(enc_key++);
 tmp[i--] = t2;
 tmp[i--] = t1;
 t1 = mulinv(*(enc_key++));
 t2 = addinv(*(enc_key++));
 t3 = addinv(*(enc_key++));
 t4 = mulinv(*(enc_key++));
 tmp[i--] = t4;
 tmp[i--] = t3;
 tmp[i--] = t2;
 tmp[i--] = t1;
 memcpy(ctx->tabl_key, tmp, 52 * sizeof(u_int16_t));
}

variable_types: round int

variable_types:
tmp
unsigned int [52]


decompiled_code:
int __fastcall idea_decrypt(__m128i *a1, unsigned __int16 *a2)
{
idea_invertkey(a1);
return idea_scrambling((unsigned __int16 *)a1, a2);
}

canonical_decompiled_code:
int __fastcall func10(__m128i *a1, unsigned __int16 *a2)
{
func9(a1);
return func2((unsigned __int16 *)a1, a2);
}

original_code:
void
idea_decrypt(struct idea_context *dec, u_int16_t *block)
{
 idea_invertkey(dec);
 idea_scrambling(dec, block);
}

canonical_original_code:
void idea_decrypt(struct idea_context *dec, unsigned int *block)
{
 idea_invertkey(dec);
 idea_scrambling(dec, block);
}


nilp

repo: inforichland/FunLisp

decompiled_code:
bool __fastcall nilp(__int64 a1)
{
return nil == a1;
}

canonical_decompiled_code:
bool __fastcall func0(__int64 a1)
{
return nil == a1;
}

original_code: bool nilp(object_t *o) { return (o == nil); }

canonical_original_code: char nilp(struct object_t *o) { return (o == nil); }

variable_types: struct object_t { enum type_t { t_nil=0, t_fixnum=1, t_character=2, t_boolean=3, t_symbol=4, t_string=5, t_cons=6, t_primitive=7, t_function=8 } type; union { struct {  } nil; struct { long value; } fixnum; struct { char value; } character; struct { char value; } boolean; struct { char *value; } symbol; struct { char *value; } string; struct { struct object_t *car; struct object_t *cdr; } cons; struct { struct object_t *(*function)(struct object_t *arguments); } primitive; struct { struct object_t *body; struct object_t *env; struct object_t *args; } function; }; } *

return_type: char

user_defined_types: struct object_t { enum type_t type; union { struct {  } nil; struct { long value; } fixnum; struct { char value; } character; struct { char value; } boolean; struct { char *value; } symbol; struct { char *value; } string; struct { struct object_t *car; struct object_t *cdr; } cons; struct { struct object_t *(*function)(struct object_t *arguments); } primitive; struct { struct object_t *body; struct object_t *env; struct object_t *args; } function; }; }


truep

decompiled_code:
bool __fastcall truep(__int64 a1)
{
return true_obj == a1;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
return true_obj == a1;
}

original_code: bool truep(object_t *o) { return (o == true_obj); }

canonical_original_code: char truep(struct object_t *o) { return (o == true_obj); }

user_defined_types: enum type_t { t_nil=0, t_fixnum=1, t_character=2, t_boolean=3, t_symbol=4, t_string=5, t_cons=6, t_primitive=7, t_function=8 }


falsep

decompiled_code:
bool __fastcall falsep(__int64 a1)
{
return false_obj == a1;
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1)
{
return false_obj == a1;
}

original_code: bool falsep(object_t *o) { return (o == false_obj); }

canonical_original_code: char falsep(struct object_t *o) { return (o == false_obj); }


quotep

decompiled_code:
bool __fastcall quotep(__int64 a1)
{
return quote == a1;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 a1)
{
return quote == a1;
}

original_code: bool quotep(object_t *o) { return (o == quote); }

canonical_original_code: char quotep(struct object_t *o) { return (o == quote); }


definep

decompiled_code:
bool __fastcall definep(__int64 a1)
{
return define == a1;
}

canonical_decompiled_code:
bool __fastcall func4(__int64 a1)
{
return define == a1;
}

original_code: bool definep(object_t *o) { return (o == define); }

canonical_original_code: char definep(struct object_t *o) { return (o == define); }


decompiled_code:
__int64 get_nil()
{
return nil;
}

canonical_decompiled_code:
__int64 func5()
{
return nil;
}

original_code: object_t *get_nil(void) { return nil; }

canonical_original_code: struct object_t *get_nil() { return nil; }

return_type: struct object_t { enum type_t { t_nil=0, t_fixnum=1, t_character=2, t_boolean=3, t_symbol=4, t_string=5, t_cons=6, t_primitive=7, t_function=8 } type; union { struct {  } nil; struct { long value; } fixnum; struct { char value; } character; struct { char value; } boolean; struct { char *value; } symbol; struct { char *value; } string; struct { struct object_t *car; struct object_t *cdr; } cons; struct { struct object_t *(*function)(struct object_t *arguments); } primitive; struct { struct object_t *body; struct object_t *env; struct object_t *args; } function; }; } *


decompiled_code:
__int64 get_true()
{
return true_obj;
}

canonical_decompiled_code:
__int64 func6()
{
return true_obj;
}

original_code: object_t *get_true(void) { return true_obj; }

canonical_original_code: struct object_t *get_true() { return true_obj; }


decompiled_code:
__int64 get_false()
{
return false_obj;
}

canonical_decompiled_code:
__int64 func7()
{
return false_obj;
}

original_code: object_t *get_false(void) { return false_obj; }

canonical_original_code: struct object_t *get_false() { return false_obj; }


decompiled_code:
__int64 get_quote()
{
return quote;
}

canonical_decompiled_code:
__int64 func8()
{
return quote;
}

original_code: object_t *get_quote(void) { return quote; }

canonical_original_code: struct object_t *get_quote() { return quote; }


decompiled_code:
__int64 get_define()
{
return define;
}

canonical_decompiled_code:
__int64 func9()
{
return define;
}

original_code: object_t *get_define(void) { return define; }

canonical_original_code: struct object_t *get_define() { return define; }


decompiled_code:
const char **__fastcall lookup_symbol(char *s2)
{
const char **v1; // rbp
const char ***v2; // rbx
const char ***v3; // r12

v1 = (const char **)symbol_table;
if ( symbol_table )
{
if ( MAX_SYMBOLS )
{
v2 = (const char ***)symbol_table;
v3 = (const char ***)((char *)symbol_table + 8 * (unsigned int)(MAX_SYMBOLS - 1) + 8);
while ( 1 )
{
v1 = *v2;
if ( *v2 )
{
if ( !strcmp(v1[1], s2) )
break;
}
if ( ++v2 == v3 )
return 0LL;
}
}
else
{
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
const char **__fastcall func10(char *s2)
{
const char **v1; // rbp
const char ***v2; // rbx
const char ***v3; // r12

v1 = (const char **)symbol_table;
if ( symbol_table )
{
if ( MAX_SYMBOLS )
{
v2 = (const char ***)symbol_table;
v3 = (const char ***)((char *)symbol_table + 8 * (unsigned int)(MAX_SYMBOLS - 1) + 8);
while ( 1 )
{
v1 = *v2;
if ( *v2 )
{
if ( !strcmp(v1[1], s2) )
break;
}
if ( ++v2 == v3 )
return 0LL;
}
}
else
{
v1 = 0LL;
}
}
return v1;
}

original_code:
object_t *lookup_symbol(const char *val)
{
        int i;
        if (symbol_table == ((void *)0))
                return ((void *)0);
        for (i = 0; i < MAX_SYMBOLS; i++) {
                if (symbol_table[i] != ((void *)0) &&
                    !strcmp(symbol_table[i]->symbol.value, val))
                        return symbol_table[i];
        }
        return ((void *)0);
}

canonical_original_code:
struct object_t *lookup_symbol(char *val)
{
        int i;
        if (symbol_table == ((void *)0))
                return ((void *)0);
        for (i = 0; i < MAX_SYMBOLS; i++) {
                if (symbol_table[i] != ((void *)0) &&
                    !strcmp(symbol_table[i]->symbol.value, val))
                        return symbol_table[i];
        }
        return ((void *)0);
}

variable_types:
val
char *


car

decompiled_code:
__int64 __fastcall car(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code: object_t *car(object_t *obj) { return obj->cons.car; }

canonical_original_code: struct object_t *car(struct object_t *obj) { return obj->cons.car; }

variable_types:
obj
struct object_t *


cdr

decompiled_code:
__int64 __fastcall cdr(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code: object_t *cdr(object_t *obj) { return obj->cons.cdr; }

canonical_original_code: struct object_t *cdr(struct object_t *obj) { return obj->cons.cdr; }


decompiled_code:
// attributes: thunk
__int64 __fastcall parent_env(__int64 a1)
{
return cdr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return func12(a1);
}

original_code: object_t *parent_env(object_t *env) { return cdr(env); }

canonical_original_code: struct object_t *parent_env(struct object_t *env) { return cdr(env); }

variable_types:
env
struct object_t *


decompiled_code:
// attributes: thunk
__int64 __fastcall frame_vars(__int64 a1)
{
return car(a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return func11(a1);
}

original_code: object_t *frame_vars(object_t *frame) { return car(frame); }

canonical_original_code: struct object_t *frame_vars(struct object_t *frame) { return car(frame); }

variable_types:
frame
struct object_t *


decompiled_code:
// attributes: thunk
__int64 __fastcall frame_vals(__int64 a1)
{
return cdr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return func12(a1);
}

original_code: object_t *frame_vals(object_t *frame) { return cdr(frame); }

canonical_original_code: struct object_t *frame_vals(struct object_t *frame) { return cdr(frame); }


decompiled_code:
__int64 __fastcall find_variable_value(__int64 a1, __int64 a2)
{
__int64 v3; // r12
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rbp

while ( 1 )
{
v3 = get_nil();
if ( v3 == a2 )
return 0LL;
v4 = car(a2);
v5 = frame_vars(v4);
v6 = frame_vals(v4);
if ( v3 != v5 )
break;
LABEL_5:
a2 = parent_env(a2);
}
while ( a1 != car(v5) )
{
v5 = cdr(v5);
v6 = cdr(v6);
if ( v3 == v5 )
goto LABEL_5;
}
return car(v6);
}

original_code:
object_t *find_variable_value(object_t *var, object_t *env)
{
        object_t *frame, *vars, *vals;
        while (env != get_nil()) {
                frame = car(env);
                vars = frame_vars(frame);
                vals = frame_vals(frame);
                while (vars != get_nil()) {
                        if (var == car(vars))
                                return car(vals);
                        vars = cdr(vars);
                        vals = cdr(vals);
                }
                env = parent_env(env);
        }
        return ((void *)0);
}

canonical_original_code:
struct object_t *find_variable_value(struct object_t *var, struct object_t *env)
{
        struct object_t *frame; struct object_t *vars; struct object_t *vals;
        while (env != get_nil()) {
                frame = car(env);
                vars = frame_vars(frame);
                vals = frame_vals(frame);
                while (vars != get_nil()) {
                        if (var == car(vars))
                                return car(vals);
                        vars = cdr(vars);
                        vals = cdr(vals);
                }
                env = parent_env(env);
        }
        return ((void *)0);
}

variable_types:
var
struct object_t *


die

decompiled_code:
void __fastcall __noreturn die(char *format)
{
fprintf(stderr, format);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func17(char *format)
{
fprintf(stderr, format);
exit(1);
}

original_code:
void die(const char *msg)
{
        fprintf(stderr, msg);
        exit(1);
}

canonical_original_code:
void die(char *msg)
{
        fprintf(stderr, msg);
        exit(1);
}

variable_types:
msg
char *


decompiled_code:
_DWORD *initialize_types()
{
_DWORD *v0; // rbx
_DWORD *result; // rax

false_obj = (__int64)create_boolean(0);
true_obj = (__int64)create_boolean(1);
v0 = create_object(0);
nil = (__int64)v0;
quote = create_symbol("quote");
define = create_symbol("define");
create_symbol("lambda");
result = extend((__int64)v0, (__int64)v0, (__int64)v0);
global_env = (__int64)result;
return result;
}

canonical_decompiled_code:
_DWORD *func19()
{
_DWORD *v0; // rbx
_DWORD *result; // rax

false_obj = (__int64)create_boolean(0);
true_obj = (__int64)create_boolean(1);
v0 = create_object(0);
nil = (__int64)v0;
quote = func18("quote");
define = func18("define");
func18("lambda");
result = extend((__int64)v0, (__int64)v0, (__int64)v0);
global_env = (__int64)result;
return result;
}

original_code:
void initialize_types(void)
{
        false_obj = create_boolean(0);
        true_obj = create_boolean(1);
        nil = create_object(t_nil);
        quote = create_symbol("quote");
        define = create_symbol("define");
        lambda = create_symbol("lambda");
        empty_env = nil;
        global_env = extend(nil, nil, empty_env);
}

canonical_original_code:
void initialize_types()
{
        false_obj = create_boolean(0);
        true_obj = create_boolean(1);
        nil = create_object(t_nil);
        quote = create_symbol("quote");
        define = create_symbol("define");
        lambda = create_symbol("lambda");
        empty_env = nil;
        global_env = extend(nil, nil, empty_env);
}


decompiled_code:
__int64 __fastcall change_variable_value(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v7; // rbp
__int64 result; // rax

while ( 1 )
{
v4 = get_nil();
if ( v4 == a3 )
die("Variable not bound!\n");
v5 = car(a3);
v6 = frame_vars(v5);
v7 = frame_vals(v5);
if ( v4 != v6 )
break;
LABEL_3:
a3 = parent_env(a3);
}
while ( 1 )
{
result = car(v6);
if ( a1 == result )
break;
v6 = cdr(v6);
v7 = cdr(v7);
if ( v4 == v6 )
goto LABEL_3;
}
*(_QWORD *)(v7 + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v7; // rbp
__int64 result; // rax

while ( 1 )
{
v4 = func5();
if ( v4 == a3 )
func17("Variable not bound!\n");
v5 = func11(a3);
v6 = func14(v5);
v7 = func15(v5);
if ( v4 != v6 )
break;
LABEL_3:
a3 = func13(a3);
}
while ( 1 )
{
result = func11(v6);
if ( a1 == result )
break;
v6 = func12(v6);
v7 = func12(v7);
if ( v4 == v6 )
goto LABEL_3;
}
*(_QWORD *)(v7 + 8) = a2;
return result;
}

original_code:
void change_variable_value(object_t *var, object_t *val, object_t *env)
{
        object_t *frame, *vars, *vals;
        while (env != get_nil()) {
                frame = car(env);
                vars = frame_vars(frame);
                vals = frame_vals(frame);
                while (vars != get_nil()) {
                        if (var == car(vars)) {
                                vals->cons.car = val;
                                return;
                        }
                        vars = cdr(vars);
                        vals = cdr(vals);
                }
                env = parent_env(env);
        }
        die("Variable not bound!\n");
}

canonical_original_code:
void change_variable_value(struct object_t *var, struct object_t *val, struct object_t *env)
{
        struct object_t *frame; struct object_t *vars; struct object_t *vals;
        while (env != get_nil()) {
                frame = car(env);
                vars = frame_vars(frame);
                vals = frame_vals(frame);
                while (vars != get_nil()) {
                        if (var == car(vars)) {
                                vals->cons.car = val;
                                return;
                        }
                        vars = cdr(vars);
                        vals = cdr(vals);
                }
                env = parent_env(env);
        }
        die("Variable not bound!\n");
}

variable_types:
val
struct object_t *


decompiled_code:
void cleanup_types()
{
__int64 v0; // rbp
__int64 v1; // rbx
void *v2; // rdi

if ( MAX_SYMBOLS )
{
v0 = 8LL * (unsigned int)MAX_SYMBOLS;
v1 = 0LL;
do
{
v2 = *(void **)((char *)symbol_table + v1);
if ( v2 )
free(v2);
v1 += 8LL;
}
while ( v1 != v0 );
}
free(symbol_table);
}

canonical_decompiled_code:
void func21()
{
__int64 v0; // rbp
__int64 v1; // rbx
void *v2; // rdi

if ( MAX_SYMBOLS )
{
v0 = 8LL * (unsigned int)MAX_SYMBOLS;
v1 = 0LL;
do
{
v2 = *(void **)((char *)symbol_table + v1);
if ( v2 )
free(v2);
v1 += 8LL;
}
while ( v1 != v0 );
}
free(symbol_table);
}

original_code:
void cleanup_types(void)
{
        int i;
        for(i = 0; i < MAX_SYMBOLS; i++)
                if (symbol_table[i] != ((void *)0))
                        free(symbol_table[i]);
        free(symbol_table);
}

canonical_original_code:
void cleanup_types()
{
        int i;
        for(i = 0; i < MAX_SYMBOLS; i++)
                if (symbol_table[i] != ((void *)0))
                        free(symbol_table[i]);
        free(symbol_table);
}


repo: intfrr/lsmtree

decompiled_code:
void __fastcall buffer_free(void *ptr)
{
void *v2; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void buffer_free(struct buffer *b)
{
 if (b->buf)
  free(b->buf);
 free(b);
}

variable_types: struct buffer { char *buf; int NUL; int buflen; } *


decompiled_code:
__int64 __fastcall buffer_detach(__int64 *a1)
{
__int64 result; // rax

result = *a1;
*((_DWORD *)a1 + 2) = 0;
*((_DWORD *)a1 + 3) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1)
{
__int64 result; // rax

result = *a1;
*((_DWORD *)a1 + 2) = 0;
*((_DWORD *)a1 + 3) = 0;
return result;
}

original_code:
char * buffer_detach(struct buffer *b)
{
 char *buffer = b->buf;
 b->NUL = 0;
 b->buflen = 0;
 return buffer;
}

canonical_original_code:
char *buffer_detach(struct buffer *b)
{
 char *buffer = b->buf;
 b->NUL = 0;
 b->buflen = 0;
 return buffer;
}

variable_types:
buffer
char *

return_type: char *

user_defined_types: struct buffer { char *buf; int NUL; int buflen; }


decompiled_code:
int __fastcall buffer_dump(__int64 a1)
{
int result; // eax
__int64 v2; // rbx

result = printf("--buffer dump:buflen<%d>,pos<%d>\n", *(unsigned int *)(a1 + 12), *(unsigned int *)(a1 + 8));
if ( *(int *)(a1 + 8) > 0 )
{
v2 = 0LL;
do
{
result = printf("\t[%d] %c\n", (unsigned int)v2, (unsigned int)*(char *)(*(_QWORD *)a1 + v2));
++v2;
}
while ( *(_DWORD *)(a1 + 8) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
int result; // eax
__int64 v2; // rbx

result = printf("--buffer dump:buflen<%d>,pos<%d>\n", *(unsigned int *)(a1 + 12), *(unsigned int *)(a1 + 8));
if ( *(int *)(a1 + 8) > 0 )
{
v2 = 0LL;
do
{
result = printf("\t[%d] %c\n", (unsigned int)v2, (unsigned int)*(char *)(*(_QWORD *)a1 + v2));
++v2;
}
while ( *(_DWORD *)(a1 + 8) > (int)v2 );
}
return result;
}

original_code:
void buffer_dump(struct buffer *b)
{
 int i;
 printf("--buffer dump:buflen<%d>,pos<%d>\n",b->buflen,b->NUL);
 for(i=0;i<b->NUL;i++)
  printf("	[%d] %c\n",i,b->buf[i]);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er15
unsigned int v5; // ebx
__int64 v6; // r13
const char *v7; // rbp
unsigned int v9; // ebp
__int64 i; // rbp
char v11; // al
unsigned int v12; // eax
char v13; // [rsp+7h] [rbp-D1h]
const char *v14; // [rsp+8h] [rbp-D0h]
__int64 v15[17]; // [rsp+10h] [rbp-C8h]
int v16; // [rsp+98h] [rbp-40h] BYREF
int v17; // [rsp+9Ch] [rbp-3Ch] BYREF

v17 = 1240;
v16 = 60;
v15[15] = 0LL;
v15[0] = (__int64)"Missing or malformed command-line argument";
v15[1] = (__int64)"Command not recognized";
v15[2] = (__int64)"UBW32 not found (is device attached and in Bootloader mode?)";
v15[3] = (__int64)"USB initialization failed (phase 1)";
v15[4] = (__int64)"USB initialization failed (phase 2)";
v15[5] = (__int64)"UBW32 could not be opened for I/O";
v15[6] = (__int64)"USB write error";
v15[7] = (__int64)"USB read error";
v15[8] = (__int64)"Could not open hex file for input";
v15[9] = (__int64)"Could not query hex file size";
v15[10] = (__int64)"Could not map hex file to memory";
v15[11] = (__int64)"Unrecognized or invalid hex file syntax";
v15[12] = (__int64)"Bad end-of-line checksum in hex file";
v15[13] = (__int64)"Unsupported record type in hex file";
v15[14] = (__int64)"Verify failed";
if ( argc > 1 )
{
v3 = 1;
v13 = 4;
v14 = 0LL;
v4 = argc - 1;
while ( 1 )
{
v6 = v3;
v7 = argv[v6];
if ( !strncasecmp(v7, "-v", 2uLL) )
{
if ( v4 <= v3 )
{
v5 = 1;
goto LABEL_16;
}
++v3;
if ( (unsigned int)_isoc99_sscanf(argv[v6 + 1], "%x", &v17) != 1 )
{
v5 = 1;
goto LABEL_16;
}
}
else if ( !strncasecmp(v7, "-p", 2uLL) )
{
if ( v4 <= v3 )
{
v5 = 1;
goto LABEL_16;
}
++v3;
if ( (unsigned int)_isoc99_sscanf(argv[v6 + 1], "%x", &v16) != 1 )
{
v5 = 1;
goto LABEL_16;
}
}
else if ( !strncasecmp(v7, "-u", 2uLL) )
{
v13 |= 1u;
}
else if ( !strncasecmp(v7, "-e", 2uLL) )
{
v13 |= 2u;
}
else if ( !strncasecmp(v7, "-n", 2uLL) )
{
v13 &= 0xFBu;
}
else if ( !strncasecmp(v7, "-w", 2uLL) )
{
if ( v4 <= v3 )
{
v5 = 1;
goto LABEL_16;
}
++v3;
v14 = argv[v6 + 1];
v13 |= 2u;
}
else
{
if ( strncasecmp(v7, "-r", 2uLL) )
{
if ( !strncasecmp(v7, "-h", 2uLL) || (v5 = 2, !strncasecmp(v7, "-?", 2uLL)) )
{
puts(
"ubw32 : a Microchip HID Bootloader utility\n"
"Option Description Default\n"
"-------------------------------------------------------------------------\n"
"-w <file> Write hex file to UBW32 (will erase first) None\n"
"-e Erase UBW32 code space (implicit if -w) No erase\n"
"-r Reset device on program exit No reset\n"
"-n No verify after write Verify on\n"
"-u Unlock configuration memory before erase/write Config locked\n"
"-v <hex> USB device vendor ID 04d8\n"
"-p <hex> USB device product ID 003c\n"
"-h or -? Help");
return 0;
}
LABEL_16:
printf("%s Error", *argv);
goto LABEL_17;
}
v13 |= 8u;
}
if ( argc <= ++v3 )
goto LABEL_31;
}
}
v13 = 4;
v14 = 0LL;
LABEL_31:
v5 = usbOpen((unsigned __int16)v17, (unsigned __int16)v16);
if ( v5 )
goto LABEL_32;
printf("UBW32 found");
usbBuf = 2;
v9 = usbWrite(1LL, 1LL);
if ( v9 )
{
putchar(10);
goto LABEL_36;
}
for ( i = 3LL; ; i += 9LL )
{
v11 = *((_BYTE *)&usbBuf + i);
if ( v11 == -1 )
break;
if ( v11 == 1 )
printf(": %d bytes free", *(unsigned int *)((char *)&usbBuf + (int)i + 5));
}
putchar(10);
if ( (v13 & 1) != 0 )
{
puts("Unlocking configuration memory...");
usbBuf = 3;
*((_BYTE *)&usbBuf + 1) = 0;
v9 = usbWrite(2LL, 0LL);
if ( v9 || !v14 )
{
if ( v9 )
{
LABEL_36:
if ( !v14 )
goto LABEL_38;
goto LABEL_37;
}
LABEL_48:
if ( (v13 & 2) == 0 )
goto LABEL_49;
puts("Erasing...");
usbBuf = 4;
usbWrite(1LL, 0LL);
usbBuf = 2;
v12 = usbWrite(1LL, 1LL);
v9 = v12;
if ( v14 )
{
if ( v12 )
goto LABEL_37;
goto LABEL_50;
}
goto LABEL_38;
}
LABEL_60:
v9 = hexOpen(v14);
if ( v9 )
goto LABEL_38;
goto LABEL_48;
}
if ( v14 )
goto LABEL_60;
if ( (v13 & 2) == 0 )
{
LABEL_49:
if ( !v14 )
goto LABEL_54;
LABEL_50:
printf("Writing hex file '%s':", v14);
v9 = hexWrite((v13 & 4) != 0);
putchar(10);
LABEL_37:
hexClose();
goto LABEL_38;
}
puts("Erasing...");
usbBuf = 4;
usbWrite(1LL, 0LL);
usbBuf = 2;
v9 = usbWrite(1LL, 1LL);
LABEL_38:
if ( v9 )
{
usbClose();
v5 = v9;
goto LABEL_32;
}
LABEL_54:
if ( (v13 & 8) != 0 )
{
puts("Resetting device...");
usbBuf = 8;
v5 = usbWrite(1LL, 0LL);
usbClose();
if ( v5 )
{
LABEL_32:
printf("%s Error", *argv);
if ( v5 <= 0x10 )
LABEL_17:
printf(": %s\n", (const char *)v15[v5 - 1]);
else
puts(" of indeterminate type.");
return v5;
}
}
else
{
usbClose();
}
return v5;
}

original_code:
int main(
  int argc,
  char *argv[])
{
 char *hexFile = ((void *)0),
              actions = (1 << 2),
              eol;
 ErrorCode status = ERR_NONE;
 int i;
 unsigned int vendorID = 0x04d8,
              productID = 0x003c;
 const char * const errorString[ERR_EOL] = {
  "Missing or malformed command-line argument",
  "Command not recognized",
  "UBW32 not found (is device attached and in Bootloader mode?)",
  "USB initialization failed (phase 1)",
  "USB initialization failed (phase 2)",
  "UBW32 could not be opened for I/O",
  "USB write error",
  "USB read error",
  "Could not open hex file for input",
  "Could not query hex file size",
  "Could not map hex file to memory",
  "Unrecognized or invalid hex file syntax",
  "Bad end-of-line checksum in hex file",
  "Unsupported record type in hex file",
  "Verify failed"
 };
 for(i=1;(i < argc) && (ERR_NONE == status);i++) {
  eol = (i >= (argc - 1));
  if(!strncasecmp(argv[i],"-v",2)) {
   if(eol || (1 != sscanf(argv[++i],"%x",&vendorID)))
    status = ERR_CMD_ARG;
  } else if(!strncasecmp(argv[i],"-p",2)) {
   if(eol || (1 != sscanf(argv[++i],"%x",&productID)))
    status = ERR_CMD_ARG;
  } else if(!strncasecmp(argv[i],"-u",2)) {
   actions |= (1 << 0);
  } else if(!strncasecmp(argv[i],"-e",2)) {
   actions |= (1 << 1);
  } else if(!strncasecmp(argv[i],"-n",2)) {
   actions &= ~(1 << 2);
  } else if(!strncasecmp(argv[i],"-w",2)) {
   if(eol) {
    status = ERR_CMD_ARG;
   } else {
    hexFile = argv[++i];
    actions |= (1 << 1);
   }
  } else if(!strncasecmp(argv[i],"-r",2)) {
   actions |= (1 << 3);
  } else if(!strncasecmp(argv[i],"-h",2) ||
            !strncasecmp(argv[i],"-?",2)) {
   (void)puts(
"ubw32 : a Microchip HID Bootloader utility\n"
"Option     Description                                      Default\n"
"-------------------------------------------------------------------------\n"
"-w <file>  Write hex file to UBW32 (will erase first)       None\n"
"-e         Erase UBW32 code space (implicit if -w)          No erase\n"
"-r         Reset device on program exit                     No reset\n"
"-n         No verify after write                            Verify on\n"
"-u         Unlock configuration memory before erase/write   Config locked\n"
"-v <hex>   USB device vendor ID                             04d8\n"
"-p <hex>   USB device product ID                            003c\n"
"-h or -?   Help");
   return 0;
  } else {
   status = ERR_CMD_UNKNOWN;
  }
 }
 if((ERR_NONE == status) &&
    (ERR_NONE == (status = usbOpen(vendorID,productID)))) {
  (void)printf("UBW32 found");
  usbBuf[0] = 0x02;
  if(ERR_NONE == (status = usbWrite(1,1))) {
   int j;
   for(i=1,j=3;usbBuf[j]!=0xFF;j+=9,i++) {
     if(usbBuf[j] == 0x01)
       (void)printf(": %d bytes free",*(unsigned int *)&usbBuf[j + 5]);
   }
  }
  (void)putchar('\n');
  if((ERR_NONE == status) && (actions & (1 << 0))) {
   (void)puts("Unlocking configuration memory...");
   usbBuf[0] = 0x03;
   usbBuf[1] = 0x00;
   status = usbWrite(2,0);
  }
  if((ERR_NONE == status) && hexFile &&
     (ERR_NONE != (status = hexOpen(hexFile))))
   hexFile = ((void *)0);
  if((ERR_NONE == status) && (actions & (1 << 1))) {
   (void)puts("Erasing...");
   usbBuf[0] = 0x04;
   status = usbWrite(1,0);
   usbBuf[0] = 0x02;
   status = usbWrite(1,1);
  }
  if(hexFile) {
   if(ERR_NONE == status) {
     (void)printf("Writing hex file '%s':",hexFile);
     status = hexWrite((actions & (1 << 2)) != 0);
     (void)putchar('\n');
   }
   hexClose();
  }
  if((ERR_NONE == status) && (actions & (1 << 3))) {
   (void)puts("Resetting device...");
   usbBuf[0] = 0x08;
   status = usbWrite(1,0);
  }
  usbClose();
 }
 if(ERR_NONE != status) {
  (void)printf("%s Error",argv[0]);
  if(status <= ERR_EOL)
   (void)printf(": %s\n",errorString[status - 1]);
  else
   (void)puts(" of indeterminate type.");
 }
 return (int)status;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *hexFile = ((void *)0); char actions = (1 << 2); char eol;
 enum ErrorCode status = ERR_NONE;
 int i;
 unsigned int vendorID = 0x04d8; unsigned int productID = 0x003c;
 char *errorString[-1] = {
  "Missing or malformed command-line argument",
  "Command not recognized",
  "UBW32 not found (is device attached and in Bootloader mode?)",
  "USB initialization failed (phase 1)",
  "USB initialization failed (phase 2)",
  "UBW32 could not be opened for I/O",
  "USB write error",
  "USB read error",
  "Could not open hex file for input",
  "Could not query hex file size",
  "Could not map hex file to memory",
  "Unrecognized or invalid hex file syntax",
  "Bad end-of-line checksum in hex file",
  "Unsupported record type in hex file",
  "Verify failed"
 };
 for(i=1;(i < argc) && (ERR_NONE == status);i++) {
  eol = (i >= (argc - 1));
  if(!strncasecmp(argv[i],"-v",2)) {
   if(eol || (1 != sscanf(argv[++i],"%x",&vendorID)))
    status = ERR_CMD_ARG;
  } else if(!strncasecmp(argv[i],"-p",2)) {
   if(eol || (1 != sscanf(argv[++i],"%x",&productID)))
    status = ERR_CMD_ARG;
  } else if(!strncasecmp(argv[i],"-u",2)) {
   actions |= (1 << 0);
  } else if(!strncasecmp(argv[i],"-e",2)) {
   actions |= (1 << 1);
  } else if(!strncasecmp(argv[i],"-n",2)) {
   actions &= ~(1 << 2);
  } else if(!strncasecmp(argv[i],"-w",2)) {
   if(eol) {
    status = ERR_CMD_ARG;
   } else {
    hexFile = argv[++i];
    actions |= (1 << 1);
   }
  } else if(!strncasecmp(argv[i],"-r",2)) {
   actions |= (1 << 3);
  } else if(!strncasecmp(argv[i],"-h",2) ||
            !strncasecmp(argv[i],"-?",2)) {
   (void)puts(
"ubw32 : a Microchip HID Bootloader utility\n"
"Option     Description                                      Default\n"
"-------------------------------------------------------------------------\n"
"-w <file>  Write hex file to UBW32 (will erase first)       None\n"
"-e         Erase UBW32 code space (implicit if -w)          No erase\n"
"-r         Reset device on program exit                     No reset\n"
"-n         No verify after write                            Verify on\n"
"-u         Unlock configuration memory before erase/write   Config locked\n"
"-v <hex>   USB device vendor ID                             04d8\n"
"-p <hex>   USB device product ID                            003c\n"
"-h or -?   Help");
   return 0;
  } else {
   status = ERR_CMD_UNKNOWN;
  }
 }
 if((ERR_NONE == status) &&
    (ERR_NONE == (status = usbOpen(vendorID,productID)))) {
  (void)printf("UBW32 found");
  usbBuf[0] = 0x02;
  if(ERR_NONE == (status = usbWrite(1,1))) {
   int j;
   for(i=1,j=3;usbBuf[j]!=0xFF;j+=9,i++) {
     if(usbBuf[j] == 0x01)
       (void)printf(": %d bytes free",*(unsigned int *)&usbBuf[j + 5]);
   }
  }
  (void)putchar('\n');
  if((ERR_NONE == status) && (actions & (1 << 0))) {
   (void)puts("Unlocking configuration memory...");
   usbBuf[0] = 0x03;
   usbBuf[1] = 0x00;
   status = usbWrite(2,0);
  }
  if((ERR_NONE == status) && hexFile &&
     (ERR_NONE != (status = hexOpen(hexFile))))
   hexFile = ((void *)0);
  if((ERR_NONE == status) && (actions & (1 << 1))) {
   (void)puts("Erasing...");
   usbBuf[0] = 0x04;
   status = usbWrite(1,0);
   usbBuf[0] = 0x02;
   status = usbWrite(1,1);
  }
  if(hexFile) {
   if(ERR_NONE == status) {
     (void)printf("Writing hex file '%s':",hexFile);
     status = hexWrite((actions & (1 << 2)) != 0);
     (void)putchar('\n');
   }
   hexClose();
  }
  if((ERR_NONE == status) && (actions & (1 << 3))) {
   (void)puts("Resetting device...");
   usbBuf[0] = 0x08;
   status = usbWrite(1,0);
  }
  usbClose();
 }
 if(ERR_NONE != status) {
  (void)printf("%s Error",argv[0]);
  if(status <= ERR_EOL)
   (void)printf(": %s\n",errorString[status - 1]);
  else
   (void)puts(" of indeterminate type.");
 }
 return (int)status;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
hexFile
char *

variable_types: actions char

variable_types: eol char

variable_types: enum ErrorCode { ERR_NONE=0, ERR_CMD_ARG=1, ERR_CMD_UNKNOWN=2, ERR_UBW32_NOT_FOUND=3, ERR_USB_INIT1=4, ERR_USB_INIT2=5, ERR_USB_OPEN=6, ERR_USB_WRITE=7, ERR_USB_READ=8, ERR_HEX_OPEN=9, ERR_HEX_STAT=10, ERR_HEX_MMAP=11, ERR_HEX_SYNTAX=12, ERR_HEX_CHECKSUM=13, ERR_HEX_RECORD=14, ERR_VERIFY=15, ERR_EOL=16 }

variable_types:
vendorID
unsigned int

variable_types:
productID
unsigned int

variable_types:
errorString
char *[-1]

variable_types: j int

return_type: int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx

v3 = SDL_GetTicks() + 16;
init("Aron", argv);
loadGame();
atexit(cleanup);
while ( 1 )
{
getInput();
draw();
delay(v3);
v3 = SDL_GetTicks() + 16;
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx

v3 = SDL_GetTicks() + 16;
func12("Aron", argv);
func13();
func20(cleanup);
while ( 1 )
{
func15();
func9();
func11(v3);
v3 = SDL_GetTicks() + 16;
}
}

original_code:
int main( int argc, char *argv[ ] )
{
  unsigned int frameLimit = SDL_GetTicks() + 16;
  int go;
  init("Aron");
  loadGame();
  atexit(cleanup);
  go = 1;
  while (go == 1)
    {
      getInput();
      draw();
      delay(frameLimit);
      frameLimit = SDL_GetTicks() + 16;
    }
  exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  unsigned int frameLimit = SDL_GetTicks() + 16;
  int go;
  init("Aron");
  loadGame();
  atexit(cleanup);
  go = 1;
  while (go == 1)
    {
      getInput();
      draw();
      delay(frameLimit);
      frameLimit = SDL_GetTicks() + 16;
    }
  exit(0);
}

variable_types:
frameLimit
unsigned int

variable_types: go int


draw

decompiled_code:
__int64 draw()
{
drawImage(map, 0LL, 0LL);
drawMap();
SDL_Flip();
return SDL_Delay();
}

canonical_decompiled_code:
__int64 func9()
{
func7(map, 0LL, 0LL);
func17();
SDL_Flip();
return SDL_Delay();
}

original_code:
void draw(void)
{
  drawImage(map.background, 0, 0);
  drawMap();
  SDL_Flip(jeu.screen);
  SDL_Delay(1);
}

canonical_original_code:
void draw()
{
  drawImage(map.background, 0, 0);
  drawMap();
  SDL_Flip(jeu.screen);
  SDL_Delay(1);
}


delay

decompiled_code:
__int64 __fastcall delay(unsigned int a1)
{
__int64 result; // rax

result = SDL_GetTicks();
if ( (unsigned int)result <= a1 )
{
if ( (int)result + 16 >= a1 )
result = SDL_Delay();
else
result = SDL_Delay();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
__int64 result; // rax

result = SDL_GetTicks();
if ( (unsigned int)result <= a1 )
{
if ( (int)result + 16 >= a1 )
result = SDL_Delay();
else
result = SDL_Delay();
}
return result;
}

original_code:
void delay(unsigned int frameLimit)
{
  unsigned int ticks = SDL_GetTicks();
  if (frameLimit < ticks)
    {
      return;
    }
  if (frameLimit > ticks + 16)
    {
      SDL_Delay(16);
    }
  else
    {
      SDL_Delay(frameLimit - ticks);
    }
}

variable_types:
ticks
unsigned int


init

decompiled_code:
__int64 init()
{
const char *v1; // rax
const char *v2; // rax

if ( (int)SDL_Init() < 0 )
{
v1 = (const char *)SDL_GetError();
printf("Could not initialize SDL: %s\n", v1);
exit(1);
}
jeu = SDL_SetVideoMode();
if ( !jeu )
{
v2 = (const char *)SDL_GetError();
printf("Couldn't set screen mode to %d x %d: %s\n", 640LL, 480LL, v2);
exit(1);
}
SDL_WM_SetCaption();
return SDL_ShowCursor();
}

canonical_decompiled_code:
__int64 func12()
{
const char *v1; // rax
const char *v2; // rax

if ( (int)SDL_Init() < 0 )
{
v1 = (const char *)SDL_GetError();
printf("Could not initialize SDL: %s\n", v1);
exit(1);
}
jeu = SDL_SetVideoMode();
if ( !jeu )
{
v2 = (const char *)SDL_GetError();
printf("Couldn't set screen mode to %d x %d: %s\n", 640LL, 480LL, v2);
exit(1);
}
SDL_WM_SetCaption();
return SDL_ShowCursor();
}

original_code:
void init(char *title)
{
  if (SDL_Init(0x00000020 ) < 0)
    {
      printf("Could not initialize SDL: %s\n", SDL_GetError());
      exit(1);
    }
  jeu.screen = SDL_SetVideoMode(640, 480, 0,
    0x20000000|0x40000000);
  if (jeu.screen == ((void *)0))
    {
      printf("Couldn't set screen mode to %d x %d: %s\n", 640,
      480, SDL_GetError());
      exit(1);
    }
  SDL_WM_SetCaption(title, ((void *)0));
  SDL_ShowCursor(0);
}

variable_types:
title
char *


loadGame

decompiled_code:
__int64 loadGame()
{
map = loadImage("graphics/background.png");
qword_404108 = loadImage("graphics/tileset.png");
return loadMap("map/map1.txt");
}

canonical_decompiled_code:
__int64 func13()
{
map = func10("graphics/background.png");
qword_404108 = func10("graphics/tileset.png");
return func16("map/map1.txt");
}

original_code:
void loadGame(void)
{
  map.background = loadImage("graphics/background.png");
  map.tileSet = loadImage("graphics/tileset.png");
  loadMap("map/map1.txt");
}

canonical_original_code:
void loadGame()
{
  map.background = loadImage("graphics/background.png");
  map.tileSet = loadImage("graphics/tileset.png");
  loadMap("map/map1.txt");
}


cleanup

decompiled_code:
__int64 cleanup()
{
if ( map )
SDL_FreeSurface();
if ( qword_404108 )
SDL_FreeSurface();
return SDL_Quit();
}

canonical_decompiled_code:
__int64 func14()
{
if ( map )
SDL_FreeSurface();
if ( qword_404108 )
SDL_FreeSurface();
return SDL_Quit();
}

original_code:
void cleanup()
{
  if (map.background != ((void *)0))
    SDL_FreeSurface(map.background);
  if (map.tileSet != ((void *)0))
    SDL_FreeSurface(map.tileSet);
  SDL_Quit();
}


drawMap

decompiled_code:
__int64 drawMap()
{
__int64 v0; // r13
unsigned int i; // er12
_DWORD *v2; // rbp
unsigned int j; // ebx
__int64 result; // rax

v0 = 0LL;
for ( i = 0; i != 480; i += 32 )
{
v2 = (_DWORD *)&map[v0 + 4] + dword_404110 / 32;
for ( j = 0; j != 640; j += 32 )
{
result = drawTile(qword_404108, j, i, (unsigned int)(32 * (*v2 % 10)), (unsigned int)(32 * (*v2 / 10)));
++v2;
}
v0 += 200LL;
}
return result;
}

original_code:
void drawMap(void)
{
  int x, y, mapX, x1, x2, mapY, y1, y2, xsource, ysource, a;
  mapX = x1 = mapY = y1 = 0;
  x2 = 640;
  y2 = 480;
  for (y = y1; y < y2; y += 32)
    {
      mapX = map.startX / 32;
      for (x = x1; x < x2; x += 32)
 {
   a = map.tile[mapY][mapX];
   ysource = a / 10 * 32;
   xsource = a % 10 * 32;
   drawTile(map.tileSet, x, y, xsource, ysource);
   mapX++;
 }
      mapY++;
    }
}

canonical_original_code:
void drawMap()
{
  int x; int y; int mapX; int x1; int x2; int mapY; int y1; int y2; int xsource; int ysource; int a;
  mapX = x1 = mapY = y1 = 0;
  x2 = 640;
  y2 = 480;
  for (y = y1; y < y2; y += 32)
    {
      mapX = map.startX / 32;
      for (x = x1; x < x2; x += 32)
 {
   a = map.tile[mapY][mapX];
   ysource = a / 10 * 32;
   xsource = a % 10 * 32;
   drawTile(map.tileSet, x, y, xsource, ysource);
   mapX++;
 }
      mapY++;
    }
}

variable_types: x int

variable_types: y int

variable_types: mapX int

variable_types: mapY int

variable_types: xsource int

variable_types: ysource int

variable_types: a int


repo: jdtw/minitorrent

decompiled_code:
int __fastcall print_hash(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx

v1 = a1;
do
printf("%02x", *v1++);
while ( v1 != a1 + 20 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx

v1 = a1;
do
printf("%02x", *v1++);
while ( v1 != a1 + 20 );
return putchar(10);
}

original_code:
void print_hash(unsigned char *hash) {
    int i;
    unsigned char *p = hash;
    for (i=0; i < 20; i++, p += 2) {
        printf("%02x", hash[i]);
    }
    printf("\n");
}

variable_types:
hash
unsigned char *

variable_types: i int

variable_types:
p
unsigned char *


decompiled_code:
char *__fastcall strip_path(char *s)
{
char *v1; // rdx
char *result; // rax

v1 = strchr(s, 47);
result = s;
if ( v1 )
result = strrchr(s, 47) + 1;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
char *v1; // rdx
char *result; // rax

v1 = strchr(s, 47);
result = s;
if ( v1 )
result = strrchr(s, 47) + 1;
return result;
}

original_code:
char *strip_path(char *path) {
    char *p;
    if (strchr(path, '/') == ((void *)0))
        p = path;
    else
        p = strrchr(path, '/') + 1;
    return p;
}

variable_types:
path
char *

variable_types:
p
char *


original_code:
void parse_torrent(char *path, torrent *t) {
    int fd, i;
    if((fd = open(path, 00)) == -1) {
        perror("open");
        return;
    }
    memset(t, 0, sizeof(*t));
    read(fd, (void*)t->tracker, 64);
    read(fd, (void*)t->file_hash, 20);
    read(fd, (void*)&t->num_chunks, sizeof(t->num_chunks));
    t->chunks = malloc(sizeof(unsigned char*) * t->num_chunks);
    for(i=0;i<t->num_chunks;i++) {
        t->chunks[i] = (unsigned char *) malloc(20);
        read(fd, (void*)t->chunks[i], 20);
    }
    read(fd, (void*)t->friendly_name, 4096);
    close(fd);
}

canonical_original_code:
void parse_torrent(char *path, struct torrent *t) {
    int fd; int i;
    if((fd = open(path, 00)) == -1) {
        perror("open");
        return;
    }
    memset(t, 0, sizeof(*t));
    read(fd, (void *)t->tracker, 64);
    read(fd, (void *)t->file_hash, 20);
    read(fd, (void *)&t->num_chunks, sizeof(t->num_chunks));
    t->chunks = malloc(sizeof(unsigned char *) * t->num_chunks);
    for(i=0;i<t->num_chunks;i++) {
        t->chunks[i] = (unsigned char *) malloc(20);
        read(fd, (void *)t->chunks[i], 20);
    }
    read(fd, (void *)t->friendly_name, 4096);
    close(fd);
}

variable_types: struct torrent { char tracker[64]; unsigned char file_hash[20]; int num_chunks; unsigned char **chunks; char friendly_name[4096]; } *

variable_types: fd int


decompiled_code:
int __fastcall dump_torrent(int a1, int a2, int a3, int a4, int a5, int a6, char s, int a8, int a9, int a10, int a11, int a12, int a13, int a14, char a15, int a16, __int64 a17, __int64 a18, char a19)
{
int result; // eax
__int64 v20; // rbp
int v21; // ebx

printf("%s: ", &a19);
print_hash((unsigned __int8 *)&a15);
puts(&s);
result = printf("%d chunk(s)\n", HIDWORD(a17));
if ( SHIDWORD(a17) > 0 )
{
v20 = 0LL;
v21 = 0;
do
{
printf("%d: ", (unsigned int)++v21);
result = print_hash(*(unsigned __int8 **)(a18 + v20));
v20 += 8LL;
}
while ( v21 < SHIDWORD(a17) );
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, int a2, int a3, int a4, int a5, int a6, char s, int a8, int a9, int a10, int a11, int a12, int a13, int a14, char a15, int a16, __int64 a17, __int64 a18, char a19)
{
int result; // eax
__int64 v20; // rbp
int v21; // ebx

printf("%s: ", &a19);
func0((unsigned __int8 *)&a15);
puts(&s);
result = printf("%d chunk(s)\n", HIDWORD(a17));
if ( SHIDWORD(a17) > 0 )
{
v20 = 0LL;
v21 = 0;
do
{
printf("%d: ", (unsigned int)++v21);
result = func0(*(unsigned __int8 **)(a18 + v20));
v20 += 8LL;
}
while ( v21 < SHIDWORD(a17) );
}
return result;
}

original_code:
void dump_torrent(torrent t) {
    int i;
    printf("%s: ", t.friendly_name);
    print_hash(t.file_hash);
    printf("%s\n", t.tracker);
    printf("%d chunk(s)\n", t.num_chunks);
    for(i=0;i<t.num_chunks;i++) {
        printf("%d: ", i+1);
        print_hash(t.chunks[i]);
    }
}

canonical_original_code:
void dump_torrent(struct torrent t) {
    int i;
    printf("%s: ", t.friendly_name);
    print_hash(t.file_hash);
    printf("%s\n", t.tracker);
    printf("%d chunk(s)\n", t.num_chunks);
    for(i=0;i<t.num_chunks;i++) {
        printf("%d: ", i+1);
        print_hash(t.chunks[i]);
    }
}

variable_types: struct torrent { char tracker[64]; unsigned char file_hash[20]; int num_chunks; unsigned char **chunks; char friendly_name[4096]; }


decompiled_code:
void __fastcall free_torrent(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, __int64 a17, void *ptr)
{
void **v18; // rbx

if ( SHIDWORD(a17) > 0 )
{
v18 = (void **)ptr;
do
free(*v18++);
while ( v18 != (void **)((char *)ptr + 8 * (unsigned int)(HIDWORD(a17) - 1) + 8) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, __int64 a17, void *ptr)
{
void **v18; // rbx

if ( SHIDWORD(a17) > 0 )
{
v18 = (void **)ptr;
do
free(*v18++);
while ( v18 != (void **)((char *)ptr + 8 * (unsigned int)(HIDWORD(a17) - 1) + 8) );
}
free(ptr);
}

original_code:
void free_torrent(torrent t) {
    int i;
    for(i=0; i<t.num_chunks; i++) {
        free(t.chunks[i]);
    }
    free(t.chunks);
}

canonical_original_code:
void free_torrent(struct torrent t) {
    int i;
    for(i=0; i<t.num_chunks; i++) {
        free(t.chunks[i]);
    }
    free(t.chunks);
}

user_defined_types: struct torrent { char tracker[64]; unsigned char file_hash[20]; int num_chunks; unsigned char **chunks; char friendly_name[4096]; }