decompiled_code:
__int64 __fastcall dbg_map_lookup(__int64 a1, int a2, const char *a3)
{
__int64 v3; // rbx
void *v4; // rdi
__int64 v5; // r12
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v3 = (unsigned int)dbg_maps_lookup(a1, a2, a3, &ptr);
fprintf(stderr, "retcount: %i\n", v3);
if ( (_DWORD)v3 == 1 )
{
v4 = ptr;
v5 = *(_QWORD *)ptr;
LABEL_3:
free(v4);
return v5;
}
if ( (int)v3 > 0 )
{
v4 = ptr;
v5 = 0LL;
goto LABEL_3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, const char *a3)
{
__int64 v3; // rbx
void *v4; // rdi
__int64 v5; // r12
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v3 = (unsigned int)func1(a1, a2, a3, &ptr);
fprintf(stderr, "retcount: %i\n", v3);
if ( (_DWORD)v3 == 1 )
{
v4 = ptr;
v5 = *(_QWORD *)ptr;
LABEL_3:
free(v4);
return v5;
}
if ( (int)v3 > 0 )
{
v4 = ptr;
v5 = 0LL;
goto LABEL_3;
}
return 0LL;
}

original_code:
mapping_t *dbg_map_lookup(proc_t *p, int flags, const char *name)
{
 int ret;
 mapping_t **maps, *map;
 ret = dbg_maps_lookup(p, flags, name, &maps);
 fprintf(stderr, "retcount: %i\n", ret);
 map = (ret == 1 ? *maps : ((void *)0));
 if (ret > 0)
  free(maps);
 return map;
}

canonical_original_code:
struct _mapping *dbg_map_lookup(struct _proc *p, int flags, char *name)
{
 int ret;
 struct _mapping **maps; struct _mapping *map;
 ret = dbg_maps_lookup(p, flags, name, &maps);
 fprintf(stderr, "retcount: %i\n", ret);
 map = (ret == 1 ? *maps : ((void *)0));
 if (ret > 0)
  free(maps);
 return map;
}

variable_types:
p
struct _proc *

variable_types: ret int

variable_types: struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc { int pid; int flags; struct _mapping *maps; char pid_str[8]; } *proc; char *data; } *

user_defined_types: struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc *proc; char *data; }


repo: kholia/passe-partout

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

result = dbg_map_lookup(a1, 3, "[stack]");
if ( !result )
result = dbg_map_lookup(a1, 7, "[stack]");
return result;
}

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

result = func2(a1, 3, "[stack]");
if ( !result )
result = func2(a1, 7, "[stack]");
return result;
}

original_code:
mapping_t *dbg_map_get_stack(proc_t *p)
{
 mapping_t *map;
 map = dbg_map_lookup(p, 1|2, "[stack]");
 if (!map)
  map = dbg_map_lookup(p, 1|2|4, "[stack]");
 return map;
}

canonical_original_code:
struct _mapping *dbg_map_get_stack(struct _proc *p)
{
 struct _mapping *map;
 map = dbg_map_lookup(p, 1|2, "[stack]");
 if (!map)
  map = dbg_map_lookup(p, 1|2|4, "[stack]");
 return map;
}

return_type: struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc { int pid; int flags; struct _mapping *maps; char pid_str[8]; } *proc; char *data; } *


decompiled_code:
__int64 __fastcall dbg_init(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
int v4; // ebx
int v5; // edi
struct sigaction v6; // [rsp+0h] [rbp-B8h] BYREF

if ( ptraced_proc )
return (unsigned int)-7;
if ( !a2 || getpid() == a2 || getppid() == a2 )
return (unsigned int)-3;
*(_OWORD *)a1 = 0LL;
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 16) = 0LL;
snprintf((char *)(a1 + 16), 8uLL, "%u", a2);
ptraced_proc = a1;
v2 = parse_maps(a1);
if ( v2 )
{
ptraced_proc = 0LL;
}
else
{
v4 = 1;
memset(&v6.sa_mask, 0, 0x90uLL);
do
{
while ( 1 )
{
v6.sa_flags = 4;
v6.sa_handler = (__sighandler_t)killme;
if ( v4 != 9 && v4 != 19 )
break;
++v4;
}
v5 = v4++;
sigaction(v5, &v6, 0LL);
}
while ( v4 != 64 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
int v4; // ebx
int v5; // edi
struct sigaction v6; // [rsp+0h] [rbp-B8h] BYREF

if ( ptraced_proc )
return (unsigned int)-7;
if ( !a2 || getpid() == a2 || getppid() == a2 )
return (unsigned int)-3;
*(_OWORD *)a1 = 0LL;
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 16) = 0LL;
snprintf((char *)(a1 + 16), 8uLL, "%u", a2);
ptraced_proc = a1;
v2 = func0(a1);
if ( v2 )
{
ptraced_proc = 0LL;
}
else
{
v4 = 1;
memset(&v6.sa_mask, 0, 0x90uLL);
do
{
while ( 1 )
{
v6.sa_flags = 4;
v6.sa_handler = (__sighandler_t)killme;
if ( v4 != 9 && v4 != 19 )
break;
++v4;
}
v5 = v4++;
sigaction(v5, &v6, 0LL);
}
while ( v4 != 64 );
}
return v2;
}

original_code:
int dbg_init(proc_t *p, pid_t pid)
{
 int ret;
 unsigned int i;
 struct sigaction sa;
 if (ptraced_proc)
  return -7;
 if (!pid || (pid == getpid()) || (pid == getppid()))
  return -3;
 memset(p, 0, sizeof(*p));
 p->pid = pid;
 snprintf(p->pid_str, 8, "%u", pid);
 ptraced_proc = p;
 ret = parse_maps(p);
 if (ret) {
  ptraced_proc = ((void *)0);
  return ret;
 }
 memset(&sa, 0, sizeof(sa));
 for (i=1; i<(64 + 1)-1; ++i) {
  sa.sa_flags = 4;
  sa.__sigaction_handler.sa_sigaction = killme;
  switch (i) {
   case 9:
   case 19:
    break;
   default:
    sigaction(i, &sa, ((void *)0));
  }
 }
 return 0;
}

canonical_original_code:
int dbg_init(struct _proc *p, int pid)
{
 int ret;
 unsigned int i;
 struct sigaction sa;
 if (ptraced_proc)
  return -7;
 if (!pid || (pid == getpid()) || (pid == getppid()))
  return -3;
 memset(p, 0, sizeof(*p));
 p->pid = pid;
 snprintf(p->pid_str, 8, "%u", pid);
 ptraced_proc = p;
 ret = parse_maps(p);
 if (ret) {
  ptraced_proc = ((void *)0);
  return ret;
 }
 memset(&sa, 0, sizeof(sa));
 for (i=1; i<(64 + 1)-1; ++i) {
  sa.sa_flags = 4;
  sa.__sigaction_handler.sa_sigaction = killme;
  switch (i) {
   case 9:
   case 19:
    break;
   default:
    sigaction(i, &sa, ((void *)0));
  }
 }
 return 0;
}

variable_types: struct _proc { int pid; int flags; struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc *proc; char *data; } *maps; char pid_str[8]; } *

variable_types: pid int

variable_types:
i
unsigned int

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

return_type: int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct _proc { int pid; int flags; struct _mapping *maps; char pid_str[8]; }

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


decompiled_code:
void __fastcall dbg_exit(__int64 a1)
{
_QWORD *v2; // rbp
void *v3; // rdi
_QWORD *v4; // rbx

v2 = *(_QWORD **)(a1 + 8);
if ( v2 )
{
while ( 1 )
{
v3 = (void *)v2[5];
if ( v3 )
free(v3);
v4 = (_QWORD *)*v2;
free(v2);
if ( !v4 )
break;
v2 = v4;
}
}
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
}

original_code:
void dbg_exit(proc_t *p)
{
 mapping_t *tmp, *next;
 for (tmp=p->maps; tmp; tmp=next) {
  if (tmp->data)
   free(tmp->data);
  next = tmp->next;
  free(tmp);
 }
 memset(p, 0, sizeof(*p));
}

canonical_original_code:
void dbg_exit(struct _proc *p)
{
 struct _mapping *tmp; struct _mapping *next;
 for (tmp=p->maps; tmp; tmp=next) {
  if (tmp->data)
   free(tmp->data);
  next = tmp->next;
  free(tmp);
 }
 memset(p, 0, sizeof(*p));
}

return_type: void


decompiled_code:
int __fastcall dbg_detach(unsigned int *a1)
{
int result; // eax

if ( (a1[1] & 1) != 0 )
{
ptrace(PTRACE_DETACH, *a1, 0LL, 0LL);
result = dbg_verbose;
a1[1] &= 0xFFFFFFFE;
if ( result )
result = fprintf(stdout, "dbg: detached from process %u\n", *a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1)
{
int result; // eax

if ( (a1[1] & 1) != 0 )
{
ptrace(PTRACE_DETACH, *a1, 0LL, 0LL);
result = dbg_verbose;
a1[1] &= 0xFFFFFFFE;
if ( result )
result = fprintf(stdout, "dbg: detached from process %u\n", *a1);
}
return result;
}

original_code:
void dbg_detach(proc_t *p)
{
 if (p->flags & 1) {
  ptrace(PTRACE_DETACH, p->pid, 0, 0);
  p->flags &= ~1;
  if (dbg_verbose)
   fprintf(stdout, "dbg: detached from process %u\n", p->pid);
 }
}

canonical_original_code:
void dbg_detach(struct _proc *p)
{
 if (p->flags & 1) {
  ptrace(PTRACE_DETACH, p->pid, 0, 0);
  p->flags &= ~1;
  if (dbg_verbose)
   fprintf(stdout, "dbg: detached from process %u\n", p->pid);
 }
}


killme

decompiled_code:
int __fastcall killme(int a1, __int64 a2)
{
int result; // eax

if ( a1 != 17 )
{
dbg_detach((unsigned int *)ptraced_proc);
ptraced_proc = 0LL;
fwrite("killed\n", 1uLL, 7uLL, stderr);
exit(0);
}
result = dbg_verbose;
if ( dbg_verbose )
result = fprintf(stderr, "dbg: attached to process %u\n", *(unsigned int *)(a2 + 16));
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, __int64 a2)
{
int result; // eax

if ( a1 != 17 )
{
func6((unsigned int *)ptraced_proc);
ptraced_proc = 0LL;
fwrite("killed\n", 1uLL, 7uLL, stderr);
exit(0);
}
result = dbg_verbose;
if ( dbg_verbose )
result = fprintf(stderr, "dbg: attached to process %u\n", *(unsigned int *)(a2 + 16));
return result;
}

original_code:
static void killme(int sig, siginfo_t *si, void *bla)
{
 if (sig == 17) {
  if (dbg_verbose)
   fprintf(stderr, "dbg: attached to process %u\n", si->_sifields._kill.si_pid);
  return;
 }
 dbg_detach(ptraced_proc);
 ptraced_proc = ((void *)0);
 fprintf(stderr, "killed\n");
 exit(0);
}

canonical_original_code:
static void killme(int sig, struct siginfo_t *si, void *bla)
{
 if (sig == 17) {
  if (dbg_verbose)
   fprintf(stderr, "dbg: attached to process %u\n", si->_sifields._kill.si_pid);
  return;
 }
 dbg_detach(ptraced_proc);
 ptraced_proc = ((void *)0);
 fprintf(stderr, "killed\n");
 exit(0);
}

variable_types: sig int

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

variable_types:
bla
void *


decompiled_code:
__int64 __fastcall dbg_attach(unsigned int *a1)
{
unsigned int v1; // er12
__int64 v2; // rsi
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = a1[1] & 1;
if ( v1 )
return (unsigned int)-5;
v2 = *a1;
a1[1] |= 1u;
if ( !ptrace(PTRACE_ATTACH, v2, 0LL, 0LL) )
{
alarm(5u);
wait((__WAIT_STATUS)&stat_loc);
alarm(0);
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
v1 = -6;
dbg_detach(a1);
}
return v1;
}
a1[1] &= 0xFFFFFFFE;
v1 = -4;
if ( *_errno_location() == 1 )
return v1;
perror("ptrace");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
unsigned int v1; // er12
__int64 v2; // rsi
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = a1[1] & 1;
if ( v1 )
return (unsigned int)-5;
v2 = *a1;
a1[1] |= 1u;
if ( !ptrace(PTRACE_ATTACH, v2, 0LL, 0LL) )
{
alarm(5u);
wait((__WAIT_STATUS)&stat_loc);
alarm(0);
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
v1 = -6;
func6(a1);
}
return v1;
}
a1[1] &= 0xFFFFFFFE;
v1 = -4;
if ( *_errno_location() == 1 )
return v1;
perror("ptrace");
return 0xFFFFFFFFLL;
}

original_code:
int dbg_attach(proc_t *p, int mode)
{
 int status;
 if (p->flags & 1)
  return -5;
 p->flags |= 1;
 if (ptrace(PTRACE_ATTACH, p->pid, 0, 0)) {
  p->flags &= ~1;
  if ((*__errno_location ()) == 1)
   return -4;
  perror("ptrace");
  return -1;
 }
 alarm(5);
 wait(&status);
 alarm(0);
 if (!(((status) & 0xff) == 0x7f)) {
  dbg_detach(p);
  return -6;
 }
 return 0;
}

canonical_original_code:
int dbg_attach(struct _proc *p, int mode)
{
 int status;
 if (p->flags & 1)
  return -5;
 p->flags |= 1;
 if (ptrace(PTRACE_ATTACH, p->pid, 0, 0)) {
  p->flags &= ~1;
  if ((*__errno_location ()) == 1)
   return -4;
  perror("ptrace");
  return -1;
 }
 alarm(5);
 wait(&status);
 alarm(0);
 if (!(((status) & 0xff) == 0x7f)) {
  dbg_detach(p);
  return -6;
 }
 return 0;
}

variable_types: mode int

variable_types: status int


