kmemmem

original_code:
void *kmemmem(const void *_str, int n, const void *_pat, int m, int **_prep)
{
 int i, j, *prep = 0, *bmGs, *bmBc;
 const ubyte_t *str, *pat;
 str = (const ubyte_t*)_str; pat = (const ubyte_t*)_pat;
 prep = (_prep == 0 || *_prep == 0)? ksBM_prep(pat, m) : *_prep;
 if (_prep && *_prep == 0) *_prep = prep;
 bmGs = prep; bmBc = prep + m;
 j = 0;
 while (j <= n - m) {
  for (i = m - 1; i >= 0 && pat[i] == str[i+j]; --i);
  if (i >= 0) {
   int max = bmBc[str[i+j]] - m + 1 + i;
   if (max < bmGs[i]) max = bmGs[i];
   j += max;
  } else return (void*)(str + j);
 }
 if (_prep == 0) free(prep);
 return 0;
}

canonical_original_code:
void *kmemmem(void *_str, int n, void *_pat, int m, int **_prep)
{
 int i; int j; int *prep = 0; int *bmGs; int *bmBc;
 unsigned char *str; unsigned char *pat;
 str = (unsigned char *)_str; pat = (unsigned char *)_pat;
 prep = (_prep == 0 || *_prep == 0)? ksBM_prep(pat, m) : *_prep;
 if (_prep && *_prep == 0) *_prep = prep;
 bmGs = prep; bmBc = prep + m;
 j = 0;
 while (j <= n - m) {
  for (i = m - 1; i >= 0 && pat[i] == str[i+j]; --i);
  if (i >= 0) {
   int max = bmBc[str[i+j]] - m + 1 + i;
   if (max < bmGs[i]) max = bmGs[i];
   j += max;
  } else return (void *)(str + j);
 }
 if (_prep == 0) free(prep);
 return 0;
}

variable_types: m int

variable_types: j int

variable_types:
prep
int *

variable_types:
bmGs
int *

variable_types:
bmBc
int *

variable_types:
str
unsigned char *

variable_types:
pat
unsigned char *

return_type: void *


kstrstr

repo: pervouchine/bamflag

decompiled_code:
__int64 __fastcall kstrstr(char *s, char *a2, int **a3)
{
int v4; // er12
int v5; // eax

v4 = strlen(a2);
v5 = strlen(s);
return kmemmem((__int64)s, v5, (unsigned __int8 *)a2, v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, char *a2, int **a3)
{
int v4; // er12
int v5; // eax

v4 = strlen(a2);
v5 = strlen(s);
return func4((__int64)s, v5, (unsigned __int8 *)a2, v4, a3);
}

original_code:
char *kstrstr(const char *str, const char *pat, int **_prep)
{
 return (char*)kmemmem(str, strlen(str), pat, strlen(pat), _prep);
}

canonical_original_code:
char *kstrstr(char *str, char *pat, int **_prep)
{
 return (char *)kmemmem(str, strlen(str), pat, strlen(pat), _prep);
}

variable_types:
str
char *

variable_types:
pat
char *

return_type: char *


kstrnstr

decompiled_code:
__int64 __fastcall kstrnstr(__int64 a1, char *a2, int a3, int **a4)
{
int v6; // eax

v6 = strlen(a2);
return kmemmem(a1, a3, (unsigned __int8 *)a2, v6, a4);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char *a2, int a3, int **a4)
{
int v6; // eax

v6 = strlen(a2);
return func4(a1, a3, (unsigned __int8 *)a2, v6, a4);
}

original_code:
char *kstrnstr(const char *str, const char *pat, int n, int **_prep)
{
 return (char*)kmemmem(str, n, pat, strlen(pat), _prep);
}

canonical_original_code:
char *kstrnstr(char *str, char *pat, int n, int **_prep)
{
 return (char *)kmemmem(str, n, pat, strlen(pat), _prep);
}

variable_types: n int


canonical_original_code:
int bcf_2qcall(struct bcf_hdr_t *h, struct bcf1_t *b)
{
 int a[4]; int k; int g[10]; int l; int map[4]; int k1; int j; int i; int i0; int anno[16]; int dp; int mq; int d_rest;
 char *s;
 if (b->ref[1] != 0 || b->n_alleles > 4) return -1;
 for (i = 0; i < b->n_gi; ++i)
  if (b->gi[i].fmt == bcf_str2int("PL", 2)) break;
 if (i == b->n_gi) return -1;
 if (read_I16(b, anno) != 0) return -1;
 d_rest = dp = anno[0] + anno[1] + anno[2] + anno[3];
 if (dp == 0) return -1;
 mq = (int)(sqrt((double)(anno[9] + anno[11]) / dp) + .499);
 i0 = i;
 a[0] = nt4_table[(int)b->ref[0]];
 if (a[0] > 3) return -1;
 a[1] = a[2] = a[3] = -2;
 if (b->alt[0] == 0) return -1;
 map[0] = map[1] = map[2] = map[3] = -2;
 map[a[0]] = 0;
 for (k = 0, s = b->alt, k1 = -1; k < 3 && *s; ++k, s += 2) {
  if (s[1] != ',' && s[1] != 0) return -1;
  a[k+1] = nt4_table[(int)*s];
  if (a[k+1] >= 0) map[a[k+1]] = k+1;
  else k1 = k+1;
  if (s[1] == 0) break;
 }
 for (k = 0; k < 4; ++k)
  if (map[k] < 0) map[k] = k1;
 for (i = 0; i < h->n_smpl; ++i) {
  int d;
  unsigned char *p = b->gi[i0].data + i * b->gi[i0].len;
  for (j = 0; j < b->gi[i0].len; ++j)
   if (p[j]) break;
  d = (int)((double)d_rest / (h->n_smpl - i) + .499);
  if (d == 0) d = 1;
  if (j == b->gi[i0].len) d = 0;
  d_rest -= d;
  for (k = j = 0; k < 4; ++k) {
   for (l = k; l < 4; ++l) {
    int t; int x = map[k]; int y = map[l];
    if (x > y) t = x, x = y, y = t;
    g[j++] = p[y * (y+1) / 2 + x];
   }
  }
  printf("%s\t%d\t%c", h->ns[b->tid], b->pos+1, *b->ref);
  printf("\t%d\t%d\t0", d, mq);
  for (j = 0; j < 10; ++j)
   printf("\t%d", g[j]);
  printf("\t%s\n", h->sns[i]);
 }
 return 0;
}

variable_types: struct bcf_hdr_t { int n_ref; int l_nm; int l_smpl; int l_txt; char *name; char **ns; } *

variable_types: struct bcf1_t { int tid; int l_str; float qual; char *str; char *ref; int n_gi; struct bcf_ginfo_t { unsigned int fmt; int len; void *data; } *gi; int n_alleles; } *

variable_types:
a
int [4]

variable_types: k int

variable_types:
g
int [10]

variable_types: l int

variable_types:
map
int [4]

variable_types: i int

variable_types:
anno
int [16]

variable_types: dp int

variable_types: mq int

variable_types:
s
char *

variable_types: d int

variable_types:
p
unsigned char *

variable_types: t int

variable_types: x int

variable_types: y int

return_type: int

user_defined_types: struct bcf1_t { int tid; int l_str; float qual; char *str; char *ref; int n_gi; struct bcf_ginfo_t *gi; int n_alleles; }


original_code:
static void append_header_text(bam_header_t *header, char* text, int len)
{
 int x = header->l_text + 1;
 int y = header->l_text + len + 1;
 if (text == 0) return;
 (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x));
 (--(y), (y)|=(y)>>1, (y)|=(y)>>2, (y)|=(y)>>4, (y)|=(y)>>8, (y)|=(y)>>16, ++(y));
 if (x < y) header->text = (char*)realloc(header->text, y);
 strncpy(header->text + header->l_text, text, len);
 header->l_text += len;
 header->text[header->l_text] = 0;
}

canonical_original_code:
static void append_header_text(struct bam_header_t *header, char *text, int len)
{
 int x = header->l_text + 1;
 int y = header->l_text + len + 1;
 if (text == 0) return;
 (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x));
 (--(y), (y)|=(y)>>1, (y)|=(y)>>2, (y)|=(y)>>4, (y)|=(y)>>8, (y)|=(y)>>16, ++(y));
 if (x < y) header->text = (char *)realloc(header->text, y);
 strncpy(header->text + header->l_text, text, len);
 header->l_text += len;
 header->text[header->l_text] = 0;
}

variable_types: struct bam_header_t { int n_targets; char **target_name; unsigned int *target_len; void *dict; unsigned long l_text; char *text; } *

variable_types:
text
char *

variable_types: len int

return_type: void


samfaipath

