decompiled_code:
void *__fastcall mem_chunk(__int64 a1, unsigned __int64 a2, size_t a3, const char *a4)
{
int v6; // ebp
void *v7; // r14
unsigned __int64 v8; // rax
char *v9; // rax
char *v10; // rsi
void *result; // rax
char *v12; // rax
void *v13; // rdi
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
int *v20; // rax
char *v21; // rax
int *v22; // rax
char *v23; // rax
void *v24; // rdi
char *v25; // rax
void *addr; // [rsp+0h] [rbp-D8h]
char *addrb; // [rsp+0h] [rbp-D8h]
int *addra; // [rsp+0h] [rbp-D8h]
size_t len; // [rsp+8h] [rbp-D0h]
size_t lena; // [rsp+8h] [rbp-D0h]
struct stat buf; // [rsp+10h] [rbp-C8h] BYREF

sigill_logobj = a1;
signal(4, (__sighandler_t)sigill_handler);
if ( sigill_error || (v6 = open(a4, 0), v6 == -1) )
{
v16 = _errno_location();
v7 = 0LL;
v17 = strerror(*v16);
log_append(a1, 1LL, 4LL, "Failed to open memory buffer (%s): %s", a4, v17);
goto LABEL_13;
}
if ( sigill_error || (v7 = malloc(a3)) == 0LL )
{
v18 = _errno_location();
v7 = 0LL;
v19 = strerror(*v18);
log_append(a1, 1LL, 4LL, "malloc: %s", v19);
}
else
{
if ( fstat(v6, &buf) == -1 )
{
v20 = _errno_location();
v21 = strerror(*v20);
log_append(a1, 1LL, 4LL, "fstat: %s", v21);
}
else if ( (buf.st_mode & 0xF000) == 0x8000 && (__int64)(a3 + a2) > buf.st_size )
{
v14 = _errno_location();
v15 = strerror(*v14);
log_append(a1, 1LL, 4LL, "mmap: Can't map beyond end of file %s: %s", a4, v15);
}
else
{
v8 = sysconf(30);
len = a2 % v8;
addr = (void *)(a3 + a2 % v8);
v9 = (char *)mmap(0LL, (size_t)addr, 1, 1, v6, a2 - a2 % v8);
if ( v9 != (char *)-1LL )
{
v10 = &v9[len];
lena = (size_t)addr;
addrb = v9;
safe_memcpy(v7, v10, a3);
if ( munmap(addrb, lena) == -1 )
{
v22 = _errno_location();
v23 = strerror(*v22);
log_append(a1, 1LL, 4LL, "%s (munmap): %s", a4, v23);
v24 = v7;
v7 = 0LL;
free(v24);
}
goto LABEL_10;
}
addra = _errno_location();
v12 = strerror(*addra);
log_append(a1, 1LL, 4LL, "%s (mmap): %s", a4, v12);
if ( lseek(v6, a2, 0) == -1 )
{
v25 = strerror(*addra);
log_append(a1, 1LL, 4LL, "%s (lseek): %s", a4, v25);
}
else if ( !sigill_error )
{
myread(a1, v6, (__int64)v7, a3, a4);
}
}
v13 = v7;
v7 = 0LL;
free(v13);
}
LABEL_10:
if ( v6 >= 0 && close(v6) == -1 )
perror(a4);
LABEL_13:
signal(4, 0LL);
result = v7;
sigill_logobj = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, unsigned __int64 a2, size_t a3, const char *a4)
{
int v6; // ebp
void *v7; // r14
unsigned __int64 v8; // rax
char *v9; // rax
char *v10; // rsi
void *result; // rax
char *v12; // rax
void *v13; // rdi
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
int *v20; // rax
char *v21; // rax
int *v22; // rax
char *v23; // rax
void *v24; // rdi
char *v25; // rax
void *addr; // [rsp+0h] [rbp-D8h]
char *addrb; // [rsp+0h] [rbp-D8h]
int *addra; // [rsp+0h] [rbp-D8h]
size_t len; // [rsp+8h] [rbp-D0h]
size_t lena; // [rsp+8h] [rbp-D0h]
struct stat buf; // [rsp+10h] [rbp-C8h] BYREF

sigill_logobj = a1;
signal(4, (__sighandler_t)sigill_handler);
if ( sigill_error || (v6 = open(a4, 0), v6 == -1) )
{
v16 = _errno_location();
v7 = 0LL;
v17 = strerror(*v16);
log_append(a1, 1LL, 4LL, "Failed to open memory buffer (%s): %s", a4, v17);
goto LABEL_13;
}
if ( sigill_error || (v7 = malloc(a3)) == 0LL )
{
v18 = _errno_location();
v7 = 0LL;
v19 = strerror(*v18);
log_append(a1, 1LL, 4LL, "malloc: %s", v19);
}
else
{
if ( fstat(v6, &buf) == -1 )
{
v20 = _errno_location();
v21 = strerror(*v20);
log_append(a1, 1LL, 4LL, "fstat: %s", v21);
}
else if ( (buf.st_mode & 0xF000) == 0x8000 && (__int64)(a3 + a2) > buf.st_size )
{
v14 = _errno_location();
v15 = strerror(*v14);
log_append(a1, 1LL, 4LL, "mmap: Can't map beyond end of file %s: %s", a4, v15);
}
else
{
v8 = sysconf(30);
len = a2 % v8;
addr = (void *)(a3 + a2 % v8);
v9 = (char *)mmap(0LL, (size_t)addr, 1, 1, v6, a2 - a2 % v8);
if ( v9 != (char *)-1LL )
{
v10 = &v9[len];
lena = (size_t)addr;
addrb = v9;
func2(v7, v10, a3);
if ( munmap(addrb, lena) == -1 )
{
v22 = _errno_location();
v23 = strerror(*v22);
log_append(a1, 1LL, 4LL, "%s (munmap): %s", a4, v23);
v24 = v7;
v7 = 0LL;
free(v24);
}
goto LABEL_10;
}
addra = _errno_location();
v12 = strerror(*addra);
log_append(a1, 1LL, 4LL, "%s (mmap): %s", a4, v12);
if ( lseek(v6, a2, 0) == -1 )
{
v25 = strerror(*addra);
log_append(a1, 1LL, 4LL, "%s (lseek): %s", a4, v25);
}
else if ( !sigill_error )
{
func0(a1, v6, (__int64)v7, a3, a4);
}
}
v13 = v7;
v7 = 0LL;
free(v13);
}
LABEL_10:
if ( v6 >= 0 && close(v6) == -1 )
perror(a4);
LABEL_13:
signal(4, 0LL);
result = v7;
sigill_logobj = 0LL;
return result;
}

original_code:
void *mem_chunk(Log_t *logp, size_t base, size_t len, const char *devmem)
{
        void *p;
        int fd = -1;
        struct stat statbuf;
 size_t mmoffset;
        void *mmp;
        sigill_logobj = logp;
        signal(4, sigill_handler);
        if(sigill_error || (fd = open(devmem, 00)) == -1) {
                log_append(logp, LOGFL_NORMAL, 4,
                           "Failed to open memory buffer (%s): %s",
                           devmem, strerror((*__errno_location ())));
                p = ((void *)0);
                goto exit;
        }
        if(sigill_error || (p = malloc(len)) == ((void *)0)) {
                log_append(logp, LOGFL_NORMAL, 4,"malloc: %s", strerror((*__errno_location ())));
                p = ((void *)0);
                goto exit;
        }
        if (sigill_error || fstat(fd, &statbuf) == -1 )
        {
                log_append(logp, LOGFL_NORMAL, 4,"fstat: %s", strerror((*__errno_location ())));
                goto err_free;
        }
        if ((sigill_error || ((((statbuf.st_mode)) & 0170000) == (0100000))) && (__off_t)(base + (off_t)len) > statbuf.st_size )
        {
                log_append(logp, LOGFL_NORMAL, 4,
                                "mmap: Can't map beyond end of file %s: %s",
                                devmem, strerror((*__errno_location ())));
                goto err_free;
        }
        mmoffset = base % sysconf(_SC_PAGESIZE);
        mmp = mmap(((void *)0), mmoffset + len, 0x1, 0x01, fd, base - mmoffset);
        if(sigill_error || (mmp == ((void *) -1))) {
                log_append(logp, LOGFL_NORMAL, 4, "%s (mmap): %s", devmem, strerror((*__errno_location ())));
   goto try_read;
        }
        safe_memcpy(p, (u8 *) mmp + mmoffset, len);
        if (sigill_error) {
                log_append(logp, LOGFL_NODUPS, 4,
                           "Failed to do memcpy() due to SIGILL signal");
                free(p);
                p = ((void *)0);
                goto exit;
        }
        if(sigill_error || (munmap(mmp, mmoffset + len) == -1)) {
                log_append(logp, LOGFL_NORMAL, 4, "%s (munmap): %s", devmem, strerror((*__errno_location ())));
                free(p);
                p = ((void *)0);
                goto exit;
        }
 goto exit;
try_read:
        if (lseek(fd, base, 0) == -1 )
        {
                log_append(logp, LOGFL_NORMAL, 4, "%s (lseek): %s", devmem, strerror((*__errno_location ())));
                goto err_free;
        }
        if(sigill_error || (myread(logp, fd, p, len, devmem) == 0)) {
                free(p);
                p = ((void *)0);
                goto exit;
        }
err_free:
        free(p);
        p = ((void *)0);
exit:
        if (fd >= 0) {
            if(close(fd) == -1)
                perror(devmem);
        }
        signal(4, ((__sighandler_t) 0));
        sigill_logobj = ((void *)0);
        return p;
}

canonical_original_code:
void *mem_chunk(struct _Log_t *logp, unsigned long base, unsigned long len, char *devmem)
{
        void *p;
        int fd = -1;
        struct stat statbuf;
 unsigned long mmoffset;
        void *mmp;
        sigill_logobj = logp;
        signal(4, sigill_handler);
        if(sigill_error || (fd = open(devmem, 00)) == -1) {
                log_append(logp, LOGFL_NORMAL, 4,
                           "Failed to open memory buffer (%s): %s",
                           devmem, strerror((*__errno_location ())));
                p = ((void *)0);
                goto exit;
        }
        if(sigill_error || (p = malloc(len)) == ((void *)0)) {
                log_append(logp, LOGFL_NORMAL, 4,"malloc: %s", strerror((*__errno_location ())));
                p = ((void *)0);
                goto exit;
        }
        if (sigill_error || fstat(fd, &statbuf) == -1 )
        {
                log_append(logp, LOGFL_NORMAL, 4,"fstat: %s", strerror((*__errno_location ())));
                goto err_free;
        }
        if ((sigill_error || ((((statbuf.st_mode)) & 0170000) == (0100000))) && (__off_t)(base + (long)len) > statbuf.st_size )
        {
                log_append(logp, LOGFL_NORMAL, 4,
                                "mmap: Can't map beyond end of file %s: %s",
                                devmem, strerror((*__errno_location ())));
                goto err_free;
        }
        mmoffset = base % sysconf(_SC_PAGESIZE);
        mmp = mmap(((void *)0), mmoffset + len, 0x1, 0x01, fd, base - mmoffset);
        if(sigill_error || (mmp == ((void *) -1))) {
                log_append(logp, LOGFL_NORMAL, 4, "%s (mmap): %s", devmem, strerror((*__errno_location ())));
   goto try_read;
        }
        safe_memcpy(p, (unsigned char *) mmp + mmoffset, len);
        if (sigill_error) {
                log_append(logp, LOGFL_NODUPS, 4,
                           "Failed to do memcpy() due to SIGILL signal");
                free(p);
                p = ((void *)0);
                goto exit;
        }
        if(sigill_error || (munmap(mmp, mmoffset + len) == -1)) {
                log_append(logp, LOGFL_NORMAL, 4, "%s (munmap): %s", devmem, strerror((*__errno_location ())));
                free(p);
                p = ((void *)0);
                goto exit;
        }
 goto exit;
try_read:
        if (lseek(fd, base, 0) == -1 )
        {
                log_append(logp, LOGFL_NORMAL, 4, "%s (lseek): %s", devmem, strerror((*__errno_location ())));
                goto err_free;
        }
        if(sigill_error || (myread(logp, fd, p, len, devmem) == 0)) {
                free(p);
                p = ((void *)0);
                goto exit;
        }
err_free:
        free(p);
        p = ((void *)0);
exit:
        if (fd >= 0) {
            if(close(fd) == -1)
                perror(devmem);
        }
        signal(4, ((void (*)(int)) 0));
        sigill_logobj = ((void *)0);
        return p;
}

variable_types:
base
unsigned long

variable_types:
len
unsigned long

variable_types:
devmem
char *

variable_types:
p
void *

variable_types:
mmoffset
unsigned long

variable_types:
mmp
void *

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


repo: nima/python-dmidecode