decompiled_code:
__int64 __fastcall dbg_get_regs(unsigned int *a1, __int64 a2)
{
return ptrace(PTRACE_GETREGS, *a1, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, __int64 a2)
{
return ptrace(PTRACE_GETREGS, *a1, 0LL, a2);
}

original_code:
int dbg_get_regs(proc_t *p, void *regs)
{
 return ptrace(PTRACE_GETREGS, p->pid, ((void *)0), regs);
}

canonical_original_code:
int dbg_get_regs(struct _proc *p, void *regs)
{
 return ptrace(PTRACE_GETREGS, p->pid, ((void *)0), regs);
}

variable_types:
regs
void *


decompiled_code:
__int64 __fastcall dbg_set_regs(unsigned int *a1, __int64 a2)
{
return ptrace(PTRACE_SETREGS, *a1, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, __int64 a2)
{
return ptrace(PTRACE_SETREGS, *a1, 0LL, a2);
}

original_code:
int dbg_set_regs(proc_t *p, const void *regs)
{
 return ptrace(PTRACE_SETREGS, p->pid, ((void *)0), regs);
}

canonical_original_code:
int dbg_set_regs(struct _proc *p, void *regs)
{
 return ptrace(PTRACE_SETREGS, p->pid, ((void *)0), regs);
}


decompiled_code:
__int64 __fastcall dbg_continue(unsigned int *a1)
{
return ptrace(PTRACE_CONT, *a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1)
{
return ptrace(PTRACE_CONT, *a1, 0LL, 0LL);
}

original_code:
int dbg_continue(proc_t *p)
{
 return ptrace(PTRACE_CONT, p->pid, ((void *)0), ((void *)0));
}

canonical_original_code:
int dbg_continue(struct _proc *p)
{
 return ptrace(PTRACE_CONT, p->pid, ((void *)0), ((void *)0));
}


decompiled_code:
char *__fastcall dbg_get_binpath(__int64 a1)
{
char *v1; // r12
size_t v2; // rbx
size_t v3; // rbp
char *v4; // r13
char *v5; // rax
ssize_t v6; // rax
char v8[104]; // [rsp+0h] [rbp-68h] BYREF

v1 = 0LL;
v2 = 0LL;
snprintf(v8, 0x3FuLL, "/proc/%s/exe", (const char *)(a1 + 16));
v8[63] = 0;
while ( 1 )
{
v3 = v2;
v2 += 256LL;
v4 = v1;
v5 = (char *)realloc(v1, v2);
v1 = v5;
if ( !v5 )
break;
v6 = readlink(v8, v5, v3 + 255);
if ( v6 > 0 )
{
v1[v6] = 0;
return v1;
}
if ( *_errno_location() != 36 )
return 0LL;
}
if ( v4 )
{
free(v4);
return v1;
}
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1)
{
char *v1; // r12
size_t v2; // rbx
size_t v3; // rbp
char *v4; // r13
char *v5; // rax
ssize_t v6; // rax
char v8[104]; // [rsp+0h] [rbp-68h] BYREF

v1 = 0LL;
v2 = 0LL;
snprintf(v8, 0x3FuLL, "/proc/%s/exe", (const char *)(a1 + 16));
v8[63] = 0;
while ( 1 )
{
v3 = v2;
v2 += 256LL;
v4 = v1;
v5 = (char *)realloc(v1, v2);
v1 = v5;
if ( !v5 )
break;
v6 = readlink(v8, v5, v3 + 255);
if ( v6 > 0 )
{
v1[v6] = 0;
return v1;
}
if ( *_errno_location() != 36 )
return 0LL;
}
if ( v4 )
{
free(v4);
return v1;
}
return 0LL;
}

original_code:
char *dbg_get_binpath(proc_t *p)
{
 ssize_t ret;
 size_t len;
 char *bak, *real_path, path[64];
 snprintf(path, 63, "/proc/%s/exe", p->pid_str);
 path[63] = 0;
 len = 0;
 real_path = ((void *)0);
 do {
  bak = real_path;
  real_path = realloc(real_path, len+256);
  if (!real_path) {
   if (bak)
    free(bak);
   return ((void *)0);
  }
  len += 256;
  ret = readlink(path, real_path, len-1);
  if (ret > 0) {
   real_path[ret] = 0;
   return real_path;
  }
 } while ((*__errno_location ()) == 36);
 return ((void *)0);
}

canonical_original_code:
char *dbg_get_binpath(struct _proc *p)
{
 long ret;
 unsigned long len;
 char *bak; char *real_path; char path[64];
 snprintf(path, 63, "/proc/%s/exe", p->pid_str);
 path[63] = 0;
 len = 0;
 real_path = ((void *)0);
 do {
  bak = real_path;
  real_path = realloc(real_path, len+256);
  if (!real_path) {
   if (bak)
    free(bak);
   return ((void *)0);
  }
  len += 256;
  ret = readlink(path, real_path, len-1);
  if (ret > 0) {
   real_path[ret] = 0;
   return real_path;
  }
 } while ((*__errno_location ()) == 36);
 return ((void *)0);
}

variable_types: ret long

variable_types:
len
unsigned long

variable_types:
bak
char *

variable_types:
path
char [64]

return_type: char *


decompiled_code:
__int64 __fastcall dbg_read(unsigned int *a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbx
int *v6; // rbp
__int64 v7; // rax

if ( !a4 )
return 0LL;
v5 = 0LL;
v6 = _errno_location();
while ( 1 )
{
*v6 = 0;
v7 = ptrace(PTRACE_PEEKDATA, *a1, (unsigned int)v5 + a2, 1LL);
if ( v7 == -1 )
{
if ( *v6 )
break;
}
*(_QWORD *)(a3 + v5) = v7;
v5 += 8LL;
if ( a4 <= (unsigned int)v5 )
return 0LL;
}
fprintf(stderr, "error: cannot fetch word @ 0x%lx\n", (unsigned int)v5 + a2);
if ( *v6 == 3 )
fwrite("ptrace: access denied or process has terminated\n", 1uLL, 0x30uLL, stderr);
else
perror("ptrace");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbx
int *v6; // rbp
__int64 v7; // rax

if ( !a4 )
return 0LL;
v5 = 0LL;
v6 = _errno_location();
while ( 1 )
{
*v6 = 0;
v7 = ptrace(PTRACE_PEEKDATA, *a1, (unsigned int)v5 + a2, 1LL);
if ( v7 == -1 )
{
if ( *v6 )
break;
}
*(_QWORD *)(a3 + v5) = v7;
v5 += 8LL;
if ( a4 <= (unsigned int)v5 )
return 0LL;
}
fprintf(stderr, "error: cannot fetch word @ 0x%lx\n", (unsigned int)v5 + a2);
if ( *v6 == 3 )
fwrite("ptrace: access denied or process has terminated\n", 1uLL, 0x30uLL, stderr);
else
perror("ptrace");
return 0xFFFFFFFFLL;
}

original_code:
int dbg_read(proc_t *p, xaddr_t addr, void *buf, unsigned int size)
{
  unsigned int i;
  long ret, *out;
  for (i=0, out=(long*)buf; i<size; i+=sizeof(long), ++out) {
    (*__errno_location ()) = 0;
    ret = ptrace(PTRACE_PEEKDATA, p->pid, addr+i, 1);
    if ((ret == -1) && (*__errno_location ())) {
      fprintf(stderr, "error: cannot fetch word @ 0x%lx\n", addr+i);
      if ((*__errno_location ()) == 3) {
        fprintf(stderr,
            "ptrace: access denied or process has terminated\n");
      } else {
        perror("ptrace");
      }
      return -1;
    }
    *out = ret;
  }
  return 0;
}

canonical_original_code:
int dbg_read(struct _proc *p, unsigned long addr, void *buf, unsigned int size)
{
  unsigned int i;
  long ret; long *out;
  for (i=0, out=(long *)buf; i<size; i+=sizeof(long), ++out) {
    (*__errno_location ()) = 0;
    ret = ptrace(PTRACE_PEEKDATA, p->pid, addr+i, 1);
    if ((ret == -1) && (*__errno_location ())) {
      fprintf(stderr, "error: cannot fetch word @ 0x%lx\n", addr+i);
      if ((*__errno_location ()) == 3) {
        fprintf(stderr,
            "ptrace: access denied or process has terminated\n");
      } else {
        perror("ptrace");
      }
      return -1;
    }
    *out = ret;
  }
  return 0;
}

variable_types:
addr
unsigned long

variable_types:
buf
void *

variable_types:
size
unsigned int

variable_types:
out
long *


decompiled_code:
__int64 __fastcall dbg_map_cache(__int64 a1)
{
unsigned int v1; // er12
size_t v3; // r12
void *v4; // rax
void *v5; // rbp
__int64 v6; // rdx

v1 = 1;
if ( *(_QWORD *)(a1 + 40) )
return v1;
v3 = *(unsigned int *)(a1 + 16);
v4 = malloc(v3);
v5 = v4;
if ( !v4 )
{
v6 = (unsigned int)v3;
v1 = -2;
fprintf(stderr, "error: failed to alloc %u bytes\n", v6);
return v1;
}
v1 = dbg_read(*(unsigned int **)(a1 + 32), *(_QWORD *)(a1 + 8), (__int64)v4, v3);
if ( v1 )
{
fprintf(stderr, "error: failed to read %u bytes\n", *(unsigned int *)(a1 + 16));
free(v5);
return v1;
}
*(_QWORD *)(a1 + 40) = v5;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
unsigned int v1; // er12
size_t v3; // r12
void *v4; // rax
void *v5; // rbp
__int64 v6; // rdx

v1 = 1;
if ( *(_QWORD *)(a1 + 40) )
return v1;
v3 = *(unsigned int *)(a1 + 16);
v4 = malloc(v3);
v5 = v4;
if ( !v4 )
{
v6 = (unsigned int)v3;
v1 = -2;
fprintf(stderr, "error: failed to alloc %u bytes\n", v6);
return v1;
}
v1 = func13(*(unsigned int **)(a1 + 32), *(_QWORD *)(a1 + 8), (__int64)v4, v3);
if ( v1 )
{
fprintf(stderr, "error: failed to read %u bytes\n", *(unsigned int *)(a1 + 16));
free(v5);
return v1;
}
*(_QWORD *)(a1 + 40) = v5;
return 0LL;
}

original_code:
int dbg_map_cache(mapping_t *map)
{
 void *buf;
 int ret;
 if (map->data)
  return 1;
 buf = malloc(map->size);
 if (!buf) {
  fprintf(stderr, "error: failed to alloc %u bytes\n", map->size);
  return -2;;
 }
 ret = dbg_read(map->proc, map->address, buf, map->size);
 if (!ret) {
  map->data = buf;
 } else {
  fprintf(stderr, "error: failed to read %u bytes\n", map->size);
  free(buf);
 }
 return ret;
}

canonical_original_code:
int dbg_map_cache(struct _mapping *map)
{
 void *buf;
 int ret;
 if (map->data)
  return 1;
 buf = malloc(map->size);
 if (!buf) {
  fprintf(stderr, "error: failed to alloc %u bytes\n", map->size);
  return -2;;
 }
 ret = dbg_read(map->proc, map->address, buf, map->size);
 if (!ret) {
  map->data = buf;
 } else {
  fprintf(stderr, "error: failed to read %u bytes\n", map->size);
  free(buf);
 }
 return ret;
}

variable_types: struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc { int pid; int flags; struct _mapping *maps; char pid_str[8]; } *proc; char *data; } *

variable_types: ret int


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

if ( (*(_BYTE *)(a1 + 4) & 1) != 0 )
result = dbg_read((unsigned int *)a1, a2, a3, 8u);
else
result = 4294967274LL;
return result;
}

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

if ( (*(_BYTE *)(a1 + 4) & 1) != 0 )
result = func13((unsigned int *)a1, a2, a3, 8u);
else
result = 4294967274LL;
return result;
}

original_code:
int dbg_read_ptr(proc_t *p, xaddr_t addr, xaddr_t *v)
{
 if (!(p->flags & 1))
  return -22;
 return dbg_read(p, addr, v, sizeof(*v));
}

canonical_original_code:
int dbg_read_ptr(struct _proc *p, unsigned long addr, unsigned long *v)
{
 if (!(p->flags & 1))
  return -22;
 return dbg_read(p, addr, v, sizeof(*v));
}

variable_types: struct _proc { int pid; int flags; struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc *proc; char *data; } *maps; char pid_str[8]; } *

variable_types:
v
unsigned long *


decompiled_code:
__int64 __fastcall dbg_get_memory(__int64 a1)
{
unsigned int v1; // er12
__int64 i; // rbx

v1 = 0;
for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)i )
{
while ( (*(_DWORD *)(i + 20) & 0xB) != 3 || !(unsigned int)dbg_map_cache(i) )
{
i = *(_QWORD *)i;
if ( !i )
return v1;
}
v1 = 1;
fprintf(stderr, "error reading %d bytes at %p\n", *(unsigned int *)(i + 16), *(const void **)(i + 8));
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
unsigned int v1; // er12
__int64 i; // rbx

v1 = 0;
for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)i )
{
while ( (*(_DWORD *)(i + 20) & 0xB) != 3 || !(unsigned int)func14(i) )
{
i = *(_QWORD *)i;
if ( !i )
return v1;
}
v1 = 1;
fprintf(stderr, "error reading %d bytes at %p\n", *(unsigned int *)(i + 16), *(const void **)(i + 8));
}
return v1;
}

original_code:
int dbg_get_memory(proc_t *p) {
    mapping_t * map;
    int error = 0;
    for (map=(p)->maps; map; map=map->next) {
        if (((map->flags & (1|2)) != (1|2))
  || (map->flags & 8))
            continue;
 if (dbg_map_cache(map)) {
            fprintf(stderr, "error reading %d bytes at %p\n", map->size, (void *)map->address);
     error = 1;
 }
    }
   return error;
}

canonical_original_code:
int dbg_get_memory(struct _proc *p) {
    struct _mapping *map;
    int error = 0;
    for (map=(p)->maps; map; map=map->next) {
        if (((map->flags & (1|2)) != (1|2))
  || (map->flags & 8))
            continue;
 if (dbg_map_cache(map)) {
            fprintf(stderr, "error reading %d bytes at %p\n", map->size, (void *)map->address);
     error = 1;
 }
    }
   return error;
}

variable_types: error int


repo: kichiki/WaoN

decompiled_code:
size_t print_pv_version()
{
fprintf(stderr, "WaoN-pv - yet-another phase vocoder, Version %s\n\n", "0.11");
fwrite("Copyright (C) 1998-2013 Kengo Ichiki <kengoichiki@gmail.com>\n", 1uLL, 0x3DuLL, stdout);
return fwrite("Web: http://kichiki.github.com/WaoN//\n\n", 1uLL, 0x27uLL, stdout);
}

canonical_decompiled_code:
size_t func0()
{
fprintf(stderr, "WaoN-pv - yet-another phase vocoder, Version %s\n\n", "0.11");
fwrite("Copyright (C) 1998-2013 Kengo Ichiki <kengoichiki@gmail.com>\n", 1uLL, 0x3DuLL, stdout);
return fwrite("Web: http://kichiki.github.com/WaoN//\n\n", 1uLL, 0x27uLL, stdout);
}

original_code:
void print_pv_version (void)
{
  fprintf (stderr, "WaoN-pv - yet-another phase vocoder, Version %s\n\n",
    "0.11");
  fprintf (stdout, "Copyright (C) 1998-2013 Kengo Ichiki "
    "<kengoichiki@gmail.com>\n");
  fprintf (stdout, "Web: http://kichiki.github.com/WaoN//\n\n");
}

canonical_original_code:
void print_pv_version()
{
  fprintf (stderr, "WaoN-pv - yet-another phase vocoder, Version %s\n\n",
    "0.11");
  fprintf (stdout, "Copyright (C) 1998-2013 Kengo Ichiki "
    "<kengoichiki@gmail.com>\n");
  fprintf (stdout, "Web: http://kichiki.github.com/WaoN//\n\n");
}


