decompiled_code:
__int64 __fastcall ppnfs_read(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v7; // rbx
int v8; // er12
unsigned int v9; // er12
__int64 v10; // rsi
void *v11; // r15
unsigned int i; // er14
__int64 v13; // r12
void *v14; // rax
__int64 v16; // [rsp+8h] [rbp-D8h]
unsigned int v17; // [rsp+10h] [rbp-D0h]
unsigned int v18; // [rsp+18h] [rbp-C8h]
unsigned int v19; // [rsp+1Ch] [rbp-C4h]
char v20[16]; // [rsp+20h] [rbp-C0h] BYREF
char v21[16]; // [rsp+30h] [rbp-B0h] BYREF
char v22[16]; // [rsp+40h] [rbp-A0h] BYREF
char v23[16]; // [rsp+50h] [rbp-90h] BYREF
char v24[16]; // [rsp+60h] [rbp-80h] BYREF
char v25[16]; // [rsp+70h] [rbp-70h] BYREF
char v26[16]; // [rsp+80h] [rbp-60h] BYREF
char v27[80]; // [rsp+90h] [rbp-50h] BYREF

v7 = ppnfs_metadata_find(a1);
clock();
v8 = NR_BITPERBLK;
_gmpz_init(v26);
init_rand(v27, v26, (unsigned int)((v8 >> 3) + 1));
ppnfs_genmodulus(v7, (unsigned int)v8, v27, v24, v23, v22);
if ( *(_QWORD *)(v7 + 384) <= a4 )
{
v17 = 0;
LABEL_11:
clock();
ppnfs_metadata_release(v7);
return v17;
}
v9 = ppnfs_client_send_gm(v24, v22);
if ( v9 )
{
v17 = 0;
goto LABEL_11;
}
v10 = *(_QWORD *)(v7 + 384) - a4;
if ( (unsigned __int64)(a4 + a3) <= *(_QWORD *)(v7 + 384) )
v10 = a3;
v17 = v10;
v16 = a4 / ((unsigned int)NR_BITPERBLK >> 4);
v19 = v16;
v18 = (v10 + a4 - 1) / (unsigned __int64)((unsigned int)NR_BITPERBLK >> 4) + 1;
if ( (unsigned int)ppnfs_client_send_blknr(
v18 - (unsigned int)v16,
v10,
(v10 + a4 - 1) % (unsigned __int64)((unsigned int)NR_BITPERBLK >> 4)) != -1 )
{
v11 = malloc(((unsigned int)NR_BITPERBLK >> 3) + 1);
for ( i = v16; i < v18; v19 = i )
{
_gmpz_init(v25);
_gmpz_powm(v25, v24, v23, v22);
v13 = ppnfs_client_retrieve_block(v19);
v14 = malloc((unsigned int)NR_BITPERBLK);
_gmp_sprintf(v14, "%Zx\n", v13);
_gmpz_init(v20);
_gmpz_init(v21);
_gmpz_powm(v20, v13, v23, v22);
discrete_log(v21, v25, v20, v22, *(unsigned int *)(v7 + 480), *(unsigned int *)(v7 + 484));
memset(v11, 0, ((unsigned int)NR_BITPERBLK >> 3) + 1);
_gmp_sprintf(v11, "%Zx", v21);
groupStr(a2, v11);
a2 += (unsigned int)NR_BITPERBLK >> 4;
++i;
}
goto LABEL_11;
}
ppnfs_metadata_release(v7);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v7; // rbx
int v8; // er12
unsigned int v9; // er12
__int64 v10; // rsi
void *v11; // r15
unsigned int i; // er14
__int64 v13; // r12
void *v14; // rax
__int64 v16; // [rsp+8h] [rbp-D8h]
unsigned int v17; // [rsp+10h] [rbp-D0h]
unsigned int v18; // [rsp+18h] [rbp-C8h]
unsigned int v19; // [rsp+1Ch] [rbp-C4h]
char v20[16]; // [rsp+20h] [rbp-C0h] BYREF
char v21[16]; // [rsp+30h] [rbp-B0h] BYREF
char v22[16]; // [rsp+40h] [rbp-A0h] BYREF
char v23[16]; // [rsp+50h] [rbp-90h] BYREF
char v24[16]; // [rsp+60h] [rbp-80h] BYREF
char v25[16]; // [rsp+70h] [rbp-70h] BYREF
char v26[16]; // [rsp+80h] [rbp-60h] BYREF
char v27[80]; // [rsp+90h] [rbp-50h] BYREF

v7 = ppnfs_metadata_find(a1);
clock();
v8 = NR_BITPERBLK;
_gmpz_init(v26);
init_rand(v27, v26, (unsigned int)((v8 >> 3) + 1));
ppnfs_genmodulus(v7, (unsigned int)v8, v27, v24, v23, v22);
if ( *(_QWORD *)(v7 + 384) <= a4 )
{
v17 = 0;
LABEL_11:
clock();
ppnfs_metadata_release(v7);
return v17;
}
v9 = ppnfs_client_send_gm(v24, v22);
if ( v9 )
{
v17 = 0;
goto LABEL_11;
}
v10 = *(_QWORD *)(v7 + 384) - a4;
if ( (unsigned __int64)(a4 + a3) <= *(_QWORD *)(v7 + 384) )
v10 = a3;
v17 = v10;
v16 = a4 / ((unsigned int)NR_BITPERBLK >> 4);
v19 = v16;
v18 = (v10 + a4 - 1) / (unsigned __int64)((unsigned int)NR_BITPERBLK >> 4) + 1;
if ( (unsigned int)ppnfs_client_send_blknr(
v18 - (unsigned int)v16,
v10,
(v10 + a4 - 1) % (unsigned __int64)((unsigned int)NR_BITPERBLK >> 4)) != -1 )
{
v11 = malloc(((unsigned int)NR_BITPERBLK >> 3) + 1);
for ( i = v16; i < v18; v19 = i )
{
_gmpz_init(v25);
_gmpz_powm(v25, v24, v23, v22);
v13 = ppnfs_client_retrieve_block(v19);
v14 = malloc((unsigned int)NR_BITPERBLK);
_gmp_sprintf(v14, "%Zx\n", v13);
_gmpz_init(v20);
_gmpz_init(v21);
_gmpz_powm(v20, v13, v23, v22);
discrete_log(v21, v25, v20, v22, *(unsigned int *)(v7 + 480), *(unsigned int *)(v7 + 484));
memset(v11, 0, ((unsigned int)NR_BITPERBLK >> 3) + 1);
_gmp_sprintf(v11, "%Zx", v21);
groupStr(a2, v11);
a2 += (unsigned int)NR_BITPERBLK >> 4;
++i;
}
goto LABEL_11;
}
ppnfs_metadata_release(v7);
return v9;
}

original_code:
static int
ppnfs_read(const char *path, char *buf, size_t size, off_t offset,
     struct fuse_file_info* info)
{
    struct ppnfs_metadata_t* mdata = ppnfs_metadata_find(path);
    clock_t start, end;
    start = clock();
    char timebuf[128];
    int modulusbits = NR_BITPERBLK;
    gmp_randstate_t rand;
    mpz_t seed;
    __gmpz_init(seed);
    init_rand(rand, seed, (modulusbits >> 3) + 1);
    mpz_t h, g, q, M;
    ppnfs_genmodulus(mdata, modulusbits, rand, &g, &q, &M);
    if (offset < mdata->st.st_size && ppnfs_client_send_gm(&g, &M) == 0) {
        char* pbuf = buf;
        if (offset + size > mdata->st.st_size) {
            size = mdata->st.st_size - offset;
        }
        mpz_t he;
        mpz_t data;
        unsigned int mask = NR_BITPERBLK >> 4;
        unsigned int blk_begin = offset / mask;
        unsigned int blk_end = (offset + size - 1) / mask + 1;
        if (ppnfs_client_send_blknr(blk_end - blk_begin) == -1){
            size = 0;
            ppnfs_metadata_release(mdata);
            return size;
        }
        char *buffer = malloc((NR_BITPERBLK >> 3) + 1);
        int i;
        for (i = blk_begin; i < blk_end; ++i) {
            __gmpz_init(h);
            __gmpz_powm(h, g, q, M);
            mpz_t* ge = ppnfs_client_retrieve_block(i);
            char* gestr = (char*)malloc(sizeof(char) * NR_BITPERBLK);
            __gmp_sprintf(gestr, "%Zx\n", ge);
            __gmpz_init(he);
            __gmpz_init(data);
            __gmpz_powm(he, *ge, q, M);
            discrete_log(data, h, he, M, mdata->prime, mdata->c);
            memset(buffer, 0, (NR_BITPERBLK >> 3) + 1);
            __gmp_sprintf(buffer, "%Zx", data);
            groupStr(pbuf, buffer);
            pbuf += (NR_BITPERBLK >> 4);
        }
    } else {
        size = 0;
    }
    end = clock();
    ppnfs_metadata_release(mdata);
 return size;
}

canonical_original_code:
static int ppnfs_read(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *info)
{
    struct ppnfs_metadata_t *mdata = ppnfs_metadata_find(path);
    long start; long end;
    start = clock();
    char timebuf[128];
    int modulusbits = NR_BITPERBLK;
    struct __gmp_randstate_struct rand[1];
    struct __mpz_struct seed[1];
    __gmpz_init(seed);
    init_rand(rand, seed, (modulusbits >> 3) + 1);
    struct __mpz_struct h[1]; struct __mpz_struct g[1]; struct __mpz_struct q[1]; struct __mpz_struct M[1];
    ppnfs_genmodulus(mdata, modulusbits, rand, &g, &q, &M);
    if (offset < mdata->st.st_size && ppnfs_client_send_gm(&g, &M) == 0) {
        char *pbuf = buf;
        if (offset + size > mdata->st.st_size) {
            size = mdata->st.st_size - offset;
        }
        struct __mpz_struct he[1];
        struct __mpz_struct data[1];
        unsigned int mask = NR_BITPERBLK >> 4;
        unsigned int blk_begin = offset / mask;
        unsigned int blk_end = (offset + size - 1) / mask + 1;
        if (ppnfs_client_send_blknr(blk_end - blk_begin) == -1){
            size = 0;
            ppnfs_metadata_release(mdata);
            return size;
        }
        char *buffer = malloc((NR_BITPERBLK >> 3) + 1);
        int i;
        for (i = blk_begin; i < blk_end; ++i) {
            __gmpz_init(h);
            __gmpz_powm(h, g, q, M);
            struct __mpz_struct (*ge)[1] = ppnfs_client_retrieve_block(i);
            char *gestr = (char*)malloc(sizeof(char) * NR_BITPERBLK);
            __gmp_sprintf(gestr, "%Zx\n", ge);
            __gmpz_init(he);
            __gmpz_init(data);
            __gmpz_powm(he, *ge, q, M);
            discrete_log(data, h, he, M, mdata->prime, mdata->c);
            memset(buffer, 0, (NR_BITPERBLK >> 3) + 1);
            __gmp_sprintf(buffer, "%Zx", data);
            groupStr(pbuf, buffer);
            pbuf += (NR_BITPERBLK >> 4);
        }
    } else {
        size = 0;
    }
    end = clock();
    ppnfs_metadata_release(mdata);
 return size;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types: start long

variable_types: end long

variable_types:
timebuf
char [128]

variable_types: modulusbits int

variable_types: struct __gmp_randstate_struct { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
pbuf
char *

variable_types:
mask
unsigned int

variable_types:
buffer
char *

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]

variable_types:
gestr
char *

user_defined_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t _mp_alg; union { void *_mp_lc; } _mp_algdata; }


repo: yubai/PPNFS

decompiled_code:
__int64 ppnfs_getattr()
{
return ppnfs_metadata_getattr();
}

canonical_decompiled_code:
__int64 func4()
{
return ppnfs_metadata_getattr();
}

original_code:
static int
ppnfs_getattr(const char *path, struct stat *stbuf)
{
    return ppnfs_metadata_getattr(path, stbuf);
}

canonical_original_code:
static int ppnfs_getattr(char *path, struct stat *stbuf)
{
    return ppnfs_metadata_getattr(path, stbuf);
}

variable_types:
path
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *

return_type: int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
int ppnfs_client_net_close()
{
return close(hsock);
}

canonical_decompiled_code:
int func3()
{
return close(hsock);
}

original_code:
void
ppnfs_client_net_close()
{
    close(hsock);
}

return_type: void


mheadcmd

decompiled_code:
_DWORD *mheadcmd()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 1;
return result;
}

canonical_decompiled_code:
_DWORD *func4()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 1;
return result;
}

original_code:
struct ppnfs_net_cmd*
mheadcmd()
{
    struct ppnfs_net_mhead_cmd* cmd;
    cmd = (struct ppnfs_net_mhead_cmd*) malloc (sizeof(struct ppnfs_net_mhead_cmd));
    cmd->type = PPNFS_REQUEST_MHEAD;
    return (struct ppnfs_net_cmd*)cmd;
}

