decompiled_code:
__int64 __fastcall SxBytesRot8(int a1)
{
unsigned __int8 v1; // ch
unsigned __int8 v2; // cl
int v3; // esi
unsigned __int8 v4; // cl
int v5; // eax
int v6; // edx

Sx01(BYTE2(a1));
Sx01(v1);
v3 = Sx01(v2);
v5 = Sx01(v4);
return v5 | v6 | (unsigned int)(v3 << 8);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
unsigned __int8 v1; // ch
unsigned __int8 v2; // cl
int v3; // esi
unsigned __int8 v4; // cl
int v5; // eax
int v6; // edx

func4(BYTE2(a1));
func4(v1);
v3 = func4(v2);
v5 = func4(v4);
return v5 | v6 | (unsigned int)(v3 << 8);
}


repo: IanHarvey/minicrypt

decompiled_code:
__int64 __fastcall Td0123(unsigned int a1, int a2, __int64 a3, unsigned __int8 a4)
{
unsigned __int8 v4; // dh

return __ROR4__(SiE9DB[BYTE2(a2)], 8) ^ SiE9DB[HIBYTE(a1)] ^ (unsigned int)(__ROL4__(SiE9DB[a4], 8) ^ __ROL4__(SiE9DB[v4], 16));
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2, __int64 a3, unsigned __int8 a4)
{
unsigned __int8 v4; // dh

return __ROR4__(SiE9DB[BYTE2(a2)], 8) ^ SiE9DB[HIBYTE(a1)] ^ (unsigned int)(__ROL4__(SiE9DB[a4], 8) ^ __ROL4__(SiE9DB[v4], 16));
}

return_type: unsigned int


invMixCol