decompiled_code:
size_t __fastcall print_pv_usage(const char *a1)
{
print_pv_version();
fwrite(
"WaoN-pv is yet-another phase vocoder, with which you can do time-strech \nand pitch-shift a sound file.\n\n",
1uLL,
0x68uLL,
stdout);
fprintf(stdout, "Usage: %s [option ...]\n\n", a1);
fwrite("Options:\n", 1uLL, 9uLL, stdout);
fwrite(" -h, --help\tprint this help.\n", 1uLL, 0x1EuLL, stdout);
fwrite(" -v, --version\tprint version information.\n", 1uLL, 0x2BuLL, stdout);
fwrite("OPTIONS FOR FILES\n", 1uLL, 0x12uLL, stdout);
fwrite(" -i, --input\tinput file (default: stdin)\n", 1uLL, 0x2AuLL, stdout);
fwrite(" -o, --output\toutput file in flac (default: play audio by ao)\n", 1uLL, 0x3FuLL, stdout);
fwrite("FFT OPTIONS\n", 1uLL, 0xCuLL, stdout);
fwrite(" -n \tFFT data number (default: 2048)\n", 1uLL, 0x2EuLL, stdout);
fwrite(" -w --window\t0 no window\n", 1uLL, 0x1AuLL, stdout);
fwrite("\t\t1 parzen window\n", 1uLL, 0x12uLL, stdout);
fwrite("\t\t2 welch window\n", 1uLL, 0x11uLL, stdout);
fwrite("\t\t3 hanning window (default)\n", 1uLL, 0x1DuLL, stdout);
fwrite("\t\t4 hamming window\n", 1uLL, 0x13uLL, stdout);
fwrite("\t\t5 blackman window\n", 1uLL, 0x14uLL, stdout);
fwrite("\t\t6 steeper 30-dB/octave rolloff window\n", 1uLL, 0x28uLL, stdout);
fwrite("PHASE-VOCODER OPTIONS\n", 1uLL, 0x16uLL, stdout);
fwrite(" -hop \thop number (default: 512)\n", 1uLL, 0x28uLL, stdout);
fwrite(" -rate \tsynthesize rate; larger is faster (default: 1.0)\n", 1uLL, 0x3FuLL, stdout);
fwrite(" -pitch\tpitch shift. +1/-1 is half-note up/down (default: 0)\n", 1uLL, 0x3EuLL, stdout);
fwrite(" -scheme \tgive the number for PV scheme\n", 1uLL, 0x2CuLL, stdout);
fwrite("\t\t1 : conventional PV\n", 1uLL, 0x16uLL, stdout);
fwrite("\t\t2 : PV by complex arithmetics with fixed hops\n", 1uLL, 0x30uLL, stdout);
fwrite("\t\t3 : Puckette's loose-locking PV\n", 1uLL, 0x22uLL, stdout);
fwrite("\t\t4 : Puckette's loose-locking PV by complex with fixed hops\n", 1uLL, 0x3DuLL, stdout);
fwrite("\t\t5 : PV with fixed hops by Ellis\n", 1uLL, 0x22uLL, stdout);
fwrite("\t\t6 : PV in freq. domain\n", 1uLL, 0x19uLL, stdout);
fwrite("\t\t7 : plain superimpose (no-FFT)\n", 1uLL, 0x21uLL, stdout);
fwrite("\t\t0 : interactive PV with curses (default)\n", 1uLL, 0x2BuLL, stdout);
return fwrite(
"KEY BINDINGS IN CURSES MODE (with -scheme 0, the default)\n"
"\tSPACE : play / stop\n"
"\t< > : set loop range\n"
"\t[{ }] : expand the loop range\n"
"\tL l : phase-lock on / off\n"
"\tW w : change window\n"
"\tH h : hop-size up / down\n"
"\tUP / DOWN : pitch up / down\n"
"\tLEFT / RIGHT : pitch up / down\n"
"\tR r HOME : reset parameters\n"
"\tN n : toggle for no-FFT mode\n"
"\tQ q : quit\n",
1uLL,
0x19DuLL,
stdout);
}

canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
func0();
fwrite(
"WaoN-pv is yet-another phase vocoder, with which you can do time-strech \nand pitch-shift a sound file.\n\n",
1uLL,
0x68uLL,
stdout);
fprintf(stdout, "Usage: %s [option ...]\n\n", a1);
fwrite("Options:\n", 1uLL, 9uLL, stdout);
fwrite(" -h, --help\tprint this help.\n", 1uLL, 0x1EuLL, stdout);
fwrite(" -v, --version\tprint version information.\n", 1uLL, 0x2BuLL, stdout);
fwrite("OPTIONS FOR FILES\n", 1uLL, 0x12uLL, stdout);
fwrite(" -i, --input\tinput file (default: stdin)\n", 1uLL, 0x2AuLL, stdout);
fwrite(" -o, --output\toutput file in flac (default: play audio by ao)\n", 1uLL, 0x3FuLL, stdout);
fwrite("FFT OPTIONS\n", 1uLL, 0xCuLL, stdout);
fwrite(" -n \tFFT data number (default: 2048)\n", 1uLL, 0x2EuLL, stdout);
fwrite(" -w --window\t0 no window\n", 1uLL, 0x1AuLL, stdout);
fwrite("\t\t1 parzen window\n", 1uLL, 0x12uLL, stdout);
fwrite("\t\t2 welch window\n", 1uLL, 0x11uLL, stdout);
fwrite("\t\t3 hanning window (default)\n", 1uLL, 0x1DuLL, stdout);
fwrite("\t\t4 hamming window\n", 1uLL, 0x13uLL, stdout);
fwrite("\t\t5 blackman window\n", 1uLL, 0x14uLL, stdout);
fwrite("\t\t6 steeper 30-dB/octave rolloff window\n", 1uLL, 0x28uLL, stdout);
fwrite("PHASE-VOCODER OPTIONS\n", 1uLL, 0x16uLL, stdout);
fwrite(" -hop \thop number (default: 512)\n", 1uLL, 0x28uLL, stdout);
fwrite(" -rate \tsynthesize rate; larger is faster (default: 1.0)\n", 1uLL, 0x3FuLL, stdout);
fwrite(" -pitch\tpitch shift. +1/-1 is half-note up/down (default: 0)\n", 1uLL, 0x3EuLL, stdout);
fwrite(" -scheme \tgive the number for PV scheme\n", 1uLL, 0x2CuLL, stdout);
fwrite("\t\t1 : conventional PV\n", 1uLL, 0x16uLL, stdout);
fwrite("\t\t2 : PV by complex arithmetics with fixed hops\n", 1uLL, 0x30uLL, stdout);
fwrite("\t\t3 : Puckette's loose-locking PV\n", 1uLL, 0x22uLL, stdout);
fwrite("\t\t4 : Puckette's loose-locking PV by complex with fixed hops\n", 1uLL, 0x3DuLL, stdout);
fwrite("\t\t5 : PV with fixed hops by Ellis\n", 1uLL, 0x22uLL, stdout);
fwrite("\t\t6 : PV in freq. domain\n", 1uLL, 0x19uLL, stdout);
fwrite("\t\t7 : plain superimpose (no-FFT)\n", 1uLL, 0x21uLL, stdout);
fwrite("\t\t0 : interactive PV with curses (default)\n", 1uLL, 0x2BuLL, stdout);
return fwrite(
"KEY BINDINGS IN CURSES MODE (with -scheme 0, the default)\n"
"\tSPACE : play / stop\n"
"\t< > : set loop range\n"
"\t[{ }] : expand the loop range\n"
"\tL l : phase-lock on / off\n"
"\tW w : change window\n"
"\tH h : hop-size up / down\n"
"\tUP / DOWN : pitch up / down\n"
"\tLEFT / RIGHT : pitch up / down\n"
"\tR r HOME : reset parameters\n"
"\tN n : toggle for no-FFT mode\n"
"\tQ q : quit\n",
1uLL,
0x19DuLL,
stdout);
}

original_code:
void print_pv_usage (char * argv0)
{
  print_pv_version ();
  fprintf (stdout, "WaoN-pv is yet-another phase vocoder, "
    "with which you can do time-strech \n"
    "and pitch-shift a sound file.\n\n");
  fprintf (stdout, "Usage: %s [option ...]\n\n", argv0);
  fprintf (stdout, "Options:\n");
  fprintf (stdout, "  -h, --help\tprint this help.\n");
  fprintf (stdout, "  -v, --version\tprint version information.\n");
  fprintf (stdout, "OPTIONS FOR FILES\n");
  fprintf (stdout, "  -i, --input\tinput file (default: stdin)\n");
  fprintf (stdout, "  -o, --output\toutput file in flac"
    " (default: play audio by ao)\n");
  fprintf (stdout, "FFT OPTIONS\n");
  fprintf (stdout, "  -n         \tFFT data number (default: 2048)\n");
  fprintf (stdout, "  -w --window\t0 no window\n");
  fprintf (stdout, "\t\t1 parzen window\n");
  fprintf (stdout, "\t\t2 welch window\n");
  fprintf (stdout, "\t\t3 hanning window (default)\n");
  fprintf (stdout, "\t\t4 hamming window\n");
  fprintf (stdout, "\t\t5 blackman window\n");
  fprintf (stdout, "\t\t6 steeper 30-dB/octave rolloff window\n");
  fprintf (stdout, "PHASE-VOCODER OPTIONS\n");
  fprintf (stdout, "  -hop       \thop number (default: 512)\n");
  fprintf (stdout, "  -rate      \tsynthesize rate; larger is faster"
    " (default: 1.0)\n");
  fprintf (stdout, "  -pitch\tpitch shift. +1/-1 is half-note up/down"
    " (default: 0)\n");
  fprintf (stdout, "  -scheme    \tgive the number for PV scheme\n");
  fprintf (stdout, "\t\t1 : conventional PV\n");
  fprintf (stdout, "\t\t2 : PV by complex arithmetics with fixed hops\n");
  fprintf (stdout, "\t\t3 : Puckette's loose-locking PV\n");
  fprintf (stdout, "\t\t4 : Puckette's loose-locking PV by complex"
    " with fixed hops\n");
  fprintf (stdout, "\t\t5 : PV with fixed hops by Ellis\n");
  fprintf (stdout, "\t\t6 : PV in freq. domain\n");
  fprintf (stdout, "\t\t7 : plain superimpose (no-FFT)\n");
  fprintf (stdout, "\t\t0 : interactive PV with curses (default)\n");
  fprintf (stdout, "KEY BINDINGS IN CURSES MODE (with -scheme 0, the default)\n"
    "\tSPACE        : play / stop\n"
    "\t< >          : set loop range\n"
    "\t[{ }]        : expand the loop range\n"
    "\tL l          : phase-lock on / off\n"
    "\tW w          : change window\n"
    "\tH h          : hop-size up / down\n"
    "\tUP / DOWN    : pitch up / down\n"
    "\tLEFT / RIGHT : pitch up / down\n"
    "\tR r HOME     : reset parameters\n"
    "\tN n          : toggle for no-FFT mode\n"
    "\tQ q          : quit\n");
}