canonical_original_code:
struct ppnfs_net_cmd *mheadcmd()
{
    struct ppnfs_net_mhead_cmd *cmd;
    cmd = (struct ppnfs_net_mhead_cmd *) malloc (sizeof(struct ppnfs_net_mhead_cmd));
    cmd->type = PPNFS_REQUEST_MHEAD;
    return (struct ppnfs_net_cmd *)cmd;
}

variable_types: struct ppnfs_net_mhead_cmd { enum _ppnfs_net_type { PPNFS_REQUEST_MHEAD=1, PPNFS_REQUEST_MDATA=2, PPNFS_REQUEST_BLOCK=3 } type; } *

return_type: struct ppnfs_net_cmd { enum _ppnfs_net_type { PPNFS_REQUEST_MHEAD=1, PPNFS_REQUEST_MDATA=2, PPNFS_REQUEST_BLOCK=3 } type; } *

user_defined_types: struct ppnfs_net_mhead_cmd { enum _ppnfs_net_type type; }

user_defined_types: struct ppnfs_net_cmd { enum _ppnfs_net_type type; }


mdatacmd

decompiled_code:
_DWORD *mdatacmd()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 2;
return result;
}

canonical_decompiled_code:
_DWORD *func5()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 2;
return result;
}

original_code:
struct ppnfs_net_cmd*
mdatacmd()
{
    struct ppnfs_net_mdata_cmd* cmd;
    cmd = (struct ppnfs_net_mdata_cmd*) malloc (sizeof(struct ppnfs_net_mdata_cmd));
    cmd->type = PPNFS_REQUEST_MDATA;
    return (struct ppnfs_net_cmd*)cmd;
}

canonical_original_code:
struct ppnfs_net_cmd *mdatacmd()
{
    struct ppnfs_net_mdata_cmd *cmd;
    cmd = (struct ppnfs_net_mdata_cmd *) malloc (sizeof(struct ppnfs_net_mdata_cmd));
    cmd->type = PPNFS_REQUEST_MDATA;
    return (struct ppnfs_net_cmd *)cmd;
}

variable_types: struct ppnfs_net_mdata_cmd { enum _ppnfs_net_type { PPNFS_REQUEST_MHEAD=1, PPNFS_REQUEST_MDATA=2, PPNFS_REQUEST_BLOCK=3 } type; } *

user_defined_types: struct ppnfs_net_mdata_cmd { enum _ppnfs_net_type type; }


decompiled_code:
int ppnfs_client_net_start()
{
int result; // eax
_DWORD *v1; // rbx
void *v2; // r12
_DWORD *v3; // rbx
size_t v4; // rbx
char *v5; // r13
__int64 v6; // rbx
int v7; // ebx
int *v8; // rax
int *v9; // rax
int *v10; // rax
int *v11; // rax
int *v12; // r14
char *v13; // rax

result = ppnfs_client_net_init(&hsock, "127.0.0.1", 11010);
if ( result != -1 )
{
v1 = mheadcmd();
if ( (unsigned int)ppnfs_client_net_send(&hsock, v1) == -1 )
{
v8 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error sending data %d\n",
151LL,
"ppnfs_client_net_start",
(unsigned int)*v8);
result = fflush(stderr);
}
else
{
free(v1);
v2 = malloc(0x58uLL);
bytecount = recv(hsock, v2, 0x58uLL, 0);
if ( bytecount == -1 )
{
v9 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving metadata head %d\n",
161LL,
"ppnfs_client_net_start",
(unsigned int)*v9);
result = fflush(stderr);
}
else
{
LODWORD(NR_BITPERBLK) = *((_DWORD *)v2 + 16);
v3 = mdatacmd();
if ( (unsigned int)ppnfs_client_net_send(&hsock, v3) == -1 )
{
v10 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error sending data %d\n",
178LL,
"ppnfs_client_net_start",
(unsigned int)*v10);
result = fflush(stderr);
}
else
{
free(v3);
ppnfs_metadata_struct_size = (((unsigned int)NR_BITPERBLK >> 3) + 496) & 0x3FFFFFF8;
v4 = *((_QWORD *)v2 + 9) * ppnfs_metadata_struct_size;
v5 = (char *)malloc(v4);
if ( v4 )
{
v6 = 0LL;
while ( recv(hsock, &v5[v6], 1uLL, 0) != -1 )
{
if ( ++v6 >= (unsigned __int64)(ppnfs_metadata_struct_size * *((_QWORD *)v2 + 9)) )
goto LABEL_9;
}
v11 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving metadata %d\n",
211LL,
"ppnfs_client_net_start",
(unsigned int)*v11);
result = fflush(stderr);
}
else
{
LABEL_9:
v7 = open64(ppnfs_metafile, 578, 438LL);
if ( v7 == -1 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Could not open '%s' : err=%d:%s\n",
237LL,
"ppnfs_client_net_start",
ppnfs_metafile,
(unsigned int)*v12,
v13);
fflush(stderr);
}
pwrite64(v7, v5, ppnfs_metadata_struct_size * *((_QWORD *)v2 + 9), 0LL);
free(v2);
free(v5);
result = close(v7);
}
}
}
}
}
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax
_DWORD *v1; // rbx
void *v2; // r12
_DWORD *v3; // rbx
size_t v4; // rbx
char *v5; // r13
__int64 v6; // rbx
int v7; // ebx
int *v8; // rax
int *v9; // rax
int *v10; // rax
int *v11; // rax
int *v12; // r14
char *v13; // rax

result = func1(&hsock, "127.0.0.1", 11010);
if ( result != -1 )
{
v1 = func4();
if ( (unsigned int)func2(&hsock, v1) == -1 )
{
v8 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error sending data %d\n",
151LL,
"ppnfs_client_net_start",
(unsigned int)*v8);
result = fflush(stderr);
}
else
{
free(v1);
v2 = malloc(0x58uLL);
bytecount = recv(hsock, v2, 0x58uLL, 0);
if ( bytecount == -1 )
{
v9 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving metadata head %d\n",
161LL,
"ppnfs_client_net_start",
(unsigned int)*v9);
result = fflush(stderr);
}
else
{
LODWORD(NR_BITPERBLK) = *((_DWORD *)v2 + 16);
v3 = func5();
if ( (unsigned int)func2(&hsock, v3) == -1 )
{
v10 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error sending data %d\n",
178LL,
"ppnfs_client_net_start",
(unsigned int)*v10);
result = fflush(stderr);
}
else
{
free(v3);
ppnfs_metadata_struct_size = (((unsigned int)NR_BITPERBLK >> 3) + 496) & 0x3FFFFFF8;
v4 = *((_QWORD *)v2 + 9) * ppnfs_metadata_struct_size;
v5 = (char *)malloc(v4);
if ( v4 )
{
v6 = 0LL;
while ( recv(hsock, &v5[v6], 1uLL, 0) != -1 )
{
if ( ++v6 >= (unsigned __int64)(ppnfs_metadata_struct_size * *((_QWORD *)v2 + 9)) )
goto LABEL_9;
}
v11 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving metadata %d\n",
211LL,
"ppnfs_client_net_start",
(unsigned int)*v11);
result = fflush(stderr);
}
else
{
LABEL_9:
v7 = open64(ppnfs_metafile, 578, 438LL);
if ( v7 == -1 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Could not open '%s' : err=%d:%s\n",
237LL,
"ppnfs_client_net_start",
ppnfs_metafile,
(unsigned int)*v12,
v13);
fflush(stderr);
}
pwrite64(v7, v5, ppnfs_metadata_struct_size * *((_QWORD *)v2 + 9), 0LL);
free(v2);
free(v5);
result = close(v7);
}
}
}
}
}
return result;
}

original_code:
void ppnfs_client_net_start()
{
    int host_port = 11010;
    char* host_name = "127.0.0.1";
    if (ppnfs_client_net_init(&hsock, host_name, host_port) == -1) {
        goto FINISH;
    }
    struct ppnfs_net_cmd* cmd = mheadcmd();
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending data %d\n", 151, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    free (cmd);
    struct ppnfs_metadata_head_t* head =
 malloc ( sizeof(struct ppnfs_metadata_head_t) );
    if((bytecount = recv(hsock, head,
                         sizeof(struct ppnfs_metadata_head_t), 0))== -1){
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving metadata head %d\n", 161, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    NR_BITPERBLK = head->bit_per_blk;
    cmd = mdatacmd();
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending data %d\n", 178, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    free (cmd);
    ppnfs_metadata_struct_size =
 sizeof(struct ppnfs_metadata_t) + sizeof(char) * ((NR_BITPERBLK>>3) + 1);
    ppnfs_metadata_struct_size = (ppnfs_metadata_struct_size + 7) & (~0x07);
    struct ppnfs_metadata_t* ppnfs_metadata =
 malloc ( ppnfs_metadata_struct_size * head->alloced_nb );
    int i;
    for (i = 0; i < ppnfs_metadata_struct_size * head->alloced_nb; ++i) {
        if (recv(hsock, (char*)ppnfs_metadata + i, 1, 0) == -1) {
            do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving metadata %d\n", 211, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
            goto FINISH;
        }
    }
    int ppnfs_metadata_fd;
    ppnfs_metadata_fd =
 open(ppnfs_metafile, 0100 | 01000 | 02,
   (0400 | 0200 | (0400 >> 3) | (0200 >> 3) |((0400 >> 3) >> 3) | ((0200 >> 3) >> 3)));
    if ( ppnfs_metadata_fd == -1 ) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Could not open '%s' : err=%d:%s\n", 237, __FUNCTION__, ppnfs_metafile, (*__errno_location ()), strerror((*__errno_location ())) ); fflush(stderr); } while(0);
    }
    pwrite(ppnfs_metadata_fd, ppnfs_metadata,
     ppnfs_metadata_struct_size * head->alloced_nb, 0);
    free (head);
    free (ppnfs_metadata);
    close(ppnfs_metadata_fd);
FINISH:
    ;
}

canonical_original_code:
void ppnfs_client_net_start()
{
    int host_port = 11010;
    char *host_name = "127.0.0.1";
    if (ppnfs_client_net_init(&hsock, host_name, host_port) == -1) {
        goto FINISH;
    }
    struct ppnfs_net_cmd *cmd = mheadcmd();
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending data %d\n", 151, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    free (cmd);
    struct ppnfs_metadata_head_t *head = malloc ( sizeof(struct ppnfs_metadata_head_t) );
    if((bytecount = recv(hsock, head,
                         sizeof(struct ppnfs_metadata_head_t), 0))== -1){
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving metadata head %d\n", 161, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    NR_BITPERBLK = head->bit_per_blk;
    cmd = mdatacmd();
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending data %d\n", 178, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    free (cmd);
    ppnfs_metadata_struct_size =
 sizeof(struct ppnfs_metadata_t) + sizeof(char) * ((NR_BITPERBLK>>3) + 1);
    ppnfs_metadata_struct_size = (ppnfs_metadata_struct_size + 7) & (~0x07);
    struct ppnfs_metadata_t *ppnfs_metadata = malloc ( ppnfs_metadata_struct_size * head->alloced_nb );
    int i;
    for (i = 0; i < ppnfs_metadata_struct_size * head->alloced_nb; ++i) {
        if (recv(hsock, (char *)ppnfs_metadata + i, 1, 0) == -1) {
            do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving metadata %d\n", 211, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
            goto FINISH;
        }
    }
    int ppnfs_metadata_fd;
    ppnfs_metadata_fd =
 open(ppnfs_metafile, 0100 | 01000 | 02,
   (0400 | 0200 | (0400 >> 3) | (0200 >> 3) |((0400 >> 3) >> 3) | ((0200 >> 3) >> 3)));
    if ( ppnfs_metadata_fd == -1 ) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Could not open '%s' : err=%d:%s\n", 237, __FUNCTION__, ppnfs_metafile, (*__errno_location ()), strerror((*__errno_location ())) ); fflush(stderr); } while(0);
    }
    pwrite(ppnfs_metadata_fd, ppnfs_metadata,
     ppnfs_metadata_struct_size * head->alloced_nb, 0);
    free (head);
    free (ppnfs_metadata);
    close(ppnfs_metadata_fd);
FINISH:
    ;
}

variable_types: struct ppnfs_net_cmd { enum _ppnfs_net_type { PPNFS_REQUEST_MHEAD=1, PPNFS_REQUEST_MDATA=2, PPNFS_REQUEST_BLOCK=3 } type; } *

variable_types: struct ppnfs_metadata_head_t { char magic[64]; unsigned int bit_per_blk; unsigned long long alloced_nb; unsigned long long first_free; } *

variable_types: struct ppnfs_metadata_t { unsigned long long hash; char d_name[-1]; unsigned long long id; unsigned long long father; unsigned long long child; unsigned long long next; unsigned long long up; unsigned long long left; unsigned long long right; unsigned long long collision_next; unsigned long long collision_previous; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } st; unsigned int prime; unsigned int c; char pi[]; } *