decompiled_code:
unsigned __int64 __fastcall u64_range(__int64 a1, __int64 a2)
{
return ((unsigned __int64)(unsigned int)(((_DWORD)a2 + 1 == (_DWORD)a1) + ((unsigned __int64)(a2 - a1) >> 32)) << 32) | (unsigned int)(a2 + 1 - a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, __int64 a2)
{
return ((unsigned __int64)(unsigned int)(((_DWORD)a2 + 1 == (_DWORD)a1) + ((unsigned __int64)(a2 - a1) >> 32)) << 32) | (unsigned int)(a2 + 1 - a1);
}

original_code:
u64 u64_range(u64 start, u64 end)
{
 u64 res;
 res.h = end.h - start.h;
 res.l = end.l - start.l;
 if (end.l < start.l)
  res.h--;
 if (++res.l == 0)
  res.h++;
 return res;
}

canonical_original_code:
struct u64 u64_range(struct u64 start, struct u64 end)
{
 struct u64 res;
 res.h = end.h - start.h;
 res.l = end.l - start.l;
 if (end.l < start.l)
  res.h--;
 if (++res.l == 0)
  res.h++;
 return res;
}

variable_types:
start
struct u64

variable_types:
end
struct u64

variable_types: struct u64 { unsigned int l; unsigned int h; }


decompiled_code:
__int64 __fastcall overwrite_smbios3_address(_BYTE *a1)
{
int v1; // eax
int v2; // edx
int v3; // eax
__int64 result; // rax

v1 = (unsigned __int8)(a1[5] + a1[18]) + (unsigned __int8)a1[19] - 32;
LOBYTE(v1) = a1[23] + a1[22] + a1[21] + a1[20] + v1;
v2 = v1;
v3 = (unsigned __int8)(a1[16] + a1[17]);
*((_QWORD *)a1 + 2) = 32LL;
result = (unsigned int)(v2 + v3);
a1[5] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax
int v2; // edx
int v3; // eax
__int64 result; // rax

v1 = (unsigned __int8)(a1[5] + a1[18]) + (unsigned __int8)a1[19] - 32;
LOBYTE(v1) = a1[23] + a1[22] + a1[21] + a1[20] + v1;
v2 = v1;
v3 = (unsigned __int8)(a1[16] + a1[17]);
*((_QWORD *)a1 + 2) = 32LL;
result = (unsigned int)(v2 + v3);
a1[5] = result;
return result;
}

variable_types:
buf
unsigned char *

return_type: void


decompiled_code:
__int64 __fastcall dmi_table_dump(__int64 a1, unsigned int a2, __int64 a3)
{
return write_dump(32LL, a2, a1, a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, __int64 a3)
{
return write_dump(32LL, a2, a1, a3, 0LL);
}

original_code:
void dmi_table_dump(const u8 *buf, u32 len, const char *dumpfile)
{
        write_dump(32, len, buf, dumpfile, 0);
}

canonical_original_code:
void dmi_table_dump(unsigned char *buf, unsigned int len, char *dumpfile)
{
        write_dump(32, len, buf, dumpfile, 0);
}

variable_types:
len
unsigned int

variable_types:
dumpfile
char *


decompiled_code:
unsigned __int64 __fastcall dmi_table(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5, char a6, __int64 a7)
{
__int64 v8; // rax
unsigned int v9; // ebx
void *v10; // rbp
__int64 v12; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v13; // [rsp+8h] [rbp-20h]

v13 = __readfsqword(0x28u);
v12 = a2;
if ( (a6 & 1) != 0 )
a1 = 0LL;
v8 = read_file(0LL, a1, &v12, a5);
v9 = v12;
v10 = (void *)v8;
if ( !v8 )
puts("read failed");
dmi_table_dump((__int64)v10, v9, a7);
free(v10);
return v13 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5, char a6, __int64 a7)
{
__int64 v8; // rax
unsigned int v9; // ebx
void *v10; // rbp
__int64 v12; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v13; // [rsp+8h] [rbp-20h]

v13 = __readfsqword(0x28u);
v12 = a2;
if ( (a6 & 1) != 0 )
a1 = 0LL;
v8 = read_file(0LL, a1, &v12, a5);
v9 = v12;
v10 = (void *)v8;
if ( !v8 )
puts("read failed");
func1((__int64)v10, v9, a7);
free(v10);
return v13 - __readfsqword(0x28u);
}

original_code:
void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
                      u32 flags, const char *dumpfile)
{
        u8 *buf;
        size_t size = len;
        buf = read_file(((void *)0), flags & (1 << 0) ? 0 : base,
                        &size, devmem);
        len = size;
        if (buf == ((void *)0))
        {
                printf("read failed\n");
        }
        dmi_table_dump(buf, len, dumpfile);
        free(buf);
}

canonical_original_code:
void dmi_table(long base, unsigned int len, unsigned short num, unsigned int ver, char *devmem, unsigned int flags, char *dumpfile)
{
        unsigned char *buf;
        unsigned long size = len;
        buf = read_file(((void *)0), flags & (1 << 0) ? 0 : base,
                        &size, devmem);
        len = size;
        if (buf == ((void *)0))
        {
                printf("read failed\n");
        }
        dmi_table_dump(buf, len, dumpfile);
        free(buf);
}

variable_types: base long

variable_types:
num
unsigned short

variable_types:
ver
unsigned int

variable_types:
flags
unsigned int

variable_types:
size
unsigned long


original_code:
static int smbios3_decode(u8 *buf, const char *devmem, u32 flags, const char *dumpfile)
{
        u32 ver;
        u64 offset;
        offset = (*(const u64 *)(buf + 0x10));
        ver = (buf[0x07] << 16) + (buf[0x08] << 8) + buf[0x09];
        if (!checksum(buf, buf[0x06]))
                return 0;
        dmi_table(((off_t)offset.h << 32) | offset.l,(u32)(*(const u32 *)(buf + 0x0C)), 0, ver, devmem, flags | (1 << 1), dumpfile);
        u8 crafted[32];
        memcpy(crafted, buf, 32);
        overwrite_smbios3_address(crafted);
        write_dump(0, crafted[0x06], crafted, dumpfile, 1);
        return 1;
}

canonical_original_code:
static int smbios3_decode(unsigned char *buf, char *devmem, unsigned int flags, char *dumpfile)
{
        unsigned int ver;
        struct u64 offset;
        offset = (*(struct u64 *)(buf + 0x10));
        ver = (buf[0x07] << 16) + (buf[0x08] << 8) + buf[0x09];
        if (!checksum(buf, buf[0x06]))
                return 0;
        dmi_table(((long)offset.h << 32) | offset.l,(u32)(*(unsigned int *)(buf + 0x0C)), 0, ver, devmem, flags | (1 << 1), dumpfile);
        unsigned char crafted[32];
        memcpy(crafted, buf, 32);
        overwrite_smbios3_address(crafted);
        write_dump(0, crafted[0x06], crafted, dumpfile, 1);
        return 1;
}

variable_types:
crafted
unsigned char [32]

return_type: int

user_defined_types: struct u64 { unsigned int l; unsigned int h; }


original_code:
static int smbios_decode(u8 *buf, const char *devmem, u32 flags, const char *dumpfile)
{
        u16 ver;
        if (!checksum(buf, buf[0x05])
         || memcmp(buf + 0x10, "_DMI_", 5) != 0
         || !checksum(buf + 0x10, 0x0F))
                return 0;
        ver = (buf[0x06] << 8) + buf[0x07];
        switch (ver)
        {
                case 0x021F:
                case 0x0221:
                        ver = 0x0203;
                        break;
                case 0x0233:
                        ver = 0x0206;
                        break;
        }
        dmi_table((u32)(*(const u32 *)(buf + 0x18)), (u16)(*(const u16 *)(buf + 0x16)), (u16)(*(const u16 *)(buf + 0x1C)),
                ver << 8, devmem, flags, dumpfile);
        u8 crafted[32];
        memcpy(crafted, buf, 32);
        overwrite_dmi_address(crafted + 0x10);
        write_dump(0, crafted[0x05], crafted, dumpfile, 1);
        return 1;
}

canonical_original_code:
static int smbios_decode(unsigned char *buf, char *devmem, unsigned int flags, char *dumpfile)
{
        unsigned short ver;
        if (!checksum(buf, buf[0x05])
         || memcmp(buf + 0x10, "_DMI_", 5) != 0
         || !checksum(buf + 0x10, 0x0F))
                return 0;
        ver = (buf[0x06] << 8) + buf[0x07];
        switch (ver)
        {
                case 0x021F:
                case 0x0221:
                        ver = 0x0203;
                        break;
                case 0x0233:
                        ver = 0x0206;
                        break;
        }
        dmi_table((u32)(*(unsigned int *)(buf + 0x18)), (u16)(*(unsigned short *)(buf + 0x16)), (u16)(*(unsigned short *)(buf + 0x1C)),
                ver << 8, devmem, flags, dumpfile);
        unsigned char crafted[32];
        memcpy(crafted, buf, 32);
        overwrite_dmi_address(crafted + 0x10);
        write_dump(0, crafted[0x05], crafted, dumpfile, 1);
        return 1;
}

variable_types:
ver
unsigned short


original_code:
static int legacy_decode(u8 *buf, const char *devmem, u32 flags, const char *dumpfile)
{
        u8 crafted[16];
        dmi_table((u32)(*(const u32 *)(buf + 0x08)), (u16)(*(const u16 *)(buf + 0x06)), (u16)(*(const u16 *)(buf + 0x0C)),
                ((buf[0x0E] & 0xF0) << 12) + ((buf[0x0E] & 0x0F) << 8),
                devmem, flags, dumpfile);
        memcpy(crafted, buf, 16);
        overwrite_smbios3_address(crafted);
        write_dump(0, 0x0F, crafted, dumpfile, 1);
        return 1;
}

canonical_original_code:
static int legacy_decode(unsigned char *buf, char *devmem, unsigned int flags, char *dumpfile)
{
        unsigned char crafted[16];
        dmi_table((u32)(*(unsigned int *)(buf + 0x08)), (u16)(*(unsigned short *)(buf + 0x06)), (u16)(*(unsigned short *)(buf + 0x0C)),
                ((buf[0x0E] & 0xF0) << 12) + ((buf[0x0E] & 0x0F) << 8),
                devmem, flags, dumpfile);
        memcpy(crafted, buf, 16);
        overwrite_smbios3_address(crafted);
        write_dump(0, 0x0F, crafted, dumpfile, 1);
        return 1;
}

variable_types:
devmem
char *

variable_types:
crafted
unsigned char [16]


dump

original_code:
int dump(const char *memdev, const char *dumpfile)
{
        int ret = 0;
        int found = 0;
        size_t fp;
        int efi;
        u8 *buf;
        size_t size;
        size = 0x20;
        if ( (buf = read_file(((void *)0), 0, &size, "/sys/firmware/dmi/tables" "/smbios_entry_point")) != ((void *)0)){
                if (size >= 24 && memcmp(buf, "_SM3_", 5) == 0){
                        if (smbios3_decode(buf, "/sys/firmware/dmi/tables" "/DMI", (1 << 0), dumpfile))
                                found++;
                } else if (size >= 31 && memcmp(buf, "_SM_", 4) == 0) {
                        if (smbios_decode(buf, "/sys/firmware/dmi/tables" "/DMI", (1 << 0), dumpfile))
                                found++;
                } else if (size >= 15 && memcmp(buf, "_DMI_", 5) == 0){
                        if (legacy_decode(buf, "/sys/firmware/dmi/tables" "/DMI", (1 << 0), dumpfile))
                                found++;
                }
                if (found){
                        ret = 1;
                        goto exit_free;
                }
        }
        efi = address_from_efi(((void *)0), &fp);
        switch(efi)
        {
                case (-1):
                        goto memory_scan;
                case (-2):
                        ret = 1;
                        goto exit_free;
        }
        if ((buf = mem_chunk(((void *)0), fp, 0x20, memdev )) == ((void *)0)){
                ret = 1;
                goto exit_free;
        }
        if (memcmp(buf, "_SM3_", 5) == 0){
                if(smbios3_decode(buf, memdev, 0, dumpfile))
                        found++;
        } else if (memcmp(buf, "_SM_", 4) == 0){
                if(smbios_decode(buf, memdev, 0, dumpfile))
                        found++;
        }
        goto done;
memory_scan:
        if((buf = mem_chunk(((void *)0), 0xF0000, 0x10000, memdev)) == ((void *)0)) {
                ret = 1;
                goto exit_free;
        }
        for(fp = 0; fp <= 0xFFF0; fp += 16){
                if(memcmp(buf + fp, "_SM3_", 5) == 0 && fp <= 0xFFE0){
                        if(smbios3_decode(buf + fp, memdev, 0, dumpfile)){
                                found++;
                                goto done;
                        }
                }
        }
        for(fp = 0; fp <= 0xFFF0; fp += 16) {
                if(memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) {
                        if(smbios_decode(buf + fp, memdev, 0, dumpfile)){
                                found++;
                                goto done;
                        }
                } else if (memcmp(buf+fp, "_DMI_", 5) == 0){
                        if(legacy_decode(buf+fp, memdev, 0, dumpfile)){
                                found++;
                                goto done;
                        }
                }
        }
done:
        if(!found){
                printf("No SMBIOS nor DMI entry point found, sorry.\n");
        }
        free(buf);
exit_free:
        if (!found)
                free(buf);
        return ret;
}

canonical_original_code:
int dump(char *memdev, char *dumpfile)
{
        int ret = 0;
        int found = 0;
        unsigned long fp;
        int efi;
        unsigned char *buf;
        unsigned long size;
        size = 0x20;
        if ( (buf = read_file(((void *)0), 0, &size, "/sys/firmware/dmi/tables" "/smbios_entry_point")) != ((void *)0)){
                if (size >= 24 && memcmp(buf, "_SM3_", 5) == 0){
                        if (smbios3_decode(buf, "/sys/firmware/dmi/tables" "/DMI", (1 << 0), dumpfile))
                                found++;
                } else if (size >= 31 && memcmp(buf, "_SM_", 4) == 0) {
                        if (smbios_decode(buf, "/sys/firmware/dmi/tables" "/DMI", (1 << 0), dumpfile))
                                found++;
                } else if (size >= 15 && memcmp(buf, "_DMI_", 5) == 0){
                        if (legacy_decode(buf, "/sys/firmware/dmi/tables" "/DMI", (1 << 0), dumpfile))
                                found++;
                }
                if (found){
                        ret = 1;
                        goto exit_free;
                }
        }
        efi = address_from_efi(((void *)0), &fp);
        switch(efi)
        {
                case (-1):
                        goto memory_scan;
                case (-2):
                        ret = 1;
                        goto exit_free;
        }
        if ((buf = mem_chunk(((void *)0), fp, 0x20, memdev )) == ((void *)0)){
                ret = 1;
                goto exit_free;
        }
        if (memcmp(buf, "_SM3_", 5) == 0){
                if(smbios3_decode(buf, memdev, 0, dumpfile))
                        found++;
        } else if (memcmp(buf, "_SM_", 4) == 0){
                if(smbios_decode(buf, memdev, 0, dumpfile))
                        found++;
        }
        goto done;
memory_scan:
        if((buf = mem_chunk(((void *)0), 0xF0000, 0x10000, memdev)) == ((void *)0)) {
                ret = 1;
                goto exit_free;
        }
        for(fp = 0; fp <= 0xFFF0; fp += 16){
                if(memcmp(buf + fp, "_SM3_", 5) == 0 && fp <= 0xFFE0){
                        if(smbios3_decode(buf + fp, memdev, 0, dumpfile)){
                                found++;
                                goto done;
                        }
                }
        }
        for(fp = 0; fp <= 0xFFF0; fp += 16) {
                if(memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) {
                        if(smbios_decode(buf + fp, memdev, 0, dumpfile)){
                                found++;
                                goto done;
                        }
                } else if (memcmp(buf+fp, "_DMI_", 5) == 0){
                        if(legacy_decode(buf+fp, memdev, 0, dumpfile)){
                                found++;
                                goto done;
                        }
                }
        }
done:
        if(!found){
                printf("No SMBIOS nor DMI entry point found, sorry.\n");
        }
        free(buf);
exit_free:
        if (!found)
                free(buf);
        return ret;
}

variable_types:
memdev
char *

variable_types: ret int

variable_types: found int

variable_types:
fp
unsigned long

variable_types: efi int


repo: nimrody/rs

canonical_original_code:
void generate_gf256()
{
 int i;
 ((void) sizeof ((8==8) ? 1 : 0), __extension__ ({ if (8==8) ; else __assert_fail ("MM==8", "gf.c", 23, __extension__ __PRETTY_FUNCTION__); }));
 for(i=0; i<8; i++)
  alpha_to[i] = 1 << i;
 for(; i<((1 << 8) - 1); i++) {
  alpha_to[i] = alpha_to[i-8] ^ alpha_to[i-6] ^ alpha_to[i-5] ^
             alpha_to[i-4];
 }
 alpha_to[((1 << 8) - 1)] = 0;
 for(i=0; i<=((1 << 8) - 1); i++) {
  unsigned int s = alpha_to[i];
  index_of[s] = i;
 }
}

variable_types: i int

variable_types:
s
unsigned int


decompiled_code:
__int64 __fastcall gf_add(unsigned int a1, int a2)
{
return a2 ^ a1;
}

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

original_code:
gf gf_add(gf a, gf b)
{
 return a ^ b;
}

canonical_original_code:
unsigned int gf_add(unsigned int a, unsigned int b)
{
 return a ^ b;
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall gf_mul(int a1, int a2)
{
__int64 result; // rax

if ( a1 && a2 )
result = *((unsigned int *)&alpha_to + (index_of[a1] + index_of[a2]) % 255);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 result; // rax

if ( a1 && a2 )
result = *((unsigned int *)&alpha_to + (index_of[a1] + index_of[a2]) % 255);
else
result = 0LL;
return result;
}

original_code:
gf gf_mul(gf a, gf b)
{
 if (a == 0 || b == 0)
  return 0;
 else {
  int na = index_of[a];
  int nb = index_of[b];
  int nc = na + nb;
  return alpha_to[nc % ((1 << 8) - 1)];
 }
}

canonical_original_code:
unsigned int gf_mul(unsigned int a, unsigned int b)
{
 if (a == 0 || b == 0)
  return 0;
 else {
  int na = index_of[a];
  int nb = index_of[b];
  int nc = na + nb;
  return alpha_to[nc % ((1 << 8) - 1)];
 }
}

variable_types: nb int

variable_types: nc int


decompiled_code:
__int64 __fastcall gf_pow(int a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
{
for ( ; a2 < 0; a2 += 255 )
;
result = *((unsigned int *)&alpha_to + index_of[a1] * a2 % 255);
}
return result;
}

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

result = 0LL;
if ( a1 )
{
for ( ; a2 < 0; a2 += 255 )
;
result = *((unsigned int *)&alpha_to + index_of[a1] * a2 % 255);
}
return result;
}

canonical_original_code:
unsigned int gf_pow(unsigned int a, int n)
{
 int ia;
 if (a==0)
  return 0;
 ((void) sizeof ((n>=0 || (n<0 && a!=0)) ? 1 : 0), __extension__ ({ if (n>=0 || (n<0 && a!=0)) ; else __assert_fail ("n>=0 || (n<0 && a!=0)", "gf.c", 125, __extension__ __PRETTY_FUNCTION__); }));
 while(n<0)
  n += ((1 << 8) - 1);
 ia = index_of[a];
 ia = (ia * n) % ((1 << 8) - 1);
 return alpha_to[ia];
}

variable_types: n int

variable_types: ia int


decompiled_code:
__int64 __fastcall gf_inv(int a1)
{
return gf_pow(a1, -1);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return func3(a1, -1);
}

original_code:
gf gf_inv(gf a)
{
 return gf_pow(a, -1);
}

canonical_original_code:
unsigned int gf_inv(unsigned int a)
{
 return gf_pow(a, -1);
}


decompiled_code:
__int64 __fastcall gf_div(__int64 a1, int a2)
{
int v2; // eax
int v3; // er8

v2 = gf_inv(a2);
return gf_mul(v3, v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
int v2; // eax
int v3; // er8

v2 = func4(a2);
return func2(v3, v2);
}

original_code:
gf gf_div(gf a, gf b)
{
 gf c = gf_inv(b);
 gf result = gf_mul(a, c);
 return result;
}

canonical_original_code:
unsigned int gf_div(unsigned int a, unsigned int b)
{
 unsigned int c = gf_inv(b);
 unsigned int result = gf_mul(a, c);
 return result;
}

variable_types:
c
unsigned int

variable_types:
result
unsigned int


decompiled_code:
__int64 __fastcall gf_poly(__int64 a1, int a2, int a3)
{
unsigned int v4; // edi
unsigned int v5; // eax
__int64 v6; // r8
__int64 v7; // r9
int v8; // er8

if ( a2 - 1 < 0 )
return 0LL;
v4 = 0;
do
{
v5 = gf_mul(v4, a3);
v4 = gf_add(v5, *(_DWORD *)(v7 + 4 * v6));
}
while ( v8 >= 0 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3)
{
unsigned int v4; // edi
unsigned int v5; // eax
__int64 v6; // r8
__int64 v7; // r9
int v8; // er8

if ( a2 - 1 < 0 )
return 0LL;
v4 = 0;
do
{
v5 = func2(v4, a3);
v4 = func1(v5, *(_DWORD *)(v7 + 4 * v6));
}
while ( v8 >= 0 );
return v4;
}

original_code:
gf gf_poly(gf p[], int n, gf a)
{
 int i = n-1;
 gf acc = 0;
 while(i>=0) {
  acc = gf_mul(acc, a);
  acc = gf_add(acc, p[i]);
  i--;
 }
 return acc;
}

canonical_original_code:
unsigned int gf_poly(unsigned int p[], int n, unsigned int a)
{
 int i = n-1;
 unsigned int acc = 0;
 while(i>=0) {
  acc = gf_mul(acc, a);
  acc = gf_add(acc, p[i]);
  i--;
 }
 return acc;
}

variable_types:
p
unsigned int []

variable_types:
acc
unsigned int


decompiled_code:
int print_alpha_to()
{
__int64 i; // rbx
const char *v1; // rax
__int64 v2; // rsi
int result; // eax

for ( i = 0LL; i != 256; ++i )
{
v1 = (const char *)print_binary(*((unsigned int *)&alpha_to + i), 8LL);
v2 = (unsigned int)i;
result = printf("a^%3d = %s\n", v2, v1);
}
return result;
}

canonical_decompiled_code:
int func7()
{
__int64 i; // rbx
const char *v1; // rax
__int64 v2; // rsi
int result; // eax

for ( i = 0LL; i != 256; ++i )
{
v1 = (const char *)print_binary(*((unsigned int *)&alpha_to + i), 8LL);
v2 = (unsigned int)i;
result = printf("a^%3d = %s\n", v2, v1);
}
return result;
}

original_code:
void print_alpha_to()
{
 int i;
 for (i=0; i<=((1 << 8) - 1); i++)
  printf("a^%3d = %s\n",i, print_binary(alpha_to[i], 8));
}


decompiled_code:
int print_index_of()
{
__int64 i; // rbx
unsigned int v1; // er12
__int64 v2; // rdi
const char *v3; // rax
int result; // eax

for ( i = 0LL; i != 256; ++i )
{
v1 = index_of[i];
v2 = (unsigned int)i;
v3 = (const char *)print_binary(v2, 8LL);
result = printf("%s = a^%d\n", v3, v1);
}
return result;
}

canonical_decompiled_code:
int func8()
{
__int64 i; // rbx
unsigned int v1; // er12
__int64 v2; // rdi
const char *v3; // rax
int result; // eax

for ( i = 0LL; i != 256; ++i )
{
v1 = index_of[i];
v2 = (unsigned int)i;
v3 = (const char *)print_binary(v2, 8LL);
result = printf("%s = a^%d\n", v3, v1);
}
return result;
}

original_code:
void print_index_of()
{
 int i;
 for (i=0; i<=((1 << 8) - 1); i++)
  printf("%s = a^%d\n",print_binary(i, 8), index_of[i]);
}


decompiled_code:
int __fastcall print_multiply_by(unsigned int a1)
{
unsigned int i; // ebx
unsigned int v2; // eax
__int64 v3; // rsi
int result; // eax

for ( i = 0; i != 256; ++i )
{
v2 = gf_mul(i, a1);
v3 = i;
result = printf("%02x x %02x = %02x\n", v3, a1, v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
unsigned int i; // ebx
unsigned int v2; // eax
__int64 v3; // rsi
int result; // eax

for ( i = 0; i != 256; ++i )
{
v2 = func2(i, a1);
v3 = i;
result = printf("%02x x %02x = %02x\n", v3, a1, v2);
}
return result;
}

original_code:
void print_multiply_by(gf m)
{
 int i;
 for(i=0; i<=((1 << 8) - 1); i++) {
  printf("%02x x %02x = %02x\n", i, m, gf_mul(i, m));
 }
}

canonical_original_code:
void print_multiply_by(unsigned int m)
{
 int i;
 for(i=0; i<=((1 << 8) - 1); i++) {
  printf("%02x x %02x = %02x\n", i, m, gf_mul(i, m));
 }
}

variable_types:
m
unsigned int


decompiled_code:
int __fastcall print_roots_table(int a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
__int64 v3; // rsi
int result; // eax

if ( 2 * a1 > 0 )
{
v1 = 0LL;
do
{
v2 = *((unsigned int *)&alpha_to + v1);
v3 = (unsigned int)v1++;
result = printf("parameter alpha%d = 8'h%02x;\n", v3, v2);
}
while ( v1 != 2 * a1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
__int64 v3; // rsi
int result; // eax

if ( 2 * a1 > 0 )
{
v1 = 0LL;
do
{
v2 = *((unsigned int *)&alpha_to + v1);
v3 = (unsigned int)v1++;
result = printf("parameter alpha%d = 8'h%02x;\n", v3, v2);
}
while ( v1 != 2 * a1 );
}
return result;
}

original_code:
void print_roots_table(int t)
{
 int i;
 for (i=0; i<=2*t-1; i++)
  printf("parameter alpha%d = 8'h%02x;\n",i, alpha_to[i]);
}

variable_types: t int


decompiled_code:
int print_inv_table()
{
__int64 v0; // rbp
__int64 v1; // r8
unsigned int v2; // er9
unsigned int v3; // er10
__int64 v4; // rsi

v0 = 1LL;
puts("case(x)");
puts(" begin");
do
{
if ( (unsigned int)gf_mul(v0, *((_DWORD *)&alpha_to + (255 - index_of[v0]) % 255)) != 1 )
_assert_fail("mul == 1", "gf.c", 0xDEu, "print_inv_table");
v4 = (unsigned int)v0++;
printf(" 8'h%02x: y = 8'h%02x; // inv(a^%3d) = a^%d\n", v4, v3, v2, v1);
}
while ( v0 != 256 );
puts(" end");
return puts("endcase");
}

canonical_decompiled_code:
int func11()
{
__int64 v0; // rbp
__int64 v1; // r8
unsigned int v2; // er9
unsigned int v3; // er10
__int64 v4; // rsi

v0 = 1LL;
puts("case(x)");
puts(" begin");
do
{
if ( (unsigned int)func2(v0, *((_DWORD *)&alpha_to + (255 - index_of[v0]) % 255)) != 1 )
_assert_fail("mul == 1", "gf.c", 0xDEu, "print_inv_table");
v4 = (unsigned int)v0++;
printf(" 8'h%02x: y = 8'h%02x; // inv(a^%3d) = a^%d\n", v4, v3, v2, v1);
}
while ( v0 != 256 );
puts(" end");
return puts("endcase");
}

original_code:
void print_inv_table()
{
 int i;
 printf("case(x)\n");
 printf("  begin\n");
 for(i=1; i<=((1 << 8) - 1); i++) {
  int power = index_of[i];
  int inv_power = (((1 << 8) - 1) - power) % ((1 << 8) - 1);
  gf inv = alpha_to[inv_power];
  gf mul = gf_mul(i, inv);
  ((void) sizeof ((mul == 1) ? 1 : 0), __extension__ ({ if (mul == 1) ; else __assert_fail ("mul == 1", "gf.c", 222, __extension__ __PRETTY_FUNCTION__); }));
  printf("    8'h%02x: y = 8'h%02x; // inv(a^%3d) = a^%d\n", i, inv, power, inv_power);
 }
 printf("  end\n");
 printf("endcase\n");
}

canonical_original_code:
void print_inv_table()
{
 int i;
 printf("case(x)\n");
 printf("  begin\n");
 for(i=1; i<=((1 << 8) - 1); i++) {
  int power = index_of[i];
  int inv_power = (((1 << 8) - 1) - power) % ((1 << 8) - 1);
  unsigned int inv = alpha_to[inv_power];
  unsigned int mul = gf_mul(i, inv);
  ((void) sizeof ((mul == 1) ? 1 : 0), __extension__ ({ if (mul == 1) ; else __assert_fail ("mul == 1", "gf.c", 222, __extension__ __PRETTY_FUNCTION__); }));
  printf("    8'h%02x: y = 8'h%02x; // inv(a^%3d) = a^%d\n", i, inv, power, inv_power);
 }
 printf("  end\n");
 printf("endcase\n");
}

variable_types: power int

variable_types:
inv
unsigned int

variable_types:
mul
unsigned int


decompiled_code:
char *__fastcall print_binary(int a1, char a2)
{
char v2; // cl
int v3; // esi
char *v4; // r8
unsigned int v5; // eax
_BYTE *i; // rcx
char v7; // dl
char *result; // rax

v2 = a2 - 1;
v3 = si_1;
v4 = (char *)&s_0 + 64 * (__int64)si_1;
v5 = 1 << v2;
for ( i = v4; v5; *(i - 1) = v7 )
{
v7 = 48 - (((v5 & a1) == 0) - 1);
++i;
v5 >>= 1;
}
*i = 0;
result = v4;
si_1 = (v3 + 1) % 4;
return result;
}

original_code:
char *print_binary(unsigned x, unsigned n)
{
 static char s[4][64];
 static int si = 0;
 int old_si = si;
 char *p = &s[si][0];
 unsigned mask = 1 << (n-1);
 while (mask) {
  *p++ = x & mask ? '1' : '0';
  mask >>= 1;
 }
 *p = '\0';
 si = (si + 1) % 4;
 return &s[old_si][0];
}

canonical_original_code:
char *print_binary(unsigned int x, unsigned int n)
{
 static char s[4][64];
 static int si = 0;
 int old_si = si;
 char *p = &s[si][0];
 unsigned int mask = 1 << (n-1);
 while (mask) {
  *p++ = x & mask ? '1' : '0';
  mask >>= 1;
 }
 *p = '\0';
 si = (si + 1) % 4;
 return &s[old_si][0];
}

variable_types:
x
unsigned int

variable_types:
n
unsigned int

variable_types: si int

variable_types:
p
char *

variable_types:
mask
unsigned int

return_type: char *


decompiled_code:
int __fastcall print_rs_syn(__int64 a1, __int64 a2, int a3, __int64 a4)
{
int v4; // ebp
__int64 v6; // rbx
__int64 v7; // rdx
__int64 v8; // rsi
int result; // eax

v4 = 2 * a3;
if ( 2 * a3 > 0 )
{
v6 = 0LL;
do
{
v7 = *(unsigned int *)(a4 + 4 * v6);
v8 = (unsigned int)v6++;
result = printf("=== s[%d] = %02x\n", v8, v7);
}
while ( v6 != v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2, int a3, __int64 a4)
{
int v4; // ebp
__int64 v6; // rbx
__int64 v7; // rdx
__int64 v8; // rsi
int result; // eax

v4 = 2 * a3;
if ( 2 * a3 > 0 )
{
v6 = 0LL;
do
{
v7 = *(unsigned int *)(a4 + 4 * v6);
v8 = (unsigned int)v6++;
result = printf("=== s[%d] = %02x\n", v8, v7);
}
while ( v6 != v4 );
}
return result;
}

original_code:
void print_rs_syn(gf c[], int n, int t, gf s[])
{
 int i;
 for(i=0; i<2*t; i++)
  printf("=== s[%d] = %02x\n", i, s[i]);
}

canonical_original_code:
void print_rs_syn(unsigned int c[], int n, int t, unsigned int s[])
{
 int i;
 for(i=0; i<2*t; i++)
  printf("=== s[%d] = %02x\n", i, s[i]);
}

variable_types:
c
unsigned int []

variable_types:
s
unsigned int []

variable_types: i int


decompiled_code:
int __fastcall print_poly(const char *a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 i; // rbx
__int64 v5; // rcx
__int64 v6; // rdx
int result; // eax

if ( a3 > 0 )
{
v3 = a3;
for ( i = 0LL; i != v3; ++i )
{
v5 = *(unsigned int *)(a2 + 4 * i);
v6 = (unsigned int)i;
result = printf("%s[%3d] = %02x\n", a1, v6, v5);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 i; // rbx
__int64 v5; // rcx
__int64 v6; // rdx
int result; // eax

if ( a3 > 0 )
{
v3 = a3;
for ( i = 0LL; i != v3; ++i )
{
v5 = *(unsigned int *)(a2 + 4 * i);
v6 = (unsigned int)i;
result = printf("%s[%3d] = %02x\n", a1, v6, v5);
}
}
return result;
}

original_code:
void print_poly(char *name, gf p[], int n)
{
 int i;
 for(i=0; i<n; i++)
  printf("%s[%3d] = %02x\n", name, i, p[i]);
}

canonical_original_code:
void print_poly(char *name, unsigned int p[], int n)
{
 int i;
 for(i=0; i<n; i++)
  printf("%s[%3d] = %02x\n", name, i, p[i]);
}

variable_types:
name
char *

variable_types: n int


repo: ningyuwhut/SysProPlan

decompiled_code:
void *__fastcall shmem_alloc(size_t n)
{
int v1; // er8
void *v3; // r12

g_shmem_fd = open("/tmp/shmem_demo", 2);
v1 = g_shmem_fd;
if ( g_shmem_fd < 0 )
{
v3 = calloc(n, 1uLL);
g_shmem_fd = open("/tmp/shmem_demo", 66, 416LL);
write(g_shmem_fd, v3, n);
free(v3);
v1 = g_shmem_fd;
}
return mmap(0LL, n, 3, 1, v1, 0LL);
}

canonical_decompiled_code:
void *__fastcall func7(size_t n)
{
int v1; // er8
void *v3; // r12

g_shmem_fd = open("/tmp/shmem_demo", 2);
v1 = g_shmem_fd;
if ( g_shmem_fd < 0 )
{
v3 = calloc(n, 1uLL);
g_shmem_fd = open("/tmp/shmem_demo", 66, 416LL);
write(g_shmem_fd, v3, n);
free(v3);
v1 = g_shmem_fd;
}
return mmap(0LL, n, 3, 1, v1, 0LL);
}

original_code:
void* shmem_alloc(size_t size)
{
 g_shmem_fd = open("/tmp/shmem_demo", 02);
 if(g_shmem_fd < 0)
 {
  char* buffer = calloc(size, 1);
  g_shmem_fd = open("/tmp/shmem_demo", 02 | 0100, 0640);
  write(g_shmem_fd, buffer, size);
  free(buffer);
 }
 void* addr = mmap(0, size, 0x1 | 0x2, 0x01, g_shmem_fd, 0);
 return addr;
}

canonical_original_code:
void *shmem_alloc(unsigned long size)
{
 g_shmem_fd = open("/tmp/shmem_demo", 02);
 if(g_shmem_fd < 0)
 {
  char *buffer = calloc(size, 1);
  g_shmem_fd = open("/tmp/shmem_demo", 02 | 0100, 0640);
  write(g_shmem_fd, buffer, size);
  free(buffer);
 }
 void *addr = mmap(0, size, 0x1 | 0x2, 0x01, g_shmem_fd, 0);
 return addr;
}

variable_types:
size
unsigned long

variable_types:
buffer
char *

variable_types:
addr
void *

return_type: void *


decompiled_code:
int __fastcall shmem_free(void *a1, size_t a2)
{
munmap(a1, a2);
return close(g_shmem_fd);
}

canonical_decompiled_code:
int __fastcall func8(void *a1, size_t a2)
{
munmap(a1, a2);
return close(g_shmem_fd);
}

original_code:
void shmem_free(void* addr, size_t size)
{
 munmap(addr, size);
 close(g_shmem_fd);
 return;
}

canonical_original_code:
void shmem_free(void *addr, unsigned long size)
{
 munmap(addr, size);
 close(g_shmem_fd);
 return;
}


pop

decompiled_code:
int __fastcall pop(__int64 a1)
{
int v1; // ebx
int result; // eax
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = 0;
v3[0] = 0LL;
do
{
while ( (unsigned int)fifo_ring_pop(a1, v3) )
usleep(0x64u);
result = printf("%s: %d data=%d\n", "pop", (unsigned int)v1, v3[0]);
if ( LODWORD(v3[0]) != v1 )
__assert_fail("i == (int)data", "fifo_ring.c", 0xB5u, "pop");
++v1;
}
while ( v1 <= 9 );
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
int v1; // ebx
int result; // eax
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = 0;
v3[0] = 0LL;
do
{
while ( (unsigned int)func9(a1, v3) )
usleep(0x64u);
result = printf("%s: %d data=%d\n", "pop", (unsigned int)v1, v3[0]);
if ( LODWORD(v3[0]) != v1 )
__assert_fail("i == (int)data", "fifo_ring.c", 0xB5u, "pop");
++v1;
}
while ( v1 <= 9 );
return result;
}

original_code:
static void pop(FifoRing* fifo)
{
 int i = 0;
 void* data = 0;
 while(i < 10)
 {
  if(fifo_ring_pop(fifo, (void**)&data) == RET_OK)
  {
   printf("%s: %d data=%d\n", __func__, i, data);
   ((void) sizeof ((i == (int)data) ? 1 : 0), __extension__ ({ if (i == (int)data) ; else __assert_fail ("i == (int)data", "fifo_ring.c", 181, __extension__ __PRETTY_FUNCTION__); }));
   i++;
  }
  else
  {
   usleep(100);
  }
 }
 return ;
}

canonical_original_code:
static void pop(struct _FifoRing *fifo)
{
 int i = 0;
 void *data = 0;
 while(i < 10)
 {
  if(fifo_ring_pop(fifo, (void **)&data) == RET_OK)
  {
   printf("%s: %d data=%d\n", __func__, i, data);
   ((void) sizeof ((i == (int)data) ? 1 : 0), __extension__ ({ if (i == (int)data) ; else __assert_fail ("i == (int)data", "fifo_ring.c", 181, __extension__ __PRETTY_FUNCTION__); }));
   i++;
  }
  else
  {
   usleep(100);
  }
 }
 return ;
}

variable_types: struct _FifoRing { int inited; int r_cursor; int w_cursor; unsigned long length; void *data[]; } *

variable_types:
data
void *


push

decompiled_code:
int __fastcall push(__int64 a1)
{
unsigned int i; // ebx
__int64 v2; // rdx
int result; // eax

for ( i = 0; i != 10; ++i )
{
while ( (unsigned int)fifo_ring_push(a1, (int)i) )
usleep(0x64u);
v2 = i;
result = printf("%s: %d\n", "push", v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
unsigned int i; // ebx
__int64 v2; // rdx
int result; // eax

for ( i = 0; i != 10; ++i )
{
while ( (unsigned int)func11(a1, (int)i) )
usleep(0x64u);
v2 = i;
result = printf("%s: %d\n", "push", v2);
}
return result;
}

original_code:
static void push(FifoRing* fifo)
{
 int i = 0;
 while(i < 10)
 {
  if(fifo_ring_push(fifo, (void*)i) == RET_OK)
  {
   printf("%s: %d\n", __func__, i);
   i++;
  }
  else
  {
   usleep(100);
  }
 }
 return;
}

canonical_original_code:
static void push(struct _FifoRing *fifo)
{
 int i = 0;
 while(i < 10)
 {
  if(fifo_ring_push(fifo, (void *)i) == RET_OK)
  {
   printf("%s: %d\n", __func__, i);
   i++;
  }
  else
  {
   usleep(100);
  }
 }
 return;
}

user_defined_types: struct _FifoRing { int inited; int r_cursor; int w_cursor; unsigned long length; void *data[]; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rbp

if ( argc == 2 )
{
v4 = fifo_ring_create(1000LL, argv, envp);
if ( !strcmp(argv[1], "pop") )
pop(v4);
else
push(v4);
fifo_ring_destroy(v4);
}
else
{
printf("usage: %s pop|push\n", *argv);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rbp

if ( argc == 2 )
{
v4 = fifo_ring_create(1000LL, argv, envp);
if ( !strcmp(argv[1], "pop") )
func10(v4);
else
func12(v4);
func13(v4);
}
else
{
printf("usage: %s pop|push\n", *argv);
}
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 if(argc != 2)
 {
  printf("usage: %s pop|push\n", argv[0]);
  return 0;
 }
 FifoRing* fifo = fifo_ring_create(1000);
 if(strcmp(argv[1], "pop") == 0)
 {
  pop(fifo);
 }
 else
 {
  push(fifo);
 }
 fifo_ring_destroy(fifo);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(argc != 2)
 {
  printf("usage: %s pop|push\n", argv[0]);
  return 0;
 }
 struct _FifoRing *fifo = fifo_ring_create(1000);
 if(strcmp(argv[1], "pop") == 0)
 {
  pop(fifo);
 }
 else
 {
  push(fifo);
 }
 fifo_ring_destroy(fifo);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall fifo_ring_pop(__int64 a1, _QWORD *a2)
{
int v2; // eax
unsigned int v3; // er8
__int64 result; // rax

if ( a1 && a2 )
{
v2 = *(_DWORD *)(a1 + 4);
v3 = 4;
if ( v2 != *(_DWORD *)(a1 + 8) )
{
v3 = 0;
*a2 = *(_QWORD *)(a1 + 8LL * v2 + 24);
*(_DWORD *)(a1 + 4) = (unsigned __int64)(v2 + 1) % *(_QWORD *)(a1 + 16);
}
result = v3;
}
else
{
printf("%s:%d Warning: thiz != NULL && data != NULL failed.\n", "fifo_ring_pop", 101LL);
result = 4LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, _QWORD *a2)
{
int v2; // eax
unsigned int v3; // er8
__int64 result; // rax

if ( a1 && a2 )
{
v2 = *(_DWORD *)(a1 + 4);
v3 = 4;
if ( v2 != *(_DWORD *)(a1 + 8) )
{
v3 = 0;
*a2 = *(_QWORD *)(a1 + 8LL * v2 + 24);
*(_DWORD *)(a1 + 4) = (unsigned __int64)(v2 + 1) % *(_QWORD *)(a1 + 16);
}
result = v3;
}
else
{
printf("%s:%d Warning: thiz != NULL && data != NULL failed.\n", "fifo_ring_pop", 101LL);
result = 4LL;
}
return result;
}

original_code:
Ret fifo_ring_pop(FifoRing* thiz, void** data)
{
 Ret ret = RET_FAIL;
 if(!(thiz != ((void *)0) && data != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && data != NULL"" failed.\n", __func__, 101); return (RET_FAIL);};
 if(thiz->r_cursor != thiz->w_cursor)
 {
  *data = thiz->data[thiz->r_cursor];
  thiz->r_cursor = (thiz->r_cursor + 1)%thiz->length;
  ret = RET_OK;
 }
 return ret;
}

canonical_original_code:
enum _Ret fifo_ring_pop(struct _FifoRing *thiz, void **data)
{
 enum _Ret ret = RET_FAIL;
 if(!(thiz != ((void *)0) && data != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && data != NULL"" failed.\n", __func__, 101); return (RET_FAIL);};
 if(thiz->r_cursor != thiz->w_cursor)
 {
  *data = thiz->data[thiz->r_cursor];
  thiz->r_cursor = (thiz->r_cursor + 1)%thiz->length;
  ret = RET_OK;
 }
 return ret;
}

variable_types:
data
void **

variable_types: enum _Ret { RET_OK=0, RET_OOM=1, RET_STOP=2, RET_INVALID_PARAMS=3, RET_FAIL=4 }


decompiled_code:
__int64 __fastcall fifo_ring_push(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
unsigned __int64 v3; // rdx
__int64 result; // rax

if ( a1 )
{
v2 = *(int *)(a1 + 8);
v3 = (unsigned __int64)((int)v2 + 1) % *(_QWORD *)(a1 + 16);
result = 4LL;
if ( *(_DWORD *)(a1 + 4) != (_DWORD)v3 )
{
*(_QWORD *)(a1 + 8 * v2 + 24) = a2;
result = 0LL;
*(_DWORD *)(a1 + 8) = v3;
}
}
else
{
printf("%s:%d Warning: thiz != NULL failed.\n", "fifo_ring_push", 118LL);
result = 4LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
unsigned __int64 v3; // rdx
__int64 result; // rax

if ( a1 )
{
v2 = *(int *)(a1 + 8);
v3 = (unsigned __int64)((int)v2 + 1) % *(_QWORD *)(a1 + 16);
result = 4LL;
if ( *(_DWORD *)(a1 + 4) != (_DWORD)v3 )
{
*(_QWORD *)(a1 + 8 * v2 + 24) = a2;
result = 0LL;
*(_DWORD *)(a1 + 8) = v3;
}
}
else
{
printf("%s:%d Warning: thiz != NULL failed.\n", "fifo_ring_push", 118LL);
result = 4LL;
}
return result;
}

original_code:
Ret fifo_ring_push(FifoRing* thiz, void* data)
{
 int w_cursor = 0;
 Ret ret = RET_FAIL;
 if(!(thiz != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL"" failed.\n", __func__, 118); return (RET_FAIL);};
 w_cursor = (thiz->w_cursor + 1) % thiz->length;
 if(w_cursor != thiz->r_cursor)
 {
  thiz->data[thiz->w_cursor] = data;
  thiz->w_cursor = w_cursor;
  ret = RET_OK;
 }
 return ret;
}

canonical_original_code:
enum _Ret fifo_ring_push(struct _FifoRing *thiz, void *data)
{
 int w_cursor = 0;
 enum _Ret ret = RET_FAIL;
 if(!(thiz != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL"" failed.\n", __func__, 118); return (RET_FAIL);};
 w_cursor = (thiz->w_cursor + 1) % thiz->length;
 if(w_cursor != thiz->r_cursor)
 {
  thiz->data[thiz->w_cursor] = data;
  thiz->w_cursor = w_cursor;
  ret = RET_OK;
 }
 return ret;
}

return_type: enum _Ret { RET_OK=0, RET_OOM=1, RET_STOP=2, RET_INVALID_PARAMS=3, RET_FAIL=4 }


decompiled_code:
int __fastcall fifo_ring_destroy(_QWORD *a1)
{
int result; // eax

if ( a1 )
result = shmem_free(a1, 8LL * a1[2] + 24);
return result;
}

canonical_decompiled_code:
int __fastcall func13(_QWORD *a1)
{
int result; // eax

if ( a1 )
result = func8(a1, 8LL * a1[2] + 24);
return result;
}

original_code:
void fifo_ring_destroy(FifoRing* thiz)
{
 if(thiz != ((void *)0))
 {
  shmem_free(thiz, sizeof(FifoRing) + thiz->length * sizeof(void*));
 }
 return;
}

canonical_original_code:
void fifo_ring_destroy(struct _FifoRing *thiz)
{
 if(thiz != ((void *)0))
 {
  shmem_free(thiz, sizeof(FifoRing) + thiz->length * sizeof(void *));
 }
 return;
}


decompiled_code:
int __fastcall on_token(__int64 a1, __int64 a2, const char *a3)
{
return printf("[%d] %s\n", a2, a3);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2, const char *a3)
{
return printf("[%d] %s\n", a2, a3);
}

original_code:
void on_token(void* ctx, int index, const char* token)
{
 printf("[%d] %s\n", index, token);
 return;
}

canonical_original_code:
void on_token(void *ctx, int index, char *token)
{
 printf("[%d] %s\n", index, token);
 return;
}

variable_types:
ctx
void *

variable_types: index int

variable_types:
token
char *


decompiled_code:
__int64 __fastcall parse_token(const char *a1, const char *a2, void (__fastcall *a3)(__int64, __int64, char *), __int64 a4)
{
char *v6; // rax
int v7; // esi
char *v8; // r14
unsigned int v9; // er12
int v11; // esi
unsigned int v12; // er15
_BYTE *v13; // rbx
__int64 v14; // rsi
char *ptr; // [rsp+18h] [rbp-40h]

v6 = strdup(a1);
v7 = *v6;
ptr = v6;
if ( *v6 )
{
v8 = v6;
v9 = 0;
while ( 2 )
{
while ( strchr(a2, v7) )
{
v7 = v8[1];
if ( !v8[1] )
goto LABEL_6;
++v8;
}
while ( 1 )
{
v11 = v8[1];
v12 = v9;
v13 = v8 + 1;
if ( !v8[1] )
{
LABEL_16:
++v9;
a3(a4, v12, v8);
goto LABEL_6;
}
while ( !strchr(a2, v11) )
{
v11 = (char)v13[1];
if ( !v13[1] )
goto LABEL_16;
++v13;
}
v14 = v9;
*v13 = 0;
++v9;
a3(a4, v14, v8);
if ( !v13[1] )
goto LABEL_6;
if ( strchr(a2, (char)v13[1]) )
break;
v8 = v13 + 1;
}
v7 = (char)v13[2];
v8 = v13 + 2;
if ( v13[2] )
continue;
break;
}
}
else
{
v9 = 0;
}
LABEL_6:
a3(a4, 0xFFFFFFFFLL, 0LL);
free(ptr);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2, void (__fastcall *a3)(__int64, __int64, char *), __int64 a4)
{
char *v6; // rax
int v7; // esi
char *v8; // r14
unsigned int v9; // er12
int v11; // esi
unsigned int v12; // er15
_BYTE *v13; // rbx
__int64 v14; // rsi
char *ptr; // [rsp+18h] [rbp-40h]

v6 = strdup(a1);
v7 = *v6;
ptr = v6;
if ( *v6 )
{
v8 = v6;
v9 = 0;
while ( 2 )
{
while ( strchr(a2, v7) )
{
v7 = v8[1];
if ( !v8[1] )
goto LABEL_6;
++v8;
}
while ( 1 )
{
v11 = v8[1];
v12 = v9;
v13 = v8 + 1;
if ( !v8[1] )
{
LABEL_16:
++v9;
a3(a4, v12, v8);
goto LABEL_6;
}
while ( !strchr(a2, v11) )
{
v11 = (char)v13[1];
if ( !v13[1] )
goto LABEL_16;
++v13;
}
v14 = v9;
*v13 = 0;
++v9;
a3(a4, v14, v8);
if ( !v13[1] )
goto LABEL_6;
if ( strchr(a2, (char)v13[1]) )
break;
v8 = v13 + 1;
}
v7 = (char)v13[2];
v8 = v13 + 2;
if ( v13[2] )
continue;
break;
}
}
else
{
v9 = 0;
}
LABEL_6:
a3(a4, 0xFFFFFFFFLL, 0LL);
free(ptr);
return v9;
}

original_code:
int parse_token(const char* text, const char* delims, OnTokenFunc on_token, void* ctx)
{
 enum _State
 {
  STAT_INIT,
  STAT_IN,
  STAT_OUT,
 }state = STAT_INIT;
 int count = 0;
 char* copy_text = strdup(text);
 char* p = copy_text;
 char* token = copy_text;
 for(p = copy_text; *p != '\0'; p++)
 {
  switch(state)
  {
   case STAT_INIT:
   case STAT_OUT:
   {
    if(!(strchr(delims, *p) != ((void *)0)))
    {
     token = p;
     state = STAT_IN;
    }
    break;
   }
   case STAT_IN:
   {
    if((strchr(delims, *p) != ((void *)0)))
    {
     *p = '\0';
     on_token(ctx, count++, token);
     state = STAT_OUT;
    }
    break;
   }
   default:break;
  }
 }
 if(state == STAT_IN)
 {
  on_token(ctx, count++, token);
 }
 on_token(ctx, -1, ((void *)0));
 free(copy_text);
 return count;
}

canonical_original_code:
int parse_token(char *text, char *delims, void (*on_token)(void *ctx, int index, char *token), void *ctx)
{
 enum _State state = STAT_INIT;
 int count = 0;
 char *copy_text = strdup(text);
 char *p = copy_text;
 char *token = copy_text;
 for(p = copy_text; *p != '\0'; p++)
 {
  switch(state)
  {
   case STAT_INIT:
   case STAT_OUT:
   {
    if(!(strchr(delims, *p) != ((void *)0)))
    {
     token = p;
     state = STAT_IN;
    }
    break;
   }
   case STAT_IN:
   {
    if((strchr(delims, *p) != ((void *)0)))
    {
     *p = '\0';
     on_token(ctx, count++, token);
     state = STAT_OUT;
    }
    break;
   }
   default:break;
  }
 }
 if(state == STAT_IN)
 {
  on_token(ctx, count++, token);
 }
 on_token(ctx, -1, ((void *)0));
 free(copy_text);
 return count;
}

variable_types:
text
char *

variable_types:
delims
char *

variable_types: void (*)(void *ctx, int index, char *token)

variable_types: enum _State { STAT_INIT=0, STAT_IN=1, STAT_OUT=2 }

variable_types: count int

variable_types:
p
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)parse_token("it is used to token segmentation. is it easy?", " .?", on_token, 0LL) != 9 )
__assert_fail(
"parse_token(\"it is used to token segmentation. is it easy?\", \" .?\", on_token, NULL) == 9",
"parse_token.c",
0x4Au,
"main");
if ( (unsigned int)parse_token(
"/backup/tools/jdk1.5.0_18/bin/:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/backup/tools/jdk1.5.0_18/bi"
"n/:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/home/lixianjing/bin",
":",
on_token,
0LL) != 9 )
__assert_fail(
"parse_token(\"/backup/tools/jdk1.5.0_18/bin/:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/backup/tools/jdk1.5.0_18/bin/:"
"/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/home/lixianjing/bin\", \":\", on_token, NULL) == 9",
"parse_token.c",
0x4Bu,
"main");
if ( (unsigned int)parse_token("/backup/tools/jdk1.5.0_18/bin/", "/", on_token, 0LL) != 4 )
__assert_fail(
"parse_token(\"/backup/tools/jdk1.5.0_18/bin/\", \"/\", on_token, NULL) == 4",
"parse_token.c",
0x4Cu,
"main");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func8("it is used to token segmentation. is it easy?", " .?", on_token, 0LL) != 9 )
__assert_fail(
"parse_token(\"it is used to token segmentation. is it easy?\", \" .?\", on_token, NULL) == 9",
"parse_token.c",
0x4Au,
"main");
if ( (unsigned int)func8(
"/backup/tools/jdk1.5.0_18/bin/:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/backup/tools/jdk1.5.0_18/bi"
"n/:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/home/lixianjing/bin",
":",
on_token,
0LL) != 9 )
__assert_fail(
"parse_token(\"/backup/tools/jdk1.5.0_18/bin/:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/backup/tools/jdk1.5.0_18/bin/:"
"/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/home/lixianjing/bin\", \":\", on_token, NULL) == 9",
"parse_token.c",
0x4Bu,
"main");
if ( (unsigned int)func8("/backup/tools/jdk1.5.0_18/bin/", "/", on_token, 0LL) != 4 )
__assert_fail(
"parse_token(\"/backup/tools/jdk1.5.0_18/bin/\", \"/\", on_token, NULL) == 4",
"parse_token.c",
0x4Cu,
"main");
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 ((void) sizeof ((parse_token("it is used to token segmentation. is it easy?", " .?", on_token, ((void *)0)) == 9) ? 1 : 0), __extension__ ({ if (parse_token("it is used to token segmentation. is it easy?", " .?", on_token, ((void *)0)) == 9) ; else __assert_fail ("parse_token(\"it is used to token segmentation. is it easy?\", \" .?\", on_token, NULL) == 9", "parse_token.c", 74, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((parse_token("/backup/tools/jdk1.5.0_18/bin/:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/backup/tools/jdk1.5.0_18/bin/:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/home/lixianjing/bin", ":", on_token, ((void *)0)) == 9) ? 1 : 0), __extension__ ({ if (parse_token("/backup/tools/jdk1.5.0_18/bin/:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/backup/tools/jdk1.5.0_18/bin/:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/home/lixianjing/bin", ":", on_token, ((void *)0)) == 9) ; else __assert_fail ("parse_token(\"/backup/tools/jdk1.5.0_18/bin/:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/backup/tools/jdk1.5.0_18/bin/:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/home/lixianjing/bin\", \":\", on_token, NULL) == 9", "parse_token.c", 75, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((parse_token("/backup/tools/jdk1.5.0_18/bin/", "/", on_token, ((void *)0)) == 4) ? 1 : 0), __extension__ ({ if (parse_token("/backup/tools/jdk1.5.0_18/bin/", "/", on_token, ((void *)0)) == 4) ; else __assert_fail ("parse_token(\"/backup/tools/jdk1.5.0_18/bin/\", \"/\", on_token, NULL) == 4", "parse_token.c", 76, __extension__ __PRETTY_FUNCTION__); }));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 ((void) sizeof ((parse_token("it is used to token segmentation. is it easy?", " .?", on_token, ((void *)0)) == 9) ? 1 : 0), __extension__ ({ if (parse_token("it is used to token segmentation. is it easy?", " .?", on_token, ((void *)0)) == 9) ; else __assert_fail ("parse_token(\"it is used to token segmentation. is it easy?\", \" .?\", on_token, NULL) == 9", "parse_token.c", 74, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((parse_token("/backup/tools/jdk1.5.0_18/bin/:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/backup/tools/jdk1.5.0_18/bin/:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/home/lixianjing/bin", ":", on_token, ((void *)0)) == 9) ? 1 : 0), __extension__ ({ if (parse_token("/backup/tools/jdk1.5.0_18/bin/:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/backup/tools/jdk1.5.0_18/bin/:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/home/lixianjing/bin", ":", on_token, ((void *)0)) == 9) ; else __assert_fail ("parse_token(\"/backup/tools/jdk1.5.0_18/bin/:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/backup/tools/jdk1.5.0_18/bin/:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/home/lixianjing/bin\", \":\", on_token, NULL) == 9", "parse_token.c", 75, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((parse_token("/backup/tools/jdk1.5.0_18/bin/", "/", on_token, ((void *)0)) == 4) ? 1 : 0), __extension__ ({ if (parse_token("/backup/tools/jdk1.5.0_18/bin/", "/", on_token, ((void *)0)) == 4) ; else __assert_fail ("parse_token(\"/backup/tools/jdk1.5.0_18/bin/\", \"/\", on_token, NULL) == 4", "parse_token.c", 76, __extension__ __PRETTY_FUNCTION__); }));
 return 0;
}


original_code:
static Ret merge_sort_impl(void** storage, void** array, size_t low, size_t mid, size_t high, DataCompareFunc cmp)
{
 size_t i = low;
 size_t j = low;
 size_t k = mid;
 if((low + 1) < mid)
 {
  size_t x = low + ((mid - low) >> 1);
  merge_sort_impl(storage, array, low, x, mid, cmp);
 }
 if((mid + 1) < high)
 {
  size_t x = mid + ((high - mid) >> 1);
  merge_sort_impl(storage, array, mid, x, high, cmp);
 }
 while(j < mid && k < high)
 {
  if(cmp(array[j], array[k]) <= 0)
  {
   storage[i++] = array[j++];
  }
  else
  {
   storage[i++] = array[k++];
  }
 }
 while(j < mid)
 {
  storage[i++] = array[j++];
 }
 while(k < high)
 {
  storage[i++] = array[k++];
 }
 for(i = low; i < high; i++)
 {
  array[i] = storage[i];
 }
 return RET_OK;
}

canonical_original_code:
static enum _Ret merge_sort_impl(void **storage, void **array, unsigned long low, unsigned long mid, unsigned long high, int (*cmp)(void *ctx, void *data))
{
 unsigned long i = low;
 unsigned long j = low;
 unsigned long k = mid;
 if((low + 1) < mid)
 {
  unsigned long x = low + ((mid - low) >> 1);
  merge_sort_impl(storage, array, low, x, mid, cmp);
 }
 if((mid + 1) < high)
 {
  unsigned long x = mid + ((high - mid) >> 1);
  merge_sort_impl(storage, array, mid, x, high, cmp);
 }
 while(j < mid && k < high)
 {
  if(cmp(array[j], array[k]) <= 0)
  {
   storage[i++] = array[j++];
  }
  else
  {
   storage[i++] = array[k++];
  }
 }
 while(j < mid)
 {
  storage[i++] = array[j++];
 }
 while(k < high)
 {
  storage[i++] = array[k++];
 }
 for(i = low; i < high; i++)
 {
  array[i] = storage[i];
 }
 return RET_OK;
}

variable_types:
storage
void **

variable_types:
array
void **

variable_types:
low
unsigned long

variable_types:
mid
unsigned long

variable_types:
high
unsigned long

variable_types:
cmp
int (*)(void *ctx, void *data)

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
k
unsigned long

variable_types:
x
unsigned long

user_defined_types: enum _Ret { RET_OK=0, RET_OOM=1, RET_STOP=2, RET_INVALID_PARAMS=3, RET_FAIL=4 }


decompiled_code:
__int64 __fastcall int_cmp(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

original_code:
int int_cmp(void* a, void* b)
{
 return (int)a - (int)b;
}

canonical_original_code:
int int_cmp(void *a, void *b)
{
 return (int)a - (int)b;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
__int64 __fastcall int_cmp_invert(int a1, int a2)
{
return (unsigned int)(a2 - a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
return (unsigned int)(a2 - a1);
}

original_code:
int int_cmp_invert(void* a, void* b)
{
 return (int)b - (int)a;
}

canonical_original_code:
int int_cmp_invert(void *a, void *b)
{
 return (int)b - (int)a;
}


decompiled_code:
__int64 __fastcall bubble_sort(_QWORD *a1, unsigned __int64 a2, int (__fastcall *a3)(_QWORD, _QWORD))
{
unsigned __int64 v3; // r13
__int64 v4; // r14
__int64 v5; // rbx
_QWORD *v6; // rbp
int v7; // eax
__int64 v8; // rax
__int64 result; // rax
unsigned __int64 v11; // [rsp+8h] [rbp-40h]

if ( a1 && a3 )
{
if ( a2 > 1 )
{
v3 = a2 - 1;
v4 = 0LL;
v11 = a2 - 2;
v5 = 1LL;
if ( a2 - 1 > 1 )
goto LABEL_5;
while ( 1 )
{
if ( a3(*a1, a1[v3]) > 0 )
{
v6 = a1;
LABEL_11:
v8 = a1[v3];
a1[v3] = *v6;
*v6 = v8;
}
if ( !v11 )
break;
while ( 1 )
{
--v3;
--v11;
v4 = 0LL;
v5 = 1LL;
if ( v3 <= 1 )
break;
do
{
LABEL_5:
v6 = &a1[v4];
v7 = a3(a1[v5], *v6);
if ( v7 > 0 )
v6 = &a1[v5];
if ( v7 > 0 )
v4 = v5;
++v5;
}
while ( v3 != v5 );
if ( a3(*v6, a1[v3]) > 0 )
goto LABEL_11;
}
}
}
result = 0LL;
}
else
{
printf("%s:%d Warning: array != NULL && cmp != NULL failed.\n", "bubble_sort", 40LL);
result = 3LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, unsigned __int64 a2, int (__fastcall *a3)(_QWORD, _QWORD))
{
unsigned __int64 v3; // r13
__int64 v4; // r14
__int64 v5; // rbx
_QWORD *v6; // rbp
int v7; // eax
__int64 v8; // rax
__int64 result; // rax
unsigned __int64 v11; // [rsp+8h] [rbp-40h]

if ( a1 && a3 )
{
if ( a2 > 1 )
{
v3 = a2 - 1;
v4 = 0LL;
v11 = a2 - 2;
v5 = 1LL;
if ( a2 - 1 > 1 )
goto LABEL_5;
while ( 1 )
{
if ( a3(*a1, a1[v3]) > 0 )
{
v6 = a1;
LABEL_11:
v8 = a1[v3];
a1[v3] = *v6;
*v6 = v8;
}
if ( !v11 )
break;
while ( 1 )
{
--v3;
--v11;
v4 = 0LL;
v5 = 1LL;
if ( v3 <= 1 )
break;
do
{
LABEL_5:
v6 = &a1[v4];
v7 = a3(a1[v5], *v6);
if ( v7 > 0 )
v6 = &a1[v5];
if ( v7 > 0 )
v4 = v5;
++v5;
}
while ( v3 != v5 );
if ( a3(*v6, a1[v3]) > 0 )
goto LABEL_11;
}
}
}
result = 0LL;
}
else
{
printf("%s:%d Warning: array != NULL && cmp != NULL failed.\n", "bubble_sort", 40LL);
result = 3LL;
}
return result;
}

original_code:
Ret bubble_sort(void** array, size_t nr, DataCompareFunc cmp)
{
 size_t i = 0;
 size_t max = 0;
 size_t right = 0;
 if(!(array != ((void *)0) && cmp != ((void *)0))) {printf("%s:%d Warning: ""array != NULL && cmp != NULL"" failed.\n", __func__, 40); return (RET_INVALID_PARAMS);};
 if(nr < 2)
 {
  return RET_OK;
 }
 for(right = nr - 1; right > 0; right--)
 {
  for(i = 1, max = 0; i < right; i++)
  {
   if(cmp(array[i], array[max]) > 0)
   {
    max = i;
   }
  }
  if(cmp(array[max], array[right]) > 0)
  {
   void* data = array[right];
   array[right] = array[max];
   array[max] = data;
  }
 }
 return RET_OK;
}

canonical_original_code:
enum _Ret bubble_sort(void **array, unsigned long nr, int (*cmp)(void *ctx, void *data))
{
 unsigned long i = 0;
 unsigned long max = 0;
 unsigned long right = 0;
 if(!(array != ((void *)0) && cmp != ((void *)0))) {printf("%s:%d Warning: ""array != NULL && cmp != NULL"" failed.\n", __func__, 40); return (RET_INVALID_PARAMS);};
 if(nr < 2)
 {
  return RET_OK;
 }
 for(right = nr - 1; right > 0; right--)
 {
  for(i = 1, max = 0; i < right; i++)
  {
   if(cmp(array[i], array[max]) > 0)
   {
    max = i;
   }
  }
  if(cmp(array[max], array[right]) > 0)
  {
   void *data = array[right];
   array[right] = array[max];
   array[max] = data;
  }
 }
 return RET_OK;
}

variable_types:
nr
unsigned long

variable_types:
max
unsigned long

variable_types:
right
unsigned long

variable_types:
data
void *


decompiled_code:
__int64 __fastcall merge_sort(__int64 a1, unsigned __int64 a2, __int64 (__fastcall *a3)(_QWORD, _QWORD))
{
__int64 result; // rax
void *v5; // rax
void *v6; // r13
unsigned int v7; // er12

if ( a1 && a3 )
{
if ( a2 > 1 && (v5 = malloc(8 * a2), (v6 = v5) != 0LL) )
{
v7 = merge_sort_impl((__int64)v5, a1, 0LL, a2 >> 1, a2, a3);
free(v6);
result = v7;
}
else
{
result = 0LL;
}
}
else
{
printf("%s:%d Warning: array != NULL && cmp != NULL failed.\n", "merge_sort", 173LL);
result = 3LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned __int64 a2, __int64 (__fastcall *a3)(_QWORD, _QWORD))
{
__int64 result; // rax
void *v5; // rax
void *v6; // r13
unsigned int v7; // er12

if ( a1 && a3 )
{
if ( a2 > 1 && (v5 = malloc(8 * a2), (v6 = v5) != 0LL) )
{
v7 = func7((__int64)v5, a1, 0LL, a2 >> 1, a2, a3);
free(v6);
result = v7;
}
else
{
result = 0LL;
}
}
else
{
printf("%s:%d Warning: array != NULL && cmp != NULL failed.\n", "merge_sort", 173LL);
result = 3LL;
}
return result;
}

original_code:
Ret merge_sort(void** array, size_t nr, DataCompareFunc cmp)
{
 void** storage = ((void *)0);
 Ret ret = RET_OK;
 if(!(array != ((void *)0) && cmp != ((void *)0))) {printf("%s:%d Warning: ""array != NULL && cmp != NULL"" failed.\n", __func__, 173); return (RET_INVALID_PARAMS);};
 if(nr > 1)
 {
  storage = (void**)malloc(sizeof(void*) * nr);
  if(storage != ((void *)0))
  {
   ret = merge_sort_impl(storage, array, 0, nr>>1, nr, cmp);
   free(storage);
  }
 }
 return ret;
}

canonical_original_code:
enum _Ret merge_sort(void **array, unsigned long nr, int (*cmp)(void *ctx, void *data))
{
 void **storage = ((void *)0);
 enum _Ret ret = RET_OK;
 if(!(array != ((void *)0) && cmp != ((void *)0))) {printf("%s:%d Warning: ""array != NULL && cmp != NULL"" failed.\n", __func__, 173); return (RET_INVALID_PARAMS);};
 if(nr > 1)
 {
  storage = (void **)malloc(sizeof(void *) * nr);
  if(storage != ((void *)0))
  {
   ret = merge_sort_impl(storage, array, 0, nr>>1, nr, cmp);
   free(storage);
  }
 }
 return ret;
}

variable_types: enum _Ret { RET_OK=0, RET_OOM=1, RET_STOP=2, RET_INVALID_PARAMS=3, RET_FAIL=4 }


decompiled_code:
void __fastcall sort_test_one_dec(void (__fastcall *a1)(char *, _QWORD, __int64 (__fastcall *)(int a1, int a2)), int a2)
{
char *v2; // rbp
char *v3; // rax

v2 = create_int_array(a2);
a1(v2, a2, int_cmp_invert);
if ( a2 > 1 )
{
v3 = v2;
do
{
if ( *((_QWORD *)v3 + 1) > *(_QWORD *)v3 )
__assert_fail("array[i] <= array[i-1]", "sort.c", 0xF1u, "sort_test_one_dec");
v3 += 8;
}
while ( v3 != &v2[8 * (a2 - 1)] );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func13(void (__fastcall *a1)(char *, _QWORD, __int64 (__fastcall *)(int a1, int a2)), int a2)
{
char *v2; // rbp
char *v3; // rax

v2 = func12(a2);
a1(v2, a2, int_cmp_invert);
if ( a2 > 1 )
{
v3 = v2;
do
{
if ( *((_QWORD *)v3 + 1) > *(_QWORD *)v3 )
__assert_fail("array[i] <= array[i-1]", "sort.c", 0xF1u, "sort_test_one_dec");
v3 += 8;
}
while ( v3 != &v2[8 * (a2 - 1)] );
}
free(v2);
}

original_code:
static void sort_test_one_dec(SortFunc sort, int n)
{
 int i = 0;
 void** array = create_int_array(n);
 sort((void**)array, n, int_cmp_invert);
 for(i = 1; i < n; i++)
 {
  ((void) sizeof ((array[i] <= array[i-1]) ? 1 : 0), __extension__ ({ if (array[i] <= array[i-1]) ; else __assert_fail ("array[i] <= array[i-1]", "sort.c", 241, __extension__ __PRETTY_FUNCTION__); }));
 }
 free(array);
 return;
}

canonical_original_code:
static void sort_test_one_dec(enum _Ret (*sort)(void **array, unsigned long nr, int (*cmp)(void *ctx, void *data)), int n)
{
 int i = 0;
 void **array = create_int_array(n);
 sort((void **)array, n, int_cmp_invert);
 for(i = 1; i < n; i++)
 {
  ((void) sizeof ((array[i] <= array[i-1]) ? 1 : 0), __extension__ ({ if (array[i] <= array[i-1]) ; else __assert_fail ("array[i] <= array[i-1]", "sort.c", 241, __extension__ __PRETTY_FUNCTION__); }));
 }
 free(array);
 return;
}

variable_types: enum _Ret { RET_OK=0, RET_OOM=1, RET_STOP=2, RET_INVALID_PARAMS=3, RET_FAIL=4 } (*)(void **array, unsigned long nr, int (*cmp)(void *ctx, void *data))

variable_types: n int

variable_types: i int


decompiled_code:
void __fastcall sort_test_one_asc(void (__fastcall *a1)(char *, _QWORD, __int64 (__fastcall *)(int a1, int a2)), int a2)
{
char *v2; // rbp
char *v3; // rax

v2 = create_int_array(a2);
a1(v2, a2, int_cmp);
if ( a2 > 1 )
{
v3 = v2;
do
{
if ( *((_QWORD *)v3 + 1) < *(_QWORD *)v3 )
__assert_fail("array[i] >= array[i-1]", "sort.c", 0xE0u, "sort_test_one_asc");
v3 += 8;
}
while ( v3 != &v2[8 * (a2 - 1)] );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func14(void (__fastcall *a1)(char *, _QWORD, __int64 (__fastcall *)(int a1, int a2)), int a2)
{
char *v2; // rbp
char *v3; // rax

v2 = func12(a2);
a1(v2, a2, int_cmp);
if ( a2 > 1 )
{
v3 = v2;
do
{
if ( *((_QWORD *)v3 + 1) < *(_QWORD *)v3 )
__assert_fail("array[i] >= array[i-1]", "sort.c", 0xE0u, "sort_test_one_asc");
v3 += 8;
}
while ( v3 != &v2[8 * (a2 - 1)] );
}
free(v2);
}

original_code:
static void sort_test_one_asc(SortFunc sort, int n)
{
 int i = 0;
 void** array = create_int_array(n);
 sort(array, n, int_cmp);
 for(i = 1; i < n; i++)
 {
  ((void) sizeof ((array[i] >= array[i-1]) ? 1 : 0), __extension__ ({ if (array[i] >= array[i-1]) ; else __assert_fail ("array[i] >= array[i-1]", "sort.c", 224, __extension__ __PRETTY_FUNCTION__); }));
 }
 free(array);
 return;
}

canonical_original_code:
static void sort_test_one_asc(enum _Ret (*sort)(void **array, unsigned long nr, int (*cmp)(void *ctx, void *data)), int n)
{
 int i = 0;
 void **array = create_int_array(n);
 sort(array, n, int_cmp);
 for(i = 1; i < n; i++)
 {
  ((void) sizeof ((array[i] >= array[i-1]) ? 1 : 0), __extension__ ({ if (array[i] >= array[i-1]) ; else __assert_fail ("array[i] >= array[i-1]", "sort.c", 224, __extension__ __PRETTY_FUNCTION__); }));
 }
 free(array);
 return;
}

variable_types:
array
void **


decompiled_code:
void __fastcall sort_test(void (__fastcall *a1)(char *, _QWORD, __int64 (__fastcall *)(int a1, int a2)))
{
int i; // ebx
int v2; // esi

for ( i = 0; i != 1000; ++i )
{
sort_test_one_dec(a1, i);
v2 = i;
sort_test_one_asc(a1, v2);
}
}

canonical_decompiled_code:
void __fastcall func15(void (__fastcall *a1)(char *, _QWORD, __int64 (__fastcall *)(int a1, int a2)))
{
int i; // ebx
int v2; // esi

for ( i = 0; i != 1000; ++i )
{
func13(a1, i);
v2 = i;
func14(a1, v2);
}
}

original_code:
static void sort_test(SortFunc sort)
{
 int i = 0;
 for(i = 0; i < 1000; i++)
 {
  sort_test_one_dec(sort, i);
  sort_test_one_asc(sort, i);
 }
 return ;
}

canonical_original_code:
static void sort_test(enum _Ret (*sort)(void **array, unsigned long nr, int (*cmp)(void *ctx, void *data)))
{
 int i = 0;
 for(i = 0; i < 1000; i++)
 {
  sort_test_one_dec(sort, i);
  sort_test_one_asc(sort, i);
 }
 return ;
}


original_code:
void quick_sort_impl(void** array, size_t left, size_t right, DataCompareFunc cmp)
{
 size_t save_left = left;
 size_t save_right = right;
 void* x = array[left];
 while(left < right)
 {
  while(cmp(array[right], x) >= 0 && left < right) right--;
  if(left != right)
  {
   array[left] = array[right];
   left++;
  }
  while(cmp(array[left], x) <= 0 && left < right) left++;
  if(left != right)
  {
   array[right] = array[left];
   right--;
  }
 }
 array[left] = x;
 if(save_left < left)
 {
  quick_sort_impl(array, save_left, left-1, cmp);
 }
 if(save_right > left)
 {
  quick_sort_impl(array, left+1, save_right, cmp);
 }
 return;
}

canonical_original_code:
void quick_sort_impl(void **array, unsigned long left, unsigned long right, int (*cmp)(void *ctx, void *data))
{
 unsigned long save_left = left;
 unsigned long save_right = right;
 void *x = array[left];
 while(left < right)
 {
  while(cmp(array[right], x) >= 0 && left < right) right--;
  if(left != right)
  {
   array[left] = array[right];
   left++;
  }
  while(cmp(array[left], x) <= 0 && left < right) left++;
  if(left != right)
  {
   array[right] = array[left];
   right--;
  }
 }
 array[left] = x;
 if(save_left < left)
 {
  quick_sort_impl(array, save_left, left-1, cmp);
 }
 if(save_right > left)
 {
  quick_sort_impl(array, left+1, save_right, cmp);
 }
 return;
}

variable_types:
left
unsigned long

variable_types:
x
void *


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

if ( a1 && a3 )
{
if ( a2 > 1 )
quick_sort_impl(a1, 0LL, a2 - 1, a3);
result = 0LL;
}
else
{
printf("%s:%d Warning: array != NULL && cmp != NULL failed.\n", "quick_sort", 109LL);
result = 3LL;
}
return result;
}

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

if ( a1 && a3 )
{
if ( a2 > 1 )
func16(a1, 0LL, a2 - 1, a3);
result = 0LL;
}
else
{
printf("%s:%d Warning: array != NULL && cmp != NULL failed.\n", "quick_sort", 109LL);
result = 3LL;
}
return result;
}

original_code:
Ret quick_sort(void** array, size_t nr, DataCompareFunc cmp)
{
 Ret ret = RET_OK;
 if(!(array != ((void *)0) && cmp != ((void *)0))) {printf("%s:%d Warning: ""array != NULL && cmp != NULL"" failed.\n", __func__, 109); return (RET_INVALID_PARAMS);};
 if(nr > 1)
 {
  quick_sort_impl(array, 0, nr - 1, cmp);
 }
 return ret;
}

canonical_original_code:
enum _Ret quick_sort(void **array, unsigned long nr, int (*cmp)(void *ctx, void *data))
{
 enum _Ret ret = RET_OK;
 if(!(array != ((void *)0) && cmp != ((void *)0))) {printf("%s:%d Warning: ""array != NULL && cmp != NULL"" failed.\n", __func__, 109); return (RET_INVALID_PARAMS);};
 if(nr > 1)
 {
  quick_sort_impl(array, 0, nr - 1, cmp);
 }
 return ret;
}

variable_types:
cmp
int (*)(void *ctx, void *data)


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
srand(0x64u);
sort_test(quick_sort, argv);
sort_test(merge_sort, argv);
sort_test(bubble_sort, argv);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
srand(0x64u);
func15(quick_sort, argv);
func15(merge_sort, argv);
func15(bubble_sort, argv);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 srand(100);
 sort_test(quick_sort);
 sort_test(merge_sort);
 sort_test(bubble_sort);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 srand(100);
 sort_test(quick_sort);
 sort_test(merge_sort);
 sort_test(bubble_sort);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
void *__fastcall thread_dec(void *a1)
{
int v1; // eax

do
atomic_dec_constprop_0();
while ( v1 != 1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // eax

do
func7();
while ( v1 != 1 );
return 0LL;
}

original_code:
static void* thread_dec(void* param)
{
 int i = 0;
 for(i = 0; i < 1000000; i++)
 {
  atomic_dec(&g_count);
 }
 return ((void *)0);
}

canonical_original_code:
static void *thread_dec(void *param)
{
 int i = 0;
 for(i = 0; i < 1000000; i++)
 {
  atomic_dec(&g_count);
 }
 return ((void *)0);
}

variable_types:
param
void *


decompiled_code:
void *__fastcall thread_inc(void *a1)
{
int v1; // eax

do
atomic_inc_constprop_0();
while ( v1 != 1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
int v1; // eax

do
func9();
while ( v1 != 1 );
return 0LL;
}

original_code:
static void* thread_inc(void* param)
{
 int i = 0;
 for(i = 0; i < 1000000; i++)
 {
  atomic_inc(&g_count);
 }
 return ((void *)0);
}

canonical_original_code:
static void *thread_inc(void *param)
{
 int i = 0;
 for(i = 0; i < 1000000; i++)
 {
  atomic_inc(&g_count);
 }
 return ((void *)0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

th = 0LL;
newthread[0] = 0LL;
pthread_create(&th, 0LL, thread_inc, 0LL);
pthread_create(newthread, 0LL, thread_dec, 0LL);
pthread_join(th, 0LL);
pthread_join(newthread[0], 0LL);
printf("count=%d\n", (unsigned int)g_count);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 pthread_t inc_tid = 0;
 pthread_t dec_tid = 0;
 pthread_create(&inc_tid, ((void *)0), thread_inc, ((void *)0));
 pthread_create(&dec_tid, ((void *)0), thread_dec, ((void *)0));
 pthread_join(inc_tid, ((void *)0));
 pthread_join(dec_tid, ((void *)0));
 printf("count=%d\n", g_count.counter);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long inc_tid = 0;
 unsigned long dec_tid = 0;
 pthread_create(&inc_tid, ((void *)0), thread_inc, ((void *)0));
 pthread_create(&dec_tid, ((void *)0), thread_dec, ((void *)0));
 pthread_join(inc_tid, ((void *)0));
 pthread_join(dec_tid, ((void *)0));
 printf("count=%d\n", g_count.counter);
 return 0;
}


strtrim

decompiled_code:
const char *__fastcall strtrim(const char *a1)
{
const char *v1; // rbx
const unsigned __int16 **v2; // rcx
__int64 v3; // rbp
const unsigned __int16 *v4; // rax
char v5; // dl
char *i; // rax

v1 = &a1[strlen(a1) - 1];
if ( a1 != v1 )
{
v2 = __ctype_b_loc();
while ( ((*v2)[*v1] & 0x2000) != 0 )
{
*v1-- = 0;
if ( a1 == v1 )
goto LABEL_6;
}
v1 = a1;
}
LABEL_6:
v3 = *v1;
if ( (_BYTE)v3 )
{
v4 = *__ctype_b_loc();
do
{
if ( (v4[v3] & 0x2000) == 0 )
{
if ( a1 == v1 )
return a1;
v5 = *v1;
for ( i = (char *)a1; *v1; v5 = *v1 )
{
++v1;
*i++ = v5;
}
goto LABEL_13;
}
v3 = *++v1;
}
while ( (_BYTE)v3 );
if ( a1 != v1 )
{
i = (char *)a1;
LABEL_13:
*i = 0;
return a1;
}
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1)
{
const char *v1; // rbx
const unsigned __int16 **v2; // rcx
__int64 v3; // rbp
const unsigned __int16 *v4; // rax
char v5; // dl
char *i; // rax

v1 = &a1[strlen(a1) - 1];
if ( a1 != v1 )
{
v2 = __ctype_b_loc();
while ( ((*v2)[*v1] & 0x2000) != 0 )
{
*v1-- = 0;
if ( a1 == v1 )
goto LABEL_6;
}
v1 = a1;
}
LABEL_6:
v3 = *v1;
if ( (_BYTE)v3 )
{
v4 = *__ctype_b_loc();
do
{
if ( (v4[v3] & 0x2000) == 0 )
{
if ( a1 == v1 )
return a1;
v5 = *v1;
for ( i = (char *)a1; *v1; v5 = *v1 )
{
++v1;
*i++ = v5;
}
goto LABEL_13;
}
v3 = *++v1;
}
while ( (_BYTE)v3 );
if ( a1 != v1 )
{
i = (char *)a1;
LABEL_13:
*i = 0;
return a1;
}
}
return a1;
}

original_code:
const char* strtrim(char* str)
{
 char* p = ((void *)0);
 p = str + strlen(str) - 1;
 while(p != str && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace))
 {
  *p = '\0';
  p--;
 }
 p = str;
 while(*p != '\0' && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace)) p++;
 if(p != str)
 {
  char* s = p;
  char* d = str;
  while(*s != '\0')
  {
   *d = *s;
   d++;
   s++;
  }
  *d = '\0';
 }
 return str;
}

canonical_original_code:
char *strtrim(char *str)
{
 char *p = ((void *)0);
 p = str + strlen(str) - 1;
 while(p != str && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace))
 {
  *p = '\0';
  p--;
 }
 p = str;
 while(*p != '\0' && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace)) p++;
 if(p != str)
 {
  char *s = p;
  char *d = str;
  while(*s != '\0')
  {
   *d = *s;
   d++;
   s++;
  }
  *d = '\0';
 }
 return str;
}

variable_types:
str
char *

variable_types:
p
char *

variable_types:
s
char *

variable_types:
d
char *


main

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

v3 = strdup("[lixianjing]\nname=lixianjing\ngender=male\n[zhangshan]\nname=zhangshan\ngender=male\nage=100");
ini_parse_internal_constprop_0(v3, argv);
free(v3);
return 0;
}

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

v3 = strdup("[lixianjing]\nname=lixianjing\ngender=male\n[zhangshan]\nname=zhangshan\ngender=male\nage=100");
func8(v3, argv);
free(v3);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 char* buffer = strdup("[lixianjing]\nname=lixianjing\ngender=male\n[zhangshan]\nname=zhangshan\ngender=male\nage=100");
 ini_parse_internal(buffer, '#', '=');
 free(buffer);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *buffer = strdup("[lixianjing]\nname=lixianjing\ngender=male\n[zhangshan]\nname=zhangshan\ngender=male\nage=100");
 ini_parse_internal(buffer, '#', '=');
 free(buffer);
 return 0;
}

variable_types:
buffer
char *


decompiled_code:
int __fastcall on_word(__int64 a1, const char *a2)
{
return puts(a2);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, const char *a2)
{
return puts(a2);
}

original_code:
void on_word(void* ctx, const char* word)
{
 printf("%s\n", word);
 return;
}

canonical_original_code:
void on_word(void *ctx, char *word)
{
 printf("%s\n", word);
 return;
}

variable_types:
ctx
void *

variable_types:
word
char *


original_code:
int word_segmentation(const char* text, OnWordFunc on_word, void* ctx)
{
 enum _State
 {
  STAT_INIT,
  STAT_IN_WORD,
  STAT_OUT_WORD,
 }state = STAT_INIT;
 int count = 0;
 char* copy_text = strdup(text);
 char* p = copy_text;
 char* word = copy_text;
 for(p = copy_text; *p != '\0'; p++)
 {
  switch(state)
  {
   case STAT_INIT:
   {
    if((((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)))
    {
     word = p;
     state = STAT_IN_WORD;
    }
    break;
   }
   case STAT_IN_WORD:
   {
    if(!(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)))
    {
     count++;
     *p = '\0';
     on_word(ctx, word);
     state = STAT_OUT_WORD;
    }
    break;
   }
   case STAT_OUT_WORD:
   {
    if((((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)))
    {
     word = p;
     state = STAT_IN_WORD;
    }
    break;
   }
   default:break;
  }
 }
 if(state == STAT_IN_WORD)
 {
  count++;
  on_word(ctx, word);
 }
 free(copy_text);
 return count;
}

canonical_original_code:
int word_segmentation(char *text, void (*on_word)(void *ctx, char *word), void *ctx)
{
 enum _State state = STAT_INIT;
 int count = 0;
 char *copy_text = strdup(text);
 char *p = copy_text;
 char *word = copy_text;
 for(p = copy_text; *p != '\0'; p++)
 {
  switch(state)
  {
   case STAT_INIT:
   {
    if((((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)))
    {
     word = p;
     state = STAT_IN_WORD;
    }
    break;
   }
   case STAT_IN_WORD:
   {
    if(!(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)))
    {
     count++;
     *p = '\0';
     on_word(ctx, word);
     state = STAT_OUT_WORD;
    }
    break;
   }
   case STAT_OUT_WORD:
   {
    if((((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)))
    {
     word = p;
     state = STAT_IN_WORD;
    }
    break;
   }
   default:break;
  }
 }
 if(state == STAT_IN_WORD)
 {
  count++;
  on_word(ctx, word);
 }
 free(copy_text);
 return count;
}

variable_types:
text
char *

variable_types: enum _State { STAT_INIT=0, STAT_IN_WORD=1, STAT_OUT_WORD=2 }

variable_types: count int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)word_segmentation("it is used to word segmentation. is it easy?", &on_word, 0LL) != 9 )
__assert_fail(
"word_segmentation(\"it is used to word segmentation. is it easy?\", on_word, NULL) == 9",
"word_segmentation.c",
0x54u,
"main");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func8("it is used to word segmentation. is it easy?", &on_word, 0LL) != 9 )
__assert_fail(
"word_segmentation(\"it is used to word segmentation. is it easy?\", on_word, NULL) == 9",
"word_segmentation.c",
0x54u,
"main");
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 ((void) sizeof ((word_segmentation("it is used to word segmentation. is it easy?", on_word, ((void *)0)) == 9) ? 1 : 0), __extension__ ({ if (word_segmentation("it is used to word segmentation. is it easy?", on_word, ((void *)0)) == 9) ; else __assert_fail ("word_segmentation(\"it is used to word segmentation. is it easy?\", on_word, NULL) == 9", "word_segmentation.c", 84, __extension__ __PRETTY_FUNCTION__); }));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 ((void) sizeof ((word_segmentation("it is used to word segmentation. is it easy?", on_word, ((void *)0)) == 9) ? 1 : 0), __extension__ ({ if (word_segmentation("it is used to word segmentation. is it easy?", on_word, ((void *)0)) == 9) ; else __assert_fail ("word_segmentation(\"it is used to word segmentation. is it easy?\", on_word, NULL) == 9", "word_segmentation.c", 84, __extension__ __PRETTY_FUNCTION__); }));
 return 0;
}


decompiled_code:
int __fastcall allocator_self_manage_merge2(__int64 a1, _QWORD *a2, __int64 *a3)
{
__int64 v3; // rax
__int64 v4; // rax

if ( a2 && a3 && (__int64 *)a2[1] == a3 )
{
v4 = a3[1];
a2[1] = v4;
if ( v4 )
*(_QWORD *)(v4 + 16) = a2;
v3 = *a3;
*a2 += *a3;
if ( *(__int64 **)(a1 + 56) == a3 )
*(_QWORD *)(a1 + 56) = a2;
}
else
{
LODWORD(v3) = printf(
"%s:%d Warning: prev != NULL && next != NULL && prev->next == next failed.\n",
"allocator_self_manage_merge2",
102LL);
}
return v3;
}

original_code:
static void allocator_self_manage_merge2(Allocator* thiz, FreeNode* prev, FreeNode* next)
{
 PrivInfo* priv = (PrivInfo*)thiz->priv;
 if(!(prev != ((void *)0) && next != ((void *)0) && prev->next == next)) {printf("%s:%d Warning: ""prev != NULL && next != NULL && prev->next == next"" failed.\n", __func__, 102); return;};
 prev->next = next->next;
 if(next->next != ((void *)0))
 {
  next->next->prev = prev;
 }
 prev->length += next->length;
 if(priv->free_list == next)
 {
  priv->free_list = prev;
 }
 return;
}

canonical_original_code:
static void allocator_self_manage_merge2(struct _Allocator *thiz, struct _FreeNode *prev, struct _FreeNode *next)
{
 struct _PrivInfo *priv = (PrivInfo*)thiz->priv;
 if(!(prev != ((void *)0) && next != ((void *)0) && prev->next == next)) {printf("%s:%d Warning: ""prev != NULL && next != NULL && prev->next == next"" failed.\n", __func__, 102); return;};
 prev->next = next->next;
 if(next->next != ((void *)0))
 {
  next->next->prev = prev;
 }
 prev->length += next->length;
 if(priv->free_list == next)
 {
  priv->free_list = prev;
 }
 return;
}

variable_types: struct _Allocator { void *(*calloc)(struct _Allocator *thiz, unsigned long nmemb, unsigned long size); void *(*alloc)(struct _Allocator *thiz, unsigned long size); void (*free)(struct _Allocator *thiz, void *ptr); void *(*realloc)(struct _Allocator *thiz, void *ptr, unsigned long size); void (*destroy)(struct _Allocator *thiz); char priv[]; } *

variable_types:
next
struct _FreeNode *

variable_types: struct _PrivInfo { char *buffer; unsigned long length; struct _FreeNode { unsigned long length; struct _FreeNode *next; struct _FreeNode *prev; } *free_list; } *

user_defined_types: struct _PrivInfo { char *buffer; unsigned long length; struct _FreeNode *free_list; }


decompiled_code:
int __fastcall allocator_self_manage_merge(__int64 a1, __int64 *a2)
{
_QWORD *v2; // rbp
__int64 *v3; // r12
__int64 *v4; // rax

v2 = (_QWORD *)a2[2];
v3 = (__int64 *)a2[1];
if ( v2 )
{
v4 = (_QWORD *)((char *)v2 + *v2);
if ( a2 == v4 )
goto LABEL_7;
}
LABEL_3:
while ( v3 )
{
v4 = (__int64 *)((char *)a2 + *a2);
if ( v3 != v4 )
break;
LODWORD(v4) = allocator_self_manage_merge2(a1, a2, v3);
v2 = (_QWORD *)a2[2];
v3 = (__int64 *)a2[1];
if ( !v2 )
goto LABEL_3;
v4 = (_QWORD *)((char *)v2 + *v2);
if ( a2 != v4 )
goto LABEL_3;
LABEL_7:
allocator_self_manage_merge2(a1, v2, a2);
LODWORD(v4) = allocator_self_manage_merge(a1, v2);
}
return (int)v4;
}

original_code:
static void allocator_self_manage_merge(Allocator* thiz, FreeNode* iter)
{
 FreeNode* prev = iter->prev;
 FreeNode* next = iter->next;
 if(prev != ((void *)0) && ((size_t)prev + prev->length) == (size_t)iter)
 {
  allocator_self_manage_merge2(thiz, prev, iter);
  allocator_self_manage_merge(thiz, prev);
 }
 if(next != ((void *)0) && ((size_t)iter + iter->length) == (size_t)next)
 {
  allocator_self_manage_merge2(thiz, iter, next);
  allocator_self_manage_merge(thiz, iter);
 }
 return;
}

canonical_original_code:
static void allocator_self_manage_merge(struct _Allocator *thiz, struct _FreeNode *iter)
{
 struct _FreeNode *prev = iter->prev;
 struct _FreeNode *next = iter->next;
 if(prev != ((void *)0) && ((unsigned long)prev + prev->length) == (unsigned long)iter)
 {
  allocator_self_manage_merge2(thiz, prev, iter);
  allocator_self_manage_merge(thiz, prev);
 }
 if(next != ((void *)0) && ((unsigned long)iter + iter->length) == (unsigned long)next)
 {
  allocator_self_manage_merge2(thiz, iter, next);
  allocator_self_manage_merge(thiz, iter);
 }
 return;
}

variable_types: struct _FreeNode { unsigned long length; struct _FreeNode *next; struct _FreeNode *prev; } *

user_defined_types: struct _Allocator { void *(*calloc)(struct _Allocator *thiz, unsigned long nmemb, unsigned long size); void *(*alloc)(struct _Allocator *thiz, unsigned long size); void (*free)(struct _Allocator *thiz, void *ptr); void *(*realloc)(struct _Allocator *thiz, void *ptr, unsigned long size); void (*destroy)(struct _Allocator *thiz); char priv[]; }


decompiled_code:
int __fastcall allocator_self_manage_free(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v3; // r8
__int64 *v4; // rsi
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
__int64 v7; // rdx

if ( a2 )
{
v3 = *(_QWORD *)(a1 + 56);
a2[1] = 0LL;
v4 = (__int64 *)(a2 - 1);
*a2 = 0LL;
v5 = v3;
if ( v3 )
{
while ( v5 <= (unsigned __int64)v4 )
{
if ( !*(_QWORD *)(v5 + 8) )
{
*(_QWORD *)(v5 + 8) = v4;
a2[1] = v5;
goto LABEL_11;
}
v5 = *(_QWORD *)(v5 + 8);
}
v6 = *(_QWORD *)(v5 + 16);
*a2 = v5;
a2[1] = v6;
v7 = *(_QWORD *)(v5 + 16);
if ( v7 )
*(_QWORD *)(v7 + 8) = v4;
*(_QWORD *)(v5 + 16) = v4;
if ( v3 == v5 )
*(_QWORD *)(a1 + 56) = v4;
LABEL_11:
LODWORD(v5) = allocator_self_manage_merge(a1, v4);
}
else
{
*(_QWORD *)(a1 + 56) = v4;
}
}
else
{
LODWORD(v5) = printf("%s:%d Warning: ptr != NULL failed.\n", "allocator_self_manage_free", 145LL);
}
return v5;
}

original_code:
static void allocator_self_manage_free(Allocator* thiz, void *ptr)
{
 FreeNode* iter = ((void *)0);
 FreeNode* free_iter = ((void *)0);
 PrivInfo* priv = (PrivInfo*)thiz->priv;
 if(!(ptr != ((void *)0))) {printf("%s:%d Warning: ""ptr != NULL"" failed.\n", __func__, 145); return;};
 free_iter = (FreeNode*)((char*)ptr - sizeof(size_t));
 free_iter->prev = ((void *)0);
 free_iter->next = ((void *)0);
 if(priv->free_list == ((void *)0))
 {
  priv->free_list = free_iter;
  return;
 }
 for(iter = priv->free_list; iter != ((void *)0); iter = iter->next)
 {
  if((size_t)iter > (size_t)free_iter)
  {
   free_iter->next = iter;
   free_iter->prev = iter->prev;
   if(iter->prev != ((void *)0))
   {
    iter->prev->next = free_iter;
   }
   iter->prev = free_iter;
   if(priv->free_list == iter)
   {
    priv->free_list = free_iter;
   }
   break;
  }
  if(iter->next == ((void *)0))
  {
   iter->next = free_iter;
   free_iter->prev = iter;
   break;
  }
 }
 allocator_self_manage_merge(thiz, free_iter);
 return;
}

canonical_original_code:
static void allocator_self_manage_free(struct _Allocator *thiz, void *ptr)
{
 struct _FreeNode *iter = ((void *)0);
 struct _FreeNode *free_iter = ((void *)0);
 struct _PrivInfo *priv = (PrivInfo*)thiz->priv;
 if(!(ptr != ((void *)0))) {printf("%s:%d Warning: ""ptr != NULL"" failed.\n", __func__, 145); return;};
 free_iter = (struct _FreeNode *)((char *)ptr - sizeof(unsigned long));
 free_iter->prev = ((void *)0);
 free_iter->next = ((void *)0);
 if(priv->free_list == ((void *)0))
 {
  priv->free_list = free_iter;
  return;
 }
 for(iter = priv->free_list; iter != ((void *)0); iter = iter->next)
 {
  if((unsigned long)iter > (unsigned long)free_iter)
  {
   free_iter->next = iter;
   free_iter->prev = iter->prev;
   if(iter->prev != ((void *)0))
   {
    iter->prev->next = free_iter;
   }
   iter->prev = free_iter;
   if(priv->free_list == iter)
   {
    priv->free_list = free_iter;
   }
   break;
  }
  if(iter->next == ((void *)0))
  {
   iter->next = free_iter;
   free_iter->prev = iter;
   break;
  }
 }
 allocator_self_manage_merge(thiz, free_iter);
 return;
}

variable_types:
ptr
void *

user_defined_types: struct _FreeNode { unsigned long length; struct _FreeNode *next; struct _FreeNode *prev; }


decompiled_code:
int __fastcall allocator_free(__int64 a1)
{
__int64 (*v1)(void); // rax
int result; // eax

if ( a1 && (v1 = *(__int64 (**)(void))(a1 + 16)) != 0LL )
result = v1();
else
result = printf("%s:%d Warning: thiz != NULL && thiz->free != NULL failed.\n", "allocator_free", 45LL);
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
__int64 (*v1)(void); // rax
int result; // eax

if ( a1 && (v1 = *(__int64 (**)(void))(a1 + 16)) != 0LL )
result = v1();
else
result = printf("%s:%d Warning: thiz != NULL && thiz->free != NULL failed.\n", "allocator_free", 45LL);
return result;
}

original_code:
static inline void allocator_free(Allocator* thiz, void *ptr)
{
 if(!(thiz != ((void *)0) && thiz->free != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->free != NULL"" failed.\n", __func__, 45); return;};
 thiz->free(thiz, ptr);
 return;
}

canonical_original_code:
static inline void allocator_free(struct _Allocator *thiz, void *ptr)
{
 if(!(thiz != ((void *)0) && thiz->free != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->free != NULL"" failed.\n", __func__, 45); return;};
 thiz->free(thiz, ptr);
 return;
}


decompiled_code:
__int64 __fastcall allocator_alloc(__int64 a1)
{
__int64 (*v1)(void); // rax

if ( a1 )
{
v1 = *(__int64 (**)(void))(a1 + 8);
if ( v1 )
return v1();
}
printf("%s:%d Warning: thiz != NULL && thiz->alloc != NULL failed.\n", "allocator_alloc", 38LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 (*v1)(void); // rax

if ( a1 )
{
v1 = *(__int64 (**)(void))(a1 + 8);
if ( v1 )
return v1();
}
printf("%s:%d Warning: thiz != NULL && thiz->alloc != NULL failed.\n", "allocator_alloc", 38LL);
return 0LL;
}

original_code:
static inline void* allocator_alloc(Allocator* thiz, size_t size)
{
 if(!(thiz != ((void *)0) && thiz->alloc != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->alloc != NULL"" failed.\n", __func__, 38); return (((void *)0));};
 return thiz->alloc(thiz, size);
}

canonical_original_code:
static inline void *allocator_alloc(struct _Allocator *thiz, unsigned long size)
{
 if(!(thiz != ((void *)0) && thiz->alloc != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->alloc != NULL"" failed.\n", __func__, 38); return (((void *)0));};
 return thiz->alloc(thiz, size);
}

variable_types:
size
unsigned long


decompiled_code:
int __fastcall allocator_destroy(__int64 a1)
{
__int64 (*v1)(void); // rax
int result; // eax

if ( a1 && (v1 = *(__int64 (**)(void))(a1 + 32)) != 0LL )
result = v1();
else
result = printf("%s:%d Warning: thiz != NULL && thiz->destroy != NULL failed.\n", "allocator_destroy", 61LL);
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
__int64 (*v1)(void); // rax
int result; // eax

if ( a1 && (v1 = *(__int64 (**)(void))(a1 + 32)) != 0LL )
result = v1();
else
result = printf("%s:%d Warning: thiz != NULL && thiz->destroy != NULL failed.\n", "allocator_destroy", 61LL);
return result;
}

original_code:
static inline void allocator_destroy(Allocator* thiz)
{
 if(!(thiz != ((void *)0) && thiz->destroy != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->destroy != NULL"" failed.\n", __func__, 61); return;};
 return thiz->destroy(thiz);
}

canonical_original_code:
static inline void allocator_destroy(struct _Allocator *thiz)
{
 if(!(thiz != ((void *)0) && thiz->destroy != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->destroy != NULL"" failed.\n", __func__, 61); return;};
 return thiz->destroy(thiz);
}