getpw

decompiled_code:
char *getpw()
{
__uid_t v0; // eax
struct passwd *v1; // rax
struct passwd *v2; // rbx
char *v3; // rax
struct spwd *v4; // rbp
char *v5; // rbp

v0 = getuid();
v1 = getpwuid(v0);
if ( !v1 )
die("slock: cannot retrieve password entry (make sure to suid or sgid slock)");
v2 = v1;
endpwent();
v3 = getenv("USER");
v4 = getspnam(v3);
if ( !v4 )
die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n");
endspent();
v5 = v4->sp_pwdp;
if ( setgid(v2->pw_gid) < 0 || setuid(v2->pw_uid) < 0 )
die("slock: cannot drop privileges");
return v5;
}

canonical_decompiled_code:
char *func2()
{
__uid_t v0; // eax
struct passwd *v1; // rax
struct passwd *v2; // rbx
char *v3; // rax
struct spwd *v4; // rbp
char *v5; // rbp

v0 = getuid();
v1 = getpwuid(v0);
if ( !v1 )
func1("slock: cannot retrieve password entry (make sure to suid or sgid slock)");
v2 = v1;
endpwent();
v3 = getenv("USER");
v4 = getspnam(v3);
if ( !v4 )
func1("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n");
endspent();
v5 = v4->sp_pwdp;
if ( setgid(v2->pw_gid) < 0 || setuid(v2->pw_uid) < 0 )
func1("slock: cannot drop privileges");
return v5;
}

original_code:
static const char *
getpw(void) {
 const char *rval;
 struct passwd *pw;
 pw = getpwuid(getuid());
 if(!pw)
  die("slock: cannot retrieve password entry (make sure to suid or sgid slock)");
 endpwent();
 rval = pw->pw_passwd;
 {
  struct spwd *sp;
  sp = getspnam(getenv("USER"));
  if(!sp)
   die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n");
  endspent();
  rval = sp->sp_pwdp;
 }
 if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
  die("slock: cannot drop privileges");
 return rval;
}

canonical_original_code:
static char *getpw() {
 char *rval;
 struct passwd *pw;
 pw = getpwuid(getuid());
 if(!pw)
  die("slock: cannot retrieve password entry (make sure to suid or sgid slock)");
 endpwent();
 rval = pw->pw_passwd;
 {
  struct spwd *sp;
  sp = getspnam(getenv("USER"));
  if(!sp)
   die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n");
  endspent();
  rval = sp->sp_pwdp;
 }
 if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
  die("slock: cannot drop privileges");
 return rval;
}

variable_types:
rval
char *

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

variable_types: struct spwd { char *sp_namp; char *sp_pwdp; long sp_lstchg; long sp_min; long sp_max; long sp_warn; long sp_inact; long sp_expire; unsigned long sp_flag; } *


repo: kostelnik/jwmtools