variable_types: i int

user_defined_types: struct ppnfs_metadata_t { unsigned long long hash; char d_name[-1]; unsigned long long id; unsigned long long father; unsigned long long child; unsigned long long next; unsigned long long up; unsigned long long left; unsigned long long right; unsigned long long collision_next; unsigned long long collision_previous; struct stat st; unsigned int prime; unsigned int c; char pi[]; }


decompiled_code:
__int64 __fastcall ppnfs_client_send_gm(__int64 a1, __int64 a2)
{
int *v2; // r12
unsigned int v3; // ebx
int *v5; // rax

v2 = blockcmd(a1, a2);
v3 = ppnfs_client_net_send(&hsock, v2);
if ( v3 == -1 )
{
v5 = _errno_location();
fprintf(stderr, "ERR|ppnfs_net.c:%d:%s|Error sending gm %d\n", 260LL, "ppnfs_client_send_gm", (unsigned int)*v5);
fflush(stderr);
}
else
{
free(v2);
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
int *v2; // r12
unsigned int v3; // ebx
int *v5; // rax

v2 = blockcmd(a1, a2);
v3 = func2(&hsock, v2);
if ( v3 == -1 )
{
v5 = _errno_location();
fprintf(stderr, "ERR|ppnfs_net.c:%d:%s|Error sending gm %d\n", 260LL, "ppnfs_client_send_gm", (unsigned int)*v5);
fflush(stderr);
}
else
{
free(v2);
v3 = 0;
}
return v3;
}

original_code:
int
ppnfs_client_send_gm(mpz_t* g, mpz_t* M)
{
    int i;
    struct ppnfs_net_cmd* cmd = blockcmd(g, M);
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending gm %d\n", 260, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        return -1;
    }
    free (cmd);
    return 0;
}

canonical_original_code:
int ppnfs_client_send_gm(struct __mpz_struct (*g)[1], struct __mpz_struct (*M)[1])
{
    int i;
    struct ppnfs_net_cmd *cmd = blockcmd(g, M);
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending gm %d\n", 260, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        return -1;
    }
    free (cmd);
    return 0;
}

variable_types:
M
struct __mpz_struct (*)[1]

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }

user_defined_types: enum _ppnfs_net_type { PPNFS_REQUEST_MHEAD=1, PPNFS_REQUEST_MDATA=2, PPNFS_REQUEST_BLOCK=3 }


decompiled_code:
__int64 __fastcall ppnfs_client_send_blknr(int a1)
{
int *v2; // rax
int buf; // [rsp+Ch] [rbp-4h] BYREF

buf = a1;
bytecount = send(hsock, &buf, 4uLL, 0);
if ( bytecount != -1 )
return 0LL;
v2 = _errno_location();
fprintf(stderr, "ERR|ppnfs_net.c:%d:%s|Error sending data %d\n", 272LL, "ppnfs_client_send_blknr", (unsigned int)*v2);
fflush(stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int *v2; // rax
int buf; // [rsp+Ch] [rbp-4h] BYREF

buf = a1;
bytecount = send(hsock, &buf, 4uLL, 0);
if ( bytecount != -1 )
return 0LL;
v2 = _errno_location();
fprintf(stderr, "ERR|ppnfs_net.c:%d:%s|Error sending data %d\n", 272LL, "ppnfs_client_send_blknr", (unsigned int)*v2);
fflush(stderr);
return 0xFFFFFFFFLL;
}

original_code:
int
ppnfs_client_send_blknr(int nr)
{
    if( (bytecount=send(hsock, &nr, sizeof(int), 0))== -1){
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending data %d\n", 272, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        return -1;
    }
    return 0;
}

variable_types: nr int


decompiled_code:
void *ppnfs_client_retrieve_block()
{
size_t v0; // r13
void *v1; // r12
void *v2; // rbx
int *v4; // rax

v0 = (unsigned int)NR_BITPERBLK;
v1 = malloc((unsigned int)NR_BITPERBLK);
v2 = malloc(0x10uLL);
bytecount = recv(hsock, v1, v0, 0);
if ( bytecount == -1 )
{
v4 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving ge %d\n",
285LL,
"ppnfs_client_retrieve_block",
(unsigned int)*v4);
fflush(stderr);
}
_gmpz_init(v2);
_gmp_sscanf(v1, "%Zx\n", v2);
return v2;
}

canonical_decompiled_code:
void *func9()
{
size_t v0; // r13
void *v1; // r12
void *v2; // rbx
int *v4; // rax

v0 = (unsigned int)NR_BITPERBLK;
v1 = malloc((unsigned int)NR_BITPERBLK);
v2 = malloc(0x10uLL);
bytecount = recv(hsock, v1, v0, 0);
if ( bytecount == -1 )
{
v4 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving ge %d\n",
285LL,
"ppnfs_client_retrieve_block",
(unsigned int)*v4);
fflush(stderr);
}
_gmpz_init(v2);
_gmp_sscanf(v1, "%Zx\n", v2);
return v2;
}

original_code:
mpz_t*
ppnfs_client_retrieve_block(unsigned int idx)
{
    char* gestr = malloc(sizeof(char) * NR_BITPERBLK);
    mpz_t* ge = (mpz_t*)malloc(sizeof(mpz_t));
    if((bytecount = recv(hsock, gestr, NR_BITPERBLK, 0))== -1){
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving ge %d\n", 285, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
    }
    __gmpz_init(*ge);
    __gmp_sscanf(gestr, "%Zx\n", ge);
    return ge;
}

canonical_original_code:
struct __mpz_struct (*ppnfs_client_retrieve_block(unsigned int idx))[1]
{
    char *gestr = malloc(sizeof(char) * NR_BITPERBLK);
    struct __mpz_struct (*ge)[1] = (mpz_t*)malloc(sizeof(mpz_t));
    if((bytecount = recv(hsock, gestr, NR_BITPERBLK, 0))== -1){
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving ge %d\n", 285, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
    }
    __gmpz_init(*ge);
    __gmp_sscanf(gestr, "%Zx\n", ge);
    return ge;
}

variable_types:
idx
unsigned int

return_type: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]


decompiled_code:
void ppnfs_client_config_init()
{
ppnfs_metafile = "/home/bai/workspace/thesis/ppnfs/client/PPNFS_METAFILE";
}

