decompiled_code:
int __fastcall print_usage(const char *a1)
{
printf("\nUsage: %s {-q|-A|-x|-d|-t|-v} <archive file> [member files...]\n", a1);
puts("\tOptions:");
puts("\t-q - Quickly append the specified member files to the archive.");
puts("\t-A - Append all files in the current directory to the archive");
puts("\t-x - Extract the specified member files from the archive. If no member files are specified, extract all.");
puts("\t-d - Delete the first instance of the specified member files from the archive");
puts("\t-t - Display a table of contents for the archive");
puts("\t-v - Display a verbose table of contents for the archive");
return puts("\t ");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
printf("\nUsage: %s {-q|-A|-x|-d|-t|-v} <archive file> [member files...]\n", a1);
puts("\tOptions:");
puts("\t-q - Quickly append the specified member files to the archive.");
puts("\t-A - Append all files in the current directory to the archive");
puts("\t-x - Extract the specified member files from the archive. If no member files are specified, extract all.");
puts("\t-d - Delete the first instance of the specified member files from the archive");
puts("\t-t - Display a table of contents for the archive");
puts("\t-v - Display a verbose table of contents for the archive");
return puts("\t ");
}

original_code:
void print_usage(char * prog_name) {
    printf("\nUsage: %s {-q|-A|-x|-d|-t|-v} <archive file> [member files...]\n", prog_name);
    printf("\tOptions:\n");
    printf("\t-q - Quickly append the specified member files to the archive.\n");
    printf("\t-A - Append all files in the current directory to the archive\n");
    printf("\t-x - Extract the specified member files from the archive. If no member files are specified, extract all.\n");
    printf("\t-d - Delete the first instance of the specified member files from the archive\n");
    printf("\t-t - Display a table of contents for the archive\n");
    printf("\t-v - Display a verbose table of contents for the archive\n");
    printf("\t \n");
}

canonical_original_code:
void print_usage(char *prog_name) {
    printf("\nUsage: %s {-q|-A|-x|-d|-t|-v} <archive file> [member files...]\n", prog_name);
    printf("\tOptions:\n");
    printf("\t-q - Quickly append the specified member files to the archive.\n");
    printf("\t-A - Append all files in the current directory to the archive\n");
    printf("\t-x - Extract the specified member files from the archive. If no member files are specified, extract all.\n");
    printf("\t-d - Delete the first instance of the specified member files from the archive\n");
    printf("\t-t - Display a table of contents for the archive\n");
    printf("\t-v - Display a verbose table of contents for the archive\n");
    printf("\t \n");
}


repo: NathanJCochran/myar

original_code:
char get_arch_opt(int argc, char* argv[]) {
    if(argc < 2) {
        printf("Error: No option provided.\n");
        print_usage(argv[0]);
        exit(0);
    }
    if(strcmp(argv[1], "-q") == 0) {return 'q';}
    if(strcmp(argv[1], "-x") == 0) {return 'x';}
    if(strcmp(argv[1], "-t") == 0) {return 't';}
    if(strcmp(argv[1], "-v") == 0) {return 'v';}
    if(strcmp(argv[1], "-d") == 0) {return 'd';}
    if(strcmp(argv[1], "-A") == 0) {return 'A';}
    if(strcmp(argv[1], "-w") == 0) {return 'w';}
    printf("Error: Invalid option '%s'\n", argv[1]);
    exit(0);
}