decompiled_code:
char *__fastcall samfaipath(char *name)
{
size_t v1; // rax
char *v2; // r12

if ( !name )
return 0LL;
v1 = strlen(name);
v2 = (char *)calloc(v1 + 5, 1uLL);
strcpy(v2, name);
strcat(v2, ".fai");
if ( access(v2, 4) == -1 )
{
if ( access(name, 4) == -1 )
{
fprintf(stderr, "[samfaipath] fail to read file %s.\n", name);
}
else
{
if ( bam_verbose > 2 )
fwrite("[samfaipath] build FASTA index...\n", 1uLL, 0x22uLL, stderr);
if ( (unsigned int)fai_build(name) == -1 )
{
fwrite("[samfaipath] fail to build FASTA index.\n", 1uLL, 0x28uLL, stderr);
free(v2);
v2 = 0LL;
}
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func5(char *name)
{
size_t v1; // rax
char *v2; // r12

if ( !name )
return 0LL;
v1 = strlen(name);
v2 = (char *)calloc(v1 + 5, 1uLL);
strcpy(v2, name);
strcat(v2, ".fai");
if ( access(v2, 4) == -1 )
{
if ( access(name, 4) == -1 )
{
fprintf(stderr, "[samfaipath] fail to read file %s.\n", name);
}
else
{
if ( bam_verbose > 2 )
fwrite("[samfaipath] build FASTA index...\n", 1uLL, 0x22uLL, stderr);
if ( (unsigned int)fai_build(name) == -1 )
{
fwrite("[samfaipath] fail to build FASTA index.\n", 1uLL, 0x28uLL, stderr);
free(v2);
v2 = 0LL;
}
}
}
return v2;
}

original_code:
char *samfaipath(const char *fn_ref)
{
 char *fn_list = 0;
 if (fn_ref == 0) return 0;
 fn_list = calloc(strlen(fn_ref) + 5, 1);
 strcat(strcpy(fn_list, fn_ref), ".fai");
 if (access(fn_list, 4) == -1) {
  if (access(fn_ref, 4) == -1) {
   fprintf(stderr, "[samfaipath] fail to read file %s.\n", fn_ref);
  } else {
   if (bam_verbose >= 3) fprintf(stderr, "[samfaipath] build FASTA index...\n");
   if (fai_build(fn_ref) == -1) {
    fprintf(stderr, "[samfaipath] fail to build FASTA index.\n");
    free(fn_list); fn_list = 0;
   }
  }
 }
 return fn_list;
}

canonical_original_code:
char *samfaipath(char *fn_ref)
{
 char *fn_list = 0;
 if (fn_ref == 0) return 0;
 fn_list = calloc(strlen(fn_ref) + 5, 1);
 strcat(strcpy(fn_list, fn_ref), ".fai");
 if (access(fn_list, 4) == -1) {
  if (access(fn_ref, 4) == -1) {
   fprintf(stderr, "[samfaipath] fail to read file %s.\n", fn_ref);
  } else {
   if (bam_verbose >= 3) fprintf(stderr, "[samfaipath] build FASTA index...\n");
   if (fai_build(fn_ref) == -1) {
    fprintf(stderr, "[samfaipath] fail to build FASTA index.\n");
    free(fn_list); fn_list = 0;
   }
  }
 }
 return fn_list;
}


original_code:
double kmin_hj(kmin_f func, int n, double *x, void *data, double r, double eps, int max_calls)
{
 double fx, fx1, *x1, *dx, radius;
 int k, n_calls = 0;
 x1 = (double*)calloc(n, sizeof(double));
 dx = (double*)calloc(n, sizeof(double));
 for (k = 0; k != n; ++k) {
  dx[k] = fabs(x[k]) * r;
  if (dx[k] == 0) dx[k] = r;
 }
 radius = r;
 fx1 = fx = func(n, x, data); ++n_calls;
 for (;;) {
  memcpy(x1, x, n * sizeof(double));
  fx1 = __kmin_hj_aux(func, n, x1, data, fx, dx, &n_calls);
  while (fx1 < fx) {
   for (k = 0; k != n; ++k) {
    double t = x[k];
    dx[k] = x1[k] > x[k]? fabs(dx[k]) : 0.0 - fabs(dx[k]);
    x[k] = x1[k];
    x1[k] = x1[k] + x1[k] - t;
   }
   fx = fx1;
   if (n_calls >= max_calls) break;
   fx1 = func(n, x1, data); ++n_calls;
   fx1 = __kmin_hj_aux(func, n, x1, data, fx1, dx, &n_calls);
   if (fx1 >= fx) break;
   for (k = 0; k != n; ++k)
    if (fabs(x1[k] - x[k]) > .5 * fabs(dx[k])) break;
   if (k == n) break;
  }
  if (radius >= eps) {
   if (n_calls >= max_calls) break;
   radius *= r;
   for (k = 0; k != n; ++k) dx[k] *= r;
  } else break;
 }
 free(x1); free(dx);
 return fx1;
}

canonical_original_code:
double kmin_hj(double (*func)(int, double *, void *), int n, double *x, void *data, double r, double eps, int max_calls)
{
 double fx; double fx1; double *x1; double *dx; double radius;
 int k; int n_calls = 0;
 x1 = (double *)calloc(n, sizeof(double));
 dx = (double *)calloc(n, sizeof(double));
 for (k = 0; k != n; ++k) {
  dx[k] = fabs(x[k]) * r;
  if (dx[k] == 0) dx[k] = r;
 }
 radius = r;
 fx1 = fx = func(n, x, data); ++n_calls;
 for (;;) {
  memcpy(x1, x, n * sizeof(double));
  fx1 = __kmin_hj_aux(func, n, x1, data, fx, dx, &n_calls);
  while (fx1 < fx) {
   for (k = 0; k != n; ++k) {
    double t = x[k];
    dx[k] = x1[k] > x[k]? fabs(dx[k]) : 0.0 - fabs(dx[k]);
    x[k] = x1[k];
    x1[k] = x1[k] + x1[k] - t;
   }
   fx = fx1;
   if (n_calls >= max_calls) break;
   fx1 = func(n, x1, data); ++n_calls;
   fx1 = __kmin_hj_aux(func, n, x1, data, fx1, dx, &n_calls);
   if (fx1 >= fx) break;
   for (k = 0; k != n; ++k)
    if (fabs(x1[k] - x[k]) > .5 * fabs(dx[k])) break;
   if (k == n) break;
  }
  if (radius >= eps) {
   if (n_calls >= max_calls) break;
   radius *= r;
   for (k = 0; k != n; ++k) dx[k] *= r;
  } else break;
 }
 free(x1); free(dx);
 return fx1;
}

variable_types:
func
double (*)(int, double *, void *)

variable_types: n int

variable_types:
x
double *

variable_types:
data
void *

variable_types: r double

variable_types: eps double

variable_types: fx double

variable_types:
dx
double *

variable_types: radius double

variable_types: k int

variable_types: t double

return_type: double


repo: pervouchine/sjcount

canonical_original_code:
static void process_cns(struct bam_header_t *h, int tid, int l, unsigned short *cns)
{
 int i; int f[2][2]; int *prev; int *curr; int *swap_tmp; int s;
 unsigned char *b;
 b = calloc(l, 1);
 f[0][0] = f[0][1] = 0;
 prev = f[0]; curr = f[1];
 for (i = 0; i < l; ++i) {
  int c = (cns[i] == 0)? 0 : (cns[i]>>8 == 0)? 1 : 2;
  int tmp0; int tmp1;
  tmp0 = prev[0] + g_param.e[0][c] + g_param.p[0][0];
  tmp1 = prev[1] + g_param.e[0][c] + g_param.p[1][0];
  if (tmp0 > tmp1) curr[0] = tmp0, b[i] = 0;
  else curr[0] = tmp1, b[i] = 1;
  tmp0 = prev[0] + g_param.e[1][c] + g_param.p[0][1];
  tmp1 = prev[1] + g_param.e[1][c] + g_param.p[1][1];
  if (tmp0 > tmp1) curr[1] = tmp0, b[i] |= 0<<1;
  else curr[1] = tmp1, b[i] |= 1<<1;
  swap_tmp = prev; prev = curr; curr = swap_tmp;
 }
 s = prev[0] > prev[1]? 0 : 1;
 for (i = l - 1; i > 0; --i) {
  b[i] |= s<<2;
  s = b[i]>>s&1;
 }
 for (i = 0, s = -1; i <= l; ++i) {
  if (i == l || ((b[i]>>2&3) == 0 && s >= 0)) {
   if (s >= 0) {
    int j;
    printf("%s:%d-%d\t0\t%s\t%d\t60\t%dM\t*\t0\t0\t", h->target_name[tid], s+1, i, h->target_name[tid], s+1, i-s);
    for (j = s; j < i; ++j) {
     int c = cns[j]>>8;
     if (c == 0) putchar('N');
     else putchar("ACGT"[c&3]);
    }
    putchar('\t');
    for (j = s; j < i; ++j)
     putchar(33 + (cns[j]>>8>>2));
    putchar('\n');
   }
   s = -1;
  } else if ((b[i]>>2&3) && s < 0) s = i;
 }
 free(b);
}

variable_types: tid int

variable_types: l int

variable_types:
cns
unsigned short *

variable_types: i int

variable_types:
prev
int *

variable_types:
curr
int *

variable_types: s int

variable_types:
b
unsigned char *

variable_types: c int

variable_types: j int

user_defined_types: struct bam_header_t { int n_targets; char **target_name; unsigned int *target_len; void *dict; unsigned long l_text; char *text; }


decompiled_code:
__int64 bam_is_big_endian()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
static inline int bam_is_big_endian()
{
 long one= 1;
 return !(*((char *)(&one)));
}

canonical_original_code:
static inline int bam_is_big_endian()
{
 long one = 1;
 return !(*((char *)(&one)));
}

variable_types: one long


decompiled_code:
__int64 __fastcall bam_swap_endian_4(int a1)
{
unsigned int v1; // edi

v1 = __ROL4__(a1, 16);
return (v1 >> 8) & 0xFF00FF | (v1 << 8) & 0xFF00FF00;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // edi

v1 = __ROL4__(a1, 16);
return (v1 >> 8) & 0xFF00FF | (v1 << 8) & 0xFF00FF00;
}

original_code:
static inline uint32_t bam_swap_endian_4(uint32_t v)
{
 v = ((v & 0x0000FFFFU) << 16) | (v >> 16);
 return ((v & 0x00FF00FFU) << 8) | ((v & 0xFF00FF00U) >> 8);
}

canonical_original_code:
static inline unsigned int bam_swap_endian_4(unsigned int v)
{
 v = ((v & 0x0000FFFFU) << 16) | (v >> 16);
 return ((v & 0x00FF00FFU) << 8) | ((v & 0xFF00FF00U) >> 8);
}

variable_types:
v
unsigned int

return_type: unsigned int


decompiled_code:
unsigned __int64 __fastcall bam_swap_endian_8(__int64 a1)
{
unsigned __int64 v1; // rdi
unsigned __int64 v2; // rax

v1 = __ROL8__(a1, 32);
v2 = (v1 >> 16) & 0xFFFF0000FFFFLL | (v1 << 16) & 0xFFFF0000FFFF0000LL;
return (v2 << 8) & 0xFF00FF00FF00FF00LL | (v2 >> 8) & 0xFF00FF00FF00FFLL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // rdi
unsigned __int64 v2; // rax

v1 = __ROL8__(a1, 32);
v2 = (v1 >> 16) & 0xFFFF0000FFFFLL | (v1 << 16) & 0xFFFF0000FFFF0000LL;
return (v2 << 8) & 0xFF00FF00FF00FF00LL | (v2 >> 8) & 0xFF00FF00FF00FFLL;
}

canonical_original_code:
static inline unsigned long bam_swap_endian_8(unsigned long v)
{
 v = ((v & 0x00000000FFFFFFFFLLU) << 32) | (v >> 32);
 v = ((v & 0x0000FFFF0000FFFFLLU) << 16) | ((v & 0xFFFF0000FFFF0000LLU) >> 16);
 return ((v & 0x00FF00FF00FF00FFLLU) << 8) | ((v & 0xFF00FF00FF00FF00LLU) >> 8);
}

variable_types:
v
unsigned long

return_type: unsigned long


decompiled_code:
char *__fastcall get_local_version(char *src)
{
size_t v1; // rax
char *v2; // rbx
unsigned __int64 i; // rdi
char *v5; // rbp
struct stat64 v6; // [rsp+0h] [rbp-A8h] BYREF

v1 = strlen(src);
v2 = (char *)calloc(v1 + 5, 1uLL);
strcpy(v2, src);
strcat(v2, ".bci");
if ( v2 == strstr(v2, "ftp://") || v2 == strstr(v2, "http://") )
{
for ( i = (unsigned __int64)&v2[(int)strlen(v2) - 1]; (unsigned __int64)v2 <= i; --i )
{
if ( *(_BYTE *)i == 47 )
break;
}
v5 = strdup((const char *)(i + 1));
if ( !stat64(v5, &v6) )
{
free(v2);
return v5;
}
fprintf(stderr, "[%s] downloading the index file...\n", "get_local_version");
download_from_remote(v2);
free(v2);
v2 = v5;
}
if ( stat64(v2, &v6) )
{
free(v2);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func7(char *src)
{
size_t v1; // rax
char *v2; // rbx
unsigned __int64 i; // rdi
char *v5; // rbp
struct stat64 v6; // [rsp+0h] [rbp-A8h] BYREF

v1 = strlen(src);
v2 = (char *)calloc(v1 + 5, 1uLL);
strcpy(v2, src);
strcat(v2, ".bci");
if ( v2 == strstr(v2, "ftp://") || v2 == strstr(v2, "http://") )
{
for ( i = (unsigned __int64)&v2[(int)strlen(v2) - 1]; (unsigned __int64)v2 <= i; --i )
{
if ( *(_BYTE *)i == 47 )
break;
}
v5 = strdup((const char *)(i + 1));
if ( !stat64(v5, &v6) )
{
free(v2);
return v5;
}
fprintf(stderr, "[%s] downloading the index file...\n", "get_local_version");
func6(v2);
free(v2);
v2 = v5;
}
if ( stat64(v2, &v6) )
{
free(v2);
v2 = 0LL;
}
return v2;
}

original_code:
static char *get_local_version(const char *fn)
{
    struct stat sbuf;
 char *fnidx = (char*)calloc(strlen(fn) + 5, 1);
 strcat(strcpy(fnidx, fn), ".bci");
 if ((strstr(fnidx, "ftp://") == fnidx || strstr(fnidx, "http://") == fnidx)) {
  char *p, *url;
  int l = strlen(fnidx);
  for (p = fnidx + l - 1; p >= fnidx; --p)
   if (*p == '/') break;
  url = fnidx; fnidx = strdup(p + 1);
  if (stat(fnidx, &sbuf) == 0) {
   free(url);
   return fnidx;
  }
  fprintf(stderr, "[%s] downloading the index file...\n", __func__);
  download_from_remote(url);
  free(url);
 }
    if (stat(fnidx, &sbuf) == 0) return fnidx;
 free(fnidx); return 0;
}

canonical_original_code:
static char *get_local_version(char *fn)
{
    struct stat sbuf;
 char *fnidx = (char*)calloc(strlen(fn) + 5, 1);
 strcat(strcpy(fnidx, fn), ".bci");
 if ((strstr(fnidx, "ftp://") == fnidx || strstr(fnidx, "http://") == fnidx)) {
  char *p; char *url;
  int l = strlen(fnidx);
  for (p = fnidx + l - 1; p >= fnidx; --p)
   if (*p == '/') break;
  url = fnidx; fnidx = strdup(p + 1);
  if (stat(fnidx, &sbuf) == 0) {
   free(url);
   return fnidx;
  }
  fprintf(stderr, "[%s] downloading the index file...\n", __func__);
  download_from_remote(url);
  free(url);
 }
    if (stat(fnidx, &sbuf) == 0) return fnidx;
 free(fnidx); return 0;
}

variable_types:
fn
char *

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

variable_types:
fnidx
char *

variable_types:
p
char *

variable_types:
url
char *

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


decompiled_code:
void __fastcall bcf_idx_destroy(void *ptr)
{
__int64 v1; // rbx

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 1) + 16 * v1++ + 8));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
__int64 v1; // rbx

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 1) + 16 * v1++ + 8));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void bcf_idx_destroy(bcf_idx_t *idx)
{
 int i;
 if (idx == 0) return;
 for (i = 0; i < idx->n; ++i) free(idx->index2[i].offset);
 free(idx->index2);
 free(idx);
}

canonical_original_code:
void bcf_idx_destroy(struct __bcf_idx_t *idx)
{
 int i;
 if (idx == 0) return;
 for (i = 0; i < idx->n; ++i) free(idx->index2[i].offset);
 free(idx->index2);
 free(idx);
}

variable_types: struct __bcf_idx_t { int n; struct bcf_lidx_t { int n; unsigned long *offset; } *index2; } *

user_defined_types: struct __bcf_idx_t { int n; struct bcf_lidx_t *index2; }


decompiled_code:
int *__fastcall bcf_idx_load(char *a1)
{
char *v1; // rax
char *v2; // rbx
int *v3; // rbp

v1 = get_local_version(a1);
v2 = v1;
if ( !v1 )
return 0LL;
v3 = bcf_idx_load_local((__int64)v1);
free(v2);
return v3;
}

canonical_decompiled_code:
int *__fastcall func10(char *a1)
{
char *v1; // rax
char *v2; // rbx
int *v3; // rbp

v1 = func7(a1);
v2 = v1;
if ( !v1 )
return 0LL;
v3 = func9((__int64)v1);
free(v2);
return v3;
}

original_code:
bcf_idx_t *bcf_idx_load(const char *fn)
{
 bcf_idx_t *idx;
    char *fname = get_local_version(fn);
 if (fname == 0) return 0;
 idx = bcf_idx_load_local(fname);
    free(fname);
 return idx;
}

canonical_original_code:
struct __bcf_idx_t *bcf_idx_load(char *fn)
{
 struct __bcf_idx_t *idx;
    char *fname = get_local_version(fn);
 if (fname == 0) return 0;
 idx = bcf_idx_load_local(fname);
    free(fname);
 return idx;
}

variable_types:
fname
char *

return_type: struct __bcf_idx_t { int n; struct bcf_lidx_t { int n; unsigned long *offset; } *index2; } *


original_code:
uint64_t bcf_idx_query(const bcf_idx_t *idx, int tid, int beg)
{
 uint64_t min_off, *offset;
 int i;
 if (beg < 0) beg = 0;
 offset = idx->index2[tid].offset;
 for (i = beg>>13; i < idx->index2[tid].n && offset[i] == 0; ++i);
 min_off = (i == idx->index2[tid].n)? offset[idx->index2[tid].n-1] : offset[i];
 return min_off;
}

canonical_original_code:
unsigned long bcf_idx_query(struct __bcf_idx_t *idx, int tid, int beg)
{
 unsigned long min_off; unsigned long *offset;
 int i;
 if (beg < 0) beg = 0;
 offset = idx->index2[tid].offset;
 for (i = beg>>13; i < idx->index2[tid].n && offset[i] == 0; ++i);
 min_off = (i == idx->index2[tid].n)? offset[idx->index2[tid].n-1] : offset[i];
 return min_off;
}

variable_types: tid int

variable_types: beg int

variable_types:
offset
unsigned long *

variable_types: i int

user_defined_types: struct bcf_lidx_t { int n; unsigned long *offset; }