canonical_decompiled_code:
void func0()
{
ppnfs_metafile = "/home/bai/workspace/thesis/ppnfs/client/PPNFS_METAFILE";
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
char *__fastcall ppnfs_metadata_get(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( a1 == -1 )
{
fprintf(stderr, "BUG|ppnfs_metadata.c:%d:%s|Attempt to fetch an EMPTY child !\n", 89LL, "ppnfs_metadata_get");
fflush(stderr);
*(_BYTE *)ppnfs_metadata_close = 0;
}
if ( ppnfs_metadata_struct_size * a1 >= ppnfs_metadata_size )
{
fprintf(stderr, "BUG|ppnfs_metadata.c:%d:%s|Out of bounds : id=%llu\n", 92LL, "ppnfs_metadata_get", a1);
fflush(stderr);
*(_BYTE *)ppnfs_metadata_close = 0;
}
return (char *)ppnfs_metadata + ppnfs_metadata_struct_size * a1;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( a1 == -1 )
{
fprintf(stderr, "BUG|ppnfs_metadata.c:%d:%s|Attempt to fetch an EMPTY child !\n", 89LL, "ppnfs_metadata_get");
fflush(stderr);
*(_BYTE *)ppnfs_metadata_close = 0;
}
if ( ppnfs_metadata_struct_size * a1 >= ppnfs_metadata_size )
{
fprintf(stderr, "BUG|ppnfs_metadata.c:%d:%s|Out of bounds : id=%llu\n", 92LL, "ppnfs_metadata_get", a1);
fflush(stderr);
*(_BYTE *)ppnfs_metadata_close = 0;
}
return (char *)ppnfs_metadata + ppnfs_metadata_struct_size * a1;
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_get(ppnfs_metadata_id id)
{
    if (!id)
        return ((void *)0);
    if (id == ppnfs_metadata_id_EMPTY) {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Attempt to fetch an EMPTY child !\n", 89, __FUNCTION__ ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
    if (id * ppnfs_metadata_struct_size >= ppnfs_metadata_size) {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Out of bounds : id=%llu\n", 92, __FUNCTION__, id ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
    return (struct ppnfs_metadata_t*)((char*)ppnfs_metadata + id * ppnfs_metadata_struct_size);
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_get(unsigned long long id)
{
    if (!id)
        return ((void *)0);
    if (id == ppnfs_metadata_id_EMPTY) {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Attempt to fetch an EMPTY child !\n", 89, __FUNCTION__ ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
    if (id * ppnfs_metadata_struct_size >= ppnfs_metadata_size) {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Out of bounds : id=%llu\n", 92, __FUNCTION__, id ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
    return (struct ppnfs_metadata_t *)((char *)ppnfs_metadata + id * ppnfs_metadata_struct_size);
}

variable_types:
id
unsigned long long

return_type: struct ppnfs_metadata_t { unsigned long long hash; char d_name[-1]; unsigned long long id; unsigned long long father; unsigned long long child; unsigned long long next; unsigned long long up; unsigned long long left; unsigned long long right; unsigned long long collision_next; unsigned long long collision_previous; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } st; unsigned int prime; unsigned int c; char pi[]; } *


decompiled_code:
bool __fastcall ppnfs_metadata_equals(char *a1, __int64 a2, int a3)
{
__int64 v5; // rdi
__int64 v6; // rax
int v7; // er14

if ( a3 <= 1 )
return *((_QWORD *)a1 + 34) == 0LL;
while ( 1 )
{
v6 = a3 - 1;
do
{
v7 = v6;
if ( *(_BYTE *)(a2 + v6) == 47 )
break;
v7 = --v6;
}
while ( (_DWORD)v6 );
if ( strncmp(a1 + 8, (const char *)(a2 + v7 + 1), a3 - v7 - 1) )
return 0;
v5 = *((_QWORD *)a1 + 34);
if ( !v5 )
break;
a1 = ppnfs_metadata_get(v5);
if ( v7 <= 1 )
return *((_QWORD *)a1 + 34) == 0LL;
a3 = v7;
}
return 0;
}

original_code:
static _Bool
ppnfs_metadata_equals(struct ppnfs_metadata_t* mdata, const char* path, int path_size)
{
    int path_start;
    while (1) {
        ;
        if (path_size <= 1)
            return mdata->father == 0;
        path_start = path_size ? path_size - 1 : 0;
        while (path_start && path[path_start] != '/')
            path_start--;
        ;
        if (strncmp(mdata->d_name, &(path[path_start + 1]),
                    path_size - path_start - 1)) {
            ;
            return 0;
        }
        if (!mdata->father)
            return 0;
        mdata = ppnfs_metadata_get(mdata->father);
        path_size = path_start;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Shall not be here.\n", 136, __FUNCTION__ ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    return -1;
}

canonical_original_code:
static _Bool ppnfs_metadata_equals(struct ppnfs_metadata_t *mdata, char *path, int path_size)
{
    int path_start;
    while (1) {
        ;
        if (path_size <= 1)
            return mdata->father == 0;
        path_start = path_size ? path_size - 1 : 0;
        while (path_start && path[path_start] != '/')
            path_start--;
        ;
        if (strncmp(mdata->d_name, &(path[path_start + 1]),
                    path_size - path_start - 1)) {
            ;
            return 0;
        }
        if (!mdata->father)
            return 0;
        mdata = ppnfs_metadata_get(mdata->father);
        path_size = path_start;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Shall not be here.\n", 136, __FUNCTION__ ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    return -1;
}

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


decompiled_code:
char *ppnfs_metadata_get_root()
{
return ppnfs_metadata_get(1LL);
}

canonical_decompiled_code:
char *func2()
{
return func0(1LL);
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_get_root()
{
    return ppnfs_metadata_get(ppnfs_metadata_id_root);
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_get_root()
{
    return ppnfs_metadata_get(ppnfs_metadata_id_root);
}


decompiled_code:
char *ppnfs_client_metadata_init()
{
int *v1; // rbx
char *v2; // rax
struct stat64 v3; // [rsp+0h] [rbp-A0h] BYREF

if ( !stat64(ppnfs_metafile, &v3) && v3.st_size )
{
ppnfs_metadata_fd = open64(ppnfs_metafile, 2);
if ( ppnfs_metadata_fd == -1 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(
stderr,
"ERR|ppnfs_metadata.c:%d:%s|Could not open '%s' : err=%d:%s\n",
34LL,
"ppnfs_client_metadata_init",
ppnfs_metafile,
(unsigned int)*v1,
v2);
fflush(stderr);
}
ppnfs_metadata_size = v3.st_size;
}
else
{
fprintf(
stderr,
"ERR|ppnfs_metadata.c:%d:%s|Could not open metafile '%s'\n",
40LL,
"ppnfs_client_metadata_init",
ppnfs_metafile);
fflush(stderr);
}
ppnfs_metadata = mmap64(0LL, ppnfs_metadata_size, 3, 1, ppnfs_metadata_fd, 0LL);
if ( (char *)ppnfs_metadata - 1 > (char *)0xFFFFFFFFFFFFFFFDLL )
{
fprintf(stderr, "ERR|ppnfs_metadata.c:%d:%s|Could not open metadata !\n", 51LL, "ppnfs_client_metadata_init");
fflush(stderr);
exit(-1);
}
return ppnfs_metadata_get_root();
}

canonical_decompiled_code:
char *func3()
{
int *v1; // rbx
char *v2; // rax
struct stat64 v3; // [rsp+0h] [rbp-A0h] BYREF

if ( !stat64(ppnfs_metafile, &v3) && v3.st_size )
{
ppnfs_metadata_fd = open64(ppnfs_metafile, 2);
if ( ppnfs_metadata_fd == -1 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(
stderr,
"ERR|ppnfs_metadata.c:%d:%s|Could not open '%s' : err=%d:%s\n",
34LL,
"ppnfs_client_metadata_init",
ppnfs_metafile,
(unsigned int)*v1,
v2);
fflush(stderr);
}
ppnfs_metadata_size = v3.st_size;
}
else
{
fprintf(
stderr,
"ERR|ppnfs_metadata.c:%d:%s|Could not open metafile '%s'\n",
40LL,
"ppnfs_client_metadata_init",
ppnfs_metafile);
fflush(stderr);
}
ppnfs_metadata = mmap64(0LL, ppnfs_metadata_size, 3, 1, ppnfs_metadata_fd, 0LL);
if ( (char *)ppnfs_metadata - 1 > (char *)0xFFFFFFFFFFFFFFFDLL )
{
fprintf(stderr, "ERR|ppnfs_metadata.c:%d:%s|Could not open metadata !\n", 51LL, "ppnfs_client_metadata_init");
fflush(stderr);
exit(-1);
}
return func2();
}

original_code:
void
ppnfs_client_metadata_init()
{
    struct stat st;
    if (stat(ppnfs_metafile, &st) == 0 && st.st_size) {
        ppnfs_metadata_fd = open(ppnfs_metafile, 02);
        if ( ppnfs_metadata_fd == -1 ) {
            do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open '%s' : err=%d:%s\n", 34, __FUNCTION__, ppnfs_metafile, (*__errno_location ()), strerror((*__errno_location ())) ); fflush(stderr); } while(0);
        }
        ppnfs_metadata_size = st.st_size;
        ;
    }
    else {
        do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open metafile '%s'\n", 40, __FUNCTION__, ppnfs_metafile ); fflush(stderr); } while(0);
    }
    ;
    ppnfs_metadata = (struct ppnfs_metadata_t*)mmap(((void *)0),
                                                    ppnfs_metadata_size,
                                                    0x1 | 0x2, 0x01,
                                                    ppnfs_metadata_fd, 0);
    if (ppnfs_metadata == ((void *)0) || ppnfs_metadata == ((void *) -1)) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open metadata !\n", 51, __FUNCTION__ ); fflush(stderr); } while(0);
        exit(-1);
    }
    struct ppnfs_metadata_t* current = ppnfs_metadata_get_root();
    ;
    ;
}

canonical_original_code:
void ppnfs_client_metadata_init()
{
    struct stat st;
    if (stat(ppnfs_metafile, &st) == 0 && st.st_size) {
        ppnfs_metadata_fd = open(ppnfs_metafile, 02);
        if ( ppnfs_metadata_fd == -1 ) {
            do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open '%s' : err=%d:%s\n", 34, __FUNCTION__, ppnfs_metafile, (*__errno_location ()), strerror((*__errno_location ())) ); fflush(stderr); } while(0);
        }
        ppnfs_metadata_size = st.st_size;
        ;
    }
    else {
        do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open metafile '%s'\n", 40, __FUNCTION__, ppnfs_metafile ); fflush(stderr); } while(0);
    }
    ;
    ppnfs_metadata = (struct ppnfs_metadata_t *)mmap(((void *)0),
                                                    ppnfs_metadata_size,
                                                    0x1 | 0x2, 0x01,
                                                    ppnfs_metadata_fd, 0);
    if (ppnfs_metadata == ((void *)0) || ppnfs_metadata == ((void *) -1)) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open metadata !\n", 51, __FUNCTION__ ); fflush(stderr); } while(0);
        exit(-1);
    }
    struct ppnfs_metadata_t *current = ppnfs_metadata_get_root();
    ;
    ;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
char *__fastcall ppnfs_metadata_find_hash(__int64 a1, unsigned __int64 a2, int a3)
{
char *v4; // rbx

v4 = ppnfs_metadata_get_root();
while ( v4 )
{
if ( *(_QWORD *)v4 > a2 )
{
v4 = ppnfs_metadata_get(*((_QWORD *)v4 + 38));
}
else if ( *(_QWORD *)v4 < a2 )
{
v4 = ppnfs_metadata_get(*((_QWORD *)v4 + 39));
}
else
{
if ( ppnfs_metadata_equals(v4, a1, a3) )
return v4;
v4 = ppnfs_metadata_get(*((_QWORD *)v4 + 40));
}
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1, unsigned __int64 a2, int a3)
{
char *v4; // rbx

v4 = func2();
while ( v4 )
{
if ( *(_QWORD *)v4 > a2 )
{
v4 = func0(*((_QWORD *)v4 + 38));
}
else if ( *(_QWORD *)v4 < a2 )
{
v4 = func0(*((_QWORD *)v4 + 39));
}
else
{
if ( func1(v4, a1, a3) )
return v4;
v4 = func0(*((_QWORD *)v4 + 40));
}
}
return v4;
}

original_code:
static struct ppnfs_metadata_t*
ppnfs_metadata_find_hash(const char* path, hash_t hash, int path_size)
{
    struct ppnfs_metadata_t* current = ppnfs_metadata_get_root();
    ;
    while (current) {
        ;
        if (hash < current->hash) {
            current = ppnfs_metadata_get(current->left);
            continue;
        }
        if (current->hash < hash) {
            current = ppnfs_metadata_get(current->right);
            continue;
        }
        if (ppnfs_metadata_equals(current, path, path_size)) {
            return current;
        }
        ;
        current = ppnfs_metadata_get(current->collision_next);
    }
    return ((void *)0);
}

canonical_original_code:
static struct ppnfs_metadata_t *ppnfs_metadata_find_hash(char *path, unsigned long long hash, int path_size)
{
    struct ppnfs_metadata_t *current = ppnfs_metadata_get_root();
    ;
    while (current) {
        ;
        if (hash < current->hash) {
            current = ppnfs_metadata_get(current->left);
            continue;
        }
        if (current->hash < hash) {
            current = ppnfs_metadata_get(current->right);
            continue;
        }
        if (ppnfs_metadata_equals(current, path, path_size)) {
            return current;
        }
        ;
        current = ppnfs_metadata_get(current->collision_next);
    }
    return ((void *)0);
}

variable_types:
hash
unsigned long long


decompiled_code:
char *__fastcall ppnfs_metadata_get_child(__int64 a1)
{
__int64 v1; // rdi

v1 = *(_QWORD *)(a1 + 280);
if ( v1 == -1 )
return 0LL;
if ( v1 )
return ppnfs_metadata_get(v1);
return ppnfs_metadata_get(0LL);
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1)
{
__int64 v1; // rdi

v1 = *(_QWORD *)(a1 + 280);
if ( v1 == -1 )
return 0LL;
if ( v1 )
return func0(v1);
return func0(0LL);
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_get_child(struct ppnfs_metadata_t* father)
{
    ppnfs_metadata_id fatherid = father->id;
    struct ppnfs_metadata_t* newmeta = ((void *)0);
    if (father->child == ppnfs_metadata_id_EMPTY) {
        ;
        return ((void *)0);
    } else if (father->child) {
        ;
        return ppnfs_metadata_get(father->child);
    }
    return ppnfs_metadata_get(father->child);
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_get_child(struct ppnfs_metadata_t *father)
{
    unsigned long long fatherid = father->id;
    struct ppnfs_metadata_t *newmeta = ((void *)0);
    if (father->child == ppnfs_metadata_id_EMPTY) {
        ;
        return ((void *)0);
    } else if (father->child) {
        ;
        return ppnfs_metadata_get(father->child);
    }
    return ppnfs_metadata_get(father->child);
}

variable_types:
father
struct ppnfs_metadata_t *

variable_types:
fatherid
unsigned long long


decompiled_code:
char *__fastcall ppnfs_metadata_walk_down(__int64 a1, __int64 a2, int a3)
{
const char *v3; // r12
__int64 v4; // rdx
const char *v5; // r15
char v6; // cl
size_t v7; // r14
__int64 v8; // r13
char *v9; // rbx
char *v10; // rax
__int64 v11; // rdi
__int64 v12; // r13
int v14; // [rsp+8h] [rbp-38h]
unsigned int v15; // [rsp+Ch] [rbp-34h]

while ( 1 )
{
v14 = a3 + 1;
v3 = (const char *)(a2 + a3 + 1);
if ( !*v3 || *v3 == 47 )
{
v5 = (const char *)(a2 + a3 + 1);
v15 = 0;
v7 = 0LL;
}
else
{
v4 = 1LL;
do
{
v15 = v4;
v5 = &v3[v4];
v6 = v3[v4];
v7 = v4++;
}
while ( v6 && v6 != 47 );
}
v8 = *(_QWORD *)(a1 + 264);
v9 = ppnfs_metadata_get_child(a1);
if ( !v9 )
break;
v10 = ppnfs_metadata_get(v8);
v11 = *((_QWORD *)v10 + 34) ? continueHash(*(_QWORD *)v10, "/") : *(_QWORD *)v10;
v12 = continueHashPartial(v11, v3, v15);
while ( *(_QWORD *)v9 != v12 || strncmp(v9 + 8, v3, v7) )
{
v9 = ppnfs_metadata_get(*((_QWORD *)v9 + 36));
if ( !v9 )
return v9;
}
if ( !*v5 )
break;
a3 = v14 + v15 + 1;
a1 = (__int64)v9;
}
return v9;
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_walk_down(struct ppnfs_metadata_t* father,
                         const char* path, int path_size)
{
    const char* rpath = ((void *)0);
    hash_t father_hash, hash;
    int rpath_size;
    ppnfs_metadata_id father_id;
walk_down_start:
    path_size++;
    rpath = &(path[path_size]);
    rpath_size = 0;
    while (rpath[rpath_size] != '\0' && rpath[rpath_size] != '/')
        rpath_size++;
    father_hash = father->hash;
    father_id = father->id;
    hash = 0;
    ;
    struct ppnfs_metadata_t* child = ppnfs_metadata_get_child(father);
    father = ((void *)0);
    if (!child)
        return ((void *)0);
    ;
    father = ppnfs_metadata_get(father_id);
    father_hash = father->father ? continueHash(father->hash, "/") : father->hash;
    hash = continueHashPartial(father_hash, rpath, rpath_size);
    for (; child; child = ppnfs_metadata_get(child->next)) {
        ;
        if (child->hash == hash && strncmp(child->d_name, rpath, rpath_size) == 0) {
            ;
            if (rpath[rpath_size]) {
                ;
                father = child;
                path_size += rpath_size + 1;
                goto walk_down_start;
            }
            return child;
        }
    }
    return ((void *)0);
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_walk_down(struct ppnfs_metadata_t *father, char *path, int path_size)
{
    char *rpath = ((void *)0);
    unsigned long long father_hash; unsigned long long hash;
    int rpath_size;
    unsigned long long father_id;
walk_down_start:
    path_size++;
    rpath = &(path[path_size]);
    rpath_size = 0;
    while (rpath[rpath_size] != '\0' && rpath[rpath_size] != '/')
        rpath_size++;
    father_hash = father->hash;
    father_id = father->id;
    hash = 0;
    ;
    struct ppnfs_metadata_t *child = ppnfs_metadata_get_child(father);
    father = ((void *)0);
    if (!child)
        return ((void *)0);
    ;
    father = ppnfs_metadata_get(father_id);
    father_hash = father->father ? continueHash(father->hash, "/") : father->hash;
    hash = continueHashPartial(father_hash, rpath, rpath_size);
    for (; child; child = ppnfs_metadata_get(child->next)) {
        ;
        if (child->hash == hash && strncmp(child->d_name, rpath, rpath_size) == 0) {
            ;
            if (rpath[rpath_size]) {
                ;
                father = child;
                path_size += rpath_size + 1;
                goto walk_down_start;
            }
            return child;
        }
    }
    return ((void *)0);
}

variable_types:
rpath
char *


decompiled_code:
char *__fastcall ppnfs_metadata_find_locked(const char *a1)
{
int v1; // er12
unsigned __int64 v2; // rax
char *result; // rax
int v4; // ebx
const char *i; // r12
unsigned __int64 v6; // rax
char *v7; // rax
int v8; // er13

v1 = strlen(a1);
v2 = doHash(a1);
result = ppnfs_metadata_find_hash((__int64)a1, v2, v1);
if ( !result )
{
v4 = v1;
for ( i = &a1[v1]; ; --i )
{
v8 = v4;
if ( !v4 )
break;
if ( *i == 47 )
{
if ( v4 <= 1 )
goto LABEL_10;
v6 = doHashPartial(a1, (unsigned int)v4);
v7 = ppnfs_metadata_find_hash((__int64)a1, v6, v4);
if ( v7 )
goto LABEL_11;
}
--v4;
}
v8 = 0;
LABEL_10:
v7 = ppnfs_metadata_get_root();
LABEL_11:
result = ppnfs_metadata_walk_down((__int64)v7, (__int64)a1, v8);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1)
{
int v1; // er12
unsigned __int64 v2; // rax
char *result; // rax
int v4; // ebx
const char *i; // r12
unsigned __int64 v6; // rax
char *v7; // rax
int v8; // er13

v1 = strlen(a1);
v2 = doHash(a1);
result = func4((__int64)a1, v2, v1);
if ( !result )
{
v4 = v1;
for ( i = &a1[v1]; ; --i )
{
v8 = v4;
if ( !v4 )
break;
if ( *i == 47 )
{
if ( v4 <= 1 )
goto LABEL_10;
v6 = doHashPartial(a1, (unsigned int)v4);
v7 = func4((__int64)a1, v6, v4);
if ( v7 )
goto LABEL_11;
}
--v4;
}
v8 = 0;
LABEL_10:
v7 = func2();
LABEL_11:
result = func6((__int64)v7, (__int64)a1, v8);
}
return result;
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_find_locked(const char* path)
{
    struct ppnfs_metadata_t* metadata;
    int path_size = strlen(path);
    hash_t hash = doHash(path);
    ;
    metadata = ppnfs_metadata_find_hash(path, hash, path_size);
    if (metadata) {
        ;
        return metadata;
    }
    ;
    while (1) {
        while (path_size && path[path_size] != '/') {
            path_size--;
        }
        if (path_size <= 1) {
            metadata = ppnfs_metadata_get_root();
            break;
        }
        hash = doHashPartial(path, path_size);
        metadata = ppnfs_metadata_find_hash(path, hash, path_size);
        if (metadata)
            break;
        path_size--;
    }
    ;
    return ppnfs_metadata_walk_down(metadata, path, path_size);
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_find_locked(char *path)
{
    struct ppnfs_metadata_t *metadata;
    int path_size = strlen(path);
    unsigned long long hash = doHash(path);
    ;
    metadata = ppnfs_metadata_find_hash(path, hash, path_size);
    if (metadata) {
        ;
        return metadata;
    }
    ;
    while (1) {
        while (path_size && path[path_size] != '/') {
            path_size--;
        }
        if (path_size <= 1) {
            metadata = ppnfs_metadata_get_root();
            break;
        }
        hash = doHashPartial(path, path_size);
        metadata = ppnfs_metadata_find_hash(path, hash, path_size);
        if (metadata)
            break;
        path_size--;
    }
    ;
    return ppnfs_metadata_walk_down(metadata, path, path_size);
}

variable_types:
path
char *


decompiled_code:
char *__fastcall ppnfs_metadata_find(const char *a1)
{
char *v1; // rbx

ppnfs_mutex_lock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_find");
v1 = ppnfs_metadata_find_locked(a1);
if ( !v1 )
ppnfs_mutex_unlock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_find");
return v1;
}

canonical_decompiled_code:
char *__fastcall func8(const char *a1)
{
char *v1; // rbx

ppnfs_mutex_lock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_find");
v1 = func7(a1);
if ( !v1 )
ppnfs_mutex_unlock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_find");
return v1;
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_find(const char* path)
{
    struct ppnfs_metadata_t* metadata;
    ppnfs_mutex_lock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
    metadata = ppnfs_metadata_find_locked(path);
    if (!metadata)
        ppnfs_mutex_unlock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
    return metadata;
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_find(char *path)
{
    struct ppnfs_metadata_t *metadata;
    ppnfs_mutex_lock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
    metadata = ppnfs_metadata_find_locked(path);
    if (!metadata)
        ppnfs_mutex_unlock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
    return metadata;
}


decompiled_code:
__int64 ppnfs_metadata_release()
{
return ppnfs_mutex_unlock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_release");
}

canonical_decompiled_code:
__int64 func9()
{
return ppnfs_mutex_unlock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_release");
}

original_code:
void
ppnfs_metadata_release(struct ppnfs_metadata_t* mdata)
{
    (void) mdata;
    ppnfs_mutex_unlock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
}

canonical_original_code:
void ppnfs_metadata_release(struct ppnfs_metadata_t *mdata)
{
    (void) mdata;
    ppnfs_mutex_unlock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
}


original_code:
int
ppnfs_metadata_getattr(const char* path, struct stat* stbuf)
{
    struct ppnfs_metadata_t* mdata = ppnfs_metadata_find(path);
    if (!mdata) {
        ;
        return -2;
    }
    ;
    memcpy(stbuf, &(mdata->st), sizeof(struct stat));
    ppnfs_metadata_release(mdata);
    if (((((stbuf->st_mode)) & 0170000) == (0040000)) && stbuf->st_size == 0) {
        stbuf->st_size = 1 << 12;
    }
    return 0;
}

canonical_original_code:
int ppnfs_metadata_getattr(char *path, struct stat *stbuf)
{
    struct ppnfs_metadata_t *mdata = ppnfs_metadata_find(path);
    if (!mdata) {
        ;
        return -2;
    }
    ;
    memcpy(stbuf, &(mdata->st), sizeof(struct stat));
    ppnfs_metadata_release(mdata);
    if (((((stbuf->st_mode)) & 0170000) == (0040000)) && stbuf->st_size == 0) {
        stbuf->st_size = 1 << 12;
    }
    return 0;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *


original_code:
static hash_t
sdbm_hash( hash_t h, const char* str, int sz )
{
    int cur = 0;
    const char* c;
    unsigned char d;
    for ( c = str ; *c ; c++ ) {
        d = (unsigned char)(*c);
        h = d + (h<<6) + (h<<16) - h;
        cur++;
        if ( cur == sz ) break;
    }
    return h;
}

canonical_original_code:
static unsigned long long sdbm_hash(unsigned long long h, char *str, int sz)
{
    int cur = 0;
    char *c;
    unsigned char d;
    for ( c = str ; *c ; c++ ) {
        d = (unsigned char)(*c);
        h = d + (h<<6) + (h<<16) - h;
        cur++;
        if ( cur == sz ) break;
    }
    return h;
}

variable_types:
h
unsigned long long

variable_types:
str
char *

variable_types: sz int

variable_types: cur int

variable_types:
c
char *

variable_types:
d
unsigned char

return_type: unsigned long long


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

result = a1 - 48;
if ( (unsigned __int8)(a1 - 48) > 9u )
{
result = a1 - 87;
if ( (unsigned __int8)(a1 - 97) >= 6u )
result = a1;
}
return result;
}

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

result = a1 - 48;
if ( (unsigned __int8)(a1 - 48) > 9u )
{
result = a1 - 87;
if ( (unsigned __int8)(a1 - 97) >= 6u )
result = a1;
}
return result;
}

original_code:
static char
ppnfs_client_convert(char ch)
{
    if (ch >= '0' && ch <= '9') {
        ch -= '0';
    } else if (ch >= 'a' && ch <= 'f') {
        ch += 0x0a;
        ch -= 'a';
    }
    return ch;
}

variable_types: ch char

return_type: char


continueHashPartial

decompiled_code:
__int64 __fastcall continueHashPartial(__int64 a1, _BYTE *a2, int a3)
{
return sdbm_hash(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _BYTE *a2, int a3)
{
return func0(a1, a2, a3);
}

original_code:
hash_t continueHashPartial ( hash_t h, const char* str, int sz )
{
    return sdbm_hash( h, str, sz );
}

canonical_original_code:
unsigned long long continueHashPartial(unsigned long long h, char *str, int sz)
{
    return sdbm_hash( h, str, sz );
}


continueHash

decompiled_code:
__int64 __fastcall continueHash(__int64 a1, _BYTE *a2)
{
return continueHashPartial(a1, a2, -1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _BYTE *a2)
{
return func2(a1, a2, -1);
}

original_code:
hash_t continueHash ( hash_t h, const char* str )
{
    return continueHashPartial ( h, str, ~((int)0) );
}

canonical_original_code:
unsigned long long continueHash(unsigned long long h, char *str)
{
    return continueHashPartial ( h, str, ~((int)0) );
}


doHashPartial

decompiled_code:
__int64 __fastcall doHashPartial(_BYTE *a1, int a2)
{
return continueHashPartial(581LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, int a2)
{
return func2(581LL, a1, a2);
}

original_code:
hash_t doHashPartial ( const char* str, int sz )
{
    hash_t h = 0x245;
    return continueHashPartial ( h, str, sz );
}

canonical_original_code:
unsigned long long doHashPartial(char *str, int sz)
{
    unsigned long long h = 0x245;
    return continueHashPartial ( h, str, sz );
}


doHash

decompiled_code:
__int64 __fastcall doHash(_BYTE *a1)
{
return doHashPartial(a1, -1);
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
return func4(a1, -1);
}

original_code:
hash_t doHash ( const char* str )
{
    return doHashPartial ( str, ~((int)0) );
}

canonical_original_code:
unsigned long long doHash(char *str)
{
    return doHashPartial ( str, ~((int)0) );
}


groupStr

decompiled_code:
size_t __fastcall groupStr(_BYTE *a1, const char *a2)
{
char *v3; // r12
size_t result; // rax
unsigned __int64 v5; // rsi
char *v6; // rdx
__int64 v7; // rdi
__int64 v8; // rax
char v9; // di
char v10; // bl

v3 = (char *)a2;
result = strlen(a2);
if ( (result & 1) != 0 )
{
v5 = (unsigned __int64)&a2[result - 1];
v6 = &v3[result];
if ( (unsigned __int64)v3 <= v5 )
{
v7 = -(__int64)result;
v8 = 0LL;
do
{
v6[v8] = *(_BYTE *)(v5 + v8);
--v8;
}
while ( v7 != v8 );
}
*v3 = 48;
v9 = 48;
}
else
{
v9 = *a2;
if ( !*a2 )
return result;
}
do
{
v10 = ppnfs_client_convert(v9);
v3 += 2;
result = ppnfs_client_convert(*(v3 - 1));
*a1++ = result + 16 * v10;
v9 = *v3;
}
while ( *v3 );
return result;
}

canonical_decompiled_code:
size_t __fastcall func6(_BYTE *a1, const char *a2)
{
char *v3; // r12
size_t result; // rax
unsigned __int64 v5; // rsi
char *v6; // rdx
__int64 v7; // rdi
__int64 v8; // rax
char v9; // di
char v10; // bl

v3 = (char *)a2;
result = strlen(a2);
if ( (result & 1) != 0 )
{
v5 = (unsigned __int64)&a2[result - 1];
v6 = &v3[result];
if ( (unsigned __int64)v3 <= v5 )
{
v7 = -(__int64)result;
v8 = 0LL;
do
{
v6[v8] = *(_BYTE *)(v5 + v8);
--v8;
}
while ( v7 != v8 );
}
*v3 = 48;
v9 = 48;
}
else
{
v9 = *a2;
if ( !*a2 )
return result;
}
do
{
v10 = func1(v9);
v3 += 2;
result = func1(*(v3 - 1));
*a1++ = result + 16 * v10;
v9 = *v3;
}
while ( *v3 );
return result;
}

original_code:
void groupStr(char *dest, char *src)
{
    char high, low;
    char *p;
    char *q;
    size_t len = strlen(src);
    int i;
    if ((len % 2) != 0) {
        p = src + len -1;
        q = src + len;
        while (p >= src) {
            *q-- = *p--;
        }
        *src = '0';
    }
    p = dest;
    q = src;
    while (*q) {
        high = ppnfs_client_convert(*q++);
        low = ppnfs_client_convert(*q++);
        *p++ = (high << 4) + low;
    }
}

canonical_original_code:
void groupStr(char *dest, char *src)
{
    char high; char low;
    char *p;
    char *q;
    unsigned long len = strlen(src);
    int i;
    if ((len % 2) != 0) {
        p = src + len -1;
        q = src + len;
        while (p >= src) {
            *q-- = *p--;
        }
        *src = '0';
    }
    p = dest;
    q = src;
    while (*q) {
        high = ppnfs_client_convert(*q++);
        low = ppnfs_client_convert(*q++);
        *p++ = (high << 4) + low;
    }
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types: high char

variable_types: low char

variable_types:
p
char *

variable_types:
q
char *

variable_types:
len
unsigned long

variable_types: i int


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
bool __fastcall ppnfs_mutex_init(pthread_mutex_t *a1)
{
bool result; // al
char *v2; // rax
pthread_mutexattr_t attr; // [rsp+18h] [rbp-8h] BYREF
int errnum; // [rsp+1Ch] [rbp-4h]

pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, 2);
errnum = pthread_mutex_init(a1, &attr);
result = errnum != 0;
if ( errnum )
{
v2 = strerror(errnum);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not init mutex : err=%d:%s\n",
25LL,
"ppnfs_mutex_init",
(unsigned int)errnum,
v2);
fflush(stdout);
result = 0;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(pthread_mutex_t *a1)
{
bool result; // al
char *v2; // rax
pthread_mutexattr_t attr; // [rsp+18h] [rbp-8h] BYREF
int errnum; // [rsp+1Ch] [rbp-4h]

pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, 2);
errnum = pthread_mutex_init(a1, &attr);
result = errnum != 0;
if ( errnum )
{
v2 = strerror(errnum);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not init mutex : err=%d:%s\n",
25LL,
"ppnfs_mutex_init",
(unsigned int)errnum,
v2);
fflush(stdout);
result = 0;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

original_code:
void
ppnfs_mutex_init(struct ppnfs_mutex_t* mutex)
{
    int res;
    pthread_mutexattr_t attr;
    pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
    if ((res = pthread_mutex_init(&(mutex->mutex), &attr)) != 0)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not init mutex : err=%d:%s\n", 24, __FUNCTION__, res, strerror(res) ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
}

canonical_original_code:
void ppnfs_mutex_init(struct ppnfs_mutex_t *mutex)
{
    int res;
    union pthread_mutexattr_t attr;
    pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
    if ((res = pthread_mutex_init(&(mutex->mutex), &attr)) != 0)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not init mutex : err=%d:%s\n", 24, __FUNCTION__, res, strerror(res) ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
}

variable_types: struct ppnfs_mutex_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned long owner; char *context; } *

variable_types: res int

variable_types: union pthread_mutexattr_t { char __size[4]; int __align; }

user_defined_types: struct ppnfs_mutex_t { union pthread_mutex_t mutex; unsigned long owner; char *context; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
char __fastcall ppnfs_mutex_destroy(__int64 a1, const char *a2)
{
char result; // al
__int64 v3; // r12
const char *v4; // rbx
char *v5; // rax
unsigned int errnum; // [rsp+1Ch] [rbp-14h]

errnum = pthread_mutex_destroy((pthread_mutex_t *)a1);
result = errnum != 0;
if ( errnum )
{
v3 = *(_QWORD *)(a1 + 40);
v4 = *(const char **)(a1 + 48);
v5 = strerror(errnum);
fprintf(
stdout,
"ERR|ppnfs_mutex.cc:%d:%s|Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n",
35LL,
"ppnfs_mutex_destroy",
a2,
errnum,
v5,
v4,
v3);
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
char __fastcall func1(__int64 a1, const char *a2)
{
char result; // al
__int64 v3; // r12
const char *v4; // rbx
char *v5; // rax
unsigned int errnum; // [rsp+1Ch] [rbp-14h]

errnum = pthread_mutex_destroy((pthread_mutex_t *)a1);
result = errnum != 0;
if ( errnum )
{
v3 = *(_QWORD *)(a1 + 40);
v4 = *(const char **)(a1 + 48);
v5 = strerror(errnum);
fprintf(
stdout,
"ERR|ppnfs_mutex.cc:%d:%s|Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n",
35LL,
"ppnfs_mutex_destroy",
a2,
errnum,
v5,
v4,
v3);
result = fflush(stdout);
}
return result;
}

original_code:
void
ppnfs_mutex_destroy(struct ppnfs_mutex_t* mutex, const char* name)
{
    int res;
    if ((res = pthread_mutex_destroy(&(mutex->mutex))) != 0)
    {
        do { fprintf(stderr, "ERR" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n", 34, __FUNCTION__, name, res, strerror(res), mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0);
    }
}

canonical_original_code:
void ppnfs_mutex_destroy(struct ppnfs_mutex_t *mutex, char *name)
{
    int res;
    if ((res = pthread_mutex_destroy(&(mutex->mutex))) != 0)
    {
        do { fprintf(stderr, "ERR" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n", 34, __FUNCTION__, name, res, strerror(res), mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0);
    }
}

variable_types:
name
char *

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall ppnfs_mutex_lock(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
__int64 v4; // r12
const char *v5; // rbx
char *v6; // rax
unsigned int errnum; // [rsp+24h] [rbp-1Ch]
pthread_t v9; // [rsp+28h] [rbp-18h]

v9 = pthread_self();
errnum = pthread_mutex_lock((pthread_mutex_t *)a1);
if ( errnum )
{
v4 = *(_QWORD *)(a1 + 40);
v5 = *(const char **)(a1 + 48);
v6 = strerror(errnum);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n",
53LL,
"ppnfs_mutex_lock",
a2,
a3,
v9,
errnum,
v6,
v5,
v4);
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
else
{
*(_QWORD *)(a1 + 40) = v9;
result = a1;
*(_QWORD *)(a1 + 48) = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
__int64 v4; // r12
const char *v5; // rbx
char *v6; // rax
unsigned int errnum; // [rsp+24h] [rbp-1Ch]
pthread_t v9; // [rsp+28h] [rbp-18h]

v9 = pthread_self();
errnum = pthread_mutex_lock((pthread_mutex_t *)a1);
if ( errnum )
{
v4 = *(_QWORD *)(a1 + 40);
v5 = *(const char **)(a1 + 48);
v6 = strerror(errnum);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n",
53LL,
"ppnfs_mutex_lock",
a2,
a3,
v9,
errnum,
v6,
v5,
v4);
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
else
{
*(_QWORD *)(a1 + 40) = v9;
result = a1;
*(_QWORD *)(a1 + 48) = a3;
}
return result;
}

original_code:
void
ppnfs_mutex_lock(struct ppnfs_mutex_t* mutex, const char* name,
                 const char* context)
{
    int res;
    pthread_t me = pthread_self();
    res = pthread_mutex_lock(&(mutex->mutex));
    if (res == 0)
    {
        mutex->owner = me;
        mutex->context = context;
        return;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n", 52, __FUNCTION__, name, context, (unsigned long) me, res, strerror(res), mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
}

canonical_original_code:
void ppnfs_mutex_lock(struct ppnfs_mutex_t *mutex, char *name, char *context)
{
    int res;
    unsigned long me = pthread_self();
    res = pthread_mutex_lock(&(mutex->mutex));
    if (res == 0)
    {
        mutex->owner = me;
        mutex->context = context;
        return;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n", 52, __FUNCTION__, name, context, (unsigned long) me, res, strerror(res), mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
}

variable_types:
context
char *

variable_types:
me
unsigned long


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall ppnfs_mutex_check_unlocked(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
pthread_t v5; // [rsp+28h] [rbp-8h]

v5 = pthread_self();
result = *(_QWORD *)(a1 + 40);
if ( v5 == result )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n",
65LL,
"ppnfs_mutex_check_unlocked",
a2,
v5,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
pthread_t v5; // [rsp+28h] [rbp-8h]

v5 = pthread_self();
result = *(_QWORD *)(a1 + 40);
if ( v5 == result )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n",
65LL,
"ppnfs_mutex_check_unlocked",
a2,
v5,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

original_code:
void
ppnfs_mutex_check_unlocked(struct ppnfs_mutex_t* mutex, const char* name,
                           const char* context)
{
    pthread_t me = pthread_self();
    if (mutex->owner == me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n", 64, __FUNCTION__, name, (unsigned long) me, context, mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
}

canonical_original_code:
void ppnfs_mutex_check_unlocked(struct ppnfs_mutex_t *mutex, char *name, char *context)
{
    unsigned long me = pthread_self();
    if (mutex->owner == me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n", 64, __FUNCTION__, name, (unsigned long) me, context, mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall ppnfs_mutex_check_locked(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
pthread_t v5; // [rsp+28h] [rbp-8h]

v5 = pthread_self();
result = *(_QWORD *)(a1 + 40);
if ( v5 != result )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n",
77LL,
"ppnfs_mutex_check_locked",
a2,
v5,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
pthread_t v5; // [rsp+28h] [rbp-8h]

v5 = pthread_self();
result = *(_QWORD *)(a1 + 40);
if ( v5 != result )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n",
77LL,
"ppnfs_mutex_check_locked",
a2,
v5,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

original_code:
void
ppnfs_mutex_check_locked(struct ppnfs_mutex_t* mutex, const char* name,
                         const char* context)
{
    pthread_t me = pthread_self();
    if (mutex->owner != me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n", 76, __FUNCTION__, name, (unsigned long) me, context, mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
}

canonical_original_code:
void ppnfs_mutex_check_locked(struct ppnfs_mutex_t *mutex, char *name, char *context)
{
    unsigned long me = pthread_self();
    if (mutex->owner != me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n", 76, __FUNCTION__, name, (unsigned long) me, context, mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
int __fastcall ppnfs_mutex_unlock(__int64 a1, const char *a2, const char *a3)
{
int result; // eax
const char *v4; // r12
__int64 v5; // rbx
char *v6; // rax
unsigned int errnum; // [rsp+24h] [rbp-1Ch]
pthread_t v9; // [rsp+28h] [rbp-18h]

v9 = pthread_self();
if ( v9 != *(_QWORD *)(a1 + 40) )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n",
91LL,
"ppnfs_mutex_unlock",
a2,
*(_QWORD *)(a1 + 40),
*(const char **)(a1 + 48),
v9,
a3);
fflush(stdout);
*(_BYTE *)ppnfs_mutex_init = 0;
}
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(a1 + 48) = 0LL;
result = pthread_mutex_unlock((pthread_mutex_t *)a1);
errnum = result;
if ( result )
{
v4 = *(const char **)(a1 + 48);
v5 = *(_QWORD *)(a1 + 40);
v6 = strerror(result);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n",
103LL,
"ppnfs_mutex_unlock",
a2,
v9,
a3,
errnum,
v6,
v5,
v4);
fflush(stdout);
result = 0;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, const char *a2, const char *a3)
{
int result; // eax
const char *v4; // r12
__int64 v5; // rbx
char *v6; // rax
unsigned int errnum; // [rsp+24h] [rbp-1Ch]
pthread_t v9; // [rsp+28h] [rbp-18h]

v9 = pthread_self();
if ( v9 != *(_QWORD *)(a1 + 40) )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n",
91LL,
"ppnfs_mutex_unlock",
a2,
*(_QWORD *)(a1 + 40),
*(const char **)(a1 + 48),
v9,
a3);
fflush(stdout);
*(_BYTE *)ppnfs_mutex_init = 0;
}
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(a1 + 48) = 0LL;
result = pthread_mutex_unlock((pthread_mutex_t *)a1);
errnum = result;
if ( result )
{
v4 = *(const char **)(a1 + 48);
v5 = *(_QWORD *)(a1 + 40);
v6 = strerror(result);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n",
103LL,
"ppnfs_mutex_unlock",
a2,
v9,
a3,
errnum,
v6,
v5,
v4);
fflush(stdout);
result = 0;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

original_code:
void
ppnfs_mutex_unlock(struct ppnfs_mutex_t* mutex, const char* name,
                   const char* context)
{
    int res;
    pthread_t me = pthread_self();
    if (mutex->owner != me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n", 90, __FUNCTION__, name, (unsigned long)mutex->owner, mutex->context, (unsigned long)me, context ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
    mutex->owner = 0;
    mutex->context = ((void *)0);
    res = pthread_mutex_unlock(&(mutex->mutex));
    if (res == 0)
    {
        return;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n", 102, __FUNCTION__, name, (unsigned long)me, context, res, strerror(res), (unsigned long)mutex->owner, mutex->context ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
}

canonical_original_code:
void ppnfs_mutex_unlock(struct ppnfs_mutex_t *mutex, char *name, char *context)
{
    int res;
    unsigned long me = pthread_self();
    if (mutex->owner != me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n", 90, __FUNCTION__, name, (unsigned long)mutex->owner, mutex->context, (unsigned long)me, context ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
    mutex->owner = 0;
    mutex->context = ((void *)0);
    res = pthread_mutex_unlock(&(mutex->mutex));
    if (res == 0)
    {
        return;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n", 102, __FUNCTION__, name, (unsigned long)me, context, res, strerror(res), (unsigned long)mutex->owner, mutex->context ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
}


comp

decompiled_code:
__int64 __fastcall comp(const void *a1, const void *a2)
{
return _gmpz_cmp((char *)a1 + 8, (char *)a2 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return _gmpz_cmp((char *)a1 + 8, (char *)a2 + 8);
}

original_code:
int comp(const void * a,const void * b)
{
 const struct tagGpow * a1 = (const struct tagGpow * )a;
 const struct tagGpow * b1 = (const struct tagGpow * )b;
 return __gmpz_cmp(a1->gpow, b1->gpow);
}

canonical_original_code:
int comp(void *a, void *b)
{
 struct tagGpow *a1 = (const struct tagGpow * )a;
 struct tagGpow *b1 = (const struct tagGpow * )b;
 return __gmpz_cmp(a1->gpow, b1->gpow);
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct tagGpow { int index; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } gpow[1]; } *

user_defined_types: struct tagGpow { int index; struct __mpz_struct gpow[1]; }


precompute

decompiled_code:
void __fastcall precompute(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r15
double v5; // xmm0_8
double v6; // xmm0_8
__int64 v7; // rdx
int v8; // er14
__int64 v9; // rbx
__int64 v10; // r13
int i; // er12

v3 = a2;
v5 = (double)a3;
if ( (double)a3 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
v7 = (unsigned int)(a3 >> 31);
LODWORD(v7) = a3 % (int)v6;
v8 = a3 / (int)v6;
if ( v8 >= 0 )
{
v9 = (unsigned int)((_DWORD)&arrG + 8);
v10 = 0LL;
for ( i = 0; i <= v8; ++i )
{
*(_DWORD *)(v9 - 8) = i;
_gmpz_init(v9, a2, v7);
a2 = a1;
_gmpz_powm_ui(v9, a1, v10, v3);
v9 += 24LL;
v10 += (int)v6;
}
}
qsort(&arrG, v8 + 1, 0x18uLL, (__compar_fn_t)comp);
}

original_code:
void precompute(mpz_t g, mpz_t m, int q)
{
 int i;
 int t = (int)sqrt(q);
 for (i = 0; i <= (int)q/t; i++)
 {
  arrG[i].index = i;
  __gmpz_init(arrG[i].gpow);
  __gmpz_powm_ui(arrG[i].gpow, g, i*t, m);
 }
 qsort(arrG, (int)q/t+1, sizeof(struct tagGpow), comp);
}

canonical_original_code:
void precompute(struct __mpz_struct g[1], struct __mpz_struct m[1], int q)
{
 int i;
 int t = (int)sqrt(q);
 for (i = 0; i <= (int)q/t; i++)
 {
  arrG[i].index = i;
  __gmpz_init(arrG[i].gpow);
  __gmpz_powm_ui(arrG[i].gpow, g, i*t, m);
 }
 qsort(arrG, (int)q/t+1, sizeof(struct tagGpow), comp);
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
m
struct __mpz_struct [1]

variable_types: q int

variable_types: t int


Shank

original_code:
int Shank(int* x, mpz_t g, mpz_t y, mpz_t m, int q)
{
 int t = (int)sqrt(q);
 int i;
 mpz_t tmpy;
 if (!bstored)
 {
  precompute(g, m, q);
  bstored = 1;
 }
 __gmpz_init(tmpy);
 for (i = 0; i <= t; i++)
 {
  __gmpz_powm_ui(tmpy, g, i, m);
  __gmpz_mul(tmpy, tmpy, y);
  __gmpz_mod(tmpy, tmpy, m);
  int mid;
  int min = 0, max = (int)q/t;
  while (max >= min)
  {
   mid = (min + max)/2;
   int r = __gmpz_cmp(tmpy, arrG[mid].gpow);
   if (r > 0)
    min = mid + 1;
   else if (r < 0)
    max = mid - 1;
   else
   {
    *x = (arrG[mid].index*t-i)%q;
    if (*x < 0)
     *x += q;
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int Shank(int *x, struct __mpz_struct g[1], struct __mpz_struct y[1], struct __mpz_struct m[1], int q)
{
 int t = (int)sqrt(q);
 int i;
 struct __mpz_struct tmpy[1];
 if (!bstored)
 {
  precompute(g, m, q);
  bstored = 1;
 }
 __gmpz_init(tmpy);
 for (i = 0; i <= t; i++)
 {
  __gmpz_powm_ui(tmpy, g, i, m);
  __gmpz_mul(tmpy, tmpy, y);
  __gmpz_mod(tmpy, tmpy, m);
  int mid;
  int min = 0; int max = (int)q/t;
  while (max >= min)
  {
   mid = (min + max)/2;
   int r = __gmpz_cmp(tmpy, arrG[mid].gpow);
   if (r > 0)
    min = mid + 1;
   else if (r < 0)
    max = mid - 1;
   else
   {
    *x = (arrG[mid].index*t-i)%q;
    if (*x < 0)
     *x += q;
    return 1;
   }
  }
 }
 return 0;
}

variable_types:
x
int *

variable_types:
y
struct __mpz_struct [1]

variable_types: mid int

variable_types: min int

variable_types: max int

variable_types: r int


original_code:
int Shank2(int* x, mpz_t g, mpz_t y, mpz_t m, int q)
{
 int t = (int)sqrt(q);
 int i;
 mpz_t * arrG = (mpz_t*)malloc((int)(q/t+1)*sizeof(mpz_t));
 for (i = 0; i <= (int)q/t; i++)
 {
  __gmpz_init(arrG[i]);
  __gmpz_powm_ui(arrG[i], g, i*t, m);
 }
 mpz_t tmpy;
 __gmpz_init(tmpy);
 for (i = 0; i <= t; i++)
 {
  __gmpz_powm_ui(tmpy, g, i, m);
  __gmpz_mul(tmpy, tmpy, y);
  __gmpz_mod(tmpy, tmpy, m);
  int j;
  for (j = 0; j <= (int)q/t; j++)
  {
   if (!__gmpz_cmp(tmpy, arrG[j]))
   {
    *x = (j*t-i)%q;
    if (*x < 0)
     *x += q;
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int Shank2(int *x, struct __mpz_struct g[1], struct __mpz_struct y[1], struct __mpz_struct m[1], int q)
{
 int t = (int)sqrt(q);
 int i;
 struct __mpz_struct (*arrG)[1] = (mpz_t*)malloc((int)(q/t+1)*sizeof(mpz_t));
 for (i = 0; i <= (int)q/t; i++)
 {
  __gmpz_init(arrG[i]);
  __gmpz_powm_ui(arrG[i], g, i*t, m);
 }
 struct __mpz_struct tmpy[1];
 __gmpz_init(tmpy);
 for (i = 0; i <= t; i++)
 {
  __gmpz_powm_ui(tmpy, g, i, m);
  __gmpz_mul(tmpy, tmpy, y);
  __gmpz_mod(tmpy, tmpy, m);
  int j;
  for (j = 0; j <= (int)q/t; j++)
  {
   if (!__gmpz_cmp(tmpy, arrG[j]))
   {
    *x = (j*t-i)%q;
    if (*x < 0)
     *x += q;
    return 1;
   }
  }
 }
 return 0;
}

variable_types: i int

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]

variable_types: j int


original_code:
void discrete_log(mpz_t x, mpz_t a, mpz_t b, mpz_t m, int p, int c)
{
    int * arrA = (int*) malloc(c*sizeof(int));
    mpz_t * arrP = (mpz_t*)malloc(c*sizeof(mpz_t));
 int i;
 for (i = 0; i < c; i++)
 {
  __gmpz_init(arrP[i]);
  __gmpz_ui_pow_ui(arrP[i], p, i);
 }
 mpz_t bi[2], abase, tmpy;
 __gmpz_init(bi[0]);
 __gmpz_init(bi[1]);
 __gmpz_init(tmpy);
 __gmpz_init(abase);
 int pos = 1;
 __gmpz_set(bi[0], b);
 __gmpz_powm(abase, a, arrP[c-1], m);
 __gmpz_powm(tmpy, bi[0], arrP[c-1], m);
 precompute(abase, m, p);
 bstored = 1;
 if(!Shank(&arrA[0], abase, tmpy, m, p))
 {
  printf("did not find log for %d\n", i);
 }
 __gmpz_set_ui(x, arrA[0]);
 mpz_t ap;
 __gmpz_init(ap);
 for (i = 1; i < c; i++)
 {
  __gmpz_mul_ui(ap, arrP[i-1], arrA[i-1]);
  __gmpz_invert(bi[pos], a, m);
  __gmpz_powm(bi[pos], bi[pos], ap, m);
  __gmpz_mul(bi[pos], bi[1-pos], bi[pos]);
  __gmpz_powm(tmpy, bi[pos], arrP[c-i-1], m);
  if (!Shank(&arrA[i], abase, tmpy, m, p))
  {
   printf("did not find log for %d\n", i);
  }
  pos = 1-pos;
  __gmpz_mul_ui(tmpy, arrP[i], arrA[i]);
  __gmpz_add(x, x, tmpy);
 }
}

canonical_original_code:
void discrete_log(struct __mpz_struct x[1], struct __mpz_struct a[1], struct __mpz_struct b[1], struct __mpz_struct m[1], int p, int c)
{
    int *arrA = (int*) malloc(c*sizeof(int));
    struct __mpz_struct (*arrP)[1] = (mpz_t*)malloc(c*sizeof(mpz_t));
 int i;
 for (i = 0; i < c; i++)
 {
  __gmpz_init(arrP[i]);
  __gmpz_ui_pow_ui(arrP[i], p, i);
 }
 struct __mpz_struct bi[2][1]; struct __mpz_struct abase[1]; struct __mpz_struct tmpy[1];
 __gmpz_init(bi[0]);
 __gmpz_init(bi[1]);
 __gmpz_init(tmpy);
 __gmpz_init(abase);
 int pos = 1;
 __gmpz_set(bi[0], b);
 __gmpz_powm(abase, a, arrP[c-1], m);
 __gmpz_powm(tmpy, bi[0], arrP[c-1], m);
 precompute(abase, m, p);
 bstored = 1;
 if(!Shank(&arrA[0], abase, tmpy, m, p))
 {
  printf("did not find log for %d\n", i);
 }
 __gmpz_set_ui(x, arrA[0]);
 struct __mpz_struct ap[1];
 __gmpz_init(ap);
 for (i = 1; i < c; i++)
 {
  __gmpz_mul_ui(ap, arrP[i-1], arrA[i-1]);
  __gmpz_invert(bi[pos], a, m);
  __gmpz_powm(bi[pos], bi[pos], ap, m);
  __gmpz_mul(bi[pos], bi[1-pos], bi[pos]);
  __gmpz_powm(tmpy, bi[pos], arrP[c-i-1], m);
  if (!Shank(&arrA[i], abase, tmpy, m, p))
  {
   printf("did not find log for %d\n", i);
  }
  pos = 1-pos;
  __gmpz_mul_ui(tmpy, arrP[i], arrA[i]);
  __gmpz_add(x, x, tmpy);
 }
}

variable_types:
a
struct __mpz_struct [1]

variable_types:
b
struct __mpz_struct [1]

variable_types: p int

variable_types: c int

variable_types:
arrA
int *

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [2][1]

variable_types: pos int


comp

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct tagGpow { int index; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } gpow[1]; } *


precompute

decompiled_code:
void __fastcall precompute(__int64 a1, __int64 a2, signed int a3)
{
int v4; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]

v4 = (int)std::sqrt<int>((unsigned int)a3);
for ( i = 0; i <= a3 / v4; ++i )
{
arrG[6 * i] = i;
_gmpz_init(&arrG[6 * i + 2]);
_gmpz_powm_ui(&arrG[6 * i + 2], a1, v4 * i, a2);
}
qsort(arrG, a3 / v4 + 1, 0x18uLL, (__compar_fn_t)comp);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, signed int a3)
{
int v4; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]

v4 = (int)std::sqrt<int>((unsigned int)a3);
for ( i = 0; i <= a3 / v4; ++i )
{
arrG[6 * i] = i;
_gmpz_init(&arrG[6 * i + 2]);
_gmpz_powm_ui(&arrG[6 * i + 2], a1, v4 * i, a2);
}
qsort(arrG, a3 / v4 + 1, 0x18uLL, (__compar_fn_t)comp);
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
m
struct __mpz_struct [1]

variable_types: q int

variable_types: t int


Shank

variable_types:
x
int *

variable_types:
y
struct __mpz_struct [1]

variable_types: i int

variable_types: mid int

variable_types: min int

variable_types: max int

variable_types: r int


decompiled_code:
__int64 __fastcall Shank2(int *a1, __int64 a2, __int64 a3, __int64 a4, signed int a5)
{
char v9[24]; // [rsp+30h] [rbp-30h] BYREF
char *v10; // [rsp+48h] [rbp-18h]
int v11; // [rsp+54h] [rbp-Ch]
int j; // [rsp+58h] [rbp-8h]
int i; // [rsp+5Ch] [rbp-4h]

v11 = (int)std::sqrt<int>((unsigned int)a5);
v10 = (char *)malloc(16LL * (a5 / v11 + 1));
for ( i = 0; i <= a5 / v11; ++i )
{
_gmpz_init(&v10[16 * i]);
_gmpz_powm_ui(&v10[16 * i], a2, v11 * i, a4);
}
_gmpz_init(v9);
i = 0;
LABEL_5:
if ( i > v11 )
return 0LL;
_gmpz_powm_ui(v9, a2, i, a4);
_gmpz_mul(v9, v9, a3);
_gmpz_mod(v9, v9, a4);
for ( j = 0; ; ++j )
{
if ( j > a5 / v11 )
{
++i;
goto LABEL_5;
}
if ( !(unsigned int)_gmpz_cmp(v9, &v10[16 * j]) )
break;
}
*a1 = (v11 * j - i) % a5;
if ( *a1 < 0 )
*a1 += a5;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, __int64 a2, __int64 a3, __int64 a4, signed int a5)
{
char v9[24]; // [rsp+30h] [rbp-30h] BYREF
char *v10; // [rsp+48h] [rbp-18h]
int v11; // [rsp+54h] [rbp-Ch]
int j; // [rsp+58h] [rbp-8h]
int i; // [rsp+5Ch] [rbp-4h]

v11 = (int)std::sqrt<int>((unsigned int)a5);
v10 = (char *)malloc(16LL * (a5 / v11 + 1));
for ( i = 0; i <= a5 / v11; ++i )
{
_gmpz_init(&v10[16 * i]);
_gmpz_powm_ui(&v10[16 * i], a2, v11 * i, a4);
}
_gmpz_init(v9);
i = 0;
LABEL_5:
if ( i > v11 )
return 0LL;
_gmpz_powm_ui(v9, a2, i, a4);
_gmpz_mul(v9, v9, a3);
_gmpz_mod(v9, v9, a4);
for ( j = 0; ; ++j )
{
if ( j > a5 / v11 )
{
++i;
goto LABEL_5;
}
if ( !(unsigned int)_gmpz_cmp(v9, &v10[16 * j]) )
break;
}
*a1 = (v11 * j - i) % a5;
if ( *a1 < 0 )
*a1 += a5;
return 1LL;
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]

variable_types: j int


decompiled_code:
int __fastcall ppnfs_mutex_destroy(__int64 a1, const char *a2)
{
int result; // eax
unsigned int v3; // ebx
__int64 v4; // r14
const char *v5; // r12
char *v6; // rax

result = pthread_mutex_destroy((pthread_mutex_t *)a1);
v3 = result;
if ( result )
{
v4 = *(_QWORD *)(a1 + 40);
v5 = *(const char **)(a1 + 48);
v6 = strerror(result);
fprintf(
stderr,
"ERR|ppnfs_mutex.c:%d:%s|Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n",
34LL,
"ppnfs_mutex_destroy",
a2,
v3,
v6,
v5,
v4);
result = fflush(stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, const char *a2)
{
int result; // eax
unsigned int v3; // ebx
__int64 v4; // r14
const char *v5; // r12
char *v6; // rax

result = pthread_mutex_destroy((pthread_mutex_t *)a1);
v3 = result;
if ( result )
{
v4 = *(_QWORD *)(a1 + 40);
v5 = *(const char **)(a1 + 48);
v6 = strerror(result);
fprintf(
stderr,
"ERR|ppnfs_mutex.c:%d:%s|Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n",
34LL,
"ppnfs_mutex_destroy",
a2,
v3,
v6,
v5,
v4);
result = fflush(stderr);
}
return result;
}

variable_types: struct ppnfs_mutex_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned long owner; char *context; } *

variable_types:
name
char *

variable_types: res int


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
unsigned int __fastcall ppnfs_mutex_lock(pthread_mutex_t *mutex, const char *a2, const char *a3)
{
__int64 v4; // r14
unsigned int result; // eax
__int64 v6; // r12
__int64 v7; // r15
const char *v8; // rbx
char *v9; // rax

v4 = pthread_self();
result = pthread_mutex_lock(mutex);
v6 = result;
if ( result )
{
v7 = mutex[1].__align;
v8 = (const char *)*(&mutex[1].__align + 1);
v9 = strerror(result);
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n",
52LL,
"ppnfs_mutex_lock",
a2,
a3,
v4,
v6,
v9,
v8,
v7);
result = fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
}
else
{
mutex[1].__align = v4;
*(&mutex[1].__align + 1) = (__int64)a3;
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func1(pthread_mutex_t *mutex, const char *a2, const char *a3)
{
__int64 v4; // r14
unsigned int result; // eax
__int64 v6; // r12
__int64 v7; // r15
const char *v8; // rbx
char *v9; // rax

v4 = pthread_self();
result = pthread_mutex_lock(mutex);
v6 = result;
if ( result )
{
v7 = mutex[1].__align;
v8 = (const char *)*(&mutex[1].__align + 1);
v9 = strerror(result);
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n",
52LL,
"ppnfs_mutex_lock",
a2,
a3,
v4,
v6,
v9,
v8,
v7);
result = fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
}
else
{
mutex[1].__align = v4;
*(&mutex[1].__align + 1) = (__int64)a3;
}
return result;
}

variable_types:
context
char *

variable_types:
me
unsigned long


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
int __fastcall ppnfs_mutex_check_unlocked(__int64 a1, const char *a2, const char *a3)
{
pthread_t v4; // rax

v4 = pthread_self();
if ( *(_QWORD *)(a1 + 40) == v4 )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n",
64LL,
"ppnfs_mutex_check_unlocked",
a2,
v4,
a3,
*(const char **)(a1 + 48),
v4);
LODWORD(v4) = fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
}
return v4;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, const char *a2, const char *a3)
{
pthread_t v4; // rax

v4 = pthread_self();
if ( *(_QWORD *)(a1 + 40) == v4 )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n",
64LL,
"ppnfs_mutex_check_unlocked",
a2,
v4,
a3,
*(const char **)(a1 + 48),
v4);
LODWORD(v4) = fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
}
return v4;
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
int __fastcall ppnfs_mutex_check_locked(__int64 a1, const char *a2, const char *a3)
{
pthread_t v4; // r9
__int64 v5; // rax

v4 = pthread_self();
v5 = *(_QWORD *)(a1 + 40);
if ( v5 != v4 )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n",
76LL,
"ppnfs_mutex_check_locked",
a2,
v4,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
LODWORD(v5) = fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
}
return v5;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2, const char *a3)
{
pthread_t v4; // r9
__int64 v5; // rax

v4 = pthread_self();
v5 = *(_QWORD *)(a1 + 40);
if ( v5 != v4 )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n",
76LL,
"ppnfs_mutex_check_locked",
a2,
v4,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
LODWORD(v5) = fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
}
return v5;
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
unsigned int __fastcall ppnfs_mutex_unlock(pthread_mutex_t *mutex, const char *a2, const char *a3)
{
pthread_t v4; // rax
pthread_t v5; // r12
__int64 v6; // r9
unsigned int result; // eax
__int64 v8; // r13
const char *v9; // r15
__int64 v10; // rbx
char *v11; // rax

v4 = pthread_self();
v5 = v4;
v6 = mutex[1].__align;
if ( v6 != v4 )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n",
90LL,
"ppnfs_mutex_unlock",
a2,
v6,
*((const char **)&mutex[1].__align + 1),
v4,
a3);
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
}
*(_OWORD *)&mutex[1].__lock = 0uLL;
result = pthread_mutex_unlock(mutex);
v8 = result;
if ( result )
{
v9 = (const char *)*(&mutex[1].__align + 1);
v10 = mutex[1].__align;
v11 = strerror(result);
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n",
102LL,
"ppnfs_mutex_unlock",
a2,
v5,
a3,
v8,
v11,
v10,
v9);
result = fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func4(pthread_mutex_t *mutex, const char *a2, const char *a3)
{
pthread_t v4; // rax
pthread_t v5; // r12
__int64 v6; // r9
unsigned int result; // eax
__int64 v8; // r13
const char *v9; // r15
__int64 v10; // rbx
char *v11; // rax

v4 = pthread_self();
v5 = v4;
v6 = mutex[1].__align;
if ( v6 != v4 )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n",
90LL,
"ppnfs_mutex_unlock",
a2,
v6,
*((const char **)&mutex[1].__align + 1),
v4,
a3);
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
}
*(_OWORD *)&mutex[1].__lock = 0uLL;
result = pthread_mutex_unlock(mutex);
v8 = result;
if ( result )
{
v9 = (const char *)*(&mutex[1].__align + 1);
v10 = mutex[1].__align;
v11 = strerror(result);
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n",
102LL,
"ppnfs_mutex_unlock",
a2,
v5,
a3,
v8,
v11,
v10,
v9);
result = fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}


decompiled_code:
__int64 __fastcall sdbm_hash(__int64 a1, const char *a2, int a3)
{
int v6; // [rsp+34h] [rbp-4h]

v6 = 0;
while ( *a2 )
{
a1 = (a1 << 6) + *(unsigned __int8 *)a2 + (a1 << 16) - a1;
if ( ++v6 == a3 )
break;
++a2;
}
return a1;
}

original_code:
static hash_t
sdbm_hash( hash_t h, const char* str, int sz )
{
    int cur = 0;
    const char* c;
    unsigned char d;
    for ( c = str ; *c ; c++ ) {
        d = (unsigned char)(*c);
        h = d + (h<<6) + (h<<16) - h;
        cur++;
        if ( cur == sz ) break;
    }
    return h;
}

canonical_original_code:
static unsigned long long sdbm_hash(unsigned long long h, char *str, int sz)
{
    int cur = 0;
    char *c;
    unsigned char d;
    for ( c = str ; *c ; c++ ) {
        d = (unsigned char)(*c);
        h = d + (h<<6) + (h<<16) - h;
        cur++;
        if ( cur == sz ) break;
    }
    return h;
}

variable_types:
h
unsigned long long

variable_types:
str
char *

variable_types: sz int

variable_types: cur int

variable_types:
c
char *

variable_types:
d
unsigned char


continueHashPartial

decompiled_code:
__int64 __fastcall continueHashPartial(__int64 a1, const char *a2, int a3)
{
return sdbm_hash(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, int a3)
{
return func0(a1, a2, a3);
}

original_code:
hash_t continueHashPartial ( hash_t h, const char* str, int sz )
{
    return sdbm_hash( h, str, sz );
}

canonical_original_code:
unsigned long long continueHashPartial(unsigned long long h, char *str, int sz)
{
    return sdbm_hash( h, str, sz );
}


continueHash

decompiled_code:
__int64 __fastcall continueHash(__int64 a1, const char *a2)
{
return continueHashPartial(a1, a2, -1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
return func1(a1, a2, -1);
}

original_code:
hash_t continueHash ( hash_t h, const char* str )
{
    return continueHashPartial ( h, str, ~((int)0) );
}

canonical_original_code:
unsigned long long continueHash(unsigned long long h, char *str)
{
    return continueHashPartial ( h, str, ~((int)0) );
}


doHashPartial

decompiled_code:
__int64 __fastcall doHashPartial(const char *a1, int a2)
{
return continueHashPartial(581LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, int a2)
{
return func1(581LL, a1, a2);
}

original_code:
hash_t doHashPartial ( const char* str, int sz )
{
    hash_t h = 0x245;
    return continueHashPartial ( h, str, sz );
}

canonical_original_code:
unsigned long long doHashPartial(char *str, int sz)
{
    unsigned long long h = 0x245;
    return continueHashPartial ( h, str, sz );
}


doHash

decompiled_code:
__int64 __fastcall doHash(const char *a1)
{
return doHashPartial(a1, -1);
}

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

original_code:
hash_t doHash ( const char* str )
{
    return doHashPartial ( str, ~((int)0) );
}

canonical_original_code:
unsigned long long doHash(char *str)
{
    return doHashPartial ( str, ~((int)0) );
}


original_code:
void reference_dgemm (int N, double ALPHA, double* A, double* B, double* C)
{
  char TRANSA = 'N';
  char TRANSB = 'N';
  int M = N;
  int K = N;
  double BETA = 1.;
  int LDA = N;
  int LDB = N;
  int LDC = N;
  dgemm_(&TRANSA, &TRANSB, &M, &N, &K, &ALPHA, A, &LDA, B, &LDB, &BETA, C, &LDC);
}

canonical_original_code:
void reference_dgemm(int N, double ALPHA, double *A, double *B, double *C)
{
  char TRANSA = 'N';
  char TRANSB = 'N';
  int M = N;
  int K = N;
  double BETA = 1.;
  int LDA = N;
  int LDB = N;
  int LDC = N;
  dgemm_(&TRANSA, &TRANSB, &M, &N, &K, &ALPHA, A, &LDA, B, &LDB, &BETA, C, &LDC);
}

variable_types: N int

variable_types: ALPHA double

variable_types:
A
double *

variable_types:
B
double *

variable_types:
C
double *

variable_types: TRANSA char

variable_types: TRANSB char

variable_types: M int

variable_types: K int

variable_types: BETA double

variable_types: LDA int

variable_types: LDB int

variable_types: LDC int