strlcpy

decompiled_code:
__int64 __fastcall strlcpy(char *dest, char *src, unsigned __int64 a3)
{
size_t v4; // rax
__int64 v5; // r13

v4 = strlen(src);
v5 = (int)v4;
if ( !a3 )
return v5;
if ( a3 > (int)v4 )
{
memcpy(dest, src, v4 + 1);
return v5;
}
strncpy(dest, src, a3 - 1);
dest[a3 - 1] = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *dest, char *src, unsigned __int64 a3)
{
size_t v4; // rax
__int64 v5; // r13

v4 = strlen(src);
v5 = (int)v4;
if ( !a3 )
return v5;
if ( a3 > (int)v4 )
{
memcpy(dest, src, v4 + 1);
return v5;
}
strncpy(dest, src, a3 - 1);
dest[a3 - 1] = 0;
return v5;
}

original_code:
size_t strlcpy(char *dst, const char *src, size_t dstlen)
{
 int srclen = strlen(src);
 if (dstlen > 0) {
  if (dstlen > srclen)
   strcpy(dst, src);
  else {
   strncpy(dst, src, dstlen - 1);
   dst[dstlen - 1] = 0;
  }
 }
 return srclen;
}

canonical_original_code:
unsigned long strlcpy(char *dst, char *src, unsigned long dstlen)
{
 int srclen = strlen(src);
 if (dstlen > 0) {
  if (dstlen > srclen)
   strcpy(dst, src);
  else {
   strncpy(dst, src, dstlen - 1);
   dst[dstlen - 1] = 0;
  }
 }
 return srclen;
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
dstlen
unsigned long

variable_types: srclen int


strlcat

repo: smaclennan/zedit

decompiled_code:
__int64 __fastcall strlcat(const char *a1, const char *a2, __int64 a3)
{
int v5; // ebp
size_t v6; // rax
int v7; // edx
int v8; // ebx
char *v9; // rdi

v5 = strlen(a1);
v6 = strlen(a2);
v7 = a3 - v5;
v8 = v6;
if ( (int)a3 - v5 <= 0 )
return v8 + v5;
v9 = (char *)&a1[v5];
if ( (int)v6 < v7 )
{
memcpy(v9, a2, v6 + 1);
return v8 + v5;
}
strncpy(v9, a2, v7 - 1);
a1[a3 - 1] = 0;
return v8 + v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2, __int64 a3)
{
int v5; // ebp
size_t v6; // rax
int v7; // edx
int v8; // ebx
char *v9; // rdi

v5 = strlen(a1);
v6 = strlen(a2);
v7 = a3 - v5;
v8 = v6;
if ( (int)a3 - v5 <= 0 )
return v8 + v5;
v9 = (char *)&a1[v5];
if ( (int)v6 < v7 )
{
memcpy(v9, a2, v6 + 1);
return v8 + v5;
}
strncpy(v9, a2, v7 - 1);
a1[a3 - 1] = 0;
return v8 + v5;
}

original_code:
size_t strlcat(char *dst, const char *src, size_t dstsize)
{
 int dstlen = strlen(dst);
 int srclen = strlen(src);
 int left = dstsize - dstlen;
 if (left > 0) {
  if (left > srclen)
   strcpy(dst + dstlen, src);
  else {
   strncpy(dst + dstlen, src, left - 1);
   dst[dstsize - 1] = 0;
  }
 }
 return dstlen + srclen;
}

canonical_original_code:
unsigned long strlcat(char *dst, char *src, unsigned long dstsize)
{
 int dstlen = strlen(dst);
 int srclen = strlen(src);
 int left = dstsize - dstlen;
 if (left > 0) {
  if (left > srclen)
   strcpy(dst + dstlen, src);
  else {
   strncpy(dst + dstlen, src, left - 1);
   dst[dstsize - 1] = 0;
  }
 }
 return dstlen + srclen;
}

variable_types:
dstsize
unsigned long

variable_types: dstlen int

variable_types: left int

return_type: unsigned long


blength

original_code:
unsigned long blength(struct buff *buff)
{
 struct page *tpage;
 unsigned long len = 0;
 for (tpage = buff->firstp; tpage; tpage = tpage->nextp)
  len += tpage->plen;
 return len;
}

variable_types: struct buff { struct page { char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; char *curcptr; unsigned int curchar; int bmodf; struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; struct mark *prev; struct mark *next; } *marks; } *

variable_types:
len
unsigned long

user_defined_types: struct buff { struct page *firstp; struct page *lastp; struct page *curpage; char *curcptr; unsigned int curchar; int bmodf; struct mark *marks; }


blocation

original_code:
unsigned long blocation(struct buff *buff)
{
 struct page *tpage;
 unsigned long len = 0;
 for (tpage = buff->firstp; tpage != buff->curpage; tpage = tpage->nextp)
  len += tpage->plen;
 return len + buff->curchar;
}

variable_types: struct page { char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *

user_defined_types: struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; struct mark *prev; struct mark *next; }


makecur

original_code:
static inline void makecur(struct buff *buff, struct page *page, int dist)
{
 buff->curpage = page;
 buff->curchar = dist;
 buff->curcptr = page->pdata + dist;
}

variable_types: struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *

variable_types:
page
struct page *

variable_types: dist int

return_type: void

user_defined_types: struct buff { struct page *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; }


bpnttomrk

original_code:
int bpnttomrk(struct buff *buff, struct mark *mark)
{
 if (mark->mbuff != buff)
  return 0;
 if (mark->mpage)
  makecur(buff, mark->mpage, mark->moffset);
 return 1;
}

variable_types: struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; } *

return_type: int

user_defined_types: struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; }


bisstart

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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) == *(_QWORD *)a1 )
result = *(_DWORD *)(a1 + 32) == 0;
return result;
}

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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) == *(_QWORD *)a1 )
result = *(_DWORD *)(a1 + 32) == 0;
return result;
}

original_code:
static inline int bisstart(struct buff *buff)
{
 return buff->curpage == buff->firstp && buff->curchar == 0;
}


bisend

decompiled_code:
_BOOL8 __fastcall bisend(__int64 a1)
{
__int64 v1; // rdx
_BOOL8 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = 0LL;
if ( !*(_QWORD *)(v1 + 4112) )
result = *(_DWORD *)(a1 + 32) >= *(_DWORD *)(v1 + 4096);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
__int64 v1; // rdx
_BOOL8 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = 0LL;
if ( !*(_QWORD *)(v1 + 4112) )
result = *(_DWORD *)(a1 + 32) >= *(_DWORD *)(v1 + 4096);
return result;
}

original_code:
static inline int bisend(struct buff *buff)
{
 return buff->curpage->nextp == ((void *)0) &&
  buff->curchar >= buff->curpage->plen;
}


makecur

canonical_original_code:
static inline void makecur(struct buff *buff, struct page *page, int dist)
{
 buff->curpage = page;
 buff->curchar = dist;
 buff->curcptr = page->pdata + dist;
}


makeoffset

original_code:
static inline void makeoffset(struct buff *buff, int dist)
{
 buff->curchar = dist;
 buff->curcptr = buff->curpage->pdata + dist;
}


original_code:
static inline void bmove1(struct buff *buff)
{
 if (++buff->curchar < ((buff)->curpage->plen))
  ++buff->curcptr;
 else if (buff->curpage->nextp)
  makecur(buff, buff->curpage->nextp, 0);
 else
  makeoffset(buff, ((buff)->curpage->plen));
}


canonical_original_code:
static inline void makeoffset(struct buff *buff, int dist)
{
 buff->curchar = dist;
 buff->curcptr = buff->curpage->pdata + dist;
}


bmrktopnt

decompiled_code:
__int64 __fastcall bmrktopnt(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 16);
*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = v2;
result = *(unsigned int *)(a1 + 32);
*(_DWORD *)(a2 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 16);
*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = v2;
result = *(unsigned int *)(a1 + 32);
*(_DWORD *)(a2 + 16) = result;
return result;
}

original_code:
static inline void bmrktopnt(struct buff *buff, struct mark *mark)
{
 mark->mbuff = buff;
 mark->mpage = buff->curpage;
 mark->moffset = buff->curchar;
}

user_defined_types: struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; }


canonical_original_code:
static inline void bmove1(struct buff *buff)
{
 if (++buff->curchar < ((buff)->curpage->plen))
  ++buff->curcptr;
 else if (buff->curpage->nextp)
  makecur(buff, buff->curpage->nextp, 0);
 else
  makeoffset(buff, ((buff)->curpage->plen));
}


btoend

decompiled_code:
void __fastcall btoend(__int64 a1)
{
makecur(a1, *(_QWORD *)(a1 + 8), *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4096LL));
}

original_code:
static inline void btoend(struct buff *buff)
{
 makecur(buff, buff->lastp, buff->lastp->plen);
}


bmrktopnt

canonical_original_code:
static inline void bmrktopnt(struct buff *buff, struct mark *mark)
{
 mark->mbuff = buff;
 mark->mpage = buff->curpage;
 mark->moffset = buff->curchar;
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
socklen_t v5; // edx
unsigned __int16 v6; // ax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

v3 = socket(2, 2, 0);
if ( v3 >= 0 )
{
v4 = v3;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = _bswap_32_constprop_0(10000LL, 2LL, 16LL);
*(_WORD *)addr.sa_data = _bswap_16(10000LL, &addr);
if ( bind(v4, &addr, v5) >= 0 )
{
len = 16;
if ( getsockname(v4, &addr, &len) >= 0 )
{
v6 = _bswap_16(*(unsigned __int16 *)addr.sa_data, &addr);
printf("The server UDP port number is %d\n", v6);
echo(v4);
}
puts("Error getsockname");
exit(1);
}
puts("Problem binding");
exit(0);
}
puts("Problem creating socket");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
socklen_t v5; // edx
unsigned __int16 v6; // ax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

v3 = socket(2, 2, 0);
if ( v3 >= 0 )
{
v4 = v3;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = func8(10000LL, 2LL, 16LL);
*(_WORD *)addr.sa_data = func7(10000LL, &addr);
if ( bind(v4, &addr, v5) >= 0 )
{
len = 16;
if ( getsockname(v4, &addr, &len) >= 0 )
{
v6 = func7(*(unsigned __int16 *)addr.sa_data, &addr);
printf("The server UDP port number is %d\n", v6);
echo(v4);
}
puts("Error getsockname");
exit(1);
}
puts("Problem binding");
exit(0);
}
puts("Problem creating socket");
exit(1);
}

original_code:
int main() {
  int ld;
  struct sockaddr_in skaddr;
  int length;
  if ((ld = socket( 2, SOCK_DGRAM, 0 )) < 0) {
    printf("Problem creating socket\n");
    exit(1);
  }
  skaddr.sin_family = 2;
  skaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  skaddr.sin_port = htons(10000);
  if (bind(ld, (struct sockaddr *) &skaddr, sizeof(skaddr))<0) {
    printf("Problem binding\n");
    exit(0);
  }
  length = sizeof( skaddr );
  if (getsockname(ld, (struct sockaddr *) &skaddr, &length)<0) {
    printf("Error getsockname\n");
    exit(1);
  }
  printf("The server UDP port number is %d\n",ntohs(skaddr.sin_port));
  echo(ld);
  return(0);
}

canonical_original_code:
int main() {
  int ld;
  struct sockaddr_in skaddr;
  int length;
  if ((ld = socket( 2, SOCK_DGRAM, 0 )) < 0) {
    printf("Problem creating socket\n");
    exit(1);
  }
  skaddr.sin_family = 2;
  skaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  skaddr.sin_port = htons(10000);
  if (bind(ld, (struct sockaddr *) &skaddr, sizeof(skaddr))<0) {
    printf("Problem binding\n");
    exit(0);
  }
  length = sizeof( skaddr );
  if (getsockname(ld, (struct sockaddr *) &skaddr, &length)<0) {
    printf("Error getsockname\n");
    exit(1);
  }
  printf("The server UDP port number is %d\n",ntohs(skaddr.sin_port));
  echo(ld);
  return(0);
}

variable_types: ld int

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

variable_types: length int

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


led

decompiled_code:
int __fastcall led(unsigned int a1, unsigned int a2)
{
int v2; // ebp
size_t v3; // rax
char buf[10]; // [rsp+6h] [rbp-92h] BYREF
char s[136]; // [rsp+10h] [rbp-88h] BYREF

printf("file: /sys/class/pwm/gpio_pwm:%d/duty_ns\n", a1);
printf("density: %d\n", a2);
sprintf(s, "/sys/class/pwm/gpio_pwm:%d/duty_ns", a1);
sprintf(buf, "%d0000", a2);
v2 = open(s, 1);
v3 = strlen(buf);
write(v2, buf, v3);
return close(v2);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1, unsigned int a2)
{
int v2; // ebp
size_t v3; // rax
char buf[10]; // [rsp+6h] [rbp-92h] BYREF
char s[136]; // [rsp+10h] [rbp-88h] BYREF

printf("file: /sys/class/pwm/gpio_pwm:%d/duty_ns\n", a1);
printf("density: %d\n", a2);
sprintf(s, "/sys/class/pwm/gpio_pwm:%d/duty_ns", a1);
sprintf(buf, "%d0000", a2);
v2 = open(s, 1);
v3 = strlen(buf);
write(v2, buf, v3);
return close(v2);
}