decompiled_code:
__int64 __fastcall bcf_idx_build(char *a1)
{
return bcf_idx_build2(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1)
{
return func11(a1, 0LL);
}

original_code:
int bcf_idx_build(const char *fn)
{
 return bcf_idx_build2(fn, 0);
}

canonical_original_code:
int bcf_idx_build(char *fn)
{
 return bcf_idx_build2(fn, 0);
}


original_code:
int bcf_parse_region(void *str2id, const char *str, int *tid, int *begin, int *end)
{
 char *s, *p;
 int i, l, k;
 l = strlen(str);
 p = s = (char*)malloc(l+1);
 for (i = k = 0; i != l; ++i)
  if (str[i] != ',' && !((*__ctype_b_loc ())[(int) ((str[i]))] & (unsigned short int) _ISspace)) s[k++] = str[i];
 s[k] = 0;
 for (i = 0; i != k; ++i) if (s[i] == ':') break;
 s[i] = 0;
 if ((*tid = bcf_str2id(str2id, s)) < 0) {
  free(s);
  return -1;
 }
 if (i == k) {
  *begin = 0; *end = 1<<29; free(s);
  return 0;
 }
 for (p = s + i + 1; i != k; ++i) if (s[i] == '-') break;
 *begin = atoi(p);
 if (i < k) {
  p = s + i + 1;
  *end = atoi(p);
 } else *end = 1<<29;
 if (*begin > 0) --*begin;
 free(s);
 if (*begin > *end) return -1;
 return 0;
}

canonical_original_code:
int bcf_parse_region(void *str2id, char *str, int *tid, int *begin, int *end)
{
 char *s; char *p;
 int i; int l; int k;
 l = strlen(str);
 p = s = (char *)malloc(l+1);
 for (i = k = 0; i != l; ++i)
  if (str[i] != ',' && !((*__ctype_b_loc ())[(int) ((str[i]))] & (unsigned short) _ISspace)) s[k++] = str[i];
 s[k] = 0;
 for (i = 0; i != k; ++i) if (s[i] == ':') break;
 s[i] = 0;
 if ((*tid = bcf_str2id(str2id, s)) < 0) {
  free(s);
  return -1;
 }
 if (i == k) {
  *begin = 0; *end = 1<<29; free(s);
  return 0;
 }
 for (p = s + i + 1; i != k; ++i) if (s[i] == '-') break;
 *begin = atoi(p);
 if (i < k) {
  p = s + i + 1;
  *end = atoi(p);
 } else *end = 1<<29;
 if (*begin > 0) --*begin;
 free(s);
 if (*begin > *end) return -1;
 return 0;
}

variable_types:
str
char *

variable_types:
tid
int *

variable_types:
begin
int *

variable_types:
end
int *

variable_types:
s
char *

variable_types: l int

variable_types: k int


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

if ( a1 == 1 )
{
fwrite("Usage: bcftools index <in.bcf>\n", 1uLL, 0x1FuLL, stderr);
result = 1LL;
}
else
{
bcf_idx_build(*(char **)(a2 + 8));
result = 0LL;
}
return result;
}

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

if ( a1 == 1 )
{
fwrite("Usage: bcftools index <in.bcf>\n", 1uLL, 0x1FuLL, stderr);
result = 1LL;
}
else
{
func12(*(char **)(a2 + 8));
result = 0LL;
}
return result;
}

original_code:
int bcf_main_index(int argc, char *argv[])
{
 if (argc == 1) {
  fprintf(stderr, "Usage: bcftools index <in.bcf>\n");
  return 1;
 }
 bcf_idx_build(argv[1]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall bam_aux_getCSi(__int64 a1, int a2)
{
__int64 v3; // rdi
__int64 result; // rax
const char *v5; // r12
int v6; // eax

v3 = bam_aux_get(a1, &unk_2F6);
result = 0LL;
if ( v3 )
{
v5 = (const char *)bam_aux2Z();
v6 = a2 + 1;
if ( (*(_BYTE *)(a1 + 12) & 0x10) != 0 )
v6 = ~a2 + strlen(v5);
result = (unsigned __int8)v5[v6];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v3; // rdi
__int64 result; // rax
const char *v5; // r12
int v6; // eax

v3 = bam_aux_get(a1, &unk_2F6);
result = 0LL;
if ( v3 )
{
v5 = (const char *)bam_aux2Z();
v6 = a2 + 1;
if ( (*(_BYTE *)(a1 + 12) & 0x10) != 0 )
v6 = ~a2 + strlen(v5);
result = (unsigned __int8)v5[v6];
}
return result;
}

original_code:
char bam_aux_getCSi(bam1_t *b, int i)
{
 uint8_t *c = bam_aux_get(b, "CS");
 char *cs = ((void *)0);
 if(0 == c) return 0;
 cs = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) i = strlen(cs) - 1 - i;
 else i++;
 return cs[i];
}

canonical_original_code:
char bam_aux_getCSi(struct bam1_t *b, int i)
{
 unsigned char *c = bam_aux_get(b, "CS");
 char *cs = ((void *)0);
 if(0 == c) return 0;
 cs = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) i = strlen(cs) - 1 - i;
 else i++;
 return cs[i];
}

variable_types: struct bam1_t { struct bam1_core_t { int tid; int pos; unsigned int bin; unsigned int flag; int l_qseq; int mtid; int mpos; int isize; } core; int l_aux; unsigned char *data; } *

variable_types:
c
unsigned char *

variable_types:
cs
char *

return_type: char

user_defined_types: struct bam1_t { struct bam1_core_t core; int l_aux; unsigned char *data; }


decompiled_code:
__int64 __fastcall bam_aux_getCQi(__int64 a1, int a2)
{
int v3; // ebx
__int64 v4; // rdi
__int64 result; // rax
const char *v6; // rax
const char *v7; // r12

v3 = a2;
v4 = bam_aux_get(a1, &unk_2F9);
result = 0LL;
if ( v4 )
{
v6 = (const char *)bam_aux2Z();
v7 = v6;
if ( (*(_BYTE *)(a1 + 12) & 0x10) != 0 )
v3 = strlen(v6) + ~a2;
result = (unsigned __int8)v7[v3];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v3; // ebx
__int64 v4; // rdi
__int64 result; // rax
const char *v6; // rax
const char *v7; // r12

v3 = a2;
v4 = bam_aux_get(a1, &unk_2F9);
result = 0LL;
if ( v4 )
{
v6 = (const char *)bam_aux2Z();
v7 = v6;
if ( (*(_BYTE *)(a1 + 12) & 0x10) != 0 )
v3 = strlen(v6) + ~a2;
result = (unsigned __int8)v7[v3];
}
return result;
}

original_code:
char bam_aux_getCQi(bam1_t *b, int i)
{
 uint8_t *c = bam_aux_get(b, "CQ");
 char *cq = ((void *)0);
 if(0 == c) return 0;
 cq = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) i = strlen(cq) - 1 - i;
 return cq[i];
}

canonical_original_code:
char bam_aux_getCQi(struct bam1_t *b, int i)
{
 unsigned char *c = bam_aux_get(b, "CQ");
 char *cq = ((void *)0);
 if(0 == c) return 0;
 cq = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) i = strlen(cq) - 1 - i;
 return cq[i];
}

variable_types:
cq
char *

user_defined_types: struct bam1_core_t { int tid; int pos; unsigned int bin; unsigned int flag; int l_qseq; int mtid; int mpos; int isize; }


original_code:
char bam_aux_getCEi(bam1_t *b, int i)
{
 int cs_i;
 uint8_t *c = bam_aux_get(b, "CS");
 char *cs = ((void *)0);
 char prev_b, cur_b;
 char cur_color, cor_color;
 if(0 == c) return 0;
 cs = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) {
  cs_i = strlen(cs) - 1 - i;
  cur_color = cs[cs_i];
  prev_b = (cs_i == 1) ? "TGCAN"[(int)bam_aux_nt2int(cs[0])] : bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i+1)/2] >> 4*(1-(i+1)%2) & 0xf)];
  cur_b = bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i)/2] >> 4*(1-(i)%2) & 0xf)];
 }
 else {
  cs_i=i+1;
  cur_color = cs[cs_i];
  prev_b = (0 == i) ? cs[0] : bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i-1)/2] >> 4*(1-(i-1)%2) & 0xf)];
  cur_b = bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i)/2] >> 4*(1-(i)%2) & 0xf)];
 }
 cor_color = bam_aux_ntnt2cs(prev_b, cur_b);
 if(cur_color == cor_color) {
  return '-';
 }
 else {
  return cur_color;
 }
}

canonical_original_code:
char bam_aux_getCEi(struct bam1_t *b, int i)
{
 int cs_i;
 unsigned char *c = bam_aux_get(b, "CS");
 char *cs = ((void *)0);
 char prev_b; char cur_b;
 char cur_color; char cor_color;
 if(0 == c) return 0;
 cs = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) {
  cs_i = strlen(cs) - 1 - i;
  cur_color = cs[cs_i];
  prev_b = (cs_i == 1) ? "TGCAN"[(int)bam_aux_nt2int(cs[0])] : bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i+1)/2] >> 4*(1-(i+1)%2) & 0xf)];
  cur_b = bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i)/2] >> 4*(1-(i)%2) & 0xf)];
 }
 else {
  cs_i=i+1;
  cur_color = cs[cs_i];
  prev_b = (0 == i) ? cs[0] : bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i-1)/2] >> 4*(1-(i-1)%2) & 0xf)];
  cur_b = bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i)/2] >> 4*(1-(i)%2) & 0xf)];
 }
 cor_color = bam_aux_ntnt2cs(prev_b, cur_b);
 if(cur_color == cor_color) {
  return '-';
 }
 else {
  return cur_color;
 }
}


