repo: gonzus/zc

decompiled_code:
_BOOL8 zc_zmq_is_valid()
{
_BOOL8 result; // rax

result = 0LL;
if ( stype_ >= 0 && nadd > 0 )
result = __PAIR64__(bind_, connect_) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 func0()
{
_BOOL8 result; // rax

result = 0LL;
if ( stype_ >= 0 && nadd > 0 )
result = __PAIR64__(bind_, connect_) != 0;
return result;
}

original_code:
static int zc_zmq_is_valid(void)
{
    if (stype_ < 0)
        return 0;
    if (nadd <= 0)
        return 0;
    if (!bind_ && !connect_)
        return 0;
    return 1;
}

canonical_original_code:
static int zc_zmq_is_valid()
{
    if (stype_ < 0)
        return 0;
    if (nadd <= 0)
        return 0;
    if (!bind_ && !connect_)
        return 0;
    return 1;
}


decompiled_code:
_BOOL8 zc_zmq_set_options()
{
char *v0; // rbx
int v1; // ebp
_BOOL4 v2; // er13
unsigned int v3; // er12
unsigned int v4; // eax
size_t v6; // r14
__int64 v7; // rax
unsigned int v8[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( nopt <= 0 )
return 0;
v0 = (char *)&sopt;
v1 = 0;
v2 = 0;
do
{
v3 = *((_DWORD *)v0 + 256);
switch ( v3 )
{
case 5u:
case 6u:
case 7u:
v6 = strlen(v0 + 1028);
v7 = zmq_setsockopt(sock_, v3, v0 + 1028, v6);
if ( verbose_ )
fprintf(
stderr,
"Socket option %s (%d) set to %d:[%s] (%d)\n",
v0,
*((unsigned int *)v0 + 256),
v6,
v0 + 1028,
v7);
if ( !v2 )
v2 = *((_DWORD *)v0 + 256) == 6;
break;
case 0xBu:
case 0xCu:
case 0x11u:
case 0x13u:
case 0x17u:
case 0x18u:
case 0x1Bu:
case 0x1Cu:
case 0x1Fu:
v8[0] = atoi(v0 + 1028);
v4 = zmq_setsockopt(sock_, v3, v8, 4LL);
if ( verbose_ )
fprintf(stderr, "Socket option %s (%d) set to %d (%d)\n", v0, *((unsigned int *)v0 + 256), v8[0], v4);
break;
default:
printf("Don't know how to handle socket option %s (%d)\n", v0, v3);
break;
}
++v1;
v0 += 2052;
}
while ( nopt > v1 );
return v2;
}

canonical_decompiled_code:
_BOOL8 func1()
{
char *v0; // rbx
int v1; // ebp
_BOOL4 v2; // er13
unsigned int v3; // er12
unsigned int v4; // eax
size_t v6; // r14
__int64 v7; // rax
unsigned int v8[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( nopt <= 0 )
return 0;
v0 = (char *)&sopt;
v1 = 0;
v2 = 0;
do
{
v3 = *((_DWORD *)v0 + 256);
switch ( v3 )
{
case 5u:
case 6u:
case 7u:
v6 = strlen(v0 + 1028);
v7 = zmq_setsockopt(sock_, v3, v0 + 1028, v6);
if ( verbose_ )
fprintf(
stderr,
"Socket option %s (%d) set to %d:[%s] (%d)\n",
v0,
*((unsigned int *)v0 + 256),
v6,
v0 + 1028,
v7);
if ( !v2 )
v2 = *((_DWORD *)v0 + 256) == 6;
break;
case 0xBu:
case 0xCu:
case 0x11u:
case 0x13u:
case 0x17u:
case 0x18u:
case 0x1Bu:
case 0x1Cu:
case 0x1Fu:
v8[0] = atoi(v0 + 1028);
v4 = zmq_setsockopt(sock_, v3, v8, 4LL);
if ( verbose_ )
fprintf(stderr, "Socket option %s (%d) set to %d (%d)\n", v0, *((unsigned int *)v0 + 256), v8[0], v4);
break;
default:
printf("Don't know how to handle socket option %s (%d)\n", v0, v3);
break;
}
++v1;
v0 += 2052;
}
while ( nopt > v1 );
return v2;
}

original_code:
static int zc_zmq_set_options(void)
{
    int subs = 0;
    int j;
    for (j = 0; j < nopt; ++j) {
        size_t olen = 0;
        int ival;
        int ret;
        switch (sopt[j].id) {
        case 6:
        case 7:
        case 5:
            olen = strlen(sopt[j].value);
            ret = zmq_setsockopt(sock_, sopt[j].id, sopt[j].value, olen);
            if (verbose_)
                fprintf(stderr, "Socket option %s (%d) set to %d:[%s] (%d)\n",
                        sopt[j].name, sopt[j].id,
                        olen, sopt[j].value, ret);
            if (! subs)
                subs = (sopt[j].id == 6);
            break;
        case 23:
        case 24:
        case 11:
        case 12:
        case 28:
        case 27:
        case 17:
        case 19:
        case 31:
            ival = atoi(sopt[j].value);
            olen = sizeof(ival);
            ret = zmq_setsockopt(sock_, sopt[j].id, &ival, olen);
            if (verbose_)
                fprintf(stderr, "Socket option %s (%d) set to %d (%d)\n",
                        sopt[j].name, sopt[j].id,
                        ival, ret);
            break;
        default:
            printf("Don't know how to handle socket option %s (%d)\n",
                   sopt[j].name, sopt[j].id);
            break;
        }
    }
    return subs;
}

canonical_original_code:
static int zc_zmq_set_options()
{
    int subs = 0;
    int j;
    for (j = 0; j < nopt; ++j) {
        unsigned long olen = 0;
        int ival;
        int ret;
        switch (sopt[j].id) {
        case 6:
        case 7:
        case 5:
            olen = strlen(sopt[j].value);
            ret = zmq_setsockopt(sock_, sopt[j].id, sopt[j].value, olen);
            if (verbose_)
                fprintf(stderr, "Socket option %s (%d) set to %d:[%s] (%d)\n",
                        sopt[j].name, sopt[j].id,
                        olen, sopt[j].value, ret);
            if (! subs)
                subs = (sopt[j].id == 6);
            break;
        case 23:
        case 24:
        case 11:
        case 12:
        case 28:
        case 27:
        case 17:
        case 19:
        case 31:
            ival = atoi(sopt[j].value);
            olen = sizeof(ival);
            ret = zmq_setsockopt(sock_, sopt[j].id, &ival, olen);
            if (verbose_)
                fprintf(stderr, "Socket option %s (%d) set to %d (%d)\n",
                        sopt[j].name, sopt[j].id,
                        ival, ret);
            break;
        default:
            printf("Don't know how to handle socket option %s (%d)\n",
                   sopt[j].name, sopt[j].id);
            break;
        }
    }
    return subs;
}

variable_types: subs int

variable_types: j int

variable_types:
olen
unsigned long

variable_types: ival int

variable_types: ret int

return_type: int


decompiled_code:
void zc_zmq_do_read()
{
int v0; // er12
int v1; // er12
const void *v2; // rax
const void *v3; // rbp
int *v4; // rax
int *v5; // rax
_BYTE v6[88]; // [rsp-58h] [rbp-58h] BYREF

if ( !goon_ )
return;
v0 = zmq_msg_init(v6);
if ( v0 < 0 )
{
if ( verbose_ )
{
v4 = _errno_location();
fprintf(stderr, "Message init returned %d (%d), aborting\n", (unsigned int)v0, (unsigned int)*v4);
}
goto LABEL_9;
}
v1 = zmq_recvmsg(sock_, v6, 0LL);
if ( v1 < 0 )
{
if ( verbose_ )
{
v5 = _errno_location();
fprintf(stderr, "Receive returned %d (%d), aborting\n", (unsigned int)v1, (unsigned int)*v5);
}
zmq_msg_close(v6);
LABEL_9:
goon_ = 0;
return;
}
v2 = (const void *)zmq_msg_data(v6);
v3 = v2;
if ( verbose_ )
fprintf(stderr, "Received %d:%p:[%*.*s]\n", (unsigned int)v1, v2, v1, v1, (const char *)v2);
fwrite(v3, 1uLL, v1, stdout);
fputc(10, stdout);
zmq_msg_close(v6);
}

canonical_decompiled_code:
void func2()
{
int v0; // er12
int v1; // er12
const void *v2; // rax
const void *v3; // rbp
int *v4; // rax
int *v5; // rax
_BYTE v6[88]; // [rsp-58h] [rbp-58h] BYREF

if ( !goon_ )
return;
v0 = zmq_msg_init(v6);
if ( v0 < 0 )
{
if ( verbose_ )
{
v4 = _errno_location();
fprintf(stderr, "Message init returned %d (%d), aborting\n", (unsigned int)v0, (unsigned int)*v4);
}
goto LABEL_9;
}
v1 = zmq_recvmsg(sock_, v6, 0LL);
if ( v1 < 0 )
{
if ( verbose_ )
{
v5 = _errno_location();
fprintf(stderr, "Receive returned %d (%d), aborting\n", (unsigned int)v1, (unsigned int)*v5);
}
zmq_msg_close(v6);
LABEL_9:
goon_ = 0;
return;
}
v2 = (const void *)zmq_msg_data(v6);
v3 = v2;
if ( verbose_ )
fprintf(stderr, "Received %d:%p:[%*.*s]\n", (unsigned int)v1, v2, v1, v1, (const char *)v2);
fwrite(v3, 1uLL, v1, stdout);
fputc(10, stdout);
zmq_msg_close(v6);
}

original_code:
static void zc_zmq_do_read(void)
{
    zmq_msg_t msg;
    int n;
    if (! goon_)
        return;
    n = zmq_msg_init(&msg);
    if (n < 0) {
        if (verbose_)
            fprintf(stderr, "Message init returned %d (%d), aborting\n",
                    n, (*__errno_location ()));
        goon_ = 0;
        return;
    }
    n = zmq_recvmsg(sock_, &msg, 0);
    if (n < 0) {
        if (verbose_)
            fprintf(stderr, "Receive returned %d (%d), aborting\n",
                    n, (*__errno_location ()));
        zmq_msg_close(&msg);
        goon_ = 0;
        return;
    }
    void* p = zmq_msg_data(&msg);
    if (verbose_)
        fprintf(stderr, "Received %d:%p:[%*.*s]\n",
                n, p, n, n, (char*) p);
    fwrite(p, 1, n, stdout);
    fputc('\n', stdout);
    zmq_msg_close(&msg);
}

canonical_original_code:
static void zc_zmq_do_read()
{
    struct zmq_msg_t msg;
    int n;
    if (! goon_)
        return;
    n = zmq_msg_init(&msg);
    if (n < 0) {
        if (verbose_)
            fprintf(stderr, "Message init returned %d (%d), aborting\n",
                    n, (*__errno_location ()));
        goon_ = 0;
        return;
    }
    n = zmq_recvmsg(sock_, &msg, 0);
    if (n < 0) {
        if (verbose_)
            fprintf(stderr, "Receive returned %d (%d), aborting\n",
                    n, (*__errno_location ()));
        zmq_msg_close(&msg);
        goon_ = 0;
        return;
    }
    void *p = zmq_msg_data(&msg);
    if (verbose_)
        fprintf(stderr, "Received %d:%p:[%*.*s]\n",
                n, p, n, n, (char *) p);
    fwrite(p, 1, n, stdout);
    fputc('\n', stdout);
    zmq_msg_close(&msg);
}

variable_types: struct zmq_msg_t { unsigned char _[64]; }

variable_types: n int

variable_types:
p
void *

return_type: void


decompiled_code:
void zc_zmq_do_write()
{
int v0; // er14
__int64 v1; // r12
_BYTE *v2; // rsi
unsigned int v3; // er13
int v4; // eax
int v5; // er12
int v6; // er12
int *v7; // rax
int *v8; // rax
_BYTE *v9; // [rsp+8h] [rbp-60h] BYREF
char v10[88]; // [rsp+10h] [rbp-58h] BYREF

v9 = 0LL;
if ( goon_ )
{
v0 = buffer_alloc(&v9);
if ( v0 >= 0 )
{
v1 = 0LL;
if ( v9 )
{
while ( 1 )
{
v3 = v1;
v4 = fgetc(stdin);
if ( v4 == -1 )
break;
v2 = v9;
if ( v1 == 1024 )
{
v3 = 1024;
goto LABEL_14;
}
if ( delimiter_ == v4 )
goto LABEL_14;
v9[v1++] = v4;
}
if ( verbose_ )
fwrite("Found EOF\n", 1uLL, 0xAuLL, stderr);
goon_ = 0;
if ( !(_DWORD)v1 )
return;
v2 = v9;
v1 = (int)v1;
LABEL_14:
v5 = zmq_msg_init_data(v10, v2, v1, zc_zmq_free, v0);
if ( v5 < 0 )
{
if ( verbose_ )
{
v7 = _errno_location();
fprintf(stderr, "Message init returned %d (%d), aborting\n", (unsigned int)v5, (unsigned int)*v7);
}
}
else
{
if ( verbose_ )
fprintf(stderr, "Sending %d:#%d:%p:[%*.*s]\n", v3, (unsigned int)v0, v9, v3, v3, v9);
v6 = zmq_sendmsg(sock_, v10, 0LL);
if ( v6 >= 0 )
{
zmq_msg_close(v10);
return;
}
if ( verbose_ )
{
v8 = _errno_location();
fprintf(stderr, "Send returned %d (%d), aborting\n", (unsigned int)v6, (unsigned int)*v8);
}
zmq_msg_close(v10);
}
}
}
goon_ = 0;
}
}

canonical_decompiled_code:
void func3()
{
int v0; // er14
__int64 v1; // r12
_BYTE *v2; // rsi
unsigned int v3; // er13
int v4; // eax
int v5; // er12
int v6; // er12
int *v7; // rax
int *v8; // rax
_BYTE *v9; // [rsp+8h] [rbp-60h] BYREF
char v10[88]; // [rsp+10h] [rbp-58h] BYREF

v9 = 0LL;
if ( goon_ )
{
v0 = buffer_alloc(&v9);
if ( v0 >= 0 )
{
v1 = 0LL;
if ( v9 )
{
while ( 1 )
{
v3 = v1;
v4 = fgetc(stdin);
if ( v4 == -1 )
break;
v2 = v9;
if ( v1 == 1024 )
{
v3 = 1024;
goto LABEL_14;
}
if ( delimiter_ == v4 )
goto LABEL_14;
v9[v1++] = v4;
}
if ( verbose_ )
fwrite("Found EOF\n", 1uLL, 0xAuLL, stderr);
goon_ = 0;
if ( !(_DWORD)v1 )
return;
v2 = v9;
v1 = (int)v1;
LABEL_14:
v5 = zmq_msg_init_data(v10, v2, v1, zc_zmq_free, v0);
if ( v5 < 0 )
{
if ( verbose_ )
{
v7 = _errno_location();
fprintf(stderr, "Message init returned %d (%d), aborting\n", (unsigned int)v5, (unsigned int)*v7);
}
}
else
{
if ( verbose_ )
fprintf(stderr, "Sending %d:#%d:%p:[%*.*s]\n", v3, (unsigned int)v0, v9, v3, v3, v9);
v6 = zmq_sendmsg(sock_, v10, 0LL);
if ( v6 >= 0 )
{
zmq_msg_close(v10);
return;
}
if ( verbose_ )
{
v8 = _errno_location();
fprintf(stderr, "Send returned %d (%d), aborting\n", (unsigned int)v6, (unsigned int)*v8);
}
zmq_msg_close(v10);
}
}
}
goon_ = 0;
}
}

original_code:
static void zc_zmq_do_write(void)
{
    int b = 0;
    char* data = 0;
    int eof = 0;
    int p = 0;
    if (! goon_)
        return;
    b = buffer_alloc(&data);
    if (b < 0 || data == 0) {
        goon_ = 0;
        return;
    }
    while (1) {
        int c = fgetc(stdin);
        if (c == (-1)) {
            if (verbose_)
                fprintf(stderr, "Found EOF\n");
            eof = 1;
            goon_ = 0;
            break;
        }
        if (p >= 1024 ||
            c == delimiter_) {
            break;
        }
        data[p++] = c;
    }
    if (p > 0 || !eof) {
        zmq_msg_t msg;
        int n;
        n = zmq_msg_init_data(&msg, data, p, zc_zmq_free, (void*) b);
        if (n < 0) {
            if (verbose_)
                fprintf(stderr, "Message init returned %d (%d), aborting\n",
                        n, (*__errno_location ()));
            goon_ = 0;
            return;
        }
        if (verbose_)
            fprintf(stderr, "Sending %d:#%d:%p:[%*.*s]\n",
                    p, b, data, p, p, data);
        n = zmq_sendmsg(sock_, &msg, 0);
        if (n < 0) {
            if (verbose_)
                fprintf(stderr, "Send returned %d (%d), aborting\n",
                        n, (*__errno_location ()));
            zmq_msg_close(&msg);
            goon_ = 0;
            return;
        }
        zmq_msg_close(&msg);
    }
}

canonical_original_code:
static void zc_zmq_do_write()
{
    int b = 0;
    char *data = 0;
    int eof = 0;
    int p = 0;
    if (! goon_)
        return;
    b = buffer_alloc(&data);
    if (b < 0 || data == 0) {
        goon_ = 0;
        return;
    }
    while (1) {
        int c = fgetc(stdin);
        if (c == (-1)) {
            if (verbose_)
                fprintf(stderr, "Found EOF\n");
            eof = 1;
            goon_ = 0;
            break;
        }
        if (p >= 1024 ||
            c == delimiter_) {
            break;
        }
        data[p++] = c;
    }
    if (p > 0 || !eof) {
        struct zmq_msg_t msg;
        int n;
        n = zmq_msg_init_data(&msg, data, p, zc_zmq_free, (void *) b);
        if (n < 0) {
            if (verbose_)
                fprintf(stderr, "Message init returned %d (%d), aborting\n",
                        n, (*__errno_location ()));
            goon_ = 0;
            return;
        }
        if (verbose_)
            fprintf(stderr, "Sending %d:#%d:%p:[%*.*s]\n",
                    p, b, data, p, p, data);
        n = zmq_sendmsg(sock_, &msg, 0);
        if (n < 0) {
            if (verbose_)
                fprintf(stderr, "Send returned %d (%d), aborting\n",
                        n, (*__errno_location ()));
            zmq_msg_close(&msg);
            goon_ = 0;
            return;
        }
        zmq_msg_close(&msg);
    }
}

variable_types: b int

variable_types:
data
char *

variable_types: eof int

variable_types: p int

variable_types: c int

user_defined_types: struct zmq_msg_t { unsigned char _[64]; }


decompiled_code:
__int64 __fastcall zc_zmq_free(const void *a1, unsigned int a2)
{
if ( verbose_ )
fprintf(stderr, "Freeing buffer #%d:%p\n", a2, a1);
return buffer_free(a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(const void *a1, unsigned int a2)
{
if ( verbose_ )
fprintf(stderr, "Freeing buffer #%d:%p\n", a2, a1);
return buffer_free(a2);
}

original_code:
static void zc_zmq_free(void* buf, void* hint)
{
    int b = (int) hint;
    if (verbose_)
        fprintf(stderr, "Freeing buffer #%d:%p\n", b, buf);
    buffer_free(b);
}

canonical_original_code:
static void zc_zmq_free(void *buf, void *hint)
{
    int b = (int) hint;
    if (verbose_)
        fprintf(stderr, "Freeing buffer #%d:%p\n", b, buf);
    buffer_free(b);
}

variable_types:
buf
void *

variable_types:
hint
void *


decompiled_code:
char *__fastcall zc_zmq_get_delimiter(char a1, char *a2)
{
char *result; // rax

*a2 = 0;
if ( ((*_ctype_b_loc())[a1] & 0x4000) != 0 )
{
sprintf(a2, "%c", (unsigned int)a1);
result = a2;
}
else if ( a1 == 9 )
{
result = a2;
strcpy(a2, "\\t");
}
else if ( a1 == 10 )
{
result = a2;
strcpy(a2, "\\n");
}
else if ( a1 )
{
*(_WORD *)a2 = 46;
result = a2;
}
else
{
result = a2;
strcpy(a2, "\\0");
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(char a1, char *a2)
{
char *result; // rax

*a2 = 0;
if ( ((*_ctype_b_loc())[a1] & 0x4000) != 0 )
{
sprintf(a2, "%c", (unsigned int)a1);
result = a2;
}
else if ( a1 == 9 )
{
result = a2;
strcpy(a2, "\\t");
}
else if ( a1 == 10 )
{
result = a2;
strcpy(a2, "\\n");
}
else if ( a1 )
{
*(_WORD *)a2 = 46;
result = a2;
}
else
{
result = a2;
strcpy(a2, "\\0");
}
return result;
}

original_code:
static const char* zc_zmq_get_delimiter(char d, char* buf)
{
    buf[0] = '\0';
    if (((*__ctype_b_loc ())[(int) (((int) d))] & (unsigned short int) _ISprint)) {
        sprintf(buf, "%c", d);
    } else {
        switch (d) {
        case '\n':
            sprintf(buf, "\\n");
            break;
        case '\0':
            sprintf(buf, "\\0");
            break;
        case '\t':
            sprintf(buf, "\\t");
            break;
        default:
            sprintf(buf, ".");
            break;
        }
    }
    return buf;
}

canonical_original_code:
static char *zc_zmq_get_delimiter(char d, char *buf)
{
    buf[0] = '\0';
    if (((*__ctype_b_loc ())[(int) (((int) d))] & (unsigned short) _ISprint)) {
        sprintf(buf, "%c", d);
    } else {
        switch (d) {
        case '\n':
            sprintf(buf, "\\n");
            break;
        case '\0':
            sprintf(buf, "\\0");
            break;
        case '\t':
            sprintf(buf, "\\t");
            break;
        default:
            sprintf(buf, ".");
            break;
        }
    }
    return buf;
}

variable_types: d char

variable_types:
buf
char *

return_type: char *


decompiled_code:
char *__fastcall zc_zmq_init(char *src)
{
char *result; // rax

result = strcpy(&prog_, src);
delimiter_ = 10;
stype_ = -1;
goon_ = 1;
return result;
}

canonical_decompiled_code:
char *__fastcall func6(char *src)
{
char *result; // rax

result = strcpy(&prog_, src);
delimiter_ = 10;
stype_ = -1;
goon_ = 1;
return result;
}

original_code:
void zc_zmq_init(const char* s)
{
    strcpy(prog_, s);
    delimiter_ = '\n';
    stype_ = -1;
    goon_ = 1;
}

canonical_original_code:
void zc_zmq_init(char *s)
{
    strcpy(prog_, s);
    delimiter_ = '\n';
    stype_ = -1;
    goon_ = 1;
}

variable_types:
s
char *


decompiled_code:
__int64 zc_zmq_cleanup()
{
if ( sock_ )
{
zmq_close();
sock_ = 0LL;
if ( verbose_ )
fwrite("Closed socket\n", 1uLL, 0xEuLL, stderr);
}
if ( ctxt_ )
{
zmq_ctx_term();
ctxt_ = 0LL;
if ( verbose_ )
fwrite("Destroyed context\n", 1uLL, 0x12uLL, stderr);
}
return buffer_clean();
}

canonical_decompiled_code:
__int64 func7()
{
if ( sock_ )
{
zmq_close();
sock_ = 0LL;
if ( verbose_ )
fwrite("Closed socket\n", 1uLL, 0xEuLL, stderr);
}
if ( ctxt_ )
{
zmq_ctx_term();
ctxt_ = 0LL;
if ( verbose_ )
fwrite("Destroyed context\n", 1uLL, 0x12uLL, stderr);
}
return buffer_clean();
}

original_code:
void zc_zmq_cleanup(void)
{
    if (sock_ != 0) {
        zmq_close(sock_);
        sock_ = 0;
        if (verbose_)
            fprintf(stderr, "Closed socket\n");
    }
    if (ctxt_ != 0) {
        zmq_ctx_term(ctxt_);
        ctxt_ = 0;
        if (verbose_)
            fprintf(stderr, "Destroyed context\n");
    }
    buffer_clean();
}

canonical_original_code:
void zc_zmq_cleanup()
{
    if (sock_ != 0) {
        zmq_close(sock_);
        sock_ = 0;
        if (verbose_)
            fprintf(stderr, "Closed socket\n");
    }
    if (ctxt_ != 0) {
        zmq_ctx_term(ctxt_);
        ctxt_ = 0;
        if (verbose_)
            fprintf(stderr, "Destroyed context\n");
    }
    buffer_clean();
}


decompiled_code:
int zc_zmq_show_usage()
{
const char *v0; // rsi

v0 = &prog_;
if ( !prog_ )
v0 = "zc";
printf("Usage: %s [-hv0rwbc] [-n num] [-o opt=val] TYPE address ...\n", v0);
puts(" -h: show this help");
puts(" -v: verbose output; default is quiet");
puts(" -0: use \\0 as delimiter for reading / writing; default is \\n");
puts(" -r: read from socket");
puts(" -w: write to socket");
puts(" -b: bind socket to address(es)");
puts(" -c: connect socket to address(es)");
puts(" -n: read / write at most num records; default is infinite");
printf(
" -o: set socket option to given value\n %s %s %s %s %s\n %s %s %s %s %s %s %s\n",
"SUBSCRIBE",
"UNSUBSCRIBE",
"IDENTITY",
"SNDHWM",
"RCVHWM",
"SNDBUF",
"RCVBUF",
"SNDTIMEO",
"RCVTIMEO",
"LINGER",
"BACKLOG",
"IPV4ONLY");
printf(" TYPE: socket type\n %s %s %s %s %s %s\n", "PUSH", "PULL", "PUB", "SUB", "REQ", "REP");
return puts(" address: one or more addresses in ZMQ format\n ('tcp://127.0.0.1:5000', 'inproc://pipe')");
}

canonical_decompiled_code:
int func8()
{
const char *v0; // rsi

v0 = &prog_;
if ( !prog_ )
v0 = "zc";
printf("Usage: %s [-hv0rwbc] [-n num] [-o opt=val] TYPE address ...\n", v0);
puts(" -h: show this help");
puts(" -v: verbose output; default is quiet");
puts(" -0: use \\0 as delimiter for reading / writing; default is \\n");
puts(" -r: read from socket");
puts(" -w: write to socket");
puts(" -b: bind socket to address(es)");
puts(" -c: connect socket to address(es)");
puts(" -n: read / write at most num records; default is infinite");
printf(
" -o: set socket option to given value\n %s %s %s %s %s\n %s %s %s %s %s %s %s\n",
"SUBSCRIBE",
"UNSUBSCRIBE",
"IDENTITY",
"SNDHWM",
"RCVHWM",
"SNDBUF",
"RCVBUF",
"SNDTIMEO",
"RCVTIMEO",
"LINGER",
"BACKLOG",
"IPV4ONLY");
printf(" TYPE: socket type\n %s %s %s %s %s %s\n", "PUSH", "PULL", "PUB", "SUB", "REQ", "REP");
return puts(" address: one or more addresses in ZMQ format\n ('tcp://127.0.0.1:5000', 'inproc://pipe')");
}

original_code:
void zc_zmq_show_usage(void)
{
    printf("Usage: %s [-hv0rwbc] [-n num] [-o opt=val] TYPE address ...\n",
           prog_[0] ? prog_ : "zc");
    printf("  -h: show this help\n");
    printf("  -v: verbose output; default is quiet\n");
    printf("  -0: use \\0 as delimiter for reading / writing; default is \\n\n");
    printf("  -r: read from socket\n");
    printf("  -w: write to socket\n");
    printf("  -b: bind socket to address(es)\n");
    printf("  -c: connect socket to address(es)\n");
    printf("  -n: read / write at most num records; default is infinite\n");
    printf("  -o: set socket option to given value\n"
           "      %s %s %s %s %s\n"
           "      %s %s %s %s %s %s %s\n",
           "SUBSCRIBE",
           "UNSUBSCRIBE",
           "IDENTITY",
           "SNDHWM",
           "RCVHWM",
           "SNDBUF",
           "RCVBUF",
           "SNDTIMEO",
           "RCVTIMEO",
           "LINGER",
           "BACKLOG",
           "IPV4ONLY");
    printf("  TYPE: socket type\n"
           "        %s %s %s %s %s %s\n",
           "PUSH",
           "PULL",
           "PUB",
           "SUB",
           "REQ",
           "REP");
    printf("  address: one or more addresses in ZMQ format\n"
           "           ('tcp://127.0.0.1:5000', 'inproc://pipe')\n");
}

canonical_original_code:
void zc_zmq_show_usage()
{
    printf("Usage: %s [-hv0rwbc] [-n num] [-o opt=val] TYPE address ...\n",
           prog_[0] ? prog_ : "zc");
    printf("  -h: show this help\n");
    printf("  -v: verbose output; default is quiet\n");
    printf("  -0: use \\0 as delimiter for reading / writing; default is \\n\n");
    printf("  -r: read from socket\n");
    printf("  -w: write to socket\n");
    printf("  -b: bind socket to address(es)\n");
    printf("  -c: connect socket to address(es)\n");
    printf("  -n: read / write at most num records; default is infinite\n");
    printf("  -o: set socket option to given value\n"
           "      %s %s %s %s %s\n"
           "      %s %s %s %s %s %s %s\n",
           "SUBSCRIBE",
           "UNSUBSCRIBE",
           "IDENTITY",
           "SNDHWM",
           "RCVHWM",
           "SNDBUF",
           "RCVBUF",
           "SNDTIMEO",
           "RCVTIMEO",
           "LINGER",
           "BACKLOG",
           "IPV4ONLY");
    printf("  TYPE: socket type\n"
           "        %s %s %s %s %s %s\n",
           "PUSH",
           "PULL",
           "PUB",
           "SUB",
           "REQ",
           "REP");
    printf("  address: one or more addresses in ZMQ format\n"
           "           ('tcp://127.0.0.1:5000', 'inproc://pipe')\n");
}


decompiled_code:
void __fastcall zc_zmq_set_verbose(int a1)
{
verbose_ = a1;
}

canonical_decompiled_code:
void __fastcall func9(int a1)
{
verbose_ = a1;
}

original_code:
void zc_zmq_set_verbose(int v)
{
    verbose_ = v;
}

variable_types: v int


decompiled_code:
int zc_zmq_will_bind()
{
int result; // eax

result = connect_;
if ( connect_ )
result = zc_zmq_show_usage();
connect_ = 0;
bind_ = 1;
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax

result = connect_;
if ( connect_ )
result = func8();
connect_ = 0;
bind_ = 1;
return result;
}

original_code:
void zc_zmq_will_bind(void)
{
    if (connect_) {
        zc_zmq_show_usage();
    }
    connect_ = 0;
    bind_ = 1;
}

canonical_original_code:
void zc_zmq_will_bind()
{
    if (connect_) {
        zc_zmq_show_usage();
    }
    connect_ = 0;
    bind_ = 1;
}


decompiled_code:
int zc_zmq_will_connect()
{
int result; // eax

result = bind_;
if ( bind_ )
result = zc_zmq_show_usage();
connect_ = 1;
bind_ = 0;
return result;
}

canonical_decompiled_code:
int func11()
{
int result; // eax

result = bind_;
if ( bind_ )
result = func8();
connect_ = 1;
bind_ = 0;
return result;
}

original_code:
void zc_zmq_will_connect(void)
{
    if (bind_) {
        zc_zmq_show_usage();
    }
    connect_ = 1;
    bind_ = 0;
}

canonical_original_code:
void zc_zmq_will_connect()
{
    if (bind_) {
        zc_zmq_show_usage();
    }
    connect_ = 1;
    bind_ = 0;
}


decompiled_code:
int zc_zmq_will_read()
{
int result; // eax

result = write_;
if ( write_ )
result = zc_zmq_show_usage();
write_ = 0;
read_ = 1;
return result;
}

canonical_decompiled_code:
int func12()
{
int result; // eax

result = write_;
if ( write_ )
result = func8();
write_ = 0;
read_ = 1;
return result;
}

original_code:
void zc_zmq_will_read(void)
{
    if (write_) {
        zc_zmq_show_usage();
    }
    write_ = 0;
    read_ = 1;
}

canonical_original_code:
void zc_zmq_will_read()
{
    if (write_) {
        zc_zmq_show_usage();
    }
    write_ = 0;
    read_ = 1;
}


decompiled_code:
int zc_zmq_will_write()
{
int result; // eax

result = read_;
if ( read_ )
result = zc_zmq_show_usage();
write_ = 1;
read_ = 0;
return result;
}

canonical_decompiled_code:
int func13()
{
int result; // eax

result = read_;
if ( read_ )
result = func8();
write_ = 1;
read_ = 0;
return result;
}

original_code:
void zc_zmq_will_write(void)
{
    if (read_) {
        zc_zmq_show_usage();
    }
    write_ = 1;
    read_ = 0;
}

canonical_original_code:
void zc_zmq_will_write()
{
    if (read_) {
        zc_zmq_show_usage();
    }
    write_ = 1;
    read_ = 0;
}


decompiled_code:
char __fastcall zc_zmq_set_type(char *src)
{
bool v1; // zf
char result; // al

strcpy(type_, src);
stype_ = -1;
v1 = strcmp(type_, "PUSH") == 0;
result = !v1;
if ( v1 )
{
stype_ = 8;
}
else
{
v1 = strcmp(type_, "PULL") == 0;
result = !v1;
if ( v1 )
{
stype_ = 7;
}
else
{
v1 = strcmp(type_, "PUB") == 0;
result = !v1;
if ( v1 )
{
stype_ = 1;
}
else
{
v1 = strcmp(type_, "SUB") == 0;
result = !v1;
if ( v1 )
{
stype_ = 2;
}
else
{
v1 = strcmp(type_, "REQ") == 0;
result = !v1;
if ( v1 )
{
stype_ = 3;
}
else
{
v1 = strcmp(type_, "REP") == 0;
result = !v1;
if ( v1 )
{
stype_ = 4;
}
else
{
result = verbose_;
if ( verbose_ )
result = fprintf(stderr, "Unknown socket type [%s]\n", type_);
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func14(char *src)
{
bool v1; // zf
char result; // al

strcpy(type_, src);
stype_ = -1;
v1 = strcmp(type_, "PUSH") == 0;
result = !v1;
if ( v1 )
{
stype_ = 8;
}
else
{
v1 = strcmp(type_, "PULL") == 0;
result = !v1;
if ( v1 )
{
stype_ = 7;
}
else
{
v1 = strcmp(type_, "PUB") == 0;
result = !v1;
if ( v1 )
{
stype_ = 1;
}
else
{
v1 = strcmp(type_, "SUB") == 0;
result = !v1;
if ( v1 )
{
stype_ = 2;
}
else
{
v1 = strcmp(type_, "REQ") == 0;
result = !v1;
if ( v1 )
{
stype_ = 3;
}
else
{
v1 = strcmp(type_, "REP") == 0;
result = !v1;
if ( v1 )
{
stype_ = 4;
}
else
{
result = verbose_;
if ( verbose_ )
result = fprintf(stderr, "Unknown socket type [%s]\n", type_);
}
}
}
}
}
}
return result;
}

original_code:
void zc_zmq_set_type(const char* type)
{
    strcpy(type_, type);
    stype_ = -1;
    if (strcmp(type_, "PUSH") == 0) {
        stype_ = 8;
    } else if (strcmp(type_, "PULL") == 0) {
        stype_ = 7;
    } else if (strcmp(type_, "PUB") == 0) {
        stype_ = 1;
    } else if (strcmp(type_, "SUB") == 0) {
        stype_ = 2;
    } else if (strcmp(type_, "REQ") == 0) {
        stype_ = 3;
    } else if (strcmp(type_, "REP") == 0) {
        stype_ = 4;
    } else {
        if (verbose_)
            fprintf(stderr, "Unknown socket type [%s]\n", type_);
    }
}

canonical_original_code:
void zc_zmq_set_type(char *type)
{
    strcpy(type_, type);
    stype_ = -1;
    if (strcmp(type_, "PUSH") == 0) {
        stype_ = 8;
    } else if (strcmp(type_, "PULL") == 0) {
        stype_ = 7;
    } else if (strcmp(type_, "PUB") == 0) {
        stype_ = 1;
    } else if (strcmp(type_, "SUB") == 0) {
        stype_ = 2;
    } else if (strcmp(type_, "REQ") == 0) {
        stype_ = 3;
    } else if (strcmp(type_, "REP") == 0) {
        stype_ = 4;
    } else {
        if (verbose_)
            fprintf(stderr, "Unknown socket type [%s]\n", type_);
    }
}

variable_types:
type
char *


decompiled_code:
int __fastcall zc_zmq_add_address(char *src)
{
int v1; // ebx
int result; // eax

v1 = nadd;
if ( nadd > 49 )
return printf("Too many addresses (max is %d): [%s]\n", 50LL, src);
result = (unsigned int)strcpy(&sadd[1024 * (__int64)nadd], src);
nadd = v1 + 1;
return result;
}

canonical_decompiled_code:
int __fastcall func15(char *src)
{
int v1; // ebx
int result; // eax

v1 = nadd;
if ( nadd > 49 )
return printf("Too many addresses (max is %d): [%s]\n", 50LL, src);
result = (unsigned int)strcpy(&sadd[1024 * (__int64)nadd], src);
nadd = v1 + 1;
return result;
}

original_code:
void zc_zmq_add_address(const char* address)
{
    if (nadd >= 50) {
        printf("Too many addresses (max is %d): [%s]\n",
               50, address);
        return;
    }
    strcpy(sadd[nadd].ep, address);
    ++nadd;
}

canonical_original_code:
void zc_zmq_add_address(char *address)
{
    if (nadd >= 50) {
        printf("Too many addresses (max is %d): [%s]\n",
               50, address);
        return;
    }
    strcpy(sadd[nadd].ep, address);
    ++nadd;
}

variable_types:
address
char *


decompiled_code:
void __fastcall zc_zmq_set_delimiter(char a1)
{
delimiter_ = a1;
}

canonical_decompiled_code:
void __fastcall func16(char a1)
{
delimiter_ = a1;
}

original_code:
void zc_zmq_set_delimiter(char d)
{
    delimiter_ = d;
}


decompiled_code:
void __fastcall zc_zmq_set_iterations(int a1)
{
iterations_ = a1;
}

canonical_decompiled_code:
void __fastcall func17(int a1)
{
iterations_ = a1;
}

original_code:
void zc_zmq_set_iterations(int n)
{
    iterations_ = n;
}


decompiled_code:
unsigned int __fastcall zc_zmq_add_option(char *src)
{
int v1; // er12
char v2; // al
char *v3; // rbp
char *v4; // rdx
__int64 v5; // rdi
unsigned int result; // eax
char v7[1064]; // [rsp+0h] [rbp-428h] BYREF

v1 = nopt;
if ( nopt > 49 )
return printf("Too many options (max is %d): [%s]\n", 50LL, src);
strcpy(v7, src);
v2 = v7[0];
if ( !v7[0] )
return printf("Invalid option without a valid separator '%c'\n", 61LL);
v3 = v7;
while ( 1 )
{
v4 = v3++;
if ( v2 == 61 )
break;
v2 = *v3;
if ( !*v3 )
return printf("Invalid option without a valid separator '%c'\n", 61LL);
}
*v4 = 0;
if ( !strcmp(v7, "SUBSCRIBE") )
{
v5 = v1;
dword_17C0[513 * v1] = 6;
LABEL_8:
strcpy((char *)&sopt + 2052 * v5, v7);
result = (unsigned int)strcpy(&byte_17C4[2052 * v5], v3);
nopt = v1 + 1;
return result;
}
if ( !strcmp(v7, "UNSUBSCRIBE") )
{
v5 = v1;
dword_17C0[513 * v1] = 7;
goto LABEL_8;
}
if ( !strcmp(v7, "IDENTITY") )
{
v5 = v1;
dword_17C0[513 * v1] = 5;
goto LABEL_8;
}
if ( !strcmp(v7, "SNDHWM") )
{
v5 = v1;
dword_17C0[513 * v1] = 23;
goto LABEL_8;
}
if ( !strcmp(v7, "RCVHWM") )
{
v5 = v1;
dword_17C0[513 * v1] = 24;
goto LABEL_8;
}
if ( !strcmp(v7, "SNDBUF") )
{
v5 = v1;
dword_17C0[513 * v1] = 11;
goto LABEL_8;
}
if ( !strcmp(v7, "RCVBUF") )
{
v5 = v1;
dword_17C0[513 * v1] = 12;
goto LABEL_8;
}
if ( !strcmp(v7, "SNDTIMEO") )
{
v5 = v1;
dword_17C0[513 * v1] = 28;
goto LABEL_8;
}
if ( !strcmp(v7, "RCVTIMEO") )
{
v5 = v1;
dword_17C0[513 * v1] = 27;
goto LABEL_8;
}
if ( !strcmp(v7, "LINGER") )
{
v5 = v1;
dword_17C0[513 * v1] = 17;
goto LABEL_8;
}
if ( !strcmp(v7, "BACKLOG") )
{
v5 = v1;
dword_17C0[513 * v1] = 19;
goto LABEL_8;
}
if ( !strcmp(v7, "IPV4ONLY") )
{
v5 = v1;
dword_17C0[513 * v1] = 31;
goto LABEL_8;
}
return printf("Invalid socket option [%s]\n", v7);
}

canonical_decompiled_code:
unsigned int __fastcall func18(char *src)
{
int v1; // er12
char v2; // al
char *v3; // rbp
char *v4; // rdx
__int64 v5; // rdi
unsigned int result; // eax
char v7[1064]; // [rsp+0h] [rbp-428h] BYREF

v1 = nopt;
if ( nopt > 49 )
return printf("Too many options (max is %d): [%s]\n", 50LL, src);
strcpy(v7, src);
v2 = v7[0];
if ( !v7[0] )
return printf("Invalid option without a valid separator '%c'\n", 61LL);
v3 = v7;
while ( 1 )
{
v4 = v3++;
if ( v2 == 61 )
break;
v2 = *v3;
if ( !*v3 )
return printf("Invalid option without a valid separator '%c'\n", 61LL);
}
*v4 = 0;
if ( !strcmp(v7, "SUBSCRIBE") )
{
v5 = v1;
dword_17C0[513 * v1] = 6;
LABEL_8:
strcpy((char *)&sopt + 2052 * v5, v7);
result = (unsigned int)strcpy(&byte_17C4[2052 * v5], v3);
nopt = v1 + 1;
return result;
}
if ( !strcmp(v7, "UNSUBSCRIBE") )
{
v5 = v1;
dword_17C0[513 * v1] = 7;
goto LABEL_8;
}
if ( !strcmp(v7, "IDENTITY") )
{
v5 = v1;
dword_17C0[513 * v1] = 5;
goto LABEL_8;
}
if ( !strcmp(v7, "SNDHWM") )
{
v5 = v1;
dword_17C0[513 * v1] = 23;
goto LABEL_8;
}
if ( !strcmp(v7, "RCVHWM") )
{
v5 = v1;
dword_17C0[513 * v1] = 24;
goto LABEL_8;
}
if ( !strcmp(v7, "SNDBUF") )
{
v5 = v1;
dword_17C0[513 * v1] = 11;
goto LABEL_8;
}
if ( !strcmp(v7, "RCVBUF") )
{
v5 = v1;
dword_17C0[513 * v1] = 12;
goto LABEL_8;
}
if ( !strcmp(v7, "SNDTIMEO") )
{
v5 = v1;
dword_17C0[513 * v1] = 28;
goto LABEL_8;
}
if ( !strcmp(v7, "RCVTIMEO") )
{
v5 = v1;
dword_17C0[513 * v1] = 27;
goto LABEL_8;
}
if ( !strcmp(v7, "LINGER") )
{
v5 = v1;
dword_17C0[513 * v1] = 17;
goto LABEL_8;
}
if ( !strcmp(v7, "BACKLOG") )
{
v5 = v1;
dword_17C0[513 * v1] = 19;
goto LABEL_8;
}
if ( !strcmp(v7, "IPV4ONLY") )
{
v5 = v1;
dword_17C0[513 * v1] = 31;
goto LABEL_8;
}
return printf("Invalid socket option [%s]\n", v7);
}

original_code:
void zc_zmq_add_option(const char* opt)
{
    char buf[1024];
    char* p = 0;
    char* q = 0;
    if (nopt >= 50) {
        printf("Too many options (max is %d): [%s]\n",
               50, opt);
        return;
    }
    strcpy(buf, opt);
    for (p = buf, q = 0; *p != '\0'; ++p) {
        if (*p == '=') {
            *p = '\0';
            q = p+1;
            break;
        }
    }
    if (q == 0) {
        printf("Invalid option without a valid separator '%c'\n",
               '=');
        return;
    }
    int ok = 1;
    if (strcmp(buf, "SUBSCRIBE") == 0) {
        sopt[nopt].id = 6;
    } else if (strcmp(buf, "UNSUBSCRIBE") == 0) {
        sopt[nopt].id = 7;
    } else if (strcmp(buf, "IDENTITY") == 0) {
        sopt[nopt].id = 5;
    } else if (strcmp(buf, "SNDHWM") == 0) {
        sopt[nopt].id = 23;
    } else if (strcmp(buf, "RCVHWM") == 0) {
        sopt[nopt].id = 24;
    } else if (strcmp(buf, "SNDBUF") == 0) {
        sopt[nopt].id = 11;
    } else if (strcmp(buf, "RCVBUF") == 0) {
        sopt[nopt].id = 12;
    } else if (strcmp(buf, "SNDTIMEO") == 0) {
        sopt[nopt].id = 28;
    } else if (strcmp(buf, "RCVTIMEO") == 0) {
        sopt[nopt].id = 27;
    } else if (strcmp(buf, "LINGER") == 0) {
        sopt[nopt].id = 17;
    } else if (strcmp(buf, "BACKLOG") == 0) {
        sopt[nopt].id = 19;
    } else if (strcmp(buf, "IPV4ONLY") == 0) {
        if (31 < 0)
            ok = 0;
        else
            sopt[nopt].id = 31;
    } else {
        ok = 0;
    }
    if (!ok) {
        printf("Invalid socket option [%s]\n", buf);
        return;
    }
    strcpy(sopt[nopt].name, buf);
    strcpy(sopt[nopt].value, q);
    ++nopt;
}

canonical_original_code:
void zc_zmq_add_option(char *opt)
{
    char buf[1024];
    char *p = 0;
    char *q = 0;
    if (nopt >= 50) {
        printf("Too many options (max is %d): [%s]\n",
               50, opt);
        return;
    }
    strcpy(buf, opt);
    for (p = buf, q = 0; *p != '\0'; ++p) {
        if (*p == '=') {
            *p = '\0';
            q = p+1;
            break;
        }
    }
    if (q == 0) {
        printf("Invalid option without a valid separator '%c'\n",
               '=');
        return;
    }
    int ok = 1;
    if (strcmp(buf, "SUBSCRIBE") == 0) {
        sopt[nopt].id = 6;
    } else if (strcmp(buf, "UNSUBSCRIBE") == 0) {
        sopt[nopt].id = 7;
    } else if (strcmp(buf, "IDENTITY") == 0) {
        sopt[nopt].id = 5;
    } else if (strcmp(buf, "SNDHWM") == 0) {
        sopt[nopt].id = 23;
    } else if (strcmp(buf, "RCVHWM") == 0) {
        sopt[nopt].id = 24;
    } else if (strcmp(buf, "SNDBUF") == 0) {
        sopt[nopt].id = 11;
    } else if (strcmp(buf, "RCVBUF") == 0) {
        sopt[nopt].id = 12;
    } else if (strcmp(buf, "SNDTIMEO") == 0) {
        sopt[nopt].id = 28;
    } else if (strcmp(buf, "RCVTIMEO") == 0) {
        sopt[nopt].id = 27;
    } else if (strcmp(buf, "LINGER") == 0) {
        sopt[nopt].id = 17;
    } else if (strcmp(buf, "BACKLOG") == 0) {
        sopt[nopt].id = 19;
    } else if (strcmp(buf, "IPV4ONLY") == 0) {
        if (31 < 0)
            ok = 0;
        else
            sopt[nopt].id = 31;
    } else {
        ok = 0;
    }
    if (!ok) {
        printf("Invalid socket option [%s]\n", buf);
        return;
    }
    strcpy(sopt[nopt].name, buf);
    strcpy(sopt[nopt].value, q);
    ++nopt;
}

variable_types:
opt
char *

variable_types:
buf
char [1024]

variable_types:
p
char *

variable_types:
q
char *

variable_types: ok int


decompiled_code:
__int64 zc_zmq_run()
{
__int64 result; // rax
const void *v1; // rax
__int64 v2; // rdi
const void *v3; // rax
_BOOL4 v4; // eax
char *v5; // rbp
int i; // ebx
unsigned int v7; // eax
int v8; // er12
unsigned int v9; // eax
int v10; // ebx
unsigned int v11; // eax
int *v12; // rax

result = zc_zmq_is_valid();
if ( !(_DWORD)result )
return result;
if ( verbose_ )
fwrite("------\n", 1uLL, 7uLL, stderr);
buffer_init();
v1 = (const void *)zmq_ctx_new();
ctxt_ = (__int64)v1;
v2 = (__int64)v1;
if ( verbose_ )
{
fprintf(stderr, "Context created: %p\n", v1);
v2 = ctxt_;
}
v3 = (const void *)zmq_socket(v2, (unsigned int)stype_);
sock_ = (__int64)v3;
if ( verbose_ )
{
fprintf(stderr, "Socket type %s (%d) created: %p\n", type_, (unsigned int)stype_, v3);
v4 = zc_zmq_set_options();
if ( stype_ != 2 )
goto LABEL_9;
}
else
{
v4 = zc_zmq_set_options();
if ( stype_ != 2 )
{
LABEL_9:
if ( nadd > 0 )
{
LABEL_10:
v5 = sadd;
for ( i = 0; nadd > i; ++i )
{
if ( bind_ )
{
v7 = zmq_bind(sock_, v5);
v8 = v7;
if ( verbose_ )
{
fprintf(stderr, "Socket bound to [%s]: %d", v5, v7);
LABEL_16:
if ( v8 < 0 )
{
v12 = _errno_location();
fprintf(stderr, " (%d)", (unsigned int)*v12);
}
fputc(10, stderr);
goto LABEL_12;
}
}
else if ( connect_ )
{
v9 = zmq_connect(sock_, v5);
v8 = v9;
if ( verbose_ )
{
fprintf(stderr, "Socket connected to [%s]: %d", v5, v9);
goto LABEL_16;
}
}
LABEL_12:
v5 += 1024;
}
}
if ( verbose_ )
{
fwrite("Running loop...\n", 1uLL, 0x10uLL, stderr);
fwrite("------\n", 1uLL, 7uLL, stderr);
}
goto LABEL_23;
}
}
if ( v4 )
goto LABEL_9;
v11 = zmq_setsockopt(sock_, 6LL, 0LL, 0LL);
if ( verbose_ )
{
fprintf(stderr, "Socket automatically subscribed to all messages: %d\n", v11);
goto LABEL_9;
}
if ( nadd > 0 )
goto LABEL_10;
LABEL_23:
goon_ = 1;
v10 = 1;
while ( 1 )
{
if ( stype_ == 3 )
{
zc_zmq_do_write();
zc_zmq_do_read();
goto LABEL_29;
}
if ( stype_ == 4 )
{
zc_zmq_do_read();
zc_zmq_do_write();
goto LABEL_29;
}
if ( read_ )
{
zc_zmq_do_read();
goto LABEL_29;
}
if ( !write_ )
break;
zc_zmq_do_write();
LABEL_29:
if ( !goon_ )
return zc_zmq_cleanup();
++v10;
if ( iterations_ > 0 && iterations_ < v10 )
{
if ( verbose_ )
fprintf(stderr, "Reached %d iterations, aborting\n", (unsigned int)iterations_);
return zc_zmq_cleanup();
}
}
if ( verbose_ )
fwrite("Invalid loop mode\n", 1uLL, 0x12uLL, stderr);
return zc_zmq_cleanup();
}

canonical_decompiled_code:
__int64 func19()
{
__int64 result; // rax
const void *v1; // rax
__int64 v2; // rdi
const void *v3; // rax
_BOOL4 v4; // eax
char *v5; // rbp
int i; // ebx
unsigned int v7; // eax
int v8; // er12
unsigned int v9; // eax
int v10; // ebx
unsigned int v11; // eax
int *v12; // rax

result = func0();
if ( !(_DWORD)result )
return result;
if ( verbose_ )
fwrite("------\n", 1uLL, 7uLL, stderr);
buffer_init();
v1 = (const void *)zmq_ctx_new();
ctxt_ = (__int64)v1;
v2 = (__int64)v1;
if ( verbose_ )
{
fprintf(stderr, "Context created: %p\n", v1);
v2 = ctxt_;
}
v3 = (const void *)zmq_socket(v2, (unsigned int)stype_);
sock_ = (__int64)v3;
if ( verbose_ )
{
fprintf(stderr, "Socket type %s (%d) created: %p\n", type_, (unsigned int)stype_, v3);
v4 = func1();
if ( stype_ != 2 )
goto LABEL_9;
}
else
{
v4 = func1();
if ( stype_ != 2 )
{
LABEL_9:
if ( nadd > 0 )
{
LABEL_10:
v5 = sadd;
for ( i = 0; nadd > i; ++i )
{
if ( bind_ )
{
v7 = zmq_bind(sock_, v5);
v8 = v7;
if ( verbose_ )
{
fprintf(stderr, "Socket bound to [%s]: %d", v5, v7);
LABEL_16:
if ( v8 < 0 )
{
v12 = _errno_location();
fprintf(stderr, " (%d)", (unsigned int)*v12);
}
fputc(10, stderr);
goto LABEL_12;
}
}
else if ( connect_ )
{
v9 = zmq_connect(sock_, v5);
v8 = v9;
if ( verbose_ )
{
fprintf(stderr, "Socket connected to [%s]: %d", v5, v9);
goto LABEL_16;
}
}
LABEL_12:
v5 += 1024;
}
}
if ( verbose_ )
{
fwrite("Running loop...\n", 1uLL, 0x10uLL, stderr);
fwrite("------\n", 1uLL, 7uLL, stderr);
}
goto LABEL_23;
}
}
if ( v4 )
goto LABEL_9;
v11 = zmq_setsockopt(sock_, 6LL, 0LL, 0LL);
if ( verbose_ )
{
fprintf(stderr, "Socket automatically subscribed to all messages: %d\n", v11);
goto LABEL_9;
}
if ( nadd > 0 )
goto LABEL_10;
LABEL_23:
goon_ = 1;
v10 = 1;
while ( 1 )
{
if ( stype_ == 3 )
{
func3();
func2();
goto LABEL_29;
}
if ( stype_ == 4 )
{
func2();
func3();
goto LABEL_29;
}
if ( read_ )
{
func2();
goto LABEL_29;
}
if ( !write_ )
break;
func3();
LABEL_29:
if ( !goon_ )
return func7();
++v10;
if ( iterations_ > 0 && iterations_ < v10 )
{
if ( verbose_ )
fprintf(stderr, "Reached %d iterations, aborting\n", (unsigned int)iterations_);
return func7();
}
}
if ( verbose_ )
fwrite("Invalid loop mode\n", 1uLL, 0x12uLL, stderr);
return func7();
}

original_code:
void zc_zmq_run(void)
{
    int count = 0;
    int subs = 0;
    int j;
    if (! zc_zmq_is_valid())
        return;
    if (verbose_)
        fprintf(stderr, "------\n");
    buffer_init(verbose_);
    ctxt_ = zmq_ctx_new();
    if (verbose_)
        fprintf(stderr, "Context created: %p\n", ctxt_);
    sock_ = zmq_socket(ctxt_, stype_);
    if (verbose_)
        fprintf(stderr, "Socket type %s (%d) created: %p\n",
                type_, stype_, sock_);
    subs = zc_zmq_set_options();
    if (stype_ == 2 && !subs) {
        int ret = zmq_setsockopt(sock_, 6, 0, 0);
        if (verbose_)
            fprintf(stderr, "Socket automatically subscribed to all messages: %d\n",
                    ret);
    }
    for (j = 0; j < nadd; ++j) {
        if (bind_) {
            int ret = zmq_bind(sock_, sadd[j].ep);
            if (verbose_) {
                fprintf(stderr, "Socket bound to [%s]: %d", sadd[j].ep, ret);
                if (ret < 0)
                    fprintf(stderr, " (%d)", (*__errno_location ()));
                fprintf(stderr, "\n");
            }
            continue;
        }
        if (connect_) {
            int ret = zmq_connect(sock_, sadd[j].ep);
            if (verbose_) {
                fprintf(stderr, "Socket connected to [%s]: %d", sadd[j].ep, ret);
                if (ret < 0)
                    fprintf(stderr, " (%d)", (*__errno_location ()));
                fprintf(stderr, "\n");
            }
            continue;
        }
    }
    if (verbose_) {
        fprintf(stderr, "Running loop...\n");
        fprintf(stderr, "------\n");
    }
    count = 0;
    goon_ = 1;
    while (goon_) {
        ++count;
        if (iterations_ > 0 &&
            count > iterations_) {
            if (verbose_)
                fprintf(stderr, "Reached %d iterations, aborting\n", iterations_);
            break;
        }
        if (stype_ == 3) {
            zc_zmq_do_write();
            zc_zmq_do_read();
        } else if (stype_ == 4) {
            zc_zmq_do_read();
            zc_zmq_do_write();
        } else if (read_) {
            zc_zmq_do_read();
        } else if (write_) {
            zc_zmq_do_write();
        } else {
            if (verbose_)
                fprintf(stderr, "Invalid loop mode\n");
            break;
        }
    }
    zc_zmq_cleanup();
}

canonical_original_code:
void zc_zmq_run()
{
    int count = 0;
    int subs = 0;
    int j;
    if (! zc_zmq_is_valid())
        return;
    if (verbose_)
        fprintf(stderr, "------\n");
    buffer_init(verbose_);
    ctxt_ = zmq_ctx_new();
    if (verbose_)
        fprintf(stderr, "Context created: %p\n", ctxt_);
    sock_ = zmq_socket(ctxt_, stype_);
    if (verbose_)
        fprintf(stderr, "Socket type %s (%d) created: %p\n",
                type_, stype_, sock_);
    subs = zc_zmq_set_options();
    if (stype_ == 2 && !subs) {
        int ret = zmq_setsockopt(sock_, 6, 0, 0);
        if (verbose_)
            fprintf(stderr, "Socket automatically subscribed to all messages: %d\n",
                    ret);
    }
    for (j = 0; j < nadd; ++j) {
        if (bind_) {
            int ret = zmq_bind(sock_, sadd[j].ep);
            if (verbose_) {
                fprintf(stderr, "Socket bound to [%s]: %d", sadd[j].ep, ret);
                if (ret < 0)
                    fprintf(stderr, " (%d)", (*__errno_location ()));
                fprintf(stderr, "\n");
            }
            continue;
        }
        if (connect_) {
            int ret = zmq_connect(sock_, sadd[j].ep);
            if (verbose_) {
                fprintf(stderr, "Socket connected to [%s]: %d", sadd[j].ep, ret);
                if (ret < 0)
                    fprintf(stderr, " (%d)", (*__errno_location ()));
                fprintf(stderr, "\n");
            }
            continue;
        }
    }
    if (verbose_) {
        fprintf(stderr, "Running loop...\n");
        fprintf(stderr, "------\n");
    }
    count = 0;
    goon_ = 1;
    while (goon_) {
        ++count;
        if (iterations_ > 0 &&
            count > iterations_) {
            if (verbose_)
                fprintf(stderr, "Reached %d iterations, aborting\n", iterations_);
            break;
        }
        if (stype_ == 3) {
            zc_zmq_do_write();
            zc_zmq_do_read();
        } else if (stype_ == 4) {
            zc_zmq_do_read();
            zc_zmq_do_write();
        } else if (read_) {
            zc_zmq_do_read();
        } else if (write_) {
            zc_zmq_do_write();
        } else {
            if (verbose_)
                fprintf(stderr, "Invalid loop mode\n");
            break;
        }
    }
    zc_zmq_cleanup();
}

variable_types: count int

variable_types: subs int

variable_types: j int

variable_types: ret int


decompiled_code:
void zc_zmq_debug()
{
char *v0; // rbp
int v1; // ebx
unsigned int v2; // er12
char *v3; // rax
const char *v4; // rcx
__int64 v5; // rdx
const char *v6; // rbx
int i; // ebp
__int64 v8; // r8
const char *v9; // rcx
__int64 v10; // rdx
const char *v11; // r9
unsigned int v12; // [rsp+8h] [rbp-30h] BYREF
unsigned int v13; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned int v14; // [rsp+10h] [rbp-28h] BYREF
char v15[34]; // [rsp+16h] [rbp-22h] BYREF

v12 = 0;
v13 = 0;
v14 = 0;
if ( verbose_ && zc_zmq_is_valid() )
{
v0 = sadd;
v1 = 0;
zmq_version(&v12, &v13, &v14);
fprintf(stderr, "ZQM version used: %d.%d.%d\n", v12, v13, v14);
fprintf(stderr, " will bind: %d\n", (unsigned int)bind_);
fprintf(stderr, " will connect: %d\n", (unsigned int)connect_);
fprintf(stderr, " will read: %d\n", (unsigned int)read_);
fprintf(stderr, " will write: %d\n", (unsigned int)write_);
fprintf(stderr, " socket type: %s (%d)\n", type_, (unsigned int)stype_);
v2 = delimiter_;
v3 = zc_zmq_get_delimiter(delimiter_, v15);
fprintf(stderr, " delimiter: %s (%d)\n", v3, v2);
fprintf(stderr, " iterations: %d\n", (unsigned int)iterations_);
if ( nadd > 0 )
{
do
{
v4 = v0;
v5 = (unsigned int)v1++;
v0 += 1024;
fprintf(stderr, " address #%2d: %s\n", v5, v4);
}
while ( nadd > v1 );
}
v6 = (const char *)&sopt;
for ( i = 0; nopt > i; ++i )
{
v8 = *((unsigned int *)v6 + 256);
v9 = v6;
v10 = (unsigned int)i;
v11 = v6 + 1028;
v6 += 2052;
fprintf(stderr, " option #%2d: %s (%d) = [%s]\n", v10, v9, v8, v11);
}
}
}

canonical_decompiled_code:
void func20()
{
char *v0; // rbp
int v1; // ebx
unsigned int v2; // er12
char *v3; // rax
const char *v4; // rcx
__int64 v5; // rdx
const char *v6; // rbx
int i; // ebp
__int64 v8; // r8
const char *v9; // rcx
__int64 v10; // rdx
const char *v11; // r9
unsigned int v12; // [rsp+8h] [rbp-30h] BYREF
unsigned int v13; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned int v14; // [rsp+10h] [rbp-28h] BYREF
char v15[34]; // [rsp+16h] [rbp-22h] BYREF

v12 = 0;
v13 = 0;
v14 = 0;
if ( verbose_ && func0() )
{
v0 = sadd;
v1 = 0;
zmq_version(&v12, &v13, &v14);
fprintf(stderr, "ZQM version used: %d.%d.%d\n", v12, v13, v14);
fprintf(stderr, " will bind: %d\n", (unsigned int)bind_);
fprintf(stderr, " will connect: %d\n", (unsigned int)connect_);
fprintf(stderr, " will read: %d\n", (unsigned int)read_);
fprintf(stderr, " will write: %d\n", (unsigned int)write_);
fprintf(stderr, " socket type: %s (%d)\n", type_, (unsigned int)stype_);
v2 = delimiter_;
v3 = func5(delimiter_, v15);
fprintf(stderr, " delimiter: %s (%d)\n", v3, v2);
fprintf(stderr, " iterations: %d\n", (unsigned int)iterations_);
if ( nadd > 0 )
{
do
{
v4 = v0;
v5 = (unsigned int)v1++;
v0 += 1024;
fprintf(stderr, " address #%2d: %s\n", v5, v4);
}
while ( nadd > v1 );
}
v6 = (const char *)&sopt;
for ( i = 0; nopt > i; ++i )
{
v8 = *((unsigned int *)v6 + 256);
v9 = v6;
v10 = (unsigned int)i;
v11 = v6 + 1028;
v6 += 2052;
fprintf(stderr, " option #%2d: %s (%d) = [%s]\n", v10, v9, v8, v11);
}
}
}

original_code:
void zc_zmq_debug(void)
{
    int major = 0;
    int minor = 0;
    int patch = 0;
    char buf[10];
    int j;
    if (! verbose_)
        return;
    if (! zc_zmq_is_valid())
        return;
    zmq_version(&major, &minor, &patch);
    fprintf(stderr, "ZQM version used: %d.%d.%d\n", major, minor, patch);
    fprintf(stderr, "       will bind: %d\n", bind_);
    fprintf(stderr, "    will connect: %d\n", connect_);
    fprintf(stderr, "       will read: %d\n", read_);
    fprintf(stderr, "      will write: %d\n", write_);
    fprintf(stderr, "     socket type: %s (%d)\n", type_, stype_);
    fprintf(stderr, "       delimiter: %s (%d)\n",
            zc_zmq_get_delimiter(delimiter_, buf),
            (int) delimiter_);
    fprintf(stderr, "      iterations: %d\n", iterations_);
    for (j = 0; j < nadd; ++j) {
        fprintf(stderr, "     address #%2d: %s\n",
                j, sadd[j].ep);
    }
    for (j = 0; j < nopt; ++j) {
        fprintf(stderr, "      option #%2d: %s (%d) = [%s]\n",
                j, sopt[j].name, sopt[j].id, sopt[j].value);
    }
}

canonical_original_code:
void zc_zmq_debug()
{
    int major = 0;
    int minor = 0;
    int patch = 0;
    char buf[10];
    int j;
    if (! verbose_)
        return;
    if (! zc_zmq_is_valid())
        return;
    zmq_version(&major, &minor, &patch);
    fprintf(stderr, "ZQM version used: %d.%d.%d\n", major, minor, patch);
    fprintf(stderr, "       will bind: %d\n", bind_);
    fprintf(stderr, "    will connect: %d\n", connect_);
    fprintf(stderr, "       will read: %d\n", read_);
    fprintf(stderr, "      will write: %d\n", write_);
    fprintf(stderr, "     socket type: %s (%d)\n", type_, stype_);
    fprintf(stderr, "       delimiter: %s (%d)\n",
            zc_zmq_get_delimiter(delimiter_, buf),
            (int) delimiter_);
    fprintf(stderr, "      iterations: %d\n", iterations_);
    for (j = 0; j < nadd; ++j) {
        fprintf(stderr, "     address #%2d: %s\n",
                j, sadd[j].ep);
    }
    for (j = 0; j < nopt; ++j) {
        fprintf(stderr, "      option #%2d: %s (%d) = [%s]\n",
                j, sopt[j].name, sopt[j].id, sopt[j].value);
    }
}

variable_types: major int

variable_types: minor int

variable_types: patch int

variable_types:
buf
char [10]


getLength

repo: gottlieb/SLUGS

decompiled_code:
__int64 __fastcall getLength(_DWORD *a1)
{
int v1; // edx
int v2; // eax

if ( !a1 )
return 0LL;
v1 = a1[128];
v2 = a1[129];
if ( v1 > v2 )
v2 += a1[130];
return (unsigned int)(v2 - v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
int v1; // edx
int v2; // eax

if ( !a1 )
return 0LL;
v1 = a1[128];
v2 = a1[129];
if ( v1 > v2 )
v2 += a1[130];
return (unsigned int)(v2 - v1);
}

original_code:
unsigned int getLength (CBRef cB){
 if (cB != ((void *)0)){
  if (cB->head <= cB->tail){
   return (cB->tail-cB->head);
  } else{
   return (cB->size + cB->tail - cB->head);
  }
 }
 else{
  return 0;
 }
}

canonical_original_code:
unsigned int getLength(struct CircBuffer *cB){
 if (cB != ((void *)0)){
  if (cB->head <= cB->tail){
   return (cB->tail-cB->head);
  } else{
   return (cB->size + cB->tail - cB->head);
  }
 }
 else{
  return 0;
 }
}

variable_types: struct CircBuffer { unsigned char buffer[512]; int head; int tail; unsigned int size; unsigned char overflowCount; } *

return_type: unsigned int


readHead

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 512);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 512);
return result;
}

original_code:
int readHead (CBRef cB){
 if (cB != ((void *)0)){
  return (cB->head);
 }
 else{
  return 0;
 }
}

canonical_original_code:
int readHead(struct CircBuffer *cB){
 if (cB != ((void *)0)){
  return (cB->head);
 }
 else{
  return 0;
 }
}

user_defined_types: struct CircBuffer { unsigned char buffer[512]; int head; int tail; unsigned int size; unsigned char overflowCount; }


readTail

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 516);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 516);
return result;
}

original_code:
int readTail (CBRef cB){
 if (cB != ((void *)0)){
  return (cB->tail);
 }
 else{
  return 0;
 }
}

canonical_original_code:
int readTail(struct CircBuffer *cB){
 if (cB != ((void *)0)){
  return (cB->tail);
 }
 else{
  return 0;
 }
}


peak

decompiled_code:
__int64 __fastcall peak(_DWORD *a1)
{
unsigned int v1; // er8
__int64 result; // rax

v1 = 0;
if ( a1 && (unsigned int)getLength(a1) )
result = *((unsigned __int8 *)a1 + (int)a1[128]);
else
result = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1)
{
unsigned int v1; // er8
__int64 result; // rax

v1 = 0;
if ( a1 && (unsigned int)func2(a1) )
result = *((unsigned __int8 *)a1 + (int)a1[128]);
else
result = v1;
return result;
}

original_code:
unsigned char peak(CBRef cB){
 if (cB != ((void *)0))
 {
  if (getLength(cB) > 0){
   return cB->buffer[cB->head];
  }
 }
 return 0;
}

canonical_original_code:
unsigned char peak(struct CircBuffer *cB){
 if (cB != ((void *)0))
 {
  if (getLength(cB) > 0){
   return cB->buffer[cB->head];
  }
 }
 return 0;
}

return_type: unsigned char


readFront

decompiled_code:
__int64 __fastcall readFront(_DWORD *a1)
{
int v1; // er8
__int64 result; // rax
__int64 v3; // rsi
int v4; // edx

if ( !a1 )
return 4294967294LL;
v1 = getLength(a1);
result = 4294967168LL;
if ( v1 )
{
v3 = (int)a1[128];
result = *((unsigned __int8 *)a1 + v3);
v4 = v3 + 1;
if ( (unsigned int)v3 >= a1[130] - 1 )
v4 = 0;
a1[128] = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1)
{
int v1; // er8
__int64 result; // rax
__int64 v3; // rsi
int v4; // edx

if ( !a1 )
return 4294967294LL;
v1 = func2(a1);
result = 4294967168LL;
if ( v1 )
{
v3 = (int)a1[128];
result = *((unsigned __int8 *)a1 + v3);
v4 = v3 + 1;
if ( (unsigned int)v3 >= a1[130] - 1 )
v4 = 0;
a1[128] = v4;
}
return result;
}

original_code:
unsigned char readFront (CBRef cB){
 if (cB != ((void *)0))
 {
  char retVal;
  if (getLength(cB) > 0){
   retVal = cB->buffer[cB->head];
   cB->head = cB->head < (cB->size -1)? cB->head+1: 0;
   return retVal;
  }
  return 128;
 }
 return 254;
}

canonical_original_code:
unsigned char readFront(struct CircBuffer *cB){
 if (cB != ((void *)0))
 {
  char retVal;
  if (getLength(cB) > 0){
   retVal = cB->buffer[cB->head];
   cB->head = cB->head < (cB->size -1)? cB->head+1: 0;
   return retVal;
  }
  return 128;
 }
 return 254;
}

variable_types: retVal char


writeBack

decompiled_code:
__int64 __fastcall writeBack(__int64 a1, char a2)
{
int v2; // er8
__int64 result; // rax
__int64 v4; // rcx
bool v5; // cc

if ( !a1 )
return 1LL;
v2 = getLength((_DWORD *)a1);
result = (unsigned int)(*(_DWORD *)(a1 + 520) - 1);
if ( v2 == (_DWORD)result )
{
++*(_BYTE *)(a1 + 524);
}
else
{
v4 = *(int *)(a1 + 516);
*(_BYTE *)(a1 + v4) = a2;
v5 = (unsigned int)result <= (unsigned int)v4;
result = 0LL;
if ( !v5 )
result = (unsigned int)(v4 + 1);
*(_DWORD *)(a1 + 516) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char a2)
{
int v2; // er8
__int64 result; // rax
__int64 v4; // rcx
bool v5; // cc

if ( !a1 )
return 1LL;
v2 = func2((_DWORD *)a1);
result = (unsigned int)(*(_DWORD *)(a1 + 520) - 1);
if ( v2 == (_DWORD)result )
{
++*(_BYTE *)(a1 + 524);
}
else
{
v4 = *(int *)(a1 + 516);
*(_BYTE *)(a1 + v4) = a2;
v5 = (unsigned int)result <= (unsigned int)v4;
result = 0LL;
if ( !v5 )
result = (unsigned int)(v4 + 1);
*(_DWORD *)(a1 + 516) = result;
}
return result;
}

original_code:
unsigned char writeBack (CBRef cB, unsigned char data){
 if (cB != ((void *)0)){
  if (getLength (cB) == (cB->size -1)){
   cB->overflowCount ++;
  } else {
   cB->buffer[cB->tail] = data;
   cB->tail = cB->tail < (cB->size -1)? cB->tail+1: 0;
  }
 }
 else{
  return 1;
 }
}

canonical_original_code:
unsigned char writeBack(struct CircBuffer *cB, unsigned char data){
 if (cB != ((void *)0)){
  if (getLength (cB) == (cB->size -1)){
   cB->overflowCount ++;
  } else {
   cB->buffer[cB->tail] = data;
   cB->tail = cB->tail < (cB->size -1)? cB->tail+1: 0;
  }
 }
 else{
  return 1;
 }
}

variable_types:
data
unsigned char


makeEmpty

decompiled_code:
void __fastcall makeEmpty(unsigned int *a1)
{
size_t v1; // rdx

if ( a1 )
{
v1 = a1[130];
if ( (_DWORD)v1 )
a1 = (unsigned int *)memset(a1, 0, v1);
*((_QWORD *)a1 + 64) = 0LL;
*((_BYTE *)a1 + 524) = 0;
}
}

canonical_decompiled_code:
void __fastcall func8(unsigned int *a1)
{
size_t v1; // rdx

if ( a1 )
{
v1 = a1[130];
if ( (_DWORD)v1 )
a1 = (unsigned int *)memset(a1, 0, v1);
*((_QWORD *)a1 + 64) = 0LL;
*((_BYTE *)a1 + 524) = 0;
}
}

original_code:
void makeEmpty(CBRef cB){
 if (cB != ((void *)0)){
  int i;
  for(i = 0; i < cB->size; ++i)
  {
   cB->buffer[i]= 0;
  }
  cB->head = 0;
  cB->tail = 0;
  cB->overflowCount = 0;
 }
}

canonical_original_code:
void makeEmpty(struct CircBuffer *cB){
 if (cB != ((void *)0)){
  int i;
  for(i = 0; i < cB->size; ++i)
  {
   cB->buffer[i]= 0;
  }
  cB->head = 0;
  cB->tail = 0;
  cB->overflowCount = 0;
 }
}

variable_types: i int


getOverflow

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

if ( a1 )
result = *(unsigned __int8 *)(a1 + 524);
return result;
}

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

if ( a1 )
result = *(unsigned __int8 *)(a1 + 524);
return result;
}

original_code:
unsigned char getOverflow(CBRef cB){
 if (cB != ((void *)0)){
  return cB->overflowCount;
 }
}

canonical_original_code:
unsigned char getOverflow(struct CircBuffer *cB){
 if (cB != ((void *)0)){
  return cB->overflowCount;
 }
}


main

canonical_name: main

repo: hahiserw/Sectors-statistics

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
void *v4; // rsp
__int64 savedregs; // [rsp+0h] [rbp+0h] BYREF

parse_args(argc, (char **)argv);
v3 = 8LL * count;
v4 = alloca(v3);
ranges = (__int64)&savedregs;
if ( count > 0 )
memset(&savedregs, 0, v3);
parse_data();
blocks_info();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
void *v4; // rsp
__int64 savedregs; // [rsp+0h] [rbp+0h] BYREF

func8(argc, (char **)argv);
v3 = 8LL * count;
v4 = alloca(v3);
ranges = (__int64)&savedregs;
if ( count > 0 )
memset(&savedregs, 0, v3);
func10();
func11();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 parse_args(argc, argv);
 struct range *new_ranges[count];
 ranges = new_ranges;
 int i;
 for (i = 0; i < count; i++)
  ranges[i] = ((void *)0);
 parse_data();
 blocks_info();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 parse_args(argc, argv);
 struct range *new_ranges[-1];
 ranges = new_ranges;
 int i;
 for (i = 0; i < count; i++)
  ranges[i] = ((void *)0);
 parse_data();
 blocks_info();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct range { unsigned long long from; } *[-1]


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"Main thing this program does is to tell where are the largest areas without bad blocks\n",
1uLL,
0x57uLL,
stderr);
fwrite("Data file as a first line should have `:disk_lba'.\n", 1uLL, 0x33uLL, stderr);
fwrite(
"Other lines should be in format: `lba_address:access_time', where access time is in milliseconds (-1 means bad sector).\n",
1uLL,
0x78uLL,
stderr);
fprintf(stderr, "Usage: %s [-v] [-c count] file\n", (const char *)program_name);
fwrite("\t-v tells what am I doing (no, not author)\n", 1uLL, 0x2BuLL, stderr);
fwrite("\t-c number of ranges (10 is default)\n", 1uLL, 0x25uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite(
"Main thing this program does is to tell where are the largest areas without bad blocks\n",
1uLL,
0x57uLL,
stderr);
fwrite("Data file as a first line should have `:disk_lba'.\n", 1uLL, 0x33uLL, stderr);
fwrite(
"Other lines should be in format: `lba_address:access_time', where access time is in milliseconds (-1 means bad sector).\n",
1uLL,
0x78uLL,
stderr);
fprintf(stderr, "Usage: %s [-v] [-c count] file\n", (const char *)program_name);
fwrite("\t-v tells what am I doing (no, not author)\n", 1uLL, 0x2BuLL, stderr);
fwrite("\t-c number of ranges (10 is default)\n", 1uLL, 0x25uLL, stderr);
exit(1);
}

original_code:
void usage(void)
{
 fprintf(stderr, "Main thing this program does is to tell where are"
  " the largest areas without bad blocks\n");
 fprintf(stderr, "Data file as a first line should have"
  " `:disk_lba'" ".\n");
 fprintf(stderr, "Other lines should be in format:"
  " `lba_address:access_time', where access time is in"
  " milliseconds (-1 means bad sector).\n");
 fprintf(stderr, "Usage: %s [-v] [-c count] file\n", program_name);
 fprintf(stderr, "\t-v tells what am I doing (no, not author)\n");
 fprintf(stderr, "\t-c number of ranges (10 is default)\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr, "Main thing this program does is to tell where are"
  " the largest areas without bad blocks\n");
 fprintf(stderr, "Data file as a first line should have"
  " `:disk_lba'" ".\n");
 fprintf(stderr, "Other lines should be in format:"
  " `lba_address:access_time', where access time is in"
  " milliseconds (-1 means bad sector).\n");
 fprintf(stderr, "Usage: %s [-v] [-c count] file\n", program_name);
 fprintf(stderr, "\t-v tells what am I doing (no, not author)\n");
 fprintf(stderr, "\t-c number of ranges (10 is default)\n");
 exit(1);
}


decompiled_code:
int __fastcall parse_args(int argc, char **argv)
{
int v2; // eax
int v3; // eax
char *v4; // rdx
int result; // eax

program_name = (__int64)*argv;
while ( 1 )
{
v2 = getopt(argc, argv, "c:v");
if ( v2 == -1 )
break;
if ( v2 == 99 )
{
v3 = atoi(optarg);
count = v3;
if ( v3 <= 0 )
{
fprintf(stderr, "Wrong number: %i\n", (unsigned int)v3);
exit(1);
}
}
else
{
if ( v2 != 118 )
goto LABEL_11;
verbose = 1;
}
}
v4 = argv[optind];
file_path = v4;
if ( !v4 )
LABEL_11:
usage();
result = verbose;
if ( verbose )
result = fprintf(stderr, "file: %s, count: %i\n", v4, (unsigned int)count);
return result;
}

canonical_decompiled_code:
int __fastcall func8(int argc, char **argv)
{
int v2; // eax
int v3; // eax
char *v4; // rdx
int result; // eax

program_name = (__int64)*argv;
while ( 1 )
{
v2 = getopt(argc, argv, "c:v");
if ( v2 == -1 )
break;
if ( v2 == 99 )
{
v3 = atoi(optarg);
count = v3;
if ( v3 <= 0 )
{
fprintf(stderr, "Wrong number: %i\n", (unsigned int)v3);
exit(1);
}
}
else
{
if ( v2 != 118 )
goto LABEL_11;
verbose = 1;
}
}
v4 = argv[optind];
file_path = v4;
if ( !v4 )
LABEL_11:
func7();
result = verbose;
if ( verbose )
result = fprintf(stderr, "file: %s, count: %i\n", v4, (unsigned int)count);
return result;
}

original_code:
void parse_args(int argc, char *argv[])
{
 program_name = argv[0];
 int option;
 while ((option = getopt(argc, argv, "c:v")) != -1) {
  switch (option) {
  case 'c':
   count = atoi(optarg);
   if (count <= 0) {
    fprintf(stderr, "Wrong number: %i\n", count);
    exit(1);
   }
   break;
  case 'v':
   verbose = 1;
   break;
  default:
   usage();
  }
 }
 file_path = argv[optind];
 if (file_path == ((void *)0))
  usage();
 if (verbose)
  fprintf(stderr, "file: %s, count: %i\n", file_path, count);
}

variable_types: option int


decompiled_code:
__int64 __fastcall add_to_long_ranges(_QWORD *a1)
{
unsigned __int64 v2; // rbp
__int64 v3; // rsi
_QWORD *v4; // r9
int v5; // er8
int v6; // er12
__int64 v7; // rax
_QWORD *v8; // rdx
int v9; // edi
int v10; // er8
__int64 v11; // rax
__int64 v12; // rcx
__int64 result; // rax

v2 = a1[1] - *a1;
if ( verbose )
fprintf(stderr, "* got range: %llu\n", v2);
v3 = ranges;
v4 = *(_QWORD **)(ranges + 8LL * count - 8);
v5 = count;
if ( v4 && v4[1] - *v4 >= v2 )
{
result = (unsigned int)verbose;
if ( verbose )
{
fwrite("range to small\n", 1uLL, 0xFuLL, stderr);
result = 0LL;
}
}
else
{
v6 = count - 1;
if ( count - 1 >= 0 )
{
v7 = v6;
while ( 1 )
{
v8 = *(_QWORD **)(ranges + 8 * v7);
v9 = v6;
v6 = v7;
if ( v8 )
{
if ( v8[1] - *v8 >= v2 )
break;
}
if ( (int)--v7 < 0 )
goto LABEL_10;
}
v6 = v9;
}
LABEL_10:
if ( v6 == -1 )
{
fwrite("WTF?! Too small range here?\n", 1uLL, 0x1CuLL, stderr);
result = 0LL;
}
else
{
if ( v4 )
{
free(*(void **)(ranges + 8LL * count - 8));
v5 = count;
v3 = ranges;
}
v10 = v5 - 2;
v11 = v10;
if ( v6 <= v10 )
{
do
{
v12 = *(_QWORD *)(v3 + 8 * v11);
if ( v12 )
*(_QWORD *)(v3 + 8LL * ((int)v11 + 1)) = v12;
--v11;
}
while ( v6 <= (int)v11 );
}
*(_QWORD *)(v3 + 8LL * v6) = a1;
if ( verbose )
fprintf(stderr, "added at index: %i\n", (unsigned int)v6);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
unsigned __int64 v2; // rbp
__int64 v3; // rsi
_QWORD *v4; // r9
int v5; // er8
int v6; // er12
__int64 v7; // rax
_QWORD *v8; // rdx
int v9; // edi
int v10; // er8
__int64 v11; // rax
__int64 v12; // rcx
__int64 result; // rax

v2 = a1[1] - *a1;
if ( verbose )
fprintf(stderr, "* got range: %llu\n", v2);
v3 = ranges;
v4 = *(_QWORD **)(ranges + 8LL * count - 8);
v5 = count;
if ( v4 && v4[1] - *v4 >= v2 )
{
result = (unsigned int)verbose;
if ( verbose )
{
fwrite("range to small\n", 1uLL, 0xFuLL, stderr);
result = 0LL;
}
}
else
{
v6 = count - 1;
if ( count - 1 >= 0 )
{
v7 = v6;
while ( 1 )
{
v8 = *(_QWORD **)(ranges + 8 * v7);
v9 = v6;
v6 = v7;
if ( v8 )
{
if ( v8[1] - *v8 >= v2 )
break;
}
if ( (int)--v7 < 0 )
goto LABEL_10;
}
v6 = v9;
}
LABEL_10:
if ( v6 == -1 )
{
fwrite("WTF?! Too small range here?\n", 1uLL, 0x1CuLL, stderr);
result = 0LL;
}
else
{
if ( v4 )
{
free(*(void **)(ranges + 8LL * count - 8));
v5 = count;
v3 = ranges;
}
v10 = v5 - 2;
v11 = v10;
if ( v6 <= v10 )
{
do
{
v12 = *(_QWORD *)(v3 + 8 * v11);
if ( v12 )
*(_QWORD *)(v3 + 8LL * ((int)v11 + 1)) = v12;
--v11;
}
while ( v6 <= (int)v11 );
}
*(_QWORD *)(v3 + 8LL * v6) = a1;
if ( verbose )
fprintf(stderr, "added at index: %i\n", (unsigned int)v6);
result = 1LL;
}
}
return result;
}

original_code:
int add_to_long_ranges(struct range *range)
{
 unsigned long long new_range = range->to - range->from;
 if (verbose)
  fprintf(stderr, "* got range: %llu\n", new_range);
 struct range *last = ranges[count-1];
 if (last != ((void *)0) && new_range <= last->to - last->from) {
  if (verbose)
   fprintf(stderr, "range to small\n");
  return 0;
 }
 int i;
 struct range *temp;
 int my_new_place = count - 1;
 for (i = count - 1; i >= 0; i--) {
  temp = ranges[i];
  if (temp == ((void *)0)) {
   my_new_place = i;
   continue;
  }
  if (new_range > temp->to - temp->from)
   my_new_place = i;
  else
   break;
 }
 if (my_new_place == -1) {
  fprintf(stderr, "WTF?! Too small range here?\n");
  return 0;
 }
 if (last != ((void *)0))
  free(last);
 for (i = count - 2; i >= my_new_place; i--) {
  temp = ranges[i];
  if (temp == ((void *)0))
   continue;
  ranges[i+1] = ranges[i];
 }
 ranges[my_new_place] = range;
 if (verbose)
  fprintf(stderr, "added at index: %i\n", my_new_place);
 return 1;
}

variable_types: struct range { unsigned long long from; } *


decompiled_code:
int blocks_info()
{
__int64 v0; // rbx
_QWORD *v1; // rbp

printf("%20s %20s %20s\n", "LBA start", "LBA end", "Blocks");
if ( count > 0 )
{
v0 = 0LL;
do
{
v1 = *(_QWORD **)(ranges + 8 * v0);
if ( !v1 )
break;
++v0;
printf("%20llu %20llu %20llu\n", *v1, v1[1], v1[1] - *v1);
free(v1);
}
while ( count > (int)v0 );
}
return printf("Badblocks: %llu\n", badblocks);
}

canonical_decompiled_code:
int func11()
{
__int64 v0; // rbx
_QWORD *v1; // rbp

printf("%20s %20s %20s\n", "LBA start", "LBA end", "Blocks");
if ( count > 0 )
{
v0 = 0LL;
do
{
v1 = *(_QWORD **)(ranges + 8 * v0);
if ( !v1 )
break;
++v0;
printf("%20llu %20llu %20llu\n", *v1, v1[1], v1[1] - *v1);
free(v1);
}
while ( count > (int)v0 );
}
return printf("Badblocks: %llu\n", badblocks);
}

original_code:
void blocks_info(void)
{
 int i;
 struct range *temp;
 printf("%20s %20s %20s\n", "LBA start", "LBA end", "Blocks");
 for (i = 0; i < count; i++) {
  temp = ranges[i];
  if (temp == ((void *)0))
   break;
  printf("%20llu %20llu %20llu\n",
   temp->from, temp->to, temp->to - temp->from);
  free(temp);
 }
 printf("Badblocks: %llu\n", badblocks);
}

canonical_original_code:
void blocks_info()
{
 int i;
 struct range *temp;
 printf("%20s %20s %20s\n", "LBA start", "LBA end", "Blocks");
 for (i = 0; i < count; i++) {
  temp = ranges[i];
  if (temp == ((void *)0))
   break;
  printf("%20llu %20llu %20llu\n",
   temp->from, temp->to, temp->to - temp->from);
  free(temp);
 }
 printf("Badblocks: %llu\n", badblocks);
}

user_defined_types: struct range { unsigned long long from; }


decompiled_code:
void __fastcall __noreturn do_server_stuff(int fd)
{
int v1; // ebx
int v2; // ebp
int v3; // eax
socklen_t addr_len; // [rsp+8h] [rbp-A0h] BYREF
float buf; // [rsp+Ch] [rbp-9Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF

v1 = 4;
addr_len = 128;
while ( 1 )
{
v2 = accept(fd, &addr, &addr_len);
if ( v2 == -1 )
break;
puts("New Connection recieved");
v3 = recv(v2, &buf, v1, 0);
v1 = v3;
if ( v3 )
{
if ( v3 == -1 )
perror("recv");
else
printf("Recieved float = %f\n", buf);
}
else
{
puts("Connection closed");
}
close(v2);
puts("Done, closing connection");
}
perror("accept");
close(fd);
exit(4);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(int fd)
{
int v1; // ebx
int v2; // ebp
int v3; // eax
socklen_t addr_len; // [rsp+8h] [rbp-A0h] BYREF
float buf; // [rsp+Ch] [rbp-9Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF

v1 = 4;
addr_len = 128;
while ( 1 )
{
v2 = accept(fd, &addr, &addr_len);
if ( v2 == -1 )
break;
puts("New Connection recieved");
v3 = recv(v2, &buf, v1, 0);
v1 = v3;
if ( v3 )
{
if ( v3 == -1 )
perror("recv");
else
printf("Recieved float = %f\n", buf);
}
else
{
puts("Connection closed");
}
close(v2);
puts("Done, closing connection");
}
perror("accept");
close(fd);
exit(4);
}

original_code:
void do_server_stuff(int servfd)
{
 int clientfd;
 struct sockaddr_storage clientaddr;
 socklen_t clientaddrlen = sizeof clientaddr;
 float recv_buff;
 int buff_len = sizeof recv_buff;
 while(1) {
  if ((clientfd = accept(servfd, (struct sockaddr *)&clientaddr, &clientaddrlen)) == -1) {
   perror("accept");
   close(servfd);
   exit(4);
  }
  printf("New Connection recieved\n");
  buff_len = recv(clientfd, &recv_buff, buff_len, 0);
  if (buff_len == 0)
   printf("Connection closed\n");
  else if (buff_len == -1)
   perror("recv");
  else
   printf("Recieved float = %f\n", recv_buff);
  close(clientfd);
  printf("Done, closing connection\n");
 }
}

canonical_original_code:
void do_server_stuff(int servfd)
{
 int clientfd;
 struct sockaddr_storage clientaddr;
 unsigned int clientaddrlen = sizeof clientaddr;
 float recv_buff;
 int buff_len = sizeof recv_buff;
 while(1) {
  if ((clientfd = accept(servfd, (struct sockaddr *)&clientaddr, &clientaddrlen)) == -1) {
   perror("accept");
   close(servfd);
   exit(4);
  }
  printf("New Connection recieved\n");
  buff_len = recv(clientfd, &recv_buff, buff_len, 0);
  if (buff_len == 0)
   printf("Connection closed\n");
  else if (buff_len == -1)
   perror("recv");
  else
   printf("Recieved float = %f\n", recv_buff);
  close(clientfd);
  printf("Done, closing connection\n");
 }
}

variable_types: servfd int

variable_types: clientfd int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
clientaddrlen
unsigned int

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
struct addrinfo *v4; // rbx
struct addrinfo *v5; // rdi
int v6; // eax
int v7; // ebp
const char *v8; // rax
int optval; // [rsp+0h] [rbp-54h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Ch] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
optval = 1;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(0LL, "4000", &req, &pai);
if ( !v3 )
{
v4 = pai;
v5 = pai;
if ( pai )
{
do
{
v6 = socket(v4->ai_family, v4->ai_socktype, v4->ai_protocol);
v7 = v6;
if ( v6 == -1 )
{
perror("socket");
}
else if ( setsockopt(v6, 1, 2, &optval, 4u) == -1 )
{
perror("setsockopt");
close(v7);
}
else
{
if ( bind(v7, v4->ai_addr, v4->ai_addrlen) != -1 )
{
freeaddrinfo(pai);
if ( listen(v7, 5) != -1 )
{
puts("Waiting for connections...");
do_server_stuff(v7);
}
perror("listen");
close(v7);
exit(3);
}
perror("bind");
close(v7);
}
v4 = v4->ai_next;
}
while ( v4 );
v5 = pai;
}
freeaddrinfo(v5);
fwrite("Not able to bind\n", 1uLL, 0x11uLL, stderr);
exit(2);
}
v8 = gai_strerror(v3);
fprintf(stderr, "getaddrinfo : %s\n", v8);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
struct addrinfo *v4; // rbx
struct addrinfo *v5; // rdi
int v6; // eax
int v7; // ebp
const char *v8; // rax
int optval; // [rsp+0h] [rbp-54h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Ch] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
optval = 1;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(0LL, "4000", &req, &pai);
if ( !v3 )
{
v4 = pai;
v5 = pai;
if ( pai )
{
do
{
v6 = socket(v4->ai_family, v4->ai_socktype, v4->ai_protocol);
v7 = v6;
if ( v6 == -1 )
{
perror("socket");
}
else if ( setsockopt(v6, 1, 2, &optval, 4u) == -1 )
{
perror("setsockopt");
close(v7);
}
else
{
if ( bind(v7, v4->ai_addr, v4->ai_addrlen) != -1 )
{
freeaddrinfo(pai);
if ( listen(v7, 5) != -1 )
{
puts("Waiting for connections...");
func7(v7);
}
perror("listen");
close(v7);
exit(3);
}
perror("bind");
close(v7);
}
v4 = v4->ai_next;
}
while ( v4 );
v5 = pai;
}
freeaddrinfo(v5);
fwrite("Not able to bind\n", 1uLL, 0x11uLL, stderr);
exit(2);
}
v8 = gai_strerror(v3);
fprintf(stderr, "getaddrinfo : %s\n", v8);
exit(1);
}

original_code:
int main(int agrc, char * argv[])
{
 int servfd;
 int retval;
 int yes = 1;
 struct addrinfo hints, * servinfo, * p;
 memset(&hints, 0, sizeof hints);
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_flags = 0x0001;
 if ((retval = getaddrinfo(((void *)0), ("4000"), &hints, &servinfo)) != 0) {
  fprintf(stderr, "getaddrinfo : %s\n", gai_strerror(retval));
  exit(1);
 }
 for (p = servinfo; p != ((void *)0); p = p->ai_next) {
  if((servfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
   perror("socket");
   continue;
  }
  if (setsockopt(servfd, 1, 2, &yes, sizeof(int)) == -1) {
   perror("setsockopt");
   close(servfd);
   continue;
  }
  if (bind(servfd, p->ai_addr, p->ai_addrlen) == -1) {
   perror("bind");
   close(servfd);
   continue;
  }
  break;
 }
 freeaddrinfo(servinfo);
 if (p == ((void *)0)) {
  fprintf(stderr, "Not able to bind\n");
  exit(2);
 }
 if (listen(servfd, (5)) == -1) {
  perror("listen");
  close(servfd);
  exit(3);
 }
 printf("Waiting for connections...\n");
 do_server_stuff(servfd);
 close(servfd);
 return 0;
}

canonical_original_code:
int main(int agrc, char *argv[])
{
 int servfd;
 int retval;
 int yes = 1;
 struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *p;
 memset(&hints, 0, sizeof hints);
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_flags = 0x0001;
 if ((retval = getaddrinfo(((void *)0), ("4000"), &hints, &servinfo)) != 0) {
  fprintf(stderr, "getaddrinfo : %s\n", gai_strerror(retval));
  exit(1);
 }
 for (p = servinfo; p != ((void *)0); p = p->ai_next) {
  if((servfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
   perror("socket");
   continue;
  }
  if (setsockopt(servfd, 1, 2, &yes, sizeof(int)) == -1) {
   perror("setsockopt");
   close(servfd);
   continue;
  }
  if (bind(servfd, p->ai_addr, p->ai_addrlen) == -1) {
   perror("bind");
   close(servfd);
   continue;
  }
  break;
 }
 freeaddrinfo(servinfo);
 if (p == ((void *)0)) {
  fprintf(stderr, "Not able to bind\n");
  exit(2);
 }
 if (listen(servfd, (5)) == -1) {
  perror("listen");
  close(servfd);
  exit(3);
 }
 printf("Waiting for connections...\n");
 do_server_stuff(servfd);
 close(servfd);
 return 0;
}

variable_types: agrc int

variable_types: retval int

variable_types: yes int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


repo: howrujh/tp

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BOOL8 v3; // rcx
int v4; // er12
pthread_t newthread; // [rsp+8h] [rbp-90h] BYREF
void *thread_return[12]; // [rsp+10h] [rbp-88h] BYREF
int v8; // [rsp+70h] [rbp-28h]

if ( (unsigned int)(argc - 1) > 1 )
return -1;
v3 = 1LL;
if ( argc == 2 )
v3 = strcmp(argv[1], "pal") != 0;
kill_thread = 0;
if ( pthread_create(&newthread, 0LL, thread_pattern_gen, (void *)v3) < 0 )
{
perror("thread create error:");
exit(0);
}
do
{
do
{
memset(thread_return, 0, sizeof(thread_return));
v8 = 0;
__isoc99_scanf();
}
while ( LODWORD(thread_return[0]) != 1953069157 );
}
while ( BYTE4(thread_return[0]) );
v4 = 0;
kill_thread = 1;
pthread_join(newthread, thread_return);
puts("test pattern generator normally closed");
return v4;
}

original_code:
int main(int argc, char* argv[])
{
 int vmode = 1;
 if(!(argc == 1 || argc ==2)){
  return -1;
 }
 if(argc ==2 && strcmp(argv[1], "pal") ==0 ){
  vmode =0;
 }else{
  vmode =1;
 }
 kill_thread = 0;
 pthread_t thread_t;
 int thread_ret;
 if(pthread_create(&thread_t, ((void *)0), thread_pattern_gen, (void*)vmode) < 0){
  perror("thread create error:");
  exit(0);
 }
 while(1){
  char input[100];
  memset(input,0,sizeof(input));
  scanf("%s", input);
  if(strcmp(input, "exit")==0){
   kill_thread= 1;
   break;
  }else if(strcmp(input, "exit")==0){
  }else{
  }
 }
 pthread_join(thread_t,(void**)&thread_ret);
 printf("test pattern generator normally closed\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int vmode = 1;
 if(!(argc == 1 || argc ==2)){
  return -1;
 }
 if(argc ==2 && strcmp(argv[1], "pal") ==0 ){
  vmode =0;
 }else{
  vmode =1;
 }
 kill_thread = 0;
 unsigned long thread_t;
 int thread_ret;
 if(pthread_create(&thread_t, ((void *)0), thread_pattern_gen, (void *)vmode) < 0){
  perror("thread create error:");
  exit(0);
 }
 while(1){
  char input[100];
  memset(input,0,sizeof(input));
  scanf("%s", input);
  if(strcmp(input, "exit")==0){
   kill_thread= 1;
   break;
  }else if(strcmp(input, "exit")==0){
  }else{
  }
 }
 pthread_join(thread_t,(void **)&thread_ret);
 printf("test pattern generator normally closed\n");
 return 0;
}

variable_types: vmode int

variable_types:
input
char [100]


repo: hyper/libparsehttp

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

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

original_code:
void parse_reset(parsehttp_t *parse)
{
 if (parse->buffer) {
  free(parse->buffer);
  parse->buffer = ((void *)0);
 }
 parse->length = 0;
 parse->pos = 0;
 parse->dataleft = 0;
 parse->state = state_request;
}

canonical_original_code:
void parse_reset(struct parsehttp_t *parse)
{
 if (parse->buffer) {
  free(parse->buffer);
  parse->buffer = ((void *)0);
 }
 parse->length = 0;
 parse->pos = 0;
 parse->dataleft = 0;
 parse->state = state_request;
}

variable_types: struct parsehttp_t { char *buffer; int length; int pos; int dataleft; enum { state_request=0, state_headers=1, state_data=2, state_done=3 } state; void (*cb_method)(char *method, void *arg); void (*cb_path)(char *path, void *arg); void (*cb_params)(char *params, void *arg); void (*cb_version)(char *version, void *arg); void (*cb_header)(char *key, char *value, void *arg); void (*cb_formdata)(char *key, char *value, void *arg); void (*cb_cookie)(char *key, char *value, void *arg); void (*cb_host)(char *host, int port, void *arg); void (*cb_datalength)(int length, void *arg); void (*cb_data)(char *data, int length, int leftover, void *arg); void (*cb_complete)(void *arg); void *arg; short internally_created; } *


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

if ( !ptr )
__assert_fail("parse", "libparsehttp.c", 0x5Cu, "parse_free");
v2 = *(void **)ptr;
if ( v2 )
free(v2);
if ( *((_WORD *)ptr + 60) > 1u )
__assert_fail(
"parse->internally_created == 0 || parse->internally_created == 1",
"libparsehttp.c",
0x62u,
"parse_free");
if ( *((_WORD *)ptr + 60) == 1 )
free(ptr);
}

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

if ( !ptr )
__assert_fail("parse", "libparsehttp.c", 0x5Cu, "parse_free");
v2 = *(void **)ptr;
if ( v2 )
free(v2);
if ( *((_WORD *)ptr + 60) > 1u )
__assert_fail(
"parse->internally_created == 0 || parse->internally_created == 1",
"libparsehttp.c",
0x62u,
"parse_free");
if ( *((_WORD *)ptr + 60) == 1 )
free(ptr);
}

original_code:
void parse_free(parsehttp_t *parse)
{
 ((void) sizeof ((parse) ? 1 : 0), __extension__ ({ if (parse) ; else __assert_fail ("parse", "libparsehttp.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 if (parse->buffer) {
  free(parse->buffer);
 }
 ((void) sizeof ((parse->internally_created == 0 || parse->internally_created == 1) ? 1 : 0), __extension__ ({ if (parse->internally_created == 0 || parse->internally_created == 1) ; else __assert_fail ("parse->internally_created == 0 || parse->internally_created == 1", "libparsehttp.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 if (parse->internally_created > 0) {
  free(parse);
 }
}

canonical_original_code:
void parse_free(struct parsehttp_t *parse)
{
 ((void) sizeof ((parse) ? 1 : 0), __extension__ ({ if (parse) ; else __assert_fail ("parse", "libparsehttp.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 if (parse->buffer) {
  free(parse->buffer);
 }
 ((void) sizeof ((parse->internally_created == 0 || parse->internally_created == 1) ? 1 : 0), __extension__ ({ if (parse->internally_created == 0 || parse->internally_created == 1) ; else __assert_fail ("parse->internally_created == 0 || parse->internally_created == 1", "libparsehttp.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 if (parse->internally_created > 0) {
  free(parse);
 }
}

user_defined_types: struct parsehttp_t { char *buffer; int length; int pos; int dataleft; enum { state_request=0, state_headers=1, state_data=2, state_done=3 } state; void (*cb_method)(char *method, void *arg); void (*cb_path)(char *path, void *arg); void (*cb_params)(char *params, void *arg); void (*cb_version)(char *version, void *arg); void (*cb_header)(char *key, char *value, void *arg); void (*cb_formdata)(char *key, char *value, void *arg); void (*cb_cookie)(char *key, char *value, void *arg); void (*cb_host)(char *host, int port, void *arg); void (*cb_datalength)(int length, void *arg); void (*cb_data)(char *data, int length, int leftover, void *arg); void (*cb_complete)(void *arg); void *arg; short internally_created; }


decompiled_code:
__int64 parse_version()
{
return 1536LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 1536LL;
}

original_code:
unsigned int parse_version(void)
{
 return(0x00000600);
}

canonical_original_code:
unsigned int parse_version()
{
 return(0x00000600);
}