main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char **v4; // r12
int v5; // er13
__int64 v6; // rbx
const char *v7; // rdi

if ( argc <= 1 )
goto LABEL_8;
v3 = argc;
v4 = argv;
v5 = strcmp(argv[1], "-n");
if ( v5 )
{
v5 = 1;
}
else
{
v3 = argc - 1;
if ( argc == 2 )
goto LABEL_9;
v4 = argv + 1;
}
v6 = 1LL;
while ( 1 )
{
v7 = v4[v6++];
fputs(v7, _bss_start);
if ( v3 <= (int)v6 )
break;
putchar(32);
}
if ( v5 )
LABEL_8:
putchar(10);
LABEL_9:
exit(0);
}

original_code:
float
main(int argc, char **argv)
{
    int opt;
    int rc;
    mkd_flag_t flags = 0;
    int debug = 0;
    int toc = 0;
    int version = 0;
    int with_html5 = 0;
    int use_mkd_line = 0;
    char *extra_footnote_prefix = 0;
    char *urlflags = 0;
    char *text = 0;
    char *ofile = 0;
    char *urlbase = 0;
    char *q;
    MMIOT *doc;
    if ( q = getenv("MARKDOWN_FLAGS") )
 flags = strtol(q, 0, 0);
    pgm = basename(argv[0]);
    opterr = 1;
    while ( (opt=getopt(argc, argv, "5b:C:df:E:F:o:s:t:TV")) != (-1) ) {
 switch (opt) {
 case '5': with_html5 = 1;
      break;
 case 'b': urlbase = optarg;
      break;
 case 'd': debug = 1;
      break;
 case 'V': version++;
      break;
 case 'E': urlflags = optarg;
      break;
 case 'F': if ( strcmp(optarg, "?") == 0 ) {
   show_flags(0);
   exit(0);
      }
      else
   flags = strtol(optarg, 0, 0);
      break;
 case 'f': if ( strcmp(optarg, "?") == 0 ) {
   show_flags(1);
   exit(0);
      }
      else if ( !set_flag(&flags, optarg) )
   complain("unknown option <%s>", optarg);
      break;
 case 't': text = optarg;
      use_mkd_line = 1;
      break;
 case 'T': toc = 1;
      break;
 case 's': text = optarg;
      break;
 case 'C': extra_footnote_prefix = optarg;
      break;
 case 'o': if ( ofile ) {
   complain("Too many -o options");
   exit(1);
      }
      if ( !freopen(ofile = optarg, "w", stdout) ) {
   perror(ofile);
   exit(1);
      }
      break;
 default: fprintf(stderr, "usage: %s [-dTV] [-b url-base]"
        " [-F bitmap] [-f {+-}flags]"
        " [-o ofile] [-s text]"
        " [-t text] [file]\n", pgm);
      exit(1);
 }
    }
    if ( version ) {
 printf("%s: discount %s%s", pgm, markdown_version,
      with_html5 ? " +html5":"");
 if ( version > 1 )
     mkd_flags_are(stdout, flags, 0);
 putchar('\n');
 exit(0);
    }
    argc -= optind;
    argv += optind;
    if ( with_html5 )
 mkd_with_html5_tags();
    if ( use_mkd_line )
 rc = mkd_generateline( text, strlen(text), stdout, flags);
    else {
 if ( text ) {
     if ( (doc = mkd_string(text, strlen(text), flags)) == 0 ) {
  perror(text);
  exit(1);
     }
 }
 else {
     if ( argc && !freopen(argv[0], "r", stdin) ) {
  perror(argv[0]);
  exit(1);
     }
     if ( (doc = mkd_in(stdin,flags)) == 0 ) {
  perror(argc ? argv[0] : "stdin");
  exit(1);
     }
 }
 if ( urlbase )
     mkd_basename(doc, urlbase);
 if ( urlflags ) {
     mkd_e_data(doc, urlflags);
     mkd_e_flags(doc, e_flags);
 }
 if ( extra_footnote_prefix )
     mkd_ref_prefix(doc, extra_footnote_prefix);
 if ( debug )
     rc = mkd_dump(doc, stdout, 0, argc ? basename(argv[0]) : "stdin");
 else {
     rc = 1;
     if ( mkd_compile(doc, flags) ) {
  rc = 0;
  if ( toc )
      mkd_generatetoc(doc, stdout);
  mkd_generatehtml(doc, stdout);
  mkd_cleanup(doc);
     }
 }
    }
    mkd_deallocate_tags();
    (void)1;
    exit( (rc == 0) ? 0 : (*__errno_location ()) );
}

canonical_original_code:
float main(int argc, char **argv)
{
    int opt;
    int rc;
    unsigned int flags = 0;
    int debug = 0;
    int toc = 0;
    int version = 0;
    int with_html5 = 0;
    int use_mkd_line = 0;
    char *extra_footnote_prefix = 0;
    char *urlflags = 0;
    char *text = 0;
    char *ofile = 0;
    char *urlbase = 0;
    char *q;
    void *doc;
    if ( q = getenv("MARKDOWN_FLAGS") )
 flags = strtol(q, 0, 0);
    pgm = basename(argv[0]);
    opterr = 1;
    while ( (opt=getopt(argc, argv, "5b:C:df:E:F:o:s:t:TV")) != (-1) ) {
 switch (opt) {
 case '5': with_html5 = 1;
      break;
 case 'b': urlbase = optarg;
      break;
 case 'd': debug = 1;
      break;
 case 'V': version++;
      break;
 case 'E': urlflags = optarg;
      break;
 case 'F': if ( strcmp(optarg, "?") == 0 ) {
   show_flags(0);
   exit(0);
      }
      else
   flags = strtol(optarg, 0, 0);
      break;
 case 'f': if ( strcmp(optarg, "?") == 0 ) {
   show_flags(1);
   exit(0);
      }
      else if ( !set_flag(&flags, optarg) )
   complain("unknown option <%s>", optarg);
      break;
 case 't': text = optarg;
      use_mkd_line = 1;
      break;
 case 'T': toc = 1;
      break;
 case 's': text = optarg;
      break;
 case 'C': extra_footnote_prefix = optarg;
      break;
 case 'o': if ( ofile ) {
   complain("Too many -o options");
   exit(1);
      }
      if ( !freopen(ofile = optarg, "w", stdout) ) {
   perror(ofile);
   exit(1);
      }
      break;
 default: fprintf(stderr, "usage: %s [-dTV] [-b url-base]"
        " [-F bitmap] [-f {+-}flags]"
        " [-o ofile] [-s text]"
        " [-t text] [file]\n", pgm);
      exit(1);
 }
    }
    if ( version ) {
 printf("%s: discount %s%s", pgm, markdown_version,
      with_html5 ? " +html5":"");
 if ( version > 1 )
     mkd_flags_are(stdout, flags, 0);
 putchar('\n');
 exit(0);
    }
    argc -= optind;
    argv += optind;
    if ( with_html5 )
 mkd_with_html5_tags();
    if ( use_mkd_line )
 rc = mkd_generateline( text, strlen(text), stdout, flags);
    else {
 if ( text ) {
     if ( (doc = mkd_string(text, strlen(text), flags)) == 0 ) {
  perror(text);
  exit(1);
     }
 }
 else {
     if ( argc && !freopen(argv[0], "r", stdin) ) {
  perror(argv[0]);
  exit(1);
     }
     if ( (doc = mkd_in(stdin,flags)) == 0 ) {
  perror(argc ? argv[0] : "stdin");
  exit(1);
     }
 }
 if ( urlbase )
     mkd_basename(doc, urlbase);
 if ( urlflags ) {
     mkd_e_data(doc, urlflags);
     mkd_e_flags(doc, e_flags);
 }
 if ( extra_footnote_prefix )
     mkd_ref_prefix(doc, extra_footnote_prefix);
 if ( debug )
     rc = mkd_dump(doc, stdout, 0, argc ? basename(argv[0]) : "stdin");
 else {
     rc = 1;
     if ( mkd_compile(doc, flags) ) {
  rc = 0;
  if ( toc )
      mkd_generatetoc(doc, stdout);
  mkd_generatehtml(doc, stdout);
  mkd_cleanup(doc);
     }
 }
    }
    mkd_deallocate_tags();
    (void)1;
    exit( (rc == 0) ? 0 : (*__errno_location ()) );
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types: rc int

variable_types:
flags
unsigned int

variable_types: debug int

variable_types: toc int

variable_types: version int

variable_types:
urlflags
char *

variable_types:
text
char *

variable_types:
ofile
char *

variable_types:
urlbase
char *

variable_types:
q
char *

variable_types:
doc
void *


repo: simonfi/pi-servo

decompiled_code:
void *gpio_setup()
{
int v0; // eax
int v1; // ebx
char *v2; // rax
char *v3; // rdi
unsigned int v4; // eax
void *result; // rax

v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
perror("open");
exit(-1);
}
v1 = v0;
v2 = (char *)malloc(0x1FFFuLL);
v3 = v2;
if ( !v2 )
{
perror("malloc");
exit(-1);
}
v4 = (unsigned __int16)v2 & 0xFFF;
if ( v4 )
v3 = &v3[-v4 + 4096];
result = mmap(v3, 0x1000uLL, 3, 17, v1, 538968064LL);
if ( (__int64)result < 0 )
{
perror("mmap");
exit(-1);
}
_gpio_ptr = (__int64)result;
return result;
}

canonical_decompiled_code:
void *func0()
{
int v0; // eax
int v1; // ebx
char *v2; // rax
char *v3; // rdi
unsigned int v4; // eax
void *result; // rax

v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
perror("open");
exit(-1);
}
v1 = v0;
v2 = (char *)malloc(0x1FFFuLL);
v3 = v2;
if ( !v2 )
{
perror("malloc");
exit(-1);
}
v4 = (unsigned __int16)v2 & 0xFFF;
if ( v4 )
v3 = &v3[-v4 + 4096];
result = mmap(v3, 0x1000uLL, 3, 17, v1, 538968064LL);
if ( (__int64)result < 0 )
{
perror("mmap");
exit(-1);
}
_gpio_ptr = (__int64)result;
return result;
}

original_code:
void gpio_setup(void)
{
 int mem_fd;
 char* gpio_mem;
 char* gpio_map;
 char* spi0_mem;
 char* spi0_map;
 if ((mem_fd = open("/dev/mem", 02|04010000) ) < 0)
 {
  perror("open");
  exit(-1);
 }
 if ((gpio_mem = malloc((4*1024) + ((4*1024)-1))) == ((void *)0))
 {
  perror("malloc");
  exit(-1);
 }
 if ((unsigned long)gpio_mem % (4*1024))
 {
  gpio_mem += (4*1024) - ((unsigned long)gpio_mem % (4*1024));
 }
 gpio_map = (unsigned char *)mmap( (caddr_t)gpio_mem,
      (4*1024),
      0x1|0x2,
      0x01|0x10,
      mem_fd,
      (0x20000000 + 0x200000));
 if ((long)gpio_map < 0)
 {
  perror("mmap");
  exit (-1);
 }
 __gpio_ptr = (volatile unsigned *)gpio_map;
}

canonical_original_code:
void gpio_setup()
{
 int mem_fd;
 char *gpio_mem;
 char *gpio_map;
 char *spi0_mem;
 char *spi0_map;
 if ((mem_fd = open("/dev/mem", 02|04010000) ) < 0)
 {
  perror("open");
  exit(-1);
 }
 if ((gpio_mem = malloc((4*1024) + ((4*1024)-1))) == ((void *)0))
 {
  perror("malloc");
  exit(-1);
 }
 if ((unsigned long)gpio_mem % (4*1024))
 {
  gpio_mem += (4*1024) - ((unsigned long)gpio_mem % (4*1024));
 }
 gpio_map = (unsigned char *)mmap( (char *)gpio_mem,
      (4*1024),
      0x1|0x2,
      0x01|0x10,
      mem_fd,
      (0x20000000 + 0x200000));
 if ((long)gpio_map < 0)
 {
  perror("mmap");
  exit (-1);
 }
 __gpio_ptr = (unsigned int *)gpio_map;
}

return_type: void


length

repo: simonkrenger/bfh-grundlagen-informatik