original_code:
void led(int channel,int density) {
  int fd;
  char file[100];
  char str_density[10];
  printf("file: /sys/class/pwm/gpio_pwm:%d/duty_ns\n", channel);
  printf("density: %d\n", density);
  sprintf(file, "/sys/class/pwm/gpio_pwm:%d/duty_ns", channel);
  sprintf(str_density, "%d0000", density);
  fd = open(file, 01);
  write (fd, str_density, strlen(str_density));
  close(fd);
}

canonical_original_code:
void led(int channel, int density) {
  int fd;
  char file[100];
  char str_density[10];
  printf("file: /sys/class/pwm/gpio_pwm:%d/duty_ns\n", channel);
  printf("density: %d\n", density);
  sprintf(file, "/sys/class/pwm/gpio_pwm:%d/duty_ns", channel);
  sprintf(str_density, "%d0000", density);
  fd = open(file, 01);
  write (fd, str_density, strlen(str_density));
  close(fd);
}

variable_types: channel int

variable_types: density int

variable_types: fd int

variable_types:
file
char [100]


decompiled_code:
__int64 __fastcall get_led_duty(unsigned int a1)
{
int v1; // ebp
unsigned int v3; // [rsp+0h] [rbp-98h]
char buf[10]; // [rsp+6h] [rbp-92h] BYREF
char s[136]; // [rsp+10h] [rbp-88h] BYREF

printf("file: /sys/class/pwm/gpio_pwm:%d/duty_ns\n", a1);
sprintf(s, "/sys/class/pwm/gpio_pwm:%d/duty_ns", a1);
v1 = open(s, 0);
read(v1, buf, 0xAuLL);
close(v1);
__isoc99_sscanf();
printf("density: %d\n", v3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
int v1; // ebp
unsigned int v3; // [rsp+0h] [rbp-98h]
char buf[10]; // [rsp+6h] [rbp-92h] BYREF
char s[136]; // [rsp+10h] [rbp-88h] BYREF

printf("file: /sys/class/pwm/gpio_pwm:%d/duty_ns\n", a1);
sprintf(s, "/sys/class/pwm/gpio_pwm:%d/duty_ns", a1);
v1 = open(s, 0);
read(v1, buf, 0xAuLL);
close(v1);
__isoc99_sscanf();
printf("density: %d\n", v3);
return v3;
}

original_code:
int get_led_duty(int channel) {
  int fd;
  int density;
  char file[100];
  char str_density[10];
  printf("file: /sys/class/pwm/gpio_pwm:%d/duty_ns\n", channel);
  sprintf(file, "/sys/class/pwm/gpio_pwm:%d/duty_ns", channel);
  fd = open(file, 00);
  read (fd, str_density, 10);
  close(fd);
  sscanf( str_density, "%3d0000", &density);
  printf("density: %d\n", density);
  return density;
}


main

decompiled_code:
// attributes: thunk
int __cdecl main(int argc, const char **argv, const char **envp)
{
return problem(argc, argv, envp);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return func7(argc, argv, envp);
}

original_code:
int main(int argc, char** argv) {
 return( problem(argc, argv) );
}

canonical_original_code:
int main(int argc, char **argv) {
 return( problem(argc, argv) );
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 message_new()
{
__int64 v0; // r12
__int64 v1; // rax

v0 = xalloc(16LL, 0LL, 0LL);
v1 = xalloc(40LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = v1;
*(_DWORD *)v1 = 24;
*(_QWORD *)(v1 + 8) = element_new;
*(_QWORD *)(v1 + 16) = element_free;
return v0;
}

original_code:
Message* message_new()
{
    Message* message = _xalloc(sizeof(Message), ((void *)0), 0);
    message->elements = _xalloc(sizeof(List), ((void *)0), 0); message->elements->element_size = sizeof(Element); message->elements->constructor = (void*)element_new; message->elements->destructor = (void*)element_free;;
    return message;
}

canonical_original_code:
struct Message *message_new()
{
    struct Message *message = _xalloc(sizeof(Message), ((void *)0), 0);
    message->elements = _xalloc(sizeof(List), ((void *)0), 0); message->elements->element_size = sizeof(Element); message->elements->constructor = (void *)element_new; message->elements->destructor = (void *)element_free;;
    return message;
}

variable_types: struct Message { int id; struct _list { int element_size; int size; void *(*constructor)(); void (*destructor)(void *); struct _iterator { void *element; struct _iterator *next; } *head; struct _iterator *tail; } *elements; } *

user_defined_types: struct Message { int id; struct _list *elements; }

user_defined_types: struct _list { int element_size; int size; void *(*constructor)(); void (*destructor)(void *); struct _iterator *head; struct _iterator *tail; }


decompiled_code:
__int64 state_new()
{
__int64 v0; // r12

v0 = xalloc(24LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = string_new();
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // r12

v0 = xalloc(24LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = string_new();
return v0;
}

original_code:
State* state_new()
{
    State* s = _xalloc(sizeof(State), ((void *)0), 0);
    s->name = string_new();
    return s;
}

canonical_original_code:
struct State *state_new()
{
    struct State *s = _xalloc(sizeof(State), ((void *)0), 0);
    s->name = string_new();
    return s;
}

variable_types: struct State { int id; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *name; int count; } *

user_defined_types: struct State { int id; struct _String *name; int count; }


decompiled_code:
__int64 element_new()
{
__int64 v0; // r12

v0 = xalloc(24LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = string_new();
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // r12

v0 = xalloc(24LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = string_new();
return v0;
}

original_code:
Element* element_new()
{
    Element* e = _xalloc(sizeof(Element), ((void *)0), 0);
    e->str_val = string_new();
    return e;
}

canonical_original_code:
struct Element *element_new()
{
    struct Element *e = _xalloc(sizeof(Element), ((void *)0), 0);
    e->str_val = string_new();
    return e;
}

variable_types: struct Element { int element_type_id; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *str_val; int is_file; } *

user_defined_types: struct Element { int element_type_id; struct _String *str_val; int is_file; }


decompiled_code:
__int64 __fastcall state_free(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
return xfree(a1, 0LL, 0LL);
}

original_code:
void state_free(State* s)
{
    string_free(s->name);
    _xfree(s, ((void *)0), 0);;
}

canonical_original_code:
void state_free(struct State *s)
{
    string_free(s->name);
    _xfree(s, ((void *)0), 0);;
}

user_defined_types: struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; }


decompiled_code:
__int64 __fastcall element_free(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
return xfree(a1, 0LL, 0LL);
}

original_code:
void element_free(Element* e)
{
    string_free(e->str_val);
    _xfree(e, ((void *)0), 0);;
}

canonical_original_code:
void element_free(struct Element *e)
{
    string_free(e->str_val);
    _xfree(e, ((void *)0), 0);;
}


decompiled_code:
__int64 __fastcall message_free(__int64 a1)
{
if ( *(_QWORD *)(a1 + 8) )
list_free();
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( *(_QWORD *)(a1 + 8) )
list_free();
return xfree(a1, 0LL, 0LL);
}

original_code:
void message_free(Message* m)
{
    if (m->elements)
        list_free(m->elements);
    _xfree(m, ((void *)0), 0);;
}

canonical_original_code:
void message_free(struct Message *m)
{
    if (m->elements)
        list_free(m->elements);
    _xfree(m, ((void *)0), 0);;
}

user_defined_types: struct _iterator { void *element; struct _iterator *next; }


decompiled_code:
void *__fastcall get_element_value(__int64 a1, _DWORD *a2)
{
__int64 i; // rbp
_DWORD *v3; // r12
void *result; // rax

if ( !a1 )
return &unk_97B;
for ( i = get_iterator(); (unsigned int)iterator_has_value(i); i = iterator_next(i) )
{
v3 = *(_DWORD **)i;
result = (void *)string_rawstr(*(_QWORD *)(*(_QWORD *)i + 8LL));
if ( *a2 == *v3 && result )
return result;
}
return &unk_97B;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, _DWORD *a2)
{
__int64 i; // rbp
_DWORD *v3; // r12
void *result; // rax

if ( !a1 )
return &unk_97B;
for ( i = get_iterator(); (unsigned int)iterator_has_value(i); i = iterator_next(i) )
{
v3 = *(_DWORD **)i;
result = (void *)string_rawstr(*(_QWORD *)(*(_QWORD *)i + 8LL));
if ( *a2 == *v3 && result )
return result;
}
return &unk_97B;
}

original_code:
char* get_element_value(List* elements, ElementType* et)
{
    Iterator* it;
    if (elements == ((void *)0)) return "";
    for(it = get_iterator(elements); iterator_has_value(it); it = iterator_next(it)) {
        Element* e = it->element;
        char* str = string_rawstr(e->str_val);
        if (et->id == e->element_type_id && str != ((void *)0))
            return str;
    }
    return "";
}

canonical_original_code:
char *get_element_value(struct _list *elements, struct ElementType *et)
{
    struct _iterator *it;
    if (elements == ((void *)0)) return "";
    for(it = get_iterator(elements); iterator_has_value(it); it = iterator_next(it)) {
        struct Element *e = it->element;
        char *str = string_rawstr(e->str_val);
        if (et->id == e->element_type_id && str != ((void *)0))
            return str;
    }
    return "";
}

variable_types: struct _list { int element_size; int size; void *(*constructor)(); void (*destructor)(void *); struct _iterator { void *element; struct _iterator *next; } *head; struct _iterator *tail; } *

variable_types: struct ElementType { int id; int type; int ticket_property; int reply_property; int required; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *name; struct _String *description; int auto_add_item; struct _String *default_value; int display_in_list; int sort; } *

variable_types:
str
char *

return_type: char *

user_defined_types: struct ElementType { int id; int type; int ticket_property; int reply_property; int required; struct _String *name; struct _String *description; int auto_add_item; struct _String *default_value; int display_in_list; int sort; }


decompiled_code:
void *__fastcall get_element_value_by_id(__int64 a1, int a2)
{
__int64 i; // rbp
_DWORD *v3; // r12
void *result; // rax

if ( !a1 )
return &unk_97B;
for ( i = get_iterator(); (unsigned int)iterator_has_value(i); i = iterator_next(i) )
{
v3 = *(_DWORD **)i;
result = (void *)string_rawstr(*(_QWORD *)(*(_QWORD *)i + 8LL));
if ( *v3 == a2 && result )
return result;
}
return &unk_97B;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, int a2)
{
__int64 i; // rbp
_DWORD *v3; // r12
void *result; // rax

if ( !a1 )
return &unk_97B;
for ( i = get_iterator(); (unsigned int)iterator_has_value(i); i = iterator_next(i) )
{
v3 = *(_DWORD **)i;
result = (void *)string_rawstr(*(_QWORD *)(*(_QWORD *)i + 8LL));
if ( *v3 == a2 && result )
return result;
}
return &unk_97B;
}

original_code:
char* get_element_value_by_id(List* elements, const int type)
{
    Iterator* it;
    if (elements == ((void *)0)) return "";
    for(it = get_iterator(elements); iterator_has_value(it); it = iterator_next(it)) {
        Element* e = it->element;
        char* str = string_rawstr(e->str_val);
        if (type == e->element_type_id && str != ((void *)0))
            return str;
    }
    return "";
}

canonical_original_code:
char *get_element_value_by_id(struct _list *elements, int type)
{
    struct _iterator *it;
    if (elements == ((void *)0)) return "";
    for(it = get_iterator(elements); iterator_has_value(it); it = iterator_next(it)) {
        struct Element *e = it->element;
        char *str = string_rawstr(e->str_val);
        if (type == e->element_type_id && str != ((void *)0))
            return str;
    }
    return "";
}

variable_types: type int

variable_types: struct _iterator { void *element; struct _iterator *next; } *


decompiled_code:
__int64 __fastcall set_element_value(__int64 a1)
{
return string_set(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return string_set(*(_QWORD *)(a1 + 8));
}

original_code:
void set_element_value(Element* e, const char* val)
{
    string_set(e->str_val, val);
}

canonical_original_code:
void set_element_value(struct Element *e, char *val)
{
    string_set(e->str_val, val);
}

variable_types:
val
char *


decompiled_code:
__int64 valid_condition_size()
{
unsigned int v0; // er12
__int64 *i; // rbp

v0 = 0;
for ( i = (__int64 *)get_iterator(); (unsigned int)iterator_has_value(i); i = (__int64 *)iterator_next(i) )
v0 -= !valid_condition(*i) - 1;
return v0;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // er12
__int64 *i; // rbp

v0 = 0;
for ( i = (__int64 *)get_iterator(); (unsigned int)iterator_has_value(i); i = (__int64 *)iterator_next(i) )
v0 -= !func10(*i) - 1;
return v0;
}

original_code:
int valid_condition_size(List* conditions)
{
    int size = 0;
    Iterator* it;
    for(it = get_iterator(conditions); iterator_has_value(it); it = iterator_next(it)) {
        Condition* c = it->element;
        if (valid_condition(c))
            size++;
    }
    return size;
}

canonical_original_code:
int valid_condition_size(struct _list *conditions)
{
    int size = 0;
    struct _iterator *it;
    for(it = get_iterator(conditions); iterator_has_value(it); it = iterator_next(it)) {
        struct Condition *c = it->element;
        if (valid_condition(c))
            size++;
    }
    return size;
}

variable_types: size int

variable_types: struct Condition { int element_type_id; int condition_type; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *value; struct _String *cookie_value; } *

user_defined_types: struct Condition { int element_type_id; int condition_type; struct _String *value; struct _String *cookie_value; }


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

if ( string_len(*(_QWORD *)(a1 + 8)) )
result = string_rawstr(*(_QWORD *)(a1 + 8));
else
result = string_rawstr(*(_QWORD *)(a1 + 16));
return result;
}

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

if ( string_len(*(_QWORD *)(a1 + 8)) )
result = string_rawstr(*(_QWORD *)(a1 + 8));
else
result = string_rawstr(*(_QWORD *)(a1 + 16));
return result;
}

original_code:
char* get_condition_valid_value(Condition* c)
{
    return string_len(c->value) ? string_rawstr(c->value) : string_rawstr(c->cookie_value);
}

canonical_original_code:
char *get_condition_valid_value(struct Condition *c)
{
    return string_len(c->value) ? string_rawstr(c->value) : string_rawstr(c->cookie_value);
}


decompiled_code:
void *__fastcall get_condition_value(__int64 a1, int a2, int a3)
{
_DWORD **i; // rbp
_DWORD *v5; // rdi

for ( i = (_DWORD **)get_iterator(); ; i = (_DWORD **)iterator_next(i) )
{
if ( !(unsigned int)iterator_has_value(i) )
return &unk_97B;
v5 = *i;
if ( **i == a2 && v5[1] == a3 )
break;
}
return (void *)get_condition_valid_value((__int64)v5);
}

canonical_decompiled_code:
void *__fastcall func13(__int64 a1, int a2, int a3)
{
_DWORD **i; // rbp
_DWORD *v5; // rdi

for ( i = (_DWORD **)get_iterator(); ; i = (_DWORD **)iterator_next(i) )
{
if ( !(unsigned int)iterator_has_value(i) )
return &unk_97B;
v5 = *i;
if ( **i == a2 && v5[1] == a3 )
break;
}
return (void *)func12((__int64)v5);
}

original_code:
char* get_condition_value(List* conditions, int element_type_id, int condition_type)
{
    Iterator* it;
    for(it = get_iterator(conditions); iterator_has_value(it); it = iterator_next(it)) {
        Condition* c = it->element;
        if (c->element_type_id == element_type_id && c->condition_type == condition_type) {
            return get_condition_valid_value(c);
        }
    }
    return "";
}

canonical_original_code:
char *get_condition_value(struct _list *conditions, int element_type_id, int condition_type)
{
    struct _iterator *it;
    for(it = get_iterator(conditions); iterator_has_value(it); it = iterator_next(it)) {
        struct Condition *c = it->element;
        if (c->element_type_id == element_type_id && c->condition_type == condition_type) {
            return get_condition_valid_value(c);
        }
    }
    return "";
}


decompiled_code:
__int64 project_info_new()
{
__int64 v0; // r12

v0 = xalloc(40LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = string_new();
*(_QWORD *)(v0 + 24) = string_new();
return v0;
}

original_code:
ProjectInfo* project_info_new()
{
    ProjectInfo* pi = _xalloc(sizeof(ProjectInfo), ((void *)0), 0);
    pi->code = string_new();
    pi->project_type = string_new();
    return pi;
}

canonical_original_code:
struct ProjectInfo *project_info_new()
{
    struct ProjectInfo *pi = _xalloc(sizeof(ProjectInfo), ((void *)0), 0);
    pi->code = string_new();
    pi->project_type = string_new();
    return pi;
}

variable_types: struct ProjectInfo { int id; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *code; int sort; struct _String *project_type; int deleted; } *

user_defined_types: struct ProjectInfo { int id; struct _String *code; int sort; struct _String *project_type; int deleted; }


decompiled_code:
__int64 __fastcall project_info_free(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
string_free(*(_QWORD *)(a1 + 24));
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
string_free(*(_QWORD *)(a1 + 24));
return xfree(a1, 0LL, 0LL);
}

original_code:
void project_info_free(ProjectInfo* pi)
{
    string_free(pi->code);
    string_free(pi->project_type);
    _xfree(pi, ((void *)0), 0);;
}

canonical_original_code:
void project_info_free(struct ProjectInfo *pi)
{
    string_free(pi->code);
    string_free(pi->project_type);
    _xfree(pi, ((void *)0), 0);;
}


decompiled_code:
_QWORD *project_new()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(40LL, 0LL, 0LL);
*v0 = string_new();
v0[1] = string_new();
v0[2] = string_new();
v0[4] = string_new();
return v0;
}

canonical_decompiled_code:
_QWORD *func16()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(40LL, 0LL, 0LL);
*v0 = string_new();
v0[1] = string_new();
v0[2] = string_new();
v0[4] = string_new();
return v0;
}

original_code:
Project* project_new()
{
    Project* p = _xalloc(sizeof(Project), ((void *)0), 0);
    p->name = string_new();
    p->home_description = string_new();
    p->home_url = string_new();
    p->locale = string_new();
    return p;
}

canonical_original_code:
struct Project *project_new()
{
    struct Project *p = _xalloc(sizeof(Project), ((void *)0), 0);
    p->name = string_new();
    p->home_description = string_new();
    p->home_url = string_new();
    p->locale = string_new();
    return p;
}

variable_types: struct Project { struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *name; struct _String *home_description; struct _String *home_url; int upload_max_size; struct _String *locale; } *

user_defined_types: struct Project { struct _String *name; struct _String *home_description; struct _String *home_url; int upload_max_size; struct _String *locale; }


decompiled_code:
__int64 __fastcall project_free(_QWORD *a1)
{
string_free(*a1);
string_free(a1[1]);
string_free(a1[2]);
string_free(a1[4]);
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func17(_QWORD *a1)
{
string_free(*a1);
string_free(a1[1]);
string_free(a1[2]);
string_free(a1[4]);
return xfree(a1, 0LL, 0LL);
}

original_code:
void project_free(Project* p)
{
    string_free(p->name);
    string_free(p->home_description);
    string_free(p->home_url);
    string_free(p->locale);
    _xfree(p, ((void *)0), 0);;
}

canonical_original_code:
void project_free(struct Project *p)
{
    string_free(p->name);
    string_free(p->home_description);
    string_free(p->home_url);
    string_free(p->locale);
    _xfree(p, ((void *)0), 0);;
}


decompiled_code:
_QWORD *search_result_new()
{
_QWORD *v0; // r12
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

v0 = (_QWORD *)xalloc(32LL, 0LL, 0LL);
v1 = xalloc(40LL, 0LL, 0LL);
v0[1] = v1;
*(_DWORD *)v1 = 16;
*(_QWORD *)(v1 + 8) = message_new;
*(_QWORD *)(v1 + 16) = message_free;
v2 = xalloc(40LL, 0LL, 0LL);
v0[2] = v2;
*(_DWORD *)v2 = 24;
*(_QWORD *)(v2 + 8) = state_new;
*(_QWORD *)(v2 + 16) = state_free;
v3 = xalloc(40LL, 0LL, 0LL);
v0[3] = v3;
*(_DWORD *)v3 = 24;
*(_QWORD *)(v3 + 8) = element_new;
*(_QWORD *)(v3 + 16) = element_free;
return v0;
}

original_code:
SearchResult* search_result_new()
{
    SearchResult* result = _xalloc(sizeof(SearchResult), ((void *)0), 0);
    result->messages = _xalloc(sizeof(List), ((void *)0), 0); result->messages->element_size = sizeof(Message); result->messages->constructor = (void*)message_new; result->messages->destructor = (void*)message_free;;
    result->states = _xalloc(sizeof(List), ((void *)0), 0); result->states->element_size = sizeof(State); result->states->constructor = (void*)state_new; result->states->destructor = (void*)state_free;;
    result->sums = _xalloc(sizeof(List), ((void *)0), 0); result->sums->element_size = sizeof(Element); result->sums->constructor = (void*)element_new; result->sums->destructor = (void*)element_free;;
    return result;
}

canonical_original_code:
struct SearchResult *search_result_new()
{
    struct SearchResult *result = _xalloc(sizeof(SearchResult), ((void *)0), 0);
    result->messages = _xalloc(sizeof(List), ((void *)0), 0); result->messages->element_size = sizeof(Message); result->messages->constructor = (void *)message_new; result->messages->destructor = (void *)message_free;;
    result->states = _xalloc(sizeof(List), ((void *)0), 0); result->states->element_size = sizeof(State); result->states->constructor = (void *)state_new; result->states->destructor = (void *)state_free;;
    result->sums = _xalloc(sizeof(List), ((void *)0), 0); result->sums->element_size = sizeof(Element); result->sums->constructor = (void *)element_new; result->sums->destructor = (void *)element_free;;
    return result;
}

variable_types: struct SearchResult { int hit_count; int page; struct _list { int element_size; int size; void *(*constructor)(); void (*destructor)(void *); struct _iterator { void *element; struct _iterator *next; } *head; struct _iterator *tail; } *messages; struct _list *states; struct _list *sums; } *

user_defined_types: struct SearchResult { int hit_count; int page; struct _list *messages; struct _list *states; struct _list *sums; }


decompiled_code:
__int64 __fastcall search_result_free(_QWORD *a1)
{
if ( a1[1] )
list_free();
if ( a1[2] )
list_free();
if ( a1[3] )
list_free();
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1)
{
if ( a1[1] )
list_free();
if ( a1[2] )
list_free();
if ( a1[3] )
list_free();
return xfree(a1, 0LL, 0LL);
}

original_code:
void search_result_free(SearchResult* sr)
{
    if (sr->messages) {
        list_free(sr->messages);
    }
    if (sr->states) {
        list_free(sr->states);
    }
    if (sr->sums) {
        list_free(sr->sums);
    }
    _xfree(sr, ((void *)0), 0);;
}

canonical_original_code:
void search_result_free(struct SearchResult *sr)
{
    if (sr->messages) {
        list_free(sr->messages);
    }
    if (sr->states) {
        list_free(sr->states);
    }
    if (sr->sums) {
        list_free(sr->sums);
    }
    _xfree(sr, ((void *)0), 0);;
}


decompiled_code:
__int64 list_item_new()
{
__int64 v0; // r12

v0 = xalloc(24LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = string_new();
return v0;
}

original_code:
ListItem* list_item_new()
{
    ListItem* li = _xalloc(sizeof(ListItem), ((void *)0), 0);
    li->name = string_new();
    return li;
}

canonical_original_code:
struct ListItem *list_item_new()
{
    struct ListItem *li = _xalloc(sizeof(ListItem), ((void *)0), 0);
    li->name = string_new();
    return li;
}

variable_types: struct ListItem { int id; int element_type_id; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *name; int close; int sort; } *

user_defined_types: struct ListItem { int id; int element_type_id; struct _String *name; int close; int sort; }


decompiled_code:
__int64 __fastcall list_item_free(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
return xfree(a1, 0LL, 0LL);
}

original_code:
void list_item_free(ListItem* li)
{
    string_free(li->name);
    _xfree(li, ((void *)0), 0);;
}

canonical_original_code:
void list_item_free(struct ListItem *li)
{
    string_free(li->name);
    _xfree(li, ((void *)0), 0);;
}


decompiled_code:
_QWORD *setting_file_new()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(40LL, 0LL, 0LL);
*v0 = string_new();
v0[1] = string_new();
v0[3] = string_new();
return v0;
}

canonical_decompiled_code:
_QWORD *func22()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(40LL, 0LL, 0LL);
*v0 = string_new();
v0[1] = string_new();
v0[3] = string_new();
return v0;
}

original_code:
SettingFile* setting_file_new()
{
    SettingFile* sf = _xalloc(sizeof(SettingFile), ((void *)0), 0);
    sf->name = string_new();
    sf->file_name = string_new();
    sf->mime_type = string_new();
    return sf;
}

canonical_original_code:
struct SettingFile *setting_file_new()
{
    struct SettingFile *sf = _xalloc(sizeof(SettingFile), ((void *)0), 0);
    sf->name = string_new();
    sf->file_name = string_new();
    sf->mime_type = string_new();
    return sf;
}

variable_types: struct SettingFile { struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *name; struct _String *file_name; int size; struct _String *mime_type; char *content; } *

user_defined_types: struct SettingFile { struct _String *name; struct _String *file_name; int size; struct _String *mime_type; char *content; }


decompiled_code:
__int64 __fastcall setting_file_free(_QWORD *a1)
{
__int64 v2; // rdi

string_free(*a1);
string_free(a1[1]);
string_free(a1[3]);
v2 = a1[4];
if ( v2 )
xfree(v2, 0LL, 0LL);
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func23(_QWORD *a1)
{
__int64 v2; // rdi

string_free(*a1);
string_free(a1[1]);
string_free(a1[3]);
v2 = a1[4];
if ( v2 )
xfree(v2, 0LL, 0LL);
return xfree(a1, 0LL, 0LL);
}

original_code:
void setting_file_free(SettingFile* file)
{
    string_free(file->name);
    string_free(file->file_name);
    string_free(file->mime_type);
    if (file->content)
        _xfree(file->content, ((void *)0), 0);;
    _xfree(file, ((void *)0), 0);;
}

canonical_original_code:
void setting_file_free(struct SettingFile *file)
{
    string_free(file->name);
    string_free(file->file_name);
    string_free(file->mime_type);
    if (file->content)
        _xfree(file->content, ((void *)0), 0);;
    _xfree(file, ((void *)0), 0);;
}


decompiled_code:
_QWORD *element_type_new()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(64LL, 0LL, 0LL);
v0[3] = string_new();
v0[4] = string_new();
v0[6] = string_new();
return v0;
}

canonical_decompiled_code:
_QWORD *func24()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(64LL, 0LL, 0LL);
v0[3] = string_new();
v0[4] = string_new();
v0[6] = string_new();
return v0;
}

original_code:
ElementType* element_type_new()
{
    ElementType* et = _xalloc(sizeof(ElementType), ((void *)0), 0);
    et->name = string_new();
    et->description = string_new();
    et->default_value = string_new();
    return et;
}

canonical_original_code:
struct ElementType *element_type_new()
{
    struct ElementType *et = _xalloc(sizeof(ElementType), ((void *)0), 0);
    et->name = string_new();
    et->description = string_new();
    et->default_value = string_new();
    return et;
}

return_type: struct ElementType { int id; int type; int ticket_property; int reply_property; int required; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *name; struct _String *description; int auto_add_item; struct _String *default_value; int display_in_list; int sort; } *


decompiled_code:
__int64 __fastcall element_type_free(_QWORD *a1)
{
string_free(a1[3]);
string_free(a1[4]);
string_free(a1[6]);
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func25(_QWORD *a1)
{
string_free(a1[3]);
string_free(a1[4]);
string_free(a1[6]);
return xfree(a1, 0LL, 0LL);
}

original_code:
void element_type_free(ElementType* e)
{
    string_free(e->name);
    string_free(e->description);
    string_free(e->default_value);
    _xfree(e, ((void *)0), 0);;
}

canonical_original_code:
void element_type_free(struct ElementType *e)
{
    string_free(e->name);
    string_free(e->description);
    string_free(e->default_value);
    _xfree(e, ((void *)0), 0);;
}


original_code:
void element_type_copy(ElementType* src, ElementType* dest)
{
    dest->id = src->id;
    dest->type = src->type;
    dest->ticket_property = src->ticket_property;
    dest->reply_property = src->reply_property;
    dest->required = src->required;
    dest->name = string_new();
    string_set(dest->name, string_rawstr(src->name));
    dest->description = string_new();
    string_set(dest->description, string_rawstr(src->description));
    dest->auto_add_item = src->auto_add_item;
    dest->default_value = string_new();
    string_set(dest->default_value, string_rawstr(src->default_value));
    dest->display_in_list = src->display_in_list;
    dest->sort = src->sort;
}

canonical_original_code:
void element_type_copy(struct ElementType *src, struct ElementType *dest)
{
    dest->id = src->id;
    dest->type = src->type;
    dest->ticket_property = src->ticket_property;
    dest->reply_property = src->reply_property;
    dest->required = src->required;
    dest->name = string_new();
    string_set(dest->name, string_rawstr(src->name));
    dest->description = string_new();
    string_set(dest->description, string_rawstr(src->description));
    dest->auto_add_item = src->auto_add_item;
    dest->default_value = string_new();
    string_set(dest->default_value, string_rawstr(src->default_value));
    dest->display_in_list = src->display_in_list;
    dest->sort = src->sort;
}

variable_types:
dest
struct ElementType *


decompiled_code:
__int64 element_file_new()
{
__int64 v0; // r12

v0 = xalloc(40LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = string_new(40LL, 0LL);
*(_QWORD *)(v0 + 24) = string_new(40LL, 0LL);
return v0;
}

original_code:
ElementFile* element_file_new()
{
    ElementFile* ef = _xalloc(sizeof(ElementFile), ((void *)0), 0);
    ef->name = string_new();
    ef->mime_type = string_new();
    return ef;
}

canonical_original_code:
struct ElementFile *element_file_new()
{
    struct ElementFile *ef = _xalloc(sizeof(ElementFile), ((void *)0), 0);
    ef->name = string_new();
    ef->mime_type = string_new();
    return ef;
}

variable_types: struct ElementFile { int id; int element_type_id; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *name; int size; struct _String *mime_type; char *content; } *

user_defined_types: struct ElementFile { int id; int element_type_id; struct _String *name; int size; struct _String *mime_type; char *content; }


decompiled_code:
__int64 __fastcall element_file_free(_QWORD *a1)
{
__int64 v2; // rdi

string_free(a1[1]);
string_free(a1[3]);
v2 = a1[4];
if ( v2 )
xfree(v2, 0LL, 0LL);
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func28(_QWORD *a1)
{
__int64 v2; // rdi

string_free(a1[1]);
string_free(a1[3]);
v2 = a1[4];
if ( v2 )
xfree(v2, 0LL, 0LL);
return xfree(a1, 0LL, 0LL);
}

original_code:
void element_file_free(ElementFile* ef)
{
    string_free(ef->name);
    string_free(ef->mime_type);
    if (ef->content)
        _xfree(ef->content, ((void *)0), 0);;
    _xfree(ef, ((void *)0), 0);;
}

canonical_original_code:
void element_file_free(struct ElementFile *ef)
{
    string_free(ef->name);
    string_free(ef->mime_type);
    if (ef->content)
        _xfree(ef->content, ((void *)0), 0);;
    _xfree(ef, ((void *)0), 0);;
}


decompiled_code:
__int64 condition_new()
{
__int64 v0; // r12

v0 = xalloc(24LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = string_new(24LL, 0LL);
*(_QWORD *)(v0 + 16) = string_new(24LL, 0LL);
return v0;
}

original_code:
Condition* condition_new()
{
    Condition* c = _xalloc(sizeof(Condition), ((void *)0), 0);
    c->value = string_new();
    c->cookie_value = string_new();
    return c;
}

canonical_original_code:
struct Condition *condition_new()
{
    struct Condition *c = _xalloc(sizeof(Condition), ((void *)0), 0);
    c->value = string_new();
    c->cookie_value = string_new();
    return c;
}

return_type: struct Condition { int element_type_id; int condition_type; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *value; struct _String *cookie_value; } *


decompiled_code:
__int64 __fastcall condition_free(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
string_free(*(_QWORD *)(a1 + 16));
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
string_free(*(_QWORD *)(a1 + 16));
return xfree(a1, 0LL, 0LL);
}

original_code:
void condition_free(Condition* c)
{
    string_free(c->value);
    string_free(c->cookie_value);
    _xfree(c, ((void *)0), 0);;
}

canonical_original_code:
void condition_free(struct Condition *c)
{
    string_free(c->value);
    string_free(c->cookie_value);
    _xfree(c, ((void *)0), 0);;
}


decompiled_code:
__int64 wiki_new()
{
__int64 v0; // r12

v0 = xalloc(24LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = string_new(24LL, 0LL);
return v0;
}

original_code:
Wiki* wiki_new()
{
    Wiki* w = _xalloc(sizeof(Wiki), ((void *)0), 0);
    w->name = string_new();
    return w;
}

canonical_original_code:
struct Wiki *wiki_new()
{
    struct Wiki *w = _xalloc(sizeof(Wiki), ((void *)0), 0);
    w->name = string_new();
    return w;
}

variable_types: struct Wiki { int id; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *name; char *content; } *

user_defined_types: struct Wiki { int id; struct _String *name; char *content; }


decompiled_code:
__int64 __fastcall wiki_free(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
xfree(*(_QWORD *)(a1 + 16), 0LL, 0LL);
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func32(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
xfree(*(_QWORD *)(a1 + 16), 0LL, 0LL);
return xfree(a1, 0LL, 0LL);
}

original_code:
void wiki_free(Wiki* wiki)
{
    string_free(wiki->name);
    _xfree(wiki->content, ((void *)0), 0);;
    _xfree(wiki, ((void *)0), 0);;
}

canonical_original_code:
void wiki_free(struct Wiki *wiki)
{
    string_free(wiki->name);
    _xfree(wiki->content, ((void *)0), 0);;
    _xfree(wiki, ((void *)0), 0);;
}


decompiled_code:
_QWORD *ticket_new()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(40LL, 0LL, 0LL);
v0[1] = string_new(40LL, 0LL);
v0[2] = string_new(40LL, 0LL);
v0[4] = string_new(40LL, 0LL);
return v0;
}

canonical_decompiled_code:
_QWORD *func33()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(40LL, 0LL, 0LL);
v0[1] = string_new(40LL, 0LL);
v0[2] = string_new(40LL, 0LL);
v0[4] = string_new(40LL, 0LL);
return v0;
}

original_code:
Ticket* ticket_new()
{
    Ticket* t = _xalloc(sizeof(Ticket), ((void *)0), 0);
    t->project_code = string_new();
    t->project_name = string_new();
    t->title = string_new();
    return t;
}

canonical_original_code:
struct Ticket *ticket_new()
{
    struct Ticket *t = _xalloc(sizeof(Ticket), ((void *)0), 0);
    t->project_code = string_new();
    t->project_name = string_new();
    t->title = string_new();
    return t;
}

variable_types: struct Ticket { int project_id; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *project_code; struct _String *project_name; int id; struct _String *title; } *

user_defined_types: struct Ticket { int project_id; struct _String *project_code; struct _String *project_name; int id; struct _String *title; }


decompiled_code:
__int64 __fastcall ticket_free(_QWORD *a1)
{
string_free(a1[1]);
string_free(a1[2]);
string_free(a1[4]);
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func34(_QWORD *a1)
{
string_free(a1[1]);
string_free(a1[2]);
string_free(a1[4]);
return xfree(a1, 0LL, 0LL);
}

original_code:
void ticket_free(Ticket* t)
{
    string_free(t->project_code);
    string_free(t->project_name);
    string_free(t->title);
    _xfree(t, ((void *)0), 0);;
}

canonical_original_code:
void ticket_free(struct Ticket *t)
{
    string_free(t->project_code);
    string_free(t->project_name);
    string_free(t->title);
    _xfree(t, ((void *)0), 0);;
}


decompiled_code:
__int64 burndown_chart_point_new()
{
__int64 v0; // r12

v0 = xalloc(16LL, 0LL, 0LL);
*(_QWORD *)(v0 + 8) = string_new(16LL, 0LL);
return v0;
}

original_code:
BurndownChartPoint* burndown_chart_point_new()
{
    BurndownChartPoint* b = _xalloc(sizeof(BurndownChartPoint), ((void *)0), 0);
    b->day = string_new();
    return b;
}

canonical_original_code:
struct BurndownChartPoint *burndown_chart_point_new()
{
    struct BurndownChartPoint *b = _xalloc(sizeof(BurndownChartPoint), ((void *)0), 0);
    b->day = string_new();
    return b;
}

variable_types: struct BurndownChartPoint { int all; int not_closed; struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *day; } *

user_defined_types: struct BurndownChartPoint { int all; int not_closed; struct _String *day; }


decompiled_code:
__int64 __fastcall burndown_chart_point_free(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func36(__int64 a1)
{
string_free(*(_QWORD *)(a1 + 8));
return xfree(a1, 0LL, 0LL);
}

original_code:
void burndown_chart_point_free(BurndownChartPoint* b)
{
    string_free(b->day);
    _xfree(b, ((void *)0), 0);;
}

canonical_original_code:
void burndown_chart_point_free(struct BurndownChartPoint *b)
{
    string_free(b->day);
    _xfree(b, ((void *)0), 0);;
}


decompiled_code:
_QWORD *user_ranking_new()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(16LL, 0LL, 0LL);
*v0 = string_new(16LL, 0LL);
return v0;
}

canonical_decompiled_code:
_QWORD *func37()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(16LL, 0LL, 0LL);
*v0 = string_new(16LL, 0LL);
return v0;
}

original_code:
UserRanking* user_ranking_new()
{
    UserRanking* u = _xalloc(sizeof(UserRanking), ((void *)0), 0);
    u->name = string_new();
    return u;
}

canonical_original_code:
struct UserRanking *user_ranking_new()
{
    struct UserRanking *u = _xalloc(sizeof(UserRanking), ((void *)0), 0);
    u->name = string_new();
    return u;
}

variable_types: struct UserRanking { struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *name; int count; } *

user_defined_types: struct UserRanking { struct _String *name; int count; }


decompiled_code:
__int64 __fastcall user_ranking_free(_QWORD *a1)
{
string_free(*a1);
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func38(_QWORD *a1)
{
string_free(*a1);
return xfree(a1, 0LL, 0LL);
}

original_code:
void user_ranking_free(UserRanking* u)
{
    string_free(u->name);
    _xfree(u, ((void *)0), 0);;
}

canonical_original_code:
void user_ranking_free(struct UserRanking *u)
{
    string_free(u->name);
    _xfree(u, ((void *)0), 0);;
}


decompiled_code:
__int64 __fastcall enc_char(unsigned __int64 a1, int a2, __int64 a3, int a4)
{
int v5; // er10
int i; // eax
int v7; // ebx
__int64 v8; // rdx
int v9; // ecx
unsigned __int64 v10; // rax
__int64 result; // rax
int v12; // esi
__int64 v13; // r10
unsigned int v14; // ecx
__int64 v15; // rdx

v5 = a4;
if ( a2 <= 1 )
{
for ( i = a2; i != 2; ++i )
a1 <<= 8;
}
v7 = a2 + 1;
if ( a2 + 1 < 0 )
{
v12 = 0;
}
else
{
v8 = a3 + a4;
v9 = 18;
do
{
++v8;
v10 = a1 >> v9;
v9 -= 6;
result = (unsigned __int8)LC0[v10 & 0x3F];
*(_BYTE *)(v8 - 1) = result;
}
while ( -6 * a2 + 6 != v9 );
v12 = a2 + 2;
v5 += v7 + 1;
if ( v12 > 3 )
return result;
}
result = (unsigned int)(4 - v12);
v13 = a3 + v5;
v14 = result;
if ( (_DWORD)result )
{
LODWORD(result) = 0;
do
{
v15 = (unsigned int)result;
result = (unsigned int)(result + 1);
*(_BYTE *)(v13 + v15) = 61;
}
while ( (unsigned int)result < v14 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1, int a2, __int64 a3, int a4)
{
int v5; // er10
int i; // eax
int v7; // ebx
__int64 v8; // rdx
int v9; // ecx
unsigned __int64 v10; // rax
__int64 result; // rax
int v12; // esi
__int64 v13; // r10
unsigned int v14; // ecx
__int64 v15; // rdx

v5 = a4;
if ( a2 <= 1 )
{
for ( i = a2; i != 2; ++i )
a1 <<= 8;
}
v7 = a2 + 1;
if ( a2 + 1 < 0 )
{
v12 = 0;
}
else
{
v8 = a3 + a4;
v9 = 18;
do
{
++v8;
v10 = a1 >> v9;
v9 -= 6;
result = (unsigned __int8)LC0[v10 & 0x3F];
*(_BYTE *)(v8 - 1) = result;
}
while ( -6 * a2 + 6 != v9 );
v12 = a2 + 2;
v5 += v7 + 1;
if ( v12 > 3 )
return result;
}
result = (unsigned int)(4 - v12);
v13 = a3 + v5;
v14 = result;
if ( (_DWORD)result )
{
LODWORD(result) = 0;
do
{
v15 = (unsigned int)result;
result = (unsigned int)(result + 1);
*(_BYTE *)(v13 + v15) = 61;
}
while ( (unsigned int)result < v14 );
}
return result;
}

original_code:
static void enc_char(unsigned long bb, int srclen, unsigned char *dist, int j)
{
    int x, i, base;
    for (i = srclen; i < 2; i++)
        bb <<= 8;
    for (base = 18, x = 0; x < srclen + 2; x++, base -= 6) {
        dist[j++] = base64[(unsigned long)((bb>>base) & 0x3F)];
    }
    for (i = x; i < 4; i++) {
        dist[j++] = (unsigned char)'=';
    }
}

canonical_original_code:
static void enc_char(unsigned long bb, int srclen, unsigned char *dist, int j)
{
    int x; int i; int base;
    for (i = srclen; i < 2; i++)
        bb <<= 8;
    for (base = 18, x = 0; x < srclen + 2; x++, base -= 6) {
        dist[j++] = base64[(unsigned long)((bb>>base) & 0x3F)];
    }
    for (i = x; i < 4; i++) {
        dist[j++] = (unsigned char)'=';
    }
}

variable_types:
bb
unsigned long

variable_types: srclen int

variable_types:
dist
unsigned char *

variable_types: j int

variable_types: x int

variable_types: i int

variable_types: base int


decompiled_code:
__int64 __fastcall base64_enc(unsigned __int8 *a1, __int64 a2)
{
__int64 result; // rax
int v4; // esi
int v5; // er12
unsigned __int8 *v6; // rbx
unsigned __int64 v7; // rdi
int v8; // ecx

result = *a1;
if ( (_BYTE)result )
{
v4 = 0;
v5 = 0;
v6 = a1;
v7 = 0LL;
do
{
while ( 1 )
{
v7 = (v7 << 8) | (unsigned __int8)result;
if ( v4 == 2 )
break;
result = *++v6;
++v4;
if ( !(_BYTE)result )
goto LABEL_6;
}
v8 = v5;
++v6;
v5 += 4;
enc_char(v7, 2, a2, v8);
result = *v6;
v4 = 0;
v7 = 0LL;
}
while ( (_BYTE)result );
LABEL_6:
if ( v4 )
result = enc_char(v7, v4 - 1, a2, v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1, __int64 a2)
{
__int64 result; // rax
int v4; // esi
int v5; // er12
unsigned __int8 *v6; // rbx
unsigned __int64 v7; // rdi
int v8; // ecx

result = *a1;
if ( (_BYTE)result )
{
v4 = 0;
v5 = 0;
v6 = a1;
v7 = 0LL;
do
{
while ( 1 )
{
v7 = (v7 << 8) | (unsigned __int8)result;
if ( v4 == 2 )
break;
result = *++v6;
++v4;
if ( !(_BYTE)result )
goto LABEL_6;
}
v8 = v5;
++v6;
v5 += 4;
func0(v7, 2, a2, v8);
result = *v6;
v4 = 0;
v7 = 0LL;
}
while ( (_BYTE)result );
LABEL_6:
if ( v4 )
result = func0(v7, v4 - 1, a2, v5);
}
return result;
}

original_code:
static void base64_enc(const unsigned char *src, unsigned char *dist)
{
    unsigned char *p = (unsigned char*)src;
    unsigned long bb = (unsigned long)0;
    int i = 0, j = 0;
    while (*p) {
        bb <<= 8;
        bb |= (unsigned long)*p;
        if (i == 2) {
            enc_char(bb, i, dist, j);
            j = j + 4;
            i = 0;
            bb = 0;
        } else {
            i++;
        }
        p++;
    }
    if (i) enc_char(bb, i - 1, dist, j);
}

canonical_original_code:
static void base64_enc(unsigned char *src, unsigned char *dist)
{
    unsigned char *p = (unsigned char*)src;
    unsigned long bb = (unsigned long)0;
    int i = 0; int j = 0;
    while (*p) {
        bb <<= 8;
        bb |= (unsigned long)*p;
        if (i == 2) {
            enc_char(bb, i, dist, j);
            j = j + 4;
            i = 0;
            bb = 0;
        } else {
            i++;
        }
        p++;
    }
    if (i) enc_char(bb, i - 1, dist, j);
}

variable_types:
src
unsigned char *

variable_types:
p
unsigned char *


xfree

decompiled_code:
// attributes: thunk
void xfree(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func3(void *ptr)
{
free(ptr);
}

original_code:
static void xfree(void* p)
{
    free(p);
    p = ((void *)0);
}

canonical_original_code:
static void xfree(void *p)
{
    free(p);
    p = ((void *)0);
}

variable_types:
p
void *


conv

decompiled_code:
int __fastcall conv(const char *a1, char *a2)
{
char v2; // dl
char *i; // rax
char v4; // dl

v2 = *a2;
for ( i = (char *)a1; *a2; v2 = *a2 )
{
if ( v2 == 10 )
*i++ = 13;
v4 = *a2++;
*i++ = v4;
}
*i = 0;
return printf("conv: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, char *a2)
{
char v2; // dl
char *i; // rax
char v4; // dl

v2 = *a2;
for ( i = (char *)a1; *a2; v2 = *a2 )
{
if ( v2 == 10 )
*i++ = 13;
v4 = *a2++;
*i++ = v4;
}
*i = 0;
return printf("conv: %s\n", a1);
}

original_code:
void conv(char* dest, char* src)
{
    char* p = src;
    char* p_dest = dest;
    while (*p) {
        if (*p == '\n') {
            *p_dest = '\r';
            p_dest++;
        }
        *p_dest = *p;
        p++;
        p_dest++;
    }
    *p_dest = '\0';
    printf("conv: %s\n", dest);
}

canonical_original_code:
void conv(char *dest, char *src)
{
    char *p = src;
    char *p_dest = dest;
    while (*p) {
        if (*p == '\n') {
            *p_dest = '\r';
            p_dest++;
        }
        *p_dest = *p;
        p++;
        p_dest++;
    }
    *p_dest = '\0';
    printf("conv: %s\n", dest);
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
p
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return 0;
}

original_code:
int main(int argc, char** argv)
{
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
_QWORD *string_new()
{
return string_new_by_block_size(0LL);
}

canonical_decompiled_code:
_QWORD *func0()
{
return string_new_by_block_size(0LL);
}

original_code:
String* string_new()
{
    return string_new_by_block_size(0);
}

canonical_original_code:
struct _String *string_new()
{
    return string_new_by_block_size(0);
}

return_type: struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *


decompiled_code:
char *__fastcall string_append(__int64 a1, const char *a2)
{
size_t v3; // rax
void *v4; // rdi
size_t v5; // r12
unsigned __int64 v6; // rax
size_t v7; // rbp
void *v8; // rax
char *result; // rax

v3 = strlen(a2);
v4 = *(void **)a1;
v5 = v3;
v6 = v3 + *(_QWORD *)(a1 + 24) + 1;
if ( *(_QWORD *)(a1 + 16) < v6 )
{
v7 = (int)(*(_QWORD *)(a1 + 8) * (v6 / *(_QWORD *)(a1 + 8) + 1));
v8 = realloc(v4, v7);
*(_QWORD *)a1 = v8;
v4 = v8;
if ( !v8 )
{
fwrite("memory error.", 1uLL, 0xDuLL, stderr);
exit(-1);
}
*(_QWORD *)(a1 + 16) = v7;
}
result = strcat((char *)v4, a2);
*(_QWORD *)(a1 + 24) += v5;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, const char *a2)
{
size_t v3; // rax
void *v4; // rdi
size_t v5; // r12
unsigned __int64 v6; // rax
size_t v7; // rbp
void *v8; // rax
char *result; // rax

v3 = strlen(a2);
v4 = *(void **)a1;
v5 = v3;
v6 = v3 + *(_QWORD *)(a1 + 24) + 1;
if ( *(_QWORD *)(a1 + 16) < v6 )
{
v7 = (int)(*(_QWORD *)(a1 + 8) * (v6 / *(_QWORD *)(a1 + 8) + 1));
v8 = realloc(v4, v7);
*(_QWORD *)a1 = v8;
v4 = v8;
if ( !v8 )
{
fwrite("memory error.", 1uLL, 0xDuLL, stderr);
exit(-1);
}
*(_QWORD *)(a1 + 16) = v7;
}
result = strcat((char *)v4, a2);
*(_QWORD *)(a1 + 24) += v5;
return result;
}

original_code:
void string_append(String* str, const char* addstr)
{
    size_t len = strlen(addstr);
    size_t size_needed = str->current_size + len + 1;
    if (size_needed > str->buf_size) {
        int new_size = str->block_size * (size_needed / str->block_size + 1);
        str->raw_chars = realloc(str->raw_chars, sizeof(char) * new_size);
        if (!str->raw_chars) {
            fprintf(stderr, "memory error.");
            exit(-1);
        }
        str->buf_size = new_size;
    }
    strcat(str->raw_chars, (char*)addstr);
    str->current_size += len;
}

canonical_original_code:
void string_append(struct _String *str, char *addstr)
{
    unsigned long len = strlen(addstr);
    unsigned long size_needed = str->current_size + len + 1;
    if (size_needed > str->buf_size) {
        int new_size = str->block_size * (size_needed / str->block_size + 1);
        str->raw_chars = realloc(str->raw_chars, sizeof(char) * new_size);
        if (!str->raw_chars) {
            fprintf(stderr, "memory error.");
            exit(-1);
        }
        str->buf_size = new_size;
    }
    strcat(str->raw_chars, (char *)addstr);
    str->current_size += len;
}

variable_types: struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *

variable_types:
addstr
char *

variable_types:
len
unsigned long


decompiled_code:
char *__fastcall string_set(_QWORD *a1, const char *a2)
{
xfree(*a1, 0LL, 0LL);
string_init(a1, a1[1]);
return string_append((__int64)a1, a2);
}

canonical_decompiled_code:
char *__fastcall func2(_QWORD *a1, const char *a2)
{
xfree(*a1, 0LL, 0LL);
string_init(a1, a1[1]);
return func1((__int64)a1, a2);
}

original_code:
void string_set(String* str, const char* newstr)
{
    _xfree(str->raw_chars, ((void *)0), 0);;
    string_init(str, str->block_size);
    string_append(str, newstr);
}

canonical_original_code:
void string_set(struct _String *str, char *newstr)
{
    _xfree(str->raw_chars, ((void *)0), 0);;
    string_init(str, str->block_size);
    string_append(str, newstr);
}

variable_types:
newstr
char *


decompiled_code:
__int64 __fastcall string_rawstr(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
char* string_rawstr(String* str)
{
    return str->raw_chars;
}

canonical_original_code:
char *string_rawstr(struct _String *str)
{
    return str->raw_chars;
}


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

v2 = *a1;
if ( v2 )
xfree(v2, 0LL, 0LL);
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
__int64 v2; // rdi

v2 = *a1;
if ( v2 )
xfree(v2, 0LL, 0LL);
return xfree(a1, 0LL, 0LL);
}

original_code:
void string_free(String* str)
{
    if (str->raw_chars)
        _xfree(str->raw_chars, ((void *)0), 0);;
    _xfree(str, ((void *)0), 0);;
}

canonical_original_code:
void string_free(struct _String *str)
{
    if (str->raw_chars)
        _xfree(str->raw_chars, ((void *)0), 0);;
    _xfree(str, ((void *)0), 0);;
}


decompiled_code:
__int64 __fastcall string_len(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
size_t string_len(String* str)
{
    return str->current_size;
}

canonical_original_code:
unsigned long string_len(struct _String *str)
{
    return str->current_size;
}


decompiled_code:
__int64 __fastcall string_replace(char **a1, char a2, const char *a3)
{
char **v4; // rax
_BYTE *v5; // r14
char **v6; // rbp
__int64 v7; // rdx
char s[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v4 = (char **)string_new();
v5 = *a1;
v6 = v4;
v7 = (unsigned int)**a1;
if ( **a1 )
{
do
{
while ( a2 != (_BYTE)v7 )
{
++v5;
sprintf(s, "%c", v7);
string_append((__int64)v6, s);
v7 = (unsigned int)(char)*v5;
if ( !*v5 )
goto LABEL_6;
}
++v5;
string_append((__int64)v6, a3);
v7 = (unsigned int)(char)*v5;
}
while ( *v5 );
LABEL_6:
v5 = *a1;
}
xfree(v5, 0LL, 0LL);
*a1 = *v6;
a1[1] = v6[1];
a1[2] = v6[2];
a1[3] = v6[3];
return xfree(v6, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(char **a1, char a2, const char *a3)
{
char **v4; // rax
_BYTE *v5; // r14
char **v6; // rbp
__int64 v7; // rdx
char s[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v4 = (char **)func0();
v5 = *a1;
v6 = v4;
v7 = (unsigned int)**a1;
if ( **a1 )
{
do
{
while ( a2 != (_BYTE)v7 )
{
++v5;
sprintf(s, "%c", v7);
func1((__int64)v6, s);
v7 = (unsigned int)(char)*v5;
if ( !*v5 )
goto LABEL_6;
}
++v5;
func1((__int64)v6, a3);
v7 = (unsigned int)(char)*v5;
}
while ( *v5 );
LABEL_6:
v5 = *a1;
}
xfree(v5, 0LL, 0LL);
*a1 = *v6;
a1[1] = v6[1];
a1[2] = v6[2];
a1[3] = v6[3];
return xfree(v6, 0LL, 0LL);
}

original_code:
void string_replace(String* str, char target_char, char* newchars)
{
    String* new_string_a = string_new(str->block_size);
    char* src = str->raw_chars;
    while (*src) {
        if (*src == target_char) {
            string_append(new_string_a, newchars);
        } else {
            char dist[2];
            sprintf(dist, "%c", *src);
            string_append(new_string_a, dist);
        }
        src++;
    }
    _xfree(str->raw_chars, ((void *)0), 0);;
    str->raw_chars = new_string_a->raw_chars;
    str->block_size = new_string_a->block_size;
    str->buf_size = new_string_a->buf_size;
    str->current_size = new_string_a->current_size;
    _xfree(new_string_a, ((void *)0), 0);;
}

canonical_original_code:
void string_replace(struct _String *str, char target_char, char *newchars)
{
    struct _String *new_string_a = string_new(str->block_size);
    char *src = str->raw_chars;
    while (*src) {
        if (*src == target_char) {
            string_append(new_string_a, newchars);
        } else {
            char dist[2];
            sprintf(dist, "%c", *src);
            string_append(new_string_a, dist);
        }
        src++;
    }
    _xfree(str->raw_chars, ((void *)0), 0);;
    str->raw_chars = new_string_a->raw_chars;
    str->block_size = new_string_a->block_size;
    str->buf_size = new_string_a->buf_size;
    str->current_size = new_string_a->current_size;
    _xfree(new_string_a, ((void *)0), 0);;
}

variable_types:
newchars
char *

variable_types:
dist
char [2]


decompiled_code:
__int64 __fastcall encode_char(unsigned __int64 a1, int a2, __int64 a3, int a4)
{
int v5; // er9
int i; // eax
int v7; // er11
__int64 v8; // rdx
int v9; // ecx
unsigned __int64 v10; // rax
__int64 result; // rax
int v12; // esi
__int64 v13; // r9
unsigned int v14; // ecx
__int64 v15; // rdx

v5 = a4;
if ( a2 <= 1 )
{
for ( i = a2; i != 2; ++i )
a1 <<= 8;
}
v7 = a2 + 1;
if ( a2 + 1 < 0 )
{
v12 = 0;
}
else
{
v8 = a3 + a4;
v9 = 18;
do
{
++v8;
v10 = a1 >> v9;
v9 -= 6;
result = (unsigned __int8)byte_458[v10 & 0x3F];
*(_BYTE *)(v8 - 1) = result;
}
while ( -6 * a2 + 6 != v9 );
v12 = a2 + 2;
v5 += v7 + 1;
if ( v12 > 3 )
return result;
}
result = (unsigned int)(4 - v12);
v13 = a3 + v5;
v14 = result;
if ( (_DWORD)result )
{
LODWORD(result) = 0;
do
{
v15 = (unsigned int)result;
result = (unsigned int)(result + 1);
*(_BYTE *)(v13 + v15) = 61;
}
while ( (unsigned int)result < v14 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1, int a2, __int64 a3, int a4)
{
int v5; // er9
int i; // eax
int v7; // er11
__int64 v8; // rdx
int v9; // ecx
unsigned __int64 v10; // rax
__int64 result; // rax
int v12; // esi
__int64 v13; // r9
unsigned int v14; // ecx
__int64 v15; // rdx

v5 = a4;
if ( a2 <= 1 )
{
for ( i = a2; i != 2; ++i )
a1 <<= 8;
}
v7 = a2 + 1;
if ( a2 + 1 < 0 )
{
v12 = 0;
}
else
{
v8 = a3 + a4;
v9 = 18;
do
{
++v8;
v10 = a1 >> v9;
v9 -= 6;
result = (unsigned __int8)byte_458[v10 & 0x3F];
*(_BYTE *)(v8 - 1) = result;
}
while ( -6 * a2 + 6 != v9 );
v12 = a2 + 2;
v5 += v7 + 1;
if ( v12 > 3 )
return result;
}
result = (unsigned int)(4 - v12);
v13 = a3 + v5;
v14 = result;
if ( (_DWORD)result )
{
LODWORD(result) = 0;
do
{
v15 = (unsigned int)result;
result = (unsigned int)(result + 1);
*(_BYTE *)(v13 + v15) = 61;
}
while ( (unsigned int)result < v14 );
}
return result;
}

original_code:
static void encode_char(unsigned long bb, int srclen, unsigned char *dist, int j)
{
    int x, i, base;
    for (i = srclen; i < 2; i++)
        bb <<= 8;
    for (base = 18, x = 0; x < srclen + 2; x++, base -= 6) {
        dist[j++] = base64[(unsigned long)((bb>>base) & 0x3F)];
    }
    for (i = x; i < 4; i++) {
        dist[j++] = (unsigned char)'=';
    }
}

canonical_original_code:
static void encode_char(unsigned long bb, int srclen, unsigned char *dist, int j)
{
    int x; int i; int base;
    for (i = srclen; i < 2; i++)
        bb <<= 8;
    for (base = 18, x = 0; x < srclen + 2; x++, base -= 6) {
        dist[j++] = base64[(unsigned long)((bb>>base) & 0x3F)];
    }
    for (i = x; i < 4; i++) {
        dist[j++] = (unsigned char)'=';
    }
}

variable_types:
bb
unsigned long

variable_types: srclen int

variable_types:
dist
unsigned char *

variable_types: j int

variable_types: x int


codetovalue

decompiled_code:
__int64 __fastcall codetovalue(unsigned __int8 a1)
{
if ( (unsigned __int8)(a1 - 65) <= 0x19u )
return a1 - 65;
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return a1 - 71;
if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned __int8)(a1 + 4);
if ( a1 == 43 )
return 62LL;
if ( a1 == 47 )
return 63LL;
return -(__int64)(a1 != 61);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
if ( (unsigned __int8)(a1 - 65) <= 0x19u )
return a1 - 65;
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return a1 - 71;
if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned __int8)(a1 + 4);
if ( a1 == 43 )
return 62LL;
if ( a1 == 47 )
return 63LL;
return -(__int64)(a1 != 61);
}

original_code:
static long codetovalue(unsigned char c)
{
    if( (c >= (unsigned char)'A') && (c <= (unsigned char)'Z') ) {
        return (long)(c - (unsigned char)'A');
    }
    else if( (c >= (unsigned char)'a') && (c <= (unsigned char)'z') ) {
        return ((long)(c - (unsigned char)'a') +26);
    }
    else if( (c >= (unsigned char)'0') && (c <= (unsigned char)'9') ) {
        return ((long)(c - (unsigned char)'0') +52);
    }
    else if( (unsigned char)'+' == c ) {
        return (long)62;
    }
    else if( (unsigned char)'/' == c ) {
        return (long)63;
    }
    else if( (unsigned char)'=' == c ) {
        return (long)0;
    }
    else {
        return -1;
    }
}

variable_types:
c
unsigned char

return_type: long


decompiled_code:
__int64 __fastcall decode_str(int a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rsi
unsigned __int8 v4; // al
__int64 v5; // rcx
int v6; // er8
_BYTE *v7; // r9
int v8; // er10
int v9; // edx
int v10; // edx
unsigned __int8 v11; // di
int v13; // edx

v2 = 0LL;
v3 = a1 + a2;
do
{
v11 = *(_BYTE *)(v3 + v2);
if ( !v11 )
return 0xFFFFFFFFLL;
v4 = codetovalue(v11);
v10 = v4 | v9;
if ( v5 != 3 )
v10 <<= 6;
v2 = v5 + 1;
}
while ( v6 + (int)v2 <= v8 );
v13 = v10 << 8;
*v7 = HIBYTE(v13);
v7[2] = BYTE1(v13);
v7[1] = BYTE2(v13);
return 0LL;
}

original_code:
static int decode_str(int enc_ptr, const unsigned char *src, unsigned char *dest)
{
    int i, j;
    unsigned long base64 = 0;
    unsigned char x;
    Union_data_t bb;
    for (i = enc_ptr; i < enc_ptr + 4; i++) {
        if (src[i] == '\0') return -1;
        x = codetovalue(src[i]);
        base64 |= x;
        if ((i - enc_ptr) != 3) base64 <<= 6;
    }
    base64 <<= 8;
    bb.data = base64;
    for (j = 0, i = 3; i >= 1; i--) {
        dest[j++] = bb.xyz[i];
    }
    return 0;
}

canonical_original_code:
static int decode_str(int enc_ptr, unsigned char *src, unsigned char *dest)
{
    int i; int j;
    unsigned long base64 = 0;
    unsigned char x;
    union Union_data_t bb;
    for (i = enc_ptr; i < enc_ptr + 4; i++) {
        if (src[i] == '\0') return -1;
        x = codetovalue(src[i]);
        base64 |= x;
        if ((i - enc_ptr) != 3) base64 <<= 6;
    }
    base64 <<= 8;
    bb.data = base64;
    for (j = 0, i = 3; i >= 1; i--) {
        dest[j++] = bb.xyz[i];
    }
    return 0;
}

variable_types:
src
unsigned char *

variable_types:
dest
unsigned char *

variable_types: i int

variable_types:
x
unsigned char

variable_types: union Union_data_t { unsigned int data; unsigned char xyz[4]; }


decompiled_code:
__int64 __fastcall base64_encode(unsigned __int8 *a1, __int64 a2)
{
__int64 result; // rax
int v4; // esi
int v5; // er12
unsigned __int8 *v6; // rbx
unsigned __int64 v7; // rdi
int v8; // ecx

result = *a1;
if ( (_BYTE)result )
{
v4 = 0;
v5 = 0;
v6 = a1;
v7 = 0LL;
do
{
while ( 1 )
{
v7 = (v7 << 8) | (unsigned __int8)result;
if ( v4 == 2 )
break;
result = *++v6;
++v4;
if ( !(_BYTE)result )
goto LABEL_6;
}
v8 = v5;
++v6;
v5 += 4;
encode_char(v7, 2, a2, v8);
result = *v6;
v4 = 0;
v7 = 0LL;
}
while ( (_BYTE)result );
LABEL_6:
if ( v4 )
result = encode_char(v7, v4 - 1, a2, v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1, __int64 a2)
{
__int64 result; // rax
int v4; // esi
int v5; // er12
unsigned __int8 *v6; // rbx
unsigned __int64 v7; // rdi
int v8; // ecx

result = *a1;
if ( (_BYTE)result )
{
v4 = 0;
v5 = 0;
v6 = a1;
v7 = 0LL;
do
{
while ( 1 )
{
v7 = (v7 << 8) | (unsigned __int8)result;
if ( v4 == 2 )
break;
result = *++v6;
++v4;
if ( !(_BYTE)result )
goto LABEL_6;
}
v8 = v5;
++v6;
v5 += 4;
func0(v7, 2, a2, v8);
result = *v6;
v4 = 0;
v7 = 0LL;
}
while ( (_BYTE)result );
LABEL_6:
if ( v4 )
result = func0(v7, v4 - 1, a2, v5);
}
return result;
}

original_code:
void base64_encode(const unsigned char *src, unsigned char *dist)
{
    unsigned char *p = (unsigned char*)src;
    unsigned long bb = (unsigned long)0;
    int i = 0, j = 0;
    while (*p) {
        bb <<= 8;
        bb |= (unsigned long)*p;
        if (i == 2) {
            encode_char(bb, i, dist, j);
            j = j + 4;
            i = 0;
            bb = 0;
        } else {
            i++;
        }
        p++;
    }
    if (i) encode_char(bb, i - 1, dist, j);
}

canonical_original_code:
void base64_encode(unsigned char *src, unsigned char *dist)
{
    unsigned char *p = (unsigned char*)src;
    unsigned long bb = (unsigned long)0;
    int i = 0; int j = 0;
    while (*p) {
        bb <<= 8;
        bb |= (unsigned long)*p;
        if (i == 2) {
            encode_char(bb, i, dist, j);
            j = j + 4;
            i = 0;
            bb = 0;
        } else {
            i++;
        }
        p++;
    }
    if (i) encode_char(bb, i - 1, dist, j);
}

variable_types:
p
unsigned char *


decompiled_code:
__int64 __fastcall base64_decode(const char *a1, char *a2)
{
int v2; // er13
int v3; // ebx
unsigned int v4; // er12
char src[4]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strlen(a1);
if ( v2 )
{
v3 = 0;
while ( 1 )
{
*(_DWORD *)src = 0;
v4 = decode_str(v3, (__int64)a1);
if ( v4 )
break;
v3 += 4;
strcat(a2, src);
if ( v3 == v2 )
return v4;
}
return 0xFFFFFFFFLL;
}
return (unsigned int)-2;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, char *a2)
{
int v2; // er13
int v3; // ebx
unsigned int v4; // er12
char src[4]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strlen(a1);
if ( v2 )
{
v3 = 0;
while ( 1 )
{
*(_DWORD *)src = 0;
v4 = func2(v3, (__int64)a1);
if ( v4 )
break;
v3 += 4;
strcat(a2, src);
if ( v3 == v2 )
return v4;
}
return 0xFFFFFFFFLL;
}
return (unsigned int)-2;
}

original_code:
int base64_decode(const unsigned char *src, unsigned char *dest)
{
    int i = 0;
    int srclen;
    char tmp[4];
    if (src == ((void *)0)) return -1;
    srclen = strlen((char*)src);
    if (!srclen % 4) return -2;
    while (srclen) {
        memset(tmp, 0, sizeof(tmp));
        if (decode_str(i, src, (unsigned char*)tmp) != 0)
            return -1;
        strcat((char*)dest, tmp);
        i += 4;
        srclen -= 4;
    }
    return 0;
}

canonical_original_code:
int base64_decode(unsigned char *src, unsigned char *dest)
{
    int i = 0;
    int srclen;
    char tmp[4];
    if (src == ((void *)0)) return -1;
    srclen = strlen((char *)src);
    if (!srclen % 4) return -2;
    while (srclen) {
        memset(tmp, 0, sizeof(tmp));
        if (decode_str(i, src, (unsigned char *)tmp) != 0)
            return -1;
        strcat((char *)dest, tmp);
        i += 4;
        srclen -= 4;
    }
    return 0;
}

variable_types:
tmp
char [4]


decompiled_code:
size_t __fastcall url_encode(const char *a1, __int64 a2, unsigned __int64 a3)
{
size_t result; // rax
size_t v6; // rbx
unsigned __int64 v7; // rdx
__int64 v8; // r13
__int64 v9; // r14
const char *v10; // rsi
__int64 v11; // r12
__int64 v12; // rdx
char *v13; // r15
__int64 v14; // rcx
char *v15; // rdi
__int64 v16; // r15
char s[60]; // [rsp+1Ch] [rbp-3Ch] BYREF

result = strlen(a1);
v6 = result;
if ( result )
{
v7 = 3 * result + 1;
result = 0LL;
if ( v7 <= a3 )
{
v8 = 0LL;
v9 = 0LL;
while ( 1 )
{
while ( 1 )
{
v10 = &a1[v9];
v11 = v9 + 1;
v12 = (unsigned __int8)a1[v9];
v13 = (char *)(a2 + v8);
if ( (unsigned __int8)(v12 + 127) > 0x1Eu && (unsigned __int8)(v12 + 32) > 0xFu )
break;
sprintf(s, "%%%02X", v12);
strncpy(v13, s, 4uLL);
v16 = v8 + 3;
if ( v6 == v11 )
return v8 + 3;
v9 += 2LL;
v8 += 6LL;
sprintf(s, "%%%02X", (unsigned __int8)a1[v11]);
strncpy((char *)(a2 + v16), s, 4uLL);
LABEL_5:
if ( v9 == v6 )
return v8;
}
if ( (unsigned __int8)(v12 - 97) > 0x19u )
{
if ( (unsigned __int8)(v12 - 42) > 0x35u
|| (v14 = 0x21FFFFFFC0FFD9LL, !_bittest64(&v14, (unsigned int)(v12 - 42))) )
{
v8 += 3LL;
sprintf(s, "%%%02X", v12);
++v9;
strncpy(v13, s, 4uLL);
goto LABEL_5;
}
}
v15 = (char *)(a2 + v8);
++v9;
++v8;
strncpy(v15, v10, 2uLL);
if ( v11 == v6 )
return v8;
}
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func5(const char *a1, __int64 a2, unsigned __int64 a3)
{
size_t result; // rax
size_t v6; // rbx
unsigned __int64 v7; // rdx
__int64 v8; // r13
__int64 v9; // r14
const char *v10; // rsi
__int64 v11; // r12
__int64 v12; // rdx
char *v13; // r15
__int64 v14; // rcx
char *v15; // rdi
__int64 v16; // r15
char s[60]; // [rsp+1Ch] [rbp-3Ch] BYREF

result = strlen(a1);
v6 = result;
if ( result )
{
v7 = 3 * result + 1;
result = 0LL;
if ( v7 <= a3 )
{
v8 = 0LL;
v9 = 0LL;
while ( 1 )
{
while ( 1 )
{
v10 = &a1[v9];
v11 = v9 + 1;
v12 = (unsigned __int8)a1[v9];
v13 = (char *)(a2 + v8);
if ( (unsigned __int8)(v12 + 127) > 0x1Eu && (unsigned __int8)(v12 + 32) > 0xFu )
break;
sprintf(s, "%%%02X", v12);
strncpy(v13, s, 4uLL);
v16 = v8 + 3;
if ( v6 == v11 )
return v8 + 3;
v9 += 2LL;
v8 += 6LL;
sprintf(s, "%%%02X", (unsigned __int8)a1[v11]);
strncpy((char *)(a2 + v16), s, 4uLL);
LABEL_5:
if ( v9 == v6 )
return v8;
}
if ( (unsigned __int8)(v12 - 97) > 0x19u )
{
if ( (unsigned __int8)(v12 - 42) > 0x35u
|| (v14 = 0x21FFFFFFC0FFD9LL, !_bittest64(&v14, (unsigned int)(v12 - 42))) )
{
v8 += 3LL;
sprintf(s, "%%%02X", v12);
++v9;
strncpy(v13, s, 4uLL);
goto LABEL_5;
}
}
v15 = (char *)(a2 + v8);
++v9;
++v8;
strncpy(v15, v10, 2uLL);
if ( v11 == v6 )
return v8;
}
}
}
return result;
}

original_code:
unsigned long url_encode(unsigned char* csource, unsigned char* cbuffer, unsigned long lbuffersize)
{
    unsigned long llength;
    unsigned long lcount = 0;
    unsigned char cbyte;
    unsigned char ctemp[4];
    unsigned long lresultcount = 0;
    llength = (unsigned long)strlen((char*)csource);
    if (!llength) { return lresultcount; }
    if (lbuffersize < (llength * 3 + 1)) { return lresultcount; }
    while (1) {
        cbyte = *(csource + lcount);
        if(((cbyte >= 0x81) && (cbyte <= 0x9F)) ||
                ((cbyte >= 0xE0) && (cbyte <= 0xEF))) {
            sprintf((char*)ctemp, "%%%02X", cbyte);
            strncpy((char*)(cbuffer + lresultcount), (char*)ctemp, 4);
            lcount++;
            lresultcount += 3;
            if (lcount == llength) { break; }
            sprintf((char*)ctemp, "%%%02X", *(csource + lcount));
            strncpy((char*)cbuffer + lresultcount, (char*)ctemp, 4);
            lcount++;
            lresultcount += 3;
        } else if (((cbyte >= 0x40) && (cbyte <= 0x5A)) ||
                ((cbyte >= 0x61) && (cbyte <= 0x7A)) ||
                ((cbyte >= 0x30) && (cbyte <= 0x39)) ||
                (cbyte == 0x2A) ||
                (cbyte == 0x2D) ||
                (cbyte == 0x2E) ||
                (cbyte == 0x5F)) {
            strncpy((char*)cbuffer + lresultcount, (char*)csource + lcount, 2);
            lcount++;
            lresultcount++;
        } else {
            sprintf((char*)ctemp, "%%%02X", cbyte);
            strncpy((char*)cbuffer + lresultcount, (char*)ctemp, 4);
            lcount++;
            lresultcount += 3;
        }
        if (lcount == llength) { break; }
    }
    return lresultcount;
}

canonical_original_code:
unsigned long url_encode(unsigned char *csource, unsigned char *cbuffer, unsigned long lbuffersize)
{
    unsigned long llength;
    unsigned long lcount = 0;
    unsigned char cbyte;
    unsigned char ctemp[4];
    unsigned long lresultcount = 0;
    llength = (unsigned long)strlen((char *)csource);
    if (!llength) { return lresultcount; }
    if (lbuffersize < (llength * 3 + 1)) { return lresultcount; }
    while (1) {
        cbyte = *(csource + lcount);
        if(((cbyte >= 0x81) && (cbyte <= 0x9F)) ||
                ((cbyte >= 0xE0) && (cbyte <= 0xEF))) {
            sprintf((char *)ctemp, "%%%02X", cbyte);
            strncpy((char *)(cbuffer + lresultcount), (char *)ctemp, 4);
            lcount++;
            lresultcount += 3;
            if (lcount == llength) { break; }
            sprintf((char *)ctemp, "%%%02X", *(csource + lcount));
            strncpy((char *)cbuffer + lresultcount, (char *)ctemp, 4);
            lcount++;
            lresultcount += 3;
        } else if (((cbyte >= 0x40) && (cbyte <= 0x5A)) ||
                ((cbyte >= 0x61) && (cbyte <= 0x7A)) ||
                ((cbyte >= 0x30) && (cbyte <= 0x39)) ||
                (cbyte == 0x2A) ||
                (cbyte == 0x2D) ||
                (cbyte == 0x2E) ||
                (cbyte == 0x5F)) {
            strncpy((char *)cbuffer + lresultcount, (char *)csource + lcount, 2);
            lcount++;
            lresultcount++;
        } else {
            sprintf((char *)ctemp, "%%%02X", cbyte);
            strncpy((char *)cbuffer + lresultcount, (char *)ctemp, 4);
            lcount++;
            lresultcount += 3;
        }
        if (lcount == llength) { break; }
    }
    return lresultcount;
}

variable_types:
csource
unsigned char *

variable_types:
cbuffer
unsigned char *

variable_types:
lbuffersize
unsigned long

variable_types:
llength
unsigned long

variable_types:
lcount
unsigned long

variable_types:
cbyte
unsigned char

variable_types:
ctemp
unsigned char [4]

variable_types:
lresultcount
unsigned long


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

v1 = (__int64 (*)(void))*((_QWORD *)a1 + 1);
if ( v1 )
result = v1();
else
result = xalloc(*a1, 0LL, 0LL);
return result;
}

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

v1 = (__int64 (*)(void))*((_QWORD *)a1 + 1);
if ( v1 )
result = v1();
else
result = xalloc(*a1, 0LL, 0LL);
return result;
}

original_code:
void* list_new_element(List* list)
{
    void* new_element;
    if (list->constructor) {
        new_element = list->constructor();
    } else {
        new_element = _xalloc(list->element_size, ((void *)0), 0);
    }
    return new_element;
}

canonical_original_code:
void *list_new_element(struct _list *list)
{
    void *new_element;
    if (list->constructor) {
        new_element = list->constructor();
    } else {
        new_element = _xalloc(list->element_size, ((void *)0), 0);
    }
    return new_element;
}

variable_types: struct _list { int element_size; int size; void *(*constructor)(); void (*destructor)(void *); struct _iterator { void *element; struct _iterator *next; } *head; struct _iterator *tail; } *

return_type: void *

user_defined_types: struct _list { int element_size; int size; void *(*constructor)(); void (*destructor)(void *); struct _iterator *head; struct _iterator *tail; }


decompiled_code:
__int64 __fastcall get_iterator(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
Iterator* get_iterator(List* list)
{
    return list->head;
}

canonical_original_code:
struct _iterator *get_iterator(struct _list *list)
{
    return list->head;
}

variable_types: struct _list { int element_size; int size; void *(*constructor)(); void (*destructor)(void *); struct _iterator *head; struct _iterator *tail; } *

return_type: struct _iterator { void *element; struct _iterator *next; } *


decompiled_code:
_BOOL8 __fastcall iterator_has_value(__int64 a1)
{
return a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return a1 != 0;
}

original_code:
int iterator_has_value(Iterator* ite)
{
    return ite != ((void *)0);
}

canonical_original_code:
int iterator_has_value(struct _iterator *ite)
{
    return ite != ((void *)0);
}

variable_types: struct _iterator { void *element; struct _iterator *next; } *


decompiled_code:
__int64 __fastcall iterator_next(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
void* iterator_next(Iterator* ite)
{
    return ite->next;
}

canonical_original_code:
void *iterator_next(struct _iterator *ite)
{
    return ite->next;
}


decompiled_code:
__int64 __fastcall list_free(__int64 a1)
{
_QWORD *v1; // rbp
_QWORD *v2; // rbx
void (*v3)(void); // rax

v1 = (_QWORD *)get_iterator(a1);
if ( v1 )
{
while ( 1 )
{
if ( *v1 )
{
v3 = *(void (**)(void))(a1 + 16);
if ( v3 )
v3();
else
xfree(*v1, 0LL, 0LL);
}
v2 = (_QWORD *)v1[1];
xfree(v1, 0LL, 0LL);
if ( !v2 )
break;
v1 = v2;
}
}
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_QWORD *v1; // rbp
_QWORD *v2; // rbx
void (*v3)(void); // rax

v1 = (_QWORD *)func1(a1);
if ( v1 )
{
while ( 1 )
{
if ( *v1 )
{
v3 = *(void (**)(void))(a1 + 16);
if ( v3 )
v3();
else
xfree(*v1, 0LL, 0LL);
}
v2 = (_QWORD *)v1[1];
xfree(v1, 0LL, 0LL);
if ( !v2 )
break;
v1 = v2;
}
}
return xfree(a1, 0LL, 0LL);
}

original_code:
void list_free(List* list)
{
    Iterator* it = get_iterator(list);
    while (1) {
        Iterator* old_it = it;
        if (it == ((void *)0)) break;
        if (it->element != ((void *)0)) {
            if (list->destructor) {
                list->destructor(it->element);
            } else {
                _xfree(it->element, ((void *)0), 0);;
            }
        }
        it = it->next;
        _xfree(old_it, ((void *)0), 0);;
    }
    _xfree(list, ((void *)0), 0);;
}

canonical_original_code:
void list_free(struct _list *list)
{
    struct _iterator *it = get_iterator(list);
    while (1) {
        struct _iterator *old_it = it;
        if (it == ((void *)0)) break;
        if (it->element != ((void *)0)) {
            if (list->destructor) {
                list->destructor(it->element);
            } else {
                _xfree(it->element, ((void *)0), 0);;
            }
        }
        it = it->next;
        _xfree(old_it, ((void *)0), 0);;
    }
    _xfree(list, ((void *)0), 0);;
}


decompiled_code:
_QWORD *template_new()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(16LL, 0LL, 0LL);
*v0 = string_new();
v0[1] = string_new();
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xalloc(16LL, 0LL, 0LL);
*v0 = string_new();
v0[1] = string_new();
return v0;
}

original_code:
Template* template_new()
{
    Template* template = _xalloc(sizeof(Template), ((void *)0), 0);
    template->name = string_new();
    template->path = string_new();
    return template;
}

canonical_original_code:
struct Template *template_new()
{
    struct Template *template = _xalloc(sizeof(Template), ((void *)0), 0);
    template->name = string_new();
    template->path = string_new();
    return template;
}

variable_types: struct Template { struct _String { char *raw_chars; unsigned long block_size; unsigned long buf_size; unsigned long current_size; } *name; struct _String *path; } *

user_defined_types: struct Template { struct _String *name; struct _String *path; }


decompiled_code:
__int64 __fastcall template_free(_QWORD *a1)
{
string_free(*a1);
string_free(a1[1]);
return xfree(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
string_free(*a1);
string_free(a1[1]);
return xfree(a1, 0LL, 0LL);
}

original_code:
void template_free(Template* template)
{
    string_free(template->name);
    string_free(template->path);
    _xfree(template, ((void *)0), 0);;
}

canonical_original_code:
void template_free(struct Template *template)
{
    string_free(template->name);
    string_free(template->path);
    _xfree(template, ((void *)0), 0);;
}


xfree

decompiled_code:
void __fastcall xfree(void *ptr)
{
--alloc_count;
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
--alloc_count;
free(ptr);
}

original_code:
static void xfree(void* p)
{
    free(p);
    p = ((void *)0);
}

canonical_original_code:
static void xfree(void *p)
{
    free(p);
    p = ((void *)0);
}

variable_types:
p
void *


decompiled_code:
__int64 get_alloc_count()
{
return (unsigned int)alloc_count;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)alloc_count;
}

original_code:
int get_alloc_count()
{
    return alloc_count;
}


main

repo: smiky/pspdev

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // r13
FILE *v4; // rax
FILE *v5; // r12
unsigned int v6; // er14
int v7; // ebp
FILE *v8; // rdi
unsigned __int8 v9; // al
unsigned __int8 v10; // bl

if ( argc <= 3 )
{
puts("bin2c inputfile outputfile recordname");
exit(0);
}
v3 = fopen(argv[2], "wt");
if ( v3 )
{
v4 = fopen(argv[1], "rb");
v5 = v4;
if ( v4 )
{
fseek(v4, 0LL, 2);
v6 = ftell(v5);
fseek(v5, 0LL, 0);
fprintf(v3, "unsigned long size_%s=%i;\n", argv[3], v6);
fprintf(v3, "unsigned char %s[]=\n{\n\t", argv[3]);
LABEL_6:
v7 = 0;
while ( 1 )
{
v8 = v5;
if ( ftell(v5) >= v6 )
break;
while ( 1 )
{
v9 = fgetc(v8);
++v7;
v10 = v9;
if ( v7 != 1 )
break;
fprintf(v3, "0x%02X", v9);
v8 = v5;
if ( ftell(v5) >= v6 )
goto LABEL_10;
}
fwrite(", ", 1uLL, 2uLL, v3);
fprintf(v3, "0x%02X", v10);
if ( v7 == 10 )
{
fwrite(", \n\t", 1uLL, 4uLL, v3);
goto LABEL_6;
}
}
LABEL_10:
fclose(v8);
fwrite("\n};\n", 1uLL, 4uLL, v3);
fclose(v3);
}
else
{
fwrite("Could not open file\n", 1uLL, 0x14uLL, stderr);
}
}
else
{
fwrite("Could not open output file\n", 1uLL, 0x1BuLL, stderr);
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int i;
 int x, y, z, zz;
 char buffer[0x200];
 time_t start, end;
 int colisiones;
 int is_ps3_flag = 0;
 char *ptr, *ptr0, *ptr1, *ptr2, *ptr3;
 char *prefix = "";
 int prefixlen = 0;
 printf("SHA1 hash dictionary attack v2.1 by adresd\n");
 printf("based on the original by djhuevo\n");
 printf("PS3 support added by xorloser\n");
 if (argc < 3) {
  printf("usage:\n\t%s <hash_list> <dictionary> [-ps3] [prefix]\n", argv[0]);
  return 1;
 }
 if (load_hash_list(argv[1]) < 0) {
  fprintf(stderr, "can't open the hash file %s\n", argv[1]);
  return 2;
 }
 if (load_dictionary(argv[2]) < 0) {
  fprintf(stderr, "can't open the dictionary file %s\n", argv[2]);
  return 3;
 }
 if (argc > 3) {
  if( !strcmp("-ps3", argv[3]) ) {
   is_ps3_flag = 1;
   if (argc > 4) {
    prefix = argv[4];
    strcpy(buffer, prefix);
    prefixlen = strlen(prefix);
   }
  }
  else
  {
   prefix = argv[3];
   strcpy(buffer, prefix);
   prefixlen = strlen(prefix);
  }
 }
 if (hash_count < 1 || dict_count < 1) {
  fprintf(stderr, "error on input data.\n");
  fprintf(stderr, "hash_count = %d, dict_count = %d\n", hash_count, dict_count);
  return 4;
 }
 if ((fout = fopen("results.xml", "wba")) <= 0) {
  printf("Failed to open output file\n");
  exit(1);
 }
 printf("\nprefix : '%s'\n", prefix != "" ? prefix : "<None>");
 printf("hash count : %d\n", hash_count);
 printf("dictionary words: %d\n\n", dict_count);
 fillsearchtable();
 printf("\nsearching...\n\n");
 fflush(stdout);
 time(&start);
 ptr = buffer + prefixlen;
 colisiones = 0;
 for (x = 0; x < dict_count; x++) {
  ptr0 = ptr;
  for (i = 0; i < dict_member_length[x]; i++) {
   *(ptr0++) = dict[x][i];
  }
  *(ptr0) = 0;
  printf("// processing word: %s\n", buffer);
  fflush(stdout);
  for (y = 0; y < dict_count; y++) {
   ptr1 = ptr0;
   for (i = 0; i < dict_member_length[y]; i++) {
    *(ptr1++) = dict[y][i];
   }
   *(ptr1) = 0;
   if (strcmp(dict[x], dict[y]) != 0) {
    for (z = 0; z < dict_count; z++) {
     ptr2 = ptr1;
     for (i = 0; i < dict_member_length[z]; i++) {
      *(ptr2++) = dict[z][i];
     }
     if (strcmp(dict[y], dict[z]) != 0) {
      for (zz = 0; zz < dict_count; zz++) {
       ptr3 = ptr2;
       for (i = 0; i < dict_member_length[zz]; i++) {
        *(ptr3++) = dict[zz][i];
       }
       *(ptr3) = 0x00;
       findhash(buffer, ptr3 - buffer, is_ps3_flag);
      }
     }
     *(ptr2) = 0x00;
     findhash(buffer, ptr2 - buffer, is_ps3_flag);
    }
   }
   *(ptr1) = 0x00;
   findhash(buffer, ptr1 - buffer, is_ps3_flag);
  }
  *(ptr0) = 0x00;
  findhash(buffer, ptr0 - buffer, is_ps3_flag);
 }
 time(&end);
 printf("\n\nhash count : %d\n", hash_count);
 printf("dictionary words: %d\n\n", dict_count);
 printf("\n\ntime : %f seconds.\n", difftime(end, start));
 fclose(fout);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 int x; int y; int z; int zz;
 char buffer[512];
 long start; long end;
 int colisiones;
 int is_ps3_flag = 0;
 char *ptr; char *ptr0; char *ptr1; char *ptr2; char *ptr3;
 char *prefix = "";
 int prefixlen = 0;
 printf("SHA1 hash dictionary attack v2.1 by adresd\n");
 printf("based on the original by djhuevo\n");
 printf("PS3 support added by xorloser\n");
 if (argc < 3) {
  printf("usage:\n\t%s <hash_list> <dictionary> [-ps3] [prefix]\n", argv[0]);
  return 1;
 }
 if (load_hash_list(argv[1]) < 0) {
  fprintf(stderr, "can't open the hash file %s\n", argv[1]);
  return 2;
 }
 if (load_dictionary(argv[2]) < 0) {
  fprintf(stderr, "can't open the dictionary file %s\n", argv[2]);
  return 3;
 }
 if (argc > 3) {
  if( !strcmp("-ps3", argv[3]) ) {
   is_ps3_flag = 1;
   if (argc > 4) {
    prefix = argv[4];
    strcpy(buffer, prefix);
    prefixlen = strlen(prefix);
   }
  }
  else
  {
   prefix = argv[3];
   strcpy(buffer, prefix);
   prefixlen = strlen(prefix);
  }
 }
 if (hash_count < 1 || dict_count < 1) {
  fprintf(stderr, "error on input data.\n");
  fprintf(stderr, "hash_count = %d, dict_count = %d\n", hash_count, dict_count);
  return 4;
 }
 if ((fout = fopen("results.xml", "wba")) <= 0) {
  printf("Failed to open output file\n");
  exit(1);
 }
 printf("\nprefix : '%s'\n", prefix != "" ? prefix : "<None>");
 printf("hash count : %d\n", hash_count);
 printf("dictionary words: %d\n\n", dict_count);
 fillsearchtable();
 printf("\nsearching...\n\n");
 fflush(stdout);
 time(&start);
 ptr = buffer + prefixlen;
 colisiones = 0;
 for (x = 0; x < dict_count; x++) {
  ptr0 = ptr;
  for (i = 0; i < dict_member_length[x]; i++) {
   *(ptr0++) = dict[x][i];
  }
  *(ptr0) = 0;
  printf("// processing word: %s\n", buffer);
  fflush(stdout);
  for (y = 0; y < dict_count; y++) {
   ptr1 = ptr0;
   for (i = 0; i < dict_member_length[y]; i++) {
    *(ptr1++) = dict[y][i];
   }
   *(ptr1) = 0;
   if (strcmp(dict[x], dict[y]) != 0) {
    for (z = 0; z < dict_count; z++) {
     ptr2 = ptr1;
     for (i = 0; i < dict_member_length[z]; i++) {
      *(ptr2++) = dict[z][i];
     }
     if (strcmp(dict[y], dict[z]) != 0) {
      for (zz = 0; zz < dict_count; zz++) {
       ptr3 = ptr2;
       for (i = 0; i < dict_member_length[zz]; i++) {
        *(ptr3++) = dict[zz][i];
       }
       *(ptr3) = 0x00;
       findhash(buffer, ptr3 - buffer, is_ps3_flag);
      }
     }
     *(ptr2) = 0x00;
     findhash(buffer, ptr2 - buffer, is_ps3_flag);
    }
   }
   *(ptr1) = 0x00;
   findhash(buffer, ptr1 - buffer, is_ps3_flag);
  }
  *(ptr0) = 0x00;
  findhash(buffer, ptr0 - buffer, is_ps3_flag);
 }
 time(&end);
 printf("\n\nhash count : %d\n", hash_count);
 printf("dictionary words: %d\n\n", dict_count);
 printf("\n\ntime : %f seconds.\n", difftime(end, start));
 fclose(fout);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: x int

variable_types: y int

variable_types: z int

variable_types: zz int

variable_types:
buffer
char [512]

variable_types: start long

variable_types: end long

variable_types: colisiones int

variable_types:
ptr
char *

variable_types:
prefix
char *

variable_types: prefixlen int


repo: smiletiger/GccDemo

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("hello world\r");
return 0;
}

original_code:
int main(int argc,char **argv)
{
 printf("hello world\r\n");
}

canonical_original_code:
int main(int argc, char **argv)
{
 printf("hello world\r\n");
}