canonical_original_code:
char get_arch_opt(int argc, char *argv[]) {
    if(argc < 2) {
        printf("Error: No option provided.\n");
        print_usage(argv[0]);
        exit(0);
    }
    if(strcmp(argv[1], "-q") == 0) {return 'q';}
    if(strcmp(argv[1], "-x") == 0) {return 'x';}
    if(strcmp(argv[1], "-t") == 0) {return 't';}
    if(strcmp(argv[1], "-v") == 0) {return 'v';}
    if(strcmp(argv[1], "-d") == 0) {return 'd';}
    if(strcmp(argv[1], "-A") == 0) {return 'A';}
    if(strcmp(argv[1], "-w") == 0) {return 'w';}
    printf("Error: Invalid option '%s'\n", argv[1]);
    exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: char


decompiled_code:
char *__fastcall get_arch_name(int a1, const char **a2, char *a3)
{
if ( a1 <= 2 )
{
puts("Error: No archive specified.");
print_usage(*a2);
exit(0);
}
return strcpy(a3, a2[2]);
}

canonical_decompiled_code:
char *__fastcall func2(int a1, const char **a2, char *a3)
{
if ( a1 <= 2 )
{
puts("Error: No archive specified.");
func0(*a2);
exit(0);
}
return strcpy(a3, a2[2]);
}

original_code:
void get_arch_name(int argc, char * argv[], char * arch_name) {
    if(argc < 3) {
        printf("Error: No archive specified.\n");
        print_usage(argv[0]);
        exit(0);
    }
 strcpy(arch_name, argv[2]);
}

canonical_original_code:
void get_arch_name(int argc, char *argv[], char *arch_name) {
    if(argc < 3) {
        printf("Error: No archive specified.\n");
        print_usage(argv[0]);
        exit(0);
    }
 strcpy(arch_name, argv[2]);
}

return_type: void


original_code:
void get_members(int argc, char * argv[], char * members[]) {
    int i;
    for (i=0; i<argc-3; i++) {
        members[i] = (char *) malloc(16*sizeof(char));
        strcpy(members[i], argv[i+3]);
    }
}

canonical_original_code:
void get_members(int argc, char *argv[], char *members[]) {
    int i;
    for (i=0; i<argc-3; i++) {
        members[i] = (char *) malloc(16*sizeof(char));
        strcpy(members[i], argv[i+3]);
    }
}

variable_types:
members
char *[]

variable_types: i int


decompiled_code:
void __fastcall free_members(void **a1, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
if ( *v2 )
free(*v2);
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

canonical_decompiled_code:
void __fastcall func4(void **a1, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
if ( *v2 )
free(*v2);
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

original_code:
void free_members(char * members[], int mem_len) {
    int i;
    for (i=0; i<mem_len; i++) {
        if (members[i] != ((void *)0)) {
            free(members[i]);
        }
    }
}

canonical_original_code:
void free_members(char *members[], int mem_len) {
    int i;
    for (i=0; i<mem_len; i++) {
        if (members[i] != ((void *)0)) {
            free(members[i]);
        }
    }
}


decompiled_code:
__int64 __fastcall is_member(char *s1, const char **a2, int a3)
{
__int64 v3; // r12
const char **v4; // rbx

if ( a3 <= 0 )
return 0LL;
v3 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
v4 = a2;
while ( !*v4 || strcmp(s1, *v4) )
{
if ( ++v4 == (const char **)v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s1, const char **a2, int a3)
{
__int64 v3; // r12
const char **v4; // rbx

if ( a3 <= 0 )
return 0LL;
v3 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
v4 = a2;
while ( !*v4 || strcmp(s1, *v4) )
{
if ( ++v4 == (const char **)v3 )
return 0LL;
}
return 1LL;
}

original_code:
_Bool is_member(char * name, char * members[], int mem_len) {
    int i;
    for (i=0; i<mem_len; i++) {
        if((members[i] != ((void *)0)) && (strcmp(name, members[i]) == 0)) {
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
_Bool is_member(char *name, char *members[], int mem_len) {
    int i;
    for (i=0; i<mem_len; i++) {
        if((members[i] != ((void *)0)) && (strcmp(name, members[i]) == 0)) {
            return 1;
        }
    }
    return 0;
}

variable_types:
name
char *


decompiled_code:
void __fastcall remove_member(char *s1, const char **a2, int a3)
{
__int64 v3; // r13
const char **v4; // rbx
char *v5; // rbp

if ( a3 > 0 )
{
v3 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
v4 = a2;
do
{
while ( 1 )
{
v5 = (char *)*v4;
if ( *v4 )
{
if ( !strcmp(s1, *v4) )
break;
}
if ( ++v4 == (const char **)v3 )
return;
}
++v4;
free(v5);
*(v4 - 1) = 0LL;
}
while ( v4 != (const char **)v3 );
}
}

canonical_decompiled_code:
void __fastcall func6(char *s1, const char **a2, int a3)
{
__int64 v3; // r13
const char **v4; // rbx
char *v5; // rbp

if ( a3 > 0 )
{
v3 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
v4 = a2;
do
{
while ( 1 )
{
v5 = (char *)*v4;
if ( *v4 )
{
if ( !strcmp(s1, *v4) )
break;
}
if ( ++v4 == (const char **)v3 )
return;
}
++v4;
free(v5);
*(v4 - 1) = 0LL;
}
while ( v4 != (const char **)v3 );
}
}

original_code:
void remove_member(char * name, char * members[], int mem_len) {
    int i;
    for (i=0; i<mem_len; i++) {
        if((members[i] != ((void *)0)) && (strcmp(name, members[i]) == 0)) {
            free(members[i]);
            members[i] = ((void *)0);
        }
    }
}

canonical_original_code:
void remove_member(char *name, char *members[], int mem_len) {
    int i;
    for (i=0; i<mem_len; i++) {
        if((members[i] != ((void *)0)) && (strcmp(name, members[i]) == 0)) {
            free(members[i]);
            members[i] = ((void *)0);
        }
    }
}


decompiled_code:
int __fastcall print_date(const char *a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

timer = strtol(a1, 0LL, 10);
v1 = localtime(&timer);
if ( !v1 )
{
perror("Error getting localtime");
exit(0);
}
strftime(s, 0x13uLL, "%b %d %R %Y", v1);
return printf("%s ", s);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

timer = strtol(a1, 0LL, 10);
v1 = localtime(&timer);
if ( !v1 )
{
perror("Error getting localtime");
exit(0);
}
strftime(s, 0x13uLL, "%b %d %R %Y", v1);
return printf("%s ", s);
}

original_code:
void print_date(char * date_str) {
    long timep;
    char time_str[20];
    struct tm * time_tm;
    timep = strtol(date_str, ((void *)0), 10);
    if((time_tm = localtime((time_t *) &timep)) == ((void *)0)) {
  perror("Error getting localtime");
  exit(0);
 }
    strftime(time_str, sizeof(time_str)-1, "%b %d %R %Y", time_tm);
    printf("%s ", time_str);
}

canonical_original_code:
void print_date(char *date_str) {
    long timep;
    char time_str[20];
    struct tm *time_tm;
    timep = strtol(date_str, ((void *)0), 10);
    if((time_tm = localtime((long *) &timep)) == ((void *)0)) {
  perror("Error getting localtime");
  exit(0);
 }
    strftime(time_str, sizeof(time_str)-1, "%b %d %R %Y", time_tm);
    printf("%s ", time_str);
}

variable_types: timep long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


variable_types:
mode
unsigned long

variable_types:
perms
char [10]


decompiled_code:
void *__fastcall init_arch_itr(__int64 a1)
{
void *v1; // rax
void *v2; // rbp
void *result; // rax

v1 = malloc(0x3CuLL);
*(_QWORD *)(a1 + 8) = v1;
v2 = v1;
result = malloc(0x43uLL);
*(_QWORD *)(a1 + 16) = result;
if ( !result || !v2 )
{
perror("Error allocating memory");
exit(0);
}
return result;
}

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

v1 = malloc(0x3CuLL);
*(_QWORD *)(a1 + 8) = v1;
v2 = v1;
result = malloc(0x43uLL);
*(_QWORD *)(a1 + 16) = result;
if ( !result || !v2 )
{
perror("Error allocating memory");
exit(0);
}
return result;
}

original_code:
void init_arch_itr(struct arch_itr * itr) {
 itr->header = (struct ar_hdr *) malloc(sizeof(struct ar_hdr));
 itr->archfile = (struct ar_file *) malloc(sizeof(struct ar_file));
 if((itr->header == ((void *)0)) || (itr->archfile == ((void *)0))) {
  perror("Error allocating memory");
  exit(0);
 }
}

canonical_original_code:
void init_arch_itr(struct arch_itr *itr) {
 itr->header = (struct ar_hdr *) malloc(sizeof(struct ar_hdr));
 itr->archfile = (struct ar_file *) malloc(sizeof(struct ar_file));
 if((itr->header == ((void *)0)) || (itr->archfile == ((void *)0))) {
  perror("Error allocating memory");
  exit(0);
 }
}

variable_types: struct arch_itr { int fd; struct ar_hdr { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; } *header; struct ar_file { char name[17]; char date[13]; char uid[7]; char mode[9]; char size[11]; char fmag[3]; } *archfile; } *

user_defined_types: struct arch_itr { int fd; struct ar_hdr *header; struct ar_file *archfile; }


decompiled_code:
void __fastcall free_arch_itr(void *ptr)
{
if ( close(*(_DWORD *)ptr) == -1 )
{
perror("Error closing archive file");
exit(0);
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( close(*(_DWORD *)ptr) == -1 )
{
perror("Error closing archive file");
exit(0);
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void free_arch_itr(struct arch_itr * itr) {
 if(close(itr->fd) == -1) {
  perror("Error closing archive file");
  exit(0);
 }
 free(itr->header);
 free(itr->archfile);
 free(itr);
}

canonical_original_code:
void free_arch_itr(struct arch_itr *itr) {
 if(close(itr->fd) == -1) {
  perror("Error closing archive file");
  exit(0);
 }
 free(itr->header);
 free(itr->archfile);
 free(itr);
}

user_defined_types: struct ar_hdr { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; }

user_defined_types: struct ar_file { char name[17]; char date[13]; char uid[7]; char mode[9]; char size[11]; char fmag[3]; }


nextFile

decompiled_code:
__int64 __fastcall nextFile(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
struct ar_file * nextFile(struct arch_itr * itr) {
 return itr->archfile;
}

canonical_original_code:
struct ar_file *nextFile(struct arch_itr *itr) {
 return itr->archfile;
}

variable_types: struct arch_itr { int fd; struct ar_hdr { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; } *header; struct ar_file *archfile; } *

return_type: struct ar_file { char name[17]; char date[13]; char uid[7]; char mode[9]; char size[11]; char fmag[3]; } *


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

result = write(a2, *(const void **)(a1 + 8), 0x3CuLL);
if ( result == -1 )
{
perror("Error writing file header");
exit(0);
}
return result;
}

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

result = write(a2, *(const void **)(a1 + 8), 0x3CuLL);
if ( result == -1 )
{
perror("Error writing file header");
exit(0);
}
return result;
}

original_code:
void write_file_header_to(struct arch_itr * itr, int fd) {
 if(write(fd, (void *) itr->header, sizeof(struct ar_hdr)) == -1) {
  perror("Error writing file header");
  exit(0);
 }
}

canonical_original_code:
void write_file_header_to(struct arch_itr *itr, int fd) {
 if(write(fd, (void *) itr->header, sizeof(struct ar_hdr)) == -1) {
  perror("Error writing file header");
  exit(0);
 }
}

variable_types: fd int


decompiled_code:
signed __int64 __fastcall get_offset(const char *a1)
{
signed __int64 v1; // rax

v1 = strtoul(a1, 0LL, 10);
return (v1 % 2 == 1) + v1;
}

canonical_decompiled_code:
signed __int64 __fastcall func4(const char *a1)
{
signed __int64 v1; // rax

v1 = strtoul(a1, 0LL, 10);
return (v1 % 2 == 1) + v1;
}

original_code:
long get_offset(char * size) {
 long bytes;
 bytes = strtoul(size, ((void *)0), 10);
    if (bytes % 2 == 1)
        bytes += 1;
 return bytes;
}

canonical_original_code:
long get_offset(char *size) {
 long bytes;
 bytes = strtoul(size, ((void *)0), 10);
    if (bytes % 2 == 1)
        bytes += 1;
 return bytes;
}

variable_types:
size
char *

variable_types: bytes long

return_type: long


decompiled_code:
__int64 __fastcall write_file_contents_to(__int64 a1, int a2)
{
__int64 v2; // rbx
signed __int64 v3; // rax
__int64 result; // rax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = 0LL;
v3 = get_offset((const char *)(*(_QWORD *)(a1 + 16) + 53LL));
if ( lseek(*(_DWORD *)a1, -v3, 1) == -1 )
goto LABEL_11;
while ( strtol((const char *)(*(_QWORD *)(a1 + 16) + 53LL), 0LL, 10) > v2 )
{
if ( read(*(_DWORD *)a1, buf, 1uLL) == -1 )
{
perror("Error reading from archive file");
exit(0);
}
++v2;
if ( write(a2, buf, 1uLL) == -1 )
{
perror("Error writing file contents");
exit(0);
}
}
result = strtol((const char *)(*(_QWORD *)(a1 + 16) + 53LL), 0LL, 10) % 2;
if ( result == 1 )
{
result = lseek(*(_DWORD *)a1, 1LL, 1);
if ( result == -1 )
{
LABEL_11:
perror("Error seeking in archive file");
exit(0);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 v2; // rbx
signed __int64 v3; // rax
__int64 result; // rax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = 0LL;
v3 = func4((const char *)(*(_QWORD *)(a1 + 16) + 53LL));
if ( lseek(*(_DWORD *)a1, -v3, 1) == -1 )
goto LABEL_11;
while ( strtol((const char *)(*(_QWORD *)(a1 + 16) + 53LL), 0LL, 10) > v2 )
{
if ( read(*(_DWORD *)a1, buf, 1uLL) == -1 )
{
perror("Error reading from archive file");
exit(0);
}
++v2;
if ( write(a2, buf, 1uLL) == -1 )
{
perror("Error writing file contents");
exit(0);
}
}
result = strtol((const char *)(*(_QWORD *)(a1 + 16) + 53LL), 0LL, 10) % 2;
if ( result == 1 )
{
result = lseek(*(_DWORD *)a1, 1LL, 1);
if ( result == -1 )
{
LABEL_11:
perror("Error seeking in archive file");
exit(0);
}
}
return result;
}

original_code:
void write_file_contents_to(struct arch_itr * itr, int fd) {
 char c;
 if(lseek(itr->fd, (off_t) -(get_offset(itr->archfile->size)), 1) == -1) {
  perror("Error seeking in archive file");
  exit(0);
 }
 int i;
 for(i=0; i<strtol(itr->archfile->size, ((void *)0), 10); i++) {
  if(read(itr->fd, &c, sizeof(c)) == -1) {
   perror("Error reading from archive file");
   exit(0);
  }
  if(write(fd, &c, sizeof(c)) == -1) {
   perror("Error writing file contents");
   exit(0);
  }
 }
 if (strtol(itr->archfile->size, ((void *)0), 10)%2 == 1) {
  if(lseek(itr->fd, (off_t) 1, 1) == -1) {
   perror("Error seeking in archive file");
   exit(0);
  }
 }
}

canonical_original_code:
void write_file_contents_to(struct arch_itr *itr, int fd) {
 char c;
 if(lseek(itr->fd, (off_t) -(get_offset(itr->archfile->size)), 1) == -1) {
  perror("Error seeking in archive file");
  exit(0);
 }
 int i;
 for(i=0; i<strtol(itr->archfile->size, ((void *)0), 10); i++) {
  if(read(itr->fd, &c, sizeof(c)) == -1) {
   perror("Error reading from archive file");
   exit(0);
  }
  if(write(fd, &c, sizeof(c)) == -1) {
   perror("Error writing file contents");
   exit(0);
  }
 }
 if (strtol(itr->archfile->size, ((void *)0), 10)%2 == 1) {
  if(lseek(itr->fd, (long) 1, 1) == -1) {
   perror("Error seeking in archive file");
   exit(0);
  }
 }
}

variable_types: c char


extractFile

decompiled_code:
int __fastcall extractFile(__int64 a1)
{
unsigned __int64 v2; // r12
unsigned __int64 v3; // rax
const char *v4; // rdi
int v5; // eax
int v6; // ebp
int result; // eax
struct utimbuf v8; // [rsp+0h] [rbp-28h] BYREF

v2 = strtoul((const char *)(*(_QWORD *)(a1 + 16) + 44LL), 0LL, 8);
v3 = strtoul((const char *)(*(_QWORD *)(a1 + 16) + 17LL), 0LL, 10);
v4 = *(const char **)(a1 + 16);
v8.modtime = v3;
v8.actime = v3;
v5 = open(v4, 65, v2);
if ( v5 == -1 )
{
perror("Error opening/creating file");
exit(0);
}
v6 = v5;
write_file_contents_to(a1, v5);
if ( close(v6) == -1 )
{
perror("Error closing extracted file");
exit(0);
}
result = utime(*(const char **)(a1 + 16), &v8);
if ( result == -1 )
{
perror("Error setting timestamp of extracted file");
exit(0);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
unsigned __int64 v2; // r12
unsigned __int64 v3; // rax
const char *v4; // rdi
int v5; // eax
int v6; // ebp
int result; // eax
struct utimbuf v8; // [rsp+0h] [rbp-28h] BYREF

v2 = strtoul((const char *)(*(_QWORD *)(a1 + 16) + 44LL), 0LL, 8);
v3 = strtoul((const char *)(*(_QWORD *)(a1 + 16) + 17LL), 0LL, 10);
v4 = *(const char **)(a1 + 16);
v8.modtime = v3;
v8.actime = v3;
v5 = open(v4, 65, v2);
if ( v5 == -1 )
{
perror("Error opening/creating file");
exit(0);
}
v6 = v5;
func5(a1, v5);
if ( close(v6) == -1 )
{
perror("Error closing extracted file");
exit(0);
}
result = utime(*(const char **)(a1 + 16), &v8);
if ( result == -1 )
{
perror("Error setting timestamp of extracted file");
exit(0);
}
return result;
}

original_code:
void extractFile(struct arch_itr * itr) {
 int fd;
 unsigned long mode;
 struct utimbuf times;
 mode = strtoul(itr->archfile->mode, ((void *)0), 8);
 times.actime = times.modtime = (time_t) strtoul(itr->archfile->date, ((void *)0), 10);
 if ((fd = open(itr->archfile->name, 01 | 0100, mode)) == -1) {
  perror("Error opening/creating file");
  exit(0);
 }
 write_file_contents_to(itr, fd);
 if(close(fd) == -1) {
  perror("Error closing extracted file");
  exit(0);
 }
 if(utime(itr->archfile->name, &times) == -1) {
  perror("Error setting timestamp of extracted file");
  exit(0);
 }
}

canonical_original_code:
void extractFile(struct arch_itr *itr) {
 int fd;
 unsigned long mode;
 struct utimbuf times;
 mode = strtoul(itr->archfile->mode, ((void *)0), 8);
 times.actime = times.modtime = (long) strtoul(itr->archfile->date, ((void *)0), 10);
 if ((fd = open(itr->archfile->name, 01 | 0100, mode)) == -1) {
  perror("Error opening/creating file");
  exit(0);
 }
 write_file_contents_to(itr, fd);
 if(close(fd) == -1) {
  perror("Error closing extracted file");
  exit(0);
 }
 if(utime(itr->archfile->name, &times) == -1) {
  perror("Error setting timestamp of extracted file");
  exit(0);
 }
}

variable_types: struct utimbuf { long actime; long modtime; }


decompiled_code:
bool __fastcall get_header(int a1, void *a2)
{
int v2; // eax

v2 = read(a1, a2, 0x3CuLL);
if ( v2 == -1 )
{
perror("Error reading header from archive file");
exit(0);
}
return v2 == 60;
}

canonical_decompiled_code:
bool __fastcall func7(int a1, void *a2)
{
int v2; // eax

v2 = read(a1, a2, 0x3CuLL);
if ( v2 == -1 )
{
perror("Error reading header from archive file");
exit(0);
}
return v2 == 60;
}

original_code:
_Bool get_header(int fd, struct ar_hdr * header) {
    int num_read = read(fd, (void *) header, sizeof(struct ar_hdr));
    if (num_read == -1) {
        perror("Error reading header from archive file");
        exit(0);
    }
    if (num_read == sizeof(struct ar_hdr)) {
        return 1;
    }
    else {
        return 0;
    }
}

canonical_original_code:
_Bool get_header(int fd, struct ar_hdr *header) {
    int num_read = read(fd, (void *) header, sizeof(struct ar_hdr));
    if (num_read == -1) {
        perror("Error reading header from archive file");
        exit(0);
    }
    if (num_read == sizeof(struct ar_hdr)) {
        return 1;
    }
    else {
        return 0;
    }
}

variable_types: struct ar_hdr { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; } *


hasNextFile

decompiled_code:
__int64 __fastcall hasNextFile(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
signed __int64 v4; // rax

LOBYTE(v1) = get_header(*(_DWORD *)a1, *(void **)(a1 + 8));
v2 = v1;
if ( (_BYTE)v1 )
{
get_archfile(*(_BYTE **)(a1 + 8), *(_BYTE **)(a1 + 16));
v4 = get_offset((const char *)(*(_QWORD *)(a1 + 16) + 53LL));
if ( lseek(*(_DWORD *)a1, v4, 1) == -1 )
{
perror("Error seeking in archive file");
exit(0);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
signed __int64 v4; // rax

LOBYTE(v1) = func7(*(_DWORD *)a1, *(void **)(a1 + 8));
v2 = v1;
if ( (_BYTE)v1 )
{
get_archfile(*(_BYTE **)(a1 + 8), *(_BYTE **)(a1 + 16));
v4 = func4((const char *)(*(_QWORD *)(a1 + 16) + 53LL));
if ( lseek(*(_DWORD *)a1, v4, 1) == -1 )
{
perror("Error seeking in archive file");
exit(0);
}
}
return v2;
}

original_code:
_Bool hasNextFile(struct arch_itr * itr) {
    if (get_header(itr->fd, itr->header)) {
        get_archfile(itr->header, itr->archfile);
        if(lseek(itr->fd, (off_t) get_offset(itr->archfile->size), 1) == -1) {
   perror("Error seeking in archive file");
   exit(0);
  }
  return 1;
    }
    else {
        return 0;
 }
}

canonical_original_code:
_Bool hasNextFile(struct arch_itr *itr) {
    if (get_header(itr->fd, itr->header)) {
        get_archfile(itr->header, itr->archfile);
        if(lseek(itr->fd, (long) get_offset(itr->archfile->size), 1) == -1) {
   perror("Error seeking in archive file");
   exit(0);
  }
  return 1;
    }
    else {
        return 0;
 }
}


CutString

repo: Nebuleon/hocoslamfy

original_code:
static uint32_t CutString(const char* String, const uint32_t MaxWidth,
 struct StringCut* Cuts, uint32_t CutsAllocated)
{
 uint32_t Cut = 0;
 uint32_t CutStart = 0, Cur = 0, CutWidth = 0;
 uint32_t LastSpace = -1;
 _Bool SpaceInCut = 0;
 while (String[Cur] != '\0')
 {
  if (String[Cur] != '\n')
  {
   if (String[Cur] == ' ')
   {
    LastSpace = Cur;
    SpaceInCut = 1;
   }
   CutWidth += _font_width[(uint8_t) String[Cur]];
  }
  if (String[Cur] == '\n' || CutWidth > MaxWidth)
  {
   if (Cut < CutsAllocated)
    Cuts[Cut].Start = CutStart;
   if (String[Cur] == '\n')
   {
    if (Cut < CutsAllocated)
     Cuts[Cut].End = Cur;
   }
   else if (CutWidth > MaxWidth)
   {
    if (SpaceInCut)
    {
     if (Cut < CutsAllocated)
      Cuts[Cut].End = LastSpace;
     Cur = LastSpace;
    }
    else
    {
     if (Cut < CutsAllocated)
      Cuts[Cut].End = Cur;
     Cur--;
    }
   }
   CutStart = Cur + 1;
   CutWidth = 0;
   SpaceInCut = 0;
   Cut++;
  }
  Cur++;
 }
 if (Cut < CutsAllocated)
 {
  Cuts[Cut].Start = CutStart;
  Cuts[Cut].End = Cur;
 }
 return Cut + 1;
}

canonical_original_code:
static unsigned int CutString(char *String, unsigned int MaxWidth, struct StringCut *Cuts, unsigned int CutsAllocated)
{
 unsigned int Cut = 0;
 unsigned int CutStart = 0; unsigned int Cur = 0; unsigned int CutWidth = 0;
 unsigned int LastSpace = -1;
 _Bool SpaceInCut = 0;
 while (String[Cur] != '\0')
 {
  if (String[Cur] != '\n')
  {
   if (String[Cur] == ' ')
   {
    LastSpace = Cur;
    SpaceInCut = 1;
   }
   CutWidth += _font_width[(unsigned char) String[Cur]];
  }
  if (String[Cur] == '\n' || CutWidth > MaxWidth)
  {
   if (Cut < CutsAllocated)
    Cuts[Cut].Start = CutStart;
   if (String[Cur] == '\n')
   {
    if (Cut < CutsAllocated)
     Cuts[Cut].End = Cur;
   }
   else if (CutWidth > MaxWidth)
   {
    if (SpaceInCut)
    {
     if (Cut < CutsAllocated)
      Cuts[Cut].End = LastSpace;
     Cur = LastSpace;
    }
    else
    {
     if (Cut < CutsAllocated)
      Cuts[Cut].End = Cur;
     Cur--;
    }
   }
   CutStart = Cur + 1;
   CutWidth = 0;
   SpaceInCut = 0;
   Cut++;
  }
  Cur++;
 }
 if (Cut < CutsAllocated)
 {
  Cuts[Cut].Start = CutStart;
  Cuts[Cut].End = Cur;
 }
 return Cut + 1;
}

variable_types:
String
char *

variable_types:
MaxWidth
unsigned int

variable_types: struct StringCut { unsigned int Start; unsigned int End; } *

variable_types:
CutsAllocated
unsigned int

variable_types:
Cut
unsigned int

variable_types:
CutStart
unsigned int

variable_types:
Cur
unsigned int

variable_types:
CutWidth
unsigned int

variable_types:
LastSpace
unsigned int

return_type: unsigned int


GetSectionRenderedWidth

decompiled_code:
__int64 __fastcall GetSectionRenderedWidth(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
unsigned __int8 *v4; // rax
__int64 v5; // rcx
__int64 v6; // rdx

if ( a2 >= a3 )
return 0LL;
v3 = 0;
v4 = (unsigned __int8 *)(a1 + a2);
v5 = (__int64)&v4[a3 - 1 - a2 + 1];
do
{
v6 = *v4++;
v3 += *((unsigned __int8 *)&font_width + v6);
}
while ( v4 != (unsigned __int8 *)v5 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
unsigned __int8 *v4; // rax
__int64 v5; // rcx
__int64 v6; // rdx

if ( a2 >= a3 )
return 0LL;
v3 = 0;
v4 = (unsigned __int8 *)(a1 + a2);
v5 = (__int64)&v4[a3 - 1 - a2 + 1];
do
{
v6 = *v4++;
v3 += *((unsigned __int8 *)&font_width + v6);
}
while ( v4 != (unsigned __int8 *)v5 );
return v3;
}

original_code:
uint32_t GetSectionRenderedWidth(const char* String, const uint32_t Start, const uint32_t End)
{
 uint32_t Result = 0, i;
 for (i = Start; i < End; i++)
  Result += _font_width[(uint8_t) String[i]];
 return Result;
}

canonical_original_code:
unsigned int GetSectionRenderedWidth(char *String, unsigned int Start, unsigned int End)
{
 unsigned int Result = 0; unsigned int i;
 for (i = Start; i < End; i++)
  Result += _font_width[(unsigned char) String[i]];
 return Result;
}

variable_types:
Start
unsigned int

variable_types:
End
unsigned int

variable_types:
Result
unsigned int

variable_types:
i
unsigned int


original_code:
void PrintString16(const char* String, uint16_t TextColor,
 void* Dest, uint32_t DestPitch, uint32_t X, uint32_t Y, uint32_t Width, uint32_t Height,
 enum HorizontalAlignment HorizontalAlignment, enum VerticalAlignment VerticalAlignment)
{
 struct StringCut* Cuts = malloc((Height / _font_height) * sizeof(struct StringCut));
 uint32_t CutCount = CutString(String, Width, Cuts, Height / _font_height), Cut;
 if (CutCount > Height / _font_height)
  CutCount = Height / _font_height;
 for (Cut = 0; Cut < CutCount; Cut++)
 {
  uint32_t TextWidth = GetSectionRenderedWidth(String, Cuts[Cut].Start, Cuts[Cut].End);
  uint32_t LineX, LineY;
  switch (HorizontalAlignment)
  {
   case LEFT: LineX = X; break;
   case CENTER: LineX = X + (Width - TextWidth) / 2; break;
   case RIGHT: LineX = (X + Width) - TextWidth; break;
   default: LineX = 0; break;
  }
  switch (VerticalAlignment)
  {
   case TOP:
    LineY = Y + Cut * _font_height;
    break;
   case MIDDLE:
    LineY = Y + (Height - CutCount * _font_height) / 2 + Cut * _font_height;
    break;
   case BOTTOM:
    LineY = (Y + Height) - (CutCount - Cut) * _font_height;
    break;
   default:
    LineY = 0;
    break;
  }
  uint32_t Cur;
  for (Cur = Cuts[Cut].Start; Cur < Cuts[Cut].End; Cur++)
  {
   uint32_t glyph_offset = (uint32_t) String[Cur] * _font_height;
   uint32_t glyph_width = _font_width[(uint8_t) String[Cur]];
   uint32_t glyph_column, glyph_row;
   uint16_t current_halfword;
   for(glyph_row = 0; glyph_row < _font_height; glyph_row++, glyph_offset++)
   {
    current_halfword = _font_bits[glyph_offset];
    for (glyph_column = 0; glyph_column < glyph_width; glyph_column++)
    {
     if ((current_halfword >> (15 - glyph_column)) & 0x01)
      *(uint16_t*) ((uint8_t*) Dest + (LineY + glyph_row) * DestPitch + (LineX + glyph_column) * sizeof(uint16_t)) = TextColor;
    }
   }
   LineX += glyph_width;
  }
 }
 free(Cuts);
}

canonical_original_code:
void PrintString16(char *String, unsigned short TextColor, void *Dest, unsigned int DestPitch, unsigned int X, unsigned int Y, unsigned int Width, unsigned int Height, enum HorizontalAlignment HorizontalAlignment, enum VerticalAlignment VerticalAlignment)
{
 struct StringCut *Cuts = malloc((Height / _font_height) * sizeof(struct StringCut));
 unsigned int CutCount = CutString(String, Width, Cuts, Height / _font_height); unsigned int Cut;
 if (CutCount > Height / _font_height)
  CutCount = Height / _font_height;
 for (Cut = 0; Cut < CutCount; Cut++)
 {
  unsigned int TextWidth = GetSectionRenderedWidth(String, Cuts[Cut].Start, Cuts[Cut].End);
  unsigned int LineX; unsigned int LineY;
  switch (HorizontalAlignment)
  {
   case LEFT: LineX = X; break;
   case CENTER: LineX = X + (Width - TextWidth) / 2; break;
   case RIGHT: LineX = (X + Width) - TextWidth; break;
   default: LineX = 0; break;
  }
  switch (VerticalAlignment)
  {
   case TOP:
    LineY = Y + Cut * _font_height;
    break;
   case MIDDLE:
    LineY = Y + (Height - CutCount * _font_height) / 2 + Cut * _font_height;
    break;
   case BOTTOM:
    LineY = (Y + Height) - (CutCount - Cut) * _font_height;
    break;
   default:
    LineY = 0;
    break;
  }
  unsigned int Cur;
  for (Cur = Cuts[Cut].Start; Cur < Cuts[Cut].End; Cur++)
  {
   unsigned int glyph_offset = (uint32_t) String[Cur] * _font_height;
   unsigned int glyph_width = _font_width[(uint8_t) String[Cur]];
   unsigned int glyph_column; unsigned int glyph_row;
   unsigned short current_halfword;
   for(glyph_row = 0; glyph_row < _font_height; glyph_row++, glyph_offset++)
   {
    current_halfword = _font_bits[glyph_offset];
    for (glyph_column = 0; glyph_column < glyph_width; glyph_column++)
    {
     if ((current_halfword >> (15 - glyph_column)) & 0x01)
      *(unsigned short *) ((unsigned char *) Dest + (LineY + glyph_row) * DestPitch + (LineX + glyph_column) * sizeof(unsigned short)) = TextColor;
    }
   }
   LineX += glyph_width;
  }
 }
 free(Cuts);
}

variable_types:
TextColor
unsigned short

variable_types:
Dest
void *

variable_types:
DestPitch
unsigned int

variable_types:
X
unsigned int

variable_types:
Y
unsigned int

variable_types:
Width
unsigned int

variable_types:
Height
unsigned int

variable_types: enum HorizontalAlignment { LEFT=0, CENTER=1, RIGHT=2 }

variable_types: enum VerticalAlignment { TOP=0, MIDDLE=1, BOTTOM=2 }

variable_types:
CutCount
unsigned int

variable_types:
TextWidth
unsigned int

variable_types:
LineX
unsigned int

variable_types:
LineY
unsigned int

user_defined_types: struct StringCut { unsigned int Start; unsigned int End; }


original_code:
void PrintString32(const char* String, uint32_t TextColor,
 void* Dest, uint32_t DestPitch, uint32_t X, uint32_t Y, uint32_t Width, uint32_t Height,
 enum HorizontalAlignment HorizontalAlignment, enum VerticalAlignment VerticalAlignment)
{
 struct StringCut* Cuts = malloc((Height / _font_height) * sizeof(struct StringCut));
 uint32_t CutCount = CutString(String, Width, Cuts, Height / _font_height), Cut;
 if (CutCount > Height / _font_height)
  CutCount = Height / _font_height;
 for (Cut = 0; Cut < CutCount; Cut++)
 {
  uint32_t TextWidth = GetSectionRenderedWidth(String, Cuts[Cut].Start, Cuts[Cut].End);
  uint32_t LineX, LineY;
  switch (HorizontalAlignment)
  {
   case LEFT: LineX = X; break;
   case CENTER: LineX = X + (Width - TextWidth) / 2; break;
   case RIGHT: LineX = (X + Width) - TextWidth; break;
   default: LineX = 0; break;
  }
  switch (VerticalAlignment)
  {
   case TOP:
    LineY = Y + Cut * _font_height;
    break;
   case MIDDLE:
    LineY = Y + (Height - CutCount * _font_height) / 2 + Cut * _font_height;
    break;
   case BOTTOM:
    LineY = (Y + Height) - (CutCount - Cut) * _font_height;
    break;
   default:
    LineY = 0;
    break;
  }
  uint32_t Cur;
  for (Cur = Cuts[Cut].Start; Cur < Cuts[Cut].End; Cur++)
  {
   uint32_t glyph_offset = (uint32_t) String[Cur] * _font_height;
   uint32_t glyph_width = _font_width[(uint8_t) String[Cur]];
   uint32_t glyph_column, glyph_row;
   uint16_t current_halfword;
   for(glyph_row = 0; glyph_row < _font_height; glyph_row++, glyph_offset++)
   {
    current_halfword = _font_bits[glyph_offset];
    for (glyph_column = 0; glyph_column < glyph_width; glyph_column++)
    {
     if ((current_halfword >> (15 - glyph_column)) & 0x01)
      *(uint32_t*) ((uint8_t*) Dest + (LineY + glyph_row) * DestPitch + (LineX + glyph_column) * sizeof(uint32_t)) = TextColor;
    }
   }
   LineX += glyph_width;
  }
 }
 free(Cuts);
}

canonical_original_code:
void PrintString32(char *String, unsigned int TextColor, void *Dest, unsigned int DestPitch, unsigned int X, unsigned int Y, unsigned int Width, unsigned int Height, enum HorizontalAlignment HorizontalAlignment, enum VerticalAlignment VerticalAlignment)
{
 struct StringCut *Cuts = malloc((Height / _font_height) * sizeof(struct StringCut));
 unsigned int CutCount = CutString(String, Width, Cuts, Height / _font_height); unsigned int Cut;
 if (CutCount > Height / _font_height)
  CutCount = Height / _font_height;
 for (Cut = 0; Cut < CutCount; Cut++)
 {
  unsigned int TextWidth = GetSectionRenderedWidth(String, Cuts[Cut].Start, Cuts[Cut].End);
  unsigned int LineX; unsigned int LineY;
  switch (HorizontalAlignment)
  {
   case LEFT: LineX = X; break;
   case CENTER: LineX = X + (Width - TextWidth) / 2; break;
   case RIGHT: LineX = (X + Width) - TextWidth; break;
   default: LineX = 0; break;
  }
  switch (VerticalAlignment)
  {
   case TOP:
    LineY = Y + Cut * _font_height;
    break;
   case MIDDLE:
    LineY = Y + (Height - CutCount * _font_height) / 2 + Cut * _font_height;
    break;
   case BOTTOM:
    LineY = (Y + Height) - (CutCount - Cut) * _font_height;
    break;
   default:
    LineY = 0;
    break;
  }
  unsigned int Cur;
  for (Cur = Cuts[Cut].Start; Cur < Cuts[Cut].End; Cur++)
  {
   unsigned int glyph_offset = (uint32_t) String[Cur] * _font_height;
   unsigned int glyph_width = _font_width[(uint8_t) String[Cur]];
   unsigned int glyph_column; unsigned int glyph_row;
   unsigned short current_halfword;
   for(glyph_row = 0; glyph_row < _font_height; glyph_row++, glyph_offset++)
   {
    current_halfword = _font_bits[glyph_offset];
    for (glyph_column = 0; glyph_column < glyph_width; glyph_column++)
    {
     if ((current_halfword >> (15 - glyph_column)) & 0x01)
      *(unsigned int *) ((unsigned char *) Dest + (LineY + glyph_row) * DestPitch + (LineX + glyph_column) * sizeof(unsigned int)) = TextColor;
    }
   }
   LineX += glyph_width;
  }
 }
 free(Cuts);
}

variable_types:
String
char *

variable_types:
TextColor
unsigned int

variable_types: struct StringCut { unsigned int Start; unsigned int End; } *

variable_types:
Cut
unsigned int

variable_types:
Cur
unsigned int

user_defined_types: enum HorizontalAlignment { LEFT=0, CENTER=1, RIGHT=2 }

user_defined_types: enum VerticalAlignment { TOP=0, MIDDLE=1, BOTTOM=2 }


GetRenderedWidth

decompiled_code:
__int64 __fastcall GetRenderedWidth(unsigned __int8 *a1)
{
void *v2; // rbp
unsigned int v3; // eax
unsigned int v4; // er12
__int64 v5; // rdi
unsigned int v6; // er13
unsigned int v7; // er9
unsigned int v8; // ecx
unsigned __int8 *v9; // rax
__int64 v10; // rsi
unsigned int v11; // edx
__int64 v12; // rcx

v2 = malloc(8uLL);
v3 = CutString(a1, 0xFFFFFFFF, (__int64)v2, 1u);
v4 = v3;
if ( v3 > 1 )
{
v2 = realloc(v2, 8LL * v3);
CutString(a1, 0xFFFFFFFF, (__int64)v2, v4);
}
else if ( !v3 )
{
v6 = 0;
goto LABEL_10;
}
v5 = 0LL;
v6 = 0;
do
{
v7 = *((_DWORD *)v2 + 2 * v5);
v8 = *((_DWORD *)v2 + 2 * v5 + 1);
if ( v7 < v8 )
{
v9 = &a1[v7];
v10 = (__int64)&a1[v7 + 1 + v8 - 1 - v7];
v11 = 0;
do
{
v12 = *v9++;
v11 += *((unsigned __int8 *)&font_width + v12);
}
while ( (unsigned __int8 *)v10 != v9 );
if ( v6 < v11 )
v6 = v11;
}
++v5;
}
while ( v4 > (unsigned int)v5 );
LABEL_10:
free(v2);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1)
{
void *v2; // rbp
unsigned int v3; // eax
unsigned int v4; // er12
__int64 v5; // rdi
unsigned int v6; // er13
unsigned int v7; // er9
unsigned int v8; // ecx
unsigned __int8 *v9; // rax
__int64 v10; // rsi
unsigned int v11; // edx
__int64 v12; // rcx

v2 = malloc(8uLL);
v3 = func0(a1, 0xFFFFFFFF, (__int64)v2, 1u);
v4 = v3;
if ( v3 > 1 )
{
v2 = realloc(v2, 8LL * v3);
func0(a1, 0xFFFFFFFF, (__int64)v2, v4);
}
else if ( !v3 )
{
v6 = 0;
goto LABEL_10;
}
v5 = 0LL;
v6 = 0;
do
{
v7 = *((_DWORD *)v2 + 2 * v5);
v8 = *((_DWORD *)v2 + 2 * v5 + 1);
if ( v7 < v8 )
{
v9 = &a1[v7];
v10 = (__int64)&a1[v7 + 1 + v8 - 1 - v7];
v11 = 0;
do
{
v12 = *v9++;
v11 += *((unsigned __int8 *)&font_width + v12);
}
while ( (unsigned __int8 *)v10 != v9 );
if ( v6 < v11 )
v6 = v11;
}
++v5;
}
while ( v4 > (unsigned int)v5 );
LABEL_10:
free(v2);
return v6;
}

original_code:
uint32_t GetRenderedWidth(const char* str)
{
 struct StringCut* Cuts = malloc(sizeof(struct StringCut));
 uint32_t CutCount = CutString(str, (4294967295U), Cuts, 1);
 if (CutCount > 1)
 {
  Cuts = realloc(Cuts, CutCount * sizeof(struct StringCut));
  CutString(str, (4294967295U), Cuts, CutCount);
 }
 uint32_t Result = 0, LineWidth, Cut;
 for (Cut = 0; Cut < CutCount; Cut++)
 {
  LineWidth = 0;
  uint32_t Cur;
  for (Cur = Cuts[Cut].Start; Cur < Cuts[Cut].End; Cur++)
  {
   LineWidth += _font_width[(uint8_t) str[Cur]];
  }
  if (LineWidth > Result)
   Result = LineWidth;
 }
 free(Cuts);
 return Result;
}

canonical_original_code:
unsigned int GetRenderedWidth(char *str)
{
 struct StringCut *Cuts = malloc(sizeof(struct StringCut));
 unsigned int CutCount = CutString(str, (4294967295U), Cuts, 1);
 if (CutCount > 1)
 {
  Cuts = realloc(Cuts, CutCount * sizeof(struct StringCut));
  CutString(str, (4294967295U), Cuts, CutCount);
 }
 unsigned int Result = 0; unsigned int LineWidth; unsigned int Cut;
 for (Cut = 0; Cut < CutCount; Cut++)
 {
  LineWidth = 0;
  unsigned int Cur;
  for (Cur = Cuts[Cut].Start; Cur < Cuts[Cut].End; Cur++)
  {
   LineWidth += _font_width[(unsigned char) str[Cur]];
  }
  if (LineWidth > Result)
   Result = LineWidth;
 }
 free(Cuts);
 return Result;
}

variable_types:
str
char *

variable_types:
Result
unsigned int

variable_types:
LineWidth
unsigned int


GetRenderedHeight

decompiled_code:
__int64 __fastcall GetRenderedHeight(unsigned __int8 *a1)
{
return (unsigned int)CutString(a1, 0xFFFFFFFF, 0LL, 0) * font_height;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1)
{
return (unsigned int)func0(a1, 0xFFFFFFFF, 0LL, 0) * font_height;
}

original_code:
uint32_t GetRenderedHeight(const char* str)
{
 return CutString(str, (4294967295U), ((void *)0), 0) * _font_height;
}

canonical_original_code:
unsigned int GetRenderedHeight(char *str)
{
 return CutString(str, (4294967295U), ((void *)0), 0) * _font_height;
}


original_code:
void PrintStringOutline16(const char* String, uint16_t TextColor, uint16_t OutlineColor,
 void* Dest, uint32_t DestPitch, uint32_t X, uint32_t Y, uint32_t Width, uint32_t Height,
 enum HorizontalAlignment HorizontalAlignment, enum VerticalAlignment VerticalAlignment)
{
 uint32_t sx, sy;
 for (sx = 0; sx <= 2; sx++)
  for (sy = 0; sy <= 2; sy++)
   if (!(sx == 1 && sy == 1))
    PrintString16(String, OutlineColor, Dest, DestPitch, X + sx, Y + sy, Width - 2, Height - 2, HorizontalAlignment, VerticalAlignment);
 PrintString16(String, TextColor, Dest, DestPitch, X + 1, Y + 1, Width - 2, Height - 2, HorizontalAlignment, VerticalAlignment);
}

canonical_original_code:
void PrintStringOutline16(char *String, unsigned short TextColor, unsigned short OutlineColor, void *Dest, unsigned int DestPitch, unsigned int X, unsigned int Y, unsigned int Width, unsigned int Height, enum HorizontalAlignment HorizontalAlignment, enum VerticalAlignment VerticalAlignment)
{
 unsigned int sx; unsigned int sy;
 for (sx = 0; sx <= 2; sx++)
  for (sy = 0; sy <= 2; sy++)
   if (!(sx == 1 && sy == 1))
    PrintString16(String, OutlineColor, Dest, DestPitch, X + sx, Y + sy, Width - 2, Height - 2, HorizontalAlignment, VerticalAlignment);
 PrintString16(String, TextColor, Dest, DestPitch, X + 1, Y + 1, Width - 2, Height - 2, HorizontalAlignment, VerticalAlignment);
}

variable_types:
TextColor
unsigned short

variable_types:
OutlineColor
unsigned short

variable_types:
Dest
void *

variable_types:
DestPitch
unsigned int

variable_types:
X
unsigned int

variable_types:
Y
unsigned int

variable_types:
sx
unsigned int

variable_types:
sy
unsigned int


original_code:
void PrintStringOutline32(const char* String, uint32_t TextColor, uint32_t OutlineColor,
 void* Dest, uint32_t DestPitch, uint32_t X, uint32_t Y, uint32_t Width, uint32_t Height,
 enum HorizontalAlignment HorizontalAlignment, enum VerticalAlignment VerticalAlignment)
{
 uint32_t sx, sy;
 for (sx = 0; sx <= 2; sx++)
  for (sy = 0; sy <= 2; sy++)
   if (!(sx == 1 && sy == 1))
    PrintString32(String, OutlineColor, Dest, DestPitch, X + sx, Y + sy, Width - 2, Height - 2, HorizontalAlignment, VerticalAlignment);
 PrintString32(String, TextColor, Dest, DestPitch, X + 1, Y + 1, Width - 2, Height - 2, HorizontalAlignment, VerticalAlignment);
}

canonical_original_code:
void PrintStringOutline32(char *String, unsigned int TextColor, unsigned int OutlineColor, void *Dest, unsigned int DestPitch, unsigned int X, unsigned int Y, unsigned int Width, unsigned int Height, enum HorizontalAlignment HorizontalAlignment, enum VerticalAlignment VerticalAlignment)
{
 unsigned int sx; unsigned int sy;
 for (sx = 0; sx <= 2; sx++)
  for (sy = 0; sy <= 2; sy++)
   if (!(sx == 1 && sy == 1))
    PrintString32(String, OutlineColor, Dest, DestPitch, X + sx, Y + sy, Width - 2, Height - 2, HorizontalAlignment, VerticalAlignment);
 PrintString32(String, TextColor, Dest, DestPitch, X + 1, Y + 1, Width - 2, Height - 2, HorizontalAlignment, VerticalAlignment);
}

variable_types:
OutlineColor
unsigned int

variable_types:
Width
unsigned int

variable_types:
Height
unsigned int

variable_types: enum HorizontalAlignment { LEFT=0, CENTER=1, RIGHT=2 }

variable_types: enum VerticalAlignment { TOP=0, MIDDLE=1, BOTTOM=2 }


repo: Nehmulos/ascension-switch

decompiled_code:
_QWORD *List_create()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
List* List_create() {
    List* this = malloc(sizeof(List));
    this->first = ((void *)0);
    this->last = ((void *)0);
    return this;
}

canonical_original_code:
struct List *List_create() {
    struct List *this = malloc(sizeof(List));
    this->first = ((void *)0);
    this->last = ((void *)0);
    return this;
}

variable_types: struct List { struct ListNode { struct ListNode *previous; struct ListNode *next; void *data; } *first; struct ListNode *last; } *

user_defined_types: struct List { struct ListNode *first; struct ListNode *last; }


decompiled_code:
__int64 __fastcall List_getIndexForData(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // er8

v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = 0;
while ( *(_QWORD *)(v2 + 16) != a2 )
{
v2 = *(_QWORD *)(v2 + 8);
++v3;
if ( !v2 )
return 0xFFFFFFFFLL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // er8

v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = 0;
while ( *(_QWORD *)(v2 + 16) != a2 )
{
v2 = *(_QWORD *)(v2 + 8);
++v3;
if ( !v2 )
return 0xFFFFFFFFLL;
}
return v3;
}

original_code:
int List_getIndexForData(List* this, void* data) {
    int i = 0;
    ListNode* it = this->first;
    while (it) {
        if (it->data == data) {
            return i;
        }
        ++i;
        it = it->next;
    }
    return -1;
}

canonical_original_code:
int List_getIndexForData(struct List *this, void *data) {
    int i = 0;
    struct ListNode *it = this->first;
    while (it) {
        if (it->data == data) {
            return i;
        }
        ++i;
        it = it->next;
    }
    return -1;
}

variable_types:
data
void *

variable_types: i int

variable_types: struct ListNode { struct ListNode *previous; struct ListNode *next; void *data; } *

return_type: int


decompiled_code:
__int64 __fastcall List_getNodeForData(__int64 *a1, __int64 a2)
{
__int64 result; // rax

for ( result = *a1; result; result = *(_QWORD *)(result + 8) )
{
if ( *(_QWORD *)(result + 16) == a2 )
break;
}
return result;
}

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

for ( result = *a1; result; result = *(_QWORD *)(result + 8) )
{
if ( *(_QWORD *)(result + 16) == a2 )
break;
}
return result;
}

original_code:
ListNode* List_getNodeForData(List* this, void* data) {
    ListNode* it = this->first;
    while (it) {
        if (it->data == data) {
            return it;
        }
        it = it->next;
    }
    return ((void *)0);
}

canonical_original_code:
struct ListNode *List_getNodeForData(struct List *this, void *data) {
    struct ListNode *it = this->first;
    while (it) {
        if (it->data == data) {
            return it;
        }
        it = it->next;
    }
    return ((void *)0);
}

variable_types: struct List { struct ListNode *first; struct ListNode *last; } *

return_type: struct ListNode { struct ListNode *previous; struct ListNode *next; void *data; } *


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

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

original_code:
void ListNode_destroy(ListNode* this) {
    free(this);
}

canonical_original_code:
void ListNode_destroy(struct ListNode *this) {
    free(this);
}

user_defined_types: struct ListNode { struct ListNode *previous; struct ListNode *next; void *data; }


decompiled_code:
void __fastcall List_destroy(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
ListNode_destroy(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
func3(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void List_destroy(List* this) {
    ListNode* it = this->first;
    while (it) {
        ListNode* next = it->next;
        ListNode_destroy(it);
        it = next;
    }
    free(this);
}

canonical_original_code:
void List_destroy(struct List *this) {
    struct ListNode *it = this->first;
    while (it) {
        struct ListNode *next = it->next;
        ListNode_destroy(it);
        it = next;
    }
    free(this);
}


original_code:
void List_eraseByData(List* this, void* data) {
    ListNode* it = this->first;
    while (it) {
        if (it->data == data) {
            if (it->previous) {
                it->previous->next = it->next;
            }
            if (it->next) {
                it->next->previous = it->previous;
            }
            if (it == this->first) {
                this->first = it->next;
            }
            if (it == this->last) {
                this->last = it->previous;
            }
            ListNode_destroy(it);
            return;
        }
        it = it->next;
    }
}

canonical_original_code:
void List_eraseByData(struct List *this, void *data) {
    struct ListNode *it = this->first;
    while (it) {
        if (it->data == data) {
            if (it->previous) {
                it->previous->next = it->next;
            }
            if (it->next) {
                it->next->previous = it->previous;
            }
            if (it == this->first) {
                this->first = it->next;
            }
            if (it == this->last) {
                this->last = it->previous;
            }
            ListNode_destroy(it);
            return;
        }
        it = it->next;
    }
}


decompiled_code:
__int64 __fastcall List_length(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

original_code:
int List_length(List* this) {
    int n = 0;
    for (ListNode* it = this->first; it; it = it->next) {
 ++n;
    }
    return n;
}

canonical_original_code:
int List_length(struct List *this) {
    int n = 0;
    for (struct ListNode *it = this->first; it; it = it->next) {
 ++n;
    }
    return n;
}

variable_types: n int


original_code:
void List_qSortIt(List* this, int (*compare)(void* a, void* b), ListNode* start, ListNode* end) {
    if (start == end) {
 return;
    }
    ListNode* it = start;
    ListNode* jt = end->previous ? end->previous : it;
    void* pivot = end->data;
    while (it != jt) {
 while (1 != compare(it->data, pivot) && it != jt) {
     it = it->next;
 }
 while (-1 != compare(jt->data, pivot) && jt != it) {
     jt = jt->previous;
 }
 if (it != jt) {
     void* swapCache = it->data;
     it->data = jt->data;
     jt->data = swapCache;
 }
    }
    if (1 == compare(it->data, pivot)) {
 void* swapCache = it->data;
 it->data = end->data;
 end->data = swapCache;
    }
    if (it->previous && start != it) {
 List_qSortIt(this, compare, start, it->previous);
    }
    if (it->next && end != it) {
 List_qSortIt(this, compare, it->next, end);
    }
}

canonical_original_code:
void List_qSortIt(struct List *this, int (*compare)(void *a, void *b), struct ListNode *start, struct ListNode *end) {
    if (start == end) {
 return;
    }
    struct ListNode *it = start;
    struct ListNode *jt = end->previous ? end->previous : it;
    void *pivot = end->data;
    while (it != jt) {
 while (1 != compare(it->data, pivot) && it != jt) {
     it = it->next;
 }
 while (-1 != compare(jt->data, pivot) && jt != it) {
     jt = jt->previous;
 }
 if (it != jt) {
     void *swapCache = it->data;
     it->data = jt->data;
     jt->data = swapCache;
 }
    }
    if (1 == compare(it->data, pivot)) {
 void *swapCache = it->data;
 it->data = end->data;
 end->data = swapCache;
    }
    if (it->previous && start != it) {
 List_qSortIt(this, compare, start, it->previous);
    }
    if (it->next && end != it) {
 List_qSortIt(this, compare, it->next, end);
    }
}

variable_types:
compare
int (*)(void *a, void *b)

variable_types:
start
struct ListNode *

variable_types:
end
struct ListNode *

variable_types:
pivot
void *

variable_types:
swapCache
void *


decompiled_code:
void __fastcall List_qSort(__int64 a1, __int64 (__fastcall *a2)(__int64, __int64))
{
_QWORD *v2; // rcx

v2 = *(_QWORD **)(a1 + 8);
if ( *(_QWORD *)a1 )
{
if ( v2 )
List_qSortIt(a1, a2, *(_QWORD **)a1, v2);
}
}

original_code:
void List_qSort(List* this, int (*compare)(void* a, void* b)) {
    ListNode* a = this->first;
    ListNode* b = this->last;
    if (a && b) {
 List_qSortIt(this, compare, a, b);
    }
}

canonical_original_code:
void List_qSort(struct List *this, int (*compare)(void *a, void *b)) {
    struct ListNode *a = this->first;
    struct ListNode *b = this->last;
    if (a && b) {
 List_qSortIt(this, compare, a, b);
    }
}


decompiled_code:
_QWORD *Vector_Create()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
Vector* Vector_Create(void) {
    Vector* this = malloc(sizeof(Vector));
 this->elements = ((void *)0);
    this->usedElements = 0;
    this->_allocatedElements = 0;
    return this;
}

canonical_original_code:
struct Vector *Vector_Create() {
    struct Vector *this = malloc(sizeof(Vector));
 this->elements = ((void *)0);
    this->usedElements = 0;
    this->_allocatedElements = 0;
    return this;
}

variable_types: struct Vector { void **elements; unsigned int usedElements; unsigned int _allocatedElements; } *


decompiled_code:
__int64 __fastcall Vector_getLastElement(__int64 a1)
{
int v1; // edx
__int64 *v2; // rax
__int64 v3; // rdx
__int64 v4; // r8

v1 = *(_DWORD *)(a1 + 8);
if ( !v1 )
return 0LL;
v2 = *(__int64 **)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(v1 - 1) + 8;
do
{
v4 = *v2;
if ( *v2 )
break;
++v2;
}
while ( v2 != (__int64 *)v3 );
return v4;
}

original_code:
void* Vector_getLastElement(Vector* this) {
 for (int i=0; i < this->usedElements; ++i) {
  if (this->elements[i] != ((void *)0)) {
   return this->elements[i];
  }
 }
 return ((void *)0);
}

canonical_original_code:
void *Vector_getLastElement(struct Vector *this) {
 for (int i = 0; i < this->usedElements; ++i) {
  if (this->elements[i] != ((void *)0)) {
   return this->elements[i];
  }
 }
 return ((void *)0);
}

return_type: void *

user_defined_types: struct Vector { void **elements; unsigned int usedElements; unsigned int _allocatedElements; }


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

result = 0LL;
if ( *(_DWORD *)(a1 + 8) > a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 8) > a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

original_code:
void* Vector_Get(Vector* this, unsigned int i) {
    if (i < this->usedElements) {
        return this->elements[i];
    }
    return ((void *)0);
}

canonical_original_code:
void *Vector_Get(struct Vector *this, unsigned int i) {
    if (i < this->usedElements) {
        return this->elements[i];
    }
    return ((void *)0);
}

variable_types:
i
unsigned int


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

if ( *((_DWORD *)a1 + 2) > a2 )
{
result = *a1;
*(_QWORD *)(*a1 + 8LL * a2) = a3;
}
return result;
}

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

if ( *((_DWORD *)a1 + 2) > a2 )
{
result = *a1;
*(_QWORD *)(*a1 + 8LL * a2) = a3;
}
return result;
}

original_code:
void Vector_Set(Vector* this, unsigned int i, void* element) {
    if (i < this->usedElements) {
        this->elements[i] = element;
    }
}

canonical_original_code:
void Vector_Set(struct Vector *this, unsigned int i, void *element) {
    if (i < this->usedElements) {
        this->elements[i] = element;
    }
}

variable_types:
element
void *


decompiled_code:
void __fastcall Vector_Destroy(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
}

canonical_decompiled_code:
void __fastcall func4(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
}

original_code:
void Vector_Destroy(Vector* this) {
    if (this->elements) {
        free(this->elements);
    }
}

canonical_original_code:
void Vector_Destroy(struct Vector *this) {
    if (this->elements) {
        free(this->elements);
    }
}


decompiled_code:
__int64 __fastcall Vector_AddElement(__int64 a1, __int64 a2)
{
unsigned int v3; // esi

v3 = *(_DWORD *)(a1 + 12);
if ( v3 <= *(_DWORD *)(a1 + 8) )
Vector_RecreateWithoutSizeCheck(a1, v3 + 8);
return Vector_AddElementWithoutSizeCheck(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
unsigned int v3; // esi

v3 = *(_DWORD *)(a1 + 12);
if ( v3 <= *(_DWORD *)(a1 + 8) )
func6(a1, v3 + 8);
return func5(a1, a2);
}

original_code:
void Vector_AddElement(Vector* this, void* element) {
    if (this->_allocatedElements <= this->usedElements) {
        _Vector_RecreateWithoutSizeCheck(this, this->_allocatedElements + 8);
    }
    _Vector_AddElementWithoutSizeCheck(this, element);
}

canonical_original_code:
void Vector_AddElement(struct Vector *this, void *element) {
    if (this->_allocatedElements <= this->usedElements) {
        _Vector_RecreateWithoutSizeCheck(this, this->_allocatedElements + 8);
    }
    _Vector_AddElementWithoutSizeCheck(this, element);
}


decompiled_code:
void __fastcall Vector_ShrinkCache(__int64 a1, char a2)
{
unsigned int v2; // edx
unsigned int v4; // esi

v2 = *(_DWORD *)(a1 + 12);
v4 = *(_DWORD *)(a1 + 8);
if ( v2 - 8 > v4 )
{
Vector_RecreateWithoutSizeCheck(a1, v4 + 8);
}
else if ( v2 > v4 )
{
if ( a2 )
Vector_RecreateWithoutSizeCheck(a1, v4);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, char a2)
{
unsigned int v2; // edx
unsigned int v4; // esi

v2 = *(_DWORD *)(a1 + 12);
v4 = *(_DWORD *)(a1 + 8);
if ( v2 - 8 > v4 )
{
func6(a1, v4 + 8);
}
else if ( v2 > v4 )
{
if ( a2 )
func6(a1, v4);
}
}

original_code:
void Vector_ShrinkCache(Vector* this, _Bool maximumShrink) {
    if (this->_allocatedElements - 8 > this->usedElements) {
        _Vector_RecreateWithoutSizeCheck(this, this->usedElements+8);
    } else if (maximumShrink && this->_allocatedElements > this->usedElements) {
        _Vector_RecreateWithoutSizeCheck(this, this->usedElements);
    }
}

canonical_original_code:
void Vector_ShrinkCache(struct Vector *this, _Bool maximumShrink) {
    if (this->_allocatedElements - 8 > this->usedElements) {
        _Vector_RecreateWithoutSizeCheck(this, this->usedElements+8);
    } else if (maximumShrink && this->_allocatedElements > this->usedElements) {
        _Vector_RecreateWithoutSizeCheck(this, this->usedElements);
    }
}


repo: Neil-UWA/Algorithm

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

for ( result = *(_QWORD *)(a1 + 8); result; result = *(_QWORD *)(result + 8) )
{
if ( *(_DWORD *)result == a2 )
break;
}
return result;
}

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

for ( result = *(_QWORD *)(a1 + 8); result; result = *(_QWORD *)(result + 8) )
{
if ( *(_DWORD *)result == a2 )
break;
}
return result;
}

original_code:
LinkNode* find_element(LinkNode *head, int item)
{
 LinkNode *p = ((void *)0);
 p = head->next;
 while(((void *)0) != p){
  if (item == p->item) {
   return p;
  }
  p = p->next;
 }
 return p;
}

canonical_original_code:
struct _LinkNode *find_element(struct _LinkNode *head, int item)
{
 struct _LinkNode *p = ((void *)0);
 p = head->next;
 while(((void *)0) != p){
  if (item == p->item) {
   return p;
  }
  p = p->next;
 }
 return p;
}

variable_types:
head
struct _LinkNode *

variable_types: item int

variable_types: struct _LinkNode { int item; struct _LinkNode *next; } *


decompiled_code:
int __fastcall show_link(__int64 a1)
{
unsigned int *i; // rbx
int result; // eax

for ( i = *(unsigned int **)(a1 + 8); i; i = (unsigned int *)*((_QWORD *)i + 1) )
result = printf("%d\n", *i);
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
unsigned int *i; // rbx
int result; // eax

for ( i = *(unsigned int **)(a1 + 8); i; i = (unsigned int *)*((_QWORD *)i + 1) )
result = printf("%d\n", *i);
return result;
}

original_code:
void show_link(LinkNode *head)
{
 LinkNode *p = ((void *)0);
 p = head->next;
 while(((void *)0) != p){
  printf("%d\n", p->item);
  p = p->next;
 }
}

canonical_original_code:
void show_link(struct _LinkNode *head)
{
 struct _LinkNode *p = ((void *)0);
 p = head->next;
 while(((void *)0) != p){
  printf("%d\n", p->item);
  p = p->next;
 }
}

user_defined_types: struct _LinkNode { int item; struct _LinkNode *next; }


main

canonical_name: main

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

original_code:
int main(int argc, const char *argv[])
{
 return -1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 return -1;
}

variable_types: argc int

variable_types:
argv
char *[]


preOrderTraverse

decompiled_code:
__int64 __fastcall preOrderTraverse(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
do
{
printf("%d\n", *v1);
result = preOrderTraverse(*((_QWORD *)v1 + 1));
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
do
{
printf("%d\n", *v1);
result = func7(*((_QWORD *)v1 + 1));
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( v1 );
}
return result;
}

original_code:
void preOrderTraverse(btree_t *t) {
 if (((void *)0) == t) {
  return;
 }
 printf("%d\n", t->key);
 preOrderTraverse(t->left);
 preOrderTraverse(t->right);
}

canonical_original_code:
void preOrderTraverse(struct _btree_t *t) {
 if (((void *)0) == t) {
  return;
 }
 printf("%d\n", t->key);
 preOrderTraverse(t->left);
 preOrderTraverse(t->right);
}

variable_types: struct _btree_t { int key; struct _btree_t *left; } *


inOrderTraverse

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

if ( a1 )
{
preOrderTraverse(a1[1]);
printf("%d\n", *(unsigned int *)a1);
result = preOrderTraverse(a1[2]);
}
return result;
}

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

if ( a1 )
{
func7(a1[1]);
printf("%d\n", *(unsigned int *)a1);
result = func7(a1[2]);
}
return result;
}

original_code:
void inOrderTraverse(btree_t *t){
 if (((void *)0) == t) {
  return;
 }
 preOrderTraverse(t->left);
 printf("%d\n", t->key);
 preOrderTraverse(t->right);
}

canonical_original_code:
void inOrderTraverse(struct _btree_t *t){
 if (((void *)0) == t) {
  return;
 }
 preOrderTraverse(t->left);
 printf("%d\n", t->key);
 preOrderTraverse(t->right);
}

user_defined_types: struct _btree_t { int key; struct _btree_t *left; }


postOrderTraverse

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

if ( a1 )
{
preOrderTraverse(a1[2]);
printf("%d\n", *(unsigned int *)a1);
result = preOrderTraverse(a1[1]);
}
return result;
}

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

if ( a1 )
{
func7(a1[2]);
printf("%d\n", *(unsigned int *)a1);
result = func7(a1[1]);
}
return result;
}

original_code:
void postOrderTraverse(btree_t *t){
 if (((void *)0) == t) {
  return;
 }
 preOrderTraverse(t->right);
 printf("%d\n", t->key);
 preOrderTraverse(t->left);
}

canonical_original_code:
void postOrderTraverse(struct _btree_t *t){
 if (((void *)0) == t) {
  return;
 }
 preOrderTraverse(t->right);
 printf("%d\n", t->key);
 preOrderTraverse(t->left);
}


minimum

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
btree_t* minimum(btree_t *t){
 while(((void *)0) != t->left){
  t = t->left;
 }
 return t;
}

canonical_original_code:
struct _btree_t *minimum(struct _btree_t *t){
 while(((void *)0) != t->left){
  t = t->left;
 }
 return t;
}

variable_types:
t
struct _btree_t *

return_type: struct _btree_t { int key; struct _btree_t *left; } *


maximum

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

original_code:
btree_t* maximum(btree_t *t){
 while(((void *)0) != t->right){
  t = t->right;
 }
 return t;
}

canonical_original_code:
struct _btree_t *maximum(struct _btree_t *t){
 while(((void *)0) != t->right){
  t = t->right;
 }
 return t;
}


decompiled_code:
void __fastcall delete_tree(void *ptr)
{
if ( ptr )
{
delete_tree(*((void **)ptr + 1));
delete_tree(*((void **)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
if ( ptr )
{
func13(*((void **)ptr + 1));
func13(*((void **)ptr + 2));
free(ptr);
}
}

original_code:
void delete_tree(btree_t *t) {
 if (t) {
  delete_tree(t->left);
  delete_tree(t->right);
  free(t);
  t = ((void *)0);
 }
}

canonical_original_code:
void delete_tree(struct _btree_t *t) {
 if (t) {
  delete_tree(t->left);
  delete_tree(t->right);
  free(t);
  t = ((void *)0);
 }
}


original_code:
void tree_test(void (*f)(btree_t **, int), btree_t *t, int i, ...) {
 va_list parg;
 int value;
 f(&t, i);
 __builtin_va_start(parg,i);
 while((value = __builtin_va_arg(parg,int))){
  f(&t, value);
 }
 __builtin_va_end(parg);
}

canonical_original_code:
void tree_test(void (*f)(struct _btree_t **, int), struct _btree_t *t, int i, ...) {
 __builtin_va_list parg;
 int value;
 f(&t, i);
 __builtin_va_start(parg,i);
 while((value = __builtin_va_arg(parg,int))){
  f(&t, value);
 }
 __builtin_va_end(parg);
}

variable_types: void (*)(struct _btree_t { int key; struct _btree_t *left; } **, int)

variable_types: i int

variable_types: value int


repo: Nekrofage/KomandoMap

original_code:
s16b player_place(int y, int x)
{
 Thing t;
 t.x = x * 64 + 32;
 t.y = y * 64 + 32;
 t.angle = ((s32b)(rand()%(360)));
 t.type = 1;
 t.options = 0x7;
 add_thing(&t);
}

canonical_original_code:
short player_place(int y, int x)
{
 struct Thing t;
 t.x = x * 64 + 32;
 t.y = y * 64 + 32;
 t.angle = ((s32b)(rand()%(360)));
 t.type = 1;
 t.options = 0x7;
 add_thing(&t);
}

variable_types: y int

variable_types: x int

variable_types: struct Thing { short x; short y; short angle; short type; short options; }

return_type: short


variable_types: good char

variable_types: great char

user_defined_types: struct Thing { short x; short y; short angle; short type; short options; }


decompiled_code:
void place_gold()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void place_gold(int y, int x)
{
 printf("");
}


original_code:
bool_hack place_monster(int y, int x, bool_hack slp, bool_hack grp)
{
 Thing t;
 int fun_monsters[11] = {0x0bbc,
       0x0009,
       0x0bb9,
       0x0bba,
       0x003a,
       0x0bbe,
       0x0bbd,
       0x0045,
       0x0bbb,
       0x0042,
       0x0047};
 t.x = x * 64 + 32;
 t.y = y * 64 + 32;
 t.angle = ((s32b)(rand()%(360)))-1;
 t.type = fun_monsters[((s32b)(rand()%(11)))];
 t.options = 0x7;
 cave_m_idx[y][x]=t.type + 1;
 add_thing(&t);
}

canonical_original_code:
char place_monster(int y, int x, char slp, char grp)
{
 struct Thing t;
 int fun_monsters[11] = {0x0bbc,
       0x0009,
       0x0bb9,
       0x0bba,
       0x003a,
       0x0bbe,
       0x0bbd,
       0x0045,
       0x0bbb,
       0x0042,
       0x0047};
 t.x = x * 64 + 32;
 t.y = y * 64 + 32;
 t.angle = ((s32b)(rand()%(360)))-1;
 t.type = fun_monsters[((s32b)(rand()%(11)))];
 t.options = 0x7;
 cave_m_idx[y][x]=t.type + 1;
 add_thing(&t);
}

variable_types: slp char

variable_types: grp char


decompiled_code:
void place_monster_aux()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
bool_hack place_monster_aux(int y, int x, int r_idx, bool_hack slp, bool_hack grp)
{
 printf("");
}

canonical_original_code:
char place_monster_aux(int y, int x, int r_idx, char slp, char grp)
{
 printf("");
}


decompiled_code:
__int64 __fastcall place_trap(int a1, int a2)
{
__int64 v2; // r8
__int64 v3; // r9
__int64 result; // rax

cave_set_feat(a1, a2, 16);
result = (unsigned int)(sector_counter + 1);
sector_counter = result;
*((_DWORD *)&cave_sector_map + v3 + v2) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2)
{
__int64 v2; // r8
__int64 v3; // r9
__int64 result; // rax

func5(a1, a2, 16);
result = (unsigned int)(sector_counter + 1);
sector_counter = result;
*((_DWORD *)&cave_sector_map + v3 + v2) = result;
return result;
}

original_code:
void place_trap(int y, int x)
{
 cave_set_feat(y, x, 0x10);
 cave_sector_map[y][x]=++sector_counter;
}


distance

decompiled_code:
__int64 __fastcall distance(int a1, int a2, int a3, int a4)
{
int v4; // eax
int v5; // edx

v4 = a3 - a1;
if ( a1 > a3 )
v4 = a1 - a3;
v5 = a4 - a2;
if ( a2 > a4 )
v5 = a2 - a4;
if ( v4 <= v5 )
v4 >>= 1;
else
v5 >>= 1;
return (unsigned int)(v5 + v4);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2, int a3, int a4)
{
int v4; // eax
int v5; // edx

v4 = a3 - a1;
if ( a1 > a3 )
v4 = a1 - a3;
v5 = a4 - a2;
if ( a2 > a4 )
v5 = a2 - a4;
if ( v4 <= v5 )
v4 >>= 1;
else
v5 >>= 1;
return (unsigned int)(v5 + v4);
}

variable_types: ay int

variable_types: ax int


los

variable_types: dx int

variable_types: dy int

variable_types: sx int

variable_types: sy int

variable_types: qx int

variable_types: qy int

variable_types: tx int

variable_types: ty int

variable_types: m int


scatter

decompiled_code:
int *__fastcall scatter(int *a1, int *a2, int a3, int a4, int a5)
{
unsigned int v7; // er12
int v8; // ebp
int v9; // ebx
int v10; // ecx
int v11; // er13
int v12; // ebx
int v13; // eax
int v14; // er9
int *result; // rax
unsigned int v16; // [rsp+0h] [rbp-58h]
int v17; // [rsp+4h] [rbp-54h]
int v18; // [rsp+8h] [rbp-50h]

v7 = a3 - 1;
v8 = 2 * a5 + 1;
v17 = a4 - a5;
v18 = a3 - a5;
v16 = a4 - 1;
while ( 1 )
{
do
{
v9 = rand();
v10 = rand();
}
while ( v7 > 0x81 );
if ( v16 <= 0xC3 )
{
v11 = v9 % v8 + v18;
v12 = v10 % v8 + v17;
if ( a5 <= 1 || (v13 = distance(a3, a4, v11, v12), v13 <= v14) )
{
if ( (unsigned __int8)los(a3, a4, v11, v12) )
break;
}
}
}
*a1 = v11;
result = a2;
*a2 = v12;
return result;
}

variable_types:
yp
int *

variable_types:
xp
int *

variable_types: y int

variable_types: x int

variable_types: d int

variable_types: nx int

variable_types: ny int


decompiled_code:
__int64 get_mon_num()
{
return (unsigned int)(rand() % 10);
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned int)(rand() % 10);
}

original_code:
s16b get_mon_num(int level)
{
 return ((s32b)(rand()%(10)));
}

canonical_original_code:
short get_mon_num(int level)
{
 return ((s32b)(rand()%(10)));
}

variable_types: level int


decompiled_code:
bool alloc_monster()
{
int v0; // ebp
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rax

do
{
do
{
v0 = rand() % 132;
v1 = rand() % 198;
v2 = 198LL * v0;
}
while ( cave_feat[v1 + v2] != 1 );
v3 = v1 + v2;
}
while ( cave_o_idx[v3] || cave_m_idx[v3] );
return (unsigned __int8)place_monster(v0, v1) != 0;
}

canonical_decompiled_code:
bool func11()
{
int v0; // ebp
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rax

do
{
do
{
v0 = rand() % 132;
v1 = rand() % 198;
v2 = 198LL * v0;
}
while ( cave_feat[v1 + v2] != 1 );
v3 = v1 + v2;
}
while ( cave_o_idx[v3] || cave_m_idx[v3] );
return (unsigned __int8)func3(v0, v1) != 0;
}

original_code:
bool_hack alloc_monster(int dis, int slp)
{
 int y, x;
 while (1)
 {
  y = ((s32b)(rand()%(132)));
  x = ((s32b)(rand()%(198)));
  if (!((cave_feat[y][x] == 0x01) && (cave_o_idx[y][x] == 0) && (cave_m_idx[y][x] == 0))) continue;
  else break;
 }
 if (place_monster(y, x, slp, 1)) return (1);
 return (0);
}

canonical_original_code:
char alloc_monster(int dis, int slp)
{
 int y; int x;
 while (1)
 {
  y = ((s32b)(rand()%(132)));
  x = ((s32b)(rand()%(198)));
  if (!((cave_feat[y][x] == 0x01) && (cave_o_idx[y][x] == 0) && (cave_m_idx[y][x] == 0))) continue;
  else break;
 }
 if (place_monster(y, x, slp, 1)) return (1);
 return (0);
}

variable_types: dis int

variable_types: slp int


original_code:
s16b Rand_normal(int mean, int stand)
{
 s16b tmp;
 s16b offset;
 s16b low = 0;
 s16b high = 256;
 if (stand < 1) return (mean);
 tmp = ((s32b)(rand()%(32768)));
 while (low < high)
 {
  int mid = (low + high) >> 1;
  if (Rand_normal_table[mid] < tmp)
  {
   low = mid + 1;
  }
  else
  {
   high = mid;
  }
 }
 offset = (long)stand * (long)low / 64;
 if (((s32b)(rand()%(100))) < 50) return (mean - offset);
 return (mean + offset);
}

canonical_original_code:
short Rand_normal(int mean, int stand)
{
 short tmp;
 short offset;
 short low = 0;
 short high = 256;
 if (stand < 1) return (mean);
 tmp = ((s32b)(rand()%(32768)));
 while (low < high)
 {
  int mid = (low + high) >> 1;
  if (Rand_normal_table[mid] < tmp)
  {
   low = mid + 1;
  }
  else
  {
   high = mid;
  }
 }
 offset = (long)stand * (long)low / 64;
 if (((s32b)(rand()%(100))) < 50) return (mean - offset);
 return (mean + offset);
}

variable_types: mean int

variable_types: stand int

variable_types: tmp short

variable_types: offset short

variable_types: low short

variable_types: high short

variable_types: mid int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rdi

v3 = time(0LL);
v4 = v3;
srand(v3);
generate_cave(v4, argv);
vectorize();
return 0;
}

original_code:
int main(int argc, char** argv)
{
 int x, y;
 srand(time(((void *)0)));
 generate_cave();
 vectorize();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int x; int y;
 srand(time(((void *)0)));
 generate_cave();
 vectorize();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


printUsage

repo: NerdyProjects/HS--PixInvader

decompiled_code:
int printUsage()
{
return puts("Usage: program <data layout file> <output binary file>");
}

canonical_decompiled_code:
int func7()
{
return puts("Usage: program <data layout file> <output binary file>");
}

original_code:
void printUsage(void)
{
  printf("Usage: program <data layout file> <output binary file>\n");
}

canonical_original_code:
void printUsage()
{
  printf("Usage: program <data layout file> <output binary file>\n");
}


repo: NetAngels/redirector

decompiled_code:
__int64 __fastcall get_options(int argc, char **argv, __int64 a3, _QWORD *a4)
{
unsigned int v4; // er14
int v7; // eax
char *v8; // rax
struct passwd *v9; // rax
__uid_t v10; // edx
__gid_t v11; // eax
__int16 v12; // ax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = 0;
*(_QWORD *)(a3 + 8) = "0.0.0.0";
*(_WORD *)(a3 + 32) = 80;
while ( 1 )
{
longind[0] = 0;
v7 = getopt_long(argc, argv, options_1, &long_options_0, longind);
if ( v7 == -1 )
break;
if ( v4 )
return v4;
switch ( v7 )
{
case 'f':
v4 = 0;
*(_QWORD *)a3 = strdup(optarg);
break;
case 'i':
v4 = 0;
*(_QWORD *)(a3 + 8) = strdup(optarg);
break;
case 'p':
v4 = 0;
v12 = atoi(optarg);
*(_WORD *)(a3 + 32) = v12;
if ( !v12 )
{
*a4 = "incorrect port number";
v4 = 1;
}
break;
case 'u':
v8 = strdup(optarg);
*(_QWORD *)(a3 + 16) = v8;
v9 = getpwnam(v8);
if ( v9 )
{
v10 = v9->pw_uid;
v11 = v9->pw_gid;
v4 = 0;
*(_DWORD *)(a3 + 24) = v10;
*(_DWORD *)(a3 + 28) = v11;
}
else
{
*a4 = "user with given name not found";
v4 = 1;
}
break;
case 'v':
++*(_DWORD *)(a3 + 36);
v4 = 0;
break;
default:
v4 = 1;
break;
}
}
if ( v4 || *(_QWORD *)a3 )
return v4;
*a4 = "required option --file (-f) is not set";
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv, __int64 a3, _QWORD *a4)
{
unsigned int v4; // er14
int v7; // eax
char *v8; // rax
struct passwd *v9; // rax
__uid_t v10; // edx
__gid_t v11; // eax
__int16 v12; // ax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = 0;
*(_QWORD *)(a3 + 8) = "0.0.0.0";
*(_WORD *)(a3 + 32) = 80;
while ( 1 )
{
longind[0] = 0;
v7 = getopt_long(argc, argv, options_1, &long_options_0, longind);
if ( v7 == -1 )
break;
if ( v4 )
return v4;
switch ( v7 )
{
case 'f':
v4 = 0;
*(_QWORD *)a3 = strdup(optarg);
break;
case 'i':
v4 = 0;
*(_QWORD *)(a3 + 8) = strdup(optarg);
break;
case 'p':
v4 = 0;
v12 = atoi(optarg);
*(_WORD *)(a3 + 32) = v12;
if ( !v12 )
{
*a4 = "incorrect port number";
v4 = 1;
}
break;
case 'u':
v8 = strdup(optarg);
*(_QWORD *)(a3 + 16) = v8;
v9 = getpwnam(v8);
if ( v9 )
{
v10 = v9->pw_uid;
v11 = v9->pw_gid;
v4 = 0;
*(_DWORD *)(a3 + 24) = v10;
*(_DWORD *)(a3 + 28) = v11;
}
else
{
*a4 = "user with given name not found";
v4 = 1;
}
break;
case 'v':
++*(_DWORD *)(a3 + 36);
v4 = 0;
break;
default:
v4 = 1;
break;
}
}
if ( v4 || *(_QWORD *)a3 )
return v4;
*a4 = "required option --file (-f) is not set";
return 1LL;
}

original_code:
int get_options(int ac, char **av, rd_options *opts, char **err)
{
    static char options[] = "f:i:p:u:vh";
    static struct option long_options[] = {
       {"file", 1, 0, 'f'},
       {"ip", 1, 0, 'i'},
       {"port", 1, 0, 'p'},
       {"user", 1, 0, 'u'},
       {"verbose", 0, 0, 'v'},
       {"help", 0, 0, 'h'},
    };
    int c;
    int has_error = 0;
    struct passwd *pwd;
    opts->ip = "0.0.0.0";
    opts->port = 80;
    while (1) {
        int option_index = 0;
        c = getopt_long(ac, av, options, long_options, &option_index);
        if (c == -1 || has_error)
            break;
        switch (c) {
        case 'f':
            opts->filename = strdup(optarg);
            break;
        case 'i':
            opts->ip = strdup(optarg);
            break;
        case 'p':
            opts->port = atoi(optarg);
            if (opts->port <= 0 || opts->port > 65535) {
                *err = "incorrect port number";
                has_error ++;
            }
            break;
        case 'u':
            opts->username = strdup(optarg);
            pwd = getpwnam(opts->username);
            if (!pwd) {
                *err = "user with given name not found";
                has_error ++;
            } else {
                opts->uid = pwd->pw_uid;
                opts->gid = pwd->pw_gid;
            }
            break;
        case 'v':
            opts->verbose ++;
            break;
        case 'h':
            has_error ++;
            break;
        default:
            has_error ++;
            break;
        }
    }
    if (has_error)
        return 1;
    if (!opts->filename) {
        *err = "required option --file (-f) is not set";
        return 1;
    }
    return 0;
}

canonical_original_code:
int get_options(int ac, char **av, struct __rd_options *opts, char **err)
{
    static char options[] = "f:i:p:u:vh";
    static struct option long_options[] = {
       {"file", 1, 0, 'f'},
       {"ip", 1, 0, 'i'},
       {"port", 1, 0, 'p'},
       {"user", 1, 0, 'u'},
       {"verbose", 0, 0, 'v'},
       {"help", 0, 0, 'h'},
    };
    int c;
    int has_error = 0;
    struct passwd *pwd;
    opts->ip = "0.0.0.0";
    opts->port = 80;
    while (1) {
        int option_index = 0;
        c = getopt_long(ac, av, options, long_options, &option_index);
        if (c == -1 || has_error)
            break;
        switch (c) {
        case 'f':
            opts->filename = strdup(optarg);
            break;
        case 'i':
            opts->ip = strdup(optarg);
            break;
        case 'p':
            opts->port = atoi(optarg);
            if (opts->port <= 0 || opts->port > 65535) {
                *err = "incorrect port number";
                has_error ++;
            }
            break;
        case 'u':
            opts->username = strdup(optarg);
            pwd = getpwnam(opts->username);
            if (!pwd) {
                *err = "user with given name not found";
                has_error ++;
            } else {
                opts->uid = pwd->pw_uid;
                opts->gid = pwd->pw_gid;
            }
            break;
        case 'v':
            opts->verbose ++;
            break;
        case 'h':
            has_error ++;
            break;
        default:
            has_error ++;
            break;
        }
    }
    if (has_error)
        return 1;
    if (!opts->filename) {
        *err = "required option --file (-f) is not set";
        return 1;
    }
    return 0;
}

variable_types: ac int

variable_types:
av
char **

variable_types: struct __rd_options { char *filename; char *ip; char *username; unsigned int uid; unsigned int gid; unsigned short port; unsigned int verbose; } *

variable_types:
err
char **

variable_types:
options
char []

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: c int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
size_t __fastcall print_help(const char *a1)
{
if ( a1 )
fprintf(stderr, "Error: %s\n\n", a1);
return fwrite(
"USAGE: redirector [options]\n"
"\n"
"Options: \n"
"-f, --file (required). Set the BDB filename\n"
"-i, --ip (optional, default \"0.0.0.0\"). Set the IP to bind to\n"
"-p, --port (optional, default 80). Set the port number\n"
"-u, --user (optional). Set the effective UID\n"
"-v, --verbose (optional). Make the redirector log every request to stdout\n"
"-h, --help. This help.\n",
1uLL,
0x156uLL,
stderr);
}

canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
if ( a1 )
fprintf(stderr, "Error: %s\n\n", a1);
return fwrite(
"USAGE: redirector [options]\n"
"\n"
"Options: \n"
"-f, --file (required). Set the BDB filename\n"
"-i, --ip (optional, default \"0.0.0.0\"). Set the IP to bind to\n"
"-p, --port (optional, default 80). Set the port number\n"
"-u, --user (optional). Set the effective UID\n"
"-v, --verbose (optional). Make the redirector log every request to stdout\n"
"-h, --help. This help.\n",
1uLL,
0x156uLL,
stderr);
}

original_code:
void print_help(const char *err)
{
    if (err)
        fprintf(stderr, "Error: %s\n\n", err);
    fprintf(stderr, ""
        "USAGE: redirector [options]\n"
        "\n"
        "Options: \n"
        "-f, --file (required). Set the BDB filename\n"
        "-i, --ip (optional, default \"0.0.0.0\"). Set the IP to bind to\n"
        "-p, --port (optional, default 80). Set the port number\n"
        "-u, --user (optional). Set the effective UID\n"
        "-v, --verbose (optional). Make the redirector log every request to stdout\n"
        "-h, --help. This help.\n"
    );
}

canonical_original_code:
void print_help(char *err)
{
    if (err)
        fprintf(stderr, "Error: %s\n\n", err);
    fprintf(stderr, ""
        "USAGE: redirector [options]\n"
        "\n"
        "Options: \n"
        "-f, --file (required). Set the BDB filename\n"
        "-i, --ip (optional, default \"0.0.0.0\"). Set the IP to bind to\n"
        "-p, --port (optional, default 80). Set the port number\n"
        "-u, --user (optional). Set the effective UID\n"
        "-v, --verbose (optional). Make the redirector log every request to stdout\n"
        "-h, --help. This help.\n"
    );
}

variable_types:
err
char *


lowercase

decompiled_code:
void __fastcall lowercase(char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( (_BYTE)v1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( (_BYTE)v1 );
}
}

canonical_decompiled_code:
void __fastcall func2(char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( (_BYTE)v1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( (_BYTE)v1 );
}
}

original_code:
void lowercase(char *str)
{
   size_t i = 0;
   while (str[i]) {
      str[i] = tolower(str[i]);
      i++;
   }
}

canonical_original_code:
void lowercase(char *str)
{
   unsigned long i = 0;
   while (str[i]) {
      str[i] = tolower(str[i]);
      i++;
   }
}

variable_types:
str
char *

variable_types:
i
unsigned long


repo: NetDirect/nfsshell

decompiled_code:
char *__fastcall mount1_null_1(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, _QWORD, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD); // rax
bool v3; // zf
char *result; // rax

v2 = *(unsigned int (__fastcall ***)(__int64, _QWORD, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD))(a2 + 8);
clnt_res_11 = 0;
v3 = (*v2)(a2, 0LL, &xdr_void, a1, &xdr_void, &clnt_res_11, TIMEOUT, 0LL) == 0;
result = &clnt_res_11;
if ( !v3 )
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, _QWORD, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD); // rax
bool v3; // zf
char *result; // rax

v2 = *(unsigned int (__fastcall ***)(__int64, _QWORD, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD))(a2 + 8);
clnt_res_11 = 0;
v3 = (*v2)(a2, 0LL, &xdr_void, a1, &xdr_void, &clnt_res_11, TIMEOUT, 0LL) == 0;
result = &clnt_res_11;
if ( !v3 )
result = 0LL;
return result;
}

original_code:
void *
mount1_null_1(void *argp, CLIENT *clnt)
{
 static char clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 0, (xdrproc_t) xdr_void, (caddr_t) argp, (xdrproc_t) xdr_void, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return ((void *)&clnt_res);
}

canonical_original_code:
void *mount1_null_1(void *argp, struct CLIENT *clnt)
{
 static char clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 0, (int (*)(struct XDR *, void *, ...)) xdr_void, (char *) argp, (int (*)(struct XDR *, void *, ...)) xdr_void, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return ((void *)&clnt_res);
}

variable_types:
argp
void *

variable_types: struct CLIENT { struct AUTH { struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; } ah_cred; struct opaque_auth ah_verf; union des_block { struct { unsigned int high; unsigned int low; } key; char c[8]; } ah_key; struct auth_ops { void (*ah_nextverf)(struct AUTH *); int (*ah_marshal)(struct AUTH *, struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *); int (*ah_validate)(struct AUTH *, struct opaque_auth *); int (*ah_refresh)(struct AUTH *); void (*ah_destroy)(struct AUTH *); } *ah_ops; char *ah_private; } *cl_auth; struct clnt_ops { enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 } (*cl_call)(struct CLIENT *, unsigned long, int (*)(struct XDR *, void *, ...), char *, int (*)(struct XDR *, void *, ...), char *, struct timeval { long tv_sec; long tv_usec; }); void (*cl_abort)(); void (*cl_geterr)(struct CLIENT *, struct rpc_err { enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 } re_status; union { int RE_errno; enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 } RE_why; struct { unsigned long low; unsigned long high; } RE_vers; struct { long s1; long s2; } RE_lb; } ru; } *); int (*cl_freeres)(struct CLIENT *, int (*)(struct XDR *, void *, ...), char *); void (*cl_destroy)(struct CLIENT *); int (*cl_control)(struct CLIENT *, int, char *); } *cl_ops; char *cl_private; } *

user_defined_types: struct CLIENT { struct AUTH *cl_auth; struct clnt_ops *cl_ops; char *cl_private; }

user_defined_types: struct AUTH { struct opaque_auth ah_cred; struct opaque_auth ah_verf; union des_block ah_key; struct auth_ops *ah_ops; char *ah_private; }

user_defined_types: struct clnt_ops { enum clnt_stat (*cl_call)(struct CLIENT *, unsigned long, int (*)(struct XDR *, void *, ...), char *, int (*)(struct XDR *, void *, ...), char *, struct timeval); void (*cl_abort)(); void (*cl_geterr)(struct CLIENT *, struct rpc_err *); int (*cl_freeres)(struct CLIENT *, int (*)(struct XDR *, void *, ...), char *); void (*cl_destroy)(struct CLIENT *); int (*cl_control)(struct CLIENT *, int, char *); }

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }

user_defined_types: struct auth_ops { void (*ah_nextverf)(struct AUTH *); int (*ah_marshal)(struct AUTH *, struct XDR *); int (*ah_validate)(struct AUTH *, struct opaque_auth *); int (*ah_refresh)(struct AUTH *); void (*ah_destroy)(struct AUTH *); }

user_defined_types: struct rpc_err { enum clnt_stat re_status; union { int RE_errno; enum auth_stat RE_why; struct { unsigned long low; unsigned long high; } RE_vers; struct { long s1; long s2; } RE_lb; } ru; }


decompiled_code:
char *__fastcall mount1_umnt_1(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, __int64, bool_t (**)(XDR *, dirpath *), __int64, bool_t (**)(void), char *, __int64, _QWORD); // rax
bool v3; // zf
char *result; // rax

v2 = *(unsigned int (__fastcall ***)(__int64, __int64, bool_t (**)(XDR *, dirpath *), __int64, bool_t (**)(void), char *, __int64, _QWORD))(a2 + 8);
clnt_res_8 = 0;
v3 = (*v2)(a2, 3LL, &xdr_dirpath, a1, &xdr_void, &clnt_res_8, TIMEOUT, 0LL) == 0;
result = &clnt_res_8;
if ( !v3 )
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, __int64, bool_t (**)(XDR *, dirpath *), __int64, bool_t (**)(void), char *, __int64, _QWORD); // rax
bool v3; // zf
char *result; // rax

v2 = *(unsigned int (__fastcall ***)(__int64, __int64, bool_t (**)(XDR *, dirpath *), __int64, bool_t (**)(void), char *, __int64, _QWORD))(a2 + 8);
clnt_res_8 = 0;
v3 = (*v2)(a2, 3LL, &xdr_dirpath, a1, &xdr_void, &clnt_res_8, TIMEOUT, 0LL) == 0;
result = &clnt_res_8;
if ( !v3 )
result = 0LL;
return result;
}

original_code:
void *
mount1_umnt_1(dirpath *argp, CLIENT *clnt)
{
 static char clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 3, (xdrproc_t) xdr_dirpath, (caddr_t) argp, (xdrproc_t) xdr_void, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return ((void *)&clnt_res);
}

canonical_original_code:
void *mount1_umnt_1(char **argp, struct CLIENT *clnt)
{
 static char clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 3, (int (*)(struct XDR *, void *, ...)) xdr_dirpath, (char *) argp, (int (*)(struct XDR *, void *, ...)) xdr_void, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return ((void *)&clnt_res);
}

variable_types:
argp
char **

user_defined_types: struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; }

user_defined_types: union des_block { struct { unsigned int high; unsigned int low; } key; char c[8]; }

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }

user_defined_types: enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 }

user_defined_types: struct timeval { long tv_sec; long tv_usec; }

user_defined_types: enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 }


decompiled_code:
char *__fastcall mount1_umntall_1(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, __int64, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD); // rax
bool v3; // zf
char *result; // rax

v2 = *(unsigned int (__fastcall ***)(__int64, __int64, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD))(a2 + 8);
clnt_res_7 = 0;
v3 = (*v2)(a2, 4LL, &xdr_void, a1, &xdr_void, &clnt_res_7, TIMEOUT, 0LL) == 0;
result = &clnt_res_7;
if ( !v3 )
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, __int64, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD); // rax
bool v3; // zf
char *result; // rax

v2 = *(unsigned int (__fastcall ***)(__int64, __int64, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD))(a2 + 8);
clnt_res_7 = 0;
v3 = (*v2)(a2, 4LL, &xdr_void, a1, &xdr_void, &clnt_res_7, TIMEOUT, 0LL) == 0;
result = &clnt_res_7;
if ( !v3 )
result = 0LL;
return result;
}