decompiled_code:
__int64 __fastcall invMixCol(int a1)
{
unsigned int v1; // eax

v1 = SxBytes(a1);
return Td0123(v1, v1, v1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
unsigned int v1; // eax

v1 = func6(a1);
return func8(v1, v1, v1, v1);
}

original_code:
static uint32_t invMixCol(uint32_t w)
{
  w = SxBytes(w);
  return Td0123(w,w,w,w);
}

canonical_original_code:
static unsigned int invMixCol(unsigned int w)
{
  w = SxBytes(w);
  return Td0123(w,w,w,w);
}

variable_types:
w
unsigned int


decompiled_code:
__int64 __fastcall AESMini_Init_Decrypt(_DWORD *a1, unsigned int *a2, int a3)
{
__int64 result; // rax
int v4; // er8
int v5; // edx
int v6; // ecx
int v7; // esi
_DWORD *v8; // rcx
int *v9; // r9
int *v10; // r10

AESMini_Init_Encrypt(a1, a2, a3);
result = (unsigned int)*a1;
v4 = 4 * result;
v5 = 4 * result + 3;
if ( v5 > 0 )
{
result = 0LL;
do
{
v6 = v5;
v7 = a1[result + 1];
--v5;
v8 = &a1[(v6 ^ 3) + 1];
a1[++result] = *v8;
*v8 = v7;
}
while ( v5 > (int)result );
}
if ( v4 > 4 )
{
v9 = a1 + 5;
do
{
result = invMixCol(*v9);
*(v9 - 1) = result;
}
while ( v10 != v9 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1, unsigned int *a2, int a3)
{
__int64 result; // rax
int v4; // er8
int v5; // edx
int v6; // ecx
int v7; // esi
_DWORD *v8; // rcx
int *v9; // r9
int *v10; // r10

func12(a1, a2, a3);
result = (unsigned int)*a1;
v4 = 4 * result;
v5 = 4 * result + 3;
if ( v5 > 0 )
{
result = 0LL;
do
{
v6 = v5;
v7 = a1[result + 1];
--v5;
v8 = &a1[(v6 ^ 3) + 1];
a1[++result] = *v8;
*v8 = v7;
}
while ( v5 > (int)result );
}
if ( v4 > 4 )
{
v9 = a1 + 5;
do
{
result = func11(*v9);
*(v9 - 1) = result;
}
while ( v10 != v9 );
}
return result;
}

original_code:
static void AESMini_Init_Decrypt(AESMini_keys *ctx, const uint8_t *keyData, int nkeybytes)
{
  int i, j;
  int nkeys;
  uint32_t *rk = ctx->roundkeys;
  uint32_t temp;
  AESMini_Init_Encrypt(ctx, keyData, nkeybytes);
  nkeys = 4*ctx->nrounds;
  for (i = 0, j = nkeys+3; i < j; i++, j--)
  {
    temp = rk[i]; rk[i] = rk[j^3]; rk[j^3] = temp;
  }
  for (i = 4; i < nkeys; i++)
  {
    rk[i] = invMixCol(rk[i]);
  }
}

canonical_original_code:
static void AESMini_Init_Decrypt(struct AESMini_keys *ctx, unsigned char *keyData, int nkeybytes)
{
  int i; int j;
  int nkeys;
  unsigned int *rk = ctx->roundkeys;
  unsigned int temp;
  AESMini_Init_Encrypt(ctx, keyData, nkeybytes);
  nkeys = 4*ctx->nrounds;
  for (i = 0, j = nkeys+3; i < j; i++, j--)
  {
    temp = rk[i]; rk[i] = rk[j^3]; rk[j^3] = temp;
  }
  for (i = 4; i < nkeys; i++)
  {
    rk[i] = invMixCol(rk[i]);
  }
}

variable_types: struct AESMini_keys { int nrounds; unsigned int roundkeys[60]; } *

variable_types:
keyData
unsigned char *

variable_types: nkeybytes int

variable_types: i int

variable_types: j int

variable_types: nkeys int

variable_types:
rk
unsigned int *

variable_types:
temp
unsigned int

return_type: void


decompiled_code:
__int64 __fastcall getU32(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

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

canonical_original_code:
static unsigned int getU32(unsigned char *pt)
{
  return (pt[0] << 24) | (pt[1] << 16) | (pt[2] << 8) | pt[3];
}

variable_types:
pt
unsigned char *


decompiled_code:
__int64 __fastcall Te0(unsigned __int8 a1)
{
int v1; // edx

v1 = (unsigned __int16)Sx0201[a1];
return ((unsigned __int8)v1 << 8) ^ (v1 << 16) ^ (unsigned __int8)v1 ^ (unsigned int)BYTE1(v1);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 a1)
{
int v1; // edx

v1 = (unsigned __int16)Sx0201[a1];
return ((unsigned __int8)v1 << 8) ^ (v1 << 16) ^ (unsigned __int8)v1 ^ (unsigned int)BYTE1(v1);
}

canonical_original_code:
static unsigned int Te0(unsigned char idx)
{
  unsigned int s0201 = Sx0201[idx];
  unsigned int s01 = s0201 & 0xFF;
  unsigned int s03 = s01 ^ (s0201 >> 8);
  return (s0201 << 16) ^ (s01 << 8) ^ s03;
}

variable_types:
idx
unsigned char


decompiled_code:
__int64 __fastcall Te0123(int a1, int a2)
{
unsigned __int8 v2; // dh
unsigned __int8 v3; // bh
int v4; // esi
unsigned __int8 v5; // r10
int v6; // eax
int v7; // er8
int v8; // er9

v3 = v2;
Te0(HIBYTE(a1));
v4 = Te0(BYTE2(a2));
Te0(v3);
v6 = Te0(v5);
return __ROL4__(v6, 8) ^ v8 ^ (unsigned int)(__ROL4__(v7, 16) ^ __ROR4__(v4, 8));
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
unsigned __int8 v2; // dh
unsigned __int8 v3; // bh
int v4; // esi
unsigned __int8 v5; // r10
int v6; // eax
int v7; // er8
int v8; // er9

v3 = v2;
func9(HIBYTE(a1));
v4 = func9(BYTE2(a2));
func9(v3);
v6 = func9(v5);
return __ROL4__(v6, 8) ^ v8 ^ (unsigned int)(__ROL4__(v7, 16) ^ __ROR4__(v4, 8));
}


decompiled_code:
__int64 __fastcall Sx01(unsigned __int8 a1)
{
return LOBYTE(Sx0201[a1]);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 a1)
{
return LOBYTE(Sx0201[a1]);
}

original_code:
static uint32_t Sx01(uint32_t idx)
{
  return Sx0201[idx & 0xFF] & 0xFF;
}

canonical_original_code:
static unsigned int Sx01(unsigned int idx)
{
  return Sx0201[idx & 0xFF] & 0xFF;
}

variable_types:
idx
unsigned int


SxBytes

decompiled_code:
__int64 __fastcall SxBytes(int a1)
{
unsigned __int8 v1; // er8^2
unsigned __int8 v2; // r8^1
unsigned __int8 v3; // r8
int v4; // eax
int v5; // ecx
int v6; // edx

Sx01(HIBYTE(a1));
Sx01(v1);
Sx01(v2);
v4 = Sx01(v3);
return v4 | v6 | (unsigned int)(v5 << 8);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
unsigned __int8 v1; // er8^2
unsigned __int8 v2; // r8^1
unsigned __int8 v3; // r8
int v4; // eax
int v5; // ecx
int v6; // edx

func11(HIBYTE(a1));
func11(v1);
func11(v2);
v4 = func11(v3);
return v4 | v6 | (unsigned int)(v5 << 8);
}


canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
unsigned __int8 v1; // ch
unsigned __int8 v2; // cl
int v3; // esi
unsigned __int8 v4; // cl
int v5; // eax
int v6; // edx

func11(BYTE2(a1));
func11(v1);
v3 = func11(v2);
v5 = func11(v4);
return v5 | v6 | (unsigned int)(v3 << 8);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
size_t v4; // rax
unsigned int v5; // eax
char *v6; // rdi
__int64 v7; // rcx
__int64 v8; // rdx
int result; // eax
char v10; // [rsp+0h] [rbp-18h]

setlocale(6, "");
if ( argc <= 2 )
{
printf("Usage:%s option\n", *argv);
printf("for example:%s ip port \n", *argv);
result = -1;
}
else
{
v3 = argv[1];
v4 = strlen(v3);
if ( v4 > 0x100 )
{
terminal_print("IP length error\n", v10);
result = -2;
}
else
{
v5 = v4 + 1;
v6 = cp;
if ( v5 >= 8 )
{
v7 = v5 >> 3;
qmemcpy(cp, v3, 8 * v7);
v6 = &cp[8 * v7];
v3 += 8 * v7;
}
v8 = 0LL;
if ( (v5 & 4) != 0 )
{
*(_DWORD *)v6 = *(_DWORD *)v3;
v8 = 4LL;
}
if ( (v5 & 2) != 0 )
{
*(_WORD *)&v6[v8] = *(_WORD *)&v3[v8];
v8 += 2LL;
}
if ( (v5 & 1) != 0 )
v6[v8] = v3[v8];
port = atoi(argv[2]);
result = ((int)main_loop() >> 31) & 0xFFFFFFFD;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
size_t v4; // rax
unsigned int v5; // eax
char *v6; // rdi
__int64 v7; // rcx
__int64 v8; // rdx
int result; // eax
char v10; // [rsp+0h] [rbp-18h]

setlocale(6, "");
if ( argc <= 2 )
{
printf("Usage:%s option\n", *argv);
printf("for example:%s ip port \n", *argv);
result = -1;
}
else
{
v3 = argv[1];
v4 = strlen(v3);
if ( v4 > 0x100 )
{
func8("IP length error\n", v10);
result = -2;
}
else
{
v5 = v4 + 1;
v6 = cp;
if ( v5 >= 8 )
{
v7 = v5 >> 3;
qmemcpy(cp, v3, 8 * v7);
v6 = &cp[8 * v7];
v3 += 8 * v7;
}
v8 = 0LL;
if ( (v5 & 4) != 0 )
{
*(_DWORD *)v6 = *(_DWORD *)v3;
v8 = 4LL;
}
if ( (v5 & 2) != 0 )
{
*(_WORD *)&v6[v8] = *(_WORD *)&v3[v8];
v8 += 2LL;
}
if ( (v5 & 1) != 0 )
v6[v8] = v3[v8];
port = atoi(argv[2]);
result = ((int)func20() >> 31) & 0xFFFFFFFD;
}
}
return result;
}

original_code:
int main(int argc, char* argv[])
{
 setlocale(6,"");
 int ret = -1;
 if(argc<3){
  printf("Usage:%s option\n",argv[0]);
  printf("for example:%s ip port \n",argv[0]);
  return -1;
 }
 if(strlen(argv[1]) > sizeof(ip)){
  terminal_print("IP length error\n");
  return -2;
 }
 strcpy(ip, argv[1]);
 port = atoi(argv[2]);
 ret = main_loop();
 if(ret < 0){
  return -3;
 }
 if(ret == 0){
  return 0;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 setlocale(6,"");
 int ret = -1;
 if(argc<3){
  printf("Usage:%s option\n",argv[0]);
  printf("for example:%s ip port \n",argv[0]);
  return -1;
 }
 if(strlen(argv[1]) > sizeof(ip)){
  terminal_print("IP length error\n");
  return -2;
 }
 strcpy(ip, argv[1]);
 port = atoi(argv[2]);
 ret = main_loop();
 if(ret < 0){
  return -3;
 }
 if(ret == 0){
  return 0;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int

return_type: int


decompiled_code:
int terminal_print(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-10D0h] BYREF
char s[16]; // [rsp+20h] [rbp-10B8h] BYREF
char v4[4080]; // [rsp+30h] [rbp-10A8h] BYREF

va_start(arg, format);
memset(v4, 0, sizeof(v4));
*(_OWORD *)s = 0LL;
vsnprintf(s, 0x1000uLL, format, arg);
return printf("%s", s);
}

canonical_decompiled_code:
int func8(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-10D0h] BYREF
char s[16]; // [rsp+20h] [rbp-10B8h] BYREF
char v4[4080]; // [rsp+30h] [rbp-10A8h] BYREF

va_start(arg, format);
memset(v4, 0, sizeof(v4));
*(_OWORD *)s = 0LL;
vsnprintf(s, 0x1000uLL, format, arg);
return printf("%s", s);
}

original_code:
int terminal_print(char* msg, ...)
{
 int ret = -1;
 va_list argp;
 char sTmp[4096] = {0};
 __builtin_va_start(argp,msg);
 vsnprintf(sTmp, 4096, msg, argp);
 __builtin_va_end(argp);
 ret = printf("%s",sTmp );
 return ret;
}

canonical_original_code:
int terminal_print(char *msg, ...)
{
 int ret = -1;
 __builtin_va_list argp;
 char sTmp[4096] = {0};
 __builtin_va_start(argp,msg);
 vsnprintf(sTmp, 4096, msg, argp);
 __builtin_va_end(argp);
 ret = printf("%s",sTmp );
 return ret;
}

variable_types:
msg
char *

variable_types:
sTmp
char [4096]


decompiled_code:
__int64 tcp_close()
{
__int64 result; // rax

if ( shutdown(sockfd, 2) < 0 )
{
terminal_print("shutdown error\n");
result = 0xFFFFFFFFLL;
}
else if ( close(sockfd) < 0 )
{
terminal_print("close fd error\n");
result = 4294967294LL;
}
else
{
result = 0LL;
}
return result;
}

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

if ( shutdown(sockfd, 2) < 0 )
{
func8("shutdown error\n");
result = 0xFFFFFFFFLL;
}
else if ( close(sockfd) < 0 )
{
func8("close fd error\n");
result = 4294967294LL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int tcp_close()
{
 int ret = -1;
 ret = shutdown(sockfd, SHUT_RDWR );
 if(ret < 0){
  terminal_print("shutdown error\n");
  return -1;
 }
 ret = close(sockfd);
 if(ret < 0){
  terminal_print("close fd error\n");
  return -2;
 }
 return 0;
}


decompiled_code:
ssize_t __fastcall Socket_Read(int a1, void *a2, int a3)
{
return recv(a1, a2, a3, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func10(int a1, void *a2, int a3)
{
return recv(a1, a2, a3, 0);
}

original_code:
int Socket_Read(int nSock,char* pBuf,int nSize)
{
 int ret;
 ret = recv(nSock,pBuf,nSize,0);
 return ret;
}

canonical_original_code:
int Socket_Read(int nSock, char *pBuf, int nSize)
{
 int ret;
 ret = recv(nSock,pBuf,nSize,0);
 return ret;
}

variable_types: nSock int

variable_types:
pBuf
char *

variable_types: nSize int


decompiled_code:
ssize_t __fastcall Socket_Write(int a1, const void *a2, int a3)
{
return send(a1, a2, a3, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func11(int a1, const void *a2, int a3)
{
return send(a1, a2, a3, 0);
}

original_code:
int Socket_Write(int nSock,char* pBuf,int nSize)
{
 int ret;
 ret = send(nSock,pBuf,nSize,0);
 return ret;
}

canonical_original_code:
int Socket_Write(int nSock, char *pBuf, int nSize)
{
 int ret;
 ret = send(nSock,pBuf,nSize,0);
 return ret;
}


decompiled_code:
// attributes: thunk
int Socket_Create(int domain, int type, int protocol)
{
return socket(domain, type, protocol);
}

canonical_decompiled_code:
int func12(int domain, int type, int protocol)
{
return socket(domain, type, protocol);
}

original_code:
int Socket_Create(int af,int type,int protocol)
{
 int sock=0;
 sock=socket(af,type,protocol);
 if (sock == -1) return -1;
 return sock;
}

canonical_original_code:
int Socket_Create(int af, int type, int protocol)
{
 int sock = 0;
 sock=socket(af,type,protocol);
 if (sock == -1) return -1;
 return sock;
}

variable_types: af int

variable_types: type int

variable_types: protocol int

variable_types: sock int


unpackage

original_code:
int unpackage(char* buf, int len)
{
 QA_HEAD* head = (QA_HEAD*)buf;
 INFOR* p = (INFOR*)(buf + sizeof(QA_HEAD));
 if(head->package_id != 11){
  terminal_print("package_id error\n");
  return -1;
 }
 if(head->infor_num == 0){
  terminal_print("你要查询的信息不存在！\n");
  return 0;
 }
 if(len != (int)(sizeof(QA_HEAD) + head->infor_num * sizeof(INFOR)) || len != head->package_len){
  terminal_print("包长度错误\n");
  return -2;
 }
 int i;
 for(i = 0 ; i < head->infor_num ; i++){
  terminal_print("你要查询的信息如下:\n姓名：%s\n简拼：%s\n全拼：%s\n公司电话：%s\n私人电话：%s\n分机号：%s\nEmail：%s\n",
    p->myname,
    p->abbreviation,
    p->full,
    p->company,
    p->privation,
    p->extension,
    p->emall
    );
  p += sizeof(INFOR);
 };
 return 0;
}

canonical_original_code:
int unpackage(char *buf, int len)
{
 struct QA_HEAD *head = (QA_HEAD*)buf;
 struct Infor_Struct *p = (INFOR*)(buf + sizeof(QA_HEAD));
 if(head->package_id != 11){
  terminal_print("package_id error\n");
  return -1;
 }
 if(head->infor_num == 0){
  terminal_print("你要查询的信息不存在！\n");
  return 0;
 }
 if(len != (int)(sizeof(QA_HEAD) + head->infor_num * sizeof(INFOR)) || len != head->package_len){
  terminal_print("包长度错误\n");
  return -2;
 }
 int i;
 for(i = 0 ; i < head->infor_num ; i++){
  terminal_print("你要查询的信息如下:\n姓名：%s\n简拼：%s\n全拼：%s\n公司电话：%s\n私人电话：%s\n分机号：%s\nEmail：%s\n",
    p->myname,
    p->abbreviation,
    p->full,
    p->company,
    p->privation,
    p->extension,
    p->emall
    );
  p += sizeof(INFOR);
 };
 return 0;
}

variable_types:
buf
char *

variable_types: len int

variable_types: struct QA_HEAD { int package_len; int infor_num; int package_id; } *

variable_types: struct Infor_Struct { char myname[32]; char abbreviation[32]; char full[32]; char company[32]; char privation[32]; char extension[32]; char emall[32]; } *

variable_types: i int


decompiled_code:
__int64 __fastcall read_ser(_DWORD *a1, int a2)
{
int v2; // er12
int v3; // eax

v2 = 0;
while ( 1 )
{
v3 = Socket_Read(sockfd, (char *)a1 + v2, a2 - v2 - 1);
if ( v3 < 0 )
{
v2 = -1;
terminal_print(aSocket_0);
return (unsigned int)v2;
}
v2 += v3;
if ( v2 == 7 )
break;
if ( !v3 )
{
if ( v2 )
{
if ( v2 <= 11 )
{
v2 = -4;
terminal_print(aSocket_2);
}
else if ( *a1 != v2 )
{
v2 = -5;
terminal_print((char *)&byte_402084);
}
}
else
{
v2 = -3;
terminal_print("server end\n");
}
return (unsigned int)v2;
}
}
terminal_print(aSocket_1);
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, int a2)
{
int v2; // er12
int v3; // eax

v2 = 0;
while ( 1 )
{
v3 = func10(sockfd, (char *)a1 + v2, a2 - v2 - 1);
if ( v3 < 0 )
{
v2 = -1;
func8(aSocket_0);
return (unsigned int)v2;
}
v2 += v3;
if ( v2 == 7 )
break;
if ( !v3 )
{
if ( v2 )
{
if ( v2 <= 11 )
{
v2 = -4;
func8(aSocket_2);
}
else if ( *a1 != v2 )
{
v2 = -5;
func8((char *)&byte_402084);
}
}
else
{
v2 = -3;
func8("server end\n");
}
return (unsigned int)v2;
}
}
func8(aSocket_1);
return 4294967294LL;
}

original_code:
int read_ser(char* buf, int buf_len)
{
 int ret = -1;
 int len = 0;
 QA_HEAD*head = (QA_HEAD*) buf;
 do{
  ret = Socket_Read(sockfd, buf+len, buf_len - len - 1);
  if( ret < 0 ) {
   terminal_print("socket读错误\n");
   return -1;
  }
  len += ret;
  if ( len == sizeof(buf) - 1)
  {
   terminal_print("socket返回包太长\n");
   return -2;
  }
 }while( ret != 0 );
 if(len == 0){
  terminal_print("server end\n");
  return -3;
 }
 if(len < (int)sizeof(QA_HEAD)){
  terminal_print("socket返回包太短\n");
  return -4;
 }
 if(len != head->package_len) {
  terminal_print("返回包长度错误\n");
  return -5;
 }
 return len;
}

canonical_original_code:
int read_ser(char *buf, int buf_len)
{
 int ret = -1;
 int len = 0;
 struct QA_HEAD *head = (QA_HEAD*) buf;
 do{
  ret = Socket_Read(sockfd, buf+len, buf_len - len - 1);
  if( ret < 0 ) {
   terminal_print("socket读错误\n");
   return -1;
  }
  len += ret;
  if ( len == sizeof(buf) - 1)
  {
   terminal_print("socket返回包太长\n");
   return -2;
  }
 }while( ret != 0 );
 if(len == 0){
  terminal_print("server end\n");
  return -3;
 }
 if(len < (int)sizeof(QA_HEAD)){
  terminal_print("socket返回包太短\n");
  return -4;
 }
 if(len != head->package_len) {
  terminal_print("返回包长度错误\n");
  return -5;
 }
 return len;
}

user_defined_types: struct QA_HEAD { int package_len; int infor_num; int package_id; }


decompiled_code:
__int64 __fastcall write_ser(__int64 a1, int a2)
{
unsigned int v2; // er12
int v3; // eax

if ( a1 )
{
if ( a2 == 72 )
{
v2 = 0;
while ( 1 )
{
v3 = Socket_Write(sockfd, (const void *)(a1 + (int)v2), 72 - v2);
if ( v3 < 0 )
break;
if ( v3 != 72 )
{
v2 += v3;
if ( v2 != 72 )
continue;
}
return v2;
}
v2 = -3;
terminal_print("write_ser write error\n");
}
else
{
v2 = -2;
terminal_print("write_ser buf_len error\n");
}
}
else
{
v2 = -1;
terminal_print("write_ser buf is NULL\n");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, int a2)
{
unsigned int v2; // er12
int v3; // eax

if ( a1 )
{
if ( a2 == 72 )
{
v2 = 0;
while ( 1 )
{
v3 = func11(sockfd, (const void *)(a1 + (int)v2), 72 - v2);
if ( v3 < 0 )
break;
if ( v3 != 72 )
{
v2 += v3;
if ( v2 != 72 )
continue;
}
return v2;
}
v2 = -3;
func8("write_ser write error\n");
}
else
{
v2 = -2;
func8("write_ser buf_len error\n");
}
}
else
{
v2 = -1;
func8("write_ser buf is NULL\n");
}
return v2;
}

original_code:
int write_ser(char* buf, int buf_len)
{
 int len = 0;
 if(buf == ((void *)0)){
  terminal_print("write_ser buf is NULL\n");
  return -1;
 }
 if(buf_len != 64 + sizeof(QR_HEAD)){
  terminal_print("write_ser buf_len error\n");
  return -2;
 }
 while(1) {
  int ret = -1;
  ret = Socket_Write(sockfd, buf + len, buf_len - len);
  if(ret < 0) {
   terminal_print("write_ser write error\n");
   return -3;
  }
  if(ret == buf_len) {
   break;
  }
  len += ret;
  if(len == buf_len) {
   break;
  }
 }
 return len ;
}

canonical_original_code:
int write_ser(char *buf, int buf_len)
{
 int len = 0;
 if(buf == ((void *)0)){
  terminal_print("write_ser buf is NULL\n");
  return -1;
 }
 if(buf_len != 64 + sizeof(QR_HEAD)){
  terminal_print("write_ser buf_len error\n");
  return -2;
 }
 while(1) {
  int ret = -1;
  ret = Socket_Write(sockfd, buf + len, buf_len - len);
  if(ret < 0) {
   terminal_print("write_ser write error\n");
   return -3;
  }
  if(ret == buf_len) {
   break;
  }
  len += ret;
  if(len == buf_len) {
   break;
  }
 }
 return len ;
}


decompiled_code:
__int64 __fastcall build_package(_QWORD *a1, int a2)
{
__int64 result; // rax

if ( a1 )
{
if ( a2 == 72 )
{
*a1 = 0xA00000048LL;
result = 0LL;
}
else
{
terminal_print("build_pack buf_len error\n");
result = 4294967294LL;
}
}
else
{
terminal_print("build_package buf is NULL\n");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(_QWORD *a1, int a2)
{
__int64 result; // rax

if ( a1 )
{
if ( a2 == 72 )
{
*a1 = 0xA00000048LL;
result = 0LL;
}
else
{
func8("build_pack buf_len error\n");
result = 4294967294LL;
}
}
else
{
func8("build_package buf is NULL\n");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int build_package(char* buf, int buf_len)
{
 if(buf == ((void *)0)){
  terminal_print("build_package buf is NULL\n");
  return -1;
 }
 if(buf_len != 64 + sizeof(QR_HEAD)) {
  terminal_print("build_pack buf_len error\n");
  return -2;
 }
 QR_PACK* pack = (QR_PACK*)buf;
 pack->package_len = sizeof(QR_PACK);
 pack->package_id = 10;
 return 0;
}

canonical_original_code:
int build_package(char *buf, int buf_len)
{
 if(buf == ((void *)0)){
  terminal_print("build_package buf is NULL\n");
  return -1;
 }
 if(buf_len != 64 + sizeof(QR_HEAD)) {
  terminal_print("build_pack buf_len error\n");
  return -2;
 }
 struct QR_PACK *pack = (QR_PACK*)buf;
 pack->package_len = sizeof(QR_PACK);
 pack->package_id = 10;
 return 0;
}

variable_types: struct QR_PACK { int package_len; int package_id; char body[64]; } *


decompiled_code:
__int64 __fastcall read_stdin(const char *a1)
{
bool v1; // cf
bool v2; // zf
const char *v4; // rdi
__int64 v5; // rcx
unsigned int v6; // er12

terminal_print((char *)&byte_402260);
terminal_print("input message:");
fflush(stdout);
fflush(stdin);
__isoc99_scanf();
v4 = "quit";
v5 = 4LL;
do
{
if ( !v5 )
break;
v1 = *a1 < (unsigned int)*v4;
v2 = *a1++ == *v4++;
--v5;
}
while ( v2 );
v6 = (char)((!v1 && !v2) - v1);
if ( (!v1 && !v2) == v1 )
{
terminal_print(aQuit_0, a1);
}
else
{
v6 = -1;
fflush(stdout);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1)
{
bool v1; // cf
bool v2; // zf
const char *v4; // rdi
__int64 v5; // rcx
unsigned int v6; // er12

func8((char *)&byte_402260);
func8("input message:");
fflush(stdout);
fflush(stdin);
__isoc99_scanf();
v4 = "quit";
v5 = 4LL;
do
{
if ( !v5 )
break;
v1 = *a1 < (unsigned int)*v4;
v2 = *a1++ == *v4++;
--v5;
}
while ( v2 );
v6 = (char)((!v1 && !v2) - v1);
if ( (!v1 && !v2) == v1 )
{
func8(aQuit_0, a1);
}
else
{
v6 = -1;
fflush(stdout);
}
return v6;
}

original_code:
int read_stdin(char*data, int len)
{
 int ret = -1;
 terminal_print("查找支持：中文名、简拼、全拼、公司手机号、私人号码、分机号、邮箱！\n退出系统请输入：quit\n");
 terminal_print("input message:");
 fflush(stdout);
 fflush(stdin);
 scanf("%63s", data);
 if(strncmp(data, "quit", sizeof("quit")-1)==0){
  terminal_print("quit 退出命令\n");
  return 0;
 }
 fflush(stdout);
 return ret;
}

canonical_original_code:
int read_stdin(char *data, int len)
{
 int ret = -1;
 terminal_print("查找支持：中文名、简拼、全拼、公司手机号、私人号码、分机号、邮箱！\n退出系统请输入：quit\n");
 terminal_print("input message:");
 fflush(stdout);
 fflush(stdin);
 scanf("%63s", data);
 if(strncmp(data, "quit", sizeof("quit")-1)==0){
  terminal_print("quit 退出命令\n");
  return 0;
 }
 fflush(stdout);
 return ret;
}

variable_types:
data
char *


decompiled_code:
__int64 __fastcall read_input(const char *a1)
{
__int64 result; // rax

result = read_stdin(a1);
if ( (int)result < 0 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(const char *a1)
{
__int64 result; // rax

result = func17(a1);
if ( (int)result < 0 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int read_input(char* buf, int buf_size)
{
 int ret = -1;
 ret = read_stdin(buf, buf_size);
 if(ret < 0){
  return -1;
 }
 return ret;
}

canonical_original_code:
int read_input(char *buf, int buf_size)
{
 int ret = -1;
 ret = read_stdin(buf, buf_size);
 if(ret < 0){
  return -1;
 }
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 tcp_init()
{
__int64 result; // rax
struct sockaddr v1; // [rsp+0h] [rbp-18h] BYREF

sockfd = Socket_Create(2, 1, 0);
if ( sockfd < -1 )
{
terminal_print("socket error\n");
result = 0xFFFFFFFFLL;
}
else
{
v1 = 0LL;
v1.sa_family = 2;
*(_WORD *)v1.sa_data = _bswap_16(port);
*(_DWORD *)&v1.sa_data[2] = inet_addr(cp);
if ( connect(sockfd, &v1, 0x10u) < 0 )
{
terminal_print("connect error\n");
result = 4294967294LL;
}
else
{
terminal_print((char *)&byte_402160);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func19()
{
__int64 result; // rax
struct sockaddr v1; // [rsp+0h] [rbp-18h] BYREF

sockfd = func12(2, 1, 0);
if ( sockfd < -1 )
{
func8("socket error\n");
result = 0xFFFFFFFFLL;
}
else
{
v1 = 0LL;
v1.sa_family = 2;
*(_WORD *)v1.sa_data = func7(port);
*(_DWORD *)&v1.sa_data[2] = inet_addr(cp);
if ( connect(sockfd, &v1, 0x10u) < 0 )
{
func8("connect error\n");
result = 4294967294LL;
}
else
{
func8((char *)&byte_402160);
result = 0LL;
}
}
return result;
}

original_code:
int tcp_init()
{
 int ret = -1;
 sockfd = Socket_Create(2, SOCK_STREAM, 0);
 if (sockfd < -1){
  terminal_print("socket error\n");
  return -1;
 }
 struct sockaddr_in seraddr;
 memset (&seraddr, 0, sizeof(seraddr));
 seraddr.sin_family = 2;
 seraddr.sin_port = htons(port);
 seraddr.sin_addr.s_addr=inet_addr(ip);
 ret = connect(sockfd, (struct sockaddr*)&seraddr, sizeof(seraddr));
 if(ret < 0){
  terminal_print("connect error\n");
  return -2;
 }
 terminal_print("与服务器连接成功！\n");
 return 0;
}

canonical_original_code:
int tcp_init()
{
 int ret = -1;
 sockfd = Socket_Create(2, SOCK_STREAM, 0);
 if (sockfd < -1){
  terminal_print("socket error\n");
  return -1;
 }
 struct sockaddr_in seraddr;
 memset (&seraddr, 0, sizeof(seraddr));
 seraddr.sin_family = 2;
 seraddr.sin_port = htons(port);
 seraddr.sin_addr.s_addr=inet_addr(ip);
 ret = connect(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));
 if(ret < 0){
  terminal_print("connect error\n");
  return -2;
 }
 terminal_print("与服务器连接成功！\n");
 return 0;
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


original_code:
int main_loop()
{
 char w_buf[sizeof(QR_PACK)] = {0};
 char r_buf[4097] = {0};
 while(1){
  int len = 0 ;
  int ret = -1 ;
  ret = tcp_init();
  if(ret < 0){
   tcp_close();
   return -1;
  }
  ret = read_input(w_buf + sizeof(QR_HEAD), 64);
  if(ret < 0){
   return -2;
  }
  if(ret == 0){
   return 0;
  }
  ret = build_package(w_buf, sizeof(w_buf));
  if(ret < 0){
   return -3;
  }
  ret = write_ser(w_buf, sizeof(w_buf));
  if(ret < 0){
   return -4;
  }
  len = read_ser(r_buf, sizeof(r_buf));
  if(len < 0){
   return -5;
  }
  ret = unpackage(r_buf, len);
  if(ret < 0){
   return -6;
  }
  ret = tcp_close();
  if(ret < 0){
   return -7;
  }
  memset(w_buf, 0, sizeof(w_buf));
  memset(r_buf, 0, sizeof(r_buf));
 }
 return 0;
}

canonical_original_code:
int main_loop()
{
 char w_buf[-1] = {0};
 char r_buf[4097] = {0};
 while(1){
  int len = 0;
  int ret = -1;
  ret = tcp_init();
  if(ret < 0){
   tcp_close();
   return -1;
  }
  ret = read_input(w_buf + sizeof(QR_HEAD), 64);
  if(ret < 0){
   return -2;
  }
  if(ret == 0){
   return 0;
  }
  ret = build_package(w_buf, sizeof(w_buf));
  if(ret < 0){
   return -3;
  }
  ret = write_ser(w_buf, sizeof(w_buf));
  if(ret < 0){
   return -4;
  }
  len = read_ser(r_buf, sizeof(r_buf));
  if(len < 0){
   return -5;
  }
  ret = unpackage(r_buf, len);
  if(ret < 0){
   return -6;
  }
  ret = tcp_close();
  if(ret < 0){
   return -7;
  }
  memset(w_buf, 0, sizeof(w_buf));
  memset(r_buf, 0, sizeof(r_buf));
 }
 return 0;
}


repo: IllegalLeft/Kyzoku

decompiled_code:
__int64 __fastcall limit_vel(int *a1, int *a2, int a3)
{
int v3; // ecx
int v4; // eax
int v5; // ecx
int v6; // edx
int v7; // eax
unsigned int v8; // edx
__int64 result; // rax

v3 = *a1;
if ( *a1 > a3 )
{
*a1 = a3;
v3 = a3;
}
v4 = -a3;
if ( -a3 > v3 )
*a1 = v4;
v5 = *a2;
if ( *a2 > a3 )
{
*a2 = a3;
v5 = a3;
}
if ( v4 > v5 )
*a2 = v4;
v6 = player[3];
v7 = v6 + player[5];
if ( v7 > 612 )
{
player[5] = 0;
v7 = v6;
}
if ( v7 < 0 )
player[5] = 0;
v8 = player[4];
result = v8 + player[6];
if ( (int)result > 595 )
{
player[6] = 0;
result = v8;
}
if ( (int)result <= 31 )
player[6] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int *a2, int a3)
{
int v3; // ecx
int v4; // eax
int v5; // ecx
int v6; // edx
int v7; // eax
unsigned int v8; // edx
__int64 result; // rax

v3 = *a1;
if ( *a1 > a3 )
{
*a1 = a3;
v3 = a3;
}
v4 = -a3;
if ( -a3 > v3 )
*a1 = v4;
v5 = *a2;
if ( *a2 > a3 )
{
*a2 = a3;
v5 = a3;
}
if ( v4 > v5 )
*a2 = v4;
v6 = player[3];
v7 = v6 + player[5];
if ( v7 > 612 )
{
player[5] = 0;
v7 = v6;
}
if ( v7 < 0 )
player[5] = 0;
v8 = player[4];
result = v8 + player[6];
if ( (int)result > 595 )
{
player[6] = 0;
result = v8;
}
if ( (int)result <= 31 )
player[6] = 0;
return result;
}

original_code:
void limit_vel(int* vel_x, int* vel_y, int limit)
{
    if (*vel_x > limit)
        *vel_x = limit;
    if (*vel_x < -limit)
        *vel_x = -limit;
    if (*vel_y > limit)
        *vel_y = limit;
    if (*vel_y < -limit)
        *vel_y = -limit;
    if((player.x + player.vel_x) > (20 * 32 - 28))
        player.vel_x = 0;
    if((player.x + player.vel_x) < 0)
        player.vel_x = 0;
    if((player.y + player.vel_y) > (20 * 32 - 32 - 13))
        player.vel_y = 0;
    if((player.y + player.vel_y) < 32)
        player.vel_y = 0;
}

canonical_original_code:
void limit_vel(int *vel_x, int *vel_y, int limit)
{
    if (*vel_x > limit)
        *vel_x = limit;
    if (*vel_x < -limit)
        *vel_x = -limit;
    if (*vel_y > limit)
        *vel_y = limit;
    if (*vel_y < -limit)
        *vel_y = -limit;
    if((player.x + player.vel_x) > (20 * 32 - 28))
        player.vel_x = 0;
    if((player.x + player.vel_x) < 0)
        player.vel_x = 0;
    if((player.y + player.vel_y) > (20 * 32 - 32 - 13))
        player.vel_y = 0;
    if((player.y + player.vel_y) < 32)
        player.vel_y = 0;
}

variable_types: limit int


decompiled_code:
__int64 __fastcall get_collision(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
{
int v8; // eax
int v9; // edx
int v10; // eax
int v11; // edx
int v12; // eax

v9 = a1 + a3;
LOBYTE(v8) = v9 <= a5;
LOBYTE(v9) = a1 >= a7 + a5;
v10 = v9 | v8;
v11 = a6 + a8;
LOBYTE(v11) = a2 >= a6 + a8;
v12 = v11 | v10;
LOBYTE(v11) = a4 + a2 <= a6;
return (v11 | v12) ^ 1u;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
{
int v8; // eax
int v9; // edx
int v10; // eax
int v11; // edx
int v12; // eax

v9 = a1 + a3;
LOBYTE(v8) = v9 <= a5;
LOBYTE(v9) = a1 >= a7 + a5;
v10 = v9 | v8;
v11 = a6 + a8;
LOBYTE(v11) = a2 >= a6 + a8;
v12 = v11 | v10;
LOBYTE(v11) = a4 + a2 <= a6;
return (v11 | v12) ^ 1u;
}

original_code:
_Bool get_collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
{
    int top1, bottom1, right1, left1;
    int top2, bottom2, right2, left2;
    top1 = y1;
    bottom1 = y1 + h1;
    left1 = x1;
    right1 = x1 + w1;
    top2 = y2;
    bottom2 = y2 + h2;
    left2 = x2;
    right2 = x2 + w2;
    if (bottom1 <= top2)
        return 0;
    if (top1 >= bottom2)
        return 0;
    if (right1 <= left2)
        return 0;
    if (left1 >= right2)
        return 0;
    return 1;
}

canonical_original_code:
_Bool get_collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
{
    int top1; int bottom1; int right1; int left1;
    int top2; int bottom2; int right2; int left2;
    top1 = y1;
    bottom1 = y1 + h1;
    left1 = x1;
    right1 = x1 + w1;
    top2 = y2;
    bottom2 = y2 + h2;
    left2 = x2;
    right2 = x2 + w2;
    if (bottom1 <= top2)
        return 0;
    if (top1 >= bottom2)
        return 0;
    if (right1 <= left2)
        return 0;
    if (left1 >= right2)
        return 0;
    return 1;
}


decompiled_code:
unsigned __int64 player_shoot()
{
unsigned __int64 v0; // rdx
unsigned __int64 result; // rax

v0 = (unsigned int)((_DWORD)&bullet + 36);
LODWORD(result) = 0;
while ( *(_BYTE *)v0 )
{
result = (unsigned int)(result + 1);
v0 += 40LL;
if ( (_DWORD)result == 30 )
return result;
}
result = (unsigned __int64)&bullet + 40 * (int)result;
*(_BYTE *)(result + 36) = 1;
*(_QWORD *)(result + 24) = 6LL;
return result;
}

canonical_decompiled_code:
unsigned __int64 func4()
{
unsigned __int64 v0; // rdx
unsigned __int64 result; // rax

v0 = (unsigned int)((_DWORD)&bullet + 36);
LODWORD(result) = 0;
while ( *(_BYTE *)v0 )
{
result = (unsigned int)(result + 1);
v0 += 40LL;
if ( (_DWORD)result == 30 )
return result;
}
result = (unsigned __int64)&bullet + 40 * (int)result;
*(_BYTE *)(result + 36) = 1;
*(_QWORD *)(result + 24) = 6LL;
return result;
}

original_code:
void player_shoot()
{
    int next = -1;
    int i;
    for (i = 0; i < 30; i++)
    {
        if (bullet[i].shot == 0)
        {
            next = i;
            break;
        }
    }
    if (!(next < 0) )
    {
        bullet[next].shot = 1;
        bullet[next].vel_x = 6;
        bullet[next].vel_y = 0;
    }
}

variable_types: next int


decompiled_code:
unsigned __int64 player_shootsub()
{
unsigned __int64 v0; // rdx
int v1; // eax
int v2; // ecx
__int64 v3; // rsi
unsigned __int64 result; // rax
char *v5; // rax
char *v6; // rax
__int64 v7; // [rsp+0h] [rbp-20h]
int v8; // [rsp+8h] [rbp-18h]

v7 = -1LL;
v0 = (unsigned int)((_DWORD)&bullet + 36);
v1 = 0;
v2 = -1;
v8 = -1;
do
{
if ( !*(_BYTE *)v0 )
{
v3 = v2++;
*((_DWORD *)&v7 + v3) = v1;
if ( v2 > 5 )
break;
}
++v1;
v0 += 40LL;
}
while ( v1 != 30 );
result = (unsigned int)player[12];
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
{
v5 = (char *)&bullet + 40 * (int)v7;
v5[36] = 1;
*((_QWORD *)v5 + 3) = 6LL;
v6 = (char *)&bullet + 40 * SHIDWORD(v7);
*((_QWORD *)v6 + 3) = 0x200000005LL;
v6[36] = 1;
result = (unsigned __int64)&bullet + 40 * v8;
*(_BYTE *)(result + 36) = 1;
*(_QWORD *)(result + 24) = 0xFFFFFFFE00000005LL;
}
}
else
{
result = (unsigned __int64)&bullet + 40 * (int)v7;
*(_BYTE *)(result + 36) = 1;
*(_QWORD *)(result + 24) = 14LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func5()
{
unsigned __int64 v0; // rdx
int v1; // eax
int v2; // ecx
__int64 v3; // rsi
unsigned __int64 result; // rax
char *v5; // rax
char *v6; // rax
__int64 v7; // [rsp+0h] [rbp-20h]
int v8; // [rsp+8h] [rbp-18h]

v7 = -1LL;
v0 = (unsigned int)((_DWORD)&bullet + 36);
v1 = 0;
v2 = -1;
v8 = -1;
do
{
if ( !*(_BYTE *)v0 )
{
v3 = v2++;
*((_DWORD *)&v7 + v3) = v1;
if ( v2 > 5 )
break;
}
++v1;
v0 += 40LL;
}
while ( v1 != 30 );
result = (unsigned int)player[12];
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
{
v5 = (char *)&bullet + 40 * (int)v7;
v5[36] = 1;
*((_QWORD *)v5 + 3) = 6LL;
v6 = (char *)&bullet + 40 * SHIDWORD(v7);
*((_QWORD *)v6 + 3) = 0x200000005LL;
v6[36] = 1;
result = (unsigned __int64)&bullet + 40 * v8;
*(_BYTE *)(result + 36) = 1;
*(_QWORD *)(result + 24) = 0xFFFFFFFE00000005LL;
}
}
else
{
result = (unsigned __int64)&bullet + 40 * (int)v7;
*(_BYTE *)(result + 36) = 1;
*(_QWORD *)(result + 24) = 14LL;
}
return result;
}

original_code:
void player_shootsub()
{
    int next = -1;
    int freebullets[5] = {-1, -1, -1, -1, -1};
    for (int i = 0; i < 30; i++)
    {
        if (bullet[i].shot == 0)
        {
            freebullets[next] = i;
            next++;
            if (next > 5)
                break;
        }
    }
    switch (player.subweapon)
    {
        case 0:
            bullet[freebullets[0]].shot = 1;
            bullet[freebullets[0]].vel_x = 14;
            bullet[freebullets[0]].vel_y = 0;
            break;
        case 1:
            bullet[freebullets[0]].shot = 1;
            bullet[freebullets[0]].vel_x = 6;
            bullet[freebullets[0]].vel_y = 0;
            bullet[freebullets[1]].shot = 1;
            bullet[freebullets[1]].vel_x = 5;
            bullet[freebullets[1]].vel_y = 2;
            bullet[freebullets[2]].shot = 1;
            bullet[freebullets[2]].vel_x = 5;
            bullet[freebullets[2]].vel_y = -2;
            break;
        default:
            break;
    }
}

variable_types:
freebullets
int [5]


decompiled_code:
__int64 reset_bullets()
{
__int64 result; // rax

result = (unsigned int)((_DWORD)&bullet + 16);
do
{
if ( *(int *)result > 640 )
*(_BYTE *)(result + 20) = 0;
result += 40LL;
}
while ( (_UNKNOWN *)result != (_UNKNOWN *)((char *)&bullet + 1216) );
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax

result = (unsigned int)((_DWORD)&bullet + 16);
do
{
if ( *(int *)result > 640 )
*(_BYTE *)(result + 20) = 0;
result += 40LL;
}
while ( (_UNKNOWN *)result != (_UNKNOWN *)((char *)&bullet + 1216) );
return result;
}

original_code:
void reset_bullets()
{
    int i;
    for (i = 0; i < 30;i++)
    {
        if (bullet[i].x > 20 * 32)
            bullet[i].shot = 0;
    }
}


decompiled_code:
__int64 move_bullets()
{
__int64 v0; // rax
int v1; // edi

v0 = (unsigned int)((_DWORD)&bullet + 16);
do
{
while ( !*(_BYTE *)(v0 + 20) )
{
*(_DWORD *)v0 = 0;
v0 += 40LL;
*(_DWORD *)(v0 - 36) = 0;
if ( (_UNKNOWN *)v0 == (_UNKNOWN *)((char *)&bullet + 1216) )
return reset_bullets();
}
if ( !*(_DWORD *)v0 && !*(_DWORD *)(v0 + 4) )
{
v1 = player[4];
*(_DWORD *)v0 = player[3] + 20;
*(_DWORD *)(v0 + 4) = v1 + 15;
}
apply_vel((_DWORD *)v0, (_DWORD *)(v0 + 4), *(_DWORD *)(v0 + 8), *(_DWORD *)(v0 + 12));
}
while ( (_UNKNOWN *)v0 != (_UNKNOWN *)((char *)&bullet + 1216) );
return reset_bullets();
}

original_code:
void move_bullets()
{
    int i;
    for (i = 0; i < 30;i++)
    {
        if (bullet[i].shot == 1)
        {
            if ((bullet[i].x == 0) && (bullet[i].y == 0))
            {
                bullet[i].x = player.x + 32 - 12;
                bullet[i].y = player.y + (32/2) - 3/2;
            }
            apply_vel(&bullet[i].x, &bullet[i].y, bullet[i].vel_x, bullet[i].vel_y);
        }
        else
        {
            bullet[i].x = 0;
            bullet[i].y = 0;
        }
    }
    reset_bullets();
}


decompiled_code:
__int16 *init_enemies()
{
__int16 *result; // rax

result = &enemy;
do
{
*((_DWORD *)result + 1) = 0;
result += 20;
*((_DWORD *)result - 8) = 0;
*((_DWORD *)result - 7) = 0;
*((_DWORD *)result - 6) = 0;
*((_BYTE *)result - 12) = 0;
*((_DWORD *)result - 5) = 0;
*((_DWORD *)result - 4) = 0;
*(result - 20) = 0;
}
while ( result != &enemy + 400 );
return result;
}

canonical_decompiled_code:
__int16 *func8()
{
__int16 *result; // rax

result = &enemy;
do
{
*((_DWORD *)result + 1) = 0;
result += 20;
*((_DWORD *)result - 8) = 0;
*((_DWORD *)result - 7) = 0;
*((_DWORD *)result - 6) = 0;
*((_BYTE *)result - 12) = 0;
*((_DWORD *)result - 5) = 0;
*((_DWORD *)result - 4) = 0;
*(result - 20) = 0;
}
while ( result != &enemy + 400 );
return result;
}

original_code:
void init_enemies()
{
    int i;
    for(i = 0; i < 20; i++)
    {
        enemy[i].h = 0;
        enemy[i].w = 0;
        enemy[i].x = 0;
        enemy[i].y = 0;
        enemy[i].active = 0;
        enemy[i].vel_x = 0;
        enemy[i].vel_y = 0;
        enemy[i].tile = 0;
    }
}


decompiled_code:
__int64 enemy_move()
{
__int64 result; // rax

result = (unsigned int)((_DWORD)enemy + 12);
do
{
if ( *(_BYTE *)(result + 16) )
{
apply_vel((_DWORD *)result, (_DWORD *)(result + 4), *(_DWORD *)(result + 8), *(_DWORD *)(result + 12));
}
else
{
*(_DWORD *)result = 640;
*(_DWORD *)(result + 4) = 640;
}
if ( *(_DWORD *)result <= -*(_DWORD *)(result - 4) )
*(_BYTE *)(result + 16) = 0;
result += 40LL;
}
while ( (__int16 *)result != &enemy[406] );
return result;
}

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

result = (unsigned int)((_DWORD)enemy + 12);
do
{
if ( *(_BYTE *)(result + 16) )
{
func1((_DWORD *)result, (_DWORD *)(result + 4), *(_DWORD *)(result + 8), *(_DWORD *)(result + 12));
}
else
{
*(_DWORD *)result = 640;
*(_DWORD *)(result + 4) = 640;
}
if ( *(_DWORD *)result <= -*(_DWORD *)(result - 4) )
*(_BYTE *)(result + 16) = 0;
result += 40LL;
}
while ( (__int16 *)result != &enemy[406] );
return result;
}

original_code:
void enemy_move()
{
    int i;
    for (i = 0; i < 20; i++)
    {
        if (enemy[i].active == 1)
        {
            apply_vel(&enemy[i].x, &enemy[i].y, enemy[i].vel_x, enemy[i].vel_y);
        }
        else
        {
            enemy[i].x = 20 * 32;
            enemy[i].y = 20 * 32;
        }
        if (enemy[i].x <= (-enemy[i].w))
            enemy[i].active = 0;
    }
}


original_code:
int init_items()
{
    int i;
    for (i = 0; i < 20; i++)
    {
        item[i].x = 0;
        item[i].y = 0;
        item[i].active = 0;
        item[i].type = 0;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall item_spawn(__int16 a1, int a2, int a3)
{
int v4; // eax
unsigned __int64 v5; // rdx
__int64 v6; // rax

v4 = 0;
v5 = (unsigned int)((_DWORD)item + 8);
do
{
if ( !*(_BYTE *)v5 )
{
v6 = 3LL * v4;
item[v6 + 1] = a3;
item[v6] = a2;
LOBYTE(item[v6 + 2]) = 1;
HIWORD(item[v6 + 2]) = a1;
return 1LL;
}
++v4;
v5 += 12LL;
}
while ( v4 != 20 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int16 a1, int a2, int a3)
{
int v4; // eax
unsigned __int64 v5; // rdx
__int64 v6; // rax

v4 = 0;
v5 = (unsigned int)((_DWORD)item + 8);
do
{
if ( !*(_BYTE *)v5 )
{
v6 = 3LL * v4;
item[v6 + 1] = a3;
item[v6] = a2;
LOBYTE(item[v6 + 2]) = 1;
HIWORD(item[v6 + 2]) = a1;
return 1LL;
}
++v4;
v5 += 12LL;
}
while ( v4 != 20 );
return 0LL;
}

original_code:
int item_spawn(short type, int x, int y)
{
    int i;
    for (i = 0; i < 20; i++)
    {
        if (item[i].active == 0)
        {
            item[i].y = y;
            item[i].x = x;
            item[i].active = 1;
            item[i].type = type;
            return 1;
        }
    }
    return 0;
}

variable_types: type short

variable_types: x int

variable_types: y int


original_code:
_Bool check_collisions()
{
    _Bool collision;
    int enemyhb[2][2] = {
        {9, 3},
        {5, 9},
    };
    int i, j;
 for (j = 0; j < 20; j++)
 {
  if (enemy[j].active == 1)
        {
            collision = get_collision(player.x + 0, player.y + 10, player.w, player.h, enemy[j].x + enemyhb[enemy[j].type][0], enemy[j].y + enemyhb[enemy[j].type][1], enemy[j].w, enemy[j].h);
            if (collision == 1)
   {
                Mix_PlayChannelTimed(-1,snd_hit,0,-1);
    player.hp -= 10;
    if (player.hp <= 0)
                    return 1;
    player.score += enemy[j].value;
    enemy[j].active = 0;
    collision = 0;
   }
  }
 }
    for (j = 0; j < 20; j++)
    {
        if (enemy[j].active == 1)
        {
            for (i = 0; i < 30; i++)
            {
                if (bullet[i].shot == 1)
                {
                    collision = get_collision(enemy[j].x + enemyhb[enemy[j].type][0], enemy[j].y + enemyhb[enemy[j].type][1], enemy[j].w, enemy[j].h, bullet[i].x, bullet[i].y, bullet[i].w, bullet[i].h);
                    if (collision == 1)
                    {
                        Mix_PlayChannelTimed(-1,snd_hit,0,-1);
                        player.score += enemy[j].value;
                        enemy[j].active = 0;
                        if ((rand() % 10 + 1) < 2)
                            item_spawn(rand()%3, enemy[j].x+(enemy[j].w/2)-(15/2), enemy[j].y+(enemy[j].h/2)-(15/2));
                        if (bullet[i].vel_x != 14)
                            bullet[i].shot = 0;
                    }
                }
            }
        }
    }
    for (j = 0; j < 20; j++)
    {
        if (item[j].active == 1)
        {
            collision = get_collision(player.x + 0, player.y + 10, player.w, player.h, item[j].x, item[j].y, 15, 15);
            if (collision == 1)
            {
                item[j].active = 0;
                switch (item[j].type)
                {
                    case 0:
                        player.hp += 10;
                        if (player.hp > 100) player.hp = 100;
                        break;
                    case 1:
                        if (player.subweapon != 1)
                        {
                            player.subweapon = 1;
                            player.ammo = 0;
                        }
                        player.ammo += 10;
                        break;
                    case 2:
                        if (player.subweapon != 2)
                        {
                            player.subweapon = 0;
                            player.ammo = 0;
                        }
                        player.ammo += 10;
                        break;
                    default:
                        break;
                }
            }
        }
    }
    return 0;
}

canonical_original_code:
_Bool check_collisions()
{
    _Bool collision;
    int enemyhb[2][2] = {
        {9, 3},
        {5, 9},
    };
    int i; int j;
 for (j = 0; j < 20; j++)
 {
  if (enemy[j].active == 1)
        {
            collision = get_collision(player.x + 0, player.y + 10, player.w, player.h, enemy[j].x + enemyhb[enemy[j].type][0], enemy[j].y + enemyhb[enemy[j].type][1], enemy[j].w, enemy[j].h);
            if (collision == 1)
   {
                Mix_PlayChannelTimed(-1,snd_hit,0,-1);
    player.hp -= 10;
    if (player.hp <= 0)
                    return 1;
    player.score += enemy[j].value;
    enemy[j].active = 0;
    collision = 0;
   }
  }
 }
    for (j = 0; j < 20; j++)
    {
        if (enemy[j].active == 1)
        {
            for (i = 0; i < 30; i++)
            {
                if (bullet[i].shot == 1)
                {
                    collision = get_collision(enemy[j].x + enemyhb[enemy[j].type][0], enemy[j].y + enemyhb[enemy[j].type][1], enemy[j].w, enemy[j].h, bullet[i].x, bullet[i].y, bullet[i].w, bullet[i].h);
                    if (collision == 1)
                    {
                        Mix_PlayChannelTimed(-1,snd_hit,0,-1);
                        player.score += enemy[j].value;
                        enemy[j].active = 0;
                        if ((rand() % 10 + 1) < 2)
                            item_spawn(rand()%3, enemy[j].x+(enemy[j].w/2)-(15/2), enemy[j].y+(enemy[j].h/2)-(15/2));
                        if (bullet[i].vel_x != 14)
                            bullet[i].shot = 0;
                    }
                }
            }
        }
    }
    for (j = 0; j < 20; j++)
    {
        if (item[j].active == 1)
        {
            collision = get_collision(player.x + 0, player.y + 10, player.w, player.h, item[j].x, item[j].y, 15, 15);
            if (collision == 1)
            {
                item[j].active = 0;
                switch (item[j].type)
                {
                    case 0:
                        player.hp += 10;
                        if (player.hp > 100) player.hp = 100;
                        break;
                    case 1:
                        if (player.subweapon != 1)
                        {
                            player.subweapon = 1;
                            player.ammo = 0;
                        }
                        player.ammo += 10;
                        break;
                    case 2:
                        if (player.subweapon != 2)
                        {
                            player.subweapon = 0;
                            player.ammo = 0;
                        }
                        player.ammo += 10;
                        break;
                    default:
                        break;
                }
            }
        }
    }
    return 0;
}

variable_types:
enemyhb
int [2][2]

variable_types: j int


decompiled_code:
__int64 free_bullets()
{
char *v0; // rbx
__int64 v1; // rdi
__int64 result; // rax

v0 = (char *)•
do
{
v1 = *(_QWORD *)v0;
v0 += 40;
result = SDL_FreeSurface(v1);
}
while ( v0 != (char *)&bullet + 1200 );
return result;
}

canonical_decompiled_code:
__int64 func7()
{
char *v0; // rbx
__int64 v1; // rdi
__int64 result; // rax

v0 = (char *)•
do
{
v1 = *(_QWORD *)v0;
v0 += 40;
result = SDL_FreeSurface(v1);
}
while ( v0 != (char *)&bullet + 1200 );
return result;
}

original_code:
void free_bullets()
{
    int i;
    for (i = 0; i < 30; i++)
        SDL_FreeSurface(bullet[i].image);
}


repo: Infinidat/infinitrace

decompiled_code:
__int64 __fastcall hashmap_key_to_int(int *a1, _BYTE *a2)
{
int v2; // edx
_BYTE *v3; // rsi
int v4; // ecx
unsigned int v5; // eax
int v6; // edx

v2 = (char)*a2;
if ( *a2 )
{
v3 = a2 + 1;
v4 = 0;
v5 = 0;
do
{
v6 = v4 * v2;
++v4;
++v3;
v5 += v6;
v2 = (char)*(v3 - 1);
}
while ( v4 != 1024 && (_BYTE)v2 );
}
else
{
v5 = 0;
}
if ( *a1 <= 255 )
_assert_fail("m->table_size >= INITIAL_SIZE", "hashmap.c", 0x72u, "hashmap_key_to_int");
return v5 % *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, _BYTE *a2)
{
int v2; // edx
_BYTE *v3; // rsi
int v4; // ecx
unsigned int v5; // eax
int v6; // edx

v2 = (char)*a2;
if ( *a2 )
{
v3 = a2 + 1;
v4 = 0;
v5 = 0;
do
{
v6 = v4 * v2;
++v4;
++v3;
v5 += v6;
v2 = (char)*(v3 - 1);
}
while ( v4 != 1024 && (_BYTE)v2 );
}
else
{
v5 = 0;
}
if ( *a1 <= 255 )
_assert_fail("m->table_size >= INITIAL_SIZE", "hashmap.c", 0x72u, "hashmap_key_to_int");
return v5 % *a1;
}

original_code:
unsigned int hashmap_key_to_int(hashmap_map * m, const char* keystring){
   unsigned int key = 0;
   unsigned int i;
    for (i = 0 ; keystring[i] && i < 1024; i++)
        key += i * keystring[i] ;
    ((void) sizeof ((m->table_size >= (256)) ? 1 : 0), __extension__ ({ if (m->table_size >= (256)) ; else __assert_fail ("m->table_size >= INITIAL_SIZE", "hashmap.c", 114, __extension__ __PRETTY_FUNCTION__); }));
 return key % m->table_size;
}

canonical_original_code:
unsigned int hashmap_key_to_int(struct _hashmap_map *m, char *keystring){
   unsigned int key = 0;
   unsigned int i;
    for (i = 0 ; keystring[i] && i < 1024; i++)
        key += i * keystring[i] ;
    ((void) sizeof ((m->table_size >= (256)) ? 1 : 0), __extension__ ({ if (m->table_size >= (256)) ; else __assert_fail ("m->table_size >= INITIAL_SIZE", "hashmap.c", 114, __extension__ __PRETTY_FUNCTION__); }));
 return key % m->table_size;
}

variable_types: struct _hashmap_map { int table_size; int size; struct _hashmap_element { char *key; unsigned int int_key; int in_use; void *data; } *data; void **first_int; } *

variable_types:
keystring
char *

variable_types:
key
unsigned int

variable_types:
i
unsigned int

user_defined_types: struct _hashmap_map { int table_size; int size; struct _hashmap_element *data; void **first_int; }


original_code:
int hashmap_hash(map_t in, const char* key){
 int curr;
 int i;
 hashmap_map* m = (hashmap_map *) in;
 if(m->size >= (m->table_size/2)) return -2;
 curr = hashmap_key_to_int(m, key);
 for(i = 0; i< (8); i++){
  if(m->data[curr].in_use == 0)
   return curr;
  if(m->data[curr].in_use == 1 && (strcmp(m->data[curr].key,key)==0))
   return curr;
  curr = (curr + 1) % m->table_size;
 }
 return -2;
}

canonical_original_code:
int hashmap_hash(void *in, char *key){
 int curr;
 int i;
 struct _hashmap_map *m = (hashmap_map *) in;
 if(m->size >= (m->table_size/2)) return -2;
 curr = hashmap_key_to_int(m, key);
 for(i = 0; i< (8); i++){
  if(m->data[curr].in_use == 0)
   return curr;
  if(m->data[curr].in_use == 1 && (strcmp(m->data[curr].key,key)==0))
   return curr;
  curr = (curr + 1) % m->table_size;
 }
 return -2;
}

variable_types:
in
void *

variable_types:
key
char *

variable_types: curr int

variable_types: i int

user_defined_types: struct _hashmap_element { char *key; unsigned int int_key; int in_use; void *data; }


decompiled_code:
__int64 __fastcall hashmap_put(__int64 a1, char *a2, __int64 a3)
{
int v4; // eax
__int64 result; // rax
__int64 v6; // rax

v4 = hashmap_hash(a1, a2);
if ( v4 == -2 )
{
while ( 1 )
{
result = hashmap_rehash(a1);
if ( (_DWORD)result == -1 )
break;
v4 = hashmap_hash(a1, a2);
if ( v4 != -2 )
goto LABEL_6;
}
}
else
{
LABEL_6:
v6 = *(_QWORD *)(a1 + 8) + 24LL * v4;
*(_QWORD *)(v6 + 16) = a3;
*(_QWORD *)v6 = a2;
*(_DWORD *)(v6 + 12) = 1;
result = 0LL;
++*(_DWORD *)(a1 + 4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, __int64 a3)
{
int v4; // eax
__int64 result; // rax
__int64 v6; // rax

v4 = func1(a1, a2);
if ( v4 == -2 )
{
while ( 1 )
{
result = func3(a1);
if ( (_DWORD)result == -1 )
break;
v4 = func1(a1, a2);
if ( v4 != -2 )
goto LABEL_6;
}
}
else
{
LABEL_6:
v6 = *(_QWORD *)(a1 + 8) + 24LL * v4;
*(_QWORD *)(v6 + 16) = a3;
*(_QWORD *)v6 = a2;
*(_DWORD *)(v6 + 12) = 1;
result = 0LL;
++*(_DWORD *)(a1 + 4);
}
return result;
}

original_code:
int hashmap_put(map_t in, const char* key, any_t value){
 int i;
 hashmap_map* m;
 m = (hashmap_map *) in;
 i = hashmap_hash(in, key);
 while(i == -2){
  if (hashmap_rehash(in) == -1) {
   return -1;
  }
  i = hashmap_hash(in, key);
 }
 m->data[i].data = value;
 m->data[i].key = key;
 m->data[i].in_use = 1;
 m->size++;
 return 0;
}

canonical_original_code:
int hashmap_put(void *in, char *key, void *value){
 int i;
 struct _hashmap_map *m;
 m = (struct _hashmap_map *) in;
 i = hashmap_hash(in, key);
 while(i == -2){
  if (hashmap_rehash(in) == -1) {
   return -1;
  }
  i = hashmap_hash(in, key);
 }
 m->data[i].data = value;
 m->data[i].key = key;
 m->data[i].in_use = 1;
 m->size++;
 return 0;
}

variable_types:
value
void *


decompiled_code:
__int64 __fastcall hashmap_rehash(__int64 a1)
{
int v1; // er12
int v2; // ebx
void *v3; // rax
char *v4; // r13
char *v5; // rbx
__int64 v6; // r12
__int64 result; // rax

v1 = *(_DWORD *)a1;
v2 = 2 * *(_DWORD *)a1;
v3 = calloc(v2, 0x18uLL);
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = *(char **)(a1 + 8);
*(_DWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = v3;
*(_DWORD *)(a1 + 4) = 0;
if ( v1 <= 0 )
{
LABEL_7:
free(v4);
result = 0LL;
}
else
{
v5 = v4;
v6 = (__int64)&v4[24 * (v1 - 1) + 24];
while ( 1 )
{
if ( *((_DWORD *)v5 + 3) )
{
result = hashmap_put(a1, *(char **)v5, *((_QWORD *)v5 + 2));
if ( (_DWORD)result )
break;
}
v5 += 24;
if ( v5 == (char *)v6 )
goto LABEL_7;
}
}
return result;
}

original_code:
int hashmap_rehash(map_t in){
 int i;
 int old_size;
 hashmap_element* curr;
 hashmap_map *m = (hashmap_map *) in;
 hashmap_element* temp = (hashmap_element *)
  calloc(2 * m->table_size, sizeof(hashmap_element));
 if(!temp) return -1;
 curr = m->data;
 m->data = temp;
 old_size = m->table_size;
 m->table_size = 2 * m->table_size;
 m->size = 0;
 for(i = 0; i < old_size; i++){
        int status;
        if (curr[i].in_use == 0)
            continue;
  status = hashmap_put(m, curr[i].key, curr[i].data);
  if (status != 0)
   return status;
 }
 free(curr);
 return 0;
}

canonical_original_code:
int hashmap_rehash(void *in){
 int i;
 int old_size;
 struct _hashmap_element *curr;
 struct _hashmap_map *m = (hashmap_map *) in;
 struct _hashmap_element *temp = (hashmap_element *)
  calloc(2 * m->table_size, sizeof(hashmap_element));
 if(!temp) return -1;
 curr = m->data;
 m->data = temp;
 old_size = m->table_size;
 m->table_size = 2 * m->table_size;
 m->size = 0;
 for(i = 0; i < old_size; i++){
        int status;
        if (curr[i].in_use == 0)
            continue;
  status = hashmap_put(m, curr[i].key, curr[i].data);
  if (status != 0)
   return status;
 }
 free(curr);
 return 0;
}

variable_types: struct _hashmap_element { char *key; unsigned int int_key; int in_use; void *data; } *

variable_types: status int


decompiled_code:
int __fastcall hashmap_get(__int64 a1, char *a2, _QWORD *a3)
{
int v3; // er13
int v4; // eax
__int64 v5; // r12
int v6; // ebx
__int64 v7; // r15
int result; // eax

v3 = 8;
v4 = hashmap_key_to_int((int *)a1, a2);
v5 = *(_QWORD *)(a1 + 8);
v6 = v4;
do
{
v7 = v5 + 24LL * v6;
if ( *(_DWORD *)(v7 + 12) == 1 )
{
result = strcmp(*(const char **)v7, a2);
if ( !result )
{
*a3 = *(_QWORD *)(v7 + 16);
return result;
}
}
v6 = (v6 + 1) % *(_DWORD *)a1;
--v3;
}
while ( v3 );
*a3 = 0LL;
return -3;
}

original_code:
int hashmap_get(map_t in, const char* key, any_t *arg){
 int curr;
 int i;
 hashmap_map* m;
 m = (hashmap_map *) in;
 curr = hashmap_key_to_int(m, key);
 for(i = 0; i<(8); i++){
        int in_use = m->data[curr].in_use;
        if (in_use == 1){
            if (strcmp(m->data[curr].key,key)==0){
                *arg = (m->data[curr].data);
                return 0;
            }
  }
  curr = (curr + 1) % m->table_size;
 }
 *arg = ((void *)0);
 return -3;
}

canonical_original_code:
int hashmap_get(void *in, char *key, void **arg){
 int curr;
 int i;
 struct _hashmap_map *m;
 m = (struct _hashmap_map *) in;
 curr = hashmap_key_to_int(m, key);
 for(i = 0; i<(8); i++){
        int in_use = m->data[curr].in_use;
        if (in_use == 1){
            if (strcmp(m->data[curr].key,key)==0){
                *arg = (m->data[curr].data);
                return 0;
            }
  }
  curr = (curr + 1) % m->table_size;
 }
 *arg = ((void *)0);
 return -3;
}

variable_types:
arg
void **


decompiled_code:
__int64 __fastcall hashmap_int_key_to_int(int *a1, unsigned int a2)
{
if ( *a1 <= 255 )
_assert_fail("m->table_size >= INITIAL_SIZE", "hashmap.c", 0xFDu, "hashmap_int_key_to_int");
return a2 % *a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, unsigned int a2)
{
if ( *a1 <= 255 )
_assert_fail("m->table_size >= INITIAL_SIZE", "hashmap.c", 0xFDu, "hashmap_int_key_to_int");
return a2 % *a1;
}

original_code:
unsigned int hashmap_int_key_to_int(hashmap_map * m, unsigned int int_key) {
 ((void) sizeof ((m->table_size >= (256)) ? 1 : 0), __extension__ ({ if (m->table_size >= (256)) ; else __assert_fail ("m->table_size >= INITIAL_SIZE", "hashmap.c", 253, __extension__ __PRETTY_FUNCTION__); }));
 return int_key % m->table_size;
}

canonical_original_code:
unsigned int hashmap_int_key_to_int(struct _hashmap_map *m, unsigned int int_key) {
 ((void) sizeof ((m->table_size >= (256)) ? 1 : 0), __extension__ ({ if (m->table_size >= (256)) ; else __assert_fail ("m->table_size >= INITIAL_SIZE", "hashmap.c", 253, __extension__ __PRETTY_FUNCTION__); }));
 return int_key % m->table_size;
}


decompiled_code:
__int64 __fastcall hashmap_hash_int(__int64 a1, unsigned int a2)
{
unsigned int v4; // eax
unsigned int v5; // esi
unsigned int v6; // edx
int v7; // ecx
__int64 v8; // rdi
int v9; // eax

v4 = hashmap_int_key_to_int((int *)a1, a2);
v5 = *(_DWORD *)a1;
v6 = v4;
if ( *(_DWORD *)(a1 + 4) >= *(_DWORD *)a1 / 2 )
return 4294967294LL;
v7 = 8;
while ( 1 )
{
v8 = *(_QWORD *)(a1 + 8) + 24LL * v6;
v9 = *(_DWORD *)(v8 + 12);
if ( !v9 || v9 == 1 && *(_DWORD *)(v8 + 8) == a2 )
break;
v6 = (v6 + 1) % v5;
if ( !--v7 )
return 4294967294LL;
}
return v6;
}

original_code:
int hashmap_hash_int(map_t in, unsigned int int_key){
 int i;
 hashmap_map* m = (hashmap_map *) in;
    unsigned int curr = hashmap_int_key_to_int(m, int_key);
 if(m->size >= (m->table_size/2)) return -2;
 for(i = 0; i< (8); i++){
  if(m->data[curr].in_use == 0)
   return curr;
  if(m->data[curr].in_use == 1 && m->data[curr].int_key == int_key)
   return curr;
  curr = (curr + 1) % m->table_size;
 }
 return -2;
}

canonical_original_code:
int hashmap_hash_int(void *in, unsigned int int_key){
 int i;
 struct _hashmap_map *m = (hashmap_map *) in;
    unsigned int curr = hashmap_int_key_to_int(m, int_key);
 if(m->size >= (m->table_size/2)) return -2;
 for(i = 0; i< (8); i++){
  if(m->data[curr].in_use == 0)
   return curr;
  if(m->data[curr].in_use == 1 && m->data[curr].int_key == int_key)
   return curr;
  curr = (curr + 1) % m->table_size;
 }
 return -2;
}

variable_types:
curr
unsigned int


decompiled_code:
__int64 __fastcall hashmap_put_int(__int64 a1, unsigned int a2, __int64 a3)
{
_QWORD *v4; // rax
__int64 result; // rax
unsigned int v6; // er12
int v7; // eax
__int64 v8; // rax

if ( a2 > 0xFF )
{
v6 = hashmap_int_key_to_int((int *)a1, a2);
while ( 1 )
{
v7 = hashmap_hash_int(a1, v6);
if ( v7 != -2 )
break;
if ( (unsigned int)hashmap_rehash_int(a1) == -1 )
goto LABEL_9;
}
v8 = *(_QWORD *)(a1 + 8) + 24LL * v7;
*(_QWORD *)(v8 + 16) = a3;
*(_DWORD *)(v8 + 8) = a2;
*(_DWORD *)(v8 + 12) = 1;
result = 0LL;
++*(_DWORD *)(a1 + 4);
}
else
{
v4 = *(_QWORD **)(a1 + 16);
if ( v4 || (v4 = calloc(0x100uLL, 8uLL), (*(_QWORD *)(a1 + 16) = v4) != 0LL) )
{
v4[a2] = a3;
result = 0LL;
}
else
{
LABEL_9:
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, __int64 a3)
{
_QWORD *v4; // rax
__int64 result; // rax
unsigned int v6; // er12
int v7; // eax
__int64 v8; // rax

if ( a2 > 0xFF )
{
v6 = func5((int *)a1, a2);
while ( 1 )
{
v7 = func6(a1, v6);
if ( v7 != -2 )
break;
if ( (unsigned int)func8(a1) == -1 )
goto LABEL_9;
}
v8 = *(_QWORD *)(a1 + 8) + 24LL * v7;
*(_QWORD *)(v8 + 16) = a3;
*(_DWORD *)(v8 + 8) = a2;
*(_DWORD *)(v8 + 12) = 1;
result = 0LL;
++*(_DWORD *)(a1 + 4);
}
else
{
v4 = *(_QWORD **)(a1 + 16);
if ( v4 || (v4 = calloc(0x100uLL, 8uLL), (*(_QWORD *)(a1 + 16) = v4) != 0LL) )
{
v4[a2] = a3;
result = 0LL;
}
else
{
LABEL_9:
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int hashmap_put_int(map_t in, unsigned int int_key, any_t value){
 int i;
 hashmap_map* m;
 m = (hashmap_map *) in;
    if (int_key < 256) {
        if (m->first_int == ((void *)0)) {
            m->first_int = calloc(256, sizeof(any_t));
            if (((void *)0) == m->first_int)
             return -1;
        }
        m->first_int[int_key] = value ;
        return 0;
    }
    unsigned int curr = hashmap_int_key_to_int(m, int_key);
 i = hashmap_hash_int(in, curr);
 while(i == -2){
  if (hashmap_rehash_int(in) == -1) {
   return -1;
  }
  i = hashmap_hash_int(in, curr);
 }
 m->data[i].data = value;
 m->data[i].int_key = int_key;
 m->data[i].in_use = 1;
 m->size++;
 return 0;
}

canonical_original_code:
int hashmap_put_int(void *in, unsigned int int_key, void *value){
 int i;
 struct _hashmap_map *m;
 m = (struct _hashmap_map *) in;
    if (int_key < 256) {
        if (m->first_int == ((void *)0)) {
            m->first_int = calloc(256, sizeof(any_t));
            if (((void *)0) == m->first_int)
             return -1;
        }
        m->first_int[int_key] = value ;
        return 0;
    }
    unsigned int curr = hashmap_int_key_to_int(m, int_key);
 i = hashmap_hash_int(in, curr);
 while(i == -2){
  if (hashmap_rehash_int(in) == -1) {
   return -1;
  }
  i = hashmap_hash_int(in, curr);
 }
 m->data[i].data = value;
 m->data[i].int_key = int_key;
 m->data[i].in_use = 1;
 m->size++;
 return 0;
}


decompiled_code:
__int64 __fastcall hashmap_rehash_int(__int64 a1)
{
int v1; // er12
int v2; // ebx
void *v3; // rax
char *v4; // r13
char *v5; // rbx
__int64 v6; // r12
__int64 result; // rax

v1 = *(_DWORD *)a1;
v2 = 2 * *(_DWORD *)a1;
v3 = calloc(v2, 0x18uLL);
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = *(char **)(a1 + 8);
*(_DWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = v3;
*(_DWORD *)(a1 + 4) = 0;
if ( v1 <= 0 )
{
LABEL_7:
free(v4);
result = 0LL;
}
else
{
v5 = v4 + 8;
v6 = (__int64)&v4[24 * (v1 - 1) + 32];
while ( 1 )
{
if ( *((_DWORD *)v5 + 1) )
{
result = hashmap_put_int(a1, *(_DWORD *)v5, *((_QWORD *)v5 + 1));
if ( (_DWORD)result )
break;
}
v5 += 24;
if ( v5 == (char *)v6 )
goto LABEL_7;
}
}
return result;
}

original_code:
int hashmap_rehash_int(map_t in){
 int i;
 int old_size;
 hashmap_element* curr;
 hashmap_map *m = (hashmap_map *) in;
 hashmap_element* temp = (hashmap_element *)
  calloc(2 * m->table_size, sizeof(hashmap_element));
 if(!temp) return -1;
 curr = m->data;
 m->data = temp;
 old_size = m->table_size;
 m->table_size = 2 * m->table_size;
 m->size = 0;
 for(i = 0; i < old_size; i++){
        int status;
        if (curr[i].in_use == 0)
            continue;
  status = hashmap_put_int(m, curr[i].int_key, curr[i].data);
  if (status != 0)
   return status;
 }
 free(curr);
 return 0;
}

canonical_original_code:
int hashmap_rehash_int(void *in){
 int i;
 int old_size;
 struct _hashmap_element *curr;
 struct _hashmap_map *m = (hashmap_map *) in;
 struct _hashmap_element *temp = (hashmap_element *)
  calloc(2 * m->table_size, sizeof(hashmap_element));
 if(!temp) return -1;
 curr = m->data;
 m->data = temp;
 old_size = m->table_size;
 m->table_size = 2 * m->table_size;
 m->size = 0;
 for(i = 0; i < old_size; i++){
        int status;
        if (curr[i].in_use == 0)
            continue;
  status = hashmap_put_int(m, curr[i].int_key, curr[i].data);
  if (status != 0)
   return status;
 }
 free(curr);
 return 0;
}


decompiled_code:
__int64 __fastcall hashmap_get_int(__int64 a1, unsigned int a2, _QWORD *a3)
{
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax
unsigned int v7; // eax
int v8; // ecx
unsigned int v9; // edx
__int64 v10; // rax

if ( a2 > 0xFF )
{
v7 = hashmap_int_key_to_int((int *)a1, a2);
v8 = 8;
v9 = v7;
while ( 1 )
{
v10 = *(_QWORD *)(a1 + 8) + 24LL * v9;
if ( *(_DWORD *)(v10 + 12) == 1 && *(_DWORD *)(v10 + 8) == a2 )
break;
v9 = (v9 + 1) % *(_DWORD *)a1;
if ( !--v8 )
goto LABEL_4;
}
*a3 = *(_QWORD *)(v10 + 16);
result = 0LL;
}
else
{
v4 = *(_QWORD *)(a1 + 16);
if ( v4 )
{
v5 = *(_QWORD *)(v4 + 8LL * a2);
*a3 = v5;
result = v5 == 0 ? 0xFFFFFFFD : 0;
}
else
{
LABEL_4:
*a3 = 0LL;
result = 4294967293LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2, _QWORD *a3)
{
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax
unsigned int v7; // eax
int v8; // ecx
unsigned int v9; // edx
__int64 v10; // rax

if ( a2 > 0xFF )
{
v7 = func5((int *)a1, a2);
v8 = 8;
v9 = v7;
while ( 1 )
{
v10 = *(_QWORD *)(a1 + 8) + 24LL * v9;
if ( *(_DWORD *)(v10 + 12) == 1 && *(_DWORD *)(v10 + 8) == a2 )
break;
v9 = (v9 + 1) % *(_DWORD *)a1;
if ( !--v8 )
goto LABEL_4;
}
*a3 = *(_QWORD *)(v10 + 16);
result = 0LL;
}
else
{
v4 = *(_QWORD *)(a1 + 16);
if ( v4 )
{
v5 = *(_QWORD *)(v4 + 8LL * a2);
*a3 = v5;
result = v5 == 0 ? 0xFFFFFFFD : 0;
}
else
{
LABEL_4:
*a3 = 0LL;
result = 4294967293LL;
}
}
return result;
}

original_code:
int hashmap_get_int(map_t in, unsigned int int_key, any_t *arg){
 int i;
 hashmap_map* m;
 m = (hashmap_map *) in;
    if (int_key < 256) {
        *arg = m->first_int == ((void *)0) ? 0 : m->first_int[int_key];
        return *arg ? 0 : -3;
    }
    unsigned int curr = hashmap_int_key_to_int(m, int_key);
 for(i = 0; i<(8); i++){
        int in_use = m->data[curr].in_use;
        if (in_use == 1){
            if (m->data[curr].int_key == int_key) {
                *arg = (m->data[curr].data);
                return 0;
            }
  }
  curr = (curr + 1) % m->table_size;
 }
 *arg = ((void *)0);
 return -3;
}

canonical_original_code:
int hashmap_get_int(void *in, unsigned int int_key, void **arg){
 int i;
 struct _hashmap_map *m;
 m = (struct _hashmap_map *) in;
    if (int_key < 256) {
        *arg = m->first_int == ((void *)0) ? 0 : m->first_int[int_key];
        return *arg ? 0 : -3;
    }
    unsigned int curr = hashmap_int_key_to_int(m, int_key);
 for(i = 0; i<(8); i++){
        int in_use = m->data[curr].in_use;
        if (in_use == 1){
            if (m->data[curr].int_key == int_key) {
                *arg = (m->data[curr].data);
                return 0;
            }
  }
  curr = (curr + 1) % m->table_size;
 }
 *arg = ((void *)0);
 return -3;
}


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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void hashmap_free(map_t in){
 if (0 != in) {
  hashmap_map* m = (hashmap_map*) in;
  if (0 != m->data) {
   free(m->data);
  }
  free(m);
 }
}

canonical_original_code:
void hashmap_free(void *in){
 if (0 != in) {
  struct _hashmap_map *m = (hashmap_map*) in;
  if (0 != m->data) {
   free(m->data);
  }
  free(m);
 }
}


decompiled_code:
_QWORD *hashmap_new()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = malloc(0x18uLL);
if ( v0 )
{
v1 = calloc(0x100uLL, 0x18uLL);
v0[1] = v1;
if ( v1 )
{
*v0 = 256LL;
v0[2] = 0LL;
}
else
{
v3 = v0;
v0 = 0LL;
hashmap_free(v3);
}
}
return v0;
}

original_code:
map_t hashmap_new() {
 hashmap_map* m = (hashmap_map*) malloc(sizeof(hashmap_map));
 if(!m) goto err;
 m->data = (hashmap_element*) calloc((256), sizeof(hashmap_element));
 if(!m->data) goto err;
 m->table_size = (256);
 m->size = 0;
    m->first_int = ((void *)0);
 return m;
 err:
  if (m)
   hashmap_free(m);
  return ((void *)0);
}

canonical_original_code:
void *hashmap_new() {
 struct _hashmap_map *m = (hashmap_map*) malloc(sizeof(hashmap_map));
 if(!m) goto err;
 m->data = (struct _hashmap_element *) calloc((256), sizeof(hashmap_element));
 if(!m->data) goto err;
 m->table_size = (256);
 m->size = 0;
    m->first_int = ((void *)0);
 return m;
 err:
  if (m)
   hashmap_free(m);
  return ((void *)0);
}

return_type: void *


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

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

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

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

original_code:
int hashmap_length(map_t in){
 hashmap_map* m = (hashmap_map *) in;
 if(m != ((void *)0)) return m->size;
 else return 0;
}

canonical_original_code:
int hashmap_length(void *in){
 struct _hashmap_map *m = (hashmap_map *) in;
 if(m != ((void *)0)) return m->size;
 else return 0;
}


decompiled_code:
_BOOL8 trace_is_initialized()
{
return current_trace_buffer != 0LL;
}

canonical_decompiled_code:
_BOOL8 func0()
{
return current_trace_buffer != 0LL;
}

original_code: static inline int trace_is_initialized(void) { return 0 != current_trace_buffer; }

canonical_original_code: static inline int trace_is_initialized() { return 0 != current_trace_buffer; }


decompiled_code:
const char *__fastcall trace_init_static_information(__int64 a1)
{
int v1; // eax
const char *result; // rax

*(_QWORD *)a1 = &_static_log_information_start;
*(_QWORD *)(a1 + 8) = (&_static_log_information_end - &_static_log_information_start) >> 5;
*(_QWORD *)(a1 + 16) = _type_information_start;
v1 = module_id;
if ( module_id == -1 )
{
v1 = trace_module_id_alloc();
module_id = v1;
}
*(_DWORD *)(a1 + 24) = v1;
result = (const char *)trace_get_module_name(&_static_log_information_start);
if ( !result )
result = "UNKNOWN";
*(_QWORD *)(a1 + 32) = result;
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(__int64 a1)
{
int v1; // eax
const char *result; // rax

*(_QWORD *)a1 = &_static_log_information_start;
*(_QWORD *)(a1 + 8) = (&_static_log_information_end - &_static_log_information_start) >> 5;
*(_QWORD *)(a1 + 16) = _type_information_start;
v1 = module_id;
if ( module_id == -1 )
{
v1 = trace_module_id_alloc();
module_id = v1;
}
*(_DWORD *)(a1 + 24) = v1;
result = (const char *)trace_get_module_name(&_static_log_information_start);
if ( !result )
result = "UNKNOWN";
*(_QWORD *)(a1 + 32) = result;
return result;
}

original_code:
static void trace_init_static_information(struct trace_static_information *static_info)
{
    static_info->log_information_start = __static_log_information_start;
    static_info->log_descriptor_count = __static_log_information_end - __static_log_information_start;
    static_info->type_information_start = __type_information_start;
    if (TRACE_MODULE_ID_INVALID == module_id) {
        module_id = trace_module_id_alloc();
    }
    static_info->module_id = module_id;
    static_info->module_full_path = trace_get_module_name(__static_log_information_start);
    if (((void *)0) == static_info->module_full_path) {
        static_info->module_full_path = "UNKNOWN";
    }
}

variable_types: struct trace_static_information { struct trace_log_descriptor { enum trace_log_descriptor_kind { TRACE_LOG_DESCRIPTOR_KIND_FUNC_ENTRY=0, TRACE_LOG_DESCRIPTOR_KIND_FUNC_LEAVE=1, TRACE_LOG_DESCRIPTOR_KIND_EXPLICIT=2 } kind; unsigned int line; unsigned int severity; struct trace_param_descriptor { unsigned long flags; char *param_name; union { char *str; char *const_str; char *type_name; }; } *params; char *file; char *function; } *log_information_start; unsigned long log_descriptor_count; struct trace_type_definition { enum trace_type_id { TRACE_TYPE_ID_ENUM=1, TRACE_TYPE_ID_RECORD=2, TRACE_TYPE_ID_TYPEDEF=3 } type_id; char *type_name; union { void *params; struct trace_enum_value { char *name; unsigned int value; } *enum_values; }; } *type_information_start; unsigned int module_id; char *module_full_path; } *

user_defined_types: struct trace_static_information { struct trace_log_descriptor *log_information_start; unsigned long log_descriptor_count; struct trace_type_definition *type_information_start; unsigned int module_id; char *module_full_path; }

user_defined_types: struct trace_log_descriptor { enum trace_log_descriptor_kind kind; unsigned int line; unsigned int severity; struct trace_param_descriptor *params; char *file; char *function; }

user_defined_types: struct trace_type_definition { enum trace_type_id type_id; char *type_name; union { void *params; struct trace_enum_value *enum_values; }; }


decompiled_code:
__int64 TRACE__register_buffer()
{
char v0; // dl
int v1; // er12
__int128 v3; // [rsp+0h] [rbp-D8h] BYREF
__int64 v4; // [rsp+10h] [rbp-C8h]
char v5[24]; // [rsp+20h] [rbp-B8h] BYREF
int v6; // [rsp+38h] [rbp-A0h]
char v7[136]; // [rsp+50h] [rbp-88h] BYREF

trace_init_static_information((__int64)v5);
trace_static_log_data_map(v5);
if ( v6 )
{
v1 = 0;
goto LABEL_6;
}
v1 = 0;
if ( trace_is_initialized() )
{
LABEL_3:
*(_DWORD *)(current_trace_buffer + 44LL) |= 1 << v0;
return (unsigned int)v1;
}
v1 = trace_dynamic_log_buffers_map(0LL);
if ( v1 >= 0 )
{
LABEL_6:
if ( !trace_is_initialized() )
_assert_fail(
"(trace_is_initialized()) || TRACE_LOG_ASSERTION_FAILURE(trace_is_initialized())",
"trace_user_per_module.c",
0x51u,
"TRACE__register_buffer");
v0 = v6;
goto LABEL_3;
}
v4 = 0LL;
v3 = 0LL;
LODWORD(v3) = getpid();
DWORD1(v3) = v6;
if ( (int)trace_generate_shm_name(v7, &v3, 2LL, 0LL) <= 0 )
_assert_fail(
"(trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || TRACE_LOG_ASSERTION_F"
"AILURE(trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0)",
"trace_user_per_module.c",
0x4Du,
"TRACE__register_buffer");
trace_delete_shm_if_necessary(v7);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 func2()
{
char v0; // dl
int v1; // er12
__int128 v3; // [rsp+0h] [rbp-D8h] BYREF
__int64 v4; // [rsp+10h] [rbp-C8h]
char v5[24]; // [rsp+20h] [rbp-B8h] BYREF
int v6; // [rsp+38h] [rbp-A0h]
char v7[136]; // [rsp+50h] [rbp-88h] BYREF

func1((__int64)v5);
trace_static_log_data_map(v5);
if ( v6 )
{
v1 = 0;
goto LABEL_6;
}
v1 = 0;
if ( func0() )
{
LABEL_3:
*(_DWORD *)(current_trace_buffer + 44LL) |= 1 << v0;
return (unsigned int)v1;
}
v1 = trace_dynamic_log_buffers_map(0LL);
if ( v1 >= 0 )
{
LABEL_6:
if ( !func0() )
_assert_fail(
"(trace_is_initialized()) || TRACE_LOG_ASSERTION_FAILURE(trace_is_initialized())",
"trace_user_per_module.c",
0x51u,
"TRACE__register_buffer");
v0 = v6;
goto LABEL_3;
}
v4 = 0LL;
v3 = 0LL;
LODWORD(v3) = getpid();
DWORD1(v3) = v6;
if ( (int)trace_generate_shm_name(v7, &v3, 2LL, 0LL) <= 0 )
_assert_fail(
"(trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || TRACE_LOG_ASSERTION_F"
"AILURE(trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0)",
"trace_user_per_module.c",
0x4Du,
"TRACE__register_buffer");
trace_delete_shm_if_necessary(v7);
return (unsigned int)v1;
}

original_code:
static int TRACE__register_buffer(void)
{
    int rc = 0;
    struct trace_static_information static_info;
    trace_init_static_information(&static_info);
    trace_static_log_data_map(&static_info);
    if ((0 == static_info.module_id) && !trace_is_initialized()) {
        rc = trace_dynamic_log_buffers_map(0);
    }
    if (rc < 0) {
        trace_shm_name_buf shm_name;
        const struct trace_shm_module_details details = {
              .pid = getpid(),
              .module_id = static_info.module_id,
        };
        ((void) sizeof (((trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || (0)) ? 1 : 0), __extension__ ({ if ((trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || (0)) ; else __assert_fail ("(trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || TRACE_LOG_ASSERTION_FAILURE(trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0)", "trace_user_per_module.c", 77, __extension__ __PRETTY_FUNCTION__); }));
        trace_delete_shm_if_necessary(shm_name);
    }
    else {
        ((void) sizeof (((trace_is_initialized()) || (0)) ? 1 : 0), __extension__ ({ if ((trace_is_initialized()) || (0)) ; else __assert_fail ("(trace_is_initialized()) || TRACE_LOG_ASSERTION_FAILURE(trace_is_initialized())", "trace_user_per_module.c", 81, __extension__ __PRETTY_FUNCTION__); }));
        current_trace_buffer->module_ids_allocated |= ((trace_module_id_allocation_mask_t) 1 << static_info.module_id);
    }
    return rc;
}

canonical_original_code:
static int TRACE__register_buffer()
{
    int rc = 0;
    struct trace_static_information static_info;
    trace_init_static_information(&static_info);
    trace_static_log_data_map(&static_info);
    if ((0 == static_info.module_id) && !trace_is_initialized()) {
        rc = trace_dynamic_log_buffers_map(0);
    }
    if (rc < 0) {
        char shm_name[-1];
        struct trace_shm_module_details details = {
              .pid = getpid(),
              .module_id = static_info.module_id,
        };
        ((void) sizeof (((trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || (0)) ? 1 : 0), __extension__ ({ if ((trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || (0)) ; else __assert_fail ("(trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || TRACE_LOG_ASSERTION_FAILURE(trace_generate_shm_name(shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0)", "trace_user_per_module.c", 77, __extension__ __PRETTY_FUNCTION__); }));
        trace_delete_shm_if_necessary(shm_name);
    }
    else {
        ((void) sizeof (((trace_is_initialized()) || (0)) ? 1 : 0), __extension__ ({ if ((trace_is_initialized()) || (0)) ; else __assert_fail ("(trace_is_initialized()) || TRACE_LOG_ASSERTION_FAILURE(trace_is_initialized())", "trace_user_per_module.c", 81, __extension__ __PRETTY_FUNCTION__); }));
        current_trace_buffer->module_ids_allocated |= ((unsigned int) 1 << static_info.module_id);
    }
    return rc;
}

variable_types: rc int

variable_types: struct trace_static_information { struct trace_log_descriptor { enum trace_log_descriptor_kind { TRACE_LOG_DESCRIPTOR_KIND_FUNC_ENTRY=0, TRACE_LOG_DESCRIPTOR_KIND_FUNC_LEAVE=1, TRACE_LOG_DESCRIPTOR_KIND_EXPLICIT=2 } kind; unsigned int line; unsigned int severity; struct trace_param_descriptor { unsigned long flags; char *param_name; union { char *str; char *const_str; char *type_name; }; } *params; char *file; char *function; } *log_information_start; unsigned long log_descriptor_count; struct trace_type_definition { enum trace_type_id { TRACE_TYPE_ID_ENUM=1, TRACE_TYPE_ID_RECORD=2, TRACE_TYPE_ID_TYPEDEF=3 } type_id; char *type_name; union { void *params; struct trace_enum_value { char *name; unsigned int value; } *enum_values; }; } *type_information_start; unsigned int module_id; char *module_full_path; }

variable_types: struct trace_shm_module_details { int pid; unsigned int module_id; char *file_name; char *file_dir; }


decompiled_code:
__int64 TRACE__fini()
{
__int64 result; // rax

result = trace_finalize();
if ( (_DWORD)result )
_assert_fail(
"(0 == trace_finalize()) || TRACE_LOG_ASSERTION_FAILURE(0 == trace_finalize())",
"trace_user_per_module.c",
0x6Au,
"TRACE__fini");
return result;
}

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

result = trace_finalize();
if ( (_DWORD)result )
_assert_fail(
"(0 == trace_finalize()) || TRACE_LOG_ASSERTION_FAILURE(0 == trace_finalize())",
"trace_user_per_module.c",
0x6Au,
"TRACE__fini");
return result;
}

original_code:
void TRACE__fini(void)
{
    ((void) sizeof (((0 == trace_finalize()) || (0)) ? 1 : 0), __extension__ ({ if ((0 == trace_finalize()) || (0)) ; else __assert_fail ("(0 == trace_finalize()) || TRACE_LOG_ASSERTION_FAILURE(0 == trace_finalize())", "trace_user_per_module.c", 106, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void TRACE__fini()
{
    ((void) sizeof (((0 == trace_finalize()) || (0)) ? 1 : 0), __extension__ ({ if ((0 == trace_finalize()) || (0)) ; else __assert_fail ("(0 == trace_finalize()) || TRACE_LOG_ASSERTION_FAILURE(0 == trace_finalize())", "trace_user_per_module.c", 106, __extension__ __PRETTY_FUNCTION__); }));
}


decompiled_code:
__int64 __fastcall trace_get_descriptor_id(unsigned __int64 a1)
{
if ( a1 < (unsigned __int64)&_static_log_information_start || a1 >= (unsigned __int64)&_static_log_information_end )
_assert_fail(
"((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end)) || TRACE_LOG_ASSER"
"TION_FAILURE((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end))",
"trace_user_per_module.c",
0x6Fu,
"trace_get_descriptor_id");
return (__int64)(a1 - (_QWORD)&_static_log_information_start) >> 5;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1)
{
if ( a1 < (unsigned __int64)&_static_log_information_start || a1 >= (unsigned __int64)&_static_log_information_end )
_assert_fail(
"((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end)) || TRACE_LOG_ASSER"
"TION_FAILURE((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end))",
"trace_user_per_module.c",
0x6Fu,
"trace_get_descriptor_id");
return (__int64)(a1 - (_QWORD)&_static_log_information_start) >> 5;
}

original_code:
trace_log_id_t trace_get_descriptor_id(const struct trace_log_descriptor *descriptor)
{
    ((void) sizeof ((((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end)) || (0)) ? 1 : 0), __extension__ ({ if (((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end)) || (0)) ; else __assert_fail ("((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end)) || TRACE_LOG_ASSERTION_FAILURE((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end))", "trace_user_per_module.c", 111, __extension__ __PRETTY_FUNCTION__); }));
    return (trace_log_id_t) (descriptor - __static_log_information_start);
}

canonical_original_code:
unsigned int trace_get_descriptor_id(struct trace_log_descriptor *descriptor)
{
    ((void) sizeof ((((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end)) || (0)) ? 1 : 0), __extension__ ({ if (((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end)) || (0)) ; else __assert_fail ("((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end)) || TRACE_LOG_ASSERTION_FAILURE((descriptor >= __static_log_information_start) && (descriptor < __static_log_information_end))", "trace_user_per_module.c", 111, __extension__ __PRETTY_FUNCTION__); }));
    return (trace_log_id_t) (descriptor - __static_log_information_start);
}

variable_types: struct trace_log_descriptor { enum trace_log_descriptor_kind { TRACE_LOG_DESCRIPTOR_KIND_FUNC_ENTRY=0, TRACE_LOG_DESCRIPTOR_KIND_FUNC_LEAVE=1, TRACE_LOG_DESCRIPTOR_KIND_EXPLICIT=2 } kind; unsigned int line; unsigned int severity; struct trace_param_descriptor { unsigned long flags; char *param_name; union { char *str; char *const_str; char *type_name; }; } *params; char *file; char *function; } *


decompiled_code:
char *__fastcall trace_get_descriptor_ptr(unsigned int a1)
{
return (char *)&_static_log_information_start + 32 * a1;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned int a1)
{
return (char *)&_static_log_information_start + 32 * a1;
}

original_code:
const struct trace_log_descriptor *trace_get_descriptor_ptr(trace_log_id_t log_id)
{
    return __static_log_information_start + log_id;
}

canonical_original_code:
struct trace_log_descriptor *trace_get_descriptor_ptr(unsigned int log_id)
{
    return __static_log_information_start + log_id;
}

return_type: struct trace_log_descriptor { enum trace_log_descriptor_kind { TRACE_LOG_DESCRIPTOR_KIND_FUNC_ENTRY=0, TRACE_LOG_DESCRIPTOR_KIND_FUNC_LEAVE=1, TRACE_LOG_DESCRIPTOR_KIND_EXPLICIT=2 } kind; unsigned int line; unsigned int severity; struct trace_param_descriptor { unsigned long flags; char *param_name; union { char *str; char *const_str; char *type_name; }; } *params; char *file; char *function; } *


decompiled_code:
__int64 TRACE__implicit_init()
{
if ( (unsigned int)trace_init(0LL) )
_assert_fail(
"(0 == trace_init(((void *)0))) || TRACE_LOG_ASSERTION_FAILURE(0 == trace_init(((void *)0)))",
"trace_user_per_module.c",
0x64u,
"TRACE__implicit_init");
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
if ( (unsigned int)func3(0LL) )
_assert_fail(
"(0 == trace_init(((void *)0))) || TRACE_LOG_ASSERTION_FAILURE(0 == trace_init(((void *)0)))",
"trace_user_per_module.c",
0x64u,
"TRACE__implicit_init");
return 0LL;
}

original_code:
int TRACE__implicit_init(void) {
    ((void) sizeof (((0 == trace_init(((void *)0))) || (0)) ? 1 : 0), __extension__ ({ if ((0 == trace_init(((void *)0))) || (0)) ; else __assert_fail ("(0 == trace_init(((void *)0))) || TRACE_LOG_ASSERTION_FAILURE(0 == trace_init(((void *)0)))", "trace_user_per_module.c", 100, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

canonical_original_code:
int TRACE__implicit_init() {
    ((void) sizeof (((0 == trace_init(((void *)0))) || (0)) ? 1 : 0), __extension__ ({ if ((0 == trace_init(((void *)0))) || (0)) ; else __assert_fail ("(0 == trace_init(((void *)0))) || TRACE_LOG_ASSERTION_FAILURE(0 == trace_init(((void *)0)))", "trace_user_per_module.c", 100, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}


decompiled_code:
int *set_esrch_if_necessary()
{
int *result; // rax

result = _errno_location();
if ( *result == 2 )
*result = 3;
return result;
}

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

result = _errno_location();
if ( *result == 2 )
*result = 3;
return result;
}

original_code:
static void set_esrch_if_necessary(void)
{
    if (2 == (*__errno_location ())) {
       (*__errno_location ()) = 3;
    }
}

canonical_original_code:
static void set_esrch_if_necessary()
{
    if (2 == (*__errno_location ())) {
       (*__errno_location ()) = 3;
    }
}


decompiled_code:
int __fastcall wait_until_process_exited(__id_t id, siginfo_t *a2)
{
siginfo_t *v2; // rbx
int result; // eax
__int64 v4; // [rsp+0h] [rbp-98h] BYREF

v2 = a2;
if ( !a2 )
v2 = (siginfo_t *)&v4;
memset(v2, 0, sizeof(siginfo_t));
while ( 1 )
{
result = waitid(P_PID, id, v2, 4);
if ( result != -1 )
break;
if ( *_errno_location() != 4 )
goto LABEL_7;
}
if ( result )
LABEL_7:
_assert_fail(
"(0 == (__extension__ ({ long int __result; do __result = (long int) (waitid(P_PID, pid, si, 4)); while (__result ="
"= -1L && (*__errno_location ()) == 4); __result; }))) || TRACE_LOG_ASSERTION_FAILURE(0 == (__extension__ ({ long i"
"nt __result; do __result = (long int) (waitid(P_PID, pid, si, 4)); while (__result == -1L && (*__errno_location ()"
") == 4); __result; })))",
"trace_proc_util.c",
0x58u,
"wait_until_process_exited");
return result;
}

canonical_decompiled_code:
int __fastcall func1(__id_t id, siginfo_t *a2)
{
siginfo_t *v2; // rbx
int result; // eax
__int64 v4; // [rsp+0h] [rbp-98h] BYREF

v2 = a2;
if ( !a2 )
v2 = (siginfo_t *)&v4;
memset(v2, 0, sizeof(siginfo_t));
while ( 1 )
{
result = waitid(P_PID, id, v2, 4);
if ( result != -1 )
break;
if ( *_errno_location() != 4 )
goto LABEL_7;
}
if ( result )
LABEL_7:
_assert_fail(
"(0 == (__extension__ ({ long int __result; do __result = (long int) (waitid(P_PID, pid, si, 4)); while (__result ="
"= -1L && (*__errno_location ()) == 4); __result; }))) || TRACE_LOG_ASSERTION_FAILURE(0 == (__extension__ ({ long i"
"nt __result; do __result = (long int) (waitid(P_PID, pid, si, 4)); while (__result == -1L && (*__errno_location ()"
") == 4); __result; })))",
"trace_proc_util.c",
0x58u,
"wait_until_process_exited");
return result;
}

original_code:
static void wait_until_process_exited(pid_t pid, siginfo_t *si)
{
    siginfo_t ignored_si;
    if (((void *)0) == si) {
        si = &ignored_si;
    }
    memset(si, 0, sizeof(*si));
    ((void) sizeof (((0 == (__extension__ ({ long int __result; do __result = (long int) (waitid(P_PID, pid, si, 4)); while (__result == -1L && (*__errno_location ()) == 4); __result; }))) || (0)) ? 1 : 0), __extension__ ({ if ((0 == (__extension__ ({ long int __result; do __result = (long int) (waitid(P_PID, pid, si, 4)); while (__result == -1L && (*__errno_location ()) == 4); __result; }))) || (0)) ; else __assert_fail ("(0 == (__extension__ ({ long int __result; do __result = (long int) (waitid(P_PID, pid, si, 4)); while (__result == -1L && (*__errno_location ()) == 4); __result; }))) || TRACE_LOG_ASSERTION_FAILURE(0 == (__extension__ ({ long int __result; do __result = (long int) (waitid(P_PID, pid, si, 4)); while (__result == -1L && (*__errno_location ()) == 4); __result; })))", "trace_proc_util.c", 88, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void wait_until_process_exited(int pid, struct siginfo_t *si)
{
    struct siginfo_t ignored_si;
    if (((void *)0) == si) {
        si = &ignored_si;
    }
    memset(si, 0, sizeof(*si));
    ((void) sizeof (((0 == (__extension__ ({ long __result; do __result = (long) (waitid(P_PID, pid, si, 4)); while (__result == -1L && (*__errno_location ()) == 4); __result; }))) || (0)) ? 1 : 0), __extension__ ({ if ((0 == (__extension__ ({ long __result; do __result = (long) (waitid(P_PID, pid, si, 4)); while (__result == -1L && (*__errno_location ()) == 4); __result; }))) || (0)) ; else __assert_fail ("(0 == (__extension__ ({ long int __result; do __result = (long int) (waitid(P_PID, pid, si, 4)); while (__result == -1L && (*__errno_location ()) == 4); __result; }))) || TRACE_LOG_ASSERTION_FAILURE(0 == (__extension__ ({ long int __result; do __result = (long int) (waitid(P_PID, pid, si, 4)); while (__result == -1L && (*__errno_location ()) == 4); __result; })))", "trace_proc_util.c", 88, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: pid int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int __fastcall stat_pid(unsigned int a1, struct stat *a2)
{
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

snprintf(v3, 0x100uLL, "/proc/%d", a1);
return stat(v3, a2);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, struct stat *a2)
{
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

snprintf(v3, 0x100uLL, "/proc/%d", a1);
return stat(v3, a2);
}

original_code:
static int stat_pid(pid_t pid, struct stat *stat_buf)
{
    char filename[0x100];
    snprintf(filename, sizeof(filename), "/proc/%d", pid);
    return stat(filename, stat_buf);
}

canonical_original_code:
static int stat_pid(int pid, struct stat *stat_buf)
{
    char filename[256];
    snprintf(filename, sizeof(filename), "/proc/%d", pid);
    return stat(filename, stat_buf);
}

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]; } *

variable_types:
filename
char [256]

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:
__int64 __fastcall trace_get_current_exec_basename(char *dest, size_t n)
{
int v2; // eax
unsigned int v3; // er8
char *v4; // rbx
char *v5; // rax
int *v7; // rax
__int128 v8; // [rsp+0h] [rbp-1028h] BYREF
char v9[4080]; // [rsp+10h] [rbp-1018h] BYREF

v8 = 0LL;
memset(v9, 0, sizeof(v9));
v2 = readlink("/proc/self/exe", (char *)&v8, 0xFFFuLL);
v3 = v2;
if ( v2 >= 0 )
{
v4 = &dest[n - 1];
*v4 = 0;
*((_BYTE *)&v8 + v2) = 0;
v5 = basename((const char *)&v8);
strncpy(dest, v5, n);
if ( *v4 )
{
v7 = _errno_location();
v3 = -1;
*v7 = 36;
}
else
{
v3 = 0;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *dest, size_t n)
{
int v2; // eax
unsigned int v3; // er8
char *v4; // rbx
char *v5; // rax
int *v7; // rax
__int128 v8; // [rsp+0h] [rbp-1028h] BYREF
char v9[4080]; // [rsp+10h] [rbp-1018h] BYREF

v8 = 0LL;
memset(v9, 0, sizeof(v9));
v2 = readlink("/proc/self/exe", (char *)&v8, 0xFFFuLL);
v3 = v2;
if ( v2 >= 0 )
{
v4 = &dest[n - 1];
*v4 = 0;
*((_BYTE *)&v8 + v2) = 0;
v5 = basename((const char *)&v8);
strncpy(dest, v5, n);
if ( *v4 )
{
v7 = _errno_location();
v3 = -1;
*v7 = 36;
}
else
{
v3 = 0;
}
}
return v3;
}

original_code:
int trace_get_current_exec_basename(char *exec_name, size_t exec_name_size)
{
    char exec_path[4096] = "";
    int rc = readlink("/proc/self/exe", exec_path, sizeof(exec_path) - 1);
    if (rc < 0) {
        return rc;
    }
    exec_path[rc] = '\0';
    exec_name[exec_name_size - 1] = '\0';
    strncpy(exec_name, basename(exec_path), exec_name_size);
    if ('\0' != exec_name[exec_name_size - 1]) {
        (*__errno_location ()) = 36;
        return -1;
    }
    return 0;
}

canonical_original_code:
int trace_get_current_exec_basename(char *exec_name, unsigned long exec_name_size)
{
    char exec_path[4096] = "";
    int rc = readlink("/proc/self/exe", exec_path, sizeof(exec_path) - 1);
    if (rc < 0) {
        return rc;
    }
    exec_path[rc] = '\0';
    exec_name[exec_name_size - 1] = '\0';
    strncpy(exec_name, basename(exec_path), exec_name_size);
    if ('\0' != exec_name[exec_name_size - 1]) {
        (*__errno_location ()) = 36;
        return -1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall trace_get_fd_path(unsigned int a1, char *a2, size_t a3)
{
ssize_t v4; // rax
__int64 result; // rax
char v6[72]; // [rsp+0h] [rbp-48h] BYREF

sprintf(v6, "/proc/self/fd/%d", a1);
v4 = readlink(v6, a2, a3);
if ( v4 < 0 )
return 0xFFFFFFFFLL;
if ( v4 >= a3 )
{
a2[a3 - 1] = 0;
*_errno_location() = 36;
result = 0xFFFFFFFFLL;
}
else
{
a2[v4] = 0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, char *a2, size_t a3)
{
ssize_t v4; // rax
__int64 result; // rax
char v6[72]; // [rsp+0h] [rbp-48h] BYREF

sprintf(v6, "/proc/self/fd/%d", a1);
v4 = readlink(v6, a2, a3);
if ( v4 < 0 )
return 0xFFFFFFFFLL;
if ( v4 >= a3 )
{
a2[a3 - 1] = 0;
*_errno_location() = 36;
result = 0xFFFFFFFFLL;
}
else
{
a2[v4] = 0;
result = 0LL;
}
return result;
}

original_code:
int trace_get_fd_path(int fd, char *file_path, size_t file_path_buf_size)
{
    char fd_proc_path[40];
    sprintf(fd_proc_path, "/proc/self/fd/%d", fd);
    const ssize_t path_len = readlink(fd_proc_path, file_path, file_path_buf_size);
    if (path_len < 0) {
        return -1;
    }
    if ((size_t) path_len >= file_path_buf_size) {
        file_path[file_path_buf_size - 1] = '\0';
        (*__errno_location ()) = 36;
        return -1;
    }
    file_path[path_len] = '\0';
    return 0;
}

canonical_original_code:
int trace_get_fd_path(int fd, char *file_path, unsigned long file_path_buf_size)
{
    char fd_proc_path[40];
    sprintf(fd_proc_path, "/proc/self/fd/%d", fd);
    long path_len = readlink(fd_proc_path, file_path, file_path_buf_size);
    if (path_len < 0) {
        return -1;
    }
    if ((unsigned long) path_len >= file_path_buf_size) {
        file_path[file_path_buf_size - 1] = '\0';
        (*__errno_location ()) = 36;
        return -1;
    }
    file_path[path_len] = '\0';
    return 0;
}

variable_types: fd int