decompiled_code:
__int64 __fastcall bam_aux_nt2int(char a1)
{
const __int32_t *v1; // rax
int v2; // edx
__int64 result; // rax

v1 = *_ctype_toupper_loc();
v2 = v1[a1];
if ( v2 == 71 )
return 2LL;
if ( v2 > 71 )
{
LOBYTE(v1) = v2 != 84;
result = (unsigned int)((_DWORD)v1 + 3);
}
else
{
result = 0LL;
if ( v2 != 65 )
{
LOBYTE(result) = v2 != 67;
result = (unsigned int)(3 * result + 1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
const __int32_t *v1; // rax
int v2; // edx
__int64 result; // rax

v1 = *_ctype_toupper_loc();
v2 = v1[a1];
if ( v2 == 71 )
return 2LL;
if ( v2 > 71 )
{
LOBYTE(v1) = v2 != 84;
result = (unsigned int)((_DWORD)v1 + 3);
}
else
{
result = 0LL;
if ( v2 != 65 )
{
LOBYTE(result) = v2 != 67;
result = (unsigned int)(3 * result + 1);
}
}
return result;
}

original_code:
char bam_aux_nt2int(char a)
{
 switch(toupper(a)) {
  case 'A':
   return 0;
   break;
  case 'C':
   return 1;
   break;
  case 'G':
   return 2;
   break;
  case 'T':
   return 3;
   break;
  default:
   return 4;
   break;
 }
}

variable_types: a char


decompiled_code:
__int64 __fastcall bam_aux_ntnt2cs(char a1, char a2)
{
char v2; // bl
char v3; // al
__int64 result; // rax

v2 = bam_aux_nt2int(a1);
v3 = bam_aux_nt2int(a2);
if ( v2 == 4 || v3 == 4 )
result = 52LL;
else
result = (unsigned __int8)byte_2FC[(char)(v3 ^ v2)];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, char a2)
{
char v2; // bl
char v3; // al
__int64 result; // rax

v2 = func2(a1);
v3 = func2(a2);
if ( v2 == 4 || v3 == 4 )
result = 52LL;
else
result = (unsigned __int8)byte_2FC[(char)(v3 ^ v2)];
return result;
}

original_code:
char bam_aux_ntnt2cs(char a, char b)
{
 a = bam_aux_nt2int(a);
 b = bam_aux_nt2int(b);
 if(4 == a || 4 == b) return '4';
 return "0123"[(int)(a ^ b)];
}

variable_types: b char


ksprintf

original_code:
int ksprintf(kstring_t *s, const char *fmt, ...)
{
 va_list ap;
 int l;
 __builtin_va_start(ap,fmt);
 l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
 __builtin_va_end(ap);
 if (l + 1 > s->m - s->l) {
  s->m = s->l + l + 2;
  (--(s->m), (s->m)|=(s->m)>>1, (s->m)|=(s->m)>>2, (s->m)|=(s->m)>>4, (s->m)|=(s->m)>>8, (s->m)|=(s->m)>>16, ++(s->m));
  s->s = (char*)realloc(s->s, s->m);
  __builtin_va_start(ap,fmt);
  l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
 }
 __builtin_va_end(ap);
 s->l += l;
 return l;
}

canonical_original_code:
int ksprintf(struct __kstring_t *s, char *fmt, ...)
{
 __builtin_va_list ap;
 int l;
 __builtin_va_start(ap,fmt);
 l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
 __builtin_va_end(ap);
 if (l + 1 > s->m - s->l) {
  s->m = s->l + l + 2;
  (--(s->m), (s->m)|=(s->m)>>1, (s->m)|=(s->m)>>2, (s->m)|=(s->m)>>4, (s->m)|=(s->m)>>8, (s->m)|=(s->m)>>16, ++(s->m));
  s->s = (char *)realloc(s->s, s->m);
  __builtin_va_start(ap,fmt);
  l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
 }
 __builtin_va_end(ap);
 s->l += l;
 return l;
}

variable_types: struct __kstring_t { unsigned long l; char *s; } *

variable_types:
fmt
char *


kstrtok

original_code:
char *kstrtok(const char *str, const char *sep, ks_tokaux_t *aux)
{
 const char *p, *start;
 if (sep) {
  if (str == 0 && (aux->tab[0]&1)) return 0;
  aux->finished = 0;
  if (sep[1]) {
   aux->sep = -1;
   aux->tab[0] = aux->tab[1] = aux->tab[2] = aux->tab[3] = 0;
   for (p = sep; *p; ++p) aux->tab[*p>>6] |= 1ull<<(*p&0x3f);
  } else aux->sep = sep[0];
 }
 if (aux->finished) return 0;
 else if (str) aux->p = str - 1, aux->finished = 0;
 if (aux->sep < 0) {
  for (p = start = aux->p + 1; *p; ++p)
   if (aux->tab[*p>>6]>>(*p&0x3f)&1) break;
 } else {
  for (p = start = aux->p + 1; *p; ++p)
   if (*p == aux->sep) break;
 }
 aux->p = p;
 if (*p == 0) aux->finished = 1;
 return (char*)start;
}

canonical_original_code:
char *kstrtok(char *str, char *sep, struct ks_tokaux_t *aux)
{
 char *p; char *start;
 if (sep) {
  if (str == 0 && (aux->tab[0]&1)) return 0;
  aux->finished = 0;
  if (sep[1]) {
   aux->sep = -1;
   aux->tab[0] = aux->tab[1] = aux->tab[2] = aux->tab[3] = 0;
   for (p = sep; *p; ++p) aux->tab[*p>>6] |= 1ull<<(*p&0x3f);
  } else aux->sep = sep[0];
 }
 if (aux->finished) return 0;
 else if (str) aux->p = str - 1, aux->finished = 0;
 if (aux->sep < 0) {
  for (p = start = aux->p + 1; *p; ++p)
   if (aux->tab[*p>>6]>>(*p&0x3f)&1) break;
 } else {
  for (p = start = aux->p + 1; *p; ++p)
   if (*p == aux->sep) break;
 }
 aux->p = p;
 if (*p == 0) aux->finished = 1;
 return (char *)start;
}

variable_types:
str
char *

variable_types:
sep
char *

variable_types: struct ks_tokaux_t { unsigned long tab[4]; int sep; char *p; } *

variable_types:
p
char *

variable_types:
start
char *


original_code:
int ksplit_core(char *s, int delimiter, int *_max, int **_offsets)
{
 int i, n, max, last_char, last_start, *offsets, l;
 n = 0; max = *_max; offsets = *_offsets;
 l = strlen(s);
 for (i = 0, last_char = last_start = 0; i <= l; ++i) {
  if (delimiter == 0) {
   if (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISspace) || s[i] == 0) {
    if (((*__ctype_b_loc ())[(int) ((last_char))] & (unsigned short int) _ISgraph)) do { if (_offsets) { s[i] = 0; if (n == max) { max = max? max<<1 : 2; offsets = (int*)realloc(offsets, sizeof(int) * max); } offsets[n++] = last_start; } else ++n; } while (0);
   } else {
    if (((*__ctype_b_loc ())[(int) ((last_char))] & (unsigned short int) _ISspace) || last_char == 0) last_start = i;
   }
  } else {
   if (s[i] == delimiter || s[i] == 0) {
    if (last_char != 0 && last_char != delimiter) do { if (_offsets) { s[i] = 0; if (n == max) { max = max? max<<1 : 2; offsets = (int*)realloc(offsets, sizeof(int) * max); } offsets[n++] = last_start; } else ++n; } while (0);
   } else {
    if (last_char == delimiter || last_char == 0) last_start = i;
   }
  }
  last_char = s[i];
 }
 *_max = max; *_offsets = offsets;
 return n;
}

canonical_original_code:
int ksplit_core(char *s, int delimiter, int *_max, int **_offsets)
{
 int i; int n; int max; int last_char; int last_start; int *offsets; int l;
 n = 0; max = *_max; offsets = *_offsets;
 l = strlen(s);
 for (i = 0, last_char = last_start = 0; i <= l; ++i) {
  if (delimiter == 0) {
   if (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISspace) || s[i] == 0) {
    if (((*__ctype_b_loc ())[(int) ((last_char))] & (unsigned short) _ISgraph)) do { if (_offsets) { s[i] = 0; if (n == max) { max = max? max<<1 : 2; offsets = (int *)realloc(offsets, sizeof(int) * max); } offsets[n++] = last_start; } else ++n; } while (0);
   } else {
    if (((*__ctype_b_loc ())[(int) ((last_char))] & (unsigned short) _ISspace) || last_char == 0) last_start = i;
   }
  } else {
   if (s[i] == delimiter || s[i] == 0) {
    if (last_char != 0 && last_char != delimiter) do { if (_offsets) { s[i] = 0; if (n == max) { max = max? max<<1 : 2; offsets = (int *)realloc(offsets, sizeof(int) * max); } offsets[n++] = last_start; } else ++n; } while (0);
   } else {
    if (last_char == delimiter || last_char == 0) last_start = i;
   }
  }
  last_char = s[i];
 }
 *_max = max; *_offsets = offsets;
 return n;
}

variable_types:
s
char *

variable_types: delimiter int

variable_types: i int

variable_types: n int

variable_types: max int

variable_types:
offsets
int *

variable_types: l int


kmemmem

original_code:
void *kmemmem(const void *_str, int n, const void *_pat, int m, int **_prep)
{
 int i, j, *prep = 0, *bmGs, *bmBc;
 const ubyte_t *str, *pat;
 str = (const ubyte_t*)_str; pat = (const ubyte_t*)_pat;
 prep = (_prep == 0 || *_prep == 0)? ksBM_prep(pat, m) : *_prep;
 if (_prep && *_prep == 0) *_prep = prep;
 bmGs = prep; bmBc = prep + m;
 j = 0;
 while (j <= n - m) {
  for (i = m - 1; i >= 0 && pat[i] == str[i+j]; --i);
  if (i >= 0) {
   int max = bmBc[str[i+j]] - m + 1 + i;
   if (max < bmGs[i]) max = bmGs[i];
   j += max;
  } else return (void*)(str + j);
 }
 if (_prep == 0) free(prep);
 return 0;
}

canonical_original_code:
void *kmemmem(void *_str, int n, void *_pat, int m, int **_prep)
{
 int i; int j; int *prep = 0; int *bmGs; int *bmBc;
 unsigned char *str; unsigned char *pat;
 str = (unsigned char *)_str; pat = (unsigned char *)_pat;
 prep = (_prep == 0 || *_prep == 0)? ksBM_prep(pat, m) : *_prep;
 if (_prep && *_prep == 0) *_prep = prep;
 bmGs = prep; bmBc = prep + m;
 j = 0;
 while (j <= n - m) {
  for (i = m - 1; i >= 0 && pat[i] == str[i+j]; --i);
  if (i >= 0) {
   int max = bmBc[str[i+j]] - m + 1 + i;
   if (max < bmGs[i]) max = bmGs[i];
   j += max;
  } else return (void *)(str + j);
 }
 if (_prep == 0) free(prep);
 return 0;
}

variable_types: m int

variable_types: j int

variable_types:
prep
int *

variable_types:
bmGs
int *

variable_types:
bmBc
int *

variable_types:
str
unsigned char *

variable_types:
pat
unsigned char *


kstrstr

original_code:
char *kstrstr(const char *str, const char *pat, int **_prep)
{
 return (char*)kmemmem(str, strlen(str), pat, strlen(pat), _prep);
}

canonical_original_code:
char *kstrstr(char *str, char *pat, int **_prep)
{
 return (char *)kmemmem(str, strlen(str), pat, strlen(pat), _prep);
}

variable_types:
str
char *

variable_types:
pat
char *


kstrnstr

original_code:
char *kstrnstr(const char *str, const char *pat, int n, int **_prep)
{
 return (char*)kmemmem(str, n, pat, strlen(pat), _prep);
}

canonical_original_code:
char *kstrnstr(char *str, char *pat, int n, int **_prep)
{
 return (char *)kmemmem(str, n, pat, strlen(pat), _prep);
}


canonical_original_code:
int bcf_2qcall(struct bcf_hdr_t *h, struct bcf1_t *b)
{
 int a[4]; int k; int g[10]; int l; int map[4]; int k1; int j; int i; int i0; int anno[16]; int dp; int mq; int d_rest;
 char *s;
 if (b->ref[1] != 0 || b->n_alleles > 4) return -1;
 for (i = 0; i < b->n_gi; ++i)
  if (b->gi[i].fmt == bcf_str2int("PL", 2)) break;
 if (i == b->n_gi) return -1;
 if (read_I16(b, anno) != 0) return -1;
 d_rest = dp = anno[0] + anno[1] + anno[2] + anno[3];
 if (dp == 0) return -1;
 mq = (int)(sqrt((double)(anno[9] + anno[11]) / dp) + .499);
 i0 = i;
 a[0] = nt4_table[(int)b->ref[0]];
 if (a[0] > 3) return -1;
 a[1] = a[2] = a[3] = -2;
 if (b->alt[0] == 0) return -1;
 map[0] = map[1] = map[2] = map[3] = -2;
 map[a[0]] = 0;
 for (k = 0, s = b->alt, k1 = -1; k < 3 && *s; ++k, s += 2) {
  if (s[1] != ',' && s[1] != 0) return -1;
  a[k+1] = nt4_table[(int)*s];
  if (a[k+1] >= 0) map[a[k+1]] = k+1;
  else k1 = k+1;
  if (s[1] == 0) break;
 }
 for (k = 0; k < 4; ++k)
  if (map[k] < 0) map[k] = k1;
 for (i = 0; i < h->n_smpl; ++i) {
  int d;
  unsigned char *p = b->gi[i0].data + i * b->gi[i0].len;
  for (j = 0; j < b->gi[i0].len; ++j)
   if (p[j]) break;
  d = (int)((double)d_rest / (h->n_smpl - i) + .499);
  if (d == 0) d = 1;
  if (j == b->gi[i0].len) d = 0;
  d_rest -= d;
  for (k = j = 0; k < 4; ++k) {
   for (l = k; l < 4; ++l) {
    int t; int x = map[k]; int y = map[l];
    if (x > y) t = x, x = y, y = t;
    g[j++] = p[y * (y+1) / 2 + x];
   }
  }
  printf("%s\t%d\t%c", h->ns[b->tid], b->pos+1, *b->ref);
  printf("\t%d\t%d\t0", d, mq);
  for (j = 0; j < 10; ++j)
   printf("\t%d", g[j]);
  printf("\t%s\n", h->sns[i]);
 }
 return 0;
}

variable_types: struct bcf_hdr_t { int n_ref; int l_nm; int l_smpl; int l_txt; char *name; char **ns; } *

variable_types: struct bcf1_t { int tid; int l_str; float qual; char *str; char *ref; int n_gi; struct bcf_ginfo_t { unsigned int fmt; int len; void *data; } *gi; int n_alleles; } *

variable_types:
a
int [4]

variable_types: k int

variable_types:
g
int [10]

variable_types:
map
int [4]

variable_types:
anno
int [16]

variable_types: dp int

variable_types: mq int

variable_types: d int

variable_types:
p
unsigned char *

variable_types: t int

variable_types: x int

variable_types: y int


original_code:
static void append_header_text(bam_header_t *header, char* text, int len)
{
 int x = header->l_text + 1;
 int y = header->l_text + len + 1;
 if (text == 0) return;
 (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x));
 (--(y), (y)|=(y)>>1, (y)|=(y)>>2, (y)|=(y)>>4, (y)|=(y)>>8, (y)|=(y)>>16, ++(y));
 if (x < y) header->text = (char*)realloc(header->text, y);
 strncpy(header->text + header->l_text, text, len);
 header->l_text += len;
 header->text[header->l_text] = 0;
}

canonical_original_code:
static void append_header_text(struct bam_header_t *header, char *text, int len)
{
 int x = header->l_text + 1;
 int y = header->l_text + len + 1;
 if (text == 0) return;
 (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x));
 (--(y), (y)|=(y)>>1, (y)|=(y)>>2, (y)|=(y)>>4, (y)|=(y)>>8, (y)|=(y)>>16, ++(y));
 if (x < y) header->text = (char *)realloc(header->text, y);
 strncpy(header->text + header->l_text, text, len);
 header->l_text += len;
 header->text[header->l_text] = 0;
}

variable_types: struct bam_header_t { int n_targets; char **target_name; unsigned int *target_len; void *dict; unsigned long l_text; char *text; } *

variable_types:
text
char *

variable_types: len int


samfaipath

original_code:
char *samfaipath(const char *fn_ref)
{
 char *fn_list = 0;
 if (fn_ref == 0) return 0;
 fn_list = calloc(strlen(fn_ref) + 5, 1);
 strcat(strcpy(fn_list, fn_ref), ".fai");
 if (access(fn_list, 4) == -1) {
  if (access(fn_ref, 4) == -1) {
   fprintf(stderr, "[samfaipath] fail to read file %s.\n", fn_ref);
  } else {
   if (bam_verbose >= 3) fprintf(stderr, "[samfaipath] build FASTA index...\n");
   if (fai_build(fn_ref) == -1) {
    fprintf(stderr, "[samfaipath] fail to build FASTA index.\n");
    free(fn_list); fn_list = 0;
   }
  }
 }
 return fn_list;
}

canonical_original_code:
char *samfaipath(char *fn_ref)
{
 char *fn_list = 0;
 if (fn_ref == 0) return 0;
 fn_list = calloc(strlen(fn_ref) + 5, 1);
 strcat(strcpy(fn_list, fn_ref), ".fai");
 if (access(fn_list, 4) == -1) {
  if (access(fn_ref, 4) == -1) {
   fprintf(stderr, "[samfaipath] fail to read file %s.\n", fn_ref);
  } else {
   if (bam_verbose >= 3) fprintf(stderr, "[samfaipath] build FASTA index...\n");
   if (fai_build(fn_ref) == -1) {
    fprintf(stderr, "[samfaipath] fail to build FASTA index.\n");
    free(fn_list); fn_list = 0;
   }
  }
 }
 return fn_list;
}


original_code:
double kmin_hj(kmin_f func, int n, double *x, void *data, double r, double eps, int max_calls)
{
 double fx, fx1, *x1, *dx, radius;
 int k, n_calls = 0;
 x1 = (double*)calloc(n, sizeof(double));
 dx = (double*)calloc(n, sizeof(double));
 for (k = 0; k != n; ++k) {
  dx[k] = fabs(x[k]) * r;
  if (dx[k] == 0) dx[k] = r;
 }
 radius = r;
 fx1 = fx = func(n, x, data); ++n_calls;
 for (;;) {
  memcpy(x1, x, n * sizeof(double));
  fx1 = __kmin_hj_aux(func, n, x1, data, fx, dx, &n_calls);
  while (fx1 < fx) {
   for (k = 0; k != n; ++k) {
    double t = x[k];
    dx[k] = x1[k] > x[k]? fabs(dx[k]) : 0.0 - fabs(dx[k]);
    x[k] = x1[k];
    x1[k] = x1[k] + x1[k] - t;
   }
   fx = fx1;
   if (n_calls >= max_calls) break;
   fx1 = func(n, x1, data); ++n_calls;
   fx1 = __kmin_hj_aux(func, n, x1, data, fx1, dx, &n_calls);
   if (fx1 >= fx) break;
   for (k = 0; k != n; ++k)
    if (fabs(x1[k] - x[k]) > .5 * fabs(dx[k])) break;
   if (k == n) break;
  }
  if (radius >= eps) {
   if (n_calls >= max_calls) break;
   radius *= r;
   for (k = 0; k != n; ++k) dx[k] *= r;
  } else break;
 }
 free(x1); free(dx);
 return fx1;
}

canonical_original_code:
double kmin_hj(double (*func)(int, double *, void *), int n, double *x, void *data, double r, double eps, int max_calls)
{
 double fx; double fx1; double *x1; double *dx; double radius;
 int k; int n_calls = 0;
 x1 = (double *)calloc(n, sizeof(double));
 dx = (double *)calloc(n, sizeof(double));
 for (k = 0; k != n; ++k) {
  dx[k] = fabs(x[k]) * r;
  if (dx[k] == 0) dx[k] = r;
 }
 radius = r;
 fx1 = fx = func(n, x, data); ++n_calls;
 for (;;) {
  memcpy(x1, x, n * sizeof(double));
  fx1 = __kmin_hj_aux(func, n, x1, data, fx, dx, &n_calls);
  while (fx1 < fx) {
   for (k = 0; k != n; ++k) {
    double t = x[k];
    dx[k] = x1[k] > x[k]? fabs(dx[k]) : 0.0 - fabs(dx[k]);
    x[k] = x1[k];
    x1[k] = x1[k] + x1[k] - t;
   }
   fx = fx1;
   if (n_calls >= max_calls) break;
   fx1 = func(n, x1, data); ++n_calls;
   fx1 = __kmin_hj_aux(func, n, x1, data, fx1, dx, &n_calls);
   if (fx1 >= fx) break;
   for (k = 0; k != n; ++k)
    if (fabs(x1[k] - x[k]) > .5 * fabs(dx[k])) break;
   if (k == n) break;
  }
  if (radius >= eps) {
   if (n_calls >= max_calls) break;
   radius *= r;
   for (k = 0; k != n; ++k) dx[k] *= r;
  } else break;
 }
 free(x1); free(dx);
 return fx1;
}

variable_types:
func
double (*)(int, double *, void *)

variable_types: n int