decompiled_code:
__int64 __fastcall sysmonitor_meminfo_percent(int *a1, _DWORD *a2, _DWORD *a3)
{
int v5; // esi
int v6; // ecx
__int64 result; // rax
int v8; // [rsp+Ch] [rbp-2Ch] BYREF
int v9; // [rsp+10h] [rbp-28h] BYREF
int v10; // [rsp+14h] [rbp-24h] BYREF
int v11; // [rsp+18h] [rbp-20h] BYREF
int v12[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

sysmonitor_meminfo(v12, &v11, &v10, &v9, &v8);
v5 = v12[0];
v6 = v10;
*a1 = 100 * (v12[0] - v11 - v10) / v12[0];
result = (unsigned int)(100 * v6 / v5);
*a2 = result;
*a3 = 0;
if ( v9 )
{
result = (unsigned int)(100 * (v9 - v8) / v9);
*a3 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1, _DWORD *a2, _DWORD *a3)
{
int v5; // esi
int v6; // ecx
__int64 result; // rax
int v8; // [rsp+Ch] [rbp-2Ch] BYREF
int v9; // [rsp+10h] [rbp-28h] BYREF
int v10; // [rsp+14h] [rbp-24h] BYREF
int v11; // [rsp+18h] [rbp-20h] BYREF
int v12[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

func7(v12, &v11, &v10, &v9, &v8);
v5 = v12[0];
v6 = v10;
*a1 = 100 * (v12[0] - v11 - v10) / v12[0];
result = (unsigned int)(100 * v6 / v5);
*a2 = result;
*a3 = 0;
if ( v9 )
{
result = (unsigned int)(100 * (v9 - v8) / v9);
*a3 = result;
}
return result;
}

original_code:
void sysmonitor_meminfo_percent(int * memory, int * cache, int * swap) {
  int mt,mf,mc,st,sf;
  sysmonitor_meminfo(&mt,&mf,&mc,&st,&sf);
  *memory = (100*(mt-mf-mc))/mt;
  *cache = (100*mc)/mt;
  *swap = 0;
  if (st != 0)
    *swap = (100*(st-sf))/st;
}

canonical_original_code:
void sysmonitor_meminfo_percent(int *memory, int *cache, int *swap) {
  int mt; int mf; int mc; int st; int sf;
  sysmonitor_meminfo(&mt,&mf,&mc,&st,&sf);
  *memory = (100*(mt-mf-mc))/mt;
  *cache = (100*mc)/mt;
  *swap = 0;
  if (st != 0)
    *swap = (100*(st-sf))/st;
}

variable_types:
memory
int *

variable_types:
cache
int *

variable_types:
swap
int *

variable_types: mt int

variable_types: mf int

variable_types: mc int

variable_types: st int

variable_types: sf int

return_type: void


start

repo: kostja/snippets

decompiled_code:
// positive sp value has been detected, the output may be wrong!
void __fastcall __noreturn start(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

original_code:
void start()
{
 socklen_t len;
 struct sockaddr_in addr;
 int listen_fd = socket(2, SOCK_STREAM, 0);
 bzero((char *) &addr, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 addr.sin_port = htons(8080);
 int yes = 1;
 if (setsockopt(listen_fd, 1, 2, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt");
 if (bind(listen_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
  error("ERROR on binding");
 listen(listen_fd, 5);
 int addrlen;
 int fd = accept(listen_fd, ((void *)0), ((void *)0));
 if (setsockopt(fd, IPPROTO_TCP, 1, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt2");
 http(fd);
 close(listen_fd);
}

canonical_original_code:
void start()
{
 unsigned int len;
 struct sockaddr_in addr;
 int listen_fd = socket(2, SOCK_STREAM, 0);
 bzero((char *) &addr, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 addr.sin_port = htons(8080);
 int yes = 1;
 if (setsockopt(listen_fd, 1, 2, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt");
 if (bind(listen_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
  error("ERROR on binding");
 listen(listen_fd, 5);
 int addrlen;
 int fd = accept(listen_fd, ((void *)0), ((void *)0));
 if (setsockopt(fd, IPPROTO_TCP, 1, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt2");
 http(fd);
 close(listen_fd);
}

variable_types:
len
unsigned int

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

variable_types: yes int

variable_types: addrlen int

variable_types: fd int

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

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


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void error(const char *msg)
{
    perror(msg);
    exit(1);
}

canonical_original_code:
void error(char *msg)
{
    perror(msg);
    exit(1);
}

variable_types:
msg
char *


decompiled_code:
__int64 http_connect()
{
unsigned int v0; // ebx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(8080);
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
if ( connect(v0, &addr, 0x10u) < 0 )
error("connect");
optval = 1;
if ( setsockopt(v0, 6, 1, &optval, 4u) < 0 )
error("setsockopt2");
return v0;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // ebx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func7(8080);
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
if ( connect(v0, &addr, 0x10u) < 0 )
func8("connect");
optval = 1;
if ( setsockopt(v0, 6, 1, &optval, 4u) < 0 )
func8("setsockopt2");
return v0;
}

original_code:
int http_connect()
{
 socklen_t len;
 struct sockaddr_in addr;
 int fd = socket(2, SOCK_STREAM, 0);
 bzero((char *) &addr, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 addr.sin_port = htons(8080);
 addr.sin_addr.s_addr = inet_addr("127.0.0.1");
 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
  error("connect");
 int yes = 1;
 if (setsockopt(fd, IPPROTO_TCP, 1, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt2");
 return fd;
}

canonical_original_code:
int http_connect()
{
 unsigned int len;
 struct sockaddr_in addr;
 int fd = socket(2, SOCK_STREAM, 0);
 bzero((char *) &addr, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 addr.sin_port = htons(8080);
 addr.sin_addr.s_addr = inet_addr("127.0.0.1");
 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
  error("connect");
 int yes = 1;
 if (setsockopt(fd, IPPROTO_TCP, 1, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt2");
 return fd;
}

return_type: int


setparm

repo: kotatsumikan/TiarraSocketWriter

decompiled_code:
__int64 __fastcall setparm(int a1, __int64 a2)
{
int i; // ebx
const char *v4; // rsi
__int64 v5; // r8
const char *v6; // rsi
const char *v7; // rsi
const char *v8; // rsi

if ( a1 <= 0 )
return 0LL;
for ( i = 0; i < a1; ++i )
{
v5 = 8LL * i;
if ( !strcmp("-socket", *(const char **)(a2 + v5)) )
{
++i;
v6 = *(const char **)(a2 + v5 + 8);
if ( v6 )
strncpy(op_sock, v6, 0x6BuLL);
}
else if ( !strcmp("-sender", *(const char **)(a2 + 8LL * i)) )
{
++i;
v4 = *(const char **)(a2 + v5 + 8);
if ( v4 )
strncpy(op_sender, v4, 0x1FuLL);
}
else if ( !strcmp("-notice", *(const char **)(a2 + 8LL * i)) )
{
op_notice = 1;
}
else if ( !strcmp("-message", *(const char **)(a2 + 8LL * i)) )
{
++i;
v7 = *(const char **)(a2 + v5 + 8);
if ( v7 )
strncpy(op_msg, v7, 0x1FFuLL);
}
else if ( !strcmp("-channel", *(const char **)(a2 + 8LL * i)) )
{
++i;
v8 = *(const char **)(a2 + v5 + 8);
if ( v8 )
strncpy(op_ch, v8, 0x3FuLL);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2)
{
int i; // ebx
const char *v4; // rsi
__int64 v5; // r8
const char *v6; // rsi
const char *v7; // rsi
const char *v8; // rsi

if ( a1 <= 0 )
return 0LL;
for ( i = 0; i < a1; ++i )
{
v5 = 8LL * i;
if ( !strcmp("-socket", *(const char **)(a2 + v5)) )
{
++i;
v6 = *(const char **)(a2 + v5 + 8);
if ( v6 )
strncpy(op_sock, v6, 0x6BuLL);
}
else if ( !strcmp("-sender", *(const char **)(a2 + 8LL * i)) )
{
++i;
v4 = *(const char **)(a2 + v5 + 8);
if ( v4 )
strncpy(op_sender, v4, 0x1FuLL);
}
else if ( !strcmp("-notice", *(const char **)(a2 + 8LL * i)) )
{
op_notice = 1;
}
else if ( !strcmp("-message", *(const char **)(a2 + 8LL * i)) )
{
++i;
v7 = *(const char **)(a2 + v5 + 8);
if ( v7 )
strncpy(op_msg, v7, 0x1FFuLL);
}
else if ( !strcmp("-channel", *(const char **)(a2 + 8LL * i)) )
{
++i;
v8 = *(const char **)(a2 + v5 + 8);
if ( v8 )
strncpy(op_ch, v8, 0x3FuLL);
}
}
return 0LL;
}

original_code:
int setparm(int argc, char **args){
    int i=0;
    int flag=0;
    for(i=0; i<argc; i++){
        if(strcmp("-socket", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_sock, args[i], (sizeof(op_sock)-1));
        }else if(strcmp("-sender", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_sender, args[i], (sizeof(op_sender)-1));
        }else if(strcmp("-notice", args[i]) == 0){
            op_notice = 1;
        }else if(strcmp("-message", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_msg, args[i], (sizeof(op_msg)-1));
        }else if(strcmp("-channel", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_ch, args[i], (sizeof(op_ch)-1));
        }
    }
    return 0;
}

canonical_original_code:
int setparm(int argc, char **args){
    int i = 0;
    int flag = 0;
    for(i=0; i<argc; i++){
        if(strcmp("-socket", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_sock, args[i], (sizeof(op_sock)-1));
        }else if(strcmp("-sender", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_sender, args[i], (sizeof(op_sender)-1));
        }else if(strcmp("-notice", args[i]) == 0){
            op_notice = 1;
        }else if(strcmp("-message", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_msg, args[i], (sizeof(op_msg)-1));
        }else if(strcmp("-channel", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_ch, args[i], (sizeof(op_ch)-1));
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
args
char **

variable_types: i int

variable_types: flag int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
size_t v4; // rax
_DWORD v6[29]; // [rsp+Ch] [rbp-47Ch] BYREF
char s[8]; // [rsp+80h] [rbp-408h] BYREF
__int64 v8; // [rsp+88h] [rbp-400h]
char v9[1008]; // [rsp+90h] [rbp-3F8h] BYREF

*(_QWORD *)s = 0LL;
v8 = 0LL;
memset(v9, 0, sizeof(v9));
v6[0] = 0;
setparm(argc, (__int64)argv);
v3 = socket(1, 1, 0);
perror("socket ");
LOWORD(v6[1]) = 1;
strcpy((char *)&v6[1] + 2, op_sock);
connect(v3, (const struct sockaddr *)&v6[1], 0x6Eu);
perror("connect ");
if ( op_notice == 1 )
strcpy((char *)v6, "yes");
else
strcpy((char *)v6, "no");
sprintf(
s,
"NOTIFY System::SendMessage TIARRACONTROL/1.0\r\n"
"Sender: \r\n"
"Notice: %s\r\n"
"Channel: %s\r\n"
"Charset: utf-8\r\n"
"Text: %s\r\n"
"\r\n",
(const char *)v6,
op_ch,
op_msg);
v4 = strlen(s);
write(v3, s, v4);
perror("write ");
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
size_t v4; // rax
_DWORD v6[29]; // [rsp+Ch] [rbp-47Ch] BYREF
char s[8]; // [rsp+80h] [rbp-408h] BYREF
__int64 v8; // [rsp+88h] [rbp-400h]
char v9[1008]; // [rsp+90h] [rbp-3F8h] BYREF

*(_QWORD *)s = 0LL;
v8 = 0LL;
memset(v9, 0, sizeof(v9));
v6[0] = 0;
func7(argc, (__int64)argv);
v3 = socket(1, 1, 0);
perror("socket ");
LOWORD(v6[1]) = 1;
strcpy((char *)&v6[1] + 2, op_sock);
connect(v3, (const struct sockaddr *)&v6[1], 0x6Eu);
perror("connect ");
if ( op_notice == 1 )
strcpy((char *)v6, "yes");
else
strcpy((char *)v6, "no");
sprintf(
s,
"NOTIFY System::SendMessage TIARRACONTROL/1.0\r\n"
"Sender: \r\n"
"Notice: %s\r\n"
"Channel: %s\r\n"
"Charset: utf-8\r\n"
"Text: %s\r\n"
"\r\n",
(const char *)v6,
op_ch,
op_msg);
v4 = strlen(s);
write(v3, s, v4);
perror("write ");
close(v3);
return 0;
}

original_code:
int main(int argc, char* args[]){
    int sd, len;
    int rtn = 0;
    char buf[1024]={0};
    struct sockaddr_un saddr;
    char is_notice[4] = {0};
    rtn = setparm(argc, args);
    sd = socket(1, SOCK_STREAM, 0);
    perror("socket ");
    saddr.sun_family = 1;
    strcpy(saddr.sun_path, op_sock);
    len = sizeof(saddr);
    rtn = connect(sd, (struct sockaddr*)&saddr, len);
    perror("connect ");
    if(op_notice == 1){
        strcpy(is_notice, "yes");
    }else{
        strcpy(is_notice, "no");
    }
    sprintf(buf, "NOTIFY System::SendMessage TIARRACONTROL/1.0\r\nSender: \r\nNotice: %s\r\nChannel: %s\r\nCharset: utf-8\r\nText: %s\r\n\r\n", is_notice, op_ch, op_msg);
    write(sd, buf, strlen(buf));
    perror("write ");
    close(sd);
}

canonical_original_code:
int main(int argc, char *args[]){
    int sd; int len;
    int rtn = 0;
    char buf[1024] = {0};
    struct sockaddr_un saddr;
    char is_notice[4] = {0};
    rtn = setparm(argc, args);
    sd = socket(1, SOCK_STREAM, 0);
    perror("socket ");
    saddr.sun_family = 1;
    strcpy(saddr.sun_path, op_sock);
    len = sizeof(saddr);
    rtn = connect(sd, (struct sockaddr *)&saddr, len);
    perror("connect ");
    if(op_notice == 1){
        strcpy(is_notice, "yes");
    }else{
        strcpy(is_notice, "no");
    }
    sprintf(buf, "NOTIFY System::SendMessage TIARRACONTROL/1.0\r\nSender: \r\nNotice: %s\r\nChannel: %s\r\nCharset: utf-8\r\nText: %s\r\n\r\n", is_notice, op_ch, op_msg);
    write(sd, buf, strlen(buf));
    perror("write ");
    close(sd);
}

variable_types:
args
char *[]

variable_types: sd int

variable_types: len int

variable_types: rtn int

variable_types:
buf
char [1024]

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


transpose

repo: koturn/C-study

original_code:
static void transpose(int *restrict *restrict dst, const int *const restrict *restrict src, uint row, uint col) {
  uint i;
  for (i = 0; i < row; i++) {
    uint j;
    for (j = 0; j < col; j++) {
      dst[j][i] = src[i][j];
    }
  }
}

canonical_original_code:
static void transpose(int **dst, int **src, unsigned int row, unsigned int col) {
  unsigned int i;
  for (i = 0; i < row; i++) {
    unsigned int j;
    for (j = 0; j < col; j++) {
      dst[j][i] = src[i][j];
    }
  }
}

variable_types:
dst
int **

variable_types:
src
int **

variable_types:
row
unsigned int

variable_types:
col
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int


decompiled_code:
int __fastcall show_2d_array(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rbp
__int64 v5; // r12
__int64 v6; // rbx
int result; // eax

if ( a2 )
{
v4 = a1;
v5 = 4LL * (unsigned int)(a3 - 1) + 4;
do
{
v6 = 0LL;
if ( a3 )
{
do
{
printf("%4d ", *(unsigned int *)(*v4 + v6));
v6 += 4LL;
}
while ( v6 != v5 );
}
result = puts(&s);
++v4;
}
while ( v4 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rbp
__int64 v5; // r12
__int64 v6; // rbx
int result; // eax

if ( a2 )
{
v4 = a1;
v5 = 4LL * (unsigned int)(a3 - 1) + 4;
do
{
v6 = 0LL;
if ( a3 )
{
do
{
printf("%4d ", *(unsigned int *)(*v4 + v6));
v6 += 4LL;
}
while ( v6 != v5 );
}
result = puts(&s);
++v4;
}
while ( v4 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

original_code:
static void show_2d_array(const int *const restrict *restrict array, uint row, uint col) {
  uint i;
  for (i = 0; i < row; i++) {
    uint j;
    for (j = 0; j < col; j++) {
      printf("%4d ", array[i][j]);
    }
    puts("");
  }
}

canonical_original_code:
static void show_2d_array(int **array, unsigned int row, unsigned int col) {
  unsigned int i;
  for (i = 0; i < row; i++) {
    unsigned int j;
    for (j = 0; j < col; j++) {
      printf("%4d ", array[i][j]);
    }
    puts("");
  }
}

variable_types:
array
int **


decompiled_code:
void **__fastcall alloc_2d_array(size_t nmemb, unsigned int a2)
{
void **v2; // r13
__int64 v3; // rbp
void *v4; // rbx
void **v6; // r12
void **v7; // rbp

v2 = (void **)calloc((unsigned int)nmemb, 8uLL);
if ( v2 && (_DWORD)nmemb )
{
v3 = 0LL;
while ( 1 )
{
v4 = calloc(a2, 4uLL);
v2[v3] = v4;
if ( !v4 )
break;
if ( ++v3 == (unsigned int)nmemb )
return v2;
}
v6 = v2;
v7 = &v2[(unsigned int)v3];
while ( v6 != v7 )
{
free(*v6);
*v6++ = 0LL;
}
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
void **__fastcall func2(size_t nmemb, unsigned int a2)
{
void **v2; // r13
__int64 v3; // rbp
void *v4; // rbx
void **v6; // r12
void **v7; // rbp

v2 = (void **)calloc((unsigned int)nmemb, 8uLL);
if ( v2 && (_DWORD)nmemb )
{
v3 = 0LL;
while ( 1 )
{
v4 = calloc(a2, 4uLL);
v2[v3] = v4;
if ( !v4 )
break;
if ( ++v3 == (unsigned int)nmemb )
return v2;
}
v6 = v2;
v7 = &v2[(unsigned int)v3];
while ( v6 != v7 )
{
free(*v6);
*v6++ = 0LL;
}
v2 = 0LL;
}
return v2;
}

original_code:
inline static int **alloc_2d_array(uint row, uint col) {
  uint i;
  int **array;
  if ((array = ((int * *)calloc((row), sizeof(int *)))) == ((void *)0)) {
    return ((void *)0);
  }
  for (i = 0; i < row; i++) {
    if ((array[i] = ((int *)calloc((col), sizeof(int)))) == ((void *)0)) {
      uint j;
      for (j = 0; j < i; j++) {
        (free(*(&array[j])), *(&array[j]) = ((void *)0));
      }
      return ((void *)0);
    }
  }
  return array;
}

canonical_original_code:
inline static int **alloc_2d_array(unsigned int row, unsigned int col) {
  unsigned int i;
  int **array;
  if ((array = ((int **)calloc((row), sizeof(int *)))) == ((void *)0)) {
    return ((void *)0);
  }
  for (i = 0; i < row; i++) {
    if ((array[i] = ((int *)calloc((col), sizeof(int)))) == ((void *)0)) {
      unsigned int j;
      for (j = 0; j < i; j++) {
        (free(*(&array[j])), *(&array[j]) = ((void *)0));
      }
      return ((void *)0);
    }
  }
  return array;
}

return_type: int **


decompiled_code:
void __fastcall free_2d_array(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
{
free(*v2);
*v2++ = 0LL;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
{
free(*v2);
*v2++ = 0LL;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

original_code:
inline static void free_2d_array(int **array, uint row) {
  uint i;
  for (i = 0; i < row; i++) {
    (free(*(&array[i])), *(&array[i]) = ((void *)0));
  }
  (free(*(&array)), *(&array) = ((void *)0));
}

canonical_original_code:
inline static void free_2d_array(int **array, unsigned int row) {
  unsigned int i;
  for (i = 0; i < row; i++) {
    (free(*(&array[i])), *(&array[i]) = ((void *)0));
  }
  (free(*(&array)), *(&array) = ((void *)0));
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void **v3; // r13
void **v4; // rax
void **v5; // r14
unsigned int i; // er12
int result; // eax
unsigned int v8; // ebx
int v9; // [rsp+4h] [rbp-34h] BYREF
unsigned int nmemb[12]; // [rsp+8h] [rbp-30h] BYREF

printf("Number of ROW = ?\b");
_isoc99_scanf("%u", &nmemb[1]);
printf("Number of COLUMN = ?\b");
_isoc99_scanf("%u", nmemb);
v3 = alloc_2d_array(nmemb[1], nmemb[0]);
v4 = alloc_2d_array(nmemb[0], nmemb[1]);
if ( v3 && (v5 = v4) != 0LL )
{
for ( i = 0; nmemb[1] > i; ++i )
{
if ( nmemb[0] )
{
v8 = 0;
do
{
_isoc99_scanf("%d", &v9);
*((_DWORD *)v3[i] + v8++) = v9;
}
while ( nmemb[0] > v8 );
}
}
puts(&s);
puts("Matrix = ");
show_2d_array(v3, nmemb[1], nmemb[0]);
puts("============================================================");
transpose((__int64)v5, (__int64)v3, nmemb[1], nmemb[0]);
puts("Transposed Matrix = ");
show_2d_array(v5, nmemb[0], nmemb[1]);
free_2d_array(v3, nmemb[1]);
free_2d_array(v5, nmemb[1]);
result = 0;
}
else
{
fwrite("Memory allocation error!\n", 1uLL, 0x19uLL, stderr);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void **v3; // r13
void **v4; // rax
void **v5; // r14
unsigned int i; // er12
int result; // eax
unsigned int v8; // ebx
int v9; // [rsp+4h] [rbp-34h] BYREF
unsigned int nmemb[12]; // [rsp+8h] [rbp-30h] BYREF

printf("Number of ROW = ?\b");
_isoc99_scanf("%u", &nmemb[1]);
printf("Number of COLUMN = ?\b");
_isoc99_scanf("%u", nmemb);
v3 = func2(nmemb[1], nmemb[0]);
v4 = func2(nmemb[0], nmemb[1]);
if ( v3 && (v5 = v4) != 0LL )
{
for ( i = 0; nmemb[1] > i; ++i )
{
if ( nmemb[0] )
{
v8 = 0;
do
{
_isoc99_scanf("%d", &v9);
*((_DWORD *)v3[i] + v8++) = v9;
}
while ( nmemb[0] > v8 );
}
}
puts(&s);
puts("Matrix = ");
func1(v3, nmemb[1], nmemb[0]);
puts("============================================================");
func0((__int64)v5, (__int64)v3, nmemb[1], nmemb[0]);
puts("Transposed Matrix = ");
func1(v5, nmemb[0], nmemb[1]);
func3(v3, nmemb[1]);
func3(v5, nmemb[1]);
result = 0;
}
else
{
fwrite("Memory allocation error!\n", 1uLL, 0x19uLL, stderr);
result = 1;
}
return result;
}

original_code:
int main(void) {
  uint row, col;
  uint i;
  int **array, **t_array;
  printf("Number of ROW    = ?\b"); scanf("%u", &row);
  printf("Number of COLUMN = ?\b"); scanf("%u", &col);
  array = alloc_2d_array(row, col);
  t_array = alloc_2d_array(col, row);
  if (array == ((void *)0) || t_array == ((void *)0)) {
    fputs("Memory allocation error!\n", stderr);
    return 1;
  }
  for (i = 0; i < row; i++) {
    uint j;
    for (j = 0; j < col; j++) {
      int tmp;
      scanf("%d", &tmp);
      array[i][j] = tmp;
    }
  }
  puts("");
  puts("Matrix = ");
  show_2d_array((const int *const *)array, row, col);
  puts("============================================================");
  transpose(t_array, (const int *const *)array, row, col);
  puts("Transposed Matrix = ");
  show_2d_array((const int *const *)t_array, col, row);
  free_2d_array(array, row);
  free_2d_array(t_array, row);
  return 0;
}

canonical_original_code:
int main() {
  unsigned int row; unsigned int col;
  unsigned int i;
  int **array; int **t_array;
  printf("Number of ROW    = ?\b"); scanf("%u", &row);
  printf("Number of COLUMN = ?\b"); scanf("%u", &col);
  array = alloc_2d_array(row, col);
  t_array = alloc_2d_array(col, row);
  if (array == ((void *)0) || t_array == ((void *)0)) {
    fputs("Memory allocation error!\n", stderr);
    return 1;
  }
  for (i = 0; i < row; i++) {
    unsigned int j;
    for (j = 0; j < col; j++) {
      int tmp;
      scanf("%d", &tmp);
      array[i][j] = tmp;
    }
  }
  puts("");
  puts("Matrix = ");
  show_2d_array((int **)array, row, col);
  puts("============================================================");
  transpose(t_array, (int **)array, row, col);
  puts("Transposed Matrix = ");
  show_2d_array((int **)t_array, col, row);
  free_2d_array(array, row);
  free_2d_array(t_array, row);
  return 0;
}

variable_types: tmp int


decompiled_code:
__int64 __fastcall binary2decimal(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v2 = v1 + 2 * v2 - 48;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v2 = v1 + 2 * v2 - 48;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

original_code:
inline static int binary2decimal(const char *restrict bstr) {
  int sum = 0;
  for (; *bstr != '\0'; bstr++) {
    sum <<= 1;
    sum += ((*bstr) - '0');
  }
  return sum;
}

canonical_original_code:
inline static int binary2decimal(char *bstr) {
  int sum = 0;
  for (; *bstr != '\0'; bstr++) {
    sum <<= 1;
    sum += ((*bstr) - '0');
  }
  return sum;
}

variable_types:
bstr
char *

variable_types: sum int


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

v3 = binary2decimal("1110");
printf("%d + 0b%s = %d\n", 124LL, "1110", (unsigned int)(v3 + 124));
return 0;
}

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

v3 = func0("1110");
printf("%d + 0b%s = %d\n", 124LL, "1110", (unsigned int)(v3 + 124));
return 0;
}

original_code:
int main(void) {
  static const int num = 124;
  static const char *bstr = "1110";
  printf("%d + 0b%s = %d\n", num, bstr, num + binary2decimal(bstr));
  return 0;
}

canonical_original_code:
int main() {
  static int num = 124;
  static char *bstr = "1110";
  printf("%d + 0b%s = %d\n", num, bstr, num + binary2decimal(bstr));
  return 0;
}

variable_types: num int


convert

decompiled_code:
double __fastcall convert(double result)
{
if ( result < 100.0 )
return result * 3.0;
if ( result >= 150.0 )
result = result * 0.5;
return result;
}

canonical_decompiled_code:
double __fastcall func0(double result)
{
if ( result < 100.0 )
return result * 3.0;
if ( result >= 150.0 )
result = result * 0.5;
return result;
}

original_code:
inline static double convert(double x) {
  return x < 100 ? x * 3
                 : x >= 150 ? x / 2
                            : x;
}

variable_types: x double

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
unsigned int v4; // ebp
double i; // rbx
double v6; // xmm1_8

v3 = 0.0;
v4 = 0;
for ( i = *(double *)&LC5; i < v3 - 0.00000001 || v3 + 0.00000001 < i; i = v6 )
{
++v4;
v6 = convert(i);
v3 = i;
}
printf(format, v4, envp, *(double *)&LC5, i);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
unsigned int v4; // ebp
double i; // rbx
double v6; // xmm1_8

v3 = 0.0;
v4 = 0;
for ( i = *(double *)&LC5; i < v3 - 0.00000001 || v3 + 0.00000001 < i; i = v6 )
{
++v4;
v6 = func0(i);
v3 = i;
}
printf(format, v4, envp, *(double *)&LC5, i);
return 0;
}

original_code:
int main(void) {
  static const double x = 7.9;
  double y = x;
  uint cnt = 0;
  double prev_y = 0.0;
  while (!(((prev_y) - EPS) <= ((y)) && ((y)) <= ((prev_y) + EPS))) {
    cnt++;
    prev_y = y;
    y = convert(y);
  }
  printf("%fに関数を%u回用いると%fになります\n", x, cnt, y);
  return 0;
}

canonical_original_code:
int main() {
  static double x = 7.9;
  double y = x;
  unsigned int cnt = 0;
  double prev_y = 0.0;
  while (!(((prev_y) - EPS) <= ((y)) && ((y)) <= ((prev_y) + EPS))) {
    cnt++;
    prev_y = y;
    y = convert(y);
  }
  printf("%fに関数を%u回用いると%fになります\n", x, cnt, y);
  return 0;
}

variable_types: y double

variable_types:
cnt
unsigned int


repo: koturn/LessonOfUniversity

decompiled_code:
size_t __fastcall trim_dirname(const char *a1)
{
size_t result; // rax
const char *v2; // rbx

result = strlen(a1);
v2 = &a1[(unsigned int)(result - 1)];
if ( *v2 == 47 )
*v2 = 0;
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
size_t result; // rax
const char *v2; // rbx

result = strlen(a1);
v2 = &a1[(unsigned int)(result - 1)];
if ( *v2 == 47 )
*v2 = 0;
return result;
}

original_code:
static void trim_dirname(char *dirname) {
  uint idx = strlen(dirname) - 1;
  if (dirname[idx] == '/') {
    dirname[idx] = '\0';
  }
}

canonical_original_code:
static void trim_dirname(char *dirname) {
  unsigned int idx = strlen(dirname) - 1;
  if (dirname[idx] == '/') {
    dirname[idx] = '\0';
  }
}

variable_types:
dirname
char *

variable_types:
idx
unsigned int


cmpfunc

decompiled_code:
int __fastcall cmpfunc(const void *a1, const void *a2)
{
return strcmp((const char *)(*(_QWORD *)a1 + 19LL), (const char *)(*(_QWORD *)a2 + 19LL));
}

canonical_decompiled_code:
int __fastcall func2(const void *a1, const void *a2)
{
return strcmp((const char *)(*(_QWORD *)a1 + 19LL), (const char *)(*(_QWORD *)a2 + 19LL));
}

original_code:
static int cmpfunc(const void *direntp1, const void *direntp2) {
  return strcmp((*(struct dirent *const *)direntp1)->d_name,
      (*(struct dirent *const *)direntp2)->d_name);
}

canonical_original_code:
static int cmpfunc(void *direntp1, void *direntp2) {
  return strcmp((*(struct dirent **)direntp1)->d_name,
      (*(struct dirent **)direntp2)->d_name);
}

user_defined_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; }


variable_types: mode int

variable_types:
str
char []


decompiled_code:
char *__fastcall uid_to_name(__uid_t a1)
{
struct passwd *v1; // rax

v1 = getpwuid(a1);
if ( v1 )
return v1->pw_name;
sprintf(numstr_1, "%u", a1);
return numstr_1;
}

canonical_decompiled_code:
char *__fastcall func4(__uid_t a1)
{
struct passwd *v1; // rax

v1 = getpwuid(a1);
if ( v1 )
return v1->pw_name;
sprintf(numstr_1, "%u", a1);
return numstr_1;
}

original_code:
static char *uid_to_name(uid_t uid) {
  struct passwd *getpwuid(), *pw_ptr;
  static char numstr[10];
  if ((pw_ptr = getpwuid(uid)) == ((void *)0)) {
    sprintf(numstr, "%u", uid);
    return numstr;
  } else {
    return pw_ptr->pw_name;
  }
}

canonical_original_code:
static char *uid_to_name(unsigned int uid) {
  struct passwd *getpwuid(); struct passwd *pw_ptr;
  static char numstr[10];
  if ((pw_ptr = getpwuid(uid)) == ((void *)0)) {
    sprintf(numstr, "%u", uid);
    return numstr;
  } else {
    return pw_ptr->pw_name;
  }
}

variable_types:
uid
unsigned 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; } *()

variable_types:
numstr
char [10]

return_type: char *


decompiled_code:
char *__fastcall gid_to_name(__gid_t a1)
{
struct group *v1; // rax

v1 = getgrgid(a1);
if ( v1 )
return v1->gr_name;
sprintf(numstr_0, "%u", a1);
return numstr_0;
}

canonical_decompiled_code:
char *__fastcall func5(__gid_t a1)
{
struct group *v1; // rax

v1 = getgrgid(a1);
if ( v1 )
return v1->gr_name;
sprintf(numstr_0, "%u", a1);
return numstr_0;
}

original_code:
static char *gid_to_name(gid_t gid) {
  struct group *getgrgid(), *grp_ptr;
  static char numstr[10];
  if ((grp_ptr = getgrgid(gid)) == ((void *)0)) {
    sprintf(numstr, "%u", gid);
    return numstr;
  } else {
    return grp_ptr->gr_name;
  }
}

canonical_original_code:
static char *gid_to_name(unsigned int gid) {
  struct group *getgrgid(); struct group *grp_ptr;
  static char numstr[10];
  if ((grp_ptr = getgrgid(gid)) == ((void *)0)) {
    sprintf(numstr, "%u", gid);
    return numstr;
  } else {
    return grp_ptr->gr_name;
  }
}

variable_types:
gid
unsigned int

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *()


decompiled_code:
int __fastcall show_file_info(char *s, __int64 a2)
{
char *v2; // rax
char *v3; // rax
char *v4; // rax
char v6[35]; // [rsp+5h] [rbp-23h] BYREF

mode_to_letters(*(_DWORD *)(a2 + 24), v6);
printf("%s", v6);
printf("%4d ", *(unsigned int *)(a2 + 16));
v2 = uid_to_name(*(_DWORD *)(a2 + 28));
printf("%-8s ", v2);
v3 = gid_to_name(*(_DWORD *)(a2 + 32));
printf("%-8s ", v3);
printf("%8ld ", *(_QWORD *)(a2 + 48));
v4 = ctime((const time_t *)(a2 + 88));
printf("%.12s ", v4 + 4);
return puts(s);
}

original_code:
static void show_file_info(const char *filename, const struct stat *info_p) {
  char *uid_to_name(), *ctime(), *gid_to_name(), *filemode();
  void mode_to_letters();
  char modestr[11];
  mode_to_letters(info_p->st_mode, modestr);
  printf("%s" , modestr);
  printf("%4d " , (int)info_p->st_nlink);
  printf("%-8s " , uid_to_name(info_p->st_uid));
  printf("%-8s " , gid_to_name(info_p->st_gid));
  printf("%8ld " , (long)info_p->st_size);
  printf("%.12s ", 4 + ctime(&info_p->st_mtim.tv_sec));
  printf("%s\n" , filename);
}

canonical_original_code:
static void show_file_info(char *filename, struct stat *info_p) {
  char *uid_to_name(); char *ctime(); char *gid_to_name(); char *filemode();
  void mode_to_letters();
  char modestr[11];
  mode_to_letters(info_p->st_mode, modestr);
  printf("%s" , modestr);
  printf("%4d " , (int)info_p->st_nlink);
  printf("%-8s " , uid_to_name(info_p->st_uid));
  printf("%-8s " , gid_to_name(info_p->st_gid));
  printf("%8ld " , (long)info_p->st_size);
  printf("%.12s ", 4 + ctime(&info_p->st_mtim.tv_sec));
  printf("%s\n" , filename);
}

variable_types:
filename
char *

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

variable_types:
ctime
char *()

variable_types:
filemode
char *()

variable_types:
modestr
char [11]

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


decompiled_code:
char *__fastcall make_relpath(char *dest, const char *a2, const char *a3)
{
strcpy(dest, a2);
*(_WORD *)&dest[strlen(dest)] = 47;
return strcat(dest, a3);
}

canonical_decompiled_code:
char *__fastcall func7(char *dest, const char *a2, const char *a3)
{
strcpy(dest, a2);
*(_WORD *)&dest[strlen(dest)] = 47;
return strcat(dest, a3);
}

original_code:
static void make_relpath(char *new_relpath, const char *relpath, const char *dirname) {
  strcpy(new_relpath, relpath);
  strcat(new_relpath, "/");
  strcat(new_relpath, dirname);
}

canonical_original_code:
static void make_relpath(char *new_relpath, char *relpath, char *dirname) {
  strcpy(new_relpath, relpath);
  strcat(new_relpath, "/");
  strcat(new_relpath, dirname);
}

variable_types:
relpath
char *


decompiled_code:
void __fastcall show_list(_QWORD *a1, const char *a2, unsigned int a3, unsigned int a4)
{
_QWORD *v4; // r15
_QWORD *v6; // rbp
struct stat *v7; // r12
const char *v8; // rbx
_QWORD *v9; // rbx
__int64 v10; // rbp
__int64 v11; // rbx
char *v12; // rdi
__int64 v13; // rbx
__mode_t *v14; // rbp
const char *v15; // r12
struct stat *buf; // [rsp+8h] [rbp-850h]
char path[1024]; // [rsp+20h] [rbp-838h] BYREF
char dest[1080]; // [rsp+420h] [rbp-438h] BYREF

v4 = a1;
buf = (struct stat *)malloc(144LL * a3);
if ( !buf )
{
fwrite(&unk_AE0, 1uLL, 0x1EuLL, stderr);
exit(1);
}
if ( a3 )
{
v6 = a1;
v7 = buf;
do
{
v8 = (const char *)(*v6 + 19LL);
if ( stat(v8, v7) == -1 )
{
perror(v8);
return;
}
++v6;
++v7;
}
while ( v6 != &a1[a3] );
if ( (a4 & 2) != 0 )
{
v10 = (__int64)buf;
v11 = 0LL;
do
{
v12 = (char *)(v4[v11] + 19LL);
if ( *v12 != 46 || (a4 & 1) != 0 )
show_file_info(v12, v10);
++v11;
v10 += 144LL;
}
while ( a3 > (unsigned int)v11 );
}
else
{
v9 = a1;
do
{
if ( *(_BYTE *)(*v9 + 19LL) != 46 || (a4 & 1) != 0 )
puts((const char *)(*v9 + 19LL));
++v9;
}
while ( v9 != &a1[a3] );
}
if ( (a4 & 4) != 0 )
{
v14 = &buf->st_mode;
v13 = 0LL;
do
{
if ( (*v14 & 0xF000) == 0x4000 )
{
v15 = (const char *)(v4[v13] + 19LL);
if ( strcmp(v15, ".") )
{
if ( strcmp((const char *)(v4[v13] + 19LL), "..") )
{
make_relpath(dest, a2, v15);
printf("\n%s:\n", dest);
getcwd(path, 0x400uLL);
chdir(v15);
do_ls(".", dest, a4);
chdir(path);
}
}
}
++v13;
v14 += 36;
}
while ( a3 > (unsigned int)v13 );
}
}
free(buf);
}

canonical_decompiled_code:
void __fastcall func8(_QWORD *a1, const char *a2, unsigned int a3, unsigned int a4)
{
_QWORD *v4; // r15
_QWORD *v6; // rbp
struct stat *v7; // r12
const char *v8; // rbx
_QWORD *v9; // rbx
__int64 v10; // rbp
__int64 v11; // rbx
char *v12; // rdi
__int64 v13; // rbx
__mode_t *v14; // rbp
const char *v15; // r12
struct stat *buf; // [rsp+8h] [rbp-850h]
char path[1024]; // [rsp+20h] [rbp-838h] BYREF
char dest[1080]; // [rsp+420h] [rbp-438h] BYREF

v4 = a1;
buf = (struct stat *)malloc(144LL * a3);
if ( !buf )
{
fwrite(&unk_AE0, 1uLL, 0x1EuLL, stderr);
exit(1);
}
if ( a3 )
{
v6 = a1;
v7 = buf;
do
{
v8 = (const char *)(*v6 + 19LL);
if ( stat(v8, v7) == -1 )
{
perror(v8);
return;
}
++v6;
++v7;
}
while ( v6 != &a1[a3] );
if ( (a4 & 2) != 0 )
{
v10 = (__int64)buf;
v11 = 0LL;
do
{
v12 = (char *)(v4[v11] + 19LL);
if ( *v12 != 46 || (a4 & 1) != 0 )
func6(v12, v10);
++v11;
v10 += 144LL;
}
while ( a3 > (unsigned int)v11 );
}
else
{
v9 = a1;
do
{
if ( *(_BYTE *)(*v9 + 19LL) != 46 || (a4 & 1) != 0 )
puts((const char *)(*v9 + 19LL));
++v9;
}
while ( v9 != &a1[a3] );
}
if ( (a4 & 4) != 0 )
{
v14 = &buf->st_mode;
v13 = 0LL;
do
{
if ( (*v14 & 0xF000) == 0x4000 )
{
v15 = (const char *)(v4[v13] + 19LL);
if ( strcmp(v15, ".") )
{
if ( strcmp((const char *)(v4[v13] + 19LL), "..") )
{
func7(dest, a2, v15);
printf("\n%s:\n", dest);
getcwd(path, 0x400uLL);
chdir(v15);
func9(".", dest, a4);
chdir(path);
}
}
}
++v13;
v14 += 36;
}
while ( a3 > (unsigned int)v13 );
}
}
free(buf);
}

original_code:
static void show_list(struct dirent *const dirent_array[], const char relpath[], uint end_idx, int opt_flag) {
  uint i;
  char *filename;
  struct stat *infos = ((struct stat *)malloc(sizeof(struct stat) * (end_idx)));
  if (infos == ((void *)0)) {
    fputs("メモリ確保エラーです", stderr);
    exit(1);
  }
  for (i = 0; i < end_idx; i++) {
    char *filename = dirent_array[i]->d_name;
    if (stat(filename, &infos[i]) == -1) {
      perror(filename);
      return;
    }
  }
  if (opt_flag & INFO_FLAG) {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (filename[0] == '.' && !(opt_flag & ALL_FLAG)) continue;
      show_file_info(filename, &infos[i]);
    }
  } else {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (filename[0] == '.' && !(opt_flag & ALL_FLAG)) continue;
      puts(filename);
    }
  }
  if (opt_flag & RECCURSE_FLAG) {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (((((infos[i].st_mode)) & 0170000) == (0040000)) && strcmp(filename, ".") && strcmp(filename, "..")) {
        char curdir_name[1024];
        char new_relpath[1024];
        make_relpath(new_relpath, relpath, filename);
        printf("\n%s:\n", new_relpath);
        getcwd(curdir_name, sizeof(curdir_name));
        chdir(filename);
        do_ls(".", new_relpath, opt_flag);
        chdir(curdir_name);
      }
    }
  }
  free(infos);
}

canonical_original_code:
static void show_list(struct dirent *dirent_array[], char relpath[], unsigned int end_idx, int opt_flag) {
  unsigned int i;
  char *filename;
  struct stat *infos = ((struct stat *)malloc(sizeof(struct stat) * (end_idx)));
  if (infos == ((void *)0)) {
    fputs("メモリ確保エラーです", stderr);
    exit(1);
  }
  for (i = 0; i < end_idx; i++) {
    char *filename = dirent_array[i]->d_name;
    if (stat(filename, &infos[i]) == -1) {
      perror(filename);
      return;
    }
  }
  if (opt_flag & INFO_FLAG) {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (filename[0] == '.' && !(opt_flag & ALL_FLAG)) continue;
      show_file_info(filename, &infos[i]);
    }
  } else {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (filename[0] == '.' && !(opt_flag & ALL_FLAG)) continue;
      puts(filename);
    }
  }
  if (opt_flag & RECCURSE_FLAG) {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (((((infos[i].st_mode)) & 0170000) == (0040000)) && strcmp(filename, ".") && strcmp(filename, "..")) {
        char curdir_name[1024];
        char new_relpath[1024];
        make_relpath(new_relpath, relpath, filename);
        printf("\n%s:\n", new_relpath);
        getcwd(curdir_name, sizeof(curdir_name));
        chdir(filename);
        do_ls(".", new_relpath, opt_flag);
        chdir(curdir_name);
      }
    }
  }
  free(infos);
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *[]

variable_types:
relpath
char []

variable_types:
i
unsigned int

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


decompiled_code:
__int64 __fastcall parse_args(int argc, char **argv, int *a3)
{
unsigned int v4; // ebx
char v5; // al

v4 = 0;
while ( 1 )
{
v5 = getopt(argc, argv, "alR");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'a':
v4 |= 1u;
break;
case 'l':
v4 |= 2u;
break;
case 'R':
v4 |= 4u;
break;
}
}
*a3 = optind;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv, int *a3)
{
unsigned int v4; // ebx
char v5; // al

v4 = 0;
while ( 1 )
{
v5 = getopt(argc, argv, "alR");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'a':
v4 |= 1u;
break;
case 'l':
v4 |= 2u;
break;
case 'R':
v4 |= 4u;
break;
}
}
*a3 = optind;
return v4;
}

original_code:
static int parse_args(int argc, char *argv[], uint *r_index) {
  int opt_flag = 0;
  char optch;
  while ((optch = getopt(argc, argv, "alR")) != -1) {
    switch (optch) {
      case 'a':
        opt_flag |= ALL_FLAG;
        break;
      case 'l':
        opt_flag |= INFO_FLAG;
        break;
      case 'R':
        opt_flag |= RECCURSE_FLAG;
        break;
    }
  }
  *r_index = optind;
  return opt_flag;
}

canonical_original_code:
static int parse_args(int argc, char *argv[], unsigned int *r_index) {
  int opt_flag = 0;
  char optch;
  while ((optch = getopt(argc, argv, "alR")) != -1) {
    switch (optch) {
      case 'a':
        opt_flag |= ALL_FLAG;
        break;
      case 'l':
        opt_flag |= INFO_FLAG;
        break;
      case 'R':
        opt_flag |= RECCURSE_FLAG;
        break;
    }
  }
  *r_index = optind;
  return opt_flag;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: optch char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // eax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = parse_args(argc, (char **)argv, (int *)v6);
v4 = v6[0];
if ( argc == v6[0] )
{
if ( (v3 & 4) != 0 )
puts(".:");
do_ls(".", ".", v3);
}
else if ( argc - v6[0] == 1 )
{
trim_dirname(argv[v6[0]]);
if ( (v3 & 4) != 0 )
printf("%s:\n", argv[v6[0]]);
getcwd(curdir_name_2, 0x400uLL);
chdir(argv[v6[0]]);
do_ls(".", argv[v6[0]], v3);
chdir(curdir_name_2);
}
else if ( argc > v6[0] )
{
do
{
trim_dirname(argv[v4]);
printf("%s:\n", argv[v6[0]]);
getcwd(curdir_name_2, 0x400uLL);
chdir(argv[v6[0]]);
do_ls(".", argv[v6[0]], v3);
chdir(curdir_name_2);
v4 = v6[0] + 1;
v6[0] = v4;
}
while ( argc > v4 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // eax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = func0(argc, (char **)argv, (int *)v6);
v4 = v6[0];
if ( argc == v6[0] )
{
if ( (v3 & 4) != 0 )
puts(".:");
func9(".", ".", v3);
}
else if ( argc - v6[0] == 1 )
{
func1(argv[v6[0]]);
if ( (v3 & 4) != 0 )
printf("%s:\n", argv[v6[0]]);
getcwd(curdir_name_2, 0x400uLL);
chdir(argv[v6[0]]);
func9(".", argv[v6[0]], v3);
chdir(curdir_name_2);
}
else if ( argc > v6[0] )
{
do
{
func1(argv[v4]);
printf("%s:\n", argv[v6[0]]);
getcwd(curdir_name_2, 0x400uLL);
chdir(argv[v6[0]]);
func9(".", argv[v6[0]], v3);
chdir(curdir_name_2);
v4 = v6[0] + 1;
v6[0] = v4;
}
while ( argc > v4 );
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
  static char curdir_name[1024];
  uint r_index;
  int opt_flag = parse_args(argc, argv, &r_index);
  switch (argc - r_index) {
    case 0:
      if (opt_flag & RECCURSE_FLAG) {
        puts(".:");
      }
      do_ls(".", ".", opt_flag);
      break;
    case 1:
      trim_dirname(argv[r_index]);
      if (opt_flag & RECCURSE_FLAG) {
        printf("%s:\n", argv[r_index]);
      }
      getcwd(curdir_name, sizeof(curdir_name));
      chdir(argv[r_index]);
      do_ls(".", argv[r_index], opt_flag);
      chdir(curdir_name);
      break;
    default:
      for (; r_index < (uint)argc; r_index++) {
        trim_dirname(argv[r_index]);
        printf("%s:\n", argv[r_index]);
        getcwd(curdir_name, sizeof(curdir_name));
        chdir(argv[r_index]);
        do_ls(".", argv[r_index], opt_flag);
        chdir(curdir_name);
      }
      break;
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  static char curdir_name[1024];
  unsigned int r_index;
  int opt_flag = parse_args(argc, argv, &r_index);
  switch (argc - r_index) {
    case 0:
      if (opt_flag & RECCURSE_FLAG) {
        puts(".:");
      }
      do_ls(".", ".", opt_flag);
      break;
    case 1:
      trim_dirname(argv[r_index]);
      if (opt_flag & RECCURSE_FLAG) {
        printf("%s:\n", argv[r_index]);
      }
      getcwd(curdir_name, sizeof(curdir_name));
      chdir(argv[r_index]);
      do_ls(".", argv[r_index], opt_flag);
      chdir(curdir_name);
      break;
    default:
      for (; r_index < (unsigned int)argc; r_index++) {
        trim_dirname(argv[r_index]);
        printf("%s:\n", argv[r_index]);
        getcwd(curdir_name, sizeof(curdir_name));
        chdir(argv[r_index]);
        do_ls(".", argv[r_index], opt_flag);
        chdir(curdir_name);
      }
      break;
  }
  return 0;
}


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

if ( a1 == 5 )
{
puts("You win!!!!");
result = 1LL;
}
else
{
result = 0LL;
if ( a2 == 5 )
{
puts("You lose!!!!");
result = 1LL;
}
}
return result;
}

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

if ( a1 == 5 )
{
puts("You win!!!!");
result = 1LL;
}
else
{
result = 0LL;
if ( a2 == 5 )
{
puts("You lose!!!!");
result = 1LL;
}
}
return result;
}

original_code:
static uchar check_end(uint my_cnt, uint enemy_cnt) {
  if (my_cnt == 5) {
    puts("You win!!!!");
    return 1;
  } else if (enemy_cnt == 5) {
    puts("You lose!!!!");
    return 1;
  }
  return 0;
}

canonical_original_code:
static unsigned char check_end(unsigned int my_cnt, unsigned int enemy_cnt) {
  if (my_cnt == 5) {
    puts("You win!!!!");
    return 1;
  } else if (enemy_cnt == 5) {
    puts("You lose!!!!");
    return 1;
  }
  return 0;
}

return_type: unsigned char


judge

decompiled_code:
int __fastcall judge(unsigned __int64 a1, unsigned __int64 a2, unsigned int *a3, unsigned int *a4)
{
if ( a1 < a2 )
{
puts("You get a point!");
++*a3;
}
else if ( a1 <= a2 )
{
puts("Draw game!");
}
else
{
puts("Enemy get a point!");
++*a4;
}
printf("\nYour point : %u\n", *a3);
return printf("enemy's point : %u\n", *a4);
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int64 a1, unsigned __int64 a2, unsigned int *a3, unsigned int *a4)
{
if ( a1 < a2 )
{
puts("You get a point!");
++*a3;
}
else if ( a1 <= a2 )
{
puts("Draw game!");
}
else
{
puts("Enemy get a point!");
++*a4;
}
printf("\nYour point : %u\n", *a3);
return printf("enemy's point : %u\n", *a4);
}

original_code:
static void judge(ulong input_time, ulong enemy_time, uint *my_cnt, uint *enemy_cnt) {
  if (input_time < enemy_time) {
    puts("You get a point!");
    (*my_cnt)++;
  } else if (input_time > enemy_time) {
    puts("Enemy get a point!");
    (*enemy_cnt)++;
  } else {
    puts("Draw game!");
  }
  printf("\nYour point    : %u\n", *my_cnt);
  printf("enemy's point : %u\n", *enemy_cnt);
}

canonical_original_code:
static void judge(unsigned long input_time, unsigned long enemy_time, unsigned int *my_cnt, unsigned int *enemy_cnt) {
  if (input_time < enemy_time) {
    puts("You get a point!");
    (*my_cnt)++;
  } else if (input_time > enemy_time) {
    puts("Enemy get a point!");
    (*enemy_cnt)++;
  } else {
    puts("Draw game!");
  }
  printf("\nYour point    : %u\n", *my_cnt);
  printf("enemy's point : %u\n", *enemy_cnt);
}


decompiled_code:
__time_t gettimeofday_sec()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

canonical_decompiled_code:
__time_t func4()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

original_code:
static ulong gettimeofday_sec(void) {
  struct timeval t;
  gettimeofday(&t, ((void *)0));
  return t.tv_sec * 1000 + t.tv_usec / 1000;
}

canonical_original_code:
static unsigned long gettimeofday_sec() {
  struct timeval t;
  gettimeofday(&t, ((void *)0));
  return t.tv_sec * 1000 + t.tv_usec / 1000;
}

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

return_type: unsigned long


decompiled_code:
__int64 __fastcall show_ring_buf(__int64 a1, unsigned int a2, unsigned int a3)
{
int v5; // er12
__int64 result; // rax
const char *v7; // rdi

v5 = 0;
if ( a2 )
{
do
{
result = a3;
v7 = *(const char **)(a1 + 8LL * a3);
if ( !v7 )
break;
printf(v7);
++v5;
result = (a3 + 1) / a2;
a3 = (a3 + 1) % a2;
}
while ( a2 != v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3)
{
int v5; // er12
__int64 result; // rax
const char *v7; // rdi

v5 = 0;
if ( a2 )
{
do
{
result = a3;
v7 = *(const char **)(a1 + 8LL * a3);
if ( !v7 )
break;
printf(v7);
++v5;
result = (a3 + 1) / a2;
a3 = (a3 + 1) % a2;
}
while ( a2 != v5 );
}
return result;
}

original_code:
static void show_ring_buf(char *const *ring_buf, uint line_num, uint rb_idx) {
  uint i;
  for (i = 0; i < line_num && ring_buf[rb_idx] != ((void *)0); i++, rb_idx = (rb_idx + 1) % line_num) {
    1 ? (void) 0 : printf("%03d ", i + 1);
    printf(ring_buf[rb_idx]);
  }
}

canonical_original_code:
static void show_ring_buf(char **ring_buf, unsigned int line_num, unsigned int rb_idx) {
  unsigned int i;
  for (i = 0; i < line_num && ring_buf[rb_idx] != ((void *)0); i++, rb_idx = (rb_idx + 1) % line_num) {
    1 ? (void) 0 : printf("%03d ", i + 1);
    printf(ring_buf[rb_idx]);
  }
}


decompiled_code:
void __fastcall free_ring_buf(void *ptr, unsigned int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * a2) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr, unsigned int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * a2) );
}
free(ptr);
}

original_code:
static void free_ring_buf(char **ring_buf, uint line_num) {
  uint i;
  char **array_top = ring_buf;
  for (i = 0; i < line_num; i++, ring_buf++) {
    free(*ring_buf);
  }
  free(array_top);
}

canonical_original_code:
static void free_ring_buf(char **ring_buf, unsigned int line_num) {
  unsigned int i;
  char **array_top = ring_buf;
  for (i = 0; i < line_num; i++, ring_buf++) {
    free(*ring_buf);
  }
  free(array_top);
}


decompiled_code:
int __fastcall show_usage(const char *a1)
{
puts(&s);
printf(" %s [-options] prog_name\n", a1);
puts(aOptions);
puts(&byte_8E5);
puts(asc_980);
return puts(aN);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
puts(&s);
printf(" %s [-options] prog_name\n", a1);
puts(aOptions);
puts(&byte_8E5);
puts(asc_980);
return puts(aN);
}

original_code:
static void show_usage(const char *prog_name) {
  puts ("使い方");
  printf("  %s [-options] prog_name" "\n", prog_name);
  puts ("    [-options]は省略可能で、一番最後の引数の名前のファイルを読み込みます\n");
  puts ("オプション");
  puts ("  -f : ログ監視モードでファイルをオープンします");
  puts ("  -n : 何行表示するかを決定します");
}

canonical_original_code:
static void show_usage(char *prog_name) {
  puts ("使い方");
  printf("  %s [-options] prog_name" "\n", prog_name);
  puts ("    [-options]は省略可能で、一番最後の引数の名前のファイルを読み込みます\n");
  puts ("オプション");
  puts ("  -f : ログ監視モードでファイルをオープンします");
  puts ("  -n : 何行表示するかを決定します");
}


decompiled_code:
__int64 __fastcall convert_str2int(const char *a1)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 10);
if ( *endptr )
{
fwrite(&unk_9F8, 1uLL, 0x2BuLL, stderr);
exit(1);
}
if ( (int)result <= 0 )
{
fwrite(&unk_A28, 1uLL, 0x2FuLL, stderr);
exit(1);
}
if ( (_DWORD)result == 0x7FFFFFFF )
{
fwrite(&unk_8F5, 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 10);
if ( *endptr )
{
fwrite(&unk_9F8, 1uLL, 0x2BuLL, stderr);
exit(1);
}
if ( (int)result <= 0 )
{
fwrite(&unk_A28, 1uLL, 0x2FuLL, stderr);
exit(1);
}
if ( (_DWORD)result == 0x7FFFFFFF )
{
fwrite(&unk_8F5, 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

original_code:
static int convert_str2int(const char *str) {
  char *check;
  int num = strtol(str, &check, 10);
  if (*check != '\0') {
    fputs("文字列に数値以外がありました\n", stderr);
    exit(1);
  }
  if (num <= 0) {
    fputs("0以下の値を指定しないでください\n", stderr);
    exit(1);
  } else if (num == 0x7fffffff) {
    fputs("値が大きすぎます\n", stderr);
    exit(1);
  }
  return num;
}

canonical_original_code:
static int convert_str2int(char *str) {
  char *check;
  int num = strtol(str, &check, 10);
  if (*check != '\0') {
    fputs("文字列に数値以外がありました\n", stderr);
    exit(1);
  }
  if (num <= 0) {
    fputs("0以下の値を指定しないでください\n", stderr);
    exit(1);
  } else if (num == 0x7fffffff) {
    fputs("値が大きすぎます\n", stderr);
    exit(1);
  }
  return num;
}

variable_types:
str
char *

variable_types:
check
char *

variable_types: num int


decompiled_code:
void __fastcall free_2darray(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

original_code:
static void free_2darray(char **array, uint row) {
  register uint i;
  for (i = 0; i < row; i++) {
    free(array[i]);
  }
  free(array);
}

canonical_original_code:
static void free_2darray(char **array, unsigned int row) {
  register unsigned int i;
  for (i = 0; i < row; i++) {
    free(array[i]);
  }
  free(array);
}

variable_types:
array
char **

variable_types:
row
unsigned int


decompiled_code:
int __fastcall show_usage(const char *a1)
{
puts(&s);
printf(" $ %s\n", a1);
puts(asc_314);
printf(aS, a1);
puts(asc_33C);
puts(asc_370);
puts(asc_314);
puts(" Ctrl-C");
return puts(asc_3A0);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
puts(&s);
printf(" $ %s\n", a1);
puts(asc_314);
printf(aS, a1);
puts(asc_33C);
puts(asc_370);
puts(asc_314);
puts(" Ctrl-C");
return puts(asc_3A0);
}

original_code:
static void show_usage(const char *prog_name) {
  puts ("使い方:");
  printf("    $ %s" "\n", prog_name);
  puts ("  または");
  printf("    $ %s [ポート番号]" "\n", prog_name);
  puts ("\n終了方法:");
  puts ("    ゲーム中に\"quit\"と入力する");
  puts ("  または");
  puts ("    Ctrl-C");
  puts ("  で終了することができます。");
}

canonical_original_code:
static void show_usage(char *prog_name) {
  puts ("使い方:");
  printf("    $ %s" "\n", prog_name);
  puts ("  または");
  printf("    $ %s [ポート番号]" "\n", prog_name);
  puts ("\n終了方法:");
  puts ("    ゲーム中に\"quit\"と入力する");
  puts ("  または");
  puts ("    Ctrl-C");
  puts ("  で終了することができます。");
}


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

if ( a1 == 1 )
goto LABEL_4;
if ( a1 != 2 )
{
fwrite(&unk_3D0, 1uLL, 0x26uLL, stderr);
show_usage(*(const char **)a2);
return 0xFFFFFFFFLL;
}
result = convert_str2port(*(_QWORD *)(a2 + 8));
*a3 = result;
if ( (_DWORD)result != -1 )
{
LABEL_4:
*a3 = 50000;
result = 0LL;
}
return result;
}

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

if ( a1 == 1 )
goto LABEL_4;
if ( a1 != 2 )
{
fwrite(&unk_3D0, 1uLL, 0x26uLL, stderr);
func0(*(const char **)a2);
return 0xFFFFFFFFLL;
}
result = convert_str2port(*(_QWORD *)(a2 + 8));
*a3 = result;
if ( (_DWORD)result != -1 )
{
LABEL_4:
*a3 = 50000;
result = 0LL;
}
return result;
}

original_code:
static int arg_parse(int argc, char *argv[], int *port_num) {
  switch (argc) {
    case 2:
      *port_num = convert_str2port(argv[1]);
      if (*port_num == -1) return -1;
    case 1:
      *port_num = 50000;
      break;
    default:
      fputs("引数は1つにしてください。" "\n", stderr);
      show_usage(argv[0]);
      return -1;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall make_socket(__int16 a1)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebp
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

*(_DWORD *)&v5.sa_data[10] = 0;
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)v5.sa_data = _bswap_16(a1);
v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("socket");
v3 = -1;
}
else
{
v2 = v1;
v3 = bind(v1, &v5, 0x10u);
if ( v3 == -1 )
{
perror("bind");
}
else
{
listen(v2, 1);
fwrite("successfully bound, now waiting.\n", 1uLL, 0x21uLL, stderr);
v3 = accept(v2, 0LL, 0LL);
close(v2);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebp
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

*(_DWORD *)&v5.sa_data[10] = 0;
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[2] = (unsigned int)func2(0);
*(_WORD *)v5.sa_data = func3(a1);
v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("socket");
v3 = -1;
}
else
{
v2 = v1;
v3 = bind(v1, &v5, 0x10u);
if ( v3 == -1 )
{
perror("bind");
}
else
{
listen(v2, 1);
fwrite("successfully bound, now waiting.\n", 1uLL, 0x21uLL, stderr);
v3 = accept(v2, 0LL, 0LL);
close(v2);
}
}
return v3;
}

original_code:
static int make_socket(int port_num) {
  struct sockaddr_in me;
  int sock;
  int sock_new;
  memset((char *)&me, 0, sizeof(me));
  me.sin_family = 2;
  me.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  me.sin_port = htons(port_num);
  if ((sock = socket(2, SOCK_STREAM, 0)) < 0 ) {
    perror("socket");
    return -1;
  }
  if (bind(sock, (struct sockaddr *)&me, sizeof(me)) == -1){
    perror("bind");
    return -1;
  }
  listen(sock, 1);
  fputs("successfully bound, now waiting." "\n", stderr);
  sock_new = accept(sock, ((void *)0), ((void *)0));
  close(sock);
  return sock_new;
}

canonical_original_code:
static int make_socket(int port_num) {
  struct sockaddr_in me;
  int sock;
  int sock_new;
  memset((char *)&me, 0, sizeof(me));
  me.sin_family = 2;
  me.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  me.sin_port = htons(port_num);
  if ((sock = socket(2, SOCK_STREAM, 0)) < 0 ) {
    perror("socket");
    return -1;
  }
  if (bind(sock, (struct sockaddr *)&me, sizeof(me)) == -1){
    perror("bind");
    return -1;
  }
  listen(sock, 1);
  fputs("successfully bound, now waiting." "\n", stderr);
  sock_new = accept(sock, ((void *)0), ((void *)0));
  close(sock);
  return sock_new;
}

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

variable_types: sock int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // ebx
_QWORD *v5; // r12
__int64 v6; // rbp
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 1;
if ( (unsigned int)arg_parse(argc, (__int64)argv, v8) != -1 )
{
v4 = make_socket(v8[0]);
if ( v4 == -1 )
{
v3 = 1;
}
else
{
v5 = alloc_2darray(0x100u, 0x100u);
v6 = (unsigned int)read_question("question.txt", v5, 256LL);
v3 = play_game_server(v4, v5, v6);
free_2darray(v5, v6 - 1);
}
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // ebx
_QWORD *v5; // r12
__int64 v6; // rbp
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 1;
if ( (unsigned int)func1(argc, (__int64)argv, v8) != -1 )
{
v4 = func4(v8[0]);
if ( v4 == -1 )
{
v3 = 1;
}
else
{
v5 = alloc_2darray(0x100u, 0x100u);
v6 = (unsigned int)read_question("question.txt", v5, 256LL);
v3 = play_game_server(v4, v5, v6);
func5(v5, v6 - 1);
}
}
return v3;
}

original_code:
int main(int argc, char *argv[]) {
  int sock_new;
  int port_num;
  uint qnum;
  char **questions;
  int ret;
  if (arg_parse(argc, argv, &port_num) == -1) {
    return 1;
  }
  if ((sock_new = make_socket(port_num)) == -1) {
    return 1;
  }
  questions = alloc_2darray(256, 256);
  qnum = read_question(("question.txt"), questions, 256);
  ret = play_game_server(sock_new, questions, qnum);
  free_2darray(questions, qnum - 1);
  return ret;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int sock_new;
  int port_num;
  unsigned int qnum;
  char **questions;
  int ret;
  if (arg_parse(argc, argv, &port_num) == -1) {
    return 1;
  }
  if ((sock_new = make_socket(port_num)) == -1) {
    return 1;
  }
  questions = alloc_2darray(256, 256);
  qnum = read_question(("question.txt"), questions, 256);
  ret = play_game_server(sock_new, questions, qnum);
  free_2darray(questions, qnum - 1);
  return ret;
}

variable_types:
qnum
unsigned int

variable_types:
questions
char **

variable_types: ret int


decompiled_code:
__int64 __fastcall convert_str2port(const char *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = strtol(a1, &endptr, 10);
if ( *endptr )
{
fwrite(&unk_118, 1uLL, 0x34uLL, stderr);
v2 = -1;
}
else
{
v2 = v1;
if ( v1 > 0xFFFF )
{
fprintf(stderr, &format, 49152LL, 0xFFFFLL);
v2 = -1;
}
else if ( v1 <= 0x3FF )
{
fwrite(&unk_190, 1uLL, 0x40uLL, stderr);
fprintf(stderr, &format, 49152LL, 0xFFFFLL);
v2 = -1;
}
else if ( v1 - 1024 <= 0xBBFF )
{
fwrite(&unk_1D8, 1uLL, 0x42uLL, stderr);
fprintf(stderr, asc_220, 49152LL, 0xFFFFLL);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = strtol(a1, &endptr, 10);
if ( *endptr )
{
fwrite(&unk_118, 1uLL, 0x34uLL, stderr);
v2 = -1;
}
else
{
v2 = v1;
if ( v1 > 0xFFFF )
{
fprintf(stderr, &format, 49152LL, 0xFFFFLL);
v2 = -1;
}
else if ( v1 <= 0x3FF )
{
fwrite(&unk_190, 1uLL, 0x40uLL, stderr);
fprintf(stderr, &format, 49152LL, 0xFFFFLL);
v2 = -1;
}
else if ( v1 - 1024 <= 0xBBFF )
{
fwrite(&unk_1D8, 1uLL, 0x42uLL, stderr);
fprintf(stderr, asc_220, 49152LL, 0xFFFFLL);
}
}
return v2;
}

original_code:
int convert_str2port(const char *str) {
  char *check;
  int num = strtol(str, &check, 10);
  if (*check != '\0') {
    fputs("ポート番号は数値で指定してください" "\n", stderr);
    return -1;
  }
  if (num < 0 || 65535 < num) {
    fprintf((stderr), "ポート番号は %d~%d の範囲で指定してください" "\n", 49152, 65535);
    return -1;
  }
  if (0 <= num && num <= 1023) {
    fputs("ウェルノウンポートを指定しないでください。" "\n", stderr);
    fprintf((stderr), "ポート番号は %d~%d の範囲で指定してください" "\n", 49152, 65535);
    return -1;
  }
  if (1024 <= num && num <= 49151) {
    fputs("注意: 登録済みポート番号が指定されています。" "\n", stderr);
    fprintf((stderr), "      ポート番号を %d~%d の範囲で指定することを推奨します" "\n", 49152, 65535);
  }
  return num;
}

canonical_original_code:
int convert_str2port(char *str) {
  char *check;
  int num = strtol(str, &check, 10);
  if (*check != '\0') {
    fputs("ポート番号は数値で指定してください" "\n", stderr);
    return -1;
  }
  if (num < 0 || 65535 < num) {
    fprintf((stderr), "ポート番号は %d~%d の範囲で指定してください" "\n", 49152, 65535);
    return -1;
  }
  if (0 <= num && num <= 1023) {
    fputs("ウェルノウンポートを指定しないでください。" "\n", stderr);
    fprintf((stderr), "ポート番号は %d~%d の範囲で指定してください" "\n", 49152, 65535);
    return -1;
  }
  if (1024 <= num && num <= 49151) {
    fputs("注意: 登録済みポート番号が指定されています。" "\n", stderr);
    fprintf((stderr), "      ポート番号を %d~%d の範囲で指定することを推奨します" "\n", 49152, 65535);
  }
  return num;
}


decompiled_code:
int __fastcall print_fileinfo(char *s, char a2, unsigned int *a3)
{
if ( (a2 & 2) != 0 )
printf("%u ", a3[1]);
if ( (a2 & 4) != 0 )
printf("%u ", a3[2]);
if ( (a2 & 1) != 0 )
printf("%u ", *a3);
return puts(s);
}

canonical_decompiled_code:
int __fastcall func2(char *s, char a2, unsigned int *a3)
{
if ( (a2 & 2) != 0 )
printf("%u ", a3[1]);
if ( (a2 & 4) != 0 )
printf("%u ", a3[2]);
if ( (a2 & 1) != 0 )
printf("%u ", *a3);
return puts(s);
}

original_code:
static void print_fileinfo(const char *filename, int opt_flag, const wc_info *wi) {
  if (opt_flag & LINE_FLAG) printf("%u  ", wi->n_line);
  if (opt_flag & WORD_FLAG) printf("%u  ", wi->n_word);
  if (opt_flag & BYTE_FLAG) printf("%u  ", wi->n_byte);
  puts(filename);
}

canonical_original_code:
static void print_fileinfo(char *filename, int opt_flag, struct wc_info *wi) {
  if (opt_flag & LINE_FLAG) printf("%u  ", wi->n_line);
  if (opt_flag & WORD_FLAG) printf("%u  ", wi->n_word);
  if (opt_flag & BYTE_FLAG) printf("%u  ", wi->n_byte);
  puts(filename);
}

variable_types:
filename
char *

variable_types: struct wc_info { unsigned int n_byte; unsigned int n_line; unsigned int n_word; } *


decompiled_code:
__int64 __fastcall parse_args(int argc, char **argv, int *a3)
{
unsigned int v4; // ebx
char v5; // al

v4 = 0;
while ( 1 )
{
v5 = getopt(argc, argv, "clw");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'l':
v4 |= 2u;
break;
case 'w':
v4 |= 4u;
break;
case 'c':
v4 |= 1u;
break;
}
}
*a3 = optind;
if ( !v4 )
v4 = 7;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv, int *a3)
{
unsigned int v4; // ebx
char v5; // al

v4 = 0;
while ( 1 )
{
v5 = getopt(argc, argv, "clw");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'l':
v4 |= 2u;
break;
case 'w':
v4 |= 4u;
break;
case 'c':
v4 |= 1u;
break;
}
}
*a3 = optind;
if ( !v4 )
v4 = 7;
return v4;
}

original_code:
static int parse_args(int argc, char *argv[], uint *r_index) {
  int opt_flag = 0;
  char optch;
  while ((optch = getopt(argc, argv, "clw")) != -1) {
    switch (optch) {
      case 'c':
        opt_flag |= BYTE_FLAG;
        break;
      case 'l':
        opt_flag |= LINE_FLAG;
        break;
      case 'w':
        opt_flag |= WORD_FLAG;
        break;
    }
  }
  *r_index = optind;
  return opt_flag == 0x00 ? (BYTE_FLAG | LINE_FLAG | WORD_FLAG) : opt_flag;
}

canonical_original_code:
static int parse_args(int argc, char *argv[], unsigned int *r_index) {
  int opt_flag = 0;
  char optch;
  while ((optch = getopt(argc, argv, "clw")) != -1) {
    switch (optch) {
      case 'c':
        opt_flag |= BYTE_FLAG;
        break;
      case 'l':
        opt_flag |= LINE_FLAG;
        break;
      case 'w':
        opt_flag |= WORD_FLAG;
        break;
    }
  }
  *r_index = optind;
  return opt_flag == 0x00 ? (BYTE_FLAG | LINE_FLAG | WORD_FLAG) : opt_flag;
}


repo: koturn/WaveAnalyzer

decompiled_code:
__int64 __fastcall str2int(const char *a1)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 10);
if ( *endptr )
{
fwrite(&unk_378, 1uLL, 0x2BuLL, stderr);
exit(1);
}
if ( (int)result <= 0 )
{
fwrite(&unk_3A8, 1uLL, 0x2FuLL, stderr);
exit(1);
}
if ( (_DWORD)result == 0x7FFFFFFF )
{
fwrite(&unk_460, 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 10);
if ( *endptr )
{
fwrite(&unk_378, 1uLL, 0x2BuLL, stderr);
exit(1);
}
if ( (int)result <= 0 )
{
fwrite(&unk_3A8, 1uLL, 0x2FuLL, stderr);
exit(1);
}
if ( (_DWORD)result == 0x7FFFFFFF )
{
fwrite(&unk_460, 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

original_code:
static unsigned int str2int(const char *restrict nstr) {
  char *check;
  int num = strtol(nstr, &check, 10);
  if (*check != '\0') {
    fputs("文字列に数値以外がありました\n", stderr);
    exit(1);
  }
  if (num <= 0) {
    fputs("0以下の値を指定しないでください\n", stderr);
    exit(1);
  } else if (num == 0x7fffffff) {
    fputs("値が大きすぎます\n", stderr);
    exit(1);
  }
  return (unsigned int)num;
}

canonical_original_code:
static unsigned int str2int(char *nstr) {
  char *check;
  int num = strtol(nstr, &check, 10);
  if (*check != '\0') {
    fputs("文字列に数値以外がありました\n", stderr);
    exit(1);
  }
  if (num <= 0) {
    fputs("0以下の値を指定しないでください\n", stderr);
    exit(1);
  } else if (num == 0x7fffffff) {
    fputs("値が大きすぎます\n", stderr);
    exit(1);
  }
  return (unsigned int)num;
}

variable_types:
nstr
char *

return_type: unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
double *v4; // r13
double *v5; // r14
double *v6; // rsi
double *v7; // rbp
__int64 v8; // rbx
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // [rsp+8h] [rbp-80h]
double v12; // [rsp+10h] [rbp-78h]
__int64 v13; // [rsp+20h] [rbp-68h]
unsigned int v14; // [rsp+2Ch] [rbp-5Ch]

if ( argc == 3 )
{
v13 = read_wave_file(argv[1]);
v14 = str2int(argv[2]);
print_wave_header(v13);
v4 = (double *)calloc(v14, 8uLL);
v5 = (double *)calloc(v14, 8uLL);
v6 = (double *)calloc(v14, 0x10uLL);
if ( v5 == 0LL || v4 == 0LL || !v6 )
{
fwrite(&unk_3D8, 1uLL, 0x1FuLL, stderr);
result = 1;
}
else
{
auto_dft(v4, v5, *(_QWORD *)(v13 + 48), 0LL, v14);
v12 = (double)*(int *)(v13 + 24) / (double)(int)v14;
if ( v14 )
{
v7 = v6;
v8 = 0LL;
v11 = 0.0;
do
{
*v7 = (double)(int)v8 * v12;
v9 = v4[v8] * v4[v8] + v5[v8] * v5[v8];
if ( v9 < 0.0 )
v10 = sqrt(v9);
else
v10 = sqrt(v9);
v7[1] = v10;
v11 = fmax(v10, v11);
++v8;
v7 += 2;
}
while ( v8 != v14 );
}
if ( (unsigned int)show_gplot(v6, v14) == -1 )
{
fwrite(&unk_3F8, 1uLL, 0x20uLL, stderr);
fwrite(&unk_420, 1uLL, 0x3FuLL, stderr);
}
free(v4);
free(v5);
free(v6);
free_wave_data(v13);
result = 0;
}
}
else
{
fwrite("bad argument!\n", 1uLL, 0xEuLL, stderr);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
double *v4; // r13
double *v5; // r14
double *v6; // rsi
double *v7; // rbp
__int64 v8; // rbx
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // [rsp+8h] [rbp-80h]
double v12; // [rsp+10h] [rbp-78h]
__int64 v13; // [rsp+20h] [rbp-68h]
unsigned int v14; // [rsp+2Ch] [rbp-5Ch]

if ( argc == 3 )
{
v13 = read_wave_file(argv[1]);
v14 = func0(argv[2]);
print_wave_header(v13);
v4 = (double *)calloc(v14, 8uLL);
v5 = (double *)calloc(v14, 8uLL);
v6 = (double *)calloc(v14, 0x10uLL);
if ( v5 == 0LL || v4 == 0LL || !v6 )
{
fwrite(&unk_3D8, 1uLL, 0x1FuLL, stderr);
result = 1;
}
else
{
auto_dft(v4, v5, *(_QWORD *)(v13 + 48), 0LL, v14);
v12 = (double)*(int *)(v13 + 24) / (double)(int)v14;
if ( v14 )
{
v7 = v6;
v8 = 0LL;
v11 = 0.0;
do
{
*v7 = (double)(int)v8 * v12;
v9 = v4[v8] * v4[v8] + v5[v8] * v5[v8];
if ( v9 < 0.0 )
v10 = sqrt(v9);
else
v10 = sqrt(v9);
v7[1] = v10;
v11 = fmax(v10, v11);
++v8;
v7 += 2;
}
while ( v8 != v14 );
}
if ( (unsigned int)show_gplot(v6, v14) == -1 )
{
fwrite(&unk_3F8, 1uLL, 0x20uLL, stderr);
fwrite(&unk_420, 1uLL, 0x3FuLL, stderr);
}
free(v4);
free(v5);
free(v6);
free_wave_data(v13);
result = 0;
}
}
else
{
fwrite("bad argument!\n", 1uLL, 0xEuLL, stderr);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
  unsigned int N;
  unsigned int k;
  double frq_rate;
  double *restrict f_real;
  double *restrict f_imag;
  WAVE_DATA *restrict wd;
  POINT *restrict points;
  RANGE range = {{0.0, 0.0}, {0.0, 0.0}};
  if (argc != 3) {
    fprintf(stderr, "bad argument!\n");
    return 1;
  }
  wd = read_wave_file(argv[1]);
  N = str2int(argv[2]);
  print_wave_header(wd);
  f_real = ((double *)calloc((N), sizeof(double)));
  f_imag = ((double *)calloc((N), sizeof(double)));
  points = ((POINT *)calloc((N), sizeof(POINT)));
  if (f_real == ((void *)0) || f_imag == ((void *)0) || points == ((void *)0)) {
    fputs("メモリ確保エラーです\n", stderr);
    return 1;
  }
  auto_dft(f_real, f_imag, wd->s_data1, ((void *)0), N);
  frq_rate = (double)wd->samples_per_sec / N;
  for (k = 0; k < N; k++) {
    points[k].x = frq_rate * k;
    points[k].y = sqrt(((f_real[k]) * (f_real[k])) + ((f_imag[k]) * (f_imag[k])));
    if (range.max.y < points[k].y) range.max.y = points[k].y;
  }
  range.max.x = (double)wd->samples_per_sec / 2;
  range.max.y = (range.max.y == 0.0 ? 1.0 : range.max.y * 1.2);
  if (show_gplot(points, N, range) == -1) {
    fputs("gnuplotを起動できません\n", stderr);
    fputs("gnuplotにPATHが通っているか、確認してください\n", stderr);
  }
  (free(*(&f_real)), *(&f_real) = ((void *)0));
  (free(*(&f_imag)), *(&f_imag) = ((void *)0));
  (free(*(&points)), *(&points) = ((void *)0));
  free_wave_data(wd);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  unsigned int N;
  unsigned int k;
  double frq_rate;
  double *f_real;
  double *f_imag;
  struct WAVE_DATA *wd;
  struct POINT *points;
  struct RANGE range = {{0.0, 0.0}, {0.0, 0.0}};
  if (argc != 3) {
    fprintf(stderr, "bad argument!\n");
    return 1;
  }
  wd = read_wave_file(argv[1]);
  N = str2int(argv[2]);
  print_wave_header(wd);
  f_real = ((double *)calloc((N), sizeof(double)));
  f_imag = ((double *)calloc((N), sizeof(double)));
  points = ((struct POINT *)calloc((N), sizeof(POINT)));
  if (f_real == ((void *)0) || f_imag == ((void *)0) || points == ((void *)0)) {
    fputs("メモリ確保エラーです\n", stderr);
    return 1;
  }
  auto_dft(f_real, f_imag, wd->s_data1, ((void *)0), N);
  frq_rate = (double)wd->samples_per_sec / N;
  for (k = 0; k < N; k++) {
    points[k].x = frq_rate * k;
    points[k].y = sqrt(((f_real[k]) * (f_real[k])) + ((f_imag[k]) * (f_imag[k])));
    if (range.max.y < points[k].y) range.max.y = points[k].y;
  }
  range.max.x = (double)wd->samples_per_sec / 2;
  range.max.y = (range.max.y == 0.0 ? 1.0 : range.max.y * 1.2);
  if (show_gplot(points, N, range) == -1) {
    fputs("gnuplotを起動できません\n", stderr);
    fputs("gnuplotにPATHが通っているか、確認してください\n", stderr);
  }
  (free(*(&f_real)), *(&f_real) = ((void *)0));
  (free(*(&f_imag)), *(&f_imag) = ((void *)0));
  (free(*(&points)), *(&points) = ((void *)0));
  free_wave_data(wd);
  return 0;
}

variable_types: argc int

variable_types:
N
unsigned int

variable_types:
k
unsigned int

variable_types: struct WAVE_DATA { char riff_chunk_id[4]; unsigned int riff_chunk_size; char file_format_type[4]; char fmt_chunk_id[4]; unsigned int fmt_chunk_size; unsigned short wave_format_type; unsigned short channel; unsigned int samples_per_sec; unsigned int bytes_per_sec; unsigned short block_size; unsigned short bits_per_sample; char data_chunk_id[4]; unsigned int data_chunk_size; double *s_data1; double *s_data2; unsigned int length; } *

variable_types:
points
struct POINT { double x; double y; } *

variable_types: struct RANGE { struct POINT { double x; double y; } min; struct POINT max; }

user_defined_types: struct RANGE { struct POINT min; struct POINT max; }


decompiled_code:
void __fastcall free_wave_data(void *ptr)
{
free(*((void **)ptr + 6));
free(*((void **)ptr + 7));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
free(*((void **)ptr + 6));
free(*((void **)ptr + 7));
free(ptr);
}

original_code:
void free_wave_data(WAVE_DATA *restrict wd) {
  (free(*(&wd->s_data1)), *(&wd->s_data1) = ((void *)0));
  (free(*(&wd->s_data2)), *(&wd->s_data2) = ((void *)0));
  (free(*(&wd)), *(&wd) = ((void *)0));
}

canonical_original_code:
void free_wave_data(struct WAVE_DATA *wd) {
  (free(*(&wd->s_data1)), *(&wd->s_data1) = ((void *)0));
  (free(*(&wd->s_data2)), *(&wd->s_data2) = ((void *)0));
  (free(*(&wd)), *(&wd) = ((void *)0));
}

user_defined_types: struct WAVE_DATA { char riff_chunk_id[4]; unsigned int riff_chunk_size; char file_format_type[4]; char fmt_chunk_id[4]; unsigned int fmt_chunk_size; unsigned short wave_format_type; unsigned short channel; unsigned int samples_per_sec; unsigned int bytes_per_sec; unsigned short block_size; unsigned short bits_per_sample; char data_chunk_id[4]; unsigned int data_chunk_size; double *s_data1; double *s_data2; unsigned int length; }


decompiled_code:
int __fastcall print_wave_header(__int64 a1)
{
unsigned __int16 v1; // si
const char *v2; // rdx
unsigned __int16 v3; // si
const char *v4; // rdx

printf("riff_chunk_id (4byte):%12.4s (%s)\n", (const char *)a1, "constant");
printf("riff_chunk_size (4byte):%12u (%s)\n", *(unsigned int *)(a1 + 4), "36 + data_chunk_size");
printf("file_format_type (4byte):%12.4s (%s)\n", (const char *)(a1 + 8), "constant");
printf("fmt_chunk_id (4byte):%12.4s (%s)\n", (const char *)(a1 + 12), "constant");
printf("fmt_chunk_size (4byte):%12u (%s)\n", *(unsigned int *)(a1 + 16), "constant");
v1 = *(_WORD *)(a1 + 20);
v2 = "PCM";
if ( v1 != 1 )
v2 = "UNKNOWN";
printf("wave_format_type (2byte):%12u (%s)\n", v1, v2);
v3 = *(_WORD *)(a1 + 22);
v4 = "MONAURAL";
if ( v3 != 1 )
v4 = "STEREO";
printf("channel (2byte):%12u (%s)\n", v3, v4);
printf("samples_per_sec (4byte):%12u\n", *(unsigned int *)(a1 + 24));
printf("bytes_per_sec (4byte):%12u (%s)\n", *(unsigned int *)(a1 + 28), "block_size * samples_per_sec");
printf("block_size (2byte):%12u (%s)\n", *(unsigned __int16 *)(a1 + 32), "bits_per_sample * channel / 8");
printf("bits_per_sample (2byte):%12u\n", *(unsigned __int16 *)(a1 + 34));
printf("data_chunk_id (4byte):%12.4s (%s)\n", (const char *)(a1 + 36), "constant");
return printf("data_chunk_size (4byte):%12u\n", *(unsigned int *)(a1 + 40));
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
unsigned __int16 v1; // si
const char *v2; // rdx
unsigned __int16 v3; // si
const char *v4; // rdx

printf("riff_chunk_id (4byte):%12.4s (%s)\n", (const char *)a1, "constant");
printf("riff_chunk_size (4byte):%12u (%s)\n", *(unsigned int *)(a1 + 4), "36 + data_chunk_size");
printf("file_format_type (4byte):%12.4s (%s)\n", (const char *)(a1 + 8), "constant");
printf("fmt_chunk_id (4byte):%12.4s (%s)\n", (const char *)(a1 + 12), "constant");
printf("fmt_chunk_size (4byte):%12u (%s)\n", *(unsigned int *)(a1 + 16), "constant");
v1 = *(_WORD *)(a1 + 20);
v2 = "PCM";
if ( v1 != 1 )
v2 = "UNKNOWN";
printf("wave_format_type (2byte):%12u (%s)\n", v1, v2);
v3 = *(_WORD *)(a1 + 22);
v4 = "MONAURAL";
if ( v3 != 1 )
v4 = "STEREO";
printf("channel (2byte):%12u (%s)\n", v3, v4);
printf("samples_per_sec (4byte):%12u\n", *(unsigned int *)(a1 + 24));
printf("bytes_per_sec (4byte):%12u (%s)\n", *(unsigned int *)(a1 + 28), "block_size * samples_per_sec");
printf("block_size (2byte):%12u (%s)\n", *(unsigned __int16 *)(a1 + 32), "bits_per_sample * channel / 8");
printf("bits_per_sample (2byte):%12u\n", *(unsigned __int16 *)(a1 + 34));
printf("data_chunk_id (4byte):%12.4s (%s)\n", (const char *)(a1 + 36), "constant");
return printf("data_chunk_size (4byte):%12u\n", *(unsigned int *)(a1 + 40));
}

original_code:
void print_wave_header(const WAVE_DATA *restrict wd) {
  printf("riff_chunk_id    (4byte):%12.4s (%s)\n", wd->riff_chunk_id, "constant");
  printf("riff_chunk_size  (4byte):%12u (%s)\n", wd->riff_chunk_size, "36 + data_chunk_size");
  printf("file_format_type (4byte):%12.4s (%s)\n", wd->file_format_type, "constant");
  printf("fmt_chunk_id     (4byte):%12.4s (%s)\n", wd->fmt_chunk_id, "constant");
  printf("fmt_chunk_size   (4byte):%12u (%s)\n", wd->fmt_chunk_size, "constant");
  printf("wave_format_type (2byte):%12u (%s)\n", wd->wave_format_type, wd->wave_format_type == 1 ? "PCM" : "UNKNOWN");
  printf("channel          (2byte):%12u (%s)\n", wd->channel, wd->channel == 1 ? "MONAURAL" : "STEREO");
  printf("samples_per_sec  (4byte):%12u\n", wd->samples_per_sec);
  printf("bytes_per_sec    (4byte):%12u (%s)\n", wd->bytes_per_sec, "block_size * samples_per_sec");
  printf("block_size       (2byte):%12u (%s)\n", wd->block_size, "bits_per_sample * channel / 8");
  printf("bits_per_sample  (2byte):%12u\n", wd->bits_per_sample);
  printf("data_chunk_id    (4byte):%12.4s (%s)\n", wd->data_chunk_id, "constant");
  printf("data_chunk_size  (4byte):%12u\n", wd->data_chunk_size);
}

canonical_original_code:
void print_wave_header(struct WAVE_DATA *wd) {
  printf("riff_chunk_id    (4byte):%12.4s (%s)\n", wd->riff_chunk_id, "constant");
  printf("riff_chunk_size  (4byte):%12u (%s)\n", wd->riff_chunk_size, "36 + data_chunk_size");
  printf("file_format_type (4byte):%12.4s (%s)\n", wd->file_format_type, "constant");
  printf("fmt_chunk_id     (4byte):%12.4s (%s)\n", wd->fmt_chunk_id, "constant");
  printf("fmt_chunk_size   (4byte):%12u (%s)\n", wd->fmt_chunk_size, "constant");
  printf("wave_format_type (2byte):%12u (%s)\n", wd->wave_format_type, wd->wave_format_type == 1 ? "PCM" : "UNKNOWN");
  printf("channel          (2byte):%12u (%s)\n", wd->channel, wd->channel == 1 ? "MONAURAL" : "STEREO");
  printf("samples_per_sec  (4byte):%12u\n", wd->samples_per_sec);
  printf("bytes_per_sec    (4byte):%12u (%s)\n", wd->bytes_per_sec, "block_size * samples_per_sec");
  printf("block_size       (2byte):%12u (%s)\n", wd->block_size, "bits_per_sample * channel / 8");
  printf("bits_per_sample  (2byte):%12u\n", wd->bits_per_sample);
  printf("data_chunk_id    (4byte):%12.4s (%s)\n", wd->data_chunk_id, "constant");
  printf("data_chunk_size  (4byte):%12u\n", wd->data_chunk_size);
}


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

result = calloc(1uLL, 0x48uLL);
*result = 1179011410;
result[2] = 1163280727;
result[3] = 544501094;
result[4] = 16;
*((_WORD *)result + 10) = 1;
result[9] = 1635017060;
return result;
}

original_code:
WAVE_DATA *make_skelton_wave_data(void) {
  WAVE_DATA *wd = ((WAVE_DATA *)calloc((1), sizeof(WAVE_DATA)));
  strncpy(wd->riff_chunk_id, "RIFF", sizeof(char) * 4);
  strncpy(wd->file_format_type, "WAVE", sizeof(char) * 4);
  strncpy(wd->fmt_chunk_id, "fmt ", sizeof(char) * 4);
  wd->fmt_chunk_size = 16;
  wd->wave_format_type = 1;
  strncpy(wd->data_chunk_id, "data", sizeof(char) * 4);
  return wd;
}

canonical_original_code:
struct WAVE_DATA *make_skelton_wave_data() {
  struct WAVE_DATA *wd = ((WAVE_DATA *)calloc((1), sizeof(WAVE_DATA)));
  strncpy(wd->riff_chunk_id, "RIFF", sizeof(char) * 4);
  strncpy(wd->file_format_type, "WAVE", sizeof(char) * 4);
  strncpy(wd->fmt_chunk_id, "fmt ", sizeof(char) * 4);
  wd->fmt_chunk_size = 16;
  wd->wave_format_type = 1;
  strncpy(wd->data_chunk_id, "data", sizeof(char) * 4);
  return wd;
}

return_type: struct WAVE_DATA { char riff_chunk_id[4]; unsigned int riff_chunk_size; char file_format_type[4]; char fmt_chunk_id[4]; unsigned int fmt_chunk_size; unsigned short wave_format_type; unsigned short channel; unsigned int samples_per_sec; unsigned int bytes_per_sec; unsigned short block_size; unsigned short bits_per_sample; char data_chunk_id[4]; unsigned int data_chunk_size; double *s_data1; double *s_data2; unsigned int length; } *


decompiled_code:
__int64 __fastcall set_wave_data(__int64 a1, const void *a2, const void *a3, unsigned int a4, int a5, unsigned __int16 a6, unsigned __int16 a7)
{
int v10; // edx
int v11; // eax
void *v12; // rdi
__int64 result; // rax
void *v14; // rdi

*(_DWORD *)(a1 + 24) = a5;
*(_WORD *)(a1 + 22) = a6;
*(_WORD *)(a1 + 34) = a7;
v10 = a4 * a6 * (a7 >> 3);
*(_DWORD *)(a1 + 40) = v10;
*(_DWORD *)(a1 + 4) = v10 + 36;
v11 = a6 * a7 / 8;
*(_WORD *)(a1 + 32) = v11;
*(_DWORD *)(a1 + 28) = a5 * (unsigned __int16)v11;
if ( a2 )
{
v12 = calloc(a4, 8uLL);
*(_QWORD *)(a1 + 48) = v12;
if ( !v12 )
return 0xFFFFFFFFLL;
memcpy(v12, a2, a4);
}
result = 0LL;
if ( a3 )
{
v14 = calloc(a4, 8uLL);
*(_QWORD *)(a1 + 56) = v14;
if ( v14 )
{
memcpy(v14, a3, a4);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, const void *a2, const void *a3, unsigned int a4, int a5, unsigned __int16 a6, unsigned __int16 a7)
{
int v10; // edx
int v11; // eax
void *v12; // rdi
__int64 result; // rax
void *v14; // rdi

*(_DWORD *)(a1 + 24) = a5;
*(_WORD *)(a1 + 22) = a6;
*(_WORD *)(a1 + 34) = a7;
v10 = a4 * a6 * (a7 >> 3);
*(_DWORD *)(a1 + 40) = v10;
*(_DWORD *)(a1 + 4) = v10 + 36;
v11 = a6 * a7 / 8;
*(_WORD *)(a1 + 32) = v11;
*(_DWORD *)(a1 + 28) = a5 * (unsigned __int16)v11;
if ( a2 )
{
v12 = calloc(a4, 8uLL);
*(_QWORD *)(a1 + 48) = v12;
if ( !v12 )
return 0xFFFFFFFFLL;
memcpy(v12, a2, a4);
}
result = 0LL;
if ( a3 )
{
v14 = calloc(a4, 8uLL);
*(_QWORD *)(a1 + 56) = v14;
if ( v14 )
{
memcpy(v14, a3, a4);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int set_wave_data(
    WAVE_DATA *restrict wd,
    const double *restrict s_data1,
    const double *restrict s_data2,
    unsigned int N,
    unsigned int samples_per_sec,
    unsigned short channel,
    unsigned short bits_per_sample)
{
  wd->samples_per_sec = samples_per_sec;
  wd->channel = channel;
  wd->bits_per_sample = bits_per_sample;
  wd->data_chunk_size = N * channel * (bits_per_sample / 8);
  wd->riff_chunk_size = 36 + wd->data_chunk_size;
  wd->block_size = wd->bits_per_sample * wd->channel / 8;
  wd->bytes_per_sec = wd->block_size * wd->samples_per_sec;
  if (s_data1 != ((void *)0)) {
    if ((wd->s_data1 = ((double *)calloc((N), sizeof(double)))) == ((void *)0)) {
      return -1;
    }
    memcpy(wd->s_data1, s_data1, N);
  }
  if (s_data2 != ((void *)0)) {
    if ((wd->s_data2 = ((double *)calloc((N), sizeof(double)))) == ((void *)0)) {
      return -1;
    }
    memcpy(wd->s_data2, s_data2, N);
  }
  return 0;
}

canonical_original_code:
int set_wave_data(struct WAVE_DATA *wd, double *s_data1, double *s_data2, unsigned int N, unsigned int samples_per_sec, unsigned short channel, unsigned short bits_per_sample)
{
  wd->samples_per_sec = samples_per_sec;
  wd->channel = channel;
  wd->bits_per_sample = bits_per_sample;
  wd->data_chunk_size = N * channel * (bits_per_sample / 8);
  wd->riff_chunk_size = 36 + wd->data_chunk_size;
  wd->block_size = wd->bits_per_sample * wd->channel / 8;
  wd->bytes_per_sec = wd->block_size * wd->samples_per_sec;
  if (s_data1 != ((void *)0)) {
    if ((wd->s_data1 = ((double *)calloc((N), sizeof(double)))) == ((void *)0)) {
      return -1;
    }
    memcpy(wd->s_data1, s_data1, N);
  }
  if (s_data2 != ((void *)0)) {
    if ((wd->s_data2 = ((double *)calloc((N), sizeof(double)))) == ((void *)0)) {
      return -1;
    }
    memcpy(wd->s_data2, s_data2, N);
  }
  return 0;
}

variable_types:
channel
unsigned short


repo: koturn/example

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

if ( a1 != a2 || (result = 1LL, a2 != a3) )
{
if ( a1 < a2 && a1 > 0 && a2 < a3 )
{
result = 2LL;
}
else if ( a2 <= a3 || a3 <= 0 || (result = 3LL, a1 <= a2) )
{
result = 0LL;
}
}
return result;
}

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

if ( a1 != a2 || (result = 1LL, a2 != a3) )
{
if ( a1 < a2 && a1 > 0 && a2 < a3 )
{
result = 2LL;
}
else if ( a2 <= a3 || a3 <= 0 || (result = 3LL, a1 <= a2) )
{
result = 0LL;
}
}
return result;
}

original_code:
int func2(int a, int b, int c)
{
  if (a == b && b == c) {
    return 1;
  } else if (0 < a && a < b && b < c) {
    return 2;
  } else if (0 < c && c < b && b < a) {
    return 3;
  } else {
    return 0;
  }
}

variable_types: a int

variable_types: b int

variable_types: c int


prtAnswer

decompiled_code:
int __fastcall prtAnswer(__int64 a1)
{
unsigned int *v1; // r13
__int64 i; // rbp
int result; // eax
unsigned int *v4; // rbx
int v5; // er12

v1 = (unsigned int *)(unsigned int)((_DWORD)Case + 7200);
for ( i = 1LL; i != 4; ++i )
{
if ( NC[i] )
{
printf(format, *(_QWORD *)(a1 + 8 * i));
result = puts("(x, y, z) -> (a, b, c)");
if ( NC[i] > 0 )
{
v4 = v1;
v5 = 0;
do
{
result = printf("(%d, %d, %d) -> (%d, %d, %d)\n", *v4, v4[1], v4[2], v4[3], v4[4], v4[5]);
++v5;
v4 += 6;
}
while ( NC[i] > v5 );
}
}
else
{
result = printf(aS, *(_QWORD *)(a1 + 8 * i));
}
v1 += 1800;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
unsigned int *v1; // r13
__int64 i; // rbp
int result; // eax
unsigned int *v4; // rbx
int v5; // er12

v1 = (unsigned int *)(unsigned int)((_DWORD)Case + 7200);
for ( i = 1LL; i != 4; ++i )
{
if ( NC[i] )
{
printf(format, *(_QWORD *)(a1 + 8 * i));
result = puts("(x, y, z) -> (a, b, c)");
if ( NC[i] > 0 )
{
v4 = v1;
v5 = 0;
do
{
result = printf("(%d, %d, %d) -> (%d, %d, %d)\n", *v4, v4[1], v4[2], v4[3], v4[4], v4[5]);
++v5;
v4 += 6;
}
while ( NC[i] > v5 );
}
}
else
{
result = printf(aS, *(_QWORD *)(a1 + 8 * i));
}
v1 += 1800;
}
return result;
}

original_code:
void prtAnswer(char *str[])
{
  int i, j;
  for (i = 1; i < 4; i++) {
    if (NC[i] == 0) {
     printf("%s となる場合は存在しない．\n", str[i]);
    } else {
     printf("%s となるのは以下の%d通りである．\n", str[i], NC[i]);
     printf("(x, y, z) -> (a, b, c)\n");
     for (j = 0; j < NC[i]; j++) {
       printf("(%d, %d, %d) -> (%d, %d, %d)\n",
           Case[i][j].x, Case[i][j].y, Case[i][j].z,
           Case[i][j].a, Case[i][j].b, Case[i][j].c
       );
     }
    }
  }
}

canonical_original_code:
void prtAnswer(char *str[])
{
  int i; int j;
  for (i = 1; i < 4; i++) {
    if (NC[i] == 0) {
     printf("%s となる場合は存在しない．\n", str[i]);
    } else {
     printf("%s となるのは以下の%d通りである．\n", str[i], NC[i]);
     printf("(x, y, z) -> (a, b, c)\n");
     for (j = 0; j < NC[i]; j++) {
       printf("(%d, %d, %d) -> (%d, %d, %d)\n",
           Case[i][j].x, Case[i][j].y, Case[i][j].z,
           Case[i][j].a, Case[i][j].b, Case[i][j].c
       );
     }
    }
  }
}

variable_types:
str
char *[]

variable_types: i int

variable_types: j int


original_code:
void func1(int x, int y, int z)
{
  int a, b, c, nn;
  a = (x - y) * (y - z) * (z - x);
  b = x * y - y * z;
  c = (x - y + z) * (x + y - z);
  nn = func2(a, b, c);
  if (nn == 1 || nn == 2 || nn == 3) {
    Case[nn][NC[nn]].x = x;
    Case[nn][NC[nn]].y = y;
    Case[nn][NC[nn]].z = z;
    Case[nn][NC[nn]].a = a;
    Case[nn][NC[nn]].b = b;
    Case[nn][NC[nn]].c = c;
    NC[nn]++;
  }
}

canonical_original_code:
void func1(int x, int y, int z)
{
  int a; int b; int c; int nn;
  a = (x - y) * (y - z) * (z - x);
  b = x * y - y * z;
  c = (x - y + z) * (x + y - z);
  nn = func2(a, b, c);
  if (nn == 1 || nn == 2 || nn == 3) {
    Case[nn][NC[nn]].x = x;
    Case[nn][NC[nn]].y = y;
    Case[nn][NC[nn]].z = z;
    Case[nn][NC[nn]].a = a;
    Case[nn][NC[nn]].b = b;
    Case[nn][NC[nn]].c = c;
    NC[nn]++;
  }
}

variable_types: x int

variable_types: y int

variable_types: z int

variable_types: nn int


getTriangle

canonical_original_code:
void getTriangle(int n, struct Triangle t[])
{
  int i; int j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < 3; j++) {
      t[i].p[j].x = (double)(rand() % 201 - 100) / 10;
      t[i].p[j].y = (double)(rand() % 201 - 100) / 10;
    }
  }
}

variable_types: n int

variable_types: struct Triangle { struct Point { double x; } p[3]; double area; } []

user_defined_types: struct Triangle { struct Point p[3]; double area; }


calcArea

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: s double


prtTriangle

decompiled_code:
int __fastcall prtTriangle(int a1, __int64 a2)
{
int result; // eax
double *v3; // rbp
double *v4; // rbx

result = puts("( V1 ) ( V2 ) ( V3 ) Area");
if ( a1 > 0 )
{
v3 = (double *)(a2 + 48);
do
{
v4 = v3 - 6;
do
{
printf("(%5.1f, %5.1f) ", *v4, v4[1]);
v4 += 2;
}
while ( v3 != v4 );
result = printf("%5.1f\n", *v3);
v3 += 7;
}
while ( v3 != (double *)(a2 + 56LL * (unsigned int)(a1 - 1) + 104) );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, __int64 a2)
{
int result; // eax
double *v3; // rbp
double *v4; // rbx

result = puts("( V1 ) ( V2 ) ( V3 ) Area");
if ( a1 > 0 )
{
v3 = (double *)(a2 + 48);
do
{
v4 = v3 - 6;
do
{
printf("(%5.1f, %5.1f) ", *v4, v4[1]);
v4 += 2;
}
while ( v3 != v4 );
result = printf("%5.1f\n", *v3);
v3 += 7;
}
while ( v3 != (double *)(a2 + 56LL * (unsigned int)(a1 - 1) + 104) );
}
return result;
}

original_code:
void prtTriangle(int n, Triangle t[])
{
  int i, j;
  printf("(     V1     ) (     V2     ) (     V3     )  Area\n");
  for (i = 0; i < n; i++) {
    for (j = 0; j < 3; j++) {
      printf("(%5.1f, %5.1f) ", t[i].p[j].x, t[i].p[j].y);
    }
    printf("%5.1f\n", t[i].area);
  }
}

canonical_original_code:
void prtTriangle(int n, struct Triangle t[])
{
  int i; int j;
  printf("(     V1     ) (     V2     ) (     V3     )  Area\n");
  for (i = 0; i < n; i++) {
    for (j = 0; j < 3; j++) {
      printf("(%5.1f, %5.1f) ", t[i].p[j].x, t[i].p[j].y);
    }
    printf("%5.1f\n", t[i].area);
  }
}


sortTriangle

original_code:
void sortTriangle(int n, Triangle t[])
{
  int i;
  for (i = 0; i < n - 1; i++) {
    int j;
    for (j = i + 1; j < n; j++) {
      if (t[i].area < t[j].area) {
        Triangle tmp = t[i];
        t[i] = t[j];
        t[j] = tmp;
      }
    }
  }
}

canonical_original_code:
void sortTriangle(int n, struct Triangle t[])
{
  int i;
  for (i = 0; i < n - 1; i++) {
    int j;
    for (j = i + 1; j < n; j++) {
      if (t[i].area < t[j].area) {
        struct Triangle tmp = t[i];
        t[i] = t[j];
        t[j] = tmp;
      }
    }
  }
}

variable_types: struct Triangle { struct Point { double x; } p[3]; double area; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v4[701]; // [rsp+0h] [rbp-15F8h] BYREF
int v5; // [rsp+15E8h] [rbp-10h] BYREF
unsigned int seed[3]; // [rsp+15ECh] [rbp-Ch] BYREF

printf(&byte_46A, argv, envp);
_isoc99_scanf(&unk_479, seed);
srand(seed[0]);
printf(a3);
_isoc99_scanf(&unk_479, &v5);
getTriangle(v5, (__int64)v4);
calcArea(v5, v4);
sortTriangle(v5, v4);
prtTriangle(v5, (__int64)v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v4[701]; // [rsp+0h] [rbp-15F8h] BYREF
int v5; // [rsp+15E8h] [rbp-10h] BYREF
unsigned int seed[3]; // [rsp+15ECh] [rbp-Ch] BYREF

printf(&byte_46A, argv, envp);
_isoc99_scanf(&unk_479, seed);
srand(seed[0]);
printf(a3);
_isoc99_scanf(&unk_479, &v5);
func0(v5, (__int64)v4);
func1(v5, v4);
func3(v5, v4);
func2(v5, (__int64)v4);
return 0;
}

original_code:
int main(void)
{
  int seed, n;
  Triangle tri[100];
  printf("乱数 seed : ");
  scanf("%d", &seed);
  srand(seed);
  printf("3角形の個数 : ");
  scanf("%d", &n);
  getTriangle(n, tri);
  calcArea(n, tri);
  sortTriangle(n, tri);
  prtTriangle(n, tri);
  return 0;
}

canonical_original_code:
int main()
{
  int seed; int n;
  struct Triangle tri[100];
  printf("乱数 seed : ");
  scanf("%d", &seed);
  srand(seed);
  printf("3角形の個数 : ");
  scanf("%d", &n);
  getTriangle(n, tri);
  calcArea(n, tri);
  sortTriangle(n, tri);
  prtTriangle(n, tri);
  return 0;
}

variable_types: seed int

variable_types: struct Triangle { struct Point { double x; } p[3]; double area; } [100]


prtMoney

decompiled_code:
int __fastcall prtMoney(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

v1 = a1;
do
{
if ( *(int *)(v1 + 12) > 0 )
result = printf(format, *(_QWORD *)v1);
v1 += 16LL;
}
while ( v1 != a1 + 144 );
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

v1 = a1;
do
{
if ( *(int *)(v1 + 12) > 0 )
result = printf(format, *(_QWORD *)v1);
v1 += 16LL;
}
while ( v1 != a1 + 144 );
return result;
}

original_code:
void prtMoney(Money mon[])
{
  int i;
  for (i = 0; i < 9; i++) {
    if (mon[i].num > 0) {
      printf("%s = %d 枚\n", mon[i].name, mon[i].num);
    }
  }
}

canonical_original_code:
void prtMoney(struct Money mon[])
{
  int i;
  for (i = 0; i < 9; i++) {
    if (mon[i].num > 0) {
      printf("%s = %d 枚\n", mon[i].name, mon[i].num);
    }
  }
}

variable_types: struct Money { char *name; int value; int num; } []


original_code:
int func1(int kingaku, Money mon[])
{
  int i;
  int val = (int)(kingaku * 1.05);
  for (i = 0; i < 9; i++) {
    while (val - mon[i].value >= 0) {
      val -= mon[i].value;
      mon[i].num++;
    }
  }
  return (int)(kingaku * 1.05);
}

canonical_original_code:
int func1(int kingaku, struct Money mon[])
{
  int i;
  int val = (int)(kingaku * 1.05);
  for (i = 0; i < 9; i++) {
    while (val - mon[i].value >= 0) {
      val -= mon[i].value;
      mon[i].num++;
    }
  }
  return (int)(kingaku * 1.05);
}

variable_types: kingaku int

variable_types: val int

user_defined_types: struct Money { char *name; int value; int num; }