canonical_original_code:
void print_pv_usage(char *argv0)
{
  print_pv_version ();
  fprintf (stdout, "WaoN-pv is yet-another phase vocoder, "
    "with which you can do time-strech \n"
    "and pitch-shift a sound file.\n\n");
  fprintf (stdout, "Usage: %s [option ...]\n\n", argv0);
  fprintf (stdout, "Options:\n");
  fprintf (stdout, "  -h, --help\tprint this help.\n");
  fprintf (stdout, "  -v, --version\tprint version information.\n");
  fprintf (stdout, "OPTIONS FOR FILES\n");
  fprintf (stdout, "  -i, --input\tinput file (default: stdin)\n");
  fprintf (stdout, "  -o, --output\toutput file in flac"
    " (default: play audio by ao)\n");
  fprintf (stdout, "FFT OPTIONS\n");
  fprintf (stdout, "  -n         \tFFT data number (default: 2048)\n");
  fprintf (stdout, "  -w --window\t0 no window\n");
  fprintf (stdout, "\t\t1 parzen window\n");
  fprintf (stdout, "\t\t2 welch window\n");
  fprintf (stdout, "\t\t3 hanning window (default)\n");
  fprintf (stdout, "\t\t4 hamming window\n");
  fprintf (stdout, "\t\t5 blackman window\n");
  fprintf (stdout, "\t\t6 steeper 30-dB/octave rolloff window\n");
  fprintf (stdout, "PHASE-VOCODER OPTIONS\n");
  fprintf (stdout, "  -hop       \thop number (default: 512)\n");
  fprintf (stdout, "  -rate      \tsynthesize rate; larger is faster"
    " (default: 1.0)\n");
  fprintf (stdout, "  -pitch\tpitch shift. +1/-1 is half-note up/down"
    " (default: 0)\n");
  fprintf (stdout, "  -scheme    \tgive the number for PV scheme\n");
  fprintf (stdout, "\t\t1 : conventional PV\n");
  fprintf (stdout, "\t\t2 : PV by complex arithmetics with fixed hops\n");
  fprintf (stdout, "\t\t3 : Puckette's loose-locking PV\n");
  fprintf (stdout, "\t\t4 : Puckette's loose-locking PV by complex"
    " with fixed hops\n");
  fprintf (stdout, "\t\t5 : PV with fixed hops by Ellis\n");
  fprintf (stdout, "\t\t6 : PV in freq. domain\n");
  fprintf (stdout, "\t\t7 : plain superimpose (no-FFT)\n");
  fprintf (stdout, "\t\t0 : interactive PV with curses (default)\n");
  fprintf (stdout, "KEY BINDINGS IN CURSES MODE (with -scheme 0, the default)\n"
    "\tSPACE        : play / stop\n"
    "\t< >          : set loop range\n"
    "\t[{ }]        : expand the loop range\n"
    "\tL l          : phase-lock on / off\n"
    "\tW w          : change window\n"
    "\tH h          : hop-size up / down\n"
    "\tUP / DOWN    : pitch up / down\n"
    "\tLEFT / RIGHT : pitch up / down\n"
    "\tR r HOME     : reset parameters\n"
    "\tN n          : toggle for no-FFT mode\n"
    "\tQ q          : quit\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
void *v4; // r12
const char **v5; // r15
const char *v6; // r14
int v7; // eax
size_t v8; // r14
void *v9; // rax
size_t v10; // r14
__int64 v12; // r9
const char *src; // [rsp+10h] [rbp-78h]
const char *srca; // [rsp+10h] [rbp-78h]
void *dest; // [rsp+20h] [rbp-68h]
__int64 v16; // [rsp+28h] [rbp-60h]
__int64 v17; // [rsp+30h] [rbp-58h]
double v18; // [rsp+38h] [rbp-50h]
double v19; // [rsp+40h] [rbp-48h]
int v20; // [rsp+48h] [rbp-40h]
unsigned int v21; // [rsp+4Ch] [rbp-3Ch]

if ( argc <= 1 )
goto LABEL_57;
v21 = 3;
v3 = 2;
v20 = 0;
v19 = 0.0;
v17 = 512LL;
v16 = 2048LL;
dest = 0LL;
v4 = 0LL;
v5 = argv + 1;
v18 = *(double *)&LC36;
while ( 1 )
{
v6 = *v5;
if ( !strcmp(*v5, "--input") || (v7 = *(unsigned __int8 *)v6, v7 == 45) && v6[1] == 105 && !v6[2] )
{
if ( v3 >= argc )
goto LABEL_8;
src = argv[v3];
v8 = strlen(src) + 1;
v9 = malloc(v8);
v4 = v9;
if ( !v9 )
{
fwrite("main : malloc error for file_in\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
memcpy(v9, src, v8);
goto LABEL_17;
}
if ( !strcmp(*v5, "--output") )
{
LABEL_20:
if ( v3 >= argc )
goto LABEL_8;
srca = argv[v3];
v10 = strlen(srca) + 1;
dest = malloc(v10);
if ( !dest )
{
fwrite("main : malloc error for file_out\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
memcpy(dest, srca, v10);
goto LABEL_17;
}
if ( v7 == 45 )
{
if ( v6[1] == 111 && !v6[2] )
goto LABEL_20;
if ( v6[1] == 110 && !v6[2] )
{
if ( v3 >= argc )
goto LABEL_8;
v16 = atoi(argv[v3]);
goto LABEL_17;
}
}
if ( !strcmp(*v5, "-hop") )
{
if ( v3 >= argc )
goto LABEL_8;
v17 = atoi(argv[v3]);
goto LABEL_17;
}
if ( !strcmp(*v5, "-rate") )
{
if ( v3 >= argc )
goto LABEL_8;
v18 = atof(argv[v3]);
goto LABEL_17;
}
if ( !strcmp(v6, "-pitch") )
{
if ( v3 >= argc )
goto LABEL_8;
v19 = atof(argv[v3]);
goto LABEL_17;
}
if ( strcmp(v6, "-scheme") )
break;
if ( v3 >= argc )
goto LABEL_8;
v20 = atoi(argv[v3]);
LABEL_17:
v5 += 2;
v3 += 2;
if ( v3 == ((argc - 2) & 0xFFFFFFFE) + 4 )
goto LABEL_8;
}
if ( strcmp(v6, "--window") && strcmp(v6, "-w") )
{
if ( !strcmp(v6, "--version") || !strcmp(v6, "-v") )
{
print_pv_version();
exit(1);
}
LABEL_57:
print_pv_usage(*argv);
exit(1);
}
if ( v3 < argc )
{
v21 = atoi(argv[v3]);
goto LABEL_17;
}
LABEL_8:
if ( !v4 )
goto LABEL_57;
switch ( v20 )
{
case 0:
pv_complex_curses(v4, v16, v17);
break;
case 1:
pv_conventional(v4, dest, v16, v17, v21, v18, v19);
break;
case 2:
v12 = 0LL;
goto LABEL_42;
case 3:
pv_loose_lock(v4, dest, v16, v17, v21, v18, v19);
break;
case 4:
v12 = 1LL;
LABEL_42:
pv_complex(v4, dest, v16, v17, v21, v12, v18, v19);
break;
case 5:
pv_ellis(v4, dest, v16, v17, v21, v18, v19);
break;
case 6:
if ( v19 == 0.0 )
pv_freq(v4, dest, v16, v17, v21, v18);
else
fwrite("pitch-shifting is not implemented yet\n", 1uLL, 0x26uLL, stderr);
break;
case 7:
pv_nofft(v4, dest, v16, v17, v21, v18, v19);
break;
default:
fwrite("invalid scheme number\n", 1uLL, 0x16uLL, stderr);
break;
}
free(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
void *v4; // r12
const char **v5; // r15
const char *v6; // r14
int v7; // eax
size_t v8; // r14
void *v9; // rax
size_t v10; // r14
__int64 v12; // r9
const char *src; // [rsp+10h] [rbp-78h]
const char *srca; // [rsp+10h] [rbp-78h]
void *dest; // [rsp+20h] [rbp-68h]
__int64 v16; // [rsp+28h] [rbp-60h]
__int64 v17; // [rsp+30h] [rbp-58h]
double v18; // [rsp+38h] [rbp-50h]
double v19; // [rsp+40h] [rbp-48h]
int v20; // [rsp+48h] [rbp-40h]
unsigned int v21; // [rsp+4Ch] [rbp-3Ch]

if ( argc <= 1 )
goto LABEL_57;
v21 = 3;
v3 = 2;
v20 = 0;
v19 = 0.0;
v17 = 512LL;
v16 = 2048LL;
dest = 0LL;
v4 = 0LL;
v5 = argv + 1;
v18 = *(double *)&LC36;
while ( 1 )
{
v6 = *v5;
if ( !strcmp(*v5, "--input") || (v7 = *(unsigned __int8 *)v6, v7 == 45) && v6[1] == 105 && !v6[2] )
{
if ( v3 >= argc )
goto LABEL_8;
src = argv[v3];
v8 = strlen(src) + 1;
v9 = malloc(v8);
v4 = v9;
if ( !v9 )
{
fwrite("main : malloc error for file_in\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
memcpy(v9, src, v8);
goto LABEL_17;
}
if ( !strcmp(*v5, "--output") )
{
LABEL_20:
if ( v3 >= argc )
goto LABEL_8;
srca = argv[v3];
v10 = strlen(srca) + 1;
dest = malloc(v10);
if ( !dest )
{
fwrite("main : malloc error for file_out\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
memcpy(dest, srca, v10);
goto LABEL_17;
}
if ( v7 == 45 )
{
if ( v6[1] == 111 && !v6[2] )
goto LABEL_20;
if ( v6[1] == 110 && !v6[2] )
{
if ( v3 >= argc )
goto LABEL_8;
v16 = atoi(argv[v3]);
goto LABEL_17;
}
}
if ( !strcmp(*v5, "-hop") )
{
if ( v3 >= argc )
goto LABEL_8;
v17 = atoi(argv[v3]);
goto LABEL_17;
}
if ( !strcmp(*v5, "-rate") )
{
if ( v3 >= argc )
goto LABEL_8;
v18 = atof(argv[v3]);
goto LABEL_17;
}
if ( !strcmp(v6, "-pitch") )
{
if ( v3 >= argc )
goto LABEL_8;
v19 = atof(argv[v3]);
goto LABEL_17;
}
if ( strcmp(v6, "-scheme") )
break;
if ( v3 >= argc )
goto LABEL_8;
v20 = atoi(argv[v3]);
LABEL_17:
v5 += 2;
v3 += 2;
if ( v3 == ((argc - 2) & 0xFFFFFFFE) + 4 )
goto LABEL_8;
}
if ( strcmp(v6, "--window") && strcmp(v6, "-w") )
{
if ( !strcmp(v6, "--version") || !strcmp(v6, "-v") )
{
func0();
exit(1);
}
LABEL_57:
func1(*argv);
exit(1);
}
if ( v3 < argc )
{
v21 = atoi(argv[v3]);
goto LABEL_17;
}
LABEL_8:
if ( !v4 )
goto LABEL_57;
switch ( v20 )
{
case 0:
pv_complex_curses(v4, v16, v17);
break;
case 1:
pv_conventional(v4, dest, v16, v17, v21, v18, v19);
break;
case 2:
v12 = 0LL;
goto LABEL_42;
case 3:
pv_loose_lock(v4, dest, v16, v17, v21, v18, v19);
break;
case 4:
v12 = 1LL;
LABEL_42:
pv_complex(v4, dest, v16, v17, v21, v12, v18, v19);
break;
case 5:
pv_ellis(v4, dest, v16, v17, v21, v18, v19);
break;
case 6:
if ( v19 == 0.0 )
pv_freq(v4, dest, v16, v17, v21, v18);
else
fwrite("pitch-shifting is not implemented yet\n", 1uLL, 0x26uLL, stderr);
break;
case 7:
pv_nofft(v4, dest, v16, v17, v21, v18, v19);
break;
default:
fwrite("invalid scheme number\n", 1uLL, 0x16uLL, stderr);
break;
}
free(v4);
return 0;
}

original_code:
int main (int argc, char** argv)
{
  char *file_in = ((void *)0);
  char *file_out = ((void *)0);
  long len = 2048;
  long hop = 512;
  double rate = 1.0;
  double pitch_shift = 0.0;
  int scheme = 0;
  int flag_window = 3;
  int i;
  for (i = 1; i < argc; i++)
    {
      if ((strcmp (argv[i], "--input" ) == 0)
  || (strcmp (argv[i], "-i" ) == 0))
 {
   if (i+1 < argc)
     {
       file_in = (char *)malloc (sizeof (char)
     * (strlen (argv [++i]) + 1));
       if (file_in == ((void *)0)) { fprintf (stderr, "main" " : malloc error for " "file_in" "\n"); exit (1); };
       strcpy (file_in, argv[i]);
     }
 }
      else if ((strcmp (argv[i], "--output" ) == 0)
  || (strcmp (argv[i], "-o" ) == 0))
 {
   if (i+1 < argc)
     {
       file_out = (char *)malloc (sizeof (char)
      * (strlen (argv [++i]) + 1));
       if (file_out == ((void *)0)) { fprintf (stderr, "main" " : malloc error for " "file_out" "\n"); exit (1); };
       strcpy (file_out, argv[i]);
     }
 }
      else if (strcmp (argv[i], "-n" ) == 0)
 {
   if (i+1 < argc)
     {
       len = (long)atoi (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-hop" ) == 0)
 {
   if (i+1 < argc)
     {
       hop = (long)atoi (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-rate" ) == 0)
 {
   if (i+1 < argc)
     {
       rate = atof (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-pitch" ) == 0)
 {
   if (i+1 < argc)
     {
       pitch_shift = atof (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-scheme" ) == 0)
 {
   if (i+1 < argc)
     {
       scheme = atoi (argv [++i]);
     }
 }
      else if ((strcmp (argv[i], "--window") == 0)
        || (strcmp (argv[i], "-w") == 0))
 {
   if ( i+1 < argc )
     {
       flag_window = atoi (argv[++i]);
     }
 }
      else if ((strcmp (argv[i], "--version") == 0)
        || (strcmp (argv[i], "-v") == 0))
 {
   print_pv_version ();
   exit (1);
 }
      else
 {
   print_pv_usage (argv [0]);
   exit (1);
 }
    }
  if (file_in == ((void *)0))
    {
      print_pv_usage (argv [0]);
      exit (1);
    }
  switch (scheme)
    {
    case 0:
      pv_complex_curses (file_in, len, hop);
      break;
    case 1:
      pv_conventional (file_in, file_out, rate, pitch_shift,
         len, hop, flag_window);
      break;
    case 2:
      pv_complex (file_in, file_out, rate, pitch_shift,
    len, hop, flag_window,
    0
    );
      break;
    case 3:
      pv_loose_lock (file_in, file_out, rate, pitch_shift,
       len, hop, flag_window);
      break;
    case 4:
      pv_complex (file_in, file_out, rate, pitch_shift,
    len, hop, flag_window,
    1
    );
      break;
    case 5:
      pv_ellis (file_in, file_out, rate, pitch_shift,
  len, hop, flag_window);
      break;
    case 6:
      if (pitch_shift != 0.0)
 {
   fprintf (stderr, "pitch-shifting is not implemented yet\n");
   break;
 }
      pv_freq (file_in, file_out, rate, len, hop, flag_window);
      break;
    case 7:
      pv_nofft (file_in, file_out, rate, pitch_shift,
  len, hop, flag_window);
      break;
    default:
      fprintf (stderr, "invalid scheme number\n");
      break;
    }
  free (file_in);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  char *file_in = ((void *)0);
  char *file_out = ((void *)0);
  long len = 2048;
  long hop = 512;
  double rate = 1.0;
  double pitch_shift = 0.0;
  int scheme = 0;
  int flag_window = 3;
  int i;
  for (i = 1; i < argc; i++)
    {
      if ((strcmp (argv[i], "--input" ) == 0)
  || (strcmp (argv[i], "-i" ) == 0))
 {
   if (i+1 < argc)
     {
       file_in = (char *)malloc (sizeof (char)
     * (strlen (argv [++i]) + 1));
       if (file_in == ((void *)0)) { fprintf (stderr, "main" " : malloc error for " "file_in" "\n"); exit (1); };
       strcpy (file_in, argv[i]);
     }
 }
      else if ((strcmp (argv[i], "--output" ) == 0)
  || (strcmp (argv[i], "-o" ) == 0))
 {
   if (i+1 < argc)
     {
       file_out = (char *)malloc (sizeof (char)
      * (strlen (argv [++i]) + 1));
       if (file_out == ((void *)0)) { fprintf (stderr, "main" " : malloc error for " "file_out" "\n"); exit (1); };
       strcpy (file_out, argv[i]);
     }
 }
      else if (strcmp (argv[i], "-n" ) == 0)
 {
   if (i+1 < argc)
     {
       len = (long)atoi (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-hop" ) == 0)
 {
   if (i+1 < argc)
     {
       hop = (long)atoi (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-rate" ) == 0)
 {
   if (i+1 < argc)
     {
       rate = atof (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-pitch" ) == 0)
 {
   if (i+1 < argc)
     {
       pitch_shift = atof (argv [++i]);
     }
 }
      else if (strcmp (argv[i], "-scheme" ) == 0)
 {
   if (i+1 < argc)
     {
       scheme = atoi (argv [++i]);
     }
 }
      else if ((strcmp (argv[i], "--window") == 0)
        || (strcmp (argv[i], "-w") == 0))
 {
   if ( i+1 < argc )
     {
       flag_window = atoi (argv[++i]);
     }
 }
      else if ((strcmp (argv[i], "--version") == 0)
        || (strcmp (argv[i], "-v") == 0))
 {
   print_pv_version ();
   exit (1);
 }
      else
 {
   print_pv_usage (argv [0]);
   exit (1);
 }
    }
  if (file_in == ((void *)0))
    {
      print_pv_usage (argv [0]);
      exit (1);
    }
  switch (scheme)
    {
    case 0:
      pv_complex_curses (file_in, len, hop);
      break;
    case 1:
      pv_conventional (file_in, file_out, rate, pitch_shift,
         len, hop, flag_window);
      break;
    case 2:
      pv_complex (file_in, file_out, rate, pitch_shift,
    len, hop, flag_window,
    0
    );
      break;
    case 3:
      pv_loose_lock (file_in, file_out, rate, pitch_shift,
       len, hop, flag_window);
      break;
    case 4:
      pv_complex (file_in, file_out, rate, pitch_shift,
    len, hop, flag_window,
    1
    );
      break;
    case 5:
      pv_ellis (file_in, file_out, rate, pitch_shift,
  len, hop, flag_window);
      break;
    case 6:
      if (pitch_shift != 0.0)
 {
   fprintf (stderr, "pitch-shifting is not implemented yet\n");
   break;
 }
      pv_freq (file_in, file_out, rate, len, hop, flag_window);
      break;
    case 7:
      pv_nofft (file_in, file_out, rate, pitch_shift,
  len, hop, flag_window);
      break;
    default:
      fprintf (stderr, "invalid scheme number\n");
      break;
    }
  free (file_in);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: len long

variable_types: hop long

variable_types: rate double

variable_types: scheme int

variable_types: i int


decompiled_code:
void on_preference()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void
on_preference (void)
{
}

canonical_original_code:
static void on_preference()
{
}


decompiled_code:
int __fastcall print_ao_info(const char **a1, const char *a2)
{
fprintf(stdout, "%s type : %d\n", a2, *(unsigned int *)a1);
fprintf(stdout, "%s name : %s\n", a2, a1[1]);
fprintf(stdout, "%s short name : %s\n", a2, a1[2]);
return fprintf(stdout, "%s driver comment : %s\n", a2, a1[4]);
}

canonical_decompiled_code:
int __fastcall func0(const char **a1, const char *a2)
{
fprintf(stdout, "%s type : %d\n", a2, *(unsigned int *)a1);
fprintf(stdout, "%s name : %s\n", a2, a1[1]);
fprintf(stdout, "%s short name : %s\n", a2, a1[2]);
return fprintf(stdout, "%s driver comment : %s\n", a2, a1[4]);
}

original_code:
static void
print_ao_info (const ao_info *info,
        const char *label)
{
  fprintf (stdout, "%s type : %d\n", label, info->type);
  fprintf (stdout, "%s name : %s\n", label, info->name);
  fprintf (stdout, "%s short name : %s\n", label, info->short_name);
  fprintf (stdout, "%s driver comment : %s\n", label, info->comment);
}

canonical_original_code:
static void print_ao_info(struct ao_info *info, char *label)
{
  fprintf (stdout, "%s type : %d\n", label, info->type);
  fprintf (stdout, "%s name : %s\n", label, info->name);
  fprintf (stdout, "%s short name : %s\n", label, info->short_name);
  fprintf (stdout, "%s driver comment : %s\n", label, info->comment);
}

variable_types: struct ao_info { int type; char *name; char *short_name; char *author; char *comment; int preferred_byte_format; int priority; char **options; int option_count; } *

variable_types:
label
char *


decompiled_code:
int print_ao_driver_info_list()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // rbx
const char **v3; // rdi
int v5; // [rsp+Ch] [rbp-6Ch] BYREF
char s[104]; // [rsp+10h] [rbp-68h] BYREF

v0 = ao_driver_info_list(&v5);
if ( v5 > 0 )
{
v1 = v0;
v2 = 0LL;
do
{
sprintf(s, "%d : ", (unsigned int)v2);
v3 = *(const char ***)(v1 + 8 * v2++);
LODWORD(v0) = print_ao_info(v3, s);
}
while ( v5 > (int)v2 );
}
return v0;
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // rbx
const char **v3; // rdi
int v5; // [rsp+Ch] [rbp-6Ch] BYREF
char s[104]; // [rsp+10h] [rbp-68h] BYREF

v0 = ao_driver_info_list(&v5);
if ( v5 > 0 )
{
v1 = v0;
v2 = 0LL;
do
{
sprintf(s, "%d : ", (unsigned int)v2);
v3 = *(const char ***)(v1 + 8 * v2++);
LODWORD(v0) = func0(v3, s);
}
while ( v5 > (int)v2 );
}
return v0;
}

original_code:
void
print_ao_driver_info_list (void)
{
  int driver_count;
  ao_info** info_list;
  info_list = ao_driver_info_list (&driver_count);
  int i;
  char label [80];
  for (i = 0; i < driver_count; i ++)
    {
      sprintf (label, "%d : ", i);
      print_ao_info (info_list [i], label);
    }
}

canonical_original_code:
void print_ao_driver_info_list()
{
  int driver_count;
  struct ao_info **info_list;
  info_list = ao_driver_info_list (&driver_count);
  int i;
  char label[80];
  for (i = 0; i < driver_count; i ++)
    {
      sprintf (label, "%d : ", i);
      print_ao_info (info_list [i], label);
    }
}

variable_types: struct ao_info { int type; char *name; char *short_name; char *author; char *comment; int preferred_byte_format; int priority; char **options; int option_count; } **

variable_types:
label
char [80]


original_code:
double
midi_to_freq (int midi)
{
  double f;
  f = exp (log (440.0) + (double)(midi - 69) * log (2.0) / 12.0);
  return (f);
}

canonical_original_code:
double midi_to_freq(int midi)
{
  double f;
  f = exp (log (440.0) + (double)(midi - 69) * log (2.0) / 12.0);
  return (f);
}

variable_types: midi int

variable_types: f double

return_type: double


decompiled_code:
__int64 __fastcall freq_to_midi(double a1)
{
return (unsigned int)(int)(log(a1 / 440.0) * 17.31234049066756 + 69.5);
}

original_code:
int
freq_to_midi (double f)
{
  int midi;
  midi = (int)(0.5 + 69.0 + 12.0 / log (2.0) * log (f / 440.0));
  return (midi);
}

canonical_original_code:
int freq_to_midi(double f)
{
  int midi;
  midi = (int)(0.5 + 69.0 + 12.0 / log (2.0) * log (f / 440.0));
  return (midi);
}


original_code:
double
midi_to_logf (int midi)
{
  double logf;
  logf = log (440.0) + (double)(midi - 69) * log (2.0) / 12.0;
  return (logf);
}

canonical_original_code:
double midi_to_logf(int midi)
{
  double logf;
  logf = log (440.0) + (double)(midi - 69) * log (2.0) / 12.0;
  return (logf);
}

variable_types: logf double


original_code:
int
logf_to_midi (double logf)
{
  int midi;
  midi = (int)(0.5 + 69.0 + 12.0 / log (2.0) * (logf - log (440.0)));
  return (midi);
}

canonical_original_code:
int logf_to_midi(double logf)
{
  int midi;
  midi = (int)(0.5 + 69.0 + 12.0 / log (2.0) * (logf - log (440.0)));
  return (midi);
}


decompiled_code:
__int64 __fastcall get_note(double a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
__int64 result; // rax

v1 = log(a1 / 440.0);
++n_pitch;
v2 = v1 * 17.31234049066756 + 69.5 + *(double *)&adj_pitch;
result = (unsigned int)(int)v2;
*(double *)&pitch_shift = v2 - (double)(int)result + *(double *)&pitch_shift;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(double a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
__int64 result; // rax

v1 = log(a1 / 440.0);
++n_pitch;
v2 = v1 * 17.31234049066756 + 69.5 + *(double *)&adj_pitch;
result = (unsigned int)(int)v2;
*(double *)&pitch_shift = v2 - (double)(int)result + *(double *)&pitch_shift;
return result;
}

original_code:
int
get_note (double freq)
{
  extern double adj_pitch;
  extern double pitch_shift;
  extern int n_pitch;
  const double factor = 1.731234049066756242e+01;
  double dnote;
  int inote;
  dnote = 69.5 + factor * log(freq/440.0) + adj_pitch;
  inote = (int)dnote;
  pitch_shift += (dnote - (double)inote);
  n_pitch ++;
  return inote;
}

canonical_original_code:
int get_note(double freq)
{
  extern double adj_pitch;
  extern double pitch_shift;
  extern int n_pitch;
  double factor = 1.731234049066756242e+01;
  double dnote;
  int inote;
  dnote = 69.5 + factor * log(freq/440.0) + adj_pitch;
  inote = (int)dnote;
  pitch_shift += (dnote - (double)inote);
  n_pitch ++;
  return inote;
}

variable_types: freq double

variable_types: factor double

variable_types: dnote double

variable_types: inote int


decompiled_code:
ssize_t __fastcall smf_prog_change(int a1, char a2, char a3)
{
char buf[11]; // [rsp+Dh] [rbp-Bh] BYREF

buf[1] = a2 - 64;
buf[2] = a3;
buf[0] = 0;
return write(a1, buf, 3uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, char a2, char a3)
{
char buf[11]; // [rsp+Dh] [rbp-Bh] BYREF

buf[1] = a2 - 64;
buf[2] = a3;
buf[0] = 0;
return write(a1, buf, 3uLL);
}

original_code:
int
smf_prog_change (int fd, char channel, char prog)
{
  unsigned char data[3];
  data[0] = 0x00;
  data[1] = 0xC0 + channel;
  data[2] = prog;
  return write (fd, data, 3);
}

canonical_original_code:
int smf_prog_change(int fd, char channel, char prog)
{
  unsigned char data[3];
  data[0] = 0x00;
  data[1] = 0xC0 + channel;
  data[2] = prog;
  return write (fd, data, 3);
}

variable_types: fd int

variable_types: channel char

variable_types: prog char

variable_types:
data
unsigned char [3]


decompiled_code:
ssize_t __fastcall smf_tempo(int a1, int a2)
{
int buf; // [rsp+9h] [rbp-Fh] BYREF
char v4; // [rsp+Dh] [rbp-Bh]
__int16 v5; // [rsp+Eh] [rbp-Ah]

v5 = __ROL2__(a2, 8);
buf = 55705344;
v4 = BYTE2(a2);
return write(a1, &buf, 7uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func6(int a1, int a2)
{
int buf; // [rsp+9h] [rbp-Fh] BYREF
char v4; // [rsp+Dh] [rbp-Bh]
__int16 v5; // [rsp+Eh] [rbp-Ah]

v5 = __ROL2__(a2, 8);
buf = 55705344;
v4 = BYTE2(a2);
return write(a1, &buf, 7uLL);
}

original_code:
int
smf_tempo (int fd, unsigned long tempo)
{
  unsigned char data[7];
  data[0] = 0x00;
  data[1] = 0xff;
  data[2] = 0x51;
  data[3] = 0x03;
  data[4] = (char) (tempo >> 16) & 0xff;
  data[5] = (char) (tempo >> 8) & 0xff;
  data[6] = (char) (tempo ) & 0xff;
  return write (fd, data, 7);
}

canonical_original_code:
int smf_tempo(int fd, unsigned long tempo)
{
  unsigned char data[7];
  data[0] = 0x00;
  data[1] = 0xff;
  data[2] = 0x51;
  data[3] = 0x03;
  data[4] = (char) (tempo >> 16) & 0xff;
  data[5] = (char) (tempo >> 8) & 0xff;
  data[6] = (char) (tempo ) & 0xff;
  return write (fd, data, 7);
}

variable_types:
tempo
unsigned long

variable_types:
data
unsigned char [7]


decompiled_code:
ssize_t __fastcall smf_track_end(int a1)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = 3145472;
return write(a1, buf, 4uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func7(int a1)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = 3145472;
return write(a1, buf, 4uLL);
}

original_code:
int
smf_track_end (int fd)
{
  unsigned char data[4];
  data[0] = 0x00;
  data[1] = 0xff;
  data[2] = 0x2f;
  data[3] = 0x00;
  return write (fd, data, 4);
}

canonical_original_code:
int smf_track_end(int fd)
{
  unsigned char data[4];
  data[0] = 0x00;
  data[1] = 0xff;
  data[2] = 0x2f;
  data[3] = 0x00;
  return write (fd, data, 4);
}

variable_types:
data
unsigned char [4]


decompiled_code:
ssize_t __fastcall write_var_len(int a1, __int64 a2)
{
char v2; // al
__int64 v3; // rsi
char *v4; // rax
signed int v5; // edx
char v7[3]; // [rsp+Ch] [rbp-Ch] BYREF
char v8[9]; // [rsp+Fh] [rbp-9h] BYREF

v2 = a2;
v3 = a2 >> 7;
v8[0] = v2 & 0x7F;
if ( v3 <= 0 )
return write(a1, v8, 1uLL);
v4 = v7;
do
{
v4[2] = v3 | 0x80;
v5 = (unsigned int)v7 + 2 - (_DWORD)v4--;
v3 >>= 7;
}
while ( v3 );
return write(a1, &v7[4 - v5], v5);
}

canonical_decompiled_code:
ssize_t __fastcall func8(int a1, __int64 a2)
{
char v2; // al
__int64 v3; // rsi
char *v4; // rax
signed int v5; // edx
char v7[3]; // [rsp+Ch] [rbp-Ch] BYREF
char v8[9]; // [rsp+Fh] [rbp-9h] BYREF

v2 = a2;
v3 = a2 >> 7;
v8[0] = v2 & 0x7F;
if ( v3 <= 0 )
return write(a1, v8, 1uLL);
v4 = v7;
do
{
v4[2] = v3 | 0x80;
v5 = (unsigned int)v7 + 2 - (_DWORD)v4--;
v3 >>= 7;
}
while ( v3 );
return write(a1, &v7[4 - v5], v5);
}

original_code:
int
write_var_len (int fd, long value)
{
  unsigned char rep[4];
  int bytes;
  bytes = 1;
  rep[3] = value & 0x7f;
  value >>= 7;
  while (value >0)
    {
      rep[3 - bytes] = (value & 0x7f) | 0x80;
      bytes ++;
      value >>= 7;
    }
  return (write (fd, &rep[4-bytes], bytes));
}

canonical_original_code:
int write_var_len(int fd, long value)
{
  unsigned char rep[4];
  int bytes;
  bytes = 1;
  rep[3] = value & 0x7f;
  value >>= 7;
  while (value >0)
    {
      rep[3 - bytes] = (value & 0x7f) | 0x80;
      bytes ++;
      value >>= 7;
    }
  return (write (fd, &rep[4-bytes], bytes));
}

variable_types: value long

variable_types:
rep
unsigned char [4]

variable_types: bytes int


decompiled_code:
__int64 __fastcall smf_note_on(int fd, __int64 a2, char a3, char a4, char a5)
{
int v7; // ebx
char buf[43]; // [rsp+1h] [rbp-2Bh] BYREF

buf[0] = a5 - 112;
v7 = write_var_len(fd, a2);
buf[1] = a3;
buf[2] = a4;
return v7 + (unsigned int)write(fd, buf, 3uLL);
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, __int64 a2, char a3, char a4, char a5)
{
int v7; // ebx
char buf[43]; // [rsp+1h] [rbp-2Bh] BYREF

buf[0] = a5 - 112;
v7 = func8(fd, a2);
buf[1] = a3;
buf[2] = a4;
return v7 + (unsigned int)write(fd, buf, 3uLL);
}

original_code:
int
smf_note_on (int fd, long dtime, char note, char vel, char channel)
{
  unsigned char data[3];
  int num;
  num = write_var_len (fd, dtime);
  data[0] = 0x90 + channel;
  data[1] = note;
  data[2] = vel;
  num += write (fd, data, 3);
  return num;
}

canonical_original_code:
int smf_note_on(int fd, long dtime, char note, char vel, char channel)
{
  unsigned char data[3];
  int num;
  num = write_var_len (fd, dtime);
  data[0] = 0x90 + channel;
  data[1] = note;
  data[2] = vel;
  num += write (fd, data, 3);
  return num;
}

variable_types: dtime long

variable_types: note char

variable_types: vel char

variable_types: num int


decompiled_code:
__int64 __fastcall smf_note_off(int fd, __int64 a2, char a3, char a4, char a5)
{
int v7; // ebx
char buf[43]; // [rsp+1h] [rbp-2Bh] BYREF

buf[0] = a5 + 0x80;
v7 = write_var_len(fd, a2);
buf[1] = a3;
buf[2] = a4;
return v7 + (unsigned int)write(fd, buf, 3uLL);
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, __int64 a2, char a3, char a4, char a5)
{
int v7; // ebx
char buf[43]; // [rsp+1h] [rbp-2Bh] BYREF

buf[0] = a5 + 0x80;
v7 = func8(fd, a2);
buf[1] = a3;
buf[2] = a4;
return v7 + (unsigned int)write(fd, buf, 3uLL);
}

original_code:
int
smf_note_off (int fd, long dtime, char note, char vel, char channel)
{
  unsigned char data[3];
  int num;
  num = write_var_len (fd, dtime);
  data[0] = 0x80 + channel;
  data[1] = note;
  data[2] = vel;
  num += write (fd, data, 3);
  return num;
}

canonical_original_code:
int smf_note_off(int fd, long dtime, char note, char vel, char channel)
{
  unsigned char data[3];
  int num;
  num = write_var_len (fd, dtime);
  data[0] = 0x80 + channel;
  data[1] = note;
  data[2] = vel;
  num += write (fd, data, 3);
  return num;
}


decompiled_code:
__int64 __fastcall read_var_len(int fd, _QWORD *a2)
{
__int64 v2; // rax
unsigned int v3; // er12
int v4; // eax
char v5; // dl
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = 0LL;
v3 = 0;
do
{
*a2 = v2 << 7;
v4 = read(fd, buf, 1uLL);
v5 = buf[0];
v3 += v4;
v2 = *a2 + (buf[0] & 0x7F);
*a2 = v2;
}
while ( v5 < 0 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, _QWORD *a2)
{
__int64 v2; // rax
unsigned int v3; // er12
int v4; // eax
char v5; // dl
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = 0LL;
v3 = 0;
do
{
*a2 = v2 << 7;
v4 = read(fd, buf, 1uLL);
v5 = buf[0];
v3 += v4;
v2 = *a2 + (buf[0] & 0x7F);
*a2 = v2;
}
while ( v5 < 0 );
return v3;
}

original_code:
int
read_var_len (int fd, long *value)
{
  unsigned char c;
  int bytes;
  *value = 0;
  bytes = 0;
  do
    {
      (*value) <<= 7;
      bytes += read (fd, &c, 1);
      (*value) += (c & 0x7f);
    }
  while ( (c & 0x80) == 0x80 );
  return bytes;
}

canonical_original_code:
int read_var_len(int fd, long *value)
{
  unsigned char c;
  int bytes;
  *value = 0;
  bytes = 0;
  do
    {
      (*value) <<= 7;
      bytes += read (fd, &c, 1);
      (*value) += (c & 0x7f);
    }
  while ( (c & 0x80) == 0x80 );
  return bytes;
}

variable_types:
value
long *

variable_types:
c
unsigned char


wblong

decompiled_code:
ssize_t __fastcall wblong(int a1, unsigned int a2)
{
unsigned __int32 buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = _byteswap_ulong(a2);
return write(a1, buf, 4uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func12(int a1, unsigned int a2)
{
unsigned __int32 buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = _byteswap_ulong(a2);
return write(a1, buf, 4uLL);
}

original_code:
int
wblong (int fd, unsigned long ul)
{
  unsigned char data[4];
  data[0] = (char) (ul >> 24) & 0xff;
  data[1] = (char) (ul >> 16) & 0xff;
  data[2] = (char) (ul >> 8) & 0xff;
  data[3] = (char) (ul) & 0xff;
  return write (fd, data, 4);
}

canonical_original_code:
int wblong(int fd, unsigned long ul)
{
  unsigned char data[4];
  data[0] = (char) (ul >> 24) & 0xff;
  data[1] = (char) (ul >> 16) & 0xff;
  data[2] = (char) (ul >> 8) & 0xff;
  data[3] = (char) (ul) & 0xff;
  return write (fd, data, 4);
}

variable_types:
ul
unsigned long


decompiled_code:
__int64 __fastcall smf_track_head(int a1, unsigned int a2)
{
int v2; // ebx

v2 = write(a1, "MTrk", 4uLL);
return v2 + (unsigned int)wblong(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, unsigned int a2)
{
int v2; // ebx

v2 = write(a1, "MTrk", 4uLL);
return v2 + (unsigned int)func12(a1, a2);
}

original_code:
int
smf_track_head (int fd, unsigned long size)
{
  int num;
  num = write (fd, "MTrk", 4);
  num += wblong (fd, size);
  return num;
}

canonical_original_code:
int smf_track_head(int fd, unsigned long size)
{
  int num;
  num = write (fd, "MTrk", 4);
  num += wblong (fd, size);
  return num;
}

variable_types: fd int

variable_types:
size
unsigned long


wbshort

decompiled_code:
ssize_t __fastcall wbshort(int a1, __int16 a2)
{
__int16 buf[5]; // [rsp+Eh] [rbp-Ah] BYREF

buf[0] = __ROL2__(a2, 8);
return write(a1, buf, 2uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func14(int a1, __int16 a2)
{
__int16 buf[5]; // [rsp+Eh] [rbp-Ah] BYREF

buf[0] = __ROL2__(a2, 8);
return write(a1, buf, 2uLL);
}

original_code:
int
wbshort (int fd, unsigned short us)
{
  unsigned char data[2];
  data[0] = (char) (us >> 8) & 0xff;
  data[1] = (char) (us) & 0xff;
  return write (fd, data, 2);
}

canonical_original_code:
int wbshort(int fd, unsigned short us)
{
  unsigned char data[2];
  data[0] = (char) (us >> 8) & 0xff;
  data[1] = (char) (us) & 0xff;
  return write (fd, data, 2);
}

variable_types:
us
unsigned short

variable_types:
data
unsigned char [2]


decompiled_code:
__int64 __fastcall smf_header_fmt(int a1, __int16 a2, __int16 a3, __int16 a4)
{
int v6; // ebx
int v7; // ebx
int v8; // ebx
int v9; // ebx

v6 = write(a1, "MThd", 4uLL);
v7 = wblong(a1, 6u) + v6;
v8 = wbshort(a1, a2) + v7;
v9 = wbshort(a1, a3) + v8;
return v9 + (unsigned int)wbshort(a1, a4);
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, __int16 a2, __int16 a3, __int16 a4)
{
int v6; // ebx
int v7; // ebx
int v8; // ebx
int v9; // ebx

v6 = write(a1, "MThd", 4uLL);
v7 = func12(a1, 6u) + v6;
v8 = func14(a1, a2) + v7;
v9 = func14(a1, a3) + v8;
return v9 + (unsigned int)func14(a1, a4);
}

original_code:
int
smf_header_fmt (int fd,
  unsigned short format,
  unsigned short tracks,
  unsigned short divisions)
{
  int num;
  num = write (fd, "MThd", 4);
  num += wblong (fd, 6);
  num += wbshort (fd, format);
  num += wbshort (fd, tracks);
  num += wbshort (fd, divisions);
  return num;
}

canonical_original_code:
int smf_header_fmt(int fd, unsigned short format, unsigned short tracks, unsigned short divisions)
{
  int num;
  num = write (fd, "MThd", 4);
  num += wblong (fd, 6);
  num += wbshort (fd, format);
  num += wbshort (fd, tracks);
  num += wbshort (fd, divisions);
  return num;
}

variable_types:
format
unsigned short

variable_types:
tracks
unsigned short

variable_types:
divisions
unsigned short


decompiled_code:
int __fastcall WAON_notes_output_midi(unsigned int *a1, const char *a2, double a3)
{
size_t v5; // rax
unsigned __int64 v6; // rcx
int v7; // ebp
__int64 v8; // rdx
const char *v9; // rsi
__int64 v11; // r12
unsigned int v12; // er13
unsigned int v13; // er15
int i; // er14
__int64 v15; // r10
__int64 v16; // r8
char v17; // dl
int v18; // eax
__off_t v19; // rax
int v20; // eax
int v21; // [rsp+0h] [rbp-44h]
unsigned int v22; // [rsp+4h] [rbp-40h]
int v23; // [rsp+8h] [rbp-3Ch]

fprintf(stderr, "WAON_notes : n = %d\n", *a1);
fprintf(stderr, "filename : %s\n", a2);
v5 = strlen(a2);
v6 = 2LL;
if ( v5 <= 2 )
v6 = v5;
if ( !memcmp(a2, "-", v6) )
{
v21 = 1;
v7 = dup(1);
}
else
{
v21 = 0;
v7 = open(a2, 578, 384LL);
}
if ( v7 < 0 )
{
fprintf(stderr, "cannot open %s\n", a2);
exit(1);
}
if ( (unsigned int)smf_header_fmt(v7, 0, 1, (int)a3) != 14 )
return fprintf(stderr, "Error during writing mid! %d (header)\n", 0LL);
v22 = 4 * *a1 + 7;
if ( (unsigned int)smf_track_head(v7, v22) != 8 )
{
v8 = 14LL;
v9 = "Error during writing mid! %d (track header)\n";
return fprintf(stderr, v9, v8);
}
if ( (unsigned int)smf_tempo(v7, 500000) != 7 )
return fprintf(stderr, "Error during writing mid! %d (tempo)\n", 22LL);
if ( (unsigned int)smf_prog_change(v7, 0, 0) != 3 )
return fprintf(stderr, "Error during writing mid! %d (prog change)\n", 29LL);
if ( (int)*a1 <= 0 )
{
v12 = 32;
}
else
{
v11 = 0LL;
v12 = 32;
v13 = 0;
for ( i = **((_DWORD **)a1 + 1); ; i = *(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * v11) )
{
v17 = *(_BYTE *)(*((_QWORD *)a1 + 3) + v11);
if ( *(_BYTE *)(*((_QWORD *)a1 + 2) + v11) == 1 )
v15 = (unsigned int)smf_note_on(v7, (int)v13, v17, *(_BYTE *)(*((_QWORD *)a1 + 4) + v11), 0);
else
v15 = (unsigned int)smf_note_off(v7, (int)v13, v17, 64, 0);
if ( (int)v15 <= 3 )
{
v16 = (unsigned int)*(char *)(*((_QWORD *)a1 + 3) + v11);
v23 = v15;
if ( *(_BYTE *)(*((_QWORD *)a1 + 2) + v11) == 1 )
fprintf(
stderr,
"Error during writing mid! %d (note-on)\n idt = %d, note = %d, vel = %d, n_midi = %d\n",
v12,
v13,
v16,
(unsigned int)*(char *)(*((_QWORD *)a1 + 4) + v11),
v15);
else
fprintf(
stderr,
"Error during writing mid! %d (note-off)\n idt = %d, note = %d, vel = %d, n_midi = %d\n",
v12,
v13,
v16,
64LL,
v15);
LODWORD(v15) = v23;
}
v12 += v15;
if ( (int)*a1 <= (int)++v11 )
break;
v13 = *(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * v11) - i;
}
}
v18 = smf_track_end(v7);
v8 = v12;
v9 = "Error during writing mid! %d (track end)\n";
if ( v18 != 4 )
return fprintf(stderr, v9, v8);
if ( v21 )
{
if ( v22 != v12 - 18 )
fwrite(
"WaoN warning : data size seems to differ from the header prediction, and stdout isn't seekable to correct the he"
"ader. Midi players may not tolerate this.\n",
1uLL,
0x9AuLL,
stderr);
}
else
{
v19 = lseek(v7, 14LL, 0);
v8 = 14LL;
v9 = "Error during lseek %d (re-calc)\n";
if ( v19 < 0 )
return fprintf(stderr, v9, v8);
v20 = smf_track_head(v7, v12 - 18);
v8 = v12 + 4;
v9 = "Error during write %d (re-calc)\n";
if ( v20 != 8 )
return fprintf(stderr, v9, v8);
}
return close(v7);
}

canonical_decompiled_code:
int __fastcall func16(unsigned int *a1, const char *a2, double a3)
{
size_t v5; // rax
unsigned __int64 v6; // rcx
int v7; // ebp
__int64 v8; // rdx
const char *v9; // rsi
__int64 v11; // r12
unsigned int v12; // er13
unsigned int v13; // er15
int i; // er14
__int64 v15; // r10
__int64 v16; // r8
char v17; // dl
int v18; // eax
__off_t v19; // rax
int v20; // eax
int v21; // [rsp+0h] [rbp-44h]
unsigned int v22; // [rsp+4h] [rbp-40h]
int v23; // [rsp+8h] [rbp-3Ch]

fprintf(stderr, "WAON_notes : n = %d\n", *a1);
fprintf(stderr, "filename : %s\n", a2);
v5 = strlen(a2);
v6 = 2LL;
if ( v5 <= 2 )
v6 = v5;
if ( !memcmp(a2, "-", v6) )
{
v21 = 1;
v7 = dup(1);
}
else
{
v21 = 0;
v7 = open(a2, 578, 384LL);
}
if ( v7 < 0 )
{
fprintf(stderr, "cannot open %s\n", a2);
exit(1);
}
if ( (unsigned int)func15(v7, 0, 1, (int)a3) != 14 )
return fprintf(stderr, "Error during writing mid! %d (header)\n", 0LL);
v22 = 4 * *a1 + 7;
if ( (unsigned int)func13(v7, v22) != 8 )
{
v8 = 14LL;
v9 = "Error during writing mid! %d (track header)\n";
return fprintf(stderr, v9, v8);
}
if ( (unsigned int)func6(v7, 500000) != 7 )
return fprintf(stderr, "Error during writing mid! %d (tempo)\n", 22LL);
if ( (unsigned int)func5(v7, 0, 0) != 3 )
return fprintf(stderr, "Error during writing mid! %d (prog change)\n", 29LL);
if ( (int)*a1 <= 0 )
{
v12 = 32;
}
else
{
v11 = 0LL;
v12 = 32;
v13 = 0;
for ( i = **((_DWORD **)a1 + 1); ; i = *(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * v11) )
{
v17 = *(_BYTE *)(*((_QWORD *)a1 + 3) + v11);
if ( *(_BYTE *)(*((_QWORD *)a1 + 2) + v11) == 1 )
v15 = (unsigned int)func9(v7, (int)v13, v17, *(_BYTE *)(*((_QWORD *)a1 + 4) + v11), 0);
else
v15 = (unsigned int)func10(v7, (int)v13, v17, 64, 0);
if ( (int)v15 <= 3 )
{
v16 = (unsigned int)*(char *)(*((_QWORD *)a1 + 3) + v11);
v23 = v15;
if ( *(_BYTE *)(*((_QWORD *)a1 + 2) + v11) == 1 )
fprintf(
stderr,
"Error during writing mid! %d (note-on)\n idt = %d, note = %d, vel = %d, n_midi = %d\n",
v12,
v13,
v16,
(unsigned int)*(char *)(*((_QWORD *)a1 + 4) + v11),
v15);
else
fprintf(
stderr,
"Error during writing mid! %d (note-off)\n idt = %d, note = %d, vel = %d, n_midi = %d\n",
v12,
v13,
v16,
64LL,
v15);
LODWORD(v15) = v23;
}
v12 += v15;
if ( (int)*a1 <= (int)++v11 )
break;
v13 = *(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * v11) - i;
}
}
v18 = func7(v7);
v8 = v12;
v9 = "Error during writing mid! %d (track end)\n";
if ( v18 != 4 )
return fprintf(stderr, v9, v8);
if ( v21 )
{
if ( v22 != v12 - 18 )
fwrite(
"WaoN warning : data size seems to differ from the header prediction, and stdout isn't seekable to correct the he"
"ader. Midi players may not tolerate this.\n",
1uLL,
0x9AuLL,
stderr);
}
else
{
v19 = lseek(v7, 14LL, 0);
v8 = 14LL;
v9 = "Error during lseek %d (re-calc)\n";
if ( v19 < 0 )
return fprintf(stderr, v9, v8);
v20 = func13(v7, v12 - 18);
v8 = v12 + 4;
v9 = "Error during write %d (re-calc)\n";
if ( v20 != 8 )
return fprintf(stderr, v9, v8);
}
return close(v7);
}

original_code:
void
WAON_notes_output_midi (struct WAON_notes *notes,
   double div, char *filename)
{
  fprintf (stderr, "WAON_notes : n = %d\n", notes->n);
  fprintf (stderr, "filename : %s\n", filename);
  int fd;
  int flag_stdout;
  if (strncmp (filename, "-", strlen (filename)) == 0)
    {
      fd = dup(1);
      flag_stdout = 1;
    }
  else
    {
      fd = open (filename, 02| 0100| 01000, 0400| 0200);
      flag_stdout = 0;
    }
  if (fd < 0)
    {
      fprintf (stderr, "cannot open %s\n", filename);
      exit (1);
    }
  int p_midi;
  int n_midi;
  p_midi = 0;
  n_midi = smf_header_fmt (fd, 0, 1, div);
  if (n_midi != 14)
    {
      fprintf (stderr, "Error during writing mid! %d (header)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int h_midi;
  h_midi = p_midi;
  int nmidi = notes->n;
  n_midi = smf_track_head (fd, (7+4*nmidi));
  if (n_midi != 8)
    {
      fprintf (stderr, "Error during writing mid! %d (track header)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int dh_midi;
  dh_midi = p_midi;
  n_midi = smf_tempo (fd, 500000);
  if (n_midi != 7)
    {
      fprintf (stderr, "Error during writing mid! %d (tempo)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  n_midi = smf_prog_change (fd, 0, 0);
  if (n_midi != 3)
    {
      fprintf (stderr, "Error during writing mid! %d (prog change)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int idt;
  int last_step = 0;
  int i;
  for (i = 0; i < notes->n; i ++)
    {
      if (i==0) idt = 0;
      else idt = notes->step[i] - last_step;
      last_step = notes->step[i];
      if (notes->event[i] == 1)
 {
   n_midi = smf_note_on (fd, idt,
    notes->note[i],
    notes->vel[i],
    0);
 }
      else
 {
   n_midi = smf_note_off (fd, idt,
     notes->note[i],
     64,
     0);
 }
      if (n_midi < 4)
 {
   if (notes->event[i] == 1)
     {
       fprintf (stderr, "Error during writing mid! %d (note-on)\n"
         " idt = %d, note = %d, vel = %d, n_midi = %d\n",
         p_midi,
         idt, notes->note[i], notes->vel[i], n_midi);
     }
   else
     {
       fprintf (stderr, "Error during writing mid! %d (note-off)\n"
         " idt = %d, note = %d, vel = %d, n_midi = %d\n",
         p_midi,
         idt, notes->note[i], 64, n_midi);
     }
 }
      p_midi += n_midi;
    }
  n_midi = smf_track_end (fd);
  if (n_midi != 4)
    {
      fprintf (stderr, "Error during writing mid! %d (track end)\n",
        p_midi);
      return;
    }
  p_midi += n_midi;
  if (flag_stdout == 0)
    {
      if (lseek (fd, h_midi, 0) < 0)
 {
   fprintf (stderr, "Error during lseek %d (re-calc)\n", h_midi);
   return;
 }
      n_midi = smf_track_head (fd, (p_midi - dh_midi));
      if (n_midi != 8)
 {
   fprintf (stderr, "Error during write %d (re-calc)\n", p_midi);
   return;
 }
    }
  else
    {
      if ((7 + 4 * nmidi) != (p_midi - dh_midi))
 fprintf(stderr, "WaoN warning : data size seems to differ from the header prediction, and stdout isn't seekable to correct the header. Midi players may not tolerate this.\n");
    }
  close (fd);
}

canonical_original_code:
void WAON_notes_output_midi(struct WAON_notes *notes, double div, char *filename)
{
  fprintf (stderr, "WAON_notes : n = %d\n", notes->n);
  fprintf (stderr, "filename : %s\n", filename);
  int fd;
  int flag_stdout;
  if (strncmp (filename, "-", strlen (filename)) == 0)
    {
      fd = dup(1);
      flag_stdout = 1;
    }
  else
    {
      fd = open (filename, 02| 0100| 01000, 0400| 0200);
      flag_stdout = 0;
    }
  if (fd < 0)
    {
      fprintf (stderr, "cannot open %s\n", filename);
      exit (1);
    }
  int p_midi;
  int n_midi;
  p_midi = 0;
  n_midi = smf_header_fmt (fd, 0, 1, div);
  if (n_midi != 14)
    {
      fprintf (stderr, "Error during writing mid! %d (header)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int h_midi;
  h_midi = p_midi;
  int nmidi = notes->n;
  n_midi = smf_track_head (fd, (7+4*nmidi));
  if (n_midi != 8)
    {
      fprintf (stderr, "Error during writing mid! %d (track header)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int dh_midi;
  dh_midi = p_midi;
  n_midi = smf_tempo (fd, 500000);
  if (n_midi != 7)
    {
      fprintf (stderr, "Error during writing mid! %d (tempo)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  n_midi = smf_prog_change (fd, 0, 0);
  if (n_midi != 3)
    {
      fprintf (stderr, "Error during writing mid! %d (prog change)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int idt;
  int last_step = 0;
  int i;
  for (i = 0; i < notes->n; i ++)
    {
      if (i==0) idt = 0;
      else idt = notes->step[i] - last_step;
      last_step = notes->step[i];
      if (notes->event[i] == 1)
 {
   n_midi = smf_note_on (fd, idt,
    notes->note[i],
    notes->vel[i],
    0);
 }
      else
 {
   n_midi = smf_note_off (fd, idt,
     notes->note[i],
     64,
     0);
 }
      if (n_midi < 4)
 {
   if (notes->event[i] == 1)
     {
       fprintf (stderr, "Error during writing mid! %d (note-on)\n"
         " idt = %d, note = %d, vel = %d, n_midi = %d\n",
         p_midi,
         idt, notes->note[i], notes->vel[i], n_midi);
     }
   else
     {
       fprintf (stderr, "Error during writing mid! %d (note-off)\n"
         " idt = %d, note = %d, vel = %d, n_midi = %d\n",
         p_midi,
         idt, notes->note[i], 64, n_midi);
     }
 }
      p_midi += n_midi;
    }
  n_midi = smf_track_end (fd);
  if (n_midi != 4)
    {
      fprintf (stderr, "Error during writing mid! %d (track end)\n",
        p_midi);
      return;
    }
  p_midi += n_midi;
  if (flag_stdout == 0)
    {
      if (lseek (fd, h_midi, 0) < 0)
 {
   fprintf (stderr, "Error during lseek %d (re-calc)\n", h_midi);
   return;
 }
      n_midi = smf_track_head (fd, (p_midi - dh_midi));
      if (n_midi != 8)
 {
   fprintf (stderr, "Error during write %d (re-calc)\n", p_midi);
   return;
 }
    }
  else
    {
      if ((7 + 4 * nmidi) != (p_midi - dh_midi))
 fprintf(stderr, "WaoN warning : data size seems to differ from the header prediction, and stdout isn't seekable to correct the header. Midi players may not tolerate this.\n");
    }
  close (fd);
}

variable_types: struct WAON_notes { int n; int *step; char *event; char *note; char *vel; } *

variable_types: div double

variable_types:
filename
char *

variable_types: nmidi int

variable_types: idt int

variable_types: i int


decompiled_code:
void __fastcall average_FFT_into_midi(int a1, __int64 a2, __int64 a3, _QWORD *a4, double a5)
{
_DWORD *v7; // rax
_DWORD *v8; // rbp
int v9; // er13
__int64 v10; // r15
double v11; // xmm0_8
signed int v12; // eax
double v13; // xmm0_8
double v14; // xmm0_8
__int64 i; // rax
int v16; // edx
signed int v18; // [rsp+1Ch] [rbp-3Ch]

v7 = calloc(0x200uLL, 1uLL);
if ( !v7 )
{
fwrite("average_FFT_into_midi : malloc error for n\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
v8 = v7;
*a4 = 0LL;
a4[127] = 0LL;
memset(
(void *)((unsigned __int64)(a4 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a4 - (((_DWORD)a4 + 8) & 0xFFFFFFF8) + 1024) >> 3));
v9 = (a1 + 1) / 2;
if ( a1 > 2 )
{
v10 = 1LL;
do
{
while ( 1 )
{
v11 = (double)(int)v10 / (double)a1;
if ( a3 )
v11 = v11 + *(double *)(a3 + 8 * v10);
v12 = freq_to_midi(v11 * a5);
if ( (unsigned int)v12 <= 0x7F )
break;
if ( v9 <= (int)++v10 )
goto LABEL_11;
}
v13 = *(double *)(a2 + 8 * v10);
if ( v13 < 0.0 )
{
v18 = v12;
v14 = sqrt(v13);
v12 = v18;
}
else
{
v14 = sqrt(v13);
}
++v10;
++v8[v12];
*(double *)&a4[v12] = v14 + *(double *)&a4[v12];
}
while ( v9 > (int)v10 );
}
LABEL_11:
for ( i = 0LL; i != 128; ++i )
{
v16 = v8[i];
if ( v16 > 0 )
*(double *)&a4[i] = *(double *)&a4[i] / (double)v16 * (*(double *)&a4[i] / (double)v16);
}
free(v8);
}

canonical_decompiled_code:
void __fastcall func0(int a1, __int64 a2, __int64 a3, _QWORD *a4, double a5)
{
_DWORD *v7; // rax
_DWORD *v8; // rbp
int v9; // er13
__int64 v10; // r15
double v11; // xmm0_8
signed int v12; // eax
double v13; // xmm0_8
double v14; // xmm0_8
__int64 i; // rax
int v16; // edx
signed int v18; // [rsp+1Ch] [rbp-3Ch]

v7 = calloc(0x200uLL, 1uLL);
if ( !v7 )
{
fwrite("average_FFT_into_midi : malloc error for n\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
v8 = v7;
*a4 = 0LL;
a4[127] = 0LL;
memset(
(void *)((unsigned __int64)(a4 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a4 - (((_DWORD)a4 + 8) & 0xFFFFFFF8) + 1024) >> 3));
v9 = (a1 + 1) / 2;
if ( a1 > 2 )
{
v10 = 1LL;
do
{
while ( 1 )
{
v11 = (double)(int)v10 / (double)a1;
if ( a3 )
v11 = v11 + *(double *)(a3 + 8 * v10);
v12 = freq_to_midi(v11 * a5);
if ( (unsigned int)v12 <= 0x7F )
break;
if ( v9 <= (int)++v10 )
goto LABEL_11;
}
v13 = *(double *)(a2 + 8 * v10);
if ( v13 < 0.0 )
{
v18 = v12;
v14 = sqrt(v13);
v12 = v18;
}
else
{
v14 = sqrt(v13);
}
++v10;
++v8[v12];
*(double *)&a4[v12] = v14 + *(double *)&a4[v12];
}
while ( v9 > (int)v10 );
}
LABEL_11:
for ( i = 0LL; i != 128; ++i )
{
v16 = v8[i];
if ( v16 > 0 )
*(double *)&a4[i] = *(double *)&a4[i] / (double)v16 * (*(double *)&a4[i] / (double)v16);
}
free(v8);
}

original_code:
void
average_FFT_into_midi (int len, double samplerate,
         const double *amp2, const double *dphi,
         double *ave2)
{
  int k;
  int midi;
  double f;
  int *n = ((void *)0);
  n = (int *) malloc (sizeof (int) * 128);
  if (n == ((void *)0)) { fprintf (stderr, "average_FFT_into_midi" " : malloc error for " "n" "\n"); exit (1); };
  for (midi = 0; midi < 128; midi ++)
    {
      ave2 [midi] = 0.0;
      n [midi] = 0;
    }
  for (k = 1; k < (len+1)/2; k ++)
    {
      if (dphi == ((void *)0))
 {
   f = (double)k / (double)len * samplerate;
 }
      else
 {
   f = ((double)k / (double)len + dphi [k]) * samplerate;
 }
      midi = freq_to_midi (f);
      if (midi >= 0 && midi < 128)
 {
   ave2 [midi] += sqrt (amp2 [k]);
   n [midi] ++;
 }
    }
  for (midi = 0; midi < 128; midi ++)
    {
      if (n [midi] > 0)
 {
   ave2 [midi] = ave2 [midi] / (double)n [midi];
   ave2 [midi] = ave2 [midi] * ave2 [midi];
 }
    }
  free (n);
}

canonical_original_code:
void average_FFT_into_midi(int len, double samplerate, double *amp2, double *dphi, double *ave2)
{
  int k;
  int midi;
  double f;
  int *n = ((void *)0);
  n = (int *) malloc (sizeof (int) * 128);
  if (n == ((void *)0)) { fprintf (stderr, "average_FFT_into_midi" " : malloc error for " "n" "\n"); exit (1); };
  for (midi = 0; midi < 128; midi ++)
    {
      ave2 [midi] = 0.0;
      n [midi] = 0;
    }
  for (k = 1; k < (len+1)/2; k ++)
    {
      if (dphi == ((void *)0))
 {
   f = (double)k / (double)len * samplerate;
 }
      else
 {
   f = ((double)k / (double)len + dphi [k]) * samplerate;
 }
      midi = freq_to_midi (f);
      if (midi >= 0 && midi < 128)
 {
   ave2 [midi] += sqrt (amp2 [k]);
   n [midi] ++;
 }
    }
  for (midi = 0; midi < 128; midi ++)
    {
      if (n [midi] > 0)
 {
   ave2 [midi] = ave2 [midi] / (double)n [midi];
   ave2 [midi] = ave2 [midi] * ave2 [midi];
 }
    }
  free (n);
}

variable_types: len int

variable_types: samplerate double

variable_types:
dphi
double *

variable_types: k int

variable_types: midi int

variable_types: f double

variable_types:
n
int *


original_code:
void
pickup_notes (double *amp2midi,
       double cut_ratio, double rel_cut_ratio,
       int i0, int i1,
       char *intens)
{
  extern int abs_flg;
  double oct_fac = 0.0;
  int i;
  int imax;
  double max;
  double x;
  int in;
  double av;
  for (i = 0; i < 128; i++)
    {
      intens[i] = 0;
    }
  if (abs_flg == 0)
    {
      av = 0.0;
      for (i = i0; i < i1; i++)
 {
   av += amp2midi[i];
 }
      av /= (double)(i1 - i0);
    }
  else
    {
      av = 1.0;
    }
  for (;;)
    {
      if (abs_flg == 0)
 {
   max = av * pow (10.0, rel_cut_ratio);
 }
      else
 {
   max = pow (10.0, cut_ratio);
 }
      imax = -1;
      for (i = i0; i < i1; i++)
 {
   if (amp2midi[i] > max)
     {
       max = amp2midi[i];
       imax = i;
     }
 }
      if (imax == -1)
 break;
      in = imax;
      if (intens[in] == 0)
 {
   x = 127.0 / (double)(-cut_ratio)
     * (log10 (amp2midi[in]) - (double) cut_ratio);
   if (x >= 128.0)
     {
       intens[in] = 127;
     }
   else if (x > 0)
     {
       intens[in] = (int)x;
     }
   if (oct_fac > 0.0)
     {
       for (i = in + 12; in < 128; in += 12)
  {
    amp2midi[i] = sqrt (amp2midi[i])
      - oct_fac * sqrt (amp2midi[i-12]);
    if (amp2midi[i] < 0.0) amp2midi[i] = 0.0;
    else amp2midi[i] = amp2midi[i] * amp2midi[i];
  }
     }
 }
      amp2midi[imax] = 0.0;
    }
}

canonical_original_code:
void pickup_notes(double *amp2midi, double cut_ratio, double rel_cut_ratio, int i0, int i1, char *intens)
{
  extern int abs_flg;
  double oct_fac = 0.0;
  int i;
  int imax;
  double max;
  double x;
  int in;
  double av;
  for (i = 0; i < 128; i++)
    {
      intens[i] = 0;
    }
  if (abs_flg == 0)
    {
      av = 0.0;
      for (i = i0; i < i1; i++)
 {
   av += amp2midi[i];
 }
      av /= (double)(i1 - i0);
    }
  else
    {
      av = 1.0;
    }
  for (;;)
    {
      if (abs_flg == 0)
 {
   max = av * pow (10.0, rel_cut_ratio);
 }
      else
 {
   max = pow (10.0, cut_ratio);
 }
      imax = -1;
      for (i = i0; i < i1; i++)
 {
   if (amp2midi[i] > max)
     {
       max = amp2midi[i];
       imax = i;
     }
 }
      if (imax == -1)
 break;
      in = imax;
      if (intens[in] == 0)
 {
   x = 127.0 / (double)(-cut_ratio)
     * (log10 (amp2midi[in]) - (double) cut_ratio);
   if (x >= 128.0)
     {
       intens[in] = 127;
     }
   else if (x > 0)
     {
       intens[in] = (int)x;
     }
   if (oct_fac > 0.0)
     {
       for (i = in + 12; in < 128; in += 12)
  {
    amp2midi[i] = sqrt (amp2midi[i])
      - oct_fac * sqrt (amp2midi[i-12]);
    if (amp2midi[i] < 0.0) amp2midi[i] = 0.0;
    else amp2midi[i] = amp2midi[i] * amp2midi[i];
  }
     }
 }
      amp2midi[imax] = 0.0;
    }
}

variable_types:
intens
char *

variable_types: imax int

variable_types: max double

variable_types: x double

variable_types: in int

variable_types: av double


decompiled_code:
double __fastcall patch_power(double a1)
{
double v1; // xmm2_8
int v2; // edx
int v3; // eax
double result; // xmm0_8
double v5; // xmm3_8

v1 = *(double *)&if0 * a1;
v2 = (int)(*(double *)&if0 * a1);
if ( v2 <= 0 )
return 0.0;
v3 = v2 + 1;
result = 0.0;
if ( npat >= v2 + 1 )
{
v5 = *(double *)(pat + 8LL * v3 - 8);
result = ((v1 - (double)v2) * (*(double *)(pat + 8LL * v3) - v5) + v5) / *(double *)&p0;
}
return result;
}

canonical_decompiled_code:
double __fastcall func2(double a1)
{
double v1; // xmm2_8
int v2; // edx
int v3; // eax
double result; // xmm0_8
double v5; // xmm3_8

v1 = *(double *)&if0 * a1;
v2 = (int)(*(double *)&if0 * a1);
if ( v2 <= 0 )
return 0.0;
v3 = v2 + 1;
result = 0.0;
if ( npat >= v2 + 1 )
{
v5 = *(double *)(pat + 8LL * v3 - 8);
result = ((v1 - (double)v2) * (*(double *)(pat + 8LL * v3) - v5) + v5) / *(double *)&p0;
}
return result;
}

original_code:
double
patch_power (double freq_ratio)
{
  extern double *pat;
  extern int npat;
  extern double p0;
  extern double if0;
  int i0, i1;
  double dpdf;
  double f;
  double p;
  f = (double)if0 * freq_ratio;
  i0 = (int)f;
  i1 = i0 + 1;
  if (i0 < 1 || i1 > npat)
    return 0.0;
  dpdf = pat[i1] - pat[i0];
  p = pat[i0] + dpdf * (f - (double)i0);
  return (p/p0);
}

canonical_original_code:
double patch_power(double freq_ratio)
{
  extern double *pat;
  extern int npat;
  extern double p0;
  extern double if0;
  int i0; int i1;
  double dpdf;
  double f;
  double p;
  f = (double)if0 * freq_ratio;
  i0 = (int)f;
  i1 = i0 + 1;
  if (i0 < 1 || i1 > npat)
    return 0.0;
  dpdf = pat[i1] - pat[i0];
  p = pat[i0] + dpdf * (f - (double)i0);
  return (p/p0);
}

variable_types:
pat
double *

variable_types: npat int

variable_types: dpdf double

variable_types: p double


original_code:
void
note_intensity (double *p, double *fp,
  double cut_ratio, double rel_cut_ratio,
  int i0, int i1,
  double t0, char *intens)
{
  extern int patch_flg;
  extern int abs_flg;
  int i;
  int imax;
  double max;
  double x;
  double freq;
  double f;
  int in;
  double av;
  for (i = 0; i < 128; i++)
    {
      intens[i] = 0;
    }
  if (abs_flg == 0)
    {
      av = 0.0;
      for (i = i0; i < i1; i++)
 {
   av += p[i];
 }
      av /= (double)(i1 - i0);
    }
  else
    {
      av = 1.0;
    }
  for (;;)
    {
      if (abs_flg == 0)
 {
   max = av * pow (10.0, rel_cut_ratio);
 }
      else
 {
   max = pow (10.0, cut_ratio);
 }
      imax = -1;
      for (i = i0; i < i1; i++)
 {
   if (p[i] > max)
     {
       max = p[i];
       imax = i;
     }
 }
      if (imax == -1)
 break;
      if (fp == ((void *)0))
 {
   freq = (double)imax / t0;
 }
      else
 {
   freq = fp [imax];
 }
      in = get_note (freq);
      if (in >= i0 && in <= i1)
 {
   if (intens[in] == 0)
     {
       x = 127.0 / (double)(-cut_ratio)
  * (log10 (p[imax]) - (double) cut_ratio);
       if (x >= 128.0)
  {
    intens[in] = 127;
  }
       else if (x > 0)
  {
    intens[in] = (int)x;
  }
     }
 }
      if (patch_flg == 0)
 {
   p[imax] = 0.0;
   for (i = imax+1;
       p[i] != 0.0 && i < (i1-1) && p[i] >= p[i+1];
       i++)
     p[i] = 0.0;
   if (i == i1-1)
     p[i] = 0.0;
   for (i = imax-1;
        p[i] != 0.0 && i > i0 && p[i-1] <= p[i];
        i--)
     p[i] = 0.0;
   if (i == i0)
     p[i] = 0.0;
 }
      else
 {
   for (i = i0; i < i1; i++)
     {
       if (fp == ((void *)0))
  {
    f = (double)i / t0;
  }
       else
  {
    f = fp [i];
  }
       p[i] -= max * patch_power (f/freq);
       if (p[i] <0)
  {
    p[i] = 0;
  }
     }
 }
    }
}

canonical_original_code:
void note_intensity(double *p, double *fp, double cut_ratio, double rel_cut_ratio, int i0, int i1, double t0, char *intens)
{
  extern int patch_flg;
  extern int abs_flg;
  int i;
  int imax;
  double max;
  double x;
  double freq;
  double f;
  int in;
  double av;
  for (i = 0; i < 128; i++)
    {
      intens[i] = 0;
    }
  if (abs_flg == 0)
    {
      av = 0.0;
      for (i = i0; i < i1; i++)
 {
   av += p[i];
 }
      av /= (double)(i1 - i0);
    }
  else
    {
      av = 1.0;
    }
  for (;;)
    {
      if (abs_flg == 0)
 {
   max = av * pow (10.0, rel_cut_ratio);
 }
      else
 {
   max = pow (10.0, cut_ratio);
 }
      imax = -1;
      for (i = i0; i < i1; i++)
 {
   if (p[i] > max)
     {
       max = p[i];
       imax = i;
     }
 }
      if (imax == -1)
 break;
      if (fp == ((void *)0))
 {
   freq = (double)imax / t0;
 }
      else
 {
   freq = fp [imax];
 }
      in = get_note (freq);
      if (in >= i0 && in <= i1)
 {
   if (intens[in] == 0)
     {
       x = 127.0 / (double)(-cut_ratio)
  * (log10 (p[imax]) - (double) cut_ratio);
       if (x >= 128.0)
  {
    intens[in] = 127;
  }
       else if (x > 0)
  {
    intens[in] = (int)x;
  }
     }
 }
      if (patch_flg == 0)
 {
   p[imax] = 0.0;
   for (i = imax+1;
       p[i] != 0.0 && i < (i1-1) && p[i] >= p[i+1];
       i++)
     p[i] = 0.0;
   if (i == i1-1)
     p[i] = 0.0;
   for (i = imax-1;
        p[i] != 0.0 && i > i0 && p[i-1] <= p[i];
        i--)
     p[i] = 0.0;
   if (i == i0)
     p[i] = 0.0;
 }
      else
 {
   for (i = i0; i < i1; i++)
     {
       if (fp == ((void *)0))
  {
    f = (double)i / t0;
  }
       else
  {
    f = fp [i];
  }
       p[i] -= max * patch_power (f/freq);
       if (p[i] <0)
  {
    p[i] = 0;
  }
     }
 }
    }
}

variable_types:
p
double *

variable_types:
fp
double *

variable_types: i int

variable_types: freq double


hanning

decompiled_code:
double __fastcall hanning(int a1, int a2)
{
return (1.0 - cos((double)a1 * 6.283185307179586 / (double)(a2 - 1))) * 0.5;
}

variable_types: nn int


hamming

decompiled_code:
double __fastcall hamming(int a1, int a2)
{
return 0.54 - 0.46 * cos((double)a1 * 6.283185307179586 / (double)(a2 - 1));
}


windowing

decompiled_code:
void __fastcall windowing(int a1, double *a2, int a3, double *a4, double a5)
{
int i; // ebx

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
switch ( a3 )
{
case 0:
goto LABEL_5;
case 1:
*a4 = COERCE_DOUBLE(parzen(i, a1)) * *a2 / a5;
break;
case 2:
*a4 = COERCE_DOUBLE(welch(i, a1)) * *a2 / a5;
break;
case 3:
*a4 = hanning(i, a1) * *a2 / a5;
break;
case 4:
*a4 = hamming(i, a1) * *a2 / a5;
break;
case 5:
*a4 = blackman(i, a1) * *a2 / a5;
break;
case 6:
*a4 = steeper(i, a1) * *a2 / a5;
break;
default:
fwrite("invalid flag_window\n", 1uLL, 0x14uLL, stderr);
LABEL_5:
*a4 = *a2 / a5;
break;
}
++a2;
++a4;
}
}
}

canonical_decompiled_code:
void __fastcall func4(int a1, double *a2, int a3, double *a4, double a5)
{
int i; // ebx

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
switch ( a3 )
{
case 0:
goto LABEL_5;
case 1:
*a4 = COERCE_DOUBLE(parzen(i, a1)) * *a2 / a5;
break;
case 2:
*a4 = COERCE_DOUBLE(welch(i, a1)) * *a2 / a5;
break;
case 3:
*a4 = func0(i, a1) * *a2 / a5;
break;
case 4:
*a4 = func1(i, a1) * *a2 / a5;
break;
case 5:
*a4 = func2(i, a1) * *a2 / a5;
break;
case 6:
*a4 = func3(i, a1) * *a2 / a5;
break;
default:
fwrite("invalid flag_window\n", 1uLL, 0x14uLL, stderr);
LABEL_5:
*a4 = *a2 / a5;
break;
}
++a2;
++a4;
}
}
}

original_code:
void
windowing (int n, const double *data, int flag_window, double scale,
    double *out)
{
  int i;
  for (i = 0; i < n; i ++)
    {
      switch (flag_window)
 {
 case 1:
   out [i] = data [i] * parzen (i, n) / scale;
   break;
 case 2:
   out [i] = data [i] * welch (i, n) / scale;
   break;
 case 3:
   out [i] = data [i] * hanning (i, n) / scale;
   break;
 case 4:
   out [i] = data [i] * hamming (i, n) / scale;
   break;
 case 5:
   out [i] = data [i] * blackman (i, n) / scale;
   break;
 case 6:
   out [i] = data [i] * steeper (i, n) / scale;
   break;
 default:
   fprintf (stderr, "invalid flag_window\n");
 case 0:
   out [i] = data [i] / scale;
   break;
 }
    }
}

canonical_original_code:
void windowing(int n, double *data, int flag_window, double scale, double *out)
{
  int i;
  for (i = 0; i < n; i ++)
    {
      switch (flag_window)
 {
 case 1:
   out [i] = data [i] * parzen (i, n) / scale;
   break;
 case 2:
   out [i] = data [i] * welch (i, n) / scale;
   break;
 case 3:
   out [i] = data [i] * hanning (i, n) / scale;
   break;
 case 4:
   out [i] = data [i] * hamming (i, n) / scale;
   break;
 case 5:
   out [i] = data [i] * blackman (i, n) / scale;
   break;
 case 6:
   out [i] = data [i] * steeper (i, n) / scale;
   break;
 default:
   fprintf (stderr, "invalid flag_window\n");
 case 0:
   out [i] = data [i] / scale;
   break;
 }
    }
}

variable_types: n int

variable_types:
data
double *

variable_types: scale double

variable_types:
out
double *


decompiled_code:
double __fastcall init_den(int a1, char a2)
{
int v2; // ebx
double v3; // xmm1_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8

if ( a1 <= 0 )
{
v3 = 0.0;
}
else
{
v2 = 0;
v3 = 0.0;
do
{
switch ( a2 )
{
case 0:
goto LABEL_5;
case 1:
v10 = COERCE_DOUBLE(parzen(v2, a1));
v3 = v3 + v10 * v10;
break;
case 2:
v9 = COERCE_DOUBLE(welch(v2, a1));
v3 = v3 + v9 * v9;
break;
case 3:
v8 = hanning(v2, a1);
v3 = v3 + v8 * v8;
break;
case 4:
v7 = hamming(v2, a1);
v3 = v3 + v7 * v7;
break;
case 5:
v6 = blackman(v2, a1);
v3 = v3 + v6 * v6;
break;
case 6:
v5 = steeper(v2, a1);
v3 = v3 + v5 * v5;
break;
default:
fwrite("invalid flag_window\n", 1uLL, 0x14uLL, stderr);
LABEL_5:
v3 = v3 + 1.0;
break;
}
++v2;
}
while ( a1 != v2 );
}
return (double)a1 * v3;
}

canonical_decompiled_code:
double __fastcall func7(int a1, char a2)
{
int v2; // ebx
double v3; // xmm1_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8

if ( a1 <= 0 )
{
v3 = 0.0;
}
else
{
v2 = 0;
v3 = 0.0;
do
{
switch ( a2 )
{
case 0:
goto LABEL_5;
case 1:
v10 = COERCE_DOUBLE(parzen(v2, a1));
v3 = v3 + v10 * v10;
break;
case 2:
v9 = COERCE_DOUBLE(welch(v2, a1));
v3 = v3 + v9 * v9;
break;
case 3:
v8 = func0(v2, a1);
v3 = v3 + v8 * v8;
break;
case 4:
v7 = func1(v2, a1);
v3 = v3 + v7 * v7;
break;
case 5:
v6 = func2(v2, a1);
v3 = v3 + v6 * v6;
break;
case 6:
v5 = func3(v2, a1);
v3 = v3 + v5 * v5;
break;
default:
fwrite("invalid flag_window\n", 1uLL, 0x14uLL, stderr);
LABEL_5:
v3 = v3 + 1.0;
break;
}
++v2;
}
while ( a1 != v2 );
}
return (double)a1 * v3;
}

original_code:
double
init_den (int n, char flag_window)
{
  double den;
  int i;
  den = 0.0;
  for (i = 0; i < n; i ++)
    {
      switch (flag_window)
 {
 case 1:
   den += parzen (i, n) * parzen (i, n);
   break;
 case 2:
   den += welch (i, n) * welch (i, n);
   break;
 case 3:
   den += hanning (i, n) * hanning (i, n);
   break;
 case 4:
   den += hamming (i, n) * hamming (i, n);
   break;
 case 5:
   den += blackman (i, n) * blackman (i, n);
   break;
 case 6:
   den += steeper (i, n) * steeper (i, n);
   break;
 default:
   fprintf (stderr, "invalid flag_window\n");
 case 0:
   den += 1.0;
   break;
 }
    }
  den *= (double)n;
  return den;
}

canonical_original_code:
double init_den(int n, char flag_window)
{
  double den;
  int i;
  den = 0.0;
  for (i = 0; i < n; i ++)
    {
      switch (flag_window)
 {
 case 1:
   den += parzen (i, n) * parzen (i, n);
   break;
 case 2:
   den += welch (i, n) * welch (i, n);
   break;
 case 3:
   den += hanning (i, n) * hanning (i, n);
   break;
 case 4:
   den += hamming (i, n) * hamming (i, n);
   break;
 case 5:
   den += blackman (i, n) * blackman (i, n);
   break;
 case 6:
   den += steeper (i, n) * steeper (i, n);
   break;
 default:
   fprintf (stderr, "invalid flag_window\n");
 case 0:
   den += 1.0;
   break;
 }
    }
  den *= (double)n;
  return den;
}

variable_types: den double