original_code:
void *
mount1_umntall_1(void *argp, CLIENT *clnt)
{
 static char clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 4, (xdrproc_t) xdr_void, (caddr_t) argp, (xdrproc_t) xdr_void, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return ((void *)&clnt_res);
}

canonical_original_code:
void *mount1_umntall_1(void *argp, struct CLIENT *clnt)
{
 static char clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 4, (int (*)(struct XDR *, void *, ...)) xdr_void, (char *) argp, (int (*)(struct XDR *, void *, ...)) xdr_void, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return ((void *)&clnt_res);
}


decompiled_code:
char *__fastcall mount3_null_3(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, _QWORD, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD); // rax
bool v3; // zf
char *result; // rax

v2 = *(unsigned int (__fastcall ***)(__int64, _QWORD, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD))(a2 + 8);
clnt_res_5 = 0;
v3 = (*v2)(a2, 0LL, &xdr_void, a1, &xdr_void, &clnt_res_5, TIMEOUT, 0LL) == 0;
result = &clnt_res_5;
if ( !v3 )
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, _QWORD, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD); // rax
bool v3; // zf
char *result; // rax

v2 = *(unsigned int (__fastcall ***)(__int64, _QWORD, bool_t (**)(void), __int64, bool_t (**)(void), char *, __int64, _QWORD))(a2 + 8);
clnt_res_5 = 0;
v3 = (*v2)(a2, 0LL, &xdr_void, a1, &xdr_void, &clnt_res_5, TIMEOUT, 0LL) == 0;
result = &clnt_res_5;
if ( !v3 )
result = 0LL;
return result;
}

original_code:
void *
mount3_null_3(void *argp, CLIENT *clnt)
{
 static char clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 0, (xdrproc_t) xdr_void, (caddr_t) argp, (xdrproc_t) xdr_void, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return ((void *)&clnt_res);
}

canonical_original_code:
void *mount3_null_3(void *argp, struct CLIENT *clnt)
{
 static char clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 0, (int (*)(struct XDR *, void *, ...)) xdr_void, (char *) argp, (int (*)(struct XDR *, void *, ...)) xdr_void, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return ((void *)&clnt_res);
}