variable_types:
x
double *

variable_types:
data
void *

variable_types: r double

variable_types: eps double

variable_types: fx double

variable_types:
dx
double *

variable_types: radius double

variable_types: t double


interrupted

decompiled_code:
void __noreturn interrupted()
{
fwrite("Interrupted.\n", 1uLL, 0xDuLL, stderr);
if ( tfd != -1 )
unlink(temp_template);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
fwrite("Interrupted.\n", 1uLL, 0xDuLL, stderr);
if ( tfd != -1 )
unlink(temp_template);
exit(1);
}

original_code:
void interrupted(int signo) {
    fprintf(stderr,"Interrupted.\n");
    if(tfd != -1) unlink(temp_template);
    exit(1);
}

variable_types: signo int


strd

decompiled_code:
char *__fastcall strd(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func6(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

original_code:
static char * strd(char *s) {
    char *d;
    d=(char *)malloc(strlen(s) + 1);
    strcpy(d,s);
    return(d);
}

canonical_original_code:
static char *strd(char *s) {
    char *d;
    d=(char *)malloc(strlen(s) + 1);
    strcpy(d,s);
    return(d);
}

variable_types:
s
char *

variable_types:
d
char *


usage

decompiled_code:
void __noreturn usage()
{
fwrite("Usage: htpasswd [-c] passwordfile username\n", 1uLL, 0x2BuLL, stderr);
fwrite("The -c flag creates a new file.\n", 1uLL, 0x20uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3()
{
fwrite("Usage: htpasswd [-c] passwordfile username\n", 1uLL, 0x2BuLL, stderr);
fwrite("The -c flag creates a new file.\n", 1uLL, 0x20uLL, stderr);
exit(1);
}

original_code:
static void usage(void) {
    fprintf(stderr,"Usage: htpasswd [-c] passwordfile username\n");
    fprintf(stderr,"The -c flag creates a new file.\n");
    exit(1);
}

canonical_original_code:
static void usage() {
    fprintf(stderr,"Usage: htpasswd [-c] passwordfile username\n");
    fprintf(stderr,"The -c flag creates a new file.\n");
    exit(1);
}


original_code:
static int
is_leap( int year )
    {
    return year % 400? ( year % 100 ? ( year % 4 ? 0 : 1 ) : 0 ) : 1;
    }

canonical_original_code:
static int is_leap(int year)
    {
    return year % 400? ( year % 100 ? ( year % 4 ? 0 : 1 ) : 0 ) : 1;
    }

variable_types: year int


original_code:
static time_t
tm_to_time( struct tm* tmP )
    {
    time_t t;
    static int monthtab[12] = {
 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
    t = ( tmP->tm_year - 70 ) * 365;
    t += ( tmP->tm_year - 69 ) / 4;
    t += monthtab[tmP->tm_mon];
    if ( tmP->tm_mon >= 2 && is_leap( tmP->tm_year + 1900 ) )
 ++t;
    t += tmP->tm_mday - 1;
    t = t * 24 + tmP->tm_hour;
    t = t * 60 + tmP->tm_min;
    t = t * 60 + tmP->tm_sec;
    return t;
    }

canonical_original_code:
static long tm_to_time(struct tm *tmP)
    {
    long t;
    static int monthtab[12] = {
 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
    t = ( tmP->tm_year - 70 ) * 365;
    t += ( tmP->tm_year - 69 ) / 4;
    t += monthtab[tmP->tm_mon];
    if ( tmP->tm_mon >= 2 && is_leap( tmP->tm_year + 1900 ) )
 ++t;
    t += tmP->tm_mday - 1;
    t = t * 24 + tmP->tm_hour;
    t = t * 60 + tmP->tm_min;
    t = t * 60 + tmP->tm_sec;
    return t;
    }

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

variable_types: t long

variable_types:
monthtab
int [12]

return_type: long


decompiled_code:
__int64 __fastcall strlong_search(char *s1, __int64 a2, int a3, _QWORD *a4)
{
int v4; // er12
int v5; // er13
int v6; // ebx
__int64 v7; // rbp
int v8; // eax

v4 = a3 - 1;
v5 = 0;
do
{
v6 = (v4 + v5) / 2;
v7 = a2 + 16LL * v6;
v8 = strcmp(s1, *(const char **)v7);
if ( v8 < 0 )
{
v4 = v6 - 1;
}
else
{
if ( v8 <= 0 )
{
*a4 = *(_QWORD *)(v7 + 8);
return 1LL;
}
v5 = v6 + 1;
}
}
while ( v4 >= v5 );
return 0LL;
}

original_code:
static int
strlong_search( char* str, struct strlong* tab, int n, long* lP )
    {
    int i, h, l, r;
    l = 0;
    h = n - 1;
    for (;;)
 {
 i = ( h + l ) / 2;
 r = strcmp( str, tab[i].s );
 if ( r < 0 )
     h = i - 1;
 else if ( r > 0 )
     l = i + 1;
 else
     {
     *lP = tab[i].l;
     return 1;
     }
 if ( h < l )
     return 0;
 }
    }

canonical_original_code:
static int strlong_search(char *str, struct strlong *tab, int n, long *lP)
    {
    int i; int h; int l; int r;
    l = 0;
    h = n - 1;
    for (;;)
 {
 i = ( h + l ) / 2;
 r = strcmp( str, tab[i].s );
 if ( r < 0 )
     h = i - 1;
 else if ( r > 0 )
     l = i + 1;
 else
     {
     *lP = tab[i].l;
     return 1;
     }
 if ( h < l )
     return 0;
 }
    }

variable_types:
str
char *

variable_types:
tab
struct strlong { char *s; long l; } *

variable_types:
lP
long *

variable_types: i int

variable_types: h int

variable_types: l int

variable_types: r int


decompiled_code:
void __fastcall pound_case(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 **v3; // r12

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_b_loc();
do
{
if ( ((*v3)[v1] & 0x100) != 0 )
*v2 = tolower(v1);
v1 = *++v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func4(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 **v3; // r12

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_b_loc();
do
{
if ( ((*v3)[v1] & 0x100) != 0 )
*v2 = tolower(v1);
v1 = *++v2;
}
while ( *v2 );
}
}

original_code:
static void
pound_case( char* str )
    {
    for ( ; *str != '\0'; ++str )
 {
 if ( ((*__ctype_b_loc ())[(int) (((int) *str))] & (unsigned short int) _ISupper) )
     *str = tolower( (int) *str );
 }
    }

canonical_original_code:
static void pound_case(char *str)
    {
    for ( ; *str != '\0'; ++str )
 {
 if ( ((*__ctype_b_loc ())[(int) (((int) *str))] & (unsigned short) _ISupper) )
     *str = tolower( (int) *str );
 }
    }


decompiled_code:
__int64 __fastcall scan_wday(char *s1, _QWORD *a2)
{
if ( !sorted_4 )
{
qsort(&wday_tab_3, 0xEuLL, 0x10uLL, strlong_compare);
sorted_4 = 1;
}
pound_case(s1);
return strlong_search(s1, (__int64)&wday_tab_3, 14, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s1, _QWORD *a2)
{
if ( !sorted_4 )
{
qsort(&wday_tab_3, 0xEuLL, 0x10uLL, strlong_compare);
sorted_4 = 1;
}
func4(s1);
return func3(s1, (__int64)&wday_tab_3, 14, a2);
}

original_code:
static int
scan_wday( char* str_wday, long* tm_wdayP )
    {
    static struct strlong wday_tab[] = {
 { "sun", 0 }, { "sunday", 0 },
 { "mon", 1 }, { "monday", 1 },
 { "tue", 2 }, { "tuesday", 2 },
 { "wed", 3 }, { "wednesday", 3 },
 { "thu", 4 }, { "thursday", 4 },
 { "fri", 5 }, { "friday", 5 },
 { "sat", 6 }, { "saturday", 6 },
 };
    static int sorted = 0;
    if ( ! sorted )
 {
 (void) qsort(
     wday_tab, sizeof(wday_tab)/sizeof(struct strlong),
     sizeof(struct strlong), strlong_compare );
 sorted = 1;
 }
    pound_case( str_wday );
    return strlong_search(
 str_wday, wday_tab, sizeof(wday_tab)/sizeof(struct strlong), tm_wdayP );
    }

canonical_original_code:
static int scan_wday(char *str_wday, long *tm_wdayP)
    {
    static struct strlong wday_tab[] = {
 { "sun", 0 }, { "sunday", 0 },
 { "mon", 1 }, { "monday", 1 },
 { "tue", 2 }, { "tuesday", 2 },
 { "wed", 3 }, { "wednesday", 3 },
 { "thu", 4 }, { "thursday", 4 },
 { "fri", 5 }, { "friday", 5 },
 { "sat", 6 }, { "saturday", 6 },
 };
    static int sorted = 0;
    if ( ! sorted )
 {
 (void) qsort(
     wday_tab, sizeof(wday_tab)/sizeof(struct strlong),
     sizeof(struct strlong), strlong_compare );
 sorted = 1;
 }
    pound_case( str_wday );
    return strlong_search(
 str_wday, wday_tab, sizeof(wday_tab)/sizeof(struct strlong), tm_wdayP );
    }

variable_types: sorted int


decompiled_code:
__int64 __fastcall scan_mon(char *s1, _QWORD *a2)
{
if ( !sorted_2 )
{
qsort(&mon_tab_1, 0x17uLL, 0x10uLL, strlong_compare);
sorted_2 = 1;
}
pound_case(s1);
return strlong_search(s1, (__int64)&mon_tab_1, 23, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s1, _QWORD *a2)
{
if ( !sorted_2 )
{
qsort(&mon_tab_1, 0x17uLL, 0x10uLL, strlong_compare);
sorted_2 = 1;
}
func4(s1);
return func3(s1, (__int64)&mon_tab_1, 23, a2);
}

original_code:
static int
scan_mon( char* str_mon, long* tm_monP )
    {
    static struct strlong mon_tab[] = {
 { "jan", 0 }, { "january", 0 },
 { "feb", 1 }, { "february", 1 },
 { "mar", 2 }, { "march", 2 },
 { "apr", 3 }, { "april", 3 },
 { "may", 4 },
 { "jun", 5 }, { "june", 5 },
 { "jul", 6 }, { "july", 6 },
 { "aug", 7 }, { "august", 7 },
 { "sep", 8 }, { "september", 8 },
 { "oct", 9 }, { "october", 9 },
 { "nov", 10 }, { "november", 10 },
 { "dec", 11 }, { "december", 11 },
 };
    static int sorted = 0;
    if ( ! sorted )
 {
 (void) qsort(
     mon_tab, sizeof(mon_tab)/sizeof(struct strlong),
     sizeof(struct strlong), strlong_compare );
 sorted = 1;
 }
    pound_case( str_mon );
    return strlong_search(
 str_mon, mon_tab, sizeof(mon_tab)/sizeof(struct strlong), tm_monP );
    }

canonical_original_code:
static int scan_mon(char *str_mon, long *tm_monP)
    {
    static struct strlong mon_tab[] = {
 { "jan", 0 }, { "january", 0 },
 { "feb", 1 }, { "february", 1 },
 { "mar", 2 }, { "march", 2 },
 { "apr", 3 }, { "april", 3 },
 { "may", 4 },
 { "jun", 5 }, { "june", 5 },
 { "jul", 6 }, { "july", 6 },
 { "aug", 7 }, { "august", 7 },
 { "sep", 8 }, { "september", 8 },
 { "oct", 9 }, { "october", 9 },
 { "nov", 10 }, { "november", 10 },
 { "dec", 11 }, { "december", 11 },
 };
    static int sorted = 0;
    if ( ! sorted )
 {
 (void) qsort(
     mon_tab, sizeof(mon_tab)/sizeof(struct strlong),
     sizeof(struct strlong), strlong_compare );
 sorted = 1;
 }
    pound_case( str_mon );
    return strlong_search(
 str_mon, mon_tab, sizeof(mon_tab)/sizeof(struct strlong), tm_monP );
    }


original_code:
time_t
tdate_parse( char* str )
    {
    struct tm tm;
    char* cp;
    char str_mon[500], str_wday[500];
    int tm_sec, tm_min, tm_hour, tm_mday, tm_year;
    long tm_mon, tm_wday;
    time_t t;
    (void) memset( (char*) &tm, 0, sizeof(struct tm) );
    for ( cp = str; *cp == ' ' || *cp == '\t'; ++cp )
 continue;
    if ( sscanf( cp, "%d-%400[a-zA-Z]-%d %d:%d:%d GMT",
  &tm_mday, str_mon, &tm_year, &tm_hour, &tm_min,
  &tm_sec ) == 6 &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 }
    else if ( sscanf( cp, "%d %400[a-zA-Z] %d %d:%d:%d GMT",
  &tm_mday, str_mon, &tm_year, &tm_hour, &tm_min,
  &tm_sec) == 6 &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 }
    else if ( sscanf( cp, "%d:%d:%d GMT %d-%400[a-zA-Z]-%d",
  &tm_hour, &tm_min, &tm_sec, &tm_mday, str_mon,
  &tm_year ) == 6 &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 }
    else if ( sscanf( cp, "%d:%d:%d GMT %d %400[a-zA-Z] %d",
  &tm_hour, &tm_min, &tm_sec, &tm_mday, str_mon,
  &tm_year ) == 6 &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 }
    else if ( sscanf( cp, "%400[a-zA-Z], %d-%400[a-zA-Z]-%d %d:%d:%d GMT",
  str_wday, &tm_mday, str_mon, &tm_year, &tm_hour, &tm_min,
  &tm_sec ) == 7 &&
     scan_wday( str_wday, &tm_wday ) &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_wday = tm_wday;
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 }
    else if ( sscanf( cp, "%400[a-zA-Z], %d %400[a-zA-Z] %d %d:%d:%d GMT",
  str_wday, &tm_mday, str_mon, &tm_year, &tm_hour, &tm_min,
  &tm_sec ) == 7 &&
     scan_wday( str_wday, &tm_wday ) &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_wday = tm_wday;
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 }
    else if ( sscanf( cp, "%400[a-zA-Z] %400[a-zA-Z] %d %d:%d:%d GMT %d",
  str_wday, str_mon, &tm_mday, &tm_hour, &tm_min, &tm_sec,
  &tm_year ) == 7 &&
     scan_wday( str_wday, &tm_wday ) &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_wday = tm_wday;
 tm.tm_mon = tm_mon;
 tm.tm_mday = tm_mday;
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 tm.tm_year = tm_year;
 }
    else
 return (time_t) -1;
    if ( tm.tm_year > 1900 )
 tm.tm_year -= 1900;
    else if ( tm.tm_year < 70 )
 tm.tm_year += 100;
    t = tm_to_time( &tm );
    return t;
    }

canonical_original_code:
long tdate_parse(char *str)
    {
    struct tm tm;
    char *cp;
    char str_mon[500]; char str_wday[500];
    int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_year;
    long tm_mon; long tm_wday;
    long t;
    (void) memset( (char *) &tm, 0, sizeof(struct tm) );
    for ( cp = str; *cp == ' ' || *cp == '\t'; ++cp )
 continue;
    if ( sscanf( cp, "%d-%400[a-zA-Z]-%d %d:%d:%d GMT",
  &tm_mday, str_mon, &tm_year, &tm_hour, &tm_min,
  &tm_sec ) == 6 &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 }
    else if ( sscanf( cp, "%d %400[a-zA-Z] %d %d:%d:%d GMT",
  &tm_mday, str_mon, &tm_year, &tm_hour, &tm_min,
  &tm_sec) == 6 &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 }
    else if ( sscanf( cp, "%d:%d:%d GMT %d-%400[a-zA-Z]-%d",
  &tm_hour, &tm_min, &tm_sec, &tm_mday, str_mon,
  &tm_year ) == 6 &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 }
    else if ( sscanf( cp, "%d:%d:%d GMT %d %400[a-zA-Z] %d",
  &tm_hour, &tm_min, &tm_sec, &tm_mday, str_mon,
  &tm_year ) == 6 &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 }
    else if ( sscanf( cp, "%400[a-zA-Z], %d-%400[a-zA-Z]-%d %d:%d:%d GMT",
  str_wday, &tm_mday, str_mon, &tm_year, &tm_hour, &tm_min,
  &tm_sec ) == 7 &&
     scan_wday( str_wday, &tm_wday ) &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_wday = tm_wday;
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 }
    else if ( sscanf( cp, "%400[a-zA-Z], %d %400[a-zA-Z] %d %d:%d:%d GMT",
  str_wday, &tm_mday, str_mon, &tm_year, &tm_hour, &tm_min,
  &tm_sec ) == 7 &&
     scan_wday( str_wday, &tm_wday ) &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_wday = tm_wday;
 tm.tm_mday = tm_mday;
 tm.tm_mon = tm_mon;
 tm.tm_year = tm_year;
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 }
    else if ( sscanf( cp, "%400[a-zA-Z] %400[a-zA-Z] %d %d:%d:%d GMT %d",
  str_wday, str_mon, &tm_mday, &tm_hour, &tm_min, &tm_sec,
  &tm_year ) == 7 &&
     scan_wday( str_wday, &tm_wday ) &&
     scan_mon( str_mon, &tm_mon ) )
 {
 tm.tm_wday = tm_wday;
 tm.tm_mon = tm_mon;
 tm.tm_mday = tm_mday;
 tm.tm_hour = tm_hour;
 tm.tm_min = tm_min;
 tm.tm_sec = tm_sec;
 tm.tm_year = tm_year;
 }
    else
 return (time_t) -1;
    if ( tm.tm_year > 1900 )
 tm.tm_year -= 1900;
    else if ( tm.tm_year < 70 )
 tm.tm_year += 100;
    t = tm_to_time( &tm );
    return t;
    }

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

variable_types:
cp
char *


decompiled_code:
__int64 __fastcall match_one(char *a1, int a2, const char *a3)
{
char *v4; // rax
__int64 result; // rax
_BYTE *v6; // rbx
int v7; // eax
char v8; // dl
const char *v9; // r12
__int64 v10; // rbp

if ( a2 <= 0 )
return *a3 == 0;
v4 = a1;
while ( 1 )
{
v8 = *v4;
if ( *v4 == 63 )
{
if ( !*a3 )
return 0LL;
goto LABEL_7;
}
if ( v8 == 42 )
break;
if ( v8 != *a3 )
return 0LL;
LABEL_7:
++v4;
++a3;
if ( v4 - a1 >= a2 )
return *a3 == 0;
}
if ( v4[1] == 42 )
{
v6 = v4 + 2;
v7 = strlen(a3);
}
else
{
v6 = v4 + 1;
v7 = strcspn(a3, "/");
}
if ( v7 < 0 )
return 0LL;
v9 = &a3[v7];
v10 = (__int64)&v9[-v7 - 1];
while ( 1 )
{
result = match_one(v6, (unsigned int)(a2 - ((_DWORD)v6 - (_DWORD)a1)), v9);
if ( (_DWORD)result )
break;
if ( --v9 == (const char *)v10 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2, const char *a3)
{
char *v4; // rax
__int64 result; // rax
_BYTE *v6; // rbx
int v7; // eax
char v8; // dl
const char *v9; // r12
__int64 v10; // rbp

if ( a2 <= 0 )
return *a3 == 0;
v4 = a1;
while ( 1 )
{
v8 = *v4;
if ( *v4 == 63 )
{
if ( !*a3 )
return 0LL;
goto LABEL_7;
}
if ( v8 == 42 )
break;
if ( v8 != *a3 )
return 0LL;
LABEL_7:
++v4;
++a3;
if ( v4 - a1 >= a2 )
return *a3 == 0;
}
if ( v4[1] == 42 )
{
v6 = v4 + 2;
v7 = strlen(a3);
}
else
{
v6 = v4 + 1;
v7 = strcspn(a3, "/");
}
if ( v7 < 0 )
return 0LL;
v9 = &a3[v7];
v10 = (__int64)&v9[-v7 - 1];
while ( 1 )
{
result = func0(v6, (unsigned int)(a2 - ((_DWORD)v6 - (_DWORD)a1)), v9);
if ( (_DWORD)result )
break;
if ( --v9 == (const char *)v10 )
return result;
}
return 1LL;
}

original_code:
static int
match_one( const char* pattern, int patternlen, const char* string )
    {
    const char* p;
    for ( p = pattern; p - pattern < patternlen; ++p, ++string )
 {
 if ( *p == '?' && *string != '\0' )
     continue;
 if ( *p == '*' )
     {
     int i, pl;
     ++p;
     if ( *p == '*' )
  {
  ++p;
  i = strlen( string );
  }
     else
  i = strcspn( string, "/" );
     pl = patternlen - ( p - pattern );
     for ( ; i >= 0; --i )
  if ( match_one( p, pl, &(string[i]) ) )
      return 1;
     return 0;
     }
 if ( *p != *string )
     return 0;
 }
    if ( *string == '\0' )
 return 1;
    return 0;
    }

canonical_original_code:
static int match_one(char *pattern, int patternlen, char *string)
    {
    char *p;
    for ( p = pattern; p - pattern < patternlen; ++p, ++string )
 {
 if ( *p == '?' && *string != '\0' )
     continue;
 if ( *p == '*' )
     {
     int i; int pl;
     ++p;
     if ( *p == '*' )
  {
  ++p;
  i = strlen( string );
  }
     else
  i = strcspn( string, "/" );
     pl = patternlen - ( p - pattern );
     for ( ; i >= 0; --i )
  if ( match_one( p, pl, &(string[i]) ) )
      return 1;
     return 0;
     }
 if ( *p != *string )
     return 0;
 }
    if ( *string == '\0' )
 return 1;
    return 0;
    }

variable_types:
pattern
char *

variable_types: patternlen int

variable_types:
string
char *

variable_types:
p
char *

variable_types: pl int


match

decompiled_code:
__int64 __fastcall match(char *s, const char *a2)
{
int v3; // eax
char *v5; // rax
char *v6; // rbx

while ( 1 )
{
v5 = strchr(s, 124);
v6 = v5;
if ( !v5 )
{
v3 = strlen(s);
return match_one(s, v3, a2);
}
if ( (unsigned int)match_one(s, (int)v5 - (int)s, a2) )
break;
s = v6 + 1;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, const char *a2)
{
int v3; // eax
char *v5; // rax
char *v6; // rbx

while ( 1 )
{
v5 = strchr(s, 124);
v6 = v5;
if ( !v5 )
{
v3 = strlen(s);
return func0(s, v3, a2);
}
if ( (unsigned int)func0(s, (int)v5 - (int)s, a2) )
break;
s = v6 + 1;
}
return 1LL;
}

original_code:
int
match( const char* pattern, const char* string )
    {
    const char* or;
    for (;;)
 {
 or = strchr( pattern, '|' );
 if ( or == (char*) 0 )
     return match_one( pattern, strlen( pattern ), string );
 if ( match_one( pattern, or - pattern, string ) )
     return 1;
 pattern = or + 1;
 }
    }

canonical_original_code:
int match(char *pattern, char *string)
    {
    char *or;
    for (;;)
 {
 or = strchr( pattern, '|' );
 if ( or == (char *) 0 )
     return match_one( pattern, strlen( pattern ), string );
 if ( match_one( pattern, or - pattern, string ) )
     return 1;
 pattern = or + 1;
 }
    }

variable_types:
or
char *


getStringParts

repo: peterbourgon/hose-poet

original_code:
struct StringPart *getStringParts(char *s, int start, int length) {
  int i,wordstart;
  struct StringPart *head;
  for (i = start ; (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISspace) && (i < length)) ; i++)
                                                ;
  if (i >= length) return ((void *)0);
  wordstart = i;
  for (; (!((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISspace) && (i < length)) ; i++)
                                            ;
  head = (struct StringPart *)testalloc(sizeof(struct StringPart));
  head->string = &s[wordstart];
  head->length = i - wordstart;
  head->next = getStringParts(s, i, length);
  return head;
}

canonical_original_code:
struct StringPart *getStringParts(char *s, int start, int length) {
  int i; int wordstart;
  struct StringPart *head;
  for (i = start ; (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISspace) && (i < length)) ; i++)
                                                ;
  if (i >= length) return ((void *)0);
  wordstart = i;
  for (; (!((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISspace) && (i < length)) ; i++)
                                            ;
  head = (struct StringPart *)testalloc(sizeof(struct StringPart));
  head->string = &s[wordstart];
  head->length = i - wordstart;
  head->next = getStringParts(s, i, length);
  return head;
}

variable_types:
s
char *

variable_types: start int

variable_types: length int

variable_types: wordstart int

variable_types: struct StringPart { char *string; int length; struct StringPart *next; } *


cmpStringParts

decompiled_code:
__int64 __fastcall cmpStringParts(__int128 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 v5; // rcx
int v6; // er11
__int64 i; // rax
__int64 v8; // rdx
char v9; // dl
int v10; // eax

result = 0LL;
v5 = *((_QWORD *)&a1 + 1) | a1;
if ( a1 != 0 )
{
if ( *((_QWORD *)&a1 + 1) )
{
if ( (_QWORD)a1 )
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 <= 0 )
{
v8 = 0LL;
}
else
{
for ( i = 0LL; i != v6; ++i )
{
a4 = (unsigned int)i;
v8 = (unsigned int)i;
if ( *(_DWORD *)(*((_QWORD *)&a1 + 1) + 8LL) <= (int)i )
break;
v9 = *(_BYTE *)(*(_QWORD *)a1 + i);
v5 = *(unsigned __int8 *)(**((_QWORD **)&a1 + 1) + i);
if ( v9 != (_BYTE)v5 )
return (unsigned int)(v9 - (char)v5);
v8 = (unsigned int)(i + 1);
}
}
v10 = *(_DWORD *)(*((_QWORD *)&a1 + 1) + 8LL);
if ( v10 < v6 )
{
result = (unsigned int)*(char *)(*(_QWORD *)a1 + (int)v8);
}
else if ( v10 <= v6 )
{
result = cmpStringParts(*(_QWORD *)(a1 + 16), *(_QWORD *)(*((_QWORD *)&a1 + 1) + 16LL), v8, v5, a4);
}
else
{
result = (unsigned int)-*(char *)(**((_QWORD **)&a1 + 1) + (int)v8);
}
}
else
{
result = (unsigned int)-***((char ***)&a1 + 1);
}
}
else
{
result = (unsigned int)**(char **)a1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int128 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 v5; // rcx
int v6; // er11
__int64 i; // rax
__int64 v8; // rdx
char v9; // dl
int v10; // eax

result = 0LL;
v5 = *((_QWORD *)&a1 + 1) | a1;
if ( a1 != 0 )
{
if ( *((_QWORD *)&a1 + 1) )
{
if ( (_QWORD)a1 )
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 <= 0 )
{
v8 = 0LL;
}
else
{
for ( i = 0LL; i != v6; ++i )
{
a4 = (unsigned int)i;
v8 = (unsigned int)i;
if ( *(_DWORD *)(*((_QWORD *)&a1 + 1) + 8LL) <= (int)i )
break;
v9 = *(_BYTE *)(*(_QWORD *)a1 + i);
v5 = *(unsigned __int8 *)(**((_QWORD **)&a1 + 1) + i);
if ( v9 != (_BYTE)v5 )
return (unsigned int)(v9 - (char)v5);
v8 = (unsigned int)(i + 1);
}
}
v10 = *(_DWORD *)(*((_QWORD *)&a1 + 1) + 8LL);
if ( v10 < v6 )
{
result = (unsigned int)*(char *)(*(_QWORD *)a1 + (int)v8);
}
else if ( v10 <= v6 )
{
result = func1(*(_QWORD *)(a1 + 16), *(_QWORD *)(*((_QWORD *)&a1 + 1) + 16LL), v8, v5, a4);
}
else
{
result = (unsigned int)-*(char *)(**((_QWORD **)&a1 + 1) + (int)v8);
}
}
else
{
result = (unsigned int)-***((char ***)&a1 + 1);
}
}
else
{
result = (unsigned int)**(char **)a1;
}
}
return result;
}

original_code:
int cmpStringParts(struct StringPart *a, struct StringPart *b) {
  int i;
  if ((a == ((void *)0)) && (b == ((void *)0))) {
    return 0;
  } else if (b == ((void *)0)) {
    return a->string[0];
  } else if (a == ((void *)0)) {
    return 0 - b->string[0];
  } else {
    for (i = 0 ; i < a->length && i < b->length ; i++) {
      if (a->string[i] != b->string[i]) {
 return a->string[i] - b->string[i];
      }
    }
    if (a->length > b->length) {
      return a->string[i];
    } else if (b->length > a->length) {
      return -1 * b->string[i];
    } else {
      return cmpStringParts(a->next, b->next);
    }
  }
}

variable_types:
b
struct StringPart *

variable_types: i int

user_defined_types: struct StringPart { char *string; int length; struct StringPart *next; }


printStringParts

decompiled_code:
__int64 __fastcall printStringParts(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
putchar(62);
if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
putchar(*(char *)(*(_QWORD *)a1 + v1++));
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
}
putchar(60);
result = printStringParts(*(_QWORD *)(a1 + 16));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
putchar(62);
if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
putchar(*(char *)(*(_QWORD *)a1 + v1++));
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
}
putchar(60);
result = func2(*(_QWORD *)(a1 + 16));
}
return result;
}

original_code:
void printStringParts(struct StringPart *head) {
  int i;
  if (head != ((void *)0)) {
    putchar('>');
    for (i = 0 ; i < head->length ; i++) {
      putchar(head->string[i]);
    }
    putchar('<');
    printStringParts(head->next);
  }
}


countStringParts

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
a1 = *(_QWORD *)(a1 + 16);
result = (unsigned int)(result + 1);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
a1 = *(_QWORD *)(a1 + 16);
result = (unsigned int)(result + 1);
}
while ( a1 );
return result;
}

original_code:
int countStringParts(struct StringPart *head) {
  struct StringPart *current;
  int count;
  for (current = head, count = 0 ; current != ((void *)0) ;
       current = current->next, count++) ;
  return count;
}

variable_types: count int


lastChar

decompiled_code:
__int64 __fastcall lastChar(__int64 a1)
{
return *(unsigned __int8 *)(*(_QWORD *)a1 + *(int *)(a1 + 8) - 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned __int8 *)(*(_QWORD *)a1 + *(int *)(a1 + 8) - 1LL);
}

original_code:
char lastChar(struct StringPart *part) {
  return part->string[part->length - 1];
}


isSyllable

decompiled_code:
_BOOL8 __fastcall isSyllable(__int64 a1)
{
return (unsigned __int8)(lastChar(a1) - 48) <= 2u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
return (unsigned __int8)(func4(a1) - 48) <= 2u;
}

original_code:
int isSyllable(struct StringPart *part) {
  switch(lastChar(part)) {
  case '0': return 1;
  case '1': return 1;
  case '2': return 1;
  default: return 0;
  }
}


isPrimaryStress

decompiled_code:
_BOOL8 __fastcall isPrimaryStress(__int64 a1)
{
return (unsigned __int8)lastChar(a1) == 49;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return (unsigned __int8)func4(a1) == 49;
}

original_code:
int isPrimaryStress(struct StringPart *part) {
  if (lastChar(part) == '1') return 1;
  else return 0;
}


freeStringParts

decompiled_code:
__int64 __fastcall freeStringParts(_QWORD *a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1[2];
free(a1);
result = freeStringParts(v1);
}
return result;
}

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

if ( a1 )
{
v1 = a1[2];
free(a1);
result = func7(v1);
}
return result;
}

original_code:
void freeStringParts(struct StringPart *head) {
  struct StringPart *next;
  if (head != ((void *)0)) {
    next = head->next;
    free(head);
    freeStringParts(next);
  }
}


findNonSpace

original_code:
int findNonSpace(char *s, int start) {
  int i;
  for (i = start ; ((s[i] == ' ') && (s[i] != '\0')) ; i++)
                 ;
  if (s[i] == '\0')
    return -1;
  else
    return i;
}


testalloc

decompiled_code:
void *__fastcall testalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "Out of memory trying to allocate %d bytes\n", a1);
fwrite("Program terminated\n", 1uLL, 0x13uLL, stderr);
exit(2);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "Out of memory trying to allocate %d bytes\n", a1);
fwrite("Program terminated\n", 1uLL, 0x13uLL, stderr);
exit(2);
}
return result;
}

