decompiled_code:
__int64 __fastcall count_cidr_bits(__int64 a1)
{
unsigned int v1; // ecx

v1 = 0;
LODWORD(a1) = a1 ^ HIDWORD(a1);
while ( ((0xFFFFFFFF >> v1) & HIDWORD(a1)) != (_DWORD)a1 || 0xFFFFFFFF >> v1 != (_DWORD)a1 )
{
if ( ++v1 == 32 )
return 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ecx

v1 = 0;
LODWORD(a1) = a1 ^ HIDWORD(a1);
while ( ((0xFFFFFFFF >> v1) & HIDWORD(a1)) != (_DWORD)a1 || 0xFFFFFFFF >> v1 != (_DWORD)a1 )
{
if ( ++v1 == 32 )
return 0;
}
return v1;
}

original_code:
static unsigned
count_cidr_bits(struct Range range)
{
    unsigned i;
    for (i=0; i<32; i++) {
        unsigned mask = 0xFFFFFFFF >> i;
        if ((range.begin & ~mask) == (range.end & ~mask)) {
            if ((range.begin & mask) == 0 && (range.end & mask) == mask)
                return i;
        }
    }
    return 0;
}

canonical_original_code:
static unsigned int count_cidr_bits(struct Range range)
{
    unsigned int i;
    for (i=0; i<32; i++) {
        unsigned int mask = 0xFFFFFFFF >> i;
        if ((range.begin & ~mask) == (range.end & ~mask)) {
            if ((range.begin & mask) == 0 && (range.end & mask) == mask)
                return i;
        }
    }
    return 0;
}

variable_types: struct Range { unsigned int begin; unsigned int end; }

variable_types:
mask
unsigned int


repo: robertdavidgraham/masscan

decompiled_code:
__int64 vnc_selftest()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
static int
vnc_selftest(void)
{
    return 0;
}

canonical_original_code:
static int vnc_selftest()
{
    return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall vnc_append_sectype(__int64 a1, unsigned int a2)
{
__int64 result; // rax
const char *v3; // rdx
char v4[24]; // [rsp+0h] [rbp-18h] BYREF

switch ( a2 )
{
case 0u:
v3 = "invalid";
goto LABEL_4;
case 1u:
v3 = "none";
goto LABEL_4;
case 2u:
v3 = "VNC-chap";
goto LABEL_4;
case 5u:
v3 = "RA2";
goto LABEL_4;
case 6u:
v3 = "RA2ne";
goto LABEL_4;
case 7u:
v3 = "SSPI";
goto LABEL_4;
case 8u:
v3 = "SSPIne";
goto LABEL_4;
case 0x10u:
v3 = "Tight";
goto LABEL_4;
case 0x11u:
v3 = "Ultra";
goto LABEL_4;
case 0x12u:
v3 = "TLS";
goto LABEL_4;
case 0x13u:
v3 = "VeNCrypt";
goto LABEL_4;
case 0x14u:
v3 = "GTK-VNC-SASL";
goto LABEL_4;
case 0x15u:
v3 = "MD5";
goto LABEL_4;
case 0x16u:
v3 = "Colin-Dean-xvp";
goto LABEL_4;
case 0x1Eu:
v3 = "Apple30";
goto LABEL_4;
case 0x23u:
v3 = "Apple35";
LABEL_4:
result = banout_append(a1, 22LL, v3, -1LL);
break;
default:
snprintf(v4, 0x10uLL, "%u", a2);
result = banout_append(a1, 22LL, v4, -1LL);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
__int64 result; // rax
const char *v3; // rdx
char v4[24]; // [rsp+0h] [rbp-18h] BYREF

switch ( a2 )
{
case 0u:
v3 = "invalid";
goto LABEL_4;
case 1u:
v3 = "none";
goto LABEL_4;
case 2u:
v3 = "VNC-chap";
goto LABEL_4;
case 5u:
v3 = "RA2";
goto LABEL_4;
case 6u:
v3 = "RA2ne";
goto LABEL_4;
case 7u:
v3 = "SSPI";
goto LABEL_4;
case 8u:
v3 = "SSPIne";
goto LABEL_4;
case 0x10u:
v3 = "Tight";
goto LABEL_4;
case 0x11u:
v3 = "Ultra";
goto LABEL_4;
case 0x12u:
v3 = "TLS";
goto LABEL_4;
case 0x13u:
v3 = "VeNCrypt";
goto LABEL_4;
case 0x14u:
v3 = "GTK-VNC-SASL";
goto LABEL_4;
case 0x15u:
v3 = "MD5";
goto LABEL_4;
case 0x16u:
v3 = "Colin-Dean-xvp";
goto LABEL_4;
case 0x1Eu:
v3 = "Apple30";
goto LABEL_4;
case 0x23u:
v3 = "Apple35";
LABEL_4:
result = banout_append(a1, 22LL, v3, -1LL);
break;
default:
snprintf(v4, 0x10uLL, "%u", a2);
result = banout_append(a1, 22LL, v4, -1LL);
break;
}
return result;
}

original_code:
static void
vnc_append_sectype(struct BannerOutput *banout, unsigned sectype)
{
    char foo[16];
    switch (sectype) {
        case 0:
            banout_append(banout, PROTO_VNC_RFB, "invalid", ((size_t)~0));
            break;
        case 1:
            banout_append(banout, PROTO_VNC_RFB, "none", ((size_t)~0));
            break;
        case 2:
            banout_append(banout, PROTO_VNC_RFB, "VNC-chap", ((size_t)~0));
            break;
        case 5:
            banout_append(banout, PROTO_VNC_RFB, "RA2", ((size_t)~0));
            break;
        case 6:
            banout_append(banout, PROTO_VNC_RFB, "RA2ne", ((size_t)~0));
            break;
        case 7:
            banout_append(banout, PROTO_VNC_RFB, "SSPI", ((size_t)~0));
            break;
        case 8:
            banout_append(banout, PROTO_VNC_RFB, "SSPIne", ((size_t)~0));
            break;
        case 16:
            banout_append(banout, PROTO_VNC_RFB, "Tight", ((size_t)~0));
            break;
        case 17:
            banout_append(banout, PROTO_VNC_RFB, "Ultra", ((size_t)~0));
            break;
        case 18:
            banout_append(banout, PROTO_VNC_RFB, "TLS", ((size_t)~0));
            break;
        case 19:
            banout_append(banout, PROTO_VNC_RFB, "VeNCrypt", ((size_t)~0));
            break;
        case 20:
            banout_append(banout, PROTO_VNC_RFB, "GTK-VNC-SASL", ((size_t)~0));
            break;
        case 21:
            banout_append(banout, PROTO_VNC_RFB, "MD5", ((size_t)~0));
            break;
        case 22:
            banout_append(banout, PROTO_VNC_RFB, "Colin-Dean-xvp", ((size_t)~0));
            break;
        case 30:
            banout_append(banout, PROTO_VNC_RFB, "Apple30", ((size_t)~0));
            break;
        case 35:
            banout_append(banout, PROTO_VNC_RFB, "Apple35", ((size_t)~0));
            break;
        default:
            snprintf(foo, sizeof(foo), "%u", sectype);
            banout_append(banout, PROTO_VNC_RFB, foo, ((size_t)~0));
            break;
    }
}

canonical_original_code:
static void vnc_append_sectype(struct BannerOutput *banout, unsigned int sectype)
{
    char foo[16];
    switch (sectype) {
        case 0:
            banout_append(banout, PROTO_VNC_RFB, "invalid", ((unsigned long)~0));
            break;
        case 1:
            banout_append(banout, PROTO_VNC_RFB, "none", ((unsigned long)~0));
            break;
        case 2:
            banout_append(banout, PROTO_VNC_RFB, "VNC-chap", ((unsigned long)~0));
            break;
        case 5:
            banout_append(banout, PROTO_VNC_RFB, "RA2", ((unsigned long)~0));
            break;
        case 6:
            banout_append(banout, PROTO_VNC_RFB, "RA2ne", ((unsigned long)~0));
            break;
        case 7:
            banout_append(banout, PROTO_VNC_RFB, "SSPI", ((unsigned long)~0));
            break;
        case 8:
            banout_append(banout, PROTO_VNC_RFB, "SSPIne", ((unsigned long)~0));
            break;
        case 16:
            banout_append(banout, PROTO_VNC_RFB, "Tight", ((unsigned long)~0));
            break;
        case 17:
            banout_append(banout, PROTO_VNC_RFB, "Ultra", ((unsigned long)~0));
            break;
        case 18:
            banout_append(banout, PROTO_VNC_RFB, "TLS", ((unsigned long)~0));
            break;
        case 19:
            banout_append(banout, PROTO_VNC_RFB, "VeNCrypt", ((unsigned long)~0));
            break;
        case 20:
            banout_append(banout, PROTO_VNC_RFB, "GTK-VNC-SASL", ((unsigned long)~0));
            break;
        case 21:
            banout_append(banout, PROTO_VNC_RFB, "MD5", ((unsigned long)~0));
            break;
        case 22:
            banout_append(banout, PROTO_VNC_RFB, "Colin-Dean-xvp", ((unsigned long)~0));
            break;
        case 30:
            banout_append(banout, PROTO_VNC_RFB, "Apple30", ((unsigned long)~0));
            break;
        case 35:
            banout_append(banout, PROTO_VNC_RFB, "Apple35", ((unsigned long)~0));
            break;
        default:
            snprintf(foo, sizeof(foo), "%u", sectype);
            banout_append(banout, PROTO_VNC_RFB, foo, ((unsigned long)~0));
            break;
    }
}

variable_types: struct BannerOutput { struct BannerOutput *next; unsigned int protocol; unsigned int length; unsigned int max_length; unsigned char banner[200]; } *

variable_types:
sectype
unsigned int

variable_types:
foo
char [16]

return_type: void


decompiled_code:
__int64 stublua_init()
{
char *v0; // rbp
char **v1; // rbx

v0 = "liblua5.3.so";
v1 = possible_names_0;
while ( 1 )
{
v0 = (char *)dlopen(v0, 1);
if ( v0 )
break;
v0 = v1[1];
++v1;
if ( !v0 )
{
fwrite("liblua: failed to load Lua shared library\n", 1uLL, 0x2AuLL, stderr);
fwrite(" HINT: you must install Lua library\n", 1uLL, 0x27uLL, stderr);
break;
}
}
lua_version = (__int64)dlsym(v0, "lua_version");
if ( !lua_version )
fprintf(stderr, "liblua: %s: failed\n", "lua_version");
lua_close = (__int64)dlsym(v0, "lua_close");
if ( !lua_close )
fprintf(stderr, "liblua: %s: failed\n", "lua_close");
lua_getfield = (__int64)dlsym(v0, "lua_getfield");
if ( !lua_getfield )
fprintf(stderr, "liblua: %s: failed\n", "lua_getfield");
lua_getglobal = (__int64)dlsym(v0, "lua_getglobal");
if ( !lua_getglobal )
fprintf(stderr, "liblua: %s: failed\n", "lua_getglobal");
lua_geti = (__int64)dlsym(v0, "lua_geti");
if ( !lua_geti )
fprintf(stderr, "liblua: %s: failed\n", "lua_geti");
lua_gettop = (__int64)dlsym(v0, "lua_gettop");
if ( !lua_gettop )
fprintf(stderr, "liblua: %s: failed\n", "lua_gettop");
lua_isnumber = (__int64)dlsym(v0, "lua_isnumber");
if ( !lua_isnumber )
fprintf(stderr, "liblua: %s: failed\n", "lua_isnumber");
lua_isstring = (__int64)dlsym(v0, "lua_isstring");
if ( !lua_isstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_isstring");
lua_iscfunction = (__int64)dlsym(v0, "lua_iscfunction");
if ( !lua_iscfunction )
fprintf(stderr, "liblua: %s: failed\n", "lua_iscfunction");
lua_isinteger = (__int64)dlsym(v0, "lua_isinteger");
if ( !lua_isinteger )
fprintf(stderr, "liblua: %s: failed\n", "lua_isinteger");
lua_isuserdata = (__int64)dlsym(v0, "lua_isuserdata");
if ( !lua_isuserdata )
fprintf(stderr, "liblua: %s: failed\n", "lua_isuserdata");
lua_newthread = (__int64)dlsym(v0, "lua_newthread");
if ( !lua_newthread )
fprintf(stderr, "liblua: %s: failed\n", "lua_newthread");
lua_newuserdata = (__int64)dlsym(v0, "lua_newuserdata");
if ( !lua_newuserdata )
fprintf(stderr, "liblua: %s: failed\n", "lua_newuserdata");
lua_pcallk = (__int64)dlsym(v0, "lua_pcallk");
if ( !lua_pcallk )
fprintf(stderr, "liblua: %s: failed\n", "lua_pcallk");
lua_pushcclosure = (__int64)dlsym(v0, "lua_pushcclosure");
if ( !lua_pushcclosure )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushcclosure");
lua_pushinteger = (__int64)dlsym(v0, "lua_pushinteger");
if ( !lua_pushinteger )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushinteger");
lua_pushlstring = (__int64)dlsym(v0, "lua_pushlstring");
if ( !lua_pushlstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushlstring");
lua_pushnumber = (__int64)dlsym(v0, "lua_pushnumber");
if ( !lua_pushnumber )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushnumber");
lua_pushstring = (__int64)dlsym(v0, "lua_pushstring");
if ( !lua_pushstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushstring");
lua_pushvalue = (__int64)dlsym(v0, "lua_pushvalue");
if ( !lua_pushvalue )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushvalue");
lua_resume = (__int64)dlsym(v0, "lua_resume");
if ( !lua_resume )
fprintf(stderr, "liblua: %s: failed\n", "lua_resume");
lua_setfield = (__int64)dlsym(v0, "lua_setfield");
if ( !lua_setfield )
fprintf(stderr, "liblua: %s: failed\n", "lua_setfield");
lua_setglobal = (__int64)dlsym(v0, "lua_setglobal");
if ( !lua_setglobal )
fprintf(stderr, "liblua: %s: failed\n", "lua_setglobal");
lua_seti = (__int64)dlsym(v0, "lua_seti");
if ( !lua_seti )
fprintf(stderr, "liblua: %s: failed\n", "lua_seti");
lua_settop = (__int64)dlsym(v0, "lua_settop");
if ( !lua_settop )
fprintf(stderr, "liblua: %s: failed\n", "lua_settop");
lua_toboolean = (__int64)dlsym(v0, "lua_toboolean");
if ( !lua_toboolean )
fprintf(stderr, "liblua: %s: failed\n", "lua_toboolean");
lua_tointegerx = (__int64)dlsym(v0, "lua_tointegerx");
if ( !lua_tointegerx )
fprintf(stderr, "liblua: %s: failed\n", "lua_tointegerx");
lua_tolstring = (__int64)dlsym(v0, "lua_tolstring");
if ( !lua_tolstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_tolstring");
lua_tonumberx = (__int64)dlsym(v0, "lua_tonumberx");
if ( !lua_tonumberx )
fprintf(stderr, "liblua: %s: failed\n", "lua_tonumberx");
lua_type = (__int64)dlsym(v0, "lua_type");
if ( !lua_type )
fprintf(stderr, "liblua: %s: failed\n", "lua_type");
lua_typename = (__int64)dlsym(v0, "lua_typename");
if ( !lua_typename )
fprintf(stderr, "liblua: %s: failed\n", "lua_typename");
lua_version = (__int64)dlsym(v0, "lua_version");
if ( !lua_version )
fprintf(stderr, "liblua: %s: failed\n", "lua_version");
lua_xmove = (__int64)dlsym(v0, "lua_xmove");
if ( !lua_xmove )
fprintf(stderr, "liblua: %s: failed\n", "lua_xmove");
lua_yieldk = (__int64)dlsym(v0, "lua_yieldk");
if ( !lua_yieldk )
fprintf(stderr, "liblua: %s: failed\n", "lua_yieldk");
luaL_checkinteger = (__int64)dlsym(v0, "luaL_checkinteger");
if ( !luaL_checkinteger )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checkinteger");
luaL_checklstring = (__int64)dlsym(v0, "luaL_checklstring");
if ( !luaL_checklstring )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checklstring");
luaL_checkudata = (__int64)dlsym(v0, "luaL_checkudata");
if ( !luaL_checkudata )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checkudata");
luaL_len = (__int64)dlsym(v0, "luaL_len");
if ( !luaL_len )
fprintf(stderr, "liblua: %s: failed\n", "luaL_len");
luaL_loadbufferx = (__int64)dlsym(v0, "luaL_loadbufferx");
if ( !luaL_loadbufferx )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadbufferx");
luaL_loadfilex = (__int64)dlsym(v0, "luaL_loadfilex");
if ( !luaL_loadfilex )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadfilex");
luaL_loadstring = (__int64)dlsym(v0, "luaL_loadstring");
if ( !luaL_loadstring )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadstring");
luaL_newmetatable = (__int64)dlsym(v0, "luaL_newmetatable");
if ( !luaL_newmetatable )
fprintf(stderr, "liblua: %s: failed\n", "luaL_newmetatable");
luaL_newstate = (__int64)dlsym(v0, "luaL_newstate");
if ( !luaL_newstate )
fprintf(stderr, "liblua: %s: failed\n", "luaL_newstate");
luaL_openlibs = (__int64)dlsym(v0, "luaL_openlibs");
if ( !luaL_openlibs )
fprintf(stderr, "liblua: %s: failed\n", "luaL_openlibs");
luaL_ref = (__int64)dlsym(v0, "luaL_ref");
if ( !luaL_ref )
fprintf(stderr, "liblua: %s: failed\n", "luaL_ref");
luaL_setfuncs = (__int64)dlsym(v0, "luaL_setfuncs");
if ( !luaL_setfuncs )
fprintf(stderr, "liblua: %s: failed\n", "luaL_setfuncs");
luaL_setmetatable = (__int64)dlsym(v0, "luaL_setmetatable");
if ( !luaL_setmetatable )
fprintf(stderr, "liblua: %s: failed\n", "luaL_setmetatable");
luaL_unref = (__int64)dlsym(v0, "luaL_unref");
if ( !luaL_unref )
fprintf(stderr, "liblua: %s: failed\n", "luaL_unref");
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // rbp
char **v1; // rbx

v0 = "liblua5.3.so";
v1 = possible_names_0;
while ( 1 )
{
v0 = (char *)dlopen(v0, 1);
if ( v0 )
break;
v0 = v1[1];
++v1;
if ( !v0 )
{
fwrite("liblua: failed to load Lua shared library\n", 1uLL, 0x2AuLL, stderr);
fwrite(" HINT: you must install Lua library\n", 1uLL, 0x27uLL, stderr);
break;
}
}
lua_version = (__int64)dlsym(v0, "lua_version");
if ( !lua_version )
fprintf(stderr, "liblua: %s: failed\n", "lua_version");
lua_close = (__int64)dlsym(v0, "lua_close");
if ( !lua_close )
fprintf(stderr, "liblua: %s: failed\n", "lua_close");
lua_getfield = (__int64)dlsym(v0, "lua_getfield");
if ( !lua_getfield )
fprintf(stderr, "liblua: %s: failed\n", "lua_getfield");
lua_getglobal = (__int64)dlsym(v0, "lua_getglobal");
if ( !lua_getglobal )
fprintf(stderr, "liblua: %s: failed\n", "lua_getglobal");
lua_geti = (__int64)dlsym(v0, "lua_geti");
if ( !lua_geti )
fprintf(stderr, "liblua: %s: failed\n", "lua_geti");
lua_gettop = (__int64)dlsym(v0, "lua_gettop");
if ( !lua_gettop )
fprintf(stderr, "liblua: %s: failed\n", "lua_gettop");
lua_isnumber = (__int64)dlsym(v0, "lua_isnumber");
if ( !lua_isnumber )
fprintf(stderr, "liblua: %s: failed\n", "lua_isnumber");
lua_isstring = (__int64)dlsym(v0, "lua_isstring");
if ( !lua_isstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_isstring");
lua_iscfunction = (__int64)dlsym(v0, "lua_iscfunction");
if ( !lua_iscfunction )
fprintf(stderr, "liblua: %s: failed\n", "lua_iscfunction");
lua_isinteger = (__int64)dlsym(v0, "lua_isinteger");
if ( !lua_isinteger )
fprintf(stderr, "liblua: %s: failed\n", "lua_isinteger");
lua_isuserdata = (__int64)dlsym(v0, "lua_isuserdata");
if ( !lua_isuserdata )
fprintf(stderr, "liblua: %s: failed\n", "lua_isuserdata");
lua_newthread = (__int64)dlsym(v0, "lua_newthread");
if ( !lua_newthread )
fprintf(stderr, "liblua: %s: failed\n", "lua_newthread");
lua_newuserdata = (__int64)dlsym(v0, "lua_newuserdata");
if ( !lua_newuserdata )
fprintf(stderr, "liblua: %s: failed\n", "lua_newuserdata");
lua_pcallk = (__int64)dlsym(v0, "lua_pcallk");
if ( !lua_pcallk )
fprintf(stderr, "liblua: %s: failed\n", "lua_pcallk");
lua_pushcclosure = (__int64)dlsym(v0, "lua_pushcclosure");
if ( !lua_pushcclosure )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushcclosure");
lua_pushinteger = (__int64)dlsym(v0, "lua_pushinteger");
if ( !lua_pushinteger )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushinteger");
lua_pushlstring = (__int64)dlsym(v0, "lua_pushlstring");
if ( !lua_pushlstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushlstring");
lua_pushnumber = (__int64)dlsym(v0, "lua_pushnumber");
if ( !lua_pushnumber )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushnumber");
lua_pushstring = (__int64)dlsym(v0, "lua_pushstring");
if ( !lua_pushstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushstring");
lua_pushvalue = (__int64)dlsym(v0, "lua_pushvalue");
if ( !lua_pushvalue )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushvalue");
lua_resume = (__int64)dlsym(v0, "lua_resume");
if ( !lua_resume )
fprintf(stderr, "liblua: %s: failed\n", "lua_resume");
lua_setfield = (__int64)dlsym(v0, "lua_setfield");
if ( !lua_setfield )
fprintf(stderr, "liblua: %s: failed\n", "lua_setfield");
lua_setglobal = (__int64)dlsym(v0, "lua_setglobal");
if ( !lua_setglobal )
fprintf(stderr, "liblua: %s: failed\n", "lua_setglobal");
lua_seti = (__int64)dlsym(v0, "lua_seti");
if ( !lua_seti )
fprintf(stderr, "liblua: %s: failed\n", "lua_seti");
lua_settop = (__int64)dlsym(v0, "lua_settop");
if ( !lua_settop )
fprintf(stderr, "liblua: %s: failed\n", "lua_settop");
lua_toboolean = (__int64)dlsym(v0, "lua_toboolean");
if ( !lua_toboolean )
fprintf(stderr, "liblua: %s: failed\n", "lua_toboolean");
lua_tointegerx = (__int64)dlsym(v0, "lua_tointegerx");
if ( !lua_tointegerx )
fprintf(stderr, "liblua: %s: failed\n", "lua_tointegerx");
lua_tolstring = (__int64)dlsym(v0, "lua_tolstring");
if ( !lua_tolstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_tolstring");
lua_tonumberx = (__int64)dlsym(v0, "lua_tonumberx");
if ( !lua_tonumberx )
fprintf(stderr, "liblua: %s: failed\n", "lua_tonumberx");
lua_type = (__int64)dlsym(v0, "lua_type");
if ( !lua_type )
fprintf(stderr, "liblua: %s: failed\n", "lua_type");
lua_typename = (__int64)dlsym(v0, "lua_typename");
if ( !lua_typename )
fprintf(stderr, "liblua: %s: failed\n", "lua_typename");
lua_version = (__int64)dlsym(v0, "lua_version");
if ( !lua_version )
fprintf(stderr, "liblua: %s: failed\n", "lua_version");
lua_xmove = (__int64)dlsym(v0, "lua_xmove");
if ( !lua_xmove )
fprintf(stderr, "liblua: %s: failed\n", "lua_xmove");
lua_yieldk = (__int64)dlsym(v0, "lua_yieldk");
if ( !lua_yieldk )
fprintf(stderr, "liblua: %s: failed\n", "lua_yieldk");
luaL_checkinteger = (__int64)dlsym(v0, "luaL_checkinteger");
if ( !luaL_checkinteger )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checkinteger");
luaL_checklstring = (__int64)dlsym(v0, "luaL_checklstring");
if ( !luaL_checklstring )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checklstring");
luaL_checkudata = (__int64)dlsym(v0, "luaL_checkudata");
if ( !luaL_checkudata )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checkudata");
luaL_len = (__int64)dlsym(v0, "luaL_len");
if ( !luaL_len )
fprintf(stderr, "liblua: %s: failed\n", "luaL_len");
luaL_loadbufferx = (__int64)dlsym(v0, "luaL_loadbufferx");
if ( !luaL_loadbufferx )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadbufferx");
luaL_loadfilex = (__int64)dlsym(v0, "luaL_loadfilex");
if ( !luaL_loadfilex )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadfilex");
luaL_loadstring = (__int64)dlsym(v0, "luaL_loadstring");
if ( !luaL_loadstring )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadstring");
luaL_newmetatable = (__int64)dlsym(v0, "luaL_newmetatable");
if ( !luaL_newmetatable )
fprintf(stderr, "liblua: %s: failed\n", "luaL_newmetatable");
luaL_newstate = (__int64)dlsym(v0, "luaL_newstate");
if ( !luaL_newstate )
fprintf(stderr, "liblua: %s: failed\n", "luaL_newstate");
luaL_openlibs = (__int64)dlsym(v0, "luaL_openlibs");
if ( !luaL_openlibs )
fprintf(stderr, "liblua: %s: failed\n", "luaL_openlibs");
luaL_ref = (__int64)dlsym(v0, "luaL_ref");
if ( !luaL_ref )
fprintf(stderr, "liblua: %s: failed\n", "luaL_ref");
luaL_setfuncs = (__int64)dlsym(v0, "luaL_setfuncs");
if ( !luaL_setfuncs )
fprintf(stderr, "liblua: %s: failed\n", "luaL_setfuncs");
luaL_setmetatable = (__int64)dlsym(v0, "luaL_setmetatable");
if ( !luaL_setmetatable )
fprintf(stderr, "liblua: %s: failed\n", "luaL_setmetatable");
luaL_unref = (__int64)dlsym(v0, "luaL_unref");
if ( !luaL_unref )
fprintf(stderr, "liblua: %s: failed\n", "luaL_unref");
return 0LL;
}

original_code:
int stublua_init(void)
{
    void *lib = ((void *)0);
    {
        static const char *possible_names[] = {
            "liblua5.3.so",
            "liblua5.3.so.0",
            "liblua5.3.so.0.0.0",
            0
        };
        unsigned i;
        for (i=0; possible_names[i]; i++) {
            lib = dlopen(possible_names[i], 0x00001);
            if (lib) {
                break;
            } else {
                ;
            }
        }
        if (lib == ((void *)0)) {
            fprintf(stderr, "liblua: failed to load Lua shared library\n");
            fprintf(stderr, "    HINT: you must install Lua library\n");
        }
    }
    lua_version = dlsym(lib, "lua_version"); if (lua_version == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_version");;
    lua_close = dlsym(lib, "lua_close"); if (lua_close == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_close");
    lua_getfield = dlsym(lib, "lua_getfield"); if (lua_getfield == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_getfield");
    lua_getglobal = dlsym(lib, "lua_getglobal"); if (lua_getglobal == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_getglobal");
    lua_geti = dlsym(lib, "lua_geti"); if (lua_geti == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_geti");
    lua_gettop = dlsym(lib, "lua_gettop"); if (lua_gettop == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_gettop");
    lua_isnumber = dlsym(lib, "lua_isnumber"); if (lua_isnumber == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isnumber");;
    lua_isstring = dlsym(lib, "lua_isstring"); if (lua_isstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isstring");;
    lua_iscfunction = dlsym(lib, "lua_iscfunction"); if (lua_iscfunction == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_iscfunction");;
    lua_isinteger = dlsym(lib, "lua_isinteger"); if (lua_isinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isinteger");;
    lua_isuserdata = dlsym(lib, "lua_isuserdata"); if (lua_isuserdata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isuserdata");;
    lua_newthread = dlsym(lib, "lua_newthread"); if (lua_newthread == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_newthread");
    lua_newuserdata = dlsym(lib, "lua_newuserdata"); if (lua_newuserdata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_newuserdata");
    lua_pcallk = dlsym(lib, "lua_pcallk"); if (lua_pcallk == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pcallk");
    lua_pushcclosure = dlsym(lib, "lua_pushcclosure"); if (lua_pushcclosure == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushcclosure");
    lua_pushinteger = dlsym(lib, "lua_pushinteger"); if (lua_pushinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushinteger");
    lua_pushlstring = dlsym(lib, "lua_pushlstring"); if (lua_pushlstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushlstring");
    lua_pushnumber = dlsym(lib, "lua_pushnumber"); if (lua_pushnumber == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushnumber");
    lua_pushstring = dlsym(lib, "lua_pushstring"); if (lua_pushstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushstring");
    lua_pushvalue = dlsym(lib, "lua_pushvalue"); if (lua_pushvalue == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushvalue");
    lua_resume = dlsym(lib, "lua_resume"); if (lua_resume == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_resume");
    lua_setfield = dlsym(lib, "lua_setfield"); if (lua_setfield == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_setfield");
    lua_setglobal = dlsym(lib, "lua_setglobal"); if (lua_setglobal == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_setglobal");
    lua_seti = dlsym(lib, "lua_seti"); if (lua_seti == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_seti");
    lua_settop = dlsym(lib, "lua_settop"); if (lua_settop == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_settop");
    lua_toboolean = dlsym(lib, "lua_toboolean"); if (lua_toboolean == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_toboolean");
    lua_tointegerx = dlsym(lib, "lua_tointegerx"); if (lua_tointegerx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tointegerx");
    lua_tolstring = dlsym(lib, "lua_tolstring"); if (lua_tolstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tolstring");
    lua_tonumberx = dlsym(lib, "lua_tonumberx"); if (lua_tonumberx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tonumberx");
    lua_type = dlsym(lib, "lua_type"); if (lua_type == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_type");
    lua_typename = dlsym(lib, "lua_typename"); if (lua_typename == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_typename");
    lua_version = dlsym(lib, "lua_version"); if (lua_version == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_version");
    lua_xmove = dlsym(lib, "lua_xmove"); if (lua_xmove == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_xmove");
    lua_yieldk = dlsym(lib, "lua_yieldk"); if (lua_yieldk == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_yieldk");
    luaL_checkinteger = dlsym(lib, "luaL_checkinteger"); if (luaL_checkinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checkinteger");
    luaL_checklstring = dlsym(lib, "luaL_checklstring"); if (luaL_checklstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checklstring");
    luaL_checkudata = dlsym(lib, "luaL_checkudata"); if (luaL_checkudata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checkudata");
    luaL_len = dlsym(lib, "luaL_len"); if (luaL_len == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_len");
    luaL_loadbufferx = dlsym(lib, "luaL_loadbufferx"); if (luaL_loadbufferx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadbufferx");
    luaL_loadfilex = dlsym(lib, "luaL_loadfilex"); if (luaL_loadfilex == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadfilex");
    luaL_loadstring = dlsym(lib, "luaL_loadstring"); if (luaL_loadstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadstring");
    luaL_newmetatable = dlsym(lib, "luaL_newmetatable"); if (luaL_newmetatable == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_newmetatable");
    luaL_newstate = dlsym(lib, "luaL_newstate"); if (luaL_newstate == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_newstate");
    luaL_openlibs = dlsym(lib, "luaL_openlibs"); if (luaL_openlibs == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_openlibs");
    luaL_ref = dlsym(lib, "luaL_ref"); if (luaL_ref == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_ref");
    luaL_setfuncs = dlsym(lib, "luaL_setfuncs"); if (luaL_setfuncs == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_setfuncs");
    luaL_setmetatable = dlsym(lib, "luaL_setmetatable"); if (luaL_setmetatable == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_setmetatable");
    luaL_unref = dlsym(lib, "luaL_unref"); if (luaL_unref == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_unref");
    return 0;
}

canonical_original_code:
int stublua_init()
{
    void *lib = ((void *)0);
    {
        static char *possible_names[] = {
            "liblua5.3.so",
            "liblua5.3.so.0",
            "liblua5.3.so.0.0.0",
            0
        };
        unsigned int i;
        for (i=0; possible_names[i]; i++) {
            lib = dlopen(possible_names[i], 0x00001);
            if (lib) {
                break;
            } else {
                ;
            }
        }
        if (lib == ((void *)0)) {
            fprintf(stderr, "liblua: failed to load Lua shared library\n");
            fprintf(stderr, "    HINT: you must install Lua library\n");
        }
    }
    lua_version = dlsym(lib, "lua_version"); if (lua_version == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_version");;
    lua_close = dlsym(lib, "lua_close"); if (lua_close == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_close");
    lua_getfield = dlsym(lib, "lua_getfield"); if (lua_getfield == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_getfield");
    lua_getglobal = dlsym(lib, "lua_getglobal"); if (lua_getglobal == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_getglobal");
    lua_geti = dlsym(lib, "lua_geti"); if (lua_geti == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_geti");
    lua_gettop = dlsym(lib, "lua_gettop"); if (lua_gettop == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_gettop");
    lua_isnumber = dlsym(lib, "lua_isnumber"); if (lua_isnumber == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isnumber");;
    lua_isstring = dlsym(lib, "lua_isstring"); if (lua_isstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isstring");;
    lua_iscfunction = dlsym(lib, "lua_iscfunction"); if (lua_iscfunction == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_iscfunction");;
    lua_isinteger = dlsym(lib, "lua_isinteger"); if (lua_isinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isinteger");;
    lua_isuserdata = dlsym(lib, "lua_isuserdata"); if (lua_isuserdata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isuserdata");;
    lua_newthread = dlsym(lib, "lua_newthread"); if (lua_newthread == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_newthread");
    lua_newuserdata = dlsym(lib, "lua_newuserdata"); if (lua_newuserdata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_newuserdata");
    lua_pcallk = dlsym(lib, "lua_pcallk"); if (lua_pcallk == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pcallk");
    lua_pushcclosure = dlsym(lib, "lua_pushcclosure"); if (lua_pushcclosure == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushcclosure");
    lua_pushinteger = dlsym(lib, "lua_pushinteger"); if (lua_pushinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushinteger");
    lua_pushlstring = dlsym(lib, "lua_pushlstring"); if (lua_pushlstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushlstring");
    lua_pushnumber = dlsym(lib, "lua_pushnumber"); if (lua_pushnumber == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushnumber");
    lua_pushstring = dlsym(lib, "lua_pushstring"); if (lua_pushstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushstring");
    lua_pushvalue = dlsym(lib, "lua_pushvalue"); if (lua_pushvalue == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushvalue");
    lua_resume = dlsym(lib, "lua_resume"); if (lua_resume == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_resume");
    lua_setfield = dlsym(lib, "lua_setfield"); if (lua_setfield == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_setfield");
    lua_setglobal = dlsym(lib, "lua_setglobal"); if (lua_setglobal == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_setglobal");
    lua_seti = dlsym(lib, "lua_seti"); if (lua_seti == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_seti");
    lua_settop = dlsym(lib, "lua_settop"); if (lua_settop == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_settop");
    lua_toboolean = dlsym(lib, "lua_toboolean"); if (lua_toboolean == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_toboolean");
    lua_tointegerx = dlsym(lib, "lua_tointegerx"); if (lua_tointegerx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tointegerx");
    lua_tolstring = dlsym(lib, "lua_tolstring"); if (lua_tolstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tolstring");
    lua_tonumberx = dlsym(lib, "lua_tonumberx"); if (lua_tonumberx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tonumberx");
    lua_type = dlsym(lib, "lua_type"); if (lua_type == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_type");
    lua_typename = dlsym(lib, "lua_typename"); if (lua_typename == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_typename");
    lua_version = dlsym(lib, "lua_version"); if (lua_version == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_version");
    lua_xmove = dlsym(lib, "lua_xmove"); if (lua_xmove == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_xmove");
    lua_yieldk = dlsym(lib, "lua_yieldk"); if (lua_yieldk == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_yieldk");
    luaL_checkinteger = dlsym(lib, "luaL_checkinteger"); if (luaL_checkinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checkinteger");
    luaL_checklstring = dlsym(lib, "luaL_checklstring"); if (luaL_checklstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checklstring");
    luaL_checkudata = dlsym(lib, "luaL_checkudata"); if (luaL_checkudata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checkudata");
    luaL_len = dlsym(lib, "luaL_len"); if (luaL_len == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_len");
    luaL_loadbufferx = dlsym(lib, "luaL_loadbufferx"); if (luaL_loadbufferx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadbufferx");
    luaL_loadfilex = dlsym(lib, "luaL_loadfilex"); if (luaL_loadfilex == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadfilex");
    luaL_loadstring = dlsym(lib, "luaL_loadstring"); if (luaL_loadstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadstring");
    luaL_newmetatable = dlsym(lib, "luaL_newmetatable"); if (luaL_newmetatable == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_newmetatable");
    luaL_newstate = dlsym(lib, "luaL_newstate"); if (luaL_newstate == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_newstate");
    luaL_openlibs = dlsym(lib, "luaL_openlibs"); if (luaL_openlibs == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_openlibs");
    luaL_ref = dlsym(lib, "luaL_ref"); if (luaL_ref == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_ref");
    luaL_setfuncs = dlsym(lib, "luaL_setfuncs"); if (luaL_setfuncs == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_setfuncs");
    luaL_setmetatable = dlsym(lib, "luaL_setmetatable"); if (luaL_setmetatable == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_setmetatable");
    luaL_unref = dlsym(lib, "luaL_unref"); if (luaL_unref == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_unref");
    return 0;
}

variable_types:
lib
void *

variable_types:
i
unsigned int


decompiled_code:
void __fastcall ntlmssp_decode(unsigned int *a1, _WORD *a2, size_t a3, __int64 a4)
{
_WORD *v6; // rbp
unsigned int v7; // eax
__int64 v8; // rdi
size_t v9; // r13
unsigned int v10; // edx
unsigned int v11; // er13
__int64 v12; // rdx
__int64 v13; // rbx
int v14; // er15
unsigned int v15; // er8
unsigned int v16; // er15
size_t v17; // rdx
unsigned __int64 v18; // rax
void *v19; // rdi
void *v20; // rax
int v21; // [rsp+0h] [rbp-88h]
int v22; // [rsp+0h] [rbp-88h]
int v23; // [rsp+0h] [rbp-88h]
int v24; // [rsp+0h] [rbp-88h]
int v25; // [rsp+0h] [rbp-88h]
int v26; // [rsp+0h] [rbp-88h]
unsigned int v27; // [rsp+Ch] [rbp-7Ch]
unsigned int v28; // [rsp+Ch] [rbp-7Ch]
unsigned int v29; // [rsp+Ch] [rbp-7Ch]
unsigned int v30; // [rsp+Ch] [rbp-7Ch]
unsigned int v31; // [rsp+Ch] [rbp-7Ch]
unsigned int v32; // [rsp+Ch] [rbp-7Ch]
char s[120]; // [rsp+10h] [rbp-78h] BYREF

v6 = a2;
v7 = *a1;
v8 = a1[1];
v9 = v7 - (unsigned int)v8;
if ( v9 > a3 )
v9 = a3;
if ( (_DWORD)v8 )
{
memcpy((void *)(*((_QWORD *)a1 + 1) + v8), a2, v9);
v10 = *a1;
v11 = a1[1] + v9;
a1[1] = v11;
if ( v11 < v10 )
return;
v6 = (_WORD *)*((_QWORD *)a1 + 1);
v9 = v10;
}
else if ( v9 < v7 )
{
v20 = (void *)MALLOC();
*((_QWORD *)a1 + 1) = v20;
memcpy(v20, a2, v9);
a1[1] = v9;
return;
}
if ( v9 > 0x37 && *(_QWORD *)v6 == 0x5053534D4C544ELL && *((_DWORD *)v6 + 2) == 2 )
{
if ( v6[6] )
{
v12 = *((unsigned int *)v6 + 4);
if ( (unsigned int)v12 + (unsigned __int16)v6[6] < v9 )
append_unicode_string_constprop_0(a4, (__int64)"domain", (__int64)v6 + v12, (unsigned __int16)v6[6]);
}
v13 = *((unsigned int *)v6 + 11);
v14 = (unsigned __int16)v6[20];
snprintf(
s,
0x40uLL,
" version=%u.%u.%u ntlm-ver=%u",
*((unsigned __int8 *)v6 + 48),
*((unsigned __int8 *)v6 + 49),
(unsigned __int16)v6[25],
*((unsigned __int8 *)v6 + 55));
banout_append(a4, 10LL, s, -1LL);
v15 = v14 + v13;
while ( 1 )
{
v16 = v13 + 4;
if ( (int)v13 + 4 >= v15 || v16 >= v9 )
break;
v17 = v15 - v16;
v18 = *((unsigned __int8 *)v6 + (unsigned int)(v13 + 2)) | (*((unsigned __int8 *)v6 + (unsigned int)(v13 + 3)) << 8);
if ( v17 > v9 - v16 )
v17 = v9 - v16;
if ( v17 <= v18 )
v18 = v17;
switch ( *((unsigned __int8 *)v6 + v13) | (*((unsigned __int8 *)v6 + (unsigned int)(v13 + 1)) << 8) )
{
case 0:
v13 = v15;
break;
case 1:
v27 = v15;
v21 = v18;
append_unicode_string_constprop_0(a4, (__int64)"name", (__int64)v6 + v16, v18);
LODWORD(v18) = v21;
v15 = v27;
goto LABEL_26;
case 2:
v32 = v15;
v26 = v18;
append_unicode_string_constprop_0(a4, (__int64)"domain", (__int64)v6 + v16, v18);
v15 = v32;
v13 = v16 + v26;
break;
case 3:
v31 = v15;
v25 = v18;
append_unicode_string_constprop_0(a4, (__int64)"name-dns", (__int64)v6 + v16, v18);
v15 = v31;
v13 = v16 + v25;
break;
case 4:
v30 = v15;
v24 = v18;
append_unicode_string_constprop_0(a4, (__int64)"domain-dns", (__int64)v6 + v16, v18);
v15 = v30;
v13 = v16 + v24;
break;
case 5:
v29 = v15;
v23 = v18;
append_unicode_string_constprop_0(a4, (__int64)"forest", (__int64)v6 + v16, v18);
v15 = v29;
v13 = v16 + v23;
break;
case 9:
v28 = v15;
v22 = v18;
append_unicode_string_constprop_0(a4, (__int64)"target", (__int64)v6 + v16, v18);
v15 = v28;
v13 = v16 + v22;
break;
default:
LABEL_26:
v13 = v16 + (unsigned int)v18;
break;
}
}
}
v19 = (void *)*((_QWORD *)a1 + 1);
if ( v19 )
{
free(v19);
*((_QWORD *)a1 + 1) = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int *a1, _WORD *a2, size_t a3, __int64 a4)
{
_WORD *v6; // rbp
unsigned int v7; // eax
__int64 v8; // rdi
size_t v9; // r13
unsigned int v10; // edx
unsigned int v11; // er13
__int64 v12; // rdx
__int64 v13; // rbx
int v14; // er15
unsigned int v15; // er8
unsigned int v16; // er15
size_t v17; // rdx
unsigned __int64 v18; // rax
void *v19; // rdi
void *v20; // rax
int v21; // [rsp+0h] [rbp-88h]
int v22; // [rsp+0h] [rbp-88h]
int v23; // [rsp+0h] [rbp-88h]
int v24; // [rsp+0h] [rbp-88h]
int v25; // [rsp+0h] [rbp-88h]
int v26; // [rsp+0h] [rbp-88h]
unsigned int v27; // [rsp+Ch] [rbp-7Ch]
unsigned int v28; // [rsp+Ch] [rbp-7Ch]
unsigned int v29; // [rsp+Ch] [rbp-7Ch]
unsigned int v30; // [rsp+Ch] [rbp-7Ch]
unsigned int v31; // [rsp+Ch] [rbp-7Ch]
unsigned int v32; // [rsp+Ch] [rbp-7Ch]
char s[120]; // [rsp+10h] [rbp-78h] BYREF

v6 = a2;
v7 = *a1;
v8 = a1[1];
v9 = v7 - (unsigned int)v8;
if ( v9 > a3 )
v9 = a3;
if ( (_DWORD)v8 )
{
memcpy((void *)(*((_QWORD *)a1 + 1) + v8), a2, v9);
v10 = *a1;
v11 = a1[1] + v9;
a1[1] = v11;
if ( v11 < v10 )
return;
v6 = (_WORD *)*((_QWORD *)a1 + 1);
v9 = v10;
}
else if ( v9 < v7 )
{
v20 = (void *)MALLOC();
*((_QWORD *)a1 + 1) = v20;
memcpy(v20, a2, v9);
a1[1] = v9;
return;
}
if ( v9 > 0x37 && *(_QWORD *)v6 == 0x5053534D4C544ELL && *((_DWORD *)v6 + 2) == 2 )
{
if ( v6[6] )
{
v12 = *((unsigned int *)v6 + 4);
if ( (unsigned int)v12 + (unsigned __int16)v6[6] < v9 )
func0(a4, (__int64)"domain", (__int64)v6 + v12, (unsigned __int16)v6[6]);
}
v13 = *((unsigned int *)v6 + 11);
v14 = (unsigned __int16)v6[20];
snprintf(
s,
0x40uLL,
" version=%u.%u.%u ntlm-ver=%u",
*((unsigned __int8 *)v6 + 48),
*((unsigned __int8 *)v6 + 49),
(unsigned __int16)v6[25],
*((unsigned __int8 *)v6 + 55));
banout_append(a4, 10LL, s, -1LL);
v15 = v14 + v13;
while ( 1 )
{
v16 = v13 + 4;
if ( (int)v13 + 4 >= v15 || v16 >= v9 )
break;
v17 = v15 - v16;
v18 = *((unsigned __int8 *)v6 + (unsigned int)(v13 + 2)) | (*((unsigned __int8 *)v6 + (unsigned int)(v13 + 3)) << 8);
if ( v17 > v9 - v16 )
v17 = v9 - v16;
if ( v17 <= v18 )
v18 = v17;
switch ( *((unsigned __int8 *)v6 + v13) | (*((unsigned __int8 *)v6 + (unsigned int)(v13 + 1)) << 8) )
{
case 0:
v13 = v15;
break;
case 1:
v27 = v15;
v21 = v18;
func0(a4, (__int64)"name", (__int64)v6 + v16, v18);
LODWORD(v18) = v21;
v15 = v27;
goto LABEL_26;
case 2:
v32 = v15;
v26 = v18;
func0(a4, (__int64)"domain", (__int64)v6 + v16, v18);
v15 = v32;
v13 = v16 + v26;
break;
case 3:
v31 = v15;
v25 = v18;
func0(a4, (__int64)"name-dns", (__int64)v6 + v16, v18);
v15 = v31;
v13 = v16 + v25;
break;
case 4:
v30 = v15;
v24 = v18;
func0(a4, (__int64)"domain-dns", (__int64)v6 + v16, v18);
v15 = v30;
v13 = v16 + v24;
break;
case 5:
v29 = v15;
v23 = v18;
func0(a4, (__int64)"forest", (__int64)v6 + v16, v18);
v15 = v29;
v13 = v16 + v23;
break;
case 9:
v28 = v15;
v22 = v18;
func0(a4, (__int64)"target", (__int64)v6 + v16, v18);
v15 = v28;
v13 = v16 + v22;
break;
default:
LABEL_26:
v13 = v16 + (unsigned int)v18;
break;
}
}
}
v19 = (void *)*((_QWORD *)a1 + 1);
if ( v19 )
{
free(v19);
*((_QWORD *)a1 + 1) = 0LL;
}
}

original_code:
void
ntlmssp_decode(struct NtlmsspDecode *x,
              const unsigned char *px, size_t length,
              struct BannerOutput *banout)
{
    unsigned message_type;
    unsigned name_offset;
    unsigned name_length;
    unsigned info_offset;
    unsigned info_length;
    unsigned i;
    if (length > x->length - x->offset)
        length = x->length - x->offset;
    if (x->offset == 0 && x->length > length) {
        x->buf = MALLOC(x->length);
        memcpy(x->buf, px, length);
        x->offset = (unsigned)length;
        return;
    } else if (x->offset) {
        memcpy(x->buf + x->offset, px, length);
        x->offset += (unsigned)length;
        if (x->offset < x->length)
            return;
        px = x->buf;
        length = x->length;
    }
    if (length < 56)
        goto end;
    if (memcmp("NTLMSSP", px, 8) != 0)
        goto end;
    message_type = px[8] | px[9]<<8 | px[10]<<16 | px[11]<<24;
    if (message_type != 2)
        goto end;
    name_length = px[12] | px[13]<<8;
    name_offset = px[16] | px[17]<<8 | px[18]<<16 | px[19]<<24;
    if (name_length && name_length + name_offset < length) {
        append_unicode_string(banout, PROTO_SMB, "domain", px+name_offset, name_length);
    }
    info_length = px[40] | px[41]<<8;
    info_offset = px[44] | px[45]<<8 | px[46]<<16 | px[47]<<24;
    {
        char buf[64];
        snprintf(buf, sizeof(buf), " version=%u.%u.%u ntlm-ver=%u",
                  px[48],
                  px[49],
                  px[50] | px[51]<<8,
                  px[55]
                  );
        banout_append(banout, PROTO_SMB, buf, ((size_t)~0));
    }
    for (i=info_offset; i+4<info_offset+info_length && i+4<length; ) {
        unsigned type = px[i] | px[i+1]<<8;
        size_t len = px[i+2] | px[i+3]<<8;
        i += 4;
        if (len > info_offset + info_length - i)
            len = info_offset + info_length - i;
        if (len > length - i)
            len = length - i;
        switch (type) {
            case 0x00:
                i = info_offset + info_length;
                continue;
            case 1:
                append_unicode_string(banout, PROTO_SMB, "name", px+i, len);
                break;
            case 2:
                append_unicode_string(banout, PROTO_SMB, "domain", px+i, len);
                break;
            case 3:
                append_unicode_string(banout, PROTO_SMB, "name-dns", px+i, len);
                break;
            case 4:
                append_unicode_string(banout, PROTO_SMB, "domain-dns", px+i, len);
                break;
            case 5:
                append_unicode_string(banout, PROTO_SMB, "forest", px+i, len);
                break;
            case 6:
                break;
            case 7:
                break;
            case 8:
                break;
            case 9:
                append_unicode_string(banout, PROTO_SMB, "target", px+i, len);
                break;
            case 10:
                break;
            default:
                break;
        }
        i += (unsigned)len;
    }
end:
    if (x->buf) {
        free(x->buf);
        x->buf = 0;
    }
}

canonical_original_code:
void ntlmssp_decode(struct NtlmsspDecode *x, unsigned char *px, unsigned long length, struct BannerOutput *banout)
{
    unsigned int message_type;
    unsigned int name_offset;
    unsigned int name_length;
    unsigned int info_offset;
    unsigned int info_length;
    unsigned int i;
    if (length > x->length - x->offset)
        length = x->length - x->offset;
    if (x->offset == 0 && x->length > length) {
        x->buf = MALLOC(x->length);
        memcpy(x->buf, px, length);
        x->offset = (unsigned int)length;
        return;
    } else if (x->offset) {
        memcpy(x->buf + x->offset, px, length);
        x->offset += (unsigned int)length;
        if (x->offset < x->length)
            return;
        px = x->buf;
        length = x->length;
    }
    if (length < 56)
        goto end;
    if (memcmp("NTLMSSP", px, 8) != 0)
        goto end;
    message_type = px[8] | px[9]<<8 | px[10]<<16 | px[11]<<24;
    if (message_type != 2)
        goto end;
    name_length = px[12] | px[13]<<8;
    name_offset = px[16] | px[17]<<8 | px[18]<<16 | px[19]<<24;
    if (name_length && name_length + name_offset < length) {
        append_unicode_string(banout, PROTO_SMB, "domain", px+name_offset, name_length);
    }
    info_length = px[40] | px[41]<<8;
    info_offset = px[44] | px[45]<<8 | px[46]<<16 | px[47]<<24;
    {
        char buf[64];
        snprintf(buf, sizeof(buf), " version=%u.%u.%u ntlm-ver=%u",
                  px[48],
                  px[49],
                  px[50] | px[51]<<8,
                  px[55]
                  );
        banout_append(banout, PROTO_SMB, buf, ((unsigned long)~0));
    }
    for (i=info_offset; i+4<info_offset+info_length && i+4<length; ) {
        unsigned int type = px[i] | px[i+1]<<8;
        unsigned long len = px[i+2] | px[i+3]<<8;
        i += 4;
        if (len > info_offset + info_length - i)
            len = info_offset + info_length - i;
        if (len > length - i)
            len = length - i;
        switch (type) {
            case 0x00:
                i = info_offset + info_length;
                continue;
            case 1:
                append_unicode_string(banout, PROTO_SMB, "name", px+i, len);
                break;
            case 2:
                append_unicode_string(banout, PROTO_SMB, "domain", px+i, len);
                break;
            case 3:
                append_unicode_string(banout, PROTO_SMB, "name-dns", px+i, len);
                break;
            case 4:
                append_unicode_string(banout, PROTO_SMB, "domain-dns", px+i, len);
                break;
            case 5:
                append_unicode_string(banout, PROTO_SMB, "forest", px+i, len);
                break;
            case 6:
                break;
            case 7:
                break;
            case 8:
                break;
            case 9:
                append_unicode_string(banout, PROTO_SMB, "target", px+i, len);
                break;
            case 10:
                break;
            default:
                break;
        }
        i += (unsigned int)len;
    }
end:
    if (x->buf) {
        free(x->buf);
        x->buf = 0;
    }
}

variable_types: struct NtlmsspDecode { unsigned int length; unsigned int offset; unsigned char *buf; } *

variable_types:
px
unsigned char *

variable_types:
length
unsigned long

variable_types:
buf
char [64]

variable_types:
type
unsigned int

variable_types:
len
unsigned long

user_defined_types: struct BannerOutput { struct BannerOutput *next; unsigned int protocol; unsigned int length; unsigned int max_length; unsigned char banner[200]; }


decompiled_code:
void __fastcall ntlmssp_cleanup(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)(a1 + 8);
if ( v2 )
{
free(v2);
*(_QWORD *)(a1 + 8) = 0LL;
}
}

original_code:
void
ntlmssp_cleanup(struct NtlmsspDecode *x)
{
    if (x->buf) {
        free(x->buf);
        x->buf = 0;
    }
}

user_defined_types: struct NtlmsspDecode { unsigned int length; unsigned int offset; unsigned char *buf; }


decompiled_code:
__int64 __fastcall ntlmssp_decode_init(_OWORD *a1, unsigned __int64 a2)
{
__int64 result; // rax

result = 0x10000LL;
if ( a2 > 0x10000 )
LODWORD(a2) = 0x10000;
*a1 = 0LL;
*(_DWORD *)a1 = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_OWORD *a1, unsigned __int64 a2)
{
__int64 result; // rax

result = 0x10000LL;
if ( a2 > 0x10000 )
LODWORD(a2) = 0x10000;
*a1 = 0LL;
*(_DWORD *)a1 = a2;
return result;
}

original_code:
void
ntlmssp_decode_init(struct NtlmsspDecode *x, size_t length)
{
    memset(x, 0, sizeof(*x));
    if (length > 65536)
        length = 65536;
    x->length = (unsigned)length;
    x->offset = 0;
    x->buf = ((void *)0);
}

canonical_original_code:
void ntlmssp_decode_init(struct NtlmsspDecode *x, unsigned long length)
{
    memset(x, 0, sizeof(*x));
    if (length > 65536)
        length = 65536;
    x->length = (unsigned int)length;
    x->offset = 0;
    x->buf = ((void *)0);
}


decompiled_code:
__int64 __fastcall dns_name_skip_validate(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // er10
unsigned int v6; // eax
unsigned int v9; // er11
unsigned int i; // esi
__int16 v11; // cx
__int64 v12; // rdx

v5 = a2;
v6 = a2;
v9 = a3 + 1;
for ( i = 0; ; i = 0 )
{
while ( 1 )
{
if ( a3 <= v6 )
return v9;
v11 = *(unsigned __int8 *)(a1 + v6);
if ( (*(_BYTE *)(a1 + v6) & 0xC0) == 0 )
break;
if ( (*(_BYTE *)(a1 + v6) & 0xC0) == 0xC0 )
{
v12 = v6 + 1;
if ( (unsigned int)v12 < a3 )
{
++i;
v6 = (v11 << 8) & 0x3F00 | *(unsigned __int8 *)(a1 + v12);
if ( i <= 4 )
continue;
}
}
return v9;
}
if ( !(_BYTE)v11 )
break;
a4 += (unsigned __int8)v11 + 1;
v6 += (unsigned __int8)v11 + 1;
if ( a4 > 0xFE )
return v9;
}
return v5 + 2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // er10
unsigned int v6; // eax
unsigned int v9; // er11
unsigned int i; // esi
__int16 v11; // cx
__int64 v12; // rdx

v5 = a2;
v6 = a2;
v9 = a3 + 1;
for ( i = 0; ; i = 0 )
{
while ( 1 )
{
if ( a3 <= v6 )
return v9;
v11 = *(unsigned __int8 *)(a1 + v6);
if ( (*(_BYTE *)(a1 + v6) & 0xC0) == 0 )
break;
if ( (*(_BYTE *)(a1 + v6) & 0xC0) == 0xC0 )
{
v12 = v6 + 1;
if ( (unsigned int)v12 < a3 )
{
++i;
v6 = (v11 << 8) & 0x3F00 | *(unsigned __int8 *)(a1 + v12);
if ( i <= 4 )
continue;
}
}
return v9;
}
if ( !(_BYTE)v11 )
break;
a4 += (unsigned __int8)v11 + 1;
v6 += (unsigned __int8)v11 + 1;
if ( a4 > 0xFE )
return v9;
}
return v5 + 2;
}

original_code:
static unsigned
dns_name_skip_validate(const unsigned char *px, unsigned offset, unsigned length, unsigned name_length)
{
    unsigned ERROR = length + 1;
    unsigned result = offset + 2;
    unsigned recursion = 0;
    for (;;) {
        unsigned len;
        if (name_length >= 255)
            return ERROR;
        if (offset >= length)
            return ERROR;
        len = px[offset];
        if (len & 0xC0) {
            if ((len & 0xC0) != 0xC0)
                return ERROR;
            if (offset + 1 >= length)
                return ERROR;
            offset = (px[offset]&0x3F)<<8 | px[offset+1];
            if (++recursion > 4)
                return ERROR;
        } else {
            recursion = 0;
            if (len == 0) {
                return result;
            }
            name_length += len + 1;
            offset += len + 1;
        }
    }
}

canonical_original_code:
static unsigned int dns_name_skip_validate(unsigned char *px, unsigned int offset, unsigned int length, unsigned int name_length)
{
    unsigned int ERROR = length + 1;
    unsigned int result = offset + 2;
    unsigned int recursion = 0;
    for (;;) {
        unsigned int len;
        if (name_length >= 255)
            return ERROR;
        if (offset >= length)
            return ERROR;
        len = px[offset];
        if (len & 0xC0) {
            if ((len & 0xC0) != 0xC0)
                return ERROR;
            if (offset + 1 >= length)
                return ERROR;
            offset = (px[offset]&0x3F)<<8 | px[offset+1];
            if (++recursion > 4)
                return ERROR;
        } else {
            recursion = 0;
            if (len == 0) {
                return result;
            }
            name_length += len + 1;
            offset += len + 1;
        }
    }
}

variable_types:
offset
unsigned int

variable_types:
length
unsigned int

variable_types:
ERROR
unsigned int

variable_types:
result
unsigned int

variable_types:
recursion
unsigned int

variable_types:
len
unsigned int

return_type: unsigned int


decompiled_code:
void __fastcall dns_extract_name(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4)
{
unsigned int v4; // er8
__int64 v7; // rdx
_BYTE *v8; // rsi
__int16 v9; // ax
__int64 v10; // rdx
_QWORD *v11; // rcx

*(_DWORD *)(a4 + 8) = 0;
if ( a2 < a3 )
{
v4 = a2;
do
{
while ( 1 )
{
v8 = (_BYTE *)(a1 + v4);
v9 = (unsigned __int8)*v8;
if ( (*v8 & 0xC0) == 0 )
break;
if ( (*v8 & 0xC0) == 0xC0 )
{
v7 = v4 + 1;
if ( (unsigned int)v7 < a3 )
{
v4 = (v9 << 8) & 0x3F00 | *(unsigned __int8 *)(a1 + v7);
if ( v4 < a3 )
continue;
}
}
return;
}
if ( !(_BYTE)v9 )
break;
v10 = (unsigned int)(unsigned __int8)v9 + 1;
v11 = (_QWORD *)(*(_QWORD *)a4 + *(unsigned int *)(a4 + 8));
if ( (unsigned int)v10 >= 8 )
{
*v11 = *(_QWORD *)v8;
*(_QWORD *)((char *)v11 + (unsigned int)v10 - 8) = *(_QWORD *)&v8[(unsigned int)v10 - 8];
qmemcpy(
(void *)((unsigned __int64)(v11 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v8 - ((char *)v11 - ((unsigned __int64)(v11 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v10 + (_DWORD)v11 - (((_DWORD)v11 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (((_BYTE)v9 + 1) & 4) != 0 )
{
*(_DWORD *)v11 = *(_DWORD *)v8;
*(_DWORD *)((char *)v11 + (unsigned int)v10 - 4) = *(_DWORD *)&v8[(unsigned int)v10 - 4];
}
else if ( (unsigned __int8)v9 != -1 )
{
*(_BYTE *)v11 = v9;
if ( (((_BYTE)v9 + 1) & 2) != 0 )
*(_WORD *)((char *)v11 + v10 - 2) = *(_WORD *)&v8[v10 - 2];
}
v4 += (unsigned __int8)v9 + 1;
*(_DWORD *)(a4 + 8) = (unsigned __int8)(v9 + *(_DWORD *)(a4 + 8) + 1);
}
while ( v4 < a3 );
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4)
{
unsigned int v4; // er8
__int64 v7; // rdx
_BYTE *v8; // rsi
__int16 v9; // ax
__int64 v10; // rdx
_QWORD *v11; // rcx

*(_DWORD *)(a4 + 8) = 0;
if ( a2 < a3 )
{
v4 = a2;
do
{
while ( 1 )
{
v8 = (_BYTE *)(a1 + v4);
v9 = (unsigned __int8)*v8;
if ( (*v8 & 0xC0) == 0 )
break;
if ( (*v8 & 0xC0) == 0xC0 )
{
v7 = v4 + 1;
if ( (unsigned int)v7 < a3 )
{
v4 = (v9 << 8) & 0x3F00 | *(unsigned __int8 *)(a1 + v7);
if ( v4 < a3 )
continue;
}
}
return;
}
if ( !(_BYTE)v9 )
break;
v10 = (unsigned int)(unsigned __int8)v9 + 1;
v11 = (_QWORD *)(*(_QWORD *)a4 + *(unsigned int *)(a4 + 8));
if ( (unsigned int)v10 >= 8 )
{
*v11 = *(_QWORD *)v8;
*(_QWORD *)((char *)v11 + (unsigned int)v10 - 8) = *(_QWORD *)&v8[(unsigned int)v10 - 8];
qmemcpy(
(void *)((unsigned __int64)(v11 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v8 - ((char *)v11 - ((unsigned __int64)(v11 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v10 + (_DWORD)v11 - (((_DWORD)v11 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (((_BYTE)v9 + 1) & 4) != 0 )
{
*(_DWORD *)v11 = *(_DWORD *)v8;
*(_DWORD *)((char *)v11 + (unsigned int)v10 - 4) = *(_DWORD *)&v8[(unsigned int)v10 - 4];
}
else if ( (unsigned __int8)v9 != -1 )
{
*(_BYTE *)v11 = v9;
if ( (((_BYTE)v9 + 1) & 2) != 0 )
*(_WORD *)((char *)v11 + v10 - 2) = *(_WORD *)&v8[v10 - 2];
}
v4 += (unsigned __int8)v9 + 1;
*(_DWORD *)(a4 + 8) = (unsigned __int8)(v9 + *(_DWORD *)(a4 + 8) + 1);
}
while ( v4 < a3 );
}
}

original_code:
static void
dns_extract_name(const unsigned char px[], unsigned offset, unsigned max,
                 struct DomainPointer *name)
{
    name->length = 0;
    for (;;) {
        unsigned len;
        if (offset >= max)
            return;
        len = px[offset];
        if (len & 0xC0) {
            if ((len & 0xC0) != 0xC0)
                return;
            else if (offset + 1 >= max)
                return;
            else {
                offset = (px[offset]&0x3F)<<8 | px[offset+1];
            }
        } else {
            if (len == 0) {
                return;
            } else {
                memcpy((unsigned char*)name->name+name->length, px+offset, len+1);
                name->length = (unsigned char)(name->length + len + 1);
                offset += len + 1;
            }
        }
    }
}

canonical_original_code:
static void dns_extract_name(unsigned char px[], unsigned int offset, unsigned int max, struct DomainPointer *name)
{
    name->length = 0;
    for (;;) {
        unsigned int len;
        if (offset >= max)
            return;
        len = px[offset];
        if (len & 0xC0) {
            if ((len & 0xC0) != 0xC0)
                return;
            else if (offset + 1 >= max)
                return;
            else {
                offset = (px[offset]&0x3F)<<8 | px[offset+1];
            }
        } else {
            if (len == 0) {
                return;
            } else {
                memcpy((unsigned char *)name->name+name->length, px+offset, len+1);
                name->length = (unsigned char)(name->length + len + 1);
                offset += len + 1;
            }
        }
    }
}

variable_types:
px
unsigned char []

variable_types:
max
unsigned int

variable_types: struct DomainPointer { unsigned char *name; unsigned int length; } *


decompiled_code:
__int64 __fastcall dns_name_skip(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
unsigned __int8 v4; // cl
int v6; // ecx

v3 = 0;
while ( 1 )
{
if ( a3 <= a2 )
return a3 + 1;
v4 = *(_BYTE *)(a1 + a2);
if ( v4 >> 6 == 3 )
return dns_name_skip_validate(a1, a2, a3, v3);
if ( v4 >> 6 )
return a3 + 1;
if ( !v4 )
break;
v6 = (unsigned __int8)(v4 + 1);
v3 += v6;
a2 += v6;
if ( v3 > 0xFE )
return a3 + 1;
}
return a2 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
unsigned __int8 v4; // cl
int v6; // ecx

v3 = 0;
while ( 1 )
{
if ( a3 <= a2 )
return a3 + 1;
v4 = *(_BYTE *)(a1 + a2);
if ( v4 >> 6 == 3 )
return func0(a1, a2, a3, v3);
if ( v4 >> 6 )
return a3 + 1;
if ( !v4 )
break;
v6 = (unsigned __int8)(v4 + 1);
v3 += v6;
a2 += v6;
if ( v3 > 0xFE )
return a3 + 1;
}
return a2 + 1;
}

original_code:
unsigned
dns_name_skip(const unsigned char px[], unsigned offset, unsigned max)
{
    unsigned name_length = 0;
    for (;;) {
        if (name_length >= 255)
            return max + 1;
        if (offset >= max)
            return max + 1;
        switch (px[offset]>>6) {
        case 0:
            if (px[offset] == 0) {
                return offset+1;
            } else {
                name_length += px[offset] + 1;
                offset += px[offset] + 1;
                continue;
            }
            break;
        case 3:
            return dns_name_skip_validate(px, offset, max, name_length);
        case 2:
            return max + 1;
        case 1:
            return max + 1;
        }
    }
}

canonical_original_code:
unsigned int dns_name_skip(unsigned char px[], unsigned int offset, unsigned int max)
{
    unsigned int name_length = 0;
    for (;;) {
        if (name_length >= 255)
            return max + 1;
        if (offset >= max)
            return max + 1;
        switch (px[offset]>>6) {
        case 0:
            if (px[offset] == 0) {
                return offset+1;
            } else {
                name_length += px[offset] + 1;
                offset += px[offset] + 1;
                continue;
            }
            break;
        case 3:
            return dns_name_skip_validate(px, offset, max, name_length);
        case 2:
            return max + 1;
        case 1:
            return max + 1;
        }
    }
}


original_code:
void
proto_dns_parse(struct DNS_Incoming *dns, const unsigned char px[], unsigned offset, unsigned max)
{
    static const unsigned MAX_RRs = sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]);
    unsigned i;
    dns->is_valid = 0;
    dns->req = px;
    dns->req_length = max-offset;
    dns->edns0.payload_size = 512;
    if (max - offset < 12)
        return;
    dns->id = px[offset+0]<<8 | px[offset+1];
    dns->qr = (px[offset+2]>>7)&1;
    dns->aa = (px[offset+2]>>2)&1;
    dns->tc = (px[offset+2]>>1)&1;
    dns->rd = (px[offset+2]>>0)&1;
    dns->ra = (px[offset+3]>>7)&1;
    dns->z = (px[offset+3]>>4)&7;
    dns->opcode = (px[offset+2]>>3)&0xf;
    dns->rcode = (px[offset+3]>>0)&0xf;
    dns->qdcount = px[offset+4]<<8 | px[offset+5];
    dns->ancount = px[offset+6]<<8 | px[offset+7];
    dns->nscount = px[offset+8]<<8 | px[offset+9];
    dns->arcount = px[offset+10]<<8 | px[offset+11];
    dns->rr_count = 0;
    offset += 12;
    dns->is_valid = 1;
    dns->is_formerr = 1;
    for (i=0; i<dns->qdcount; i++) {
        unsigned xclass;
        unsigned xtype;
        if (dns->rr_count >= MAX_RRs)
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        offset = dns_name_skip(px, offset, max);
        offset += 4;
        if (offset > max)
            return;
        xclass = px[offset-2]<<8 | px[offset-1];
        if (xclass != 1 && xclass != 255 && xclass != 3)
            return;
        xtype = px[offset-4]<<8 | px[offset-3];
        dns->query_type = xtype;
    }
    for (i=0; i<dns->ancount + dns->nscount; i++) {
        unsigned rdlength;
        if (dns->rr_count >= sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]))
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        offset = dns_name_skip(px, offset, max);
        offset += 10;
        if (offset > max)
            return;
        rdlength = px[offset-2]<<8 | px[offset-1];
        offset += rdlength;
        if (offset > max)
            return;
    }
    for (i=0; i<dns->arcount; i++) {
        unsigned rdlength;
        if (dns->rr_count >= sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]))
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        if (offset + 11 <= max && px[offset] == 0 && px[offset+1] == 0 && px[offset+2] == 0x29) {
            dns->edns0.payload_size = px[offset+3]<<8 | px[offset+4];
            if (dns->edns0.payload_size < 512)
                return;
            dns->rcode |= px[offset+5]<<4;
            dns->edns0.version = px[offset+6];
            dns->is_edns0 = 1;
        }
        offset = dns_name_skip(px, offset, max);
        offset += 10;
        if (offset > max)
            return;
        rdlength = px[offset-2]<<8 | px[offset-1];
        offset += rdlength;
        if (offset > max)
            return;
    }
    dns->query_name.name = dns->query_name_buffer;
    dns_extract_name(px, dns->rr_offset[0], max, &dns->query_name);
    dns->is_formerr = 0;
    return;
}

canonical_original_code:
void proto_dns_parse(struct DNS_Incoming *dns, unsigned char px[], unsigned int offset, unsigned int max)
{
    static unsigned int MAX_RRs = sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]);
    unsigned int i;
    dns->is_valid = 0;
    dns->req = px;
    dns->req_length = max-offset;
    dns->edns0.payload_size = 512;
    if (max - offset < 12)
        return;
    dns->id = px[offset+0]<<8 | px[offset+1];
    dns->qr = (px[offset+2]>>7)&1;
    dns->aa = (px[offset+2]>>2)&1;
    dns->tc = (px[offset+2]>>1)&1;
    dns->rd = (px[offset+2]>>0)&1;
    dns->ra = (px[offset+3]>>7)&1;
    dns->z = (px[offset+3]>>4)&7;
    dns->opcode = (px[offset+2]>>3)&0xf;
    dns->rcode = (px[offset+3]>>0)&0xf;
    dns->qdcount = px[offset+4]<<8 | px[offset+5];
    dns->ancount = px[offset+6]<<8 | px[offset+7];
    dns->nscount = px[offset+8]<<8 | px[offset+9];
    dns->arcount = px[offset+10]<<8 | px[offset+11];
    dns->rr_count = 0;
    offset += 12;
    dns->is_valid = 1;
    dns->is_formerr = 1;
    for (i=0; i<dns->qdcount; i++) {
        unsigned int xclass;
        unsigned int xtype;
        if (dns->rr_count >= MAX_RRs)
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        offset = dns_name_skip(px, offset, max);
        offset += 4;
        if (offset > max)
            return;
        xclass = px[offset-2]<<8 | px[offset-1];
        if (xclass != 1 && xclass != 255 && xclass != 3)
            return;
        xtype = px[offset-4]<<8 | px[offset-3];
        dns->query_type = xtype;
    }
    for (i=0; i<dns->ancount + dns->nscount; i++) {
        unsigned int rdlength;
        if (dns->rr_count >= sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]))
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        offset = dns_name_skip(px, offset, max);
        offset += 10;
        if (offset > max)
            return;
        rdlength = px[offset-2]<<8 | px[offset-1];
        offset += rdlength;
        if (offset > max)
            return;
    }
    for (i=0; i<dns->arcount; i++) {
        unsigned int rdlength;
        if (dns->rr_count >= sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]))
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        if (offset + 11 <= max && px[offset] == 0 && px[offset+1] == 0 && px[offset+2] == 0x29) {
            dns->edns0.payload_size = px[offset+3]<<8 | px[offset+4];
            if (dns->edns0.payload_size < 512)
                return;
            dns->rcode |= px[offset+5]<<4;
            dns->edns0.version = px[offset+6];
            dns->is_edns0 = 1;
        }
        offset = dns_name_skip(px, offset, max);
        offset += 10;
        if (offset > max)
            return;
        rdlength = px[offset-2]<<8 | px[offset-1];
        offset += rdlength;
        if (offset > max)
            return;
    }
    dns->query_name.name = dns->query_name_buffer;
    dns_extract_name(px, dns->rr_offset[0], max, &dns->query_name);
    dns->is_formerr = 0;
    return;
}

variable_types: struct DNS_Incoming { unsigned int id; unsigned int is_valid; unsigned int is_formerr; unsigned int is_edns0; unsigned int qr; unsigned int aa; unsigned int tc; unsigned int rd; unsigned int ra; unsigned int z; unsigned int opcode; unsigned int rcode; unsigned int qdcount; unsigned int ancount; unsigned int nscount; unsigned int arcount; struct { unsigned int payload_size; unsigned int version; unsigned int z; } edns0; unsigned char *req; unsigned int req_length; struct DomainPointer { unsigned char *name; unsigned int length; } query_name; unsigned int query_type; unsigned char query_name_buffer[256]; unsigned int rr_count; unsigned short rr_offset[1024]; unsigned int edns0_offset; } *

variable_types:
xclass
unsigned int

variable_types:
xtype
unsigned int

variable_types:
rdlength
unsigned int

user_defined_types: struct DNS_Incoming { unsigned int id; unsigned int is_valid; unsigned int is_formerr; unsigned int is_edns0; unsigned int qr; unsigned int aa; unsigned int tc; unsigned int rd; unsigned int ra; unsigned int z; unsigned int opcode; unsigned int rcode; unsigned int qdcount; unsigned int ancount; unsigned int nscount; unsigned int arcount; struct { unsigned int payload_size; unsigned int version; unsigned int z; } edns0; unsigned char *req; unsigned int req_length; struct DomainPointer query_name; unsigned int query_type; unsigned char query_name_buffer[256]; unsigned int rr_count; unsigned short rr_offset[1024]; unsigned int edns0_offset; }


decompiled_code:
__int64 __fastcall dns_set_cookie(_WORD *a1, unsigned __int64 a2, unsigned __int16 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 2 )
{
*a1 = __ROL2__(a3, 8);
result = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_WORD *a1, unsigned __int64 a2, unsigned __int16 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 2 )
{
*a1 = __ROL2__(a3, 8);
result = a3;
}
return result;
}

original_code:
unsigned
dns_set_cookie(unsigned char *px, size_t length, uint64_t cookie)
{
    if (length > 2) {
        px[0] = (unsigned char)(cookie >> 8);
        px[1] = (unsigned char)(cookie >> 0);
        return cookie & 0xFFFF;
    } else
        return 0;
}

canonical_original_code:
unsigned int dns_set_cookie(unsigned char *px, unsigned long length, unsigned long cookie)
{
    if (length > 2) {
        px[0] = (unsigned char)(cookie >> 8);
        px[1] = (unsigned char)(cookie >> 0);
        return cookie & 0xFFFF;
    } else
        return 0;
}

variable_types:
px
unsigned char *

variable_types:
length
unsigned long

variable_types:
cookie
unsigned long


decompiled_code:
__int64 __fastcall throttler_start(__int64 a1, double a2)
{
__int64 v3; // rdi
__int64 v4; // rbx
__int64 v5; // rax
double v6; // xmm0_8

v3 = a1 + 8;
v4 = a1 + 32;
*(_QWORD *)(v3 + 4128) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 4144) >> 3));
*(double *)a1 = a2;
do
{
v5 = pixie_gettime();
v4 += 16LL;
*(_QWORD *)(v4 - 8) = 0LL;
*(_QWORD *)(v4 - 16) = v5;
}
while ( v4 != a1 + 4128 );
v6 = *(double *)a1;
*(_QWORD *)(a1 + 16) = LC0;
return LOG(1LL, "[+] starting throttler: rate = %0.2f-pps\n", v6);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, double a2)
{
__int64 v3; // rdi
__int64 v4; // rbx
__int64 v5; // rax
double v6; // xmm0_8

v3 = a1 + 8;
v4 = a1 + 32;
*(_QWORD *)(v3 + 4128) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 4144) >> 3));
*(double *)a1 = a2;
do
{
v5 = pixie_gettime();
v4 += 16LL;
*(_QWORD *)(v4 - 8) = 0LL;
*(_QWORD *)(v4 - 16) = v5;
}
while ( v4 != a1 + 4128 );
v6 = *(double *)a1;
*(_QWORD *)(a1 + 16) = LC0;
return LOG(1LL, "[+] starting throttler: rate = %0.2f-pps\n", v6);
}

original_code:
void
throttler_start(struct Throttler *throttler, double max_rate)
{
    unsigned i;
    memset(throttler, 0, sizeof(*throttler));
    throttler->max_rate = max_rate;
    for (i=0; i<sizeof(throttler->buckets)/sizeof(throttler->buckets[0]); i++) {
        throttler->buckets[i].timestamp = pixie_gettime();
        throttler->buckets[i].packet_count = 0;
    }
    throttler->batch_size = 1;
    LOG(1, "[+] starting throttler: rate = %0.2f-pps\n", throttler->max_rate);
}

canonical_original_code:
void throttler_start(struct Throttler *throttler, double max_rate)
{
    unsigned int i;
    memset(throttler, 0, sizeof(*throttler));
    throttler->max_rate = max_rate;
    for (i=0; i<sizeof(throttler->buckets)/sizeof(throttler->buckets[0]); i++) {
        throttler->buckets[i].timestamp = pixie_gettime();
        throttler->buckets[i].packet_count = 0;
    }
    throttler->batch_size = 1;
    LOG(1, "[+] starting throttler: rate = %0.2f-pps\n", throttler->max_rate);
}

variable_types: struct Throttler { double max_rate; double current_rate; double batch_size; unsigned int index; struct { unsigned long timestamp; unsigned long packet_count; } buckets[256]; unsigned long test_timestamp; unsigned long test_packet_count; } *

variable_types:
i
unsigned int


original_code:
uint64_t
throttler_next_batch(struct Throttler *throttler, uint64_t packet_count)
{
    uint64_t timestamp;
    uint64_t index;
    uint64_t old_timestamp;
    uint64_t old_packet_count;
    double current_rate;
    double max_rate = throttler->max_rate;
again:
    timestamp = pixie_gettime();
    index = (throttler->index) & 0xFF;
    throttler->buckets[index].timestamp = timestamp;
    throttler->buckets[index].packet_count = packet_count;
    index = (++throttler->index) & 0xFF;
    old_timestamp = throttler->buckets[index].timestamp;
    old_packet_count = throttler->buckets[index].packet_count;
    if (timestamp - old_timestamp > 1000000) {
        throttler->batch_size = 1;
        goto again;
    }
    current_rate = 1.0*(packet_count - old_packet_count)/((timestamp - old_timestamp)/1000000.0);
    if (current_rate > max_rate) {
        double waittime;
        waittime = (current_rate - max_rate) / throttler->max_rate;
        waittime *= 0.1;
        if (waittime > 0.1)
            waittime = 0.1;
        throttler->batch_size *= 0.999;
        pixie_usleep((uint64_t)(waittime * 1000000.0));
        goto again;
    }
    throttler->batch_size *= 1.005;
    if (throttler->batch_size > 10000)
        throttler->batch_size = 10000;
    throttler->current_rate = current_rate;
    throttler->test_timestamp = timestamp;
    throttler->test_packet_count = packet_count;
    return (uint64_t)throttler->batch_size;
}

canonical_original_code:
unsigned long throttler_next_batch(struct Throttler *throttler, unsigned long packet_count)
{
    unsigned long timestamp;
    unsigned long index;
    unsigned long old_timestamp;
    unsigned long old_packet_count;
    double current_rate;
    double max_rate = throttler->max_rate;
again:
    timestamp = pixie_gettime();
    index = (throttler->index) & 0xFF;
    throttler->buckets[index].timestamp = timestamp;
    throttler->buckets[index].packet_count = packet_count;
    index = (++throttler->index) & 0xFF;
    old_timestamp = throttler->buckets[index].timestamp;
    old_packet_count = throttler->buckets[index].packet_count;
    if (timestamp - old_timestamp > 1000000) {
        throttler->batch_size = 1;
        goto again;
    }
    current_rate = 1.0*(packet_count - old_packet_count)/((timestamp - old_timestamp)/1000000.0);
    if (current_rate > max_rate) {
        double waittime;
        waittime = (current_rate - max_rate) / throttler->max_rate;
        waittime *= 0.1;
        if (waittime > 0.1)
            waittime = 0.1;
        throttler->batch_size *= 0.999;
        pixie_usleep((unsigned long)(waittime * 1000000.0));
        goto again;
    }
    throttler->batch_size *= 1.005;
    if (throttler->batch_size > 10000)
        throttler->batch_size = 10000;
    throttler->current_rate = current_rate;
    throttler->test_timestamp = timestamp;
    throttler->test_packet_count = packet_count;
    return (unsigned long)throttler->batch_size;
}

variable_types:
timestamp
unsigned long

variable_types:
index
unsigned long

variable_types: waittime double

return_type: unsigned long

user_defined_types: struct Throttler { double max_rate; double current_rate; double batch_size; unsigned int index; struct { unsigned long timestamp; unsigned long packet_count; } buckets[256]; unsigned long test_timestamp; unsigned long test_packet_count; }


original_code:
uint64_t
syn_cookie_ipv4( unsigned ip_them, unsigned port_them,
            unsigned ip_me, unsigned port_me,
            uint64_t entropy)
{
    unsigned data[4];
    uint64_t x[2];
    x[0] = entropy;
    x[1] = entropy;
    data[0] = ip_them;
    data[1] = port_them;
    data[2] = ip_me;
    data[3] = port_me;
    return siphash24(data, sizeof(data), x);
}

canonical_original_code:
unsigned long syn_cookie_ipv4(unsigned int ip_them, unsigned int port_them, unsigned int ip_me, unsigned int port_me, unsigned long entropy)
{
    unsigned int data[4];
    unsigned long x[2];
    x[0] = entropy;
    x[1] = entropy;
    data[0] = ip_them;
    data[1] = port_them;
    data[2] = ip_me;
    data[3] = port_me;
    return siphash24(data, sizeof(data), x);
}

variable_types:
entropy
unsigned long

variable_types:
data
unsigned int [4]

variable_types:
x
unsigned long [2]


original_code:
uint64_t
syn_cookie_ipv6( ipv6address ip_them, unsigned port_them,
            ipv6address ip_me, unsigned port_me,
            uint64_t entropy)
{
    uint64_t data[5];
    uint64_t x[2];
    x[0] = entropy;
    x[1] = entropy;
    data[0] = ip_them.hi;
    data[1] = ip_them.lo;
    data[2] = ip_me.hi;
    data[3] = ip_me.lo;
    data[4] = port_them<<16ULL | port_me;
    return siphash24(data, sizeof(data), x);
}

canonical_original_code:
unsigned long syn_cookie_ipv6(struct ipv6address ip_them, unsigned int port_them, struct ipv6address ip_me, unsigned int port_me, unsigned long entropy)
{
    unsigned long data[5];
    unsigned long x[2];
    x[0] = entropy;
    x[1] = entropy;
    data[0] = ip_them.hi;
    data[1] = ip_them.lo;
    data[2] = ip_me.hi;
    data[3] = ip_me.lo;
    data[4] = port_them<<16ULL | port_me;
    return siphash24(data, sizeof(data), x);
}

variable_types: struct ipv6address { unsigned long hi; unsigned long lo; }

variable_types:
data
unsigned long [5]


decompiled_code:
__int64 __fastcall syn_cookie(int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, char a9, __int64 a10, __int64 a11)
{
if ( a9 == 4 )
return syn_cookie_ipv4(a7, a1, a10, a2, a3);
if ( a9 != 6 )
_assert_fail("!\"unknown ip version\"", "src/syn-cookie.c", 0x80u, "syn_cookie");
return syn_cookie_ipv6(a7, a8, a1, a10, a11, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, char a9, __int64 a10, __int64 a11)
{
if ( a9 == 4 )
return func1(a7, a1, a10, a2, a3);
if ( a9 != 6 )
_assert_fail("!\"unknown ip version\"", "src/syn-cookie.c", 0x80u, "syn_cookie");
return func2(a7, a8, a1, a10, a11, a2, a3);
}

original_code:
uint64_t
syn_cookie( ipaddress ip_them, unsigned port_them,
            ipaddress ip_me, unsigned port_me,
            uint64_t entropy)
{
    switch (ip_them.version) {
    case 4:
        return syn_cookie_ipv4(ip_them.ipv4, port_them, ip_me.ipv4, port_me, entropy);
    case 6:
        return syn_cookie_ipv6(ip_them.ipv6, port_them, ip_me.ipv6, port_me, entropy);
    default:
        ((void) sizeof ((!"unknown ip version") ? 1 : 0), __extension__ ({ if (!"unknown ip version") ; else __assert_fail ("!\"unknown ip version\"", "src/syn-cookie.c", 128, __extension__ __PRETTY_FUNCTION__); }));
        return 0;
    }
}

canonical_original_code:
unsigned long syn_cookie(struct ipaddress ip_them, unsigned int port_them, struct ipaddress ip_me, unsigned int port_me, unsigned long entropy)
{
    switch (ip_them.version) {
    case 4:
        return syn_cookie_ipv4(ip_them.ipv4, port_them, ip_me.ipv4, port_me, entropy);
    case 6:
        return syn_cookie_ipv6(ip_them.ipv6, port_them, ip_me.ipv6, port_me, entropy);
    default:
        ((void) sizeof ((!"unknown ip version") ? 1 : 0), __extension__ ({ if (!"unknown ip version") ; else __assert_fail ("!\"unknown ip version\"", "src/syn-cookie.c", 128, __extension__ __PRETTY_FUNCTION__); }));
        return 0;
    }
}

variable_types: struct ipaddress { union { unsigned int ipv4; struct ipv6address { unsigned long hi; unsigned long lo; } ipv6; }; unsigned char version; }

user_defined_types: struct ipaddress { union { unsigned int ipv4; struct ipv6address ipv6; }; unsigned char version; }


decompiled_code:
__int64 __fastcall crc_calc(char *a1, int a2)
{
__int64 v2; // rcx
unsigned int v3; // eax
char v4; // dl

if ( !a2 )
return 0LL;
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = -1;
do
{
v4 = *a1++;
v3 = crc32_table[(unsigned __int8)(v3 ^ v4)] ^ (v3 >> 8);
}
while ( (char *)v2 != a1 );
return ~v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2)
{
__int64 v2; // rcx
unsigned int v3; // eax
char v4; // dl

if ( !a2 )
return 0LL;
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = -1;
do
{
v4 = *a1++;
v3 = crc32_table[(unsigned __int8)(v3 ^ v4)] ^ (v3 >> 8);
}
while ( (char *)v2 != a1 );
return ~v3;
}

original_code:
static unsigned
crc_calc(const unsigned char *px, unsigned length)
{
    unsigned i;
    unsigned crc;
    crc = (unsigned)~0;
    for (i = 0; i < length; i++) {
        crc = crc32_table[(crc ^ px[i]) & 0xff] ^ (crc >> 8);
    }
    crc = ~crc;
    return crc;
}

canonical_original_code:
static unsigned int crc_calc(unsigned char *px, unsigned int length)
{
    unsigned int i;
    unsigned int crc;
    crc = (unsigned int)~0;
    for (i = 0; i < length; i++) {
        crc = crc32_table[(crc ^ px[i]) & 0xff] ^ (crc >> 8);
    }
    crc = ~crc;
    return crc;
}

variable_types:
length
unsigned int

variable_types:
crc
unsigned int


zadecrypt

decompiled_code:
unsigned __int64 __fastcall zadecrypt(__int64 a1, unsigned __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 result; // rax
unsigned __int64 v6; // r9
unsigned __int64 v7; // rdx
int v8; // ecx
char v9; // er8^3

result = a2;
if ( a4 > result )
a4 = result;
v6 = a4;
if ( a4 )
{
v7 = 0LL;
v8 = 1718906930;
do
{
*(_WORD *)(a3 + v7) = v8 ^ *(_WORD *)(a1 + v7);
*(_BYTE *)(a3 + v7 + 2) = *(_BYTE *)(a1 + v7 + 2) ^ BYTE2(v8);
v9 = HIBYTE(v8);
v8 = __ROL4__(v8, 1);
*(_BYTE *)(a3 + v7 + 3) = *(_BYTE *)(a1 + v7 + 3) ^ v9;
v7 += 4LL;
}
while ( v7 < v6 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, unsigned __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 result; // rax
unsigned __int64 v6; // r9
unsigned __int64 v7; // rdx
int v8; // ecx
char v9; // er8^3

result = a2;
if ( a4 > result )
a4 = result;
v6 = a4;
if ( a4 )
{
v7 = 0LL;
v8 = 1718906930;
do
{
*(_WORD *)(a3 + v7) = v8 ^ *(_WORD *)(a1 + v7);
*(_BYTE *)(a3 + v7 + 2) = *(_BYTE *)(a1 + v7 + 2) ^ BYTE2(v8);
v9 = HIBYTE(v8);
v8 = __ROL4__(v8, 1);
*(_BYTE *)(a3 + v7 + 3) = *(_BYTE *)(a1 + v7 + 3) ^ v9;
v7 += 4LL;
}
while ( v7 < v6 );
}
return result;
}

original_code:
static unsigned
zadecrypt(const unsigned char *src, size_t src_len, unsigned char *dst, size_t dst_len)
{
    unsigned key;
    size_t i;
    key = 'f'<<24 | 't'<<16 | 'p'<<8 | '2'<<0;
    for (i=0; i<dst_len && i<src_len; i+=4) {
        dst[i+0] = src[i+0] ^ (unsigned char)(key>> 0);
        dst[i+1] = src[i+1] ^ (unsigned char)(key>> 8);
        dst[i+2] = src[i+2] ^ (unsigned char)(key>>16);
        dst[i+3] = src[i+3] ^ (unsigned char)(key>>24);
        key = key<<1 | key>>31;
    }
    return (unsigned)src_len;
}

canonical_original_code:
static unsigned int zadecrypt(unsigned char *src, unsigned long src_len, unsigned char *dst, unsigned long dst_len)
{
    unsigned int key;
    unsigned long i;
    key = 'f'<<24 | 't'<<16 | 'p'<<8 | '2'<<0;
    for (i=0; i<dst_len && i<src_len; i+=4) {
        dst[i+0] = src[i+0] ^ (unsigned char)(key>> 0);
        dst[i+1] = src[i+1] ^ (unsigned char)(key>> 8);
        dst[i+2] = src[i+2] ^ (unsigned char)(key>>16);
        dst[i+3] = src[i+3] ^ (unsigned char)(key>>24);
        key = key<<1 | key>>31;
    }
    return (unsigned int)src_len;
}

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

variable_types:
key
unsigned int

variable_types:
i
unsigned long


decompiled_code:
__int64 zeroaccess_selftest()
{
int v0; // er10
int v1; // er11
__int64 v3[16]; // [rsp+0h] [rbp-80h] BYREF

zadecrypt((__int64)&sample, 0x10uLL, (__int64)v3, 0x80uLL);
LODWORD(v3[0]) = 0;
crc_calc((char *)v3, 16);
generate_getL_constprop_0_isra_0();
return ((v3[0] ^ 0xAB8D9428CE6EBEDALL | v3[1] ^ 0x3CA9D6EC99D1C0C9LL) != 0) | (unsigned int)(v1 != v0);
}

original_code:
int
zeroaccess_selftest(void)
{
    unsigned char buf[128];
    unsigned old_crc;
    unsigned new_crc;
    zadecrypt(sample, sizeof(sample), buf, sizeof(buf));
    old_crc = buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24;
    memset(buf, 0, 4);
    new_crc = crc_calc(buf, sizeof(sample));
    generate_getL(buf, sizeof(buf), 0x7f570a0f);
    if (memcmp(buf, sample, 16) != 0)
        return 1;
    if (old_crc != new_crc)
        return 1;
    return 0;
}

canonical_original_code:
int zeroaccess_selftest()
{
    unsigned char buf[128];
    unsigned int old_crc;
    unsigned int new_crc;
    zadecrypt(sample, sizeof(sample), buf, sizeof(buf));
    old_crc = buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24;
    memset(buf, 0, 4);
    new_crc = crc_calc(buf, sizeof(sample));
    generate_getL(buf, sizeof(buf), 0x7f570a0f);
    if (memcmp(buf, sample, 16) != 0)
        return 1;
    if (old_crc != new_crc)
        return 1;
    return 0;
}

variable_types:
buf
unsigned char [128]


decompiled_code:
void *queue_create()
{
void *result; // rax

result = calloc(0x10uLL, 1uLL);
if ( !result )
{
fprintf(stderr, "%s: out of memory error\n", "smack");
exit(1);
}
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

result = calloc(0x10uLL, 1uLL);
if ( !result )
{
fprintf(stderr, "%s: out of memory error\n", "smack");
exit(1);
}
return result;
}

original_code:
struct Queue *
queue_create(void)
{
    struct Queue *queue;
    queue = (struct Queue *)malloc(sizeof(*queue));
    if (queue == ((void *)0)) {
        fprintf(stderr, "%s: out of memory error\n", "smack");
        exit(1);
    }
    memset(queue, 0, sizeof(*queue));
    return queue;
}

canonical_original_code:
struct Queue *queue_create()
{
    struct Queue *queue;
    queue = (struct Queue *)malloc(sizeof(*queue));
    if (queue == ((void *)0)) {
        fprintf(stderr, "%s: out of memory error\n", "smack");
        exit(1);
    }
    memset(queue, 0, sizeof(*queue));
    return queue;
}

variable_types: struct Queue { struct QueueElement { unsigned int m_data; struct QueueElement *m_next; } *m_head; struct QueueElement *m_tail; } *

user_defined_types: struct Queue { struct QueueElement *m_head; struct QueueElement *m_tail; }


dequeue

decompiled_code:
__int64 __fastcall dequeue(void **a1)
{
int *v1; // r8
unsigned int v2; // er12

v1 = (int *)*a1;
v2 = 0;
if ( *a1 )
{
v2 = *v1;
*a1 = (void *)*((_QWORD *)v1 + 1);
free(v1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1)
{
int *v1; // r8
unsigned int v2; // er12

v1 = (int *)*a1;
v2 = 0;
if ( *a1 )
{
v2 = *v1;
*a1 = (void *)*((_QWORD *)v1 + 1);
free(v1);
}
return v2;
}

original_code:
unsigned
dequeue(struct Queue *queue)
{
    if (queue->m_head == ((void *)0))
        return 0;
    else {
        struct QueueElement *element;
        unsigned result;
        element = queue->m_head;
        result = element->m_data;
        queue->m_head = element->m_next;
        free(element);
        return result;
    }
}

canonical_original_code:
unsigned int dequeue(struct Queue *queue)
{
    if (queue->m_head == ((void *)0))
        return 0;
    else {
        struct QueueElement *element;
        unsigned int result;
        element = queue->m_head;
        result = element->m_data;
        queue->m_head = element->m_next;
        free(element);
        return result;
    }
}

variable_types: struct QueueElement { unsigned int m_data; struct QueueElement *m_next; } *

variable_types:
result
unsigned int


decompiled_code:
_BOOL8 __fastcall queue_has_more_items(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
unsigned queue_has_more_items(struct Queue * queue)
{
  return queue->m_head != ((void *)0);
}

canonical_original_code:
unsigned int queue_has_more_items(struct Queue *queue)
{
  return queue->m_head != ((void *)0);
}

user_defined_types: struct QueueElement { unsigned int m_data; struct QueueElement *m_next; }


decompiled_code:
void __fastcall queue_destroy(void *ptr)
{
if ( ptr )
{
while ( queue_has_more_items(ptr) )
dequeue((void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
while ( func2(ptr) )
func1((void **)ptr);
free(ptr);
}
}

original_code:
void
queue_destroy(struct Queue * queue)
{
    if (queue == ((void *)0))
        return;
    while (queue_has_more_items(queue))
        dequeue(queue);
    free(queue);
}

canonical_original_code:
void queue_destroy(struct Queue *queue)
{
    if (queue == ((void *)0))
        return;
    while (queue_has_more_items(queue))
        dequeue(queue);
    free(queue);
}


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

result = 0LL;
if ( a1[1] < *a1 )
{
result = a1[(a1[1] & 0xFLL) + 2];
if ( result )
a1[(a1[1]++ & 0xFLL) + 2] = 0LL;
}
return result;
}

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

result = 0LL;
if ( a1[1] < *a1 )
{
result = a1[(a1[1] & 0xFLL) + 2];
if ( result )
a1[(a1[1]++ & 0xFLL) + 2] = 0LL;
}
return result;
}

original_code:
static Element
xring_remove(struct XRing *xring)
{
    volatile Element *ring = xring->ring;
    Element num;
    if (xring->tail >= xring->head)
        return 0;
    num = ring[xring->tail & (16 -1)];
    if (num) {
        ring[xring->tail & (16 -1)] = 0;
        xring->tail++;
        return num;
    } else {
        return 0;
    }
}

canonical_original_code:
static unsigned long xring_remove(struct XRing *xring)
{
    unsigned long *ring = xring->ring;
    unsigned long num;
    if (xring->tail >= xring->head)
        return 0;
    num = ring[xring->tail & (16 -1)];
    if (num) {
        ring[xring->tail & (16 -1)] = 0;
        xring->tail++;
        return num;
    } else {
        return 0;
    }
}

variable_types: struct XRing { unsigned long long head; unsigned long long tail; unsigned long ring[16]; } *

variable_types:
ring
unsigned long *

variable_types:
num
unsigned long


original_code:
static int
xring_add(struct XRing *xring, Element value)
{
    volatile Element *ring = xring->ring;
    Element num;
    if (value == 0) {
        return XringFailure;
    }
    if (xring->head >= xring->tail + 16) {
        return XringFailure;
    }
    num = xring->ring[xring->head & (16 -1)];
    if (num == 0) {
        ring[xring->head & (16 -1)] = value;
        xring->head++;
        return XringSuccess;
    }
    return XringFailure;
}

canonical_original_code:
static int xring_add(struct XRing *xring, unsigned long value)
{
    unsigned long *ring = xring->ring;
    unsigned long num;
    if (value == 0) {
        return XringFailure;
    }
    if (xring->head >= xring->tail + 16) {
        return XringFailure;
    }
    num = xring->ring[xring->head & (16 -1)];
    if (num == 0) {
        ring[xring->head & (16 -1)] = value;
        xring->head++;
        return XringSuccess;
    }
    return XringFailure;
}

variable_types:
value
unsigned long

user_defined_types: struct XRing { unsigned long long head; unsigned long long tail; unsigned long ring[16]; }


decompiled_code:
__int64 xring_selftest()
{
int v0; // ebx
__int64 v1; // rax
__int64 v3; // [rsp+0h] [rbp-B8h] BYREF

v0 = 1000;
do
{
v1 = run_test((__int64)&v3);
if ( v1 != 500500 )
{
printf("xring: selftest failed with %lu\n", v1);
return 1LL;
}
--v0;
}
while ( v0 );
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // ebx
__int64 v1; // rax
__int64 v3; // [rsp+0h] [rbp-B8h] BYREF

v0 = 1000;
do
{
v1 = func3((__int64)&v3);
if ( v1 != 500500 )
{
printf("xring: selftest failed with %lu\n", v1);
return 1LL;
}
--v0;
}
while ( v0 );
return 0LL;
}

original_code:
int
xring_selftest(void)
{
    unsigned i;
    for (i=0; i<1000; i++) {
        uint64_t result;
        struct Test test[1];
        result = run_test(test);
        if (result != 500500) {
            printf("xring: selftest failed with %" "l" "u" "\n", result);
            return 1;
        } else
            ;
    }
    return 0;
}

canonical_original_code:
int xring_selftest()
{
    unsigned int i;
    for (i=0; i<1000; i++) {
        unsigned long result;
        struct Test test[1];
        result = run_test(test);
        if (result != 500500) {
            printf("xring: selftest failed with %" "l" "u" "\n", result);
            return 1;
        } else
            ;
    }
    return 0;
}

variable_types:
i
unsigned int

variable_types:
result
unsigned long

variable_types: struct Test { struct XRing { unsigned long long head; unsigned long long tail; unsigned long ring[16]; } xring[1]; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; } [1]

user_defined_types: struct Test { struct XRing xring[1]; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; }


decompiled_code:
__int64 __fastcall test_consumer_thread(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

while ( !*((_DWORD *)a1 + 42) )
{
v1 = xring_remove(a1);
if ( v1 )
a1[20] += v1;
}
while ( 1 )
{
result = *a1;
if ( a1[1] >= (unsigned __int64)*a1 )
break;
v2 = xring_remove(a1);
if ( v2 )
a1[20] += v2;
}
*((_DWORD *)a1 + 38) = 1;
return result;
}

original_code:
static void
test_consumer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    struct XRing *xring = test->xring;
    while (!test->not_active) {
        Element e;
        e = xring_remove(xring);
        if (e == 0)
            ;
        else {
            test->total_count += e;
        }
    }
    while (xring->tail < xring->head) {
        Element e;
        e = xring_remove(xring);
        if (e == 0)
            ;
        else {
            test->total_count += e;
        }
    }
    test->consumer_done = 1;
}

canonical_original_code:
static void test_consumer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    struct XRing *xring = test->xring;
    while (!test->not_active) {
        unsigned long e;
        e = xring_remove(xring);
        if (e == 0)
            ;
        else {
            test->total_count += e;
        }
    }
    while (xring->tail < xring->head) {
        unsigned long e;
        e = xring_remove(xring);
        if (e == 0)
            ;
        else {
            test->total_count += e;
        }
    }
    test->consumer_done = 1;
}

variable_types:
v
void *

variable_types: struct Test { struct XRing { unsigned long long head; unsigned long long tail; unsigned long ring[16]; } xring[1]; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; } *

variable_types:
e
unsigned long


decompiled_code:
__int64 __fastcall run_test(__int64 a1)
{
memset((void *)a1, 0, 0xB0uLL);
pixie_begin_thread(test_producer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 144) )
pixie_usleep(10LL);
pixie_begin_thread(test_consumer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 148) )
pixie_usleep(10LL);
*(_DWORD *)(a1 + 168) = 1;
while ( !*(_DWORD *)(a1 + 152) )
pixie_usleep(10LL);
return *(_QWORD *)(a1 + 160);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
memset((void *)a1, 0, 0xB0uLL);
pixie_begin_thread(test_producer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 144) )
pixie_usleep(10LL);
pixie_begin_thread(test_consumer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 148) )
pixie_usleep(10LL);
*(_DWORD *)(a1 + 168) = 1;
while ( !*(_DWORD *)(a1 + 152) )
pixie_usleep(10LL);
return *(_QWORD *)(a1 + 160);
}

original_code:
static uint64_t
run_test(struct Test *test)
{
    unsigned i;
    const unsigned THREADS = 1;
    memset(test, 0, sizeof(*test));
    for (i=0; i<THREADS; i++) {
        pixie_begin_thread(test_producer_thread, 0, test);
    }
    while (test->producer_started < THREADS)
        pixie_usleep(10);
    pixie_begin_thread(test_consumer_thread, 0, test);
    while (test->producer_done < THREADS)
        pixie_usleep(10);
    test->not_active = 1;
    while (!test->consumer_done)
        pixie_usleep(10);
    return test->total_count;
}

canonical_original_code:
static unsigned long run_test(struct Test *test)
{
    unsigned int i;
    unsigned int THREADS = 1;
    memset(test, 0, sizeof(*test));
    for (i=0; i<THREADS; i++) {
        pixie_begin_thread(test_producer_thread, 0, test);
    }
    while (test->producer_started < THREADS)
        pixie_usleep(10);
    pixie_begin_thread(test_consumer_thread, 0, test);
    while (test->producer_done < THREADS)
        pixie_usleep(10);
    test->not_active = 1;
    while (!test->consumer_done)
        pixie_usleep(10);
    return test->total_count;
}

variable_types:
THREADS
unsigned int


decompiled_code:
__int64 __fastcall test_producer_thread(__int64 a1)
{
__int64 v1; // rcx
__int64 result; // rax

_InterlockedAdd((volatile signed __int32 *)(a1 + 144), 1u);
v1 = 1000LL;
do
{
do
result = xring_add((_QWORD *)a1, v1);
while ( (_DWORD)result == 1 );
--v1;
}
while ( v1 );
_InterlockedAdd((volatile signed __int32 *)(a1 + 148), 1u);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rcx
__int64 result; // rax

_InterlockedAdd((volatile signed __int32 *)(a1 + 144), 1u);
v1 = 1000LL;
do
{
do
result = func1((_QWORD *)a1, v1);
while ( (_DWORD)result == 1 );
--v1;
}
while ( v1 );
_InterlockedAdd((volatile signed __int32 *)(a1 + 148), 1u);
return result;
}

original_code:
static void
test_producer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    unsigned i = 1000;
    struct XRing *xring = test->xring;
    __sync_add_and_fetch((volatile int*)(&test->producer_started), (int)(1));;
    while (i) {
        while (xring_add(xring, i) == XringFailure)
            ;
        i--;
    }
    __sync_add_and_fetch((volatile int*)(&test->producer_done), (int)(1));;
}

canonical_original_code:
static void test_producer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    unsigned int i = 1000;
    struct XRing *xring = test->xring;
    __sync_add_and_fetch((int *)(&test->producer_started), (int)(1));;
    while (i) {
        while (xring_add(xring, i) == XringFailure)
            ;
        i--;
    }
    __sync_add_and_fetch((int *)(&test->producer_done), (int)(1));;
}