decompiled_code:
__int64 __fastcall length(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int length(char str[]) {
 int len;
 for (len = 0; str[len] != '\0'; len++)
  ;
 return len;
}

variable_types:
str
char []

variable_types: len int

return_type: int


last

decompiled_code:
__int64 __fastcall last(__int64 a1, _BYTE *a2)
{
__int64 result; // rax
char v3; // dl

LODWORD(result) = length(a2) - 1;
if ( (int)result < 0 )
return 0xFFFFFFFFLL;
result = (int)result;
while ( a2[result] != v3 )
{
if ( (int)--result < 0 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _BYTE *a2)
{
__int64 result; // rax
char v3; // dl

LODWORD(result) = func7(a2) - 1;
if ( (int)result < 0 )
return 0xFFFFFFFFLL;
result = (int)result;
while ( a2[result] != v3 )
{
if ( (int)--result < 0 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int last(char letter, char str[]) {
 int str_len = length(str);
 int i = 0;
 for (i = (str_len - 1); i >= 0; i--) {
  if (str[i] == letter)
   return i;
 }
 return -1;
}

variable_types: letter char

variable_types: i int


first

decompiled_code:
__int64 __fastcall first(__int64 a1, _BYTE *a2)
{
int v2; // eax
char v3; // dl
__int64 v4; // rcx
__int64 result; // rax

v2 = length(a2);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
v4 = (unsigned int)(v2 + 1);
result = 1LL;
while ( a2[result - 1] != v3 )
{
if ( ++result == v4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, _BYTE *a2)
{
int v2; // eax
char v3; // dl
__int64 v4; // rcx
__int64 result; // rax

v2 = func7(a2);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
v4 = (unsigned int)(v2 + 1);
result = 1LL;
while ( a2[result - 1] != v3 )
{
if ( ++result == v4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int first(char letter, char str[]) {
 int str_len = length(str);
 int i;
 for (i = 0; i < str_len; i++) {
  if (str[i] == letter)
   return i + 1;
 }
 return -1;
}


count

decompiled_code:
__int64 __fastcall count(__int64 a1, _BYTE *a2)
{
int v2; // eax
unsigned __int8 v3; // cl
__int64 v4; // rdi
__int64 result; // rax
_BOOL4 v6; // edx

v2 = length(a2);
if ( v2 <= 0 )
return 0LL;
v4 = (__int64)&a2[v2 - 1 + 1];
LODWORD(result) = 0;
do
{
v6 = *a2++ == v3;
result = (unsigned int)(v6 + result);
}
while ( a2 != (_BYTE *)v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _BYTE *a2)
{
int v2; // eax
unsigned __int8 v3; // cl
__int64 v4; // rdi
__int64 result; // rax
_BOOL4 v6; // edx

v2 = func7(a2);
if ( v2 <= 0 )
return 0LL;
v4 = (__int64)&a2[v2 - 1 + 1];
LODWORD(result) = 0;
do
{
v6 = *a2++ == v3;
result = (unsigned int)(v6 + result);
}
while ( a2 != (_BYTE *)v4 );
return result;
}

original_code:
int count(char t, char s[]) {
 int occ = 0;
 int str_len = length(s);
 int i;
 for (i = 0; i < str_len; i++) {
  if (s[i] == t)
   occ++;
 }
 return occ;
}

variable_types: t char

variable_types:
s
char []

variable_types: occ int


longest

decompiled_code:
__int64 __fastcall longest(_BYTE *a1)
{
int v1; // eax
__int64 v2; // rcx
unsigned int v3; // er8
__int64 v4; // rax
unsigned int v5; // er9
int v6; // esi
int v7; // edx

v1 = length(a1);
if ( v1 <= 0 )
return 0LL;
v2 = (unsigned int)(v1 + 1);
v3 = 0;
v4 = 1LL;
v5 = 0;
v6 = 0;
v7 = 0;
do
{
while ( a1[v4 - 1] == 32 )
{
v3 = v4++;
v7 = 0;
if ( v4 == v2 )
return v5;
}
if ( ++v7 > v6 )
{
v5 = v3;
v6 = v7;
}
++v4;
}
while ( v4 != v2 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func11(_BYTE *a1)
{
int v1; // eax
__int64 v2; // rcx
unsigned int v3; // er8
__int64 v4; // rax
unsigned int v5; // er9
int v6; // esi
int v7; // edx

v1 = func7(a1);
if ( v1 <= 0 )
return 0LL;
v2 = (unsigned int)(v1 + 1);
v3 = 0;
v4 = 1LL;
v5 = 0;
v6 = 0;
v7 = 0;
do
{
while ( a1[v4 - 1] == 32 )
{
v3 = v4++;
v7 = 0;
if ( v4 == v2 )
return v5;
}
if ( ++v7 > v6 )
{
v5 = v3;
v6 = v7;
}
++v4;
}
while ( v4 != v2 );
return v5;
}

original_code:
int longest(char str[]) {
 int cur_word_len = 0, longest_len = 0;
 int i, longest_idx = 0, cur_word_idx = 0;
 int total_len = length(str);
 for (i = 0; i < total_len; i++) {
  if (str[i] == ' ') {
   cur_word_idx = i + 1;
   cur_word_len = 0;
  } else {
   cur_word_len++;
   if (cur_word_len > longest_len) {
    longest_len = cur_word_len;
    longest_idx = cur_word_idx;
   }
  }
 }
 return longest_idx;
}

canonical_original_code:
int longest(char str[]) {
 int cur_word_len = 0; int longest_len = 0;
 int i; int longest_idx = 0; int cur_word_idx = 0;
 int total_len = length(str);
 for (i = 0; i < total_len; i++) {
  if (str[i] == ' ') {
   cur_word_idx = i + 1;
   cur_word_len = 0;
  } else {
   cur_word_len++;
   if (cur_word_len > longest_len) {
    longest_len = cur_word_len;
    longest_idx = cur_word_idx;
   }
  }
 }
 return longest_idx;
}


decompiled_code:
__int64 __fastcall cmp_strings(_BYTE *a1, _BYTE *a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
int v4; // er8
__int64 result; // rax
__int64 v6; // rax

length(a1);
v4 = length(a2);
result = 1LL;
if ( (_DWORD)v2 == v4 )
{
if ( (int)v2 <= 0 )
{
LABEL_7:
result = 0LL;
}
else
{
v6 = 0LL;
while ( *(_BYTE *)(v3 + v6) == a2[v6] )
{
if ( v2 == ++v6 )
goto LABEL_7;
}
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1, _BYTE *a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
int v4; // er8
__int64 result; // rax
__int64 v6; // rax

func7(a1);
v4 = func7(a2);
result = 1LL;
if ( (_DWORD)v2 == v4 )
{
if ( (int)v2 <= 0 )
{
LABEL_7:
result = 0LL;
}
else
{
v6 = 0LL;
while ( *(_BYTE *)(v3 + v6) == a2[v6] )
{
if ( v2 == ++v6 )
goto LABEL_7;
}
result = 1LL;
}
}
return result;
}

original_code:
int cmp_strings(char str_a[], char str_b[]) {
 if (length(str_a) == length(str_b)) {
  int i;
  for (i = 0; i < length(str_a); i++) {
   if (str_a[i] != str_b[i])
    return 1;
  }
  return 0;
 }
 return 1;
}


decompiled_code:
int __fastcall print_char_distr(_BYTE *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // rdx
__int64 v5; // rbx
__int64 v6; // rsi
int vars0[34]; // [rsp+0h] [rbp+0h] BYREF

memset(vars0, 0, 0x68uLL);
LODWORD(v1) = length(a1);
if ( (int)v1 > 0 )
{
v3 = v2 + (unsigned int)(v1 - 1) + 1;
while ( 1 )
{
LODWORD(v1) = (char)*a1;
if ( (unsigned __int8)((*a1 & 0xDF) - 65) > 0x19u )
goto LABEL_4;
if ( (unsigned __int8)(v1 - 65) <= 0x19u )
{
++vars0[(char)(v1 - 65)];
LABEL_4:
if ( ++a1 == (_BYTE *)v3 )
goto LABEL_8;
}
else
{
++a1;
v1 = (int)v1 - 97;
++vars0[v1];
if ( a1 == (_BYTE *)v3 )
{
LABEL_8:
v4 = (unsigned int)vars0[0];
goto LABEL_9;
}
}
}
}
v4 = 0LL;
LABEL_9:
v5 = 0LL;
while ( !(_DWORD)v4 )
{
if ( ++v5 == 26 )
return v1;
LABEL_11:
v4 = (unsigned int)vars0[v5];
}
v6 = (unsigned int)(v5++ + 65);
LODWORD(v1) = printf("%c: %d\n", v6, v4);
if ( v5 != 26 )
goto LABEL_11;
return v1;
}

canonical_decompiled_code:
int __fastcall func13(_BYTE *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // rdx
__int64 v5; // rbx
__int64 v6; // rsi
int vars0[34]; // [rsp+0h] [rbp+0h] BYREF

memset(vars0, 0, 0x68uLL);
LODWORD(v1) = func7(a1);
if ( (int)v1 > 0 )
{
v3 = v2 + (unsigned int)(v1 - 1) + 1;
while ( 1 )
{
LODWORD(v1) = (char)*a1;
if ( (unsigned __int8)((*a1 & 0xDF) - 65) > 0x19u )
goto LABEL_4;
if ( (unsigned __int8)(v1 - 65) <= 0x19u )
{
++vars0[(char)(v1 - 65)];
LABEL_4:
if ( ++a1 == (_BYTE *)v3 )
goto LABEL_8;
}
else
{
++a1;
v1 = (int)v1 - 97;
++vars0[v1];
if ( a1 == (_BYTE *)v3 )
{
LABEL_8:
v4 = (unsigned int)vars0[0];
goto LABEL_9;
}
}
}
}
v4 = 0LL;
LABEL_9:
v5 = 0LL;
while ( !(_DWORD)v4 )
{
if ( ++v5 == 26 )
return v1;
LABEL_11:
v4 = (unsigned int)vars0[v5];
}
v6 = (unsigned int)(v5++ + 65);
LODWORD(v1) = printf("%c: %d\n", v6, v4);
if ( v5 != 26 )
goto LABEL_11;
return v1;
}

original_code:
void print_char_distr(char str[]) {
 int characters[26] = { };
 int str_len = length(str);
 int i;
 for (i = 0; i < str_len; i++) {
  int chars_upper = (str[i] >= 65 && str[i] <= 90);
  int chars_lower = (str[i] >= 97 && str[i] <= 122);
  if (chars_upper || chars_lower) {
   if (chars_upper) {
    characters[str[i] - 65]++;
   } else {
    characters[str[i] - 97]++;
   }
  }
 }
 for (i = 0; i < 26; i++) {
  if (characters[i] != 0)
   printf("%c: %d\n", i + 65, characters[i]);
 }
}

variable_types:
characters
int [26]


substitute

decompiled_code:
__int64 __fastcall substitute(__int64 a1, char a2, _BYTE *a3)
{
int v3; // eax
_BYTE *v4; // rdx
char v5; // cl
unsigned int v6; // er8
__int64 v7; // rax

v3 = length(a3);
if ( v3 <= 0 )
return 0LL;
v6 = 0;
v7 = (__int64)&v4[v3 - 1 + 1];
do
{
if ( *v4 == v5 )
{
*v4 = a2;
++v6;
}
++v4;
}
while ( v4 != (_BYTE *)v7 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, char a2, _BYTE *a3)
{
int v3; // eax
_BYTE *v4; // rdx
char v5; // cl
unsigned int v6; // er8
__int64 v7; // rax

v3 = func7(a3);
if ( v3 <= 0 )
return 0LL;
v6 = 0;
v7 = (__int64)&v4[v3 - 1 + 1];
do
{
if ( *v4 == v5 )
{
*v4 = a2;
++v6;
}
++v4;
}
while ( v4 != (_BYTE *)v7 );
return v6;
}

original_code:
int substitute(char old, char new, char str[]) {
 int str_length = length(str);
 int chars_changed = 0;
 int i;
 for (i = 0; i < str_length; i++) {
  if (str[i] == old) {
   str[i] = new;
   chars_changed++;
  }
 }
 return chars_changed;
}

variable_types: old char

variable_types: new char


decompiled_code:
__int64 __fastcall str_to_lower(_BYTE *a1)
{
int v1; // eax
unsigned int v2; // er8
__int64 v3; // rcx

v1 = length(a1);
if ( v1 <= 0 )
return 0LL;
v2 = 0;
v3 = (__int64)&a1[v1 - 1 + 1];
do
{
if ( (unsigned __int8)(*a1 - 65) <= 0x19u )
{
++v2;
*a1 += 32;
}
++a1;
}
while ( a1 != (_BYTE *)v3 );
return v2;
}

original_code:
int str_to_lower(char str[]) {
 int str_len = length(str);
 int occ = 0;
 int i;
 for (i = 0; i < str_len; i++) {
  if (str[i] >= 65 && str[i] <= 90) {
   str[i] = str[i] + 32;
   occ++;
  }
 }
 return occ;
}


decompiled_code:
__int64 __fastcall str_to_upper(_BYTE *a1)
{
int v1; // eax
unsigned int v2; // er8
__int64 v3; // rcx

v1 = length(a1);
if ( v1 <= 0 )
return 0LL;
v2 = 0;
v3 = (__int64)&a1[v1 - 1 + 1];
do
{
if ( (unsigned __int8)(*a1 - 97) <= 0x19u )
{
++v2;
*a1 -= 32;
}
++a1;
}
while ( a1 != (_BYTE *)v3 );
return v2;
}

original_code:
int str_to_upper(char str[]) {
 int str_len = length(str);
 int occ = 0;
 int i;
 for (i = 0; i < str_len; i++) {
  if (str[i] >= 97 && str[i] <= 122) {
   str[i] = str[i] - 32;
   occ++;
  }
 }
 return occ;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
char v12[20]; // [rsp+8h] [rbp-20h] BYREF

strcpy(v12, "Hello World");
strcpy(&v12[12], "hella warld");
v3 = length(v12, v12, envp);
printf("Length of test-string \"%s\": %d\n", v12, v3);
v4 = last(108LL, v12);
printf("Last occurrence of character %c in test-string \"%s\": %d\n", 108LL, v12, v4);
v5 = first(108LL, v12);
printf("First occurrence of character %c in test-string \"%s\": %d\n", 108LL, v12, v5);
v6 = count(108LL, v12);
printf("Count of character %c in test-string \"%s\": %d\n", 108LL, v12, v6);
v7 = longest(v12);
printf("Longest word of test-string \"%s\" is at index: %d\n", v12, v7);
printf("Character distribution in \"%s\":\n", v12);
print_char_distr(v12);
v8 = substitute(111LL, 97LL, v12);
printf("When substituting %c with %c, you have to do %d substitutions.\n", 111LL, 97LL, v8);
printf("The string is now \"%s\"\n", v12);
printf("Let us convert \"%s\" to lower case.\n", v12);
v9 = str_to_lower(v12);
printf("When converting to lower case, %d chars have to be replaced\n", v9);
printf("The string is now \"%s\"\n", v12);
v10 = cmp_strings(v12, &v12[12]);
printf("Result of comparison: %d\n", v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
char v12[20]; // [rsp+8h] [rbp-20h] BYREF

strcpy(v12, "Hello World");
strcpy(&v12[12], "hella warld");
v3 = func7(v12, v12, envp);
printf("Length of test-string \"%s\": %d\n", v12, v3);
v4 = func8(108LL, v12);
printf("Last occurrence of character %c in test-string \"%s\": %d\n", 108LL, v12, v4);
v5 = func9(108LL, v12);
printf("First occurrence of character %c in test-string \"%s\": %d\n", 108LL, v12, v5);
v6 = func10(108LL, v12);
printf("Count of character %c in test-string \"%s\": %d\n", 108LL, v12, v6);
v7 = func11(v12);
printf("Longest word of test-string \"%s\" is at index: %d\n", v12, v7);
printf("Character distribution in \"%s\":\n", v12);
func13(v12);
v8 = func14(111LL, 97LL, v12);
printf("When substituting %c with %c, you have to do %d substitutions.\n", 111LL, 97LL, v8);
printf("The string is now \"%s\"\n", v12);
printf("Let us convert \"%s\" to lower case.\n", v12);
v9 = func15(v12);
printf("When converting to lower case, %d chars have to be replaced\n", v9);
printf("The string is now \"%s\"\n", v12);
v10 = func12(v12, &v12[12]);
printf("Result of comparison: %d\n", v10);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 char test_string[] = "Hello World";
 char another_string[] = "hella warld";
 char single_char = 'l';
 printf("Length of test-string \"%s\": %d\n", test_string,
   length(test_string));
 printf("Last occurrence of character %c in test-string \"%s\": %d\n",
   single_char, test_string, last(single_char, test_string));
 printf("First occurrence of character %c in test-string \"%s\": %d\n",
   single_char, test_string, first(single_char, test_string));
 printf("Count of character %c in test-string \"%s\": %d\n", single_char,
   test_string, count(single_char, test_string));
 printf("Longest word of test-string \"%s\" is at index: %d\n", test_string,
   longest(test_string));
 printf("Character distribution in \"%s\":\n", test_string);
 print_char_distr(test_string);
 printf("When substituting %c with %c, you have to do %d substitutions.\n",
   'o', 'a', substitute('o', 'a', test_string));
 printf("The string is now \"%s\"\n", test_string);
 printf("Let us convert \"%s\" to lower case.\n", test_string);
 printf("When converting to lower case, %d chars have to be replaced\n",
   str_to_lower(test_string));
 printf("The string is now \"%s\"\n", test_string);
 printf("Result of comparison: %d\n",
   cmp_strings(test_string, another_string));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
_QWORD *init_list()
{
_QWORD *v0; // r12
_QWORD *v1; // rbx
_QWORD *v2; // rax
_QWORD *result; // rax

v0 = malloc(0x10uLL);
v1 = malloc(0x10uLL);
v2 = malloc(0x10uLL);
v0[1] = v1;
*(_DWORD *)v2 = 3;
v2[1] = 0LL;
v1[1] = v2;
result = v0;
*(_DWORD *)v0 = 1;
*(_DWORD *)v1 = 2;
return result;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // r12
_QWORD *v1; // rbx
_QWORD *v2; // rax
_QWORD *result; // rax

v0 = malloc(0x10uLL);
v1 = malloc(0x10uLL);
v2 = malloc(0x10uLL);
v0[1] = v1;
*(_DWORD *)v2 = 3;
v2[1] = 0LL;
v1[1] = v2;
result = v0;
*(_DWORD *)v0 = 1;
*(_DWORD *)v1 = 2;
return result;
}

original_code:
lnode* init_list() {
 lnode *first = malloc(sizeof(lnode));
 lnode *second = malloc(sizeof(lnode));
 lnode *third = malloc(sizeof(lnode));
 first->data = 1;
 first->next = second;
 (*second).data = 2;
 (*second).next = third;
 third->data = 3;
 third->next = ((void *)0);
 return first;
}

canonical_original_code:
struct node *init_list() {
 struct node *first = malloc(sizeof(lnode));
 struct node *second = malloc(sizeof(lnode));
 struct node *third = malloc(sizeof(lnode));
 first->data = 1;
 first->next = second;
 (*second).data = 2;
 (*second).next = third;
 third->data = 3;
 third->next = ((void *)0);
 return first;
}

variable_types: struct node { int data; struct node *next; } *


nodelen

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 8);
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
int nodelen(lnode* list) {
 int len = 0;
 lnode *cur = list;
 while (cur != ((void *)0)) {
  len++;
  cur = cur->next;
 }
 return len;
}

canonical_original_code:
int nodelen(struct node *list) {
 int len = 0;
 struct node *cur = list;
 while (cur != ((void *)0)) {
  len++;
  cur = cur->next;
 }
 return len;
}

user_defined_types: struct node { int data; struct node *next; }


reclen

decompiled_code:
__int64 __fastcall reclen(__int64 a1)
{
int v1; // eax
unsigned int v2; // er8

if ( !a1 )
return 0LL;
v1 = 1;
do
{
a1 = *(_QWORD *)(a1 + 8);
v2 = v1++;
}
while ( a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int v1; // eax
unsigned int v2; // er8

if ( !a1 )
return 0LL;
v1 = 1;
do
{
a1 = *(_QWORD *)(a1 + 8);
v2 = v1++;
}
while ( a1 );
return v2;
}

original_code:
int reclen(lnode* n) {
 return n ? 1 + reclen(n->next) : 0;
}

canonical_original_code:
int reclen(struct node *n) {
 return n ? 1 + reclen(n->next) : 0;
}


printlist

decompiled_code:
int __fastcall printlist(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
printf("%d ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
printf("%d ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
return putchar(10);
}

original_code:
void printlist(lnode* head) {
 lnode *current = head;
 while (current != ((void *)0)) {
  printf("%d ", current->data);
  current = current->next;
 }
 printf("\n");
}

canonical_original_code:
void printlist(struct node *head) {
 struct node *current = head;
 while (current != ((void *)0)) {
  printf("%d ", current->data);
  current = current->next;
 }
 printf("\n");
}


pop

decompiled_code:
__int64 __fastcall pop(unsigned int **a1)
{
unsigned int *v1; // r8
unsigned int v2; // er12

v1 = *a1;
v2 = **a1;
*a1 = (unsigned int *)*((_QWORD *)*a1 + 1);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int **a1)
{
unsigned int *v1; // r8
unsigned int v2; // er12

v1 = *a1;
v2 = **a1;
*a1 = (unsigned int *)*((_QWORD *)*a1 + 1);
free(v1);
return v2;
}

original_code:
int pop(lnode** list) {
 lnode *temp = *list;
 int ret = (*list)->data;
 *list = temp->next;
 free(temp);
 return ret;
}

canonical_original_code:
int pop(struct node **list) {
 struct node *temp = *list;
 int ret = (*list)->data;
 *list = temp->next;
 free(temp);
 return ret;
}

variable_types: struct node { int data; struct node *next; } **

variable_types: ret int


decompiled_code:
__int64 __fastcall get_nth(__int64 *a1, int a2)
{
_QWORD *v2; // rdx
int i; // eax

if ( (int)nodelen(*a1) <= a2 )
return 0xFFFFFFFFLL;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
v2 = (_QWORD *)v2[1];
}
return *(unsigned int *)v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, int a2)
{
_QWORD *v2; // rdx
int i; // eax

if ( (int)func8(*a1) <= a2 )
return 0xFFFFFFFFLL;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
v2 = (_QWORD *)v2[1];
}
return *(unsigned int *)v2;
}

original_code:
int get_nth(lnode** list, int n) {
 if (n >= nodelen(*list))
  return -1;
 lnode* p = *list;
 int i;
 for (i = 0; i < n; i++) {
  p = p->next;
 }
 return p->data;
}

canonical_original_code:
int get_nth(struct node **list, int n) {
 if (n >= nodelen(*list))
  return -1;
 struct node *p = *list;
 int i;
 for (i = 0; i < n; i++) {
  p = p->next;
 }
 return p->data;
}

variable_types: n int


append

decompiled_code:
__int64 __fastcall append(__int64 *a1, __int64 *a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

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

original_code:
void append(lnode** listref_a, lnode** listref_b) {
 lnode *cur = *listref_a;
 while (cur->next != ((void *)0)) {
  cur = cur->next;
 }
 cur->next = *listref_b;
}

canonical_original_code:
void append(struct node **listref_a, struct node **listref_b) {
 struct node *cur = *listref_a;
 while (cur->next != ((void *)0)) {
  cur = cur->next;
 }
 cur->next = *listref_b;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
__int64 v6; // r8
unsigned int v7; // eax
__int64 v8; // rdx
__int64 v10; // [rsp+0h] [rbp-18h] BYREF
__int64 v11; // [rsp+8h] [rbp-10h] BYREF

v10 = init_list(argc, argv, envp);
printlist(v10);
v3 = nodelen(v10);
printf("nodelen=%i\n", v3);
v4 = reclen(v10);
printf("reclen=%i\n", v4);
push(4LL, &v10);
printlist(v10);
push(5LL, &v10);
push(6LL, &v10);
printlist(v10);
while ( (int)nodelen(v10) > 3 )
{
v5 = pop(&v10);
printf("pop()=%i\n", v5);
}
printlist(v6);
v7 = get_nth(&v10, 2LL);
printf("get_nth(index 2) = %i\n", v7);
printlist(v10);
delete_list(&v10);
printf("List should now be empty: ");
printlist(v10);
push(1LL, &v10);
push(2LL, &v10);
push(3LL, &v10);
push(5LL, &v10);
printf("List is now filled again: ");
printlist(v10);
insert_nth(&v10, 1LL, 4LL);
printlist(v10);
printf("Created a new list: ");
v11 = init_list("Created a new list: ", 1LL, v8);
printlist(v11);
append(&v10, &v11);
printf("Appended the new list to the old list: ");
printlist(v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
__int64 v6; // r8
unsigned int v7; // eax
__int64 v8; // rdx
__int64 v10; // [rsp+0h] [rbp-18h] BYREF
__int64 v11; // [rsp+8h] [rbp-10h] BYREF

v10 = func7(argc, argv, envp);
func10(v10);
v3 = func8(v10);
printf("nodelen=%i\n", v3);
v4 = func9(v10);
printf("reclen=%i\n", v4);
push(4LL, &v10);
func10(v10);
push(5LL, &v10);
push(6LL, &v10);
func10(v10);
while ( (int)func8(v10) > 3 )
{
v5 = func11(&v10);
printf("pop()=%i\n", v5);
}
func10(v6);
v7 = func12(&v10, 2LL);
printf("get_nth(index 2) = %i\n", v7);
func10(v10);
func13(&v10);
printf("List should now be empty: ");
func10(v10);
push(1LL, &v10);
push(2LL, &v10);
push(3LL, &v10);
push(5LL, &v10);
printf("List is now filled again: ");
func10(v10);
insert_nth(&v10, 1LL, 4LL);
func10(v10);
printf("Created a new list: ");
v11 = func7("Created a new list: ", 1LL, v8);
func10(v11);
func14(&v10, &v11);
printf("Appended the new list to the old list: ");
func10(v10);
return 0;
}

original_code:
int main(void) {
 lnode *head = init_list();
 printlist(head);
 printf("nodelen=%i\n", nodelen(head));
 printf("reclen=%i\n", reclen(head));
 lnode **list = &head;
 push(4, list);
 printlist(*list);
 push(5, list);
 push(6, list);
 printlist(*list);
 while (nodelen(head) > 3) {
  printf("pop()=%i\n", pop(list));
 }
 printlist(*list);
 printf("get_nth(index 2) = %i\n", get_nth(list, 2));
 printlist(*list);
 delete_list(list);
 printf("List should now be empty: ");
 printlist(*list);
 push(1, list);
 push(2, list);
 push(3, list);
 push(5, list);
 printf("List is now filled again: ");
 printlist(*list);
 insert_nth(list, 1, 4);
 printlist(*list);
 printf("Created a new list: ");
 lnode* listb = init_list();
 printlist(listb);
 append(list, &listb);
 printf("Appended the new list to the old list: ");
 printlist(*list);
 return 0;
}

canonical_original_code:
int main() {
 struct node *head = init_list();
 printlist(head);
 printf("nodelen=%i\n", nodelen(head));
 printf("reclen=%i\n", reclen(head));
 struct node **list = &head;
 push(4, list);
 printlist(*list);
 push(5, list);
 push(6, list);
 printlist(*list);
 while (nodelen(head) > 3) {
  printf("pop()=%i\n", pop(list));
 }
 printlist(*list);
 printf("get_nth(index 2) = %i\n", get_nth(list, 2));
 printlist(*list);
 delete_list(list);
 printf("List should now be empty: ");
 printlist(*list);
 push(1, list);
 push(2, list);
 push(3, list);
 push(5, list);
 printf("List is now filled again: ");
 printlist(*list);
 insert_nth(list, 1, 4);
 printlist(*list);
 printf("Created a new list: ");
 struct node *listb = init_list();
 printlist(listb);
 append(list, &listb);
 printf("Appended the new list to the old list: ");
 printlist(*list);
 return 0;
}


swap

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

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

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

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void swap(int *x, int *y)
{
 int tmp;
 tmp = *x;
 *x = *y;
 *y = tmp;
}

variable_types:
x
int *

variable_types:
y
int *

variable_types: tmp int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4 = 2;
v5[0] = 5;
printf("Variable x: %i, Variable y: %i\n", 2LL, 5LL);
swap(&v4, v5);
printf("Variable x: %i, Variable y: %i\n", v4, v5[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4 = 2;
v5[0] = 5;
printf("Variable x: %i, Variable y: %i\n", 2LL, 5LL);
func7(&v4, v5);
printf("Variable x: %i, Variable y: %i\n", v4, v5[0]);
return 0;
}

original_code:
int main()
{
 int x = 2, y = 5;
 printf("Variable x: %i, Variable y: %i\n", x, y);
 swap(&x, &y);
 printf("Variable x: %i, Variable y: %i\n", x, y);
 return 0;
}

canonical_original_code:
int main()
{
 int x = 2; int y = 5;
 printf("Variable x: %i, Variable y: %i\n", x, y);
 swap(&x, &y);
 printf("Variable x: %i, Variable y: %i\n", x, y);
 return 0;
}

variable_types: x int

variable_types: y int


repo: simonster/binica

decompiled_code:
__int64 __fastcall set_seed(__int64 a1)
{
seed_val = a1;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
seed_val = a1;
return a1;
}

original_code:
long set_seed(long int sd)
{
        return seed_val = sd;
}

canonical_original_code:
long set_seed(long sd)
{
        return seed_val = sd;
}

variable_types: sd long

return_type: long


decompiled_code:
__int64 get_seed()
{
return seed_val;
}

canonical_decompiled_code:
__int64 func1()
{
return seed_val;
}

original_code:
long get_seed()
{
        return seed_val;
}

canonical_original_code:
long get_seed()
{
        return seed_val;
}


randlcg

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

if ( seed_val > 0x1F31D2B36647FLL )
{
result = 16807 * (seed_val % 0x1F31D2B36647FLL) - 12838 * (seed_val / 0x1F31D2B36647FLL);
if ( result <= 0 )
result += 0x7FFFFFFFFFFFFFFFLL;
seed_val = result;
}
else
{
result = 16807 * seed_val % 0x7FFFFFFFFFFFFFFFLL;
seed_val = result;
}
return result;
}

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

if ( seed_val > 0x1F31D2B36647FLL )
{
result = 16807 * (seed_val % 0x1F31D2B36647FLL) - 12838 * (seed_val / 0x1F31D2B36647FLL);
if ( result <= 0 )
result += 0x7FFFFFFFFFFFFFFFLL;
seed_val = result;
}
else
{
result = 16807 * seed_val % 0x7FFFFFFFFFFFFFFFLL;
seed_val = result;
}
return result;
}

original_code:
unsigned long int randlcg()
{
        if ( seed_val <= quotient )
                seed_val = (seed_val * 16807L) % 0x7fffffffffffffffL;
        else
        {
                long int high_part = seed_val / quotient;
                long int low_part = seed_val % quotient;
                long int test = 16807L * low_part - remain * high_part;
                if ( test > 0 )
                        seed_val = test;
                else
                        seed_val = test + 0x7fffffffffffffffL;
        }
        return seed_val;
}

canonical_original_code:
unsigned long randlcg()
{
        if ( seed_val <= quotient )
                seed_val = (seed_val * 16807L) % 0x7fffffffffffffffL;
        else
        {
                long high_part = seed_val / quotient;
                long low_part = seed_val % quotient;
                long test = 16807L * low_part - remain * high_part;
                if ( test > 0 )
                        seed_val = test;
                else
                        seed_val = test + 0x7fffffffffffffffL;
        }
        return seed_val;
}

variable_types: test long

return_type: unsigned long


original_code:
doublereal dsum_(integer *n, doublereal *dx, integer *incx)
{
    integer i__1, i__2;
    doublereal ret_val, d__1, d__2, d__3, d__4, d__5, d__6;
    static integer i, m;
    static doublereal dtemp;
    static integer nincx, mp1;
    ret_val = 0.;
    dtemp = 0.;
    if (*n <= 0 || *incx <= 0) {
 return ret_val;
    }
    if (*incx == 1) {
 goto L20;
    }
    nincx = *n * *incx;
    i__1 = nincx;
    i__2 = *incx;
    for (i = 1; *incx < 0 ? i >= nincx : i <= nincx; i += *incx) {
 dtemp += (d__1 = dx[(i)-1], d__1);
    }
    ret_val = dtemp;
    return ret_val;
L20:
    m = *n % 6;
    if (m == 0) {
 goto L40;
    }
    i__2 = m;
    for (i = 1; i <= m; ++i) {
 dtemp += (d__1 = dx[(i)-1], d__1);
    }
    if (*n < 6) {
 goto L60;
    }
L40:
    mp1 = m + 1;
    i__2 = *n;
    for (i = mp1; i <= *n; i += 6) {
 dtemp = dtemp + (d__1 = dx[(i)-1], d__1) + (d__2 = dx[(i + 1)-1],
  d__2) + (d__3 = dx[(i + 2)-1], d__3) + (d__4 = dx[(i + 3)-1],
  d__4) + (d__5 = dx[(i + 4)-1], d__5) + (d__6 = dx[(i + 5)-1]
  , d__6);
    }
L60:
    ret_val = dtemp;
    return ret_val;
}

canonical_original_code:
double dsum_(long *n, double *dx, long *incx)
{
    long i__1; long i__2;
    double ret_val; double d__1; double d__2; double d__3; double d__4; double d__5; double d__6;
    static long i; static long m;
    static double dtemp;
    static long nincx; static long mp1;
    ret_val = 0.;
    dtemp = 0.;
    if (*n <= 0 || *incx <= 0) {
 return ret_val;
    }
    if (*incx == 1) {
 goto L20;
    }
    nincx = *n * *incx;
    i__1 = nincx;
    i__2 = *incx;
    for (i = 1; *incx < 0 ? i >= nincx : i <= nincx; i += *incx) {
 dtemp += (d__1 = dx[(i)-1], d__1);
    }
    ret_val = dtemp;
    return ret_val;
L20:
    m = *n % 6;
    if (m == 0) {
 goto L40;
    }
    i__2 = m;
    for (i = 1; i <= m; ++i) {
 dtemp += (d__1 = dx[(i)-1], d__1);
    }
    if (*n < 6) {
 goto L60;
    }
L40:
    mp1 = m + 1;
    i__2 = *n;
    for (i = mp1; i <= *n; i += 6) {
 dtemp = dtemp + (d__1 = dx[(i)-1], d__1) + (d__2 = dx[(i + 1)-1],
  d__2) + (d__3 = dx[(i + 2)-1], d__3) + (d__4 = dx[(i + 3)-1],
  d__4) + (d__5 = dx[(i + 4)-1], d__5) + (d__6 = dx[(i + 5)-1]
  , d__6);
    }
L60:
    ret_val = dtemp;
    return ret_val;
}

variable_types:
n
long *

variable_types:
dx
double *

variable_types:
incx
long *

variable_types: i long

variable_types: m long

variable_types: dtemp double

variable_types: nincx long

return_type: double


init

repo: simonxuxin/tools

decompiled_code:
int init()
{
char *v0; // rax
__int64 v1; // rdx
char *v2; // rax
__int64 v3; // rdx

v0 = getenv("FEXP_DELIMITER");
if ( v0 )
{
v1 = (unsigned int)*v0;
Delimiter = *v0;
}
else
{
v1 = (unsigned int)Delimiter;
}
fprintf(stdout, "**** OUTMOD Using delimiter character %c\n", v1);
v2 = getenv("FEXP_QUOTE");
if ( !v2 )
return fwrite("**** OUTMOD Fields will NOT be quoted\n", 1uLL, 0x26uLL, stdout);
v3 = (unsigned int)*v2;
Quote = *v2;
return fprintf(stdout, "**** OUTMOD Fields will be quoted using %c\n", v3);
}

canonical_decompiled_code:
int func6()
{
char *v0; // rax
__int64 v1; // rdx
char *v2; // rax
__int64 v3; // rdx

v0 = getenv("FEXP_DELIMITER");
if ( v0 )
{
v1 = (unsigned int)*v0;
Delimiter = *v0;
}
else
{
v1 = (unsigned int)Delimiter;
}
fprintf(stdout, "**** OUTMOD Using delimiter character %c\n", v1);
v2 = getenv("FEXP_QUOTE");
if ( !v2 )
return fwrite("**** OUTMOD Fields will NOT be quoted\n", 1uLL, 0x26uLL, stdout);
v3 = (unsigned int)*v2;
Quote = *v2;
return fprintf(stdout, "**** OUTMOD Fields will be quoted using %c\n", v3);
}

original_code:
void init (void) {
        char *env;
        if(env = getenv("FEXP_DELIMITER")) {
                Delimiter = *env;
        }
        fprintf(stdout, "**** OUTMOD Using delimiter character %c\n", Delimiter);
        if(env = getenv("FEXP_QUOTE")) {
                Quote = *env;
                fprintf(stdout, "**** OUTMOD Fields will be quoted using %c\n", Quote);
        } else {
                fprintf(stdout, "**** OUTMOD Fields will NOT be quoted\n");
        }
        return;
}

canonical_original_code:
void init() {
        char *env;
        if(env = getenv("FEXP_DELIMITER")) {
                Delimiter = *env;
        }
        fprintf(stdout, "**** OUTMOD Using delimiter character %c\n", Delimiter);
        if(env = getenv("FEXP_QUOTE")) {
                Quote = *env;
                fprintf(stdout, "**** OUTMOD Fields will be quoted using %c\n", Quote);
        } else {
                fprintf(stdout, "**** OUTMOD Fields will NOT be quoted\n");
        }
        return;
}

variable_types:
env
char *


replace

decompiled_code:
void __fastcall replace(_BYTE *a1, int a2, const char *a3, char a4)
{
_BYTE *v6; // rbx

if ( a2 > 0 )
{
v6 = a1;
do
{
if ( strchr(a3, (char)*v6) )
*v6 = a4;
++v6;
}
while ( &a1[a2] != v6 );
}
}

canonical_decompiled_code:
void __fastcall func7(_BYTE *a1, int a2, const char *a3, char a4)
{
_BYTE *v6; // rbx

if ( a2 > 0 )
{
v6 = a1;
do
{
if ( strchr(a3, (char)*v6) )
*v6 = a4;
++v6;
}
while ( &a1[a2] != v6 );
}
}

original_code:
int replace(char *buf, int len, char *src, char tgt) {
  int i = 0;
  char *s = buf;
  while (i < len) {
    if (strchr(src, *s) != ((void *)0)) {
      *s = tgt;
    }
    i++;
    s++;
  }
}

variable_types:
buf
char *

variable_types: len int

variable_types:
src
char *

variable_types: tgt char

variable_types: i int

variable_types:
s
char *


process

decompiled_code:
__int64 __fastcall process(int *a1, unsigned __int16 *a2, unsigned int *a3, _BYTE *a4)
{
unsigned int v4; // er15
int v7; // er12
__int64 v8; // rdx

v4 = 0;
v7 = *a1;
do
{
if ( !v7 )
{
*a3 = v4;
return v4;
}
if ( *a1 != v7 )
{
++v4;
*a4++ = Delimiter;
}
if ( Quote )
{
*a4 = Quote;
++v4;
++a4;
}
memcpy(a4, a2 + 1, *a2);
replace();
v8 = *a2;
a2 = (unsigned __int16 *)((char *)a2 + v8 + 2);
a4 += v8;
v7 -= v8 + 2;
v4 += v8;
if ( Quote )
{
*a4 = Quote;
++v4;
++a4;
}
}
while ( v7 >= 0 );
v4 = 0;
fwrite("**** ERROR: Bad record encountered\n", 1uLL, 0x23uLL, stdout);
fwrite(" Please ensure that all fields in SQL are retrieved as VARCHAR\n", 1uLL, 0x43uLL, stdout);
fwrite(" and export command contains MODE RECORD FORMAT TEXT!\n", 1uLL, 0x3AuLL, stdout);
FoundError = 1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1, unsigned __int16 *a2, unsigned int *a3, _BYTE *a4)
{
unsigned int v4; // er15
int v7; // er12
__int64 v8; // rdx

v4 = 0;
v7 = *a1;
do
{
if ( !v7 )
{
*a3 = v4;
return v4;
}
if ( *a1 != v7 )
{
++v4;
*a4++ = Delimiter;
}
if ( Quote )
{
*a4 = Quote;
++v4;
++a4;
}
memcpy(a4, a2 + 1, *a2);
func7();
v8 = *a2;
a2 = (unsigned __int16 *)((char *)a2 + v8 + 2);
a4 += v8;
v7 -= v8 + 2;
v4 += v8;
if ( Quote )
{
*a4 = Quote;
++v4;
++a4;
}
}
while ( v7 >= 0 );
v4 = 0;
fwrite("**** ERROR: Bad record encountered\n", 1uLL, 0x23uLL, stdout);
fwrite(" Please ensure that all fields in SQL are retrieved as VARCHAR\n", 1uLL, 0x43uLL, stdout);
fwrite(" and export command contains MODE RECORD FORMAT TEXT!\n", 1uLL, 0x3AuLL, stdout);
FoundError = 1;
return v4;
}

original_code:
int process(int *InLen, char *InBuf, int *OutLen, char *OutBuf) {
        char *from_col = InBuf, *to_col = OutBuf;
        Int16 *col_len;
        int in_len = *InLen, out_len = 0;
        while(in_len) {
                if(in_len != *InLen) {
                        *to_col++ = Delimiter;
                        out_len++;
                }
                if(Quote) {
                        *to_col++ = Quote;
                        out_len++;
                }
                col_len = (Int16*)from_col;
                memcpy(to_col, from_col+2, *col_len);
                replace(to_col, *col_len, "\n\x00", ' ');
                from_col += *col_len + 2;
                in_len -= *col_len + 2;
                to_col += *col_len;
                out_len += *col_len;
                if(Quote) {
                        *to_col++ = Quote;
                        out_len++;
                }
                if (in_len < 0) {
                    fprintf(stdout, "**** ERROR: Bad record encountered\n");
                    fprintf(stdout, "     Please ensure that all fields in SQL are retrieved as VARCHAR\n");
                    fprintf(stdout, "     and export command contains MODE RECORD FORMAT TEXT!\n");
                    FoundError = 1;
                    return(0);
                }
        }
        *OutLen = out_len;
        return(out_len);
}

canonical_original_code:
int process(int *InLen, char *InBuf, int *OutLen, char *OutBuf) {
        char *from_col = InBuf; char *to_col = OutBuf;
        unsigned short *col_len;
        int in_len = *InLen; int out_len = 0;
        while(in_len) {
                if(in_len != *InLen) {
                        *to_col++ = Delimiter;
                        out_len++;
                }
                if(Quote) {
                        *to_col++ = Quote;
                        out_len++;
                }
                col_len = (unsigned short *)from_col;
                memcpy(to_col, from_col+2, *col_len);
                replace(to_col, *col_len, "\n\x00", ' ');
                from_col += *col_len + 2;
                in_len -= *col_len + 2;
                to_col += *col_len;
                out_len += *col_len;
                if(Quote) {
                        *to_col++ = Quote;
                        out_len++;
                }
                if (in_len < 0) {
                    fprintf(stdout, "**** ERROR: Bad record encountered\n");
                    fprintf(stdout, "     Please ensure that all fields in SQL are retrieved as VARCHAR\n");
                    fprintf(stdout, "     and export command contains MODE RECORD FORMAT TEXT!\n");
                    FoundError = 1;
                    return(0);
                }
        }
        *OutLen = out_len;
        return(out_len);
}

variable_types:
InLen
int *

variable_types:
InBuf
char *

variable_types:
OutLen
int *

variable_types:
OutBuf
char *


main

repo: simpkins/ncsvc-wrapper

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

if ( argv[argc] )
errx(1, "argv is not NULL terminated", envp);
v3 = (char *const *)update_env(envp, "/.juniper_networks/network_connect/rtwrap/librtwrap.so");
setreuid(0, 0);
setregid(0, 0);
execve("/.juniper_networks/network_connect/rtwrap/ncsvc.orig", (char *const *)argv, v3);
err(1, "execve failed");
}

original_code:
int
main(int argc, char *argv[], char *envp[])
{
    char **new_env;
    if (argv[argc] != ((void *)0))
        errx(1, "argv is not NULL terminated");
    new_env = update_env(envp, "/.juniper_networks/network_connect/rtwrap" "/librtwrap.so");
    setreuid(0, 0);
    setregid(0, 0);
    execve("/.juniper_networks/network_connect/rtwrap" "/ncsvc.orig", argv, new_env);
    err(1, "execve failed");
    return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
envp
char *[]


startswith

decompiled_code:
bool __fastcall startswith(char *s1, char *s2)
{
size_t v2; // rax

v2 = strlen(s2);
return strncmp(s1, s2, v2) == 0;
}

canonical_decompiled_code:
bool __fastcall func7(char *s1, char *s2)
{
size_t v2; // rax

v2 = strlen(s2);
return strncmp(s1, s2, v2) == 0;
}

original_code:
_Bool
startswith(char const *haystack, char const *needle)
{
    return (strncmp(haystack, needle, strlen(needle)) == 0);
}

canonical_original_code:
_Bool startswith(char *haystack, char *needle)
{
    return (strncmp(haystack, needle, strlen(needle)) == 0);
}

variable_types:
haystack
char *

variable_types:
needle
char *


repo: singpolyma/mnemonicode

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

v1 = 3 * a1 + 6;
if ( 3 * a1 + 3 >= 0 )
v1 = 3 * a1 + 3;
return (unsigned int)(v1 >> 2);
}

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

v1 = 3 * a1 + 6;
if ( 3 * a1 + 3 >= 0 )
v1 = 3 * a1 + 3;
return (unsigned int)(v1 >> 2);
}

original_code:
int
mn_words_required (int size)
{
  return ((size + 1) * 3) / 4;
}

canonical_original_code:
int mn_words_required(int size)
{
  return ((size + 1) * 3) / 4;
}

variable_types: size int


original_code:
mn_index mn_encode_word_index (void *vsrc, int srcsize, int n)
{
  mn_word32 x = 0;
  int offset;
  int remaining;
  int extra = 0;
  int i;
  mn_byte *src = vsrc;
  if (n < 0 || n >= mn_words_required (srcsize))
    return 0;
  offset = (n / 3) * 4;
  remaining = srcsize - offset;
  if (remaining <= 0)
    return 0;
  if (remaining >= 4)
    remaining = 4;
  for (i = 0; i < remaining; i++)
    x |= (unsigned long)src[offset + i] << (i * 8);
  switch (n % 3)
    {
    case 2:
      if (remaining == 3)
 extra = 1626;
      x /= (1626 * 1626);
      break;
    case 1:
      x /= 1626;
    }
  return x % 1626 + extra + 1;
}

canonical_original_code:
unsigned int mn_encode_word_index(void *vsrc, int srcsize, int n)
{
  unsigned long x = 0;
  int offset;
  int remaining;
  int extra = 0;
  int i;
  unsigned char *src = vsrc;
  if (n < 0 || n >= mn_words_required (srcsize))
    return 0;
  offset = (n / 3) * 4;
  remaining = srcsize - offset;
  if (remaining <= 0)
    return 0;
  if (remaining >= 4)
    remaining = 4;
  for (i = 0; i < remaining; i++)
    x |= (unsigned long)src[offset + i] << (i * 8);
  switch (n % 3)
    {
    case 2:
      if (remaining == 3)
 extra = 1626;
      x /= (1626 * 1626);
      break;
    case 1:
      x /= 1626;
    }
  return x % 1626 + extra + 1;
}

variable_types:
vsrc
void *

variable_types: srcsize int

variable_types: n int

variable_types:
x
unsigned long

variable_types: offset int

variable_types: remaining int

variable_types: extra int

variable_types:
src
unsigned char *

return_type: unsigned int


decompiled_code:
char *__fastcall mn_encode_word(__int64 a1, int a2, int a3)
{
return (&mn_words)[(unsigned int)mn_encode_word_index(a1, a2, a3)];
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1, int a2, int a3)
{
return (&mn_words)[(unsigned int)func8(a1, a2, a3)];
}

original_code:
const char *
mn_encode_word (void *src, int srcsize, int n)
{
  return mn_words[mn_encode_word_index (src, srcsize, n)];
}

canonical_original_code:
char *mn_encode_word(void *src, int srcsize, int n)
{
  return mn_words[mn_encode_word_index (src, srcsize, n)];
}

variable_types:
src
void *

return_type: char *


original_code:
mn_index
mn_next_word_index (char **ptr)
{
  char *wordstart;
  char wordbuf[25];
  int i = 0;
  char c;
  mn_index idx;
  while (**ptr && !((*__ctype_b_loc ())[(int) ((**ptr))] & (unsigned short int) _ISalpha))
    (*ptr)++;
  wordstart = *ptr;
  while (**ptr && ((*__ctype_b_loc ())[(int) ((**ptr))] & (unsigned short int) _ISalpha) && i < 25 - 1)
    {
      c = *(*ptr)++;
      if (c >= 'A' && c <= 'Z')
 c += 'a' - 'A';
      wordbuf[i++] = c;
    }
  wordbuf[i] = '\0';
  while (**ptr && ((*__ctype_b_loc ())[(int) ((**ptr))] & (unsigned short int) _ISalpha))
    (*ptr)++;
  while (**ptr && !((*__ctype_b_loc ())[(int) ((**ptr))] & (unsigned short int) _ISalpha))
    (*ptr)++;
  if (wordbuf[0] == '\0')
    return 0;
  for (idx = 1; idx <= (1626 +7); idx++)
    {
      if (!strcmp (wordbuf, mn_words[idx]))
 return idx;
    }
  *ptr = wordstart;
  return 0;
}

canonical_original_code:
unsigned int mn_next_word_index(char **ptr)
{
  char *wordstart;
  char wordbuf[25];
  int i = 0;
  char c;
  unsigned int idx;
  while (**ptr && !((*__ctype_b_loc ())[(int) ((**ptr))] & (unsigned short) _ISalpha))
    (*ptr)++;
  wordstart = *ptr;
  while (**ptr && ((*__ctype_b_loc ())[(int) ((**ptr))] & (unsigned short) _ISalpha) && i < 25 - 1)
    {
      c = *(*ptr)++;
      if (c >= 'A' && c <= 'Z')
 c += 'a' - 'A';
      wordbuf[i++] = c;
    }
  wordbuf[i] = '\0';
  while (**ptr && ((*__ctype_b_loc ())[(int) ((**ptr))] & (unsigned short) _ISalpha))
    (*ptr)++;
  while (**ptr && !((*__ctype_b_loc ())[(int) ((**ptr))] & (unsigned short) _ISalpha))
    (*ptr)++;
  if (wordbuf[0] == '\0')
    return 0;
  for (idx = 1; idx <= (1626 +7); idx++)
    {
      if (!strcmp (wordbuf, mn_words[idx]))
 return idx;
    }
  *ptr = wordstart;
  return 0;
}

variable_types:
ptr
char **

variable_types:
wordstart
char *

variable_types:
wordbuf
char [25]

variable_types: i int

variable_types: c char

variable_types:
idx
unsigned int


original_code:
int
mn_decode_word_index (mn_index index, void *vdest, int destsize, int *offset)
{
  mn_word32 x;
  int groupofs;
  int i;
  mn_byte *dest = vdest;
  if (*offset < 0)
    return *offset;
  if (index > (1626 +7))
    {
      *offset = -4;
      return *offset;
    }
  if (*offset > destsize)
    {
      *offset = -2;
      return *offset;
    }
  if (index > 1626 && *offset % 4 != 2)
    {
      *offset = -5;
      return *offset;
    }
  groupofs = *offset & ~3;
  x = 0;
  for (i = 0; i < 4; i++)
    if (groupofs + i < destsize)
      x |= (unsigned long)dest[groupofs + i] << (i * 8);
  if (index == 0)
    {
      switch (*offset % 4)
 {
 case 3:
   return 0;
 case 2:
   if (x <= 0xFFFF)
     return 0;
   else
     {
       *offset = -1;
       return *offset;
     }
 case 1:
   if (x <= 0xFF)
     return 0;
   else
     {
       *offset = -1;
       return *offset;
     }
 case 0:
   return 0;
 }
    }
  if (*offset == destsize)
    {
      *offset = -2;
      return *offset;
    }
  index--;
  switch (*offset % 4)
    {
    case 3:
      *offset = -3;
      return *offset;
    case 2:
      if (index >= 1626)
 {
   x += (index - 1626) * 1626 * 1626;
   (*offset)++;
 }
      else
 {
   if (index >= 1625 || (index == 1624 && x > 1312671))
     {
       *offset = -6;
       return *offset;
     }
   x += index * 1626 * 1626;
   (*offset) += 2;
 }
      break;
    case 1:
      x += index * 1626;
      (*offset)++;
      break;
    case 0:
      x = index;
      (*offset)++;
      break;
    }
  for (i = 0; i < 4; i++)
    if (groupofs + i < destsize)
      {
 dest[groupofs + i] = (mn_byte) x % 256;
 x /= 256;
      }
  return 0;
}

canonical_original_code:
int mn_decode_word_index(unsigned int index, void *vdest, int destsize, int *offset)
{
  unsigned long x;
  int groupofs;
  int i;
  unsigned char *dest = vdest;
  if (*offset < 0)
    return *offset;
  if (index > (1626 +7))
    {
      *offset = -4;
      return *offset;
    }
  if (*offset > destsize)
    {
      *offset = -2;
      return *offset;
    }
  if (index > 1626 && *offset % 4 != 2)
    {
      *offset = -5;
      return *offset;
    }
  groupofs = *offset & ~3;
  x = 0;
  for (i = 0; i < 4; i++)
    if (groupofs + i < destsize)
      x |= (unsigned long)dest[groupofs + i] << (i * 8);
  if (index == 0)
    {
      switch (*offset % 4)
 {
 case 3:
   return 0;
 case 2:
   if (x <= 0xFFFF)
     return 0;
   else
     {
       *offset = -1;
       return *offset;
     }
 case 1:
   if (x <= 0xFF)
     return 0;
   else
     {
       *offset = -1;
       return *offset;
     }
 case 0:
   return 0;
 }
    }
  if (*offset == destsize)
    {
      *offset = -2;
      return *offset;
    }
  index--;
  switch (*offset % 4)
    {
    case 3:
      *offset = -3;
      return *offset;
    case 2:
      if (index >= 1626)
 {
   x += (index - 1626) * 1626 * 1626;
   (*offset)++;
 }
      else
 {
   if (index >= 1625 || (index == 1624 && x > 1312671))
     {
       *offset = -6;
       return *offset;
     }
   x += index * 1626 * 1626;
   (*offset) += 2;
 }
      break;
    case 1:
      x += index * 1626;
      (*offset)++;
      break;
    case 0:
      x = index;
      (*offset)++;
      break;
    }
  for (i = 0; i < 4; i++)
    if (groupofs + i < destsize)
      {
 dest[groupofs + i] = (unsigned char) x % 256;
 x /= 256;
      }
  return 0;
}

variable_types:
index
unsigned int

variable_types:
vdest
void *

variable_types: destsize int

variable_types:
offset
int *

variable_types: groupofs int

variable_types:
dest
unsigned char *


original_code:
int
mn_encode (void *src, int srcsize, char *dest, int destsize, char *format)
{
  int n;
  char *fmt;
  char *destend = dest + destsize;
  const char *word;
  if (format == 0 || format[0] == '\0')
    format = "x-x-x--";
  fmt = format;
  for (n = 0; n < mn_words_required (srcsize); n++)
    {
      while (dest < destend && *fmt != '\0' && !((*__ctype_b_loc ())[(int) ((*fmt))] & (unsigned short int) _ISalpha))
 *dest++ = *fmt++;
      if (dest >= destend)
 return -2;
      if (*fmt == '\0')
 {
   if (((*__ctype_b_loc ())[(int) ((fmt[-1]))] & (unsigned short int) _ISalpha) && ((*__ctype_b_loc ())[(int) ((format[0]))] & (unsigned short int) _ISalpha))
     return -8;
   fmt = format;
   while (dest < destend && *fmt != '\0' && !((*__ctype_b_loc ())[(int) ((*fmt))] & (unsigned short int) _ISalpha))
     *dest++ = *fmt++;
   if (!((*__ctype_b_loc ())[(int) ((*fmt))] & (unsigned short int) _ISalpha))
     return -8;
 }
      word = mn_encode_word (src, srcsize, n);
      if (word == 0)
 return -2;
      while (((*__ctype_b_loc ())[(int) ((*fmt))] & (unsigned short int) _ISalpha))
 fmt++;
      while (dest < destend && *word != '\0')
 *dest++ = *word++;
    }
  if (dest < destend)
    *dest++ = '\0';
  else
    return -2;
  return 0;
}

canonical_original_code:
int mn_encode(void *src, int srcsize, char *dest, int destsize, char *format)
{
  int n;
  char *fmt;
  char *destend = dest + destsize;
  char *word;
  if (format == 0 || format[0] == '\0')
    format = "x-x-x--";
  fmt = format;
  for (n = 0; n < mn_words_required (srcsize); n++)
    {
      while (dest < destend && *fmt != '\0' && !((*__ctype_b_loc ())[(int) ((*fmt))] & (unsigned short) _ISalpha))
 *dest++ = *fmt++;
      if (dest >= destend)
 return -2;
      if (*fmt == '\0')
 {
   if (((*__ctype_b_loc ())[(int) ((fmt[-1]))] & (unsigned short) _ISalpha) && ((*__ctype_b_loc ())[(int) ((format[0]))] & (unsigned short) _ISalpha))
     return -8;
   fmt = format;
   while (dest < destend && *fmt != '\0' && !((*__ctype_b_loc ())[(int) ((*fmt))] & (unsigned short) _ISalpha))
     *dest++ = *fmt++;
   if (!((*__ctype_b_loc ())[(int) ((*fmt))] & (unsigned short) _ISalpha))
     return -8;
 }
      word = mn_encode_word (src, srcsize, n);
      if (word == 0)
 return -2;
      while (((*__ctype_b_loc ())[(int) ((*fmt))] & (unsigned short) _ISalpha))
 fmt++;
      while (dest < destend && *word != '\0')
 *dest++ = *word++;
    }
  if (dest < destend)
    *dest++ = '\0';
  else
    return -2;
  return 0;
}

variable_types: srcsize int

variable_types:
dest
char *

variable_types:
format
char *

variable_types: n int

variable_types:
fmt
char *

variable_types:
destend
char *

variable_types:
word
char *


decompiled_code:
__int64 __fastcall mn_decode(_BYTE *a1, __int64 a2, int a3)
{
unsigned int v4; // edi
__int64 result; // rax
_BYTE *v6; // [rsp+8h] [rbp-30h] BYREF
int v7[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v6 = a1;
v7[0] = 0;
while ( 1 )
{
v4 = mn_next_word_index((__int64 *)&v6);
if ( !v4 )
break;
mn_decode_word_index(v4, a2, a3, v7);
}
if ( *v6 )
return 4294967289LL;
result = mn_decode_word_index(0, a2, a3, v7);
if ( (int)result >= 0 )
result = (unsigned int)v7[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_BYTE *a1, __int64 a2, int a3)
{
unsigned int v4; // edi
__int64 result; // rax
_BYTE *v6; // [rsp+8h] [rbp-30h] BYREF
int v7[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v6 = a1;
v7[0] = 0;
while ( 1 )
{
v4 = func10((__int64 *)&v6);
if ( !v4 )
break;
func11(v4, a2, a3, v7);
}
if ( *v6 )
return 4294967289LL;
result = func11(0, a2, a3, v7);
if ( (int)result >= 0 )
result = (unsigned int)v7[0];
return result;
}

original_code:
int
mn_decode (char *src, void *dest, int destsize)
{
  mn_index index;
  int offset = 0;
  int status;
  while ((index = mn_next_word_index (&src)) != 0)
    {
      (void) mn_decode_word_index (index, dest, destsize, &offset);
    }
  if (*src != 0)
    return -7;
  status = mn_decode_word_index (0, dest, destsize, &offset);
  if (status < 0)
    return status;
  return offset;
}

canonical_original_code:
int mn_decode(char *src, void *dest, int destsize)
{
  unsigned int index;
  int offset = 0;
  int status;
  while ((index = mn_next_word_index (&src)) != 0)
    {
      (void) mn_decode_word_index (index, dest, destsize, &offset);
    }
  if (*src != 0)
    return -7;
  status = mn_decode_word_index (0, dest, destsize, &offset);
  if (status < 0)
    return status;
  return offset;
}

variable_types:
src
char *

variable_types:
dest
void *

variable_types: offset int

variable_types: status int


decompiled_code:
void re_init()
{
is_init = 0;
iset = 0;
gset = 0;
}

canonical_decompiled_code:
void func7()
{
is_init = 0;
iset = 0;
gset = 0;
}


rexp

decompiled_code:
float __fastcall rexp(float a1)
{
float v1; // xmm0_4

v1 = _nrand();
return (float)-(float)(1.0 / a1) * log(v1);
}

canonical_decompiled_code:
float __fastcall func9(float a1)
{
float v1; // xmm0_4

v1 = func8();
return (float)-(float)(1.0 / a1) * log(v1);
}

original_code:
float rexp(float __lambda) {
 return -((float)(1.0) / __lambda) * log(__nrand());
}

return_type: float


normal

original_code:
float normal(float mu, float sigma) {
 float u,v,rsq, fac;
 if (iset == 0) {
  do {
   u = (2.0 * ((float) rand() / (float) 2147483647)) - 1.0;
   v = (2.0 * ((float) rand() / (float) 2147483647)) - 1.0;
   rsq = u*u + v*v;
  }
  while (rsq >= 1.0 || rsq == 0.0);
  fac = sqrtf(-2.0 * logf(rsq) / rsq);
  gset = mu + (sigma * (u * fac));
  iset = 1 ;
  return mu + (sigma * (v * fac));
 }
 else {
  iset = 0;
  return gset;
 }
}

canonical_original_code:
float normal(float mu, float sigma) {
 float u; float v; float rsq; float fac;
 if (iset == 0) {
  do {
   u = (2.0 * ((float) rand() / (float) 2147483647)) - 1.0;
   v = (2.0 * ((float) rand() / (float) 2147483647)) - 1.0;
   rsq = u*u + v*v;
  }
  while (rsq >= 1.0 || rsq == 0.0);
  fac = sqrtf(-2.0 * logf(rsq) / rsq);
  gset = mu + (sigma * (u * fac));
  iset = 1 ;
  return mu + (sigma * (v * fac));
 }
 else {
  iset = 0;
  return gset;
 }
}

variable_types: mu float

variable_types: sigma float

variable_types: u float

variable_types: v float

variable_types: rsq float

variable_types: fac float


lognormal

decompiled_code:
void __fastcall lognormal(float x, float a2)
{
normal(x, a2);
expf(x);
}

canonical_decompiled_code:
void __fastcall func11(float x, float a2)
{
func10(x, a2);
expf(x);
}

original_code:
float lognormal(float mu, float sigma) {
 return expf(normal(mu, sigma));
}


decompiled_code:
int graph_init()
{
fp = fopen(path, "w+");
if ( !fp )
{
puts("File Cretion error");
exit(1);
}
return chmod(path, 0x1C0u);
}

canonical_decompiled_code:
int func12()
{
fp = fopen(path, "w+");
if ( !fp )
{
puts("File Cretion error");
exit(1);
}
return chmod(path, 0x1C0u);
}

original_code:
void graph_init() {
 fp = fopen(path, "w+");
 if (fp == ((void *)0)) {
  printf("File Cretion error\n");
  exit(1);
 }
 chmod(path, (0400|0200|0100));
}


decompiled_code:
int __fastcall graph_new(char a1, __int64 a2, int a3, const char *a4)
{
__int64 v6; // rbx
double v7; // xmm0_8
__int64 v9; // rbx
double v10; // xmm0_8
__int64 v11; // rbx
double v12; // xmm0_8

if ( !fp )
graph_init();
switch ( a1 )
{
case 'L':
v6 = 0LL;
fwrite("line:", 1uLL, 5uLL, fp);
if ( a3 > 0 )
{
do
{
while ( 1 )
{
v7 = *(float *)(a2 + 4 * v6);
if ( a3 - 1 == (_DWORD)v6 )
break;
++v6;
fprintf(fp, "%f, ", v7);
if ( a3 == v6 )
return fprintf(fp, ":%s\n", a4);
}
++v6;
fprintf(fp, "%f", v7);
}
while ( a3 != v6 );
}
break;
case 'X':
v11 = 0LL;
fwrite("logx:", 1uLL, 5uLL, fp);
if ( a3 > 0 )
{
do
{
v12 = *(float *)(a2 + 4 * v11);
if ( a3 - 1 == (_DWORD)v11 )
fprintf(fp, "%f", v12);
else
fprintf(fp, "%f, ", v12);
++v11;
}
while ( v11 != a3 );
}
break;
case 'H':
v9 = 0LL;
fwrite("hist:", 1uLL, 5uLL, fp);
if ( a3 > 0 )
{
do
{
v10 = *(float *)(a2 + 4 * v9);
if ( a3 - 1 == (_DWORD)v9 )
fprintf(fp, "%f", v10);
else
fprintf(fp, "%f, ", v10);
++v9;
}
while ( a3 != v9 );
}
break;
default:
printf("Invalid Graph type");
exit(1);
}
return fprintf(fp, ":%s\n", a4);
}

canonical_decompiled_code:
int __fastcall func13(char a1, __int64 a2, int a3, const char *a4)
{
__int64 v6; // rbx
double v7; // xmm0_8
__int64 v9; // rbx
double v10; // xmm0_8
__int64 v11; // rbx
double v12; // xmm0_8

if ( !fp )
func12();
switch ( a1 )
{
case 'L':
v6 = 0LL;
fwrite("line:", 1uLL, 5uLL, fp);
if ( a3 > 0 )
{
do
{
while ( 1 )
{
v7 = *(float *)(a2 + 4 * v6);
if ( a3 - 1 == (_DWORD)v6 )
break;
++v6;
fprintf(fp, "%f, ", v7);
if ( a3 == v6 )
return fprintf(fp, ":%s\n", a4);
}
++v6;
fprintf(fp, "%f", v7);
}
while ( a3 != v6 );
}
break;
case 'X':
v11 = 0LL;
fwrite("logx:", 1uLL, 5uLL, fp);
if ( a3 > 0 )
{
do
{
v12 = *(float *)(a2 + 4 * v11);
if ( a3 - 1 == (_DWORD)v11 )
fprintf(fp, "%f", v12);
else
fprintf(fp, "%f, ", v12);
++v11;
}
while ( v11 != a3 );
}
break;
case 'H':
v9 = 0LL;
fwrite("hist:", 1uLL, 5uLL, fp);
if ( a3 > 0 )
{
do
{
v10 = *(float *)(a2 + 4 * v9);
if ( a3 - 1 == (_DWORD)v9 )
fprintf(fp, "%f", v10);
else
fprintf(fp, "%f, ", v10);
++v9;
}
while ( a3 != v9 );
}
break;
default:
printf("Invalid Graph type");
exit(1);
}
return fprintf(fp, ":%s\n", a4);
}

original_code:
void graph_new(char type, float* buffer, int length, char* keyvals) {
 if (fp == ((void *)0))
  graph_init();
 int i ;
 switch(type) {
  case 'L':
   fprintf(fp, "line:");
   for (i = 0 ; i < length ; i++) {
    if (i == (length - 1))
     fprintf(fp, "%f", buffer[i]);
    else
     fprintf(fp, "%f, ", buffer[i]);
   }
                        fprintf(fp, ":%s\n", keyvals);
   return;
  case 'X':
   fprintf(fp, "logx:");
   for (i = 0 ; i < length ; i++) {
    if (i == (length - 1))
     fprintf(fp, "%f", buffer[i]);
    else
     fprintf(fp, "%f, ", buffer[i]);
   }
                        fprintf(fp, ":%s\n", keyvals);
   return;
  case 'H':
                        fprintf(fp, "hist:");
                        for (i = 0 ; i < length ; i++) {
                                if (i == (length - 1))
                                        fprintf(fp, "%f", buffer[i]);
                                else
                                        fprintf(fp, "%f, ", buffer[i]);
                        }
                        fprintf(fp, ":%s\n", keyvals);
                        return;
  default:
   printf("Invalid Graph type");
   exit(1);
 }
}

canonical_original_code:
void graph_new(char type, float *buffer, int length, char *keyvals) {
 if (fp == ((void *)0))
  graph_init();
 int i;
 switch(type) {
  case 'L':
   fprintf(fp, "line:");
   for (i = 0 ; i < length ; i++) {
    if (i == (length - 1))
     fprintf(fp, "%f", buffer[i]);
    else
     fprintf(fp, "%f, ", buffer[i]);
   }
                        fprintf(fp, ":%s\n", keyvals);
   return;
  case 'X':
   fprintf(fp, "logx:");
   for (i = 0 ; i < length ; i++) {
    if (i == (length - 1))
     fprintf(fp, "%f", buffer[i]);
    else
     fprintf(fp, "%f, ", buffer[i]);
   }
                        fprintf(fp, ":%s\n", keyvals);
   return;
  case 'H':
                        fprintf(fp, "hist:");
                        for (i = 0 ; i < length ; i++) {
                                if (i == (length - 1))
                                        fprintf(fp, "%f", buffer[i]);
                                else
                                        fprintf(fp, "%f, ", buffer[i]);
                        }
                        fprintf(fp, ":%s\n", keyvals);
                        return;
  default:
   printf("Invalid Graph type");
   exit(1);
 }
}

variable_types: type char

variable_types:
buffer
float *

variable_types: length int

variable_types:
keyvals
char *

variable_types: i int


decompiled_code:
int __fastcall graph_xy(char a1, __int64 a2, __int64 a3, int a4, const char *a5)
{
__int64 v7; // rbp
int v8; // er12
__int64 i; // rbx
double v10; // xmm0_8
__int64 v11; // rbx
double v12; // xmm0_8

v7 = a4;
if ( !fp )
graph_init();
if ( a1 != 83 )
{
printf("Invalid Graph type");
exit(1);
}
fwrite("scatter:", 1uLL, 8uLL, fp);
if ( (int)v7 <= 0 )
{
fputc(58, fp);
}
else
{
v8 = v7 - 1;
for ( i = 0LL; i != v7; ++i )
{
while ( 1 )
{
v10 = *(float *)(a2 + 4 * i);
if ( v8 == (_DWORD)i )
break;
++i;
fprintf(fp, "%f, ", v10);
if ( i == v7 )
goto LABEL_9;
}
fprintf(fp, "%f", v10);
}
LABEL_9:
v11 = 0LL;
fputc(58, fp);
do
{
while ( 1 )
{
v12 = *(float *)(a3 + 4 * v11);
if ( v8 == (_DWORD)v11 )
break;
++v11;
fprintf(fp, "%f, ", v12);
if ( v11 == v7 )
return fprintf(fp, ":%s\n", a5);
}
++v11;
fprintf(fp, "%f", v12);
}
while ( v11 != v7 );
}
return fprintf(fp, ":%s\n", a5);
}

canonical_decompiled_code:
int __fastcall func14(char a1, __int64 a2, __int64 a3, int a4, const char *a5)
{
__int64 v7; // rbp
int v8; // er12
__int64 i; // rbx
double v10; // xmm0_8
__int64 v11; // rbx
double v12; // xmm0_8

v7 = a4;
if ( !fp )
func12();
if ( a1 != 83 )
{
printf("Invalid Graph type");
exit(1);
}
fwrite("scatter:", 1uLL, 8uLL, fp);
if ( (int)v7 <= 0 )
{
fputc(58, fp);
}
else
{
v8 = v7 - 1;
for ( i = 0LL; i != v7; ++i )
{
while ( 1 )
{
v10 = *(float *)(a2 + 4 * i);
if ( v8 == (_DWORD)i )
break;
++i;
fprintf(fp, "%f, ", v10);
if ( i == v7 )
goto LABEL_9;
}
fprintf(fp, "%f", v10);
}
LABEL_9:
v11 = 0LL;
fputc(58, fp);
do
{
while ( 1 )
{
v12 = *(float *)(a3 + 4 * v11);
if ( v8 == (_DWORD)v11 )
break;
++v11;
fprintf(fp, "%f, ", v12);
if ( v11 == v7 )
return fprintf(fp, ":%s\n", a5);
}
++v11;
fprintf(fp, "%f", v12);
}
while ( v11 != v7 );
}
return fprintf(fp, ":%s\n", a5);
}

original_code:
void graph_xy(char type, float* buffer_x, float* buffer_y, int length, char* keyvals) {
 if (fp == ((void *)0))
  graph_init();
 int i ;
 switch(type) {
  case 'S':
   fprintf(fp, "scatter:");
   for (i = 0 ; i < length ; i++) {
    if (i == (length - 1))
     fprintf(fp, "%f", buffer_x[i]);
    else
     fprintf(fp, "%f, ", buffer_x[i]);
   }
   fprintf(fp,":");
   for (i = 0 ; i < length ; i++) {
    if (i == (length - 1))
     fprintf(fp, "%f", buffer_y[i]);
    else
     fprintf(fp, "%f, ", buffer_y[i]);
   }
                        fprintf(fp, ":%s\n", keyvals);
   return;
  default:
   printf("Invalid Graph type");
   exit(1);
 }
}

canonical_original_code:
void graph_xy(char type, float *buffer_x, float *buffer_y, int length, char *keyvals) {
 if (fp == ((void *)0))
  graph_init();
 int i;
 switch(type) {
  case 'S':
   fprintf(fp, "scatter:");
   for (i = 0 ; i < length ; i++) {
    if (i == (length - 1))
     fprintf(fp, "%f", buffer_x[i]);
    else
     fprintf(fp, "%f, ", buffer_x[i]);
   }
   fprintf(fp,":");
   for (i = 0 ; i < length ; i++) {
    if (i == (length - 1))
     fprintf(fp, "%f", buffer_y[i]);
    else
     fprintf(fp, "%f, ", buffer_y[i]);
   }
                        fprintf(fp, ":%s\n", keyvals);
   return;
  default:
   printf("Invalid Graph type");
   exit(1);
 }
}


decompiled_code:
int graph_show()
{
int result; // eax

fclose(fp);
result = system("../include/graph.py /tmp/graph.current");
fp = 0LL;
return result;
}

canonical_decompiled_code:
int func15()
{
int result; // eax

fclose(fp);
result = system("../include/graph.py /tmp/graph.current");
fp = 0LL;
return result;
}

original_code:
void graph_show() {
 fclose(fp);
 system("../include/graph.py /tmp/graph.current");
 fp = ((void *)0);
}


canonical_decompiled_code:
int func7()
{
fp = fopen(path, "w+");
if ( !fp )
{
puts("File Cretion error");
exit(1);
}
return chmod(path, 0x1C0u);
}

canonical_original_code:
void graph_init() {
 fp = fopen(path, "w+");
 if (fp == ((void *)0)) {
  printf("File Cretion error\n");
  exit(1);
 }
 chmod(path, (0400|0200|0100));
}


canonical_decompiled_code:
int __fastcall func8(char a1, __int64 a2, int a3, const char *a4)
{
__int64 v6; // rbx
double v7; // xmm0_8
__int64 v9; // rbx
double v10; // xmm0_8
__int64 v11; // rbx
double v12; // xmm0_8

if ( !fp )
func7();
switch ( a1 )
{
case 'L':
v6 = 0LL;
fwrite("line:", 1uLL, 5uLL, fp);
if ( a3 > 0 )
{
do
{
while ( 1 )
{
v7 = *(float *)(a2 + 4 * v6);
if ( a3 - 1 == (_DWORD)v6 )
break;
++v6;
fprintf(fp, "%f, ", v7);
if ( a3 == v6 )
return fprintf(fp, ":%s\n", a4);
}
++v6;
fprintf(fp, "%f", v7);
}
while ( a3 != v6 );
}
break;
case 'X':
v11 = 0LL;
fwrite("logx:", 1uLL, 5uLL, fp);
if ( a3 > 0 )
{
do
{
v12 = *(float *)(a2 + 4 * v11);
if ( a3 - 1 == (_DWORD)v11 )
fprintf(fp, "%f", v12);
else
fprintf(fp, "%f, ", v12);
++v11;
}
while ( v11 != a3 );
}
break;
case 'H':
v9 = 0LL;
fwrite("hist:", 1uLL, 5uLL, fp);
if ( a3 > 0 )
{
do
{
v10 = *(float *)(a2 + 4 * v9);
if ( a3 - 1 == (_DWORD)v9 )
fprintf(fp, "%f", v10);
else
fprintf(fp, "%f, ", v10);
++v9;
}
while ( a3 != v9 );
}
break;
default:
printf("Invalid Graph type");
exit(1);
}
return fprintf(fp, ":%s\n", a4);
}


canonical_decompiled_code:
int __fastcall func9(char a1, __int64 a2, __int64 a3, int a4, const char *a5)
{
__int64 v7; // rbp
int v8; // er12
__int64 i; // rbx
double v10; // xmm0_8
__int64 v11; // rbx
double v12; // xmm0_8

v7 = a4;
if ( !fp )
func7();
if ( a1 != 83 )
{
printf("Invalid Graph type");
exit(1);
}
fwrite("scatter:", 1uLL, 8uLL, fp);
if ( (int)v7 <= 0 )
{
fputc(58, fp);
}
else
{
v8 = v7 - 1;
for ( i = 0LL; i != v7; ++i )
{
while ( 1 )
{
v10 = *(float *)(a2 + 4 * i);
if ( v8 == (_DWORD)i )
break;
++i;
fprintf(fp, "%f, ", v10);
if ( i == v7 )
goto LABEL_9;
}
fprintf(fp, "%f", v10);
}
LABEL_9:
v11 = 0LL;
fputc(58, fp);
do
{
while ( 1 )
{
v12 = *(float *)(a3 + 4 * v11);
if ( v8 == (_DWORD)v11 )
break;
++v11;
fprintf(fp, "%f, ", v12);
if ( v11 == v7 )
return fprintf(fp, ":%s\n", a5);
}
++v11;
fprintf(fp, "%f", v12);
}
while ( v11 != v7 );
}
return fprintf(fp, ":%s\n", a5);
}


canonical_decompiled_code:
int func10()
{
int result; // eax

fclose(fp);
result = system("../include/graph.py /tmp/graph.current");
fp = 0LL;
return result;
}

canonical_original_code:
void graph_show() {
 fclose(fp);
 system("../include/graph.py /tmp/graph.current");
 fp = ((void *)0);
}


repo: sipwise/mediator

decompiled_code:
char *__fastcall config_set_string_option(void **a1, const char *a2)
{
char *result; // rax

free(*a1);
result = strdup(a2);
*a1 = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(void **a1, const char *a2)
{
char *result; // rax

free(*a1);
result = strdup(a2);
*a1 = result;
return result;
}

original_code:
static void config_set_string_option(char **str, const char *opt)
{
    free(*str);
    *str = strdup(opt);
}

canonical_original_code:
static void config_set_string_option(char **str, char *opt)
{
    free(*str);
    *str = strdup(opt);
}

variable_types:
str
char **

variable_types:
opt
char *


decompiled_code:
void __fastcall config_set_option(int a1, const char *a2)
{
switch ( a1 )
{
case 'A':
config_set_string_option(&config_prov_pass, a2);
break;
case 'B':
config_set_string_option(&config_cdr_db, a2);
break;
case 'D':
config_set_string_option(&config_pid_path, a2);
break;
case 'H':
config_set_string_option(&config_cdr_host, a2);
break;
case 'I':
config_intermediate_interval = atoi(a2);
break;
case 'L':
config_loglevel = atoi(a2);
break;
case 'M':
config_max_acc_age = atoi(a2);
break;
case 'N':
config_set_string_option(&config_prov_db, a2);
break;
case 'O':
config_cdr_port = atoi(a2);
break;
case 'P':
config_set_string_option(&config_cdr_pass, a2);
break;
case 'R':
config_set_string_option(&config_prov_user, a2);
break;
case 'S':
config_set_string_option(&config_prov_host, a2);
break;
case 'T':
config_prov_port = atoi(a2);
break;
case 'U':
config_set_string_option(&config_cdr_user, a2);
break;
case 'W':
config_set_string_option(&config_stats_user, a2);
break;
case 'X':
config_set_string_option(&config_stats_db, a2);
break;
case 'Y':
config_intermediate_cdr_port = atoi(a2);
break;
case 'Z':
config_set_string_option(&config_stats_host, a2);
break;
case 'a':
config_set_string_option(&config_redis_host, a2);
break;
case 'b':
config_set_string_option(&config_med_db, a2);
break;
case 'c':
config_set_string_option((void **)&config_file_path, a2);
break;
case 'd':
config_daemonize = 1;
break;
case 'e':
config_set_string_option(&config_redis_pass, a2);
break;
case 'h':
config_set_string_option(&config_med_host, a2);
break;
case 'i':
config_interval = atoi(a2);
break;
case 'l':
config_dumpcdr = 1;
break;
case 'm':
config_maintenance = 1;
break;
case 'o':
config_med_port = atoi(a2);
break;
case 'p':
config_set_string_option(&config_med_pass, a2);
break;
case 'r':
config_redis_db = atoi(a2);
break;
case 's':
strict_leg_tokens = 1;
break;
case 't':
config_redis_port = atoi(a2);
break;
case 'u':
config_set_string_option(&config_med_user, a2);
break;
case 'w':
config_set_string_option(&config_stats_pass, a2);
break;
case 'x':
config_stats_period = atoi(a2);
break;
case 'y':
config_set_string_option(&config_intermediate_cdr_host, a2);
break;
case 'z':
config_stats_port = atoi(a2);
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, const char *a2)
{
switch ( a1 )
{
case 'A':
func0(&config_prov_pass, a2);
break;
case 'B':
func0(&config_cdr_db, a2);
break;
case 'D':
func0(&config_pid_path, a2);
break;
case 'H':
func0(&config_cdr_host, a2);
break;
case 'I':
config_intermediate_interval = atoi(a2);
break;
case 'L':
config_loglevel = atoi(a2);
break;
case 'M':
config_max_acc_age = atoi(a2);
break;
case 'N':
func0(&config_prov_db, a2);
break;
case 'O':
config_cdr_port = atoi(a2);
break;
case 'P':
func0(&config_cdr_pass, a2);
break;
case 'R':
func0(&config_prov_user, a2);
break;
case 'S':
func0(&config_prov_host, a2);
break;
case 'T':
config_prov_port = atoi(a2);
break;
case 'U':
func0(&config_cdr_user, a2);
break;
case 'W':
func0(&config_stats_user, a2);
break;
case 'X':
func0(&config_stats_db, a2);
break;
case 'Y':
config_intermediate_cdr_port = atoi(a2);
break;
case 'Z':
func0(&config_stats_host, a2);
break;
case 'a':
func0(&config_redis_host, a2);
break;
case 'b':
func0(&config_med_db, a2);
break;
case 'c':
func0((void **)&config_file_path, a2);
break;
case 'd':
config_daemonize = 1;
break;
case 'e':
func0(&config_redis_pass, a2);
break;
case 'h':
func0(&config_med_host, a2);
break;
case 'i':
config_interval = atoi(a2);
break;
case 'l':
config_dumpcdr = 1;
break;
case 'm':
config_maintenance = 1;
break;
case 'o':
config_med_port = atoi(a2);
break;
case 'p':
func0(&config_med_pass, a2);
break;
case 'r':
config_redis_db = atoi(a2);
break;
case 's':
strict_leg_tokens = 1;
break;
case 't':
config_redis_port = atoi(a2);
break;
case 'u':
func0(&config_med_user, a2);
break;
case 'w':
func0(&config_stats_pass, a2);
break;
case 'x':
config_stats_period = atoi(a2);
break;
case 'y':
func0(&config_intermediate_cdr_host, a2);
break;
case 'z':
config_stats_port = atoi(a2);
break;
default:
return;
}
}

original_code:
static void config_set_option(enum config_option option, const char *value)
{
    switch (option) {
    case OPT_DAEMONIZE:
        config_daemonize = 1;
        break;
    case OPT_SYSLOG:
        config_dumpcdr = 1;
        break;
    case OPT_LOGLEVEL:
        config_loglevel = atoi(value);
        break;
    case OPT_CONFIGFILE:
        config_set_string_option(&config_file_path, value);
        break;
    case OPT_PIDFILE:
        config_set_string_option(&config_pid_path, value);
        break;
    case OPT_INTERVAL:
        config_interval = atoi(value);
        break;
    case OPT_MED_HOST:
        config_set_string_option(&config_med_host, value);
        break;
    case OPT_MED_USER:
        config_set_string_option(&config_med_user, value);
        break;
    case OPT_MED_PASS:
        config_set_string_option(&config_med_pass, value);
        break;
    case OPT_MED_DB:
        config_set_string_option(&config_med_db, value);
        break;
    case OPT_MED_PORT:
        config_med_port = atoi(value);
        break;
    case OPT_CDR_HOST:
        config_set_string_option(&config_cdr_host, value);
        break;
    case OPT_CDR_USER:
        config_set_string_option(&config_cdr_user, value);
        break;
    case OPT_CDR_PASS:
        config_set_string_option(&config_cdr_pass, value);
        break;
    case OPT_CDR_DB:
        config_set_string_option(&config_cdr_db, value);
        break;
    case OPT_CDR_PORT:
        config_cdr_port = atoi(value);
        break;
    case OPT_INTERMEDIATE_CDR_HOST:
        config_set_string_option(&config_intermediate_cdr_host, value);
        break;
    case OPT_INTERMEDIATE_CDR_PORT:
        config_intermediate_cdr_port = atoi(value);
        break;
    case OPT_PROV_HOST:
        config_set_string_option(&config_prov_host, value);
        break;
    case OPT_PROV_USER:
        config_set_string_option(&config_prov_user, value);
        break;
    case OPT_PROV_PASS:
        config_set_string_option(&config_prov_pass, value);
        break;
    case OPT_PROV_DB:
        config_set_string_option(&config_prov_db, value);
        break;
    case OPT_PROV_PORT:
        config_prov_port = atoi(value);
        break;
    case OPT_STATS_HOST:
        config_set_string_option(&config_stats_host, value);
        break;
    case OPT_STATS_USER:
        config_set_string_option(&config_stats_user, value);
        break;
    case OPT_STATS_PASS:
        config_set_string_option(&config_stats_pass, value);
        break;
    case OPT_STATS_PORT:
        config_stats_port = atoi(value);
        break;
    case OPT_STATS_DB:
        config_set_string_option(&config_stats_db, value);
        break;
    case OPT_STATS_PERIOD:
        config_stats_period = (med_stats_period_t)atoi(value);
        break;
    case OPT_REDIS_HOST:
        config_set_string_option(&config_redis_host, value);
        break;
    case OPT_REDIS_PORT:
        config_redis_port = atoi(value);
        break;
    case OPT_REDIS_DB:
        config_redis_db = atoi(value);
        break;
    case OPT_REDIS_PASS:
        config_set_string_option(&config_redis_pass, value);
        break;
    case OPT_MAINTENANCE:
        config_maintenance = 1;
        break;
    case OPT_LEG_TOKENS:
        strict_leg_tokens = 1;
        break;
    case OPT_MAX_ACC_AGE:
        config_max_acc_age = atoi(value);
        break;
    case OPT_INTERMEDIATE_INTERVAL:
        config_intermediate_interval = atoi(value);
        break;
    }
}

canonical_original_code:
static void config_set_option(enum config_option option, char *value)
{
    switch (option) {
    case OPT_DAEMONIZE:
        config_daemonize = 1;
        break;
    case OPT_SYSLOG:
        config_dumpcdr = 1;
        break;
    case OPT_LOGLEVEL:
        config_loglevel = atoi(value);
        break;
    case OPT_CONFIGFILE:
        config_set_string_option(&config_file_path, value);
        break;
    case OPT_PIDFILE:
        config_set_string_option(&config_pid_path, value);
        break;
    case OPT_INTERVAL:
        config_interval = atoi(value);
        break;
    case OPT_MED_HOST:
        config_set_string_option(&config_med_host, value);
        break;
    case OPT_MED_USER:
        config_set_string_option(&config_med_user, value);
        break;
    case OPT_MED_PASS:
        config_set_string_option(&config_med_pass, value);
        break;
    case OPT_MED_DB:
        config_set_string_option(&config_med_db, value);
        break;
    case OPT_MED_PORT:
        config_med_port = atoi(value);
        break;
    case OPT_CDR_HOST:
        config_set_string_option(&config_cdr_host, value);
        break;
    case OPT_CDR_USER:
        config_set_string_option(&config_cdr_user, value);
        break;
    case OPT_CDR_PASS:
        config_set_string_option(&config_cdr_pass, value);
        break;
    case OPT_CDR_DB:
        config_set_string_option(&config_cdr_db, value);
        break;
    case OPT_CDR_PORT:
        config_cdr_port = atoi(value);
        break;
    case OPT_INTERMEDIATE_CDR_HOST:
        config_set_string_option(&config_intermediate_cdr_host, value);
        break;
    case OPT_INTERMEDIATE_CDR_PORT:
        config_intermediate_cdr_port = atoi(value);
        break;
    case OPT_PROV_HOST:
        config_set_string_option(&config_prov_host, value);
        break;
    case OPT_PROV_USER:
        config_set_string_option(&config_prov_user, value);
        break;
    case OPT_PROV_PASS:
        config_set_string_option(&config_prov_pass, value);
        break;
    case OPT_PROV_DB:
        config_set_string_option(&config_prov_db, value);
        break;
    case OPT_PROV_PORT:
        config_prov_port = atoi(value);
        break;
    case OPT_STATS_HOST:
        config_set_string_option(&config_stats_host, value);
        break;
    case OPT_STATS_USER:
        config_set_string_option(&config_stats_user, value);
        break;
    case OPT_STATS_PASS:
        config_set_string_option(&config_stats_pass, value);
        break;
    case OPT_STATS_PORT:
        config_stats_port = atoi(value);
        break;
    case OPT_STATS_DB:
        config_set_string_option(&config_stats_db, value);
        break;
    case OPT_STATS_PERIOD:
        config_stats_period = (enum med_stats_period_t)atoi(value);
        break;
    case OPT_REDIS_HOST:
        config_set_string_option(&config_redis_host, value);
        break;
    case OPT_REDIS_PORT:
        config_redis_port = atoi(value);
        break;
    case OPT_REDIS_DB:
        config_redis_db = atoi(value);
        break;
    case OPT_REDIS_PASS:
        config_set_string_option(&config_redis_pass, value);
        break;
    case OPT_MAINTENANCE:
        config_maintenance = 1;
        break;
    case OPT_LEG_TOKENS:
        strict_leg_tokens = 1;
        break;
    case OPT_MAX_ACC_AGE:
        config_max_acc_age = atoi(value);
        break;
    case OPT_INTERMEDIATE_INTERVAL:
        config_intermediate_interval = atoi(value);
        break;
    }
}

variable_types: enum config_option { OPT_CONFIGFILE=expr, OPT_DAEMONIZE=expr, OPT_PIDFILE=expr, OPT_SYSLOG=expr, OPT_LOGLEVEL=expr, OPT_INTERVAL=expr, OPT_MED_HOST=expr, OPT_MED_PORT=expr, OPT_MED_USER=expr, OPT_MED_PASS=expr, OPT_MED_DB=expr, OPT_CDR_HOST=expr, OPT_CDR_PORT=expr, OPT_CDR_USER=expr, OPT_CDR_PASS=expr, OPT_CDR_DB=expr, OPT_INTERMEDIATE_CDR_HOST=expr, OPT_INTERMEDIATE_CDR_PORT=expr, OPT_PROV_HOST=expr, OPT_PROV_PORT=expr, OPT_PROV_USER=expr, OPT_PROV_PASS=expr, OPT_PROV_DB=expr, OPT_STATS_HOST=expr, OPT_STATS_PORT=expr, OPT_STATS_USER=expr, OPT_STATS_PASS=expr, OPT_STATS_DB=expr, OPT_REDIS_HOST=expr, OPT_REDIS_PORT=expr, OPT_REDIS_DB=expr, OPT_REDIS_PASS=expr, OPT_STATS_PERIOD=expr, OPT_MAINTENANCE=expr, OPT_LEG_TOKENS=expr, OPT_MAX_ACC_AGE=expr, OPT_INTERMEDIATE_INTERVAL=expr }

variable_types:
value
char *

user_defined_types: enum med_stats_period_t { MED_STATS_HOUR=1, MED_STATS_DAY=2, MED_STATS_MONTH=3 }


decompiled_code:
void __fastcall config_set_string_default(char **a1, const char *a2)
{
if ( !*a1 )
*a1 = strdup(a2);
}

canonical_decompiled_code:
void __fastcall func2(char **a1, const char *a2)
{
if ( !*a1 )
*a1 = strdup(a2);
}

original_code:
static void config_set_string_default(char **str, const char *def)
{
    if (*str == ((void *)0))
        *str = strdup(def);
}

canonical_original_code:
static void config_set_string_default(char **str, char *def)
{
    if (*str == ((void *)0))
        *str = strdup(def);
}

variable_types:
def
char *


decompiled_code:
void config_set_defaults()
{
config_set_string_default((char **)&config_pid_path, "/run/mediator.pid");
config_set_string_default((char **)&config_med_host, "localhost");
config_set_string_default((char **)&config_med_user, "mediator");
config_set_string_default((char **)&config_med_pass, "GimmeAllUr$$$");
config_set_string_default((char **)&config_med_db, "accounting");
config_set_string_default((char **)&config_cdr_host, "localhost");
config_set_string_default((char **)&config_cdr_user, "mediator");
config_set_string_default((char **)&config_cdr_pass, "GimmeAllUr$$$");
config_set_string_default((char **)&config_cdr_db, "accounting");
config_set_string_default((char **)&config_intermediate_cdr_host, "localhost");
config_set_string_default((char **)&config_prov_host, "localhost");
config_set_string_default((char **)&config_prov_user, "mediator");
config_set_string_default((char **)&config_prov_pass, "GimmeAllUr$$$");
config_set_string_default((char **)&config_prov_db, "provisioning");
config_set_string_default((char **)&config_stats_host, "localhost");
config_set_string_default((char **)&config_stats_user, "mediator");
config_set_string_default((char **)&config_stats_pass, "GimmeAllUr$$$");
config_set_string_default((char **)&config_stats_db, "stats");
config_set_string_default((char **)&config_redis_host, "localhost");
}

canonical_decompiled_code:
void func3()
{
func2((char **)&config_pid_path, "/run/mediator.pid");
func2((char **)&config_med_host, "localhost");
func2((char **)&config_med_user, "mediator");
func2((char **)&config_med_pass, "GimmeAllUr$$$");
func2((char **)&config_med_db, "accounting");
func2((char **)&config_cdr_host, "localhost");
func2((char **)&config_cdr_user, "mediator");
func2((char **)&config_cdr_pass, "GimmeAllUr$$$");
func2((char **)&config_cdr_db, "accounting");
func2((char **)&config_intermediate_cdr_host, "localhost");
func2((char **)&config_prov_host, "localhost");
func2((char **)&config_prov_user, "mediator");
func2((char **)&config_prov_pass, "GimmeAllUr$$$");
func2((char **)&config_prov_db, "provisioning");
func2((char **)&config_stats_host, "localhost");
func2((char **)&config_stats_user, "mediator");
func2((char **)&config_stats_pass, "GimmeAllUr$$$");
func2((char **)&config_stats_db, "stats");
func2((char **)&config_redis_host, "localhost");
}

original_code:
static void config_set_defaults(void)
{
    config_set_string_default(&config_pid_path, "/run/mediator.pid");
    config_set_string_default(&config_med_host, "localhost");
    config_set_string_default(&config_med_user, "mediator");
    config_set_string_default(&config_med_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_med_db, "accounting");
    config_set_string_default(&config_cdr_host, "localhost");
    config_set_string_default(&config_cdr_user, "mediator");
    config_set_string_default(&config_cdr_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_cdr_db, "accounting");
    config_set_string_default(&config_intermediate_cdr_host, "localhost");
    config_set_string_default(&config_prov_host, "localhost");
    config_set_string_default(&config_prov_user, "mediator");
    config_set_string_default(&config_prov_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_prov_db, "provisioning");
    config_set_string_default(&config_stats_host, "localhost");
    config_set_string_default(&config_stats_user, "mediator");
    config_set_string_default(&config_stats_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_stats_db, "stats");
    config_set_string_default(&config_redis_host, "localhost");
}

canonical_original_code:
static void config_set_defaults()
{
    config_set_string_default(&config_pid_path, "/run/mediator.pid");
    config_set_string_default(&config_med_host, "localhost");
    config_set_string_default(&config_med_user, "mediator");
    config_set_string_default(&config_med_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_med_db, "accounting");
    config_set_string_default(&config_cdr_host, "localhost");
    config_set_string_default(&config_cdr_user, "mediator");
    config_set_string_default(&config_cdr_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_cdr_db, "accounting");
    config_set_string_default(&config_intermediate_cdr_host, "localhost");
    config_set_string_default(&config_prov_host, "localhost");
    config_set_string_default(&config_prov_user, "mediator");
    config_set_string_default(&config_prov_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_prov_db, "provisioning");
    config_set_string_default(&config_stats_host, "localhost");
    config_set_string_default(&config_stats_user, "mediator");
    config_set_string_default(&config_stats_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_stats_db, "stats");
    config_set_string_default(&config_redis_host, "localhost");
}