original_code:
void *testalloc(size_t size) {
  void *toreturn;
  toreturn = (void *)malloc(size);
  if (toreturn == ((void *)0)) {
    fprintf(stderr, "Out of memory trying to allocate %d bytes\n", size);
    fprintf(stderr, "Program terminated\n");
    exit(2);
  } else {
    return toreturn;
  }
}

canonical_original_code:
void *testalloc(unsigned long size) {
  void *toreturn;
  toreturn = (void *)malloc(size);
  if (toreturn == ((void *)0)) {
    fprintf(stderr, "Out of memory trying to allocate %d bytes\n", size);
    fprintf(stderr, "Program terminated\n");
    exit(2);
  } else {
    return toreturn;
  }
}

variable_types:
size
unsigned long

variable_types:
toreturn
void *


freeBlocks

decompiled_code:
void __fastcall freeBlocks(void *ptr)
{
if ( ptr )
{
freeBlocks(*((void **)ptr + 129));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
if ( ptr )
{
func11(*((void **)ptr + 129));
free(ptr);
}
}

original_code:
void freeBlocks(struct StringBlock *block) {
  if (block == ((void *)0)) {
    return;
  } else {
    freeBlocks(block->next);
    free(block);
  }
}

variable_types: struct StringBlock { char block[1024]; int length; struct StringBlock *next; } *


lineLength

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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 1024) + (unsigned int)lineLength(*(_QWORD *)(a1 + 1032));
return result;
}

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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 1024) + (unsigned int)func12(*(_QWORD *)(a1 + 1032));
return result;
}

original_code:
int lineLength(struct StringBlock *block) {
  if (block == ((void *)0)) {
    return 0;
  } else {
    return block->length + lineLength(block->next);
  }
}

user_defined_types: struct StringBlock { char block[1024]; int length; struct StringBlock *next; }


cmpLongLine

decompiled_code:
__int64 __fastcall cmpLongLine(__int128 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 v5; // rcx
int v6; // er11
__int64 i; // rax
__int64 v8; // rdx
char v9; // dl
int v10; // eax

result = 0LL;
v5 = *((_QWORD *)&a1 + 1) | a1;
if ( a1 != 0 )
{
if ( *((_QWORD *)&a1 + 1) )
{
v6 = *(_DWORD *)(a1 + 1024);
if ( v6 <= 0 )
{
v8 = 0LL;
}
else
{
for ( i = 0LL; i != v6; ++i )
{
a4 = (unsigned int)i;
v8 = (unsigned int)i;
if ( *(_DWORD *)(*((_QWORD *)&a1 + 1) + 1024LL) <= (int)i )
break;
v9 = *(_BYTE *)(a1 + i);
v5 = *(unsigned __int8 *)(*((_QWORD *)&a1 + 1) + i);
if ( v9 != (_BYTE)v5 )
return (unsigned int)(v9 - (char)v5);
v8 = (unsigned int)(i + 1);
}
}
v10 = *(_DWORD *)(*((_QWORD *)&a1 + 1) + 1024LL);
if ( v10 < v6 )
{
result = (unsigned int)*(char *)(a1 + (int)v8);
}
else if ( v10 <= v6 )
{
result = cmpLongLine(*(_QWORD *)(a1 + 1032), *(_QWORD *)(*((_QWORD *)&a1 + 1) + 1032LL), v8, v5, a4);
}
else
{
result = (unsigned int)-*(char *)(*((_QWORD *)&a1 + 1) + (int)v8);
}
}
else
{
result = (unsigned int)*(char *)a1;
}
}
return result;
}

original_code:
int cmpLongLine(struct StringBlock *a, struct StringBlock *b) {
  int i;
  if ((a == ((void *)0)) && (b == ((void *)0))) {
    return 0;
  } else if (b == ((void *)0)) {
    return a->block[0];
  } else if (b == ((void *)0)) {
    return 0 - a->block[0];
  } else {
    for (i = 0 ; i < a->length && i < b->length ; i++) {
      if (a->block[i] != b->block[i]) {
 return a->block[i] - b->block[i];
      }
    }
    if (a->length > b->length) {
      return a->block[i];
    } else if (b->length > a->length) {
      return -1 * b->block[i];
    } else {
      return cmpLongLine(a->next, b->next);
    }
  }
}

variable_types:
b
struct StringBlock *


findSpace

decompiled_code:
__int64 __fastcall findSpace(char *a1)
{
char v1; // dl
__int64 v2; // rax
unsigned int v3; // ecx

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

original_code:
int findSpace(char *s) {
  int i;
  for (i = 0 ; ((s[i] != ' ') && (s[i] != '\0')) ; i++)
                  ;
  if (s[i] == '\0')
    return -1;
  else
    return i;
}


stringToWordEntry

decompiled_code:
__int64 __fastcall stringToWordEntry(const char *a1)
{
size_t v1; // rax
__int64 v2; // rbx
__int64 v3; // rbp
__int64 i; // rbx

v1 = strlen(a1);
v2 = getStringParts(a1, 0LL, v1);
v3 = 0LL;
if ( (int)countStringParts(v2) > 1 )
{
v3 = testalloc(48LL);
*(_QWORD *)(v3 + 8) = v2;
*(_QWORD *)(v3 + 16) = *(_QWORD *)(v2 + 16);
*(_QWORD *)(v3 + 24) = 0LL;
*(_DWORD *)(v3 + 32) = 0;
for ( i = *(_QWORD *)(v2 + 16); i; i = *(_QWORD *)(i + 16) )
{
if ( (unsigned int)isSyllable(i) )
{
++*(_DWORD *)(v3 + 32);
if ( (unsigned int)isPrimaryStress(i) )
*(_QWORD *)(v3 + 24) = i;
}
}
*(_QWORD *)(v3 + 40) = 0LL;
*(_QWORD *)v3 = a1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
size_t v1; // rax
__int64 v2; // rbx
__int64 v3; // rbp
__int64 i; // rbx

v1 = strlen(a1);
v2 = getStringParts(a1, 0LL, v1);
v3 = 0LL;
if ( (int)countStringParts(v2) > 1 )
{
v3 = testalloc(48LL);
*(_QWORD *)(v3 + 8) = v2;
*(_QWORD *)(v3 + 16) = *(_QWORD *)(v2 + 16);
*(_QWORD *)(v3 + 24) = 0LL;
*(_DWORD *)(v3 + 32) = 0;
for ( i = *(_QWORD *)(v2 + 16); i; i = *(_QWORD *)(i + 16) )
{
if ( (unsigned int)isSyllable(i) )
{
++*(_DWORD *)(v3 + 32);
if ( (unsigned int)isPrimaryStress(i) )
*(_QWORD *)(v3 + 24) = i;
}
}
*(_QWORD *)(v3 + 40) = 0LL;
*(_QWORD *)v3 = a1;
}
return v3;
}

original_code:
struct WordEntry *stringToWordEntry(char *string) {
  struct WordEntry *toreturn;
  struct StringPart *parts;
  struct StringPart *current;
  parts = getStringParts(string, 0, strlen(string));
  if (countStringParts(parts) < 2) return ((void *)0);
  toreturn = (struct WordEntry *)testalloc(sizeof(struct WordEntry));
  toreturn->word = parts;
  toreturn->phonemes = parts->next;
  toreturn->rhymekey = ((void *)0);
  toreturn->syllables = 0;
  for (current = parts->next ; current != ((void *)0) ;
       current = current->next) {
    if (isSyllable(current)) {
      toreturn->syllables++;
      if (isPrimaryStress(current))
 toreturn->rhymekey = current;
    }
  }
  toreturn->alternate = ((void *)0);
  toreturn->string = string;
  return toreturn;
}

variable_types: struct WordEntry { char *string; struct StringPart { char *string; int length; struct StringPart *next; } *word; struct StringPart *phonemes; struct StringPart *rhymekey; int syllables; struct WordEntry *alternate; } *

user_defined_types: struct WordEntry { char *string; struct StringPart *word; struct StringPart *phonemes; struct StringPart *rhymekey; int syllables; struct WordEntry *alternate; }


isMultiplePronunciation

decompiled_code:
_BOOL8 __fastcall isMultiplePronunciation(__int64 a1)
{
return *(_BYTE *)(**(_QWORD **)(a1 + 8) + *(int *)(*(_QWORD *)(a1 + 8) + 8LL) - 1LL) == 41;
}

original_code:
int isMultiplePronunciation(struct WordEntry *entry) {
  if (entry->word->string[entry->word->length - 1] == ')')
    return 1;
  else
    return 0;
}


freeWordEntry

decompiled_code:
void __fastcall freeWordEntry(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

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

original_code:
void freeWordEntry(struct WordEntry *entry) {
  free(entry->string);
  free(entry);
}


popWordEntry

decompiled_code:
__int64 __fastcall popWordEntry(__int64 **a1)
{
__int64 *v1; // rax
__int64 v2; // rbx

v1 = *a1;
if ( !*a1 )
return 0LL;
*a1 = (__int64 *)v1[1];
v2 = *v1;
free(v1);
return v2;
}

original_code:
struct WordEntry *popWordEntry(struct WordEntryStack **stack) {
  struct WordEntryStack *head;
  struct WordEntry *toreturn;
  head = *stack;
  if (head == ((void *)0)) return ((void *)0);
  *stack = head->next;
  toreturn = head->entry;
  free(head);
  return toreturn;
}

variable_types: struct WordEntryStack { struct WordEntry *entry; struct WordEntryStack *next; } **

variable_types: struct WordEntryStack { struct WordEntry { char *string; struct StringPart { char *string; int length; struct StringPart *next; } *word; struct StringPart *phonemes; struct StringPart *rhymekey; int syllables; struct WordEntry *alternate; } *entry; struct WordEntryStack *next; } *


reverseWordEntryStack

decompiled_code:
__int64 __fastcall reverseWordEntryStack(__int64 *a1)
{
__int64 v1; // rax
__int64 *v3; // [rsp+8h] [rbp-20h] BYREF
__int64 v4; // [rsp+18h] [rbp-10h] BYREF

v3 = a1;
v4 = 0LL;
while ( v3 )
{
v1 = popWordEntry(&v3);
pushWordEntry(&v4, v1);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
__int64 v1; // rax
__int64 *v3; // [rsp+8h] [rbp-20h] BYREF
__int64 v4; // [rsp+18h] [rbp-10h] BYREF

v3 = a1;
v4 = 0LL;
while ( v3 )
{
v1 = func4(&v3);
pushWordEntry(&v4, v1);
}
return v4;
}

original_code:
struct WordEntryStack *reverseWordEntryStack(struct WordEntryStack *stack) {
  struct WordEntryStack *toreturn = ((void *)0);
  while (stack != ((void *)0)) {
    pushWordEntry(&toreturn, popWordEntry(&stack));
  }
  return toreturn;
}

variable_types:
stack
struct WordEntryStack *

return_type: struct WordEntryStack { struct WordEntry { char *string; struct StringPart { char *string; int length; struct StringPart *next; } *word; struct StringPart *phonemes; struct StringPart *rhymekey; int syllables; struct WordEntry *alternate; } *entry; struct WordEntryStack *next; } *

user_defined_types: struct WordEntryStack { struct WordEntry *entry; struct WordEntryStack *next; }


freeWordEntryStack

decompiled_code:
void __fastcall freeWordEntryStack(void *ptr)
{
if ( ptr )
{
freeWordEntryStack(*((void **)ptr + 1));
freeWordEntry(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
if ( ptr )
{
func6(*((void **)ptr + 1));
func3(*(void **)ptr);
free(ptr);
}
}

original_code:
void freeWordEntryStack(struct WordEntryStack *stack) {
  if (stack == ((void *)0)) return;
  else {
    freeWordEntryStack(stack->next);
    freeWordEntry(stack->entry);
    free(stack);
  }
}


freeOnlyEntryTree

decompiled_code:
void __fastcall freeOnlyEntryTree(void *ptr)
{
if ( ptr )
{
freeOnlyEntryTree(*((void **)ptr + 2));
freeOnlyEntryTree(*((void **)ptr + 3));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
if ( ptr )
{
func7(*((void **)ptr + 2));
func7(*((void **)ptr + 3));
free(ptr);
}
}

original_code:
void freeOnlyEntryTree(struct WordEntryTree *tree) {
  if (tree == ((void *)0)) return;
  else {
    freeOnlyEntryTree(tree->lesser);
    freeOnlyEntryTree(tree->greater);
    free(tree);
  }
}

variable_types: struct WordEntryTree { struct StringPart { char *string; int length; struct StringPart *next; } *rhymekey; struct WordEntryStack { struct WordEntry { char *string; struct StringPart *word; struct StringPart *phonemes; struct StringPart *rhymekey; int syllables; struct WordEntry *alternate; } *entry; struct WordEntryStack *next; } *rhymes; struct WordEntryTree *lesser; struct WordEntryTree *greater; } *

user_defined_types: struct WordEntryTree { struct StringPart *rhymekey; struct WordEntryStack *rhymes; struct WordEntryTree *lesser; struct WordEntryTree *greater; }


isBaseWord

original_code:
int isBaseWord(struct WordEntry *entry, struct WordEntry *multiple) {
  int i;
  if (isMultiplePronunciation(entry)) return 0;
  for (i = 0 ; multiple->word->string[i] != '(' ; i++) {
    if (entry->word->string[i] != multiple->word->string[i])
      return 0;
  }
  if (i == entry->word->length)
    return 1;
  else
    return 0;
}

variable_types:
multiple
struct WordEntry *


addMultiplePronunciation

decompiled_code:
__int64 __fastcall addMultiplePronunciation(__int64 *a1, __int64 a2, int a3)
{
__int64 *v3; // rbp
__int64 result; // rax
__int64 v6; // rbx

v3 = a1;
result = 1LL;
if ( a1 )
{
while ( 1 )
{
v6 = *v3;
if ( isBaseWord(*v3, a2) )
break;
v3 = (__int64 *)v3[1];
if ( !v3 )
return 1LL;
}
if ( *(_QWORD *)(v6 + 40) )
{
while ( 1 )
{
if ( a3 )
{
result = cmpStringParts(*(_QWORD *)(a2 + 24), *(_QWORD *)(v6 + 24));
if ( !(_DWORD)result )
break;
}
v6 = *(_QWORD *)(v6 + 40);
if ( !*(_QWORD *)(v6 + 40) )
goto LABEL_12;
}
}
else
{
LABEL_12:
if ( !a3 || (result = cmpStringParts(*(_QWORD *)(a2 + 24), *(_QWORD *)(v6 + 24)), (_DWORD)result) )
{
*(_QWORD *)(v6 + 40) = a2;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, __int64 a2, int a3)
{
__int64 *v3; // rbp
__int64 result; // rax
__int64 v6; // rbx

v3 = a1;
result = 1LL;
if ( a1 )
{
while ( 1 )
{
v6 = *v3;
if ( func8(*v3, a2) )
break;
v3 = (__int64 *)v3[1];
if ( !v3 )
return 1LL;
}
if ( *(_QWORD *)(v6 + 40) )
{
while ( 1 )
{
if ( a3 )
{
result = cmpStringParts(*(_QWORD *)(a2 + 24), *(_QWORD *)(v6 + 24));
if ( !(_DWORD)result )
break;
}
v6 = *(_QWORD *)(v6 + 40);
if ( !*(_QWORD *)(v6 + 40) )
goto LABEL_12;
}
}
else
{
LABEL_12:
if ( !a3 || (result = cmpStringParts(*(_QWORD *)(a2 + 24), *(_QWORD *)(v6 + 24)), (_DWORD)result) )
{
*(_QWORD *)(v6 + 40) = a2;
result = 1LL;
}
}
}
return result;
}

original_code:
int addMultiplePronunciation(struct WordEntryStack *stack,
         struct WordEntry *entry,
         int skipduplicates) {
  struct WordEntryStack *base;
  struct WordEntry *alternate;
  for (base = stack ; (base != ((void *)0)) && (!isBaseWord(base->entry, entry)) ;
       base = base->next) ;
  if (base == ((void *)0)) return 1;
  alternate = base->entry;
  while (alternate->alternate != ((void *)0)) {
    if (skipduplicates &&
 (cmpStringParts(entry->rhymekey, alternate->rhymekey) == 0)) return 0;
    else alternate = alternate->alternate;
  }
  if (!skipduplicates ||
      cmpStringParts(entry->rhymekey, alternate->rhymekey) != 0) {
    alternate->alternate = entry;
    return 1;
  } else {
    return 0;
  }
}

variable_types:
entry
struct WordEntry *

variable_types: skipduplicates int


fatalError

decompiled_code:
void __fastcall __noreturn fatalError(char *format)
{
fprintf(stderr, format);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *format)
{
fprintf(stderr, format);
exit(1);
}

original_code:
void fatalError(char s[]) {
  fprintf(stderr, s);
  exit(1);
}

variable_types:
s
char []


swapSyllableModes

decompiled_code:
__int64 __fastcall swapSyllableModes(_DWORD *a1)
{
__int64 result; // rax

result = *a1 | 1u;
if ( (*a1 & 1) != 0 )
result = *a1 & 0xFFFFFFFE;
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1)
{
__int64 result; // rax

result = *a1 | 1u;
if ( (*a1 & 1) != 0 )
result = *a1 & 0xFFFFFFFE;
*a1 = result;
return result;
}

original_code:
void swapSyllableModes(int *flags) {
  if (*flags & 1) {
    *flags &= ~1;
  } else {
    *flags |= 1;
  }
}

variable_types:
flags
int *


swapMergedModes

decompiled_code:
__int64 __fastcall swapMergedModes(_DWORD *a1)
{
__int64 result; // rax

result = *a1 | 4u;
if ( (*a1 & 4) != 0 )
result = *a1 & 0xFFFFFFFB;
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1)
{
__int64 result; // rax

result = *a1 | 4u;
if ( (*a1 & 4) != 0 )
result = *a1 & 0xFFFFFFFB;
*a1 = result;
return result;
}

original_code:
void swapMergedModes(int *flags) {
  if (*flags & 4) {
    *flags &= ~4;
  } else {
    *flags |= 4;
  }
}


testalloc

canonical_decompiled_code:
void *__fastcall func7(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "Out of memory trying to allocate %d bytes\n", a1);
fwrite("Program terminated\n", 1uLL, 0x13uLL, stderr);
exit(2);
}
return result;
}

original_code:
void *testalloc(size_t size) {
  void *toreturn;
  toreturn = (void *)malloc(size);
  if (toreturn == ((void *)0)) {
    fprintf(stderr, "Out of memory trying to allocate %d bytes\n", size);
    fprintf(stderr, "Program terminated\n");
    exit(2);
  } else {
    return toreturn;
  }
}


freeBlocks

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
if ( ptr )
{
func9(*((void **)ptr + 129));
free(ptr);
}
}

original_code:
void freeBlocks(struct StringBlock *block) {
  if (block == ((void *)0)) {
    return;
  } else {
    freeBlocks(block->next);
    free(block);
  }
}


lineLength

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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 1024) + (unsigned int)func10(*(_QWORD *)(a1 + 1032));
return result;
}

original_code:
int lineLength(struct StringBlock *block) {
  if (block == ((void *)0)) {
    return 0;
  } else {
    return block->length + lineLength(block->next);
  }
}


cmpLongLine

decompiled_code:
__int64 __fastcall cmpLongLine(__int128 a1)
{
__int64 result; // rax
int v2; // er11
__int64 i; // rax
int v4; // edx
char v5; // dl
char v6; // cl
int v7; // eax

result = 0LL;
if ( a1 != 0 )
{
if ( *((_QWORD *)&a1 + 1) )
{
v2 = *(_DWORD *)(a1 + 1024);
if ( v2 <= 0 )
{
v4 = 0;
}
else
{
for ( i = 0LL; i != v2; ++i )
{
v4 = i;
if ( *(_DWORD *)(*((_QWORD *)&a1 + 1) + 1024LL) <= (int)i )
break;
v5 = *(_BYTE *)(a1 + i);
v6 = *(_BYTE *)(*((_QWORD *)&a1 + 1) + i);
if ( v5 != v6 )
return (unsigned int)(v5 - v6);
v4 = i + 1;
}
}
v7 = *(_DWORD *)(*((_QWORD *)&a1 + 1) + 1024LL);
if ( v7 < v2 )
{
result = (unsigned int)*(char *)(a1 + v4);
}
else if ( v7 <= v2 )
{
result = cmpLongLine(*(_QWORD *)(a1 + 1032), *(_QWORD *)(*((_QWORD *)&a1 + 1) + 1032LL));
}
else
{
result = (unsigned int)-*(char *)(*((_QWORD *)&a1 + 1) + v4);
}
}
else
{
result = (unsigned int)*(char *)a1;
}
}
return result;
}

original_code:
int cmpLongLine(struct StringBlock *a, struct StringBlock *b) {
  int i;
  if ((a == ((void *)0)) && (b == ((void *)0))) {
    return 0;
  } else if (b == ((void *)0)) {
    return a->block[0];
  } else if (b == ((void *)0)) {
    return 0 - a->block[0];
  } else {
    for (i = 0 ; i < a->length && i < b->length ; i++) {
      if (a->block[i] != b->block[i]) {
 return a->block[i] - b->block[i];
      }
    }
    if (a->length > b->length) {
      return a->block[i];
    } else if (b->length > a->length) {
      return -1 * b->block[i];
    } else {
      return cmpLongLine(a->next, b->next);
    }
  }
}


repo: petersenna/rdtscbench

decompiled_code:
int __fastcall rdtscb_measure(const char *a1, int a2, int a3, void (__fastcall *a4)(char *, char *))
{
int v6; // ebx
long double v7; // fst7
long double x; // [rsp+10h] [rbp-68h]
char v10[8]; // [rsp+30h] [rbp-48h] BYREF
__int64 v11; // [rsp+38h] [rbp-40h]
char v12[8]; // [rsp+40h] [rbp-38h] BYREF
__int64 v13; // [rsp+48h] [rbp-30h]

printf("%s: ", a1);
if ( a2 <= 0 )
{
x = 1.0;
}
else
{
v6 = a2;
x = 1.0;
do
{
a4(v12, v10);
x = (long double)(unsigned int)(int)(double)((int)v11 - (int)v13) * x;
if ( a3 == 1 )
printf(" %llu, ", v11 - v13);
--v6;
}
while ( v6 );
}
v7 = powl(x, 1.0 / (long double)a2);
return printf("%25.6Lf clocks. Geom. mean of %4.0d values.\n", v7, (unsigned int)a2);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, int a2, int a3, void (__fastcall *a4)(char *, char *))
{
int v6; // ebx
long double v7; // fst7
long double x; // [rsp+10h] [rbp-68h]
char v10[8]; // [rsp+30h] [rbp-48h] BYREF
__int64 v11; // [rsp+38h] [rbp-40h]
char v12[8]; // [rsp+40h] [rbp-38h] BYREF
__int64 v13; // [rsp+48h] [rbp-30h]

printf("%s: ", a1);
if ( a2 <= 0 )
{
x = 1.0;
}
else
{
v6 = a2;
x = 1.0;
do
{
a4(v12, v10);
x = (long double)(unsigned int)(int)(double)((int)v11 - (int)v13) * x;
if ( a3 == 1 )
printf(" %llu, ", v11 - v13);
--v6;
}
while ( v6 );
}
v7 = powl(x, 1.0 / (long double)a2);
return printf("%25.6Lf clocks. Geom. mean of %4.0d values.\n", v7, (unsigned int)a2);
}

original_code:
void inline rdtscb_measure (char msg[32], int repeats, int detailed, void (*function)( struct timespec *ts, struct timespec *te ) ){
 struct timespec begin, end, diff;
 long double acc = 1;
 int i = 0;
 printf ("%s: ", msg);
 for ( i = repeats; i > 0; i-- ){
  function( &begin, &end );
  diff.tv_nsec = end.tv_nsec - begin.tv_nsec;
  acc *= (long)(double)diff.tv_nsec;
  if ( detailed == 1 )
   printf ( " %llu, ", diff.tv_nsec );
 }
 long double power = 1;
 power /= repeats;
 long double valuemean = powl ( acc, power );
 printf ("%25.6Lf clocks. Geom. mean of %4.0d values.\n", valuemean, repeats );
}

canonical_original_code:
inline void rdtscb_measure(char msg[32], int repeats, int detailed, void (*function)(struct timespec *ts, struct timespec *te)){
 struct timespec begin; struct timespec end; struct timespec diff;
 long double acc = 1;
 int i = 0;
 printf ("%s: ", msg);
 for ( i = repeats; i > 0; i-- ){
  function( &begin, &end );
  diff.tv_nsec = end.tv_nsec - begin.tv_nsec;
  acc *= (long)(double)diff.tv_nsec;
  if ( detailed == 1 )
   printf ( " %llu, ", diff.tv_nsec );
 }
 long double power = 1;
 power /= repeats;
 long double valuemean = powl ( acc, power );
 printf ("%25.6Lf clocks. Geom. mean of %4.0d values.\n", valuemean, repeats );
}

variable_types:
msg
char [32]

variable_types: repeats int

variable_types: detailed int

variable_types: void (*)(struct timespec { long tv_sec; long tv_nsec; } *ts, struct timespec *te)

variable_types:
acc
long double

variable_types:
power
long double

variable_types:
valuemean
long double


decompiled_code:
unsigned __int64 __fastcall rdtscb_getticks(__int64 a1)
{
unsigned __int64 v6; // rdx
unsigned __int64 result; // rax

__asm { cpuid }
result = __rdtsc();
v6 = (unsigned __int64)HIDWORD(result) << 32;
result = (unsigned int)result;
*(_QWORD *)(a1 + 8) = (unsigned int)result | v6;
return result;
}

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

__asm { cpuid }
result = __rdtsc();
v6 = (unsigned __int64)HIDWORD(result) << 32;
result = (unsigned int)result;
*(_QWORD *)(a1 + 8) = (unsigned int)result | v6;
return result;
}

original_code:
__inline__ void rdtscb_getticks(struct timespec *ts) {
 unsigned int a, d;
 asm("cpuid");
 asm volatile("rdtsc" : "=a" (a), "=d" (d));
 ts->tv_nsec = (((uint64_t)a) | (((uint64_t)d) << 32));
}

canonical_original_code:
__inline__ void rdtscb_getticks(struct timespec *ts) {
 unsigned int a; unsigned int d;
 asm("cpuid");
 asm volatile("rdtsc" : "=a" (a), "=d" (d));
 ts->tv_nsec = (((unsigned long)a) | (((unsigned long)d) << 32));
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *

variable_types:
a
unsigned int

variable_types:
d
unsigned int