main

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

while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "hVvf");
if ( v4 == -1 )
break;
if ( v4 == 104 )
{
usage(stdout, *argv);
exit(0);
}
if ( v4 > 104 )
{
if ( v4 != 118 )
goto LABEL_10;
verbose = 1;
}
else
{
if ( v4 == 86 )
{
puts("rm-lowmem (lowmem-tools) 0.1.0");
exit(0);
}
if ( v4 != 102 )
goto LABEL_10;
filesonly = 1;
}
}
v5 = optind;
if ( optind != argc )
{
v6 = 0;
while ( argc > (int)v5 )
{
v7 = argv[v5++];
v6 |= unlink_recursive(v7);
}
exit(v6 != 0);
}
fprintf(stderr, "%s: missing operand\n", *argv);
LABEL_10:
usage(stderr, *argv);
exit(1);
}

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

while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "hVvf");
if ( v4 == -1 )
break;
if ( v4 == 104 )
{
func7(stdout, *argv);
exit(0);
}
if ( v4 > 104 )
{
if ( v4 != 118 )
goto LABEL_10;
verbose = 1;
}
else
{
if ( v4 == 86 )
{
puts("rm-lowmem (lowmem-tools) 0.1.0");
exit(0);
}
if ( v4 != 102 )
goto LABEL_10;
filesonly = 1;
}
}
v5 = optind;
if ( optind != argc )
{
v6 = 0;
while ( argc > (int)v5 )
{
v7 = argv[v5++];
v6 |= func8(v7);
}
exit(v6 != 0);
}
fprintf(stderr, "%s: missing operand\n", *argv);
LABEL_10:
func7(stderr, *argv);
exit(1);
}

original_code:
int main(int argc, char *argv[]) {
  int i, opt, fail=0;
  const char *dirname;
  while((opt = getopt(argc, argv, "hVvf")) != -1) {
    switch(opt) {
    case 'h':
      usage(stdout, argv[0]);
      exit(0);
    case 'V':
      printf("rm-lowmem (lowmem-tools) " "0.1.0" "\n");
      exit(0);
    case 'v':
      verbose = 1;
      break;
    case 'f':
      filesonly = 1;
      break;
    default:
      usage(stderr, argv[0]);
      exit(1);
    }
  }
  if(optind == argc) {
    fprintf(stderr, "%s: missing operand\n", argv[0]);
    usage(stderr, argv[0]);
    exit(1);
  }
  for(i = optind; i < argc; ++i) {
    dirname = argv[i];
    fail |= unlink_recursive(dirname);
  }
  exit(fail ? 1 : 0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int i; int opt; int fail = 0;
  char *dirname;
  while((opt = getopt(argc, argv, "hVvf")) != -1) {
    switch(opt) {
    case 'h':
      usage(stdout, argv[0]);
      exit(0);
    case 'V':
      printf("rm-lowmem (lowmem-tools) " "0.1.0" "\n");
      exit(0);
    case 'v':
      verbose = 1;
      break;
    case 'f':
      filesonly = 1;
      break;
    default:
      usage(stderr, argv[0]);
      exit(1);
    }
  }
  if(optind == argc) {
    fprintf(stderr, "%s: missing operand\n", argv[0]);
    usage(stderr, argv[0]);
    exit(1);
  }
  for(i = optind; i < argc; ++i) {
    dirname = argv[i];
    fail |= unlink_recursive(dirname);
  }
  exit(fail ? 1 : 0);
}

variable_types:
argv
char *[]

variable_types: i int

variable_types: opt int

variable_types: fail int


repo: ScottDuckworth/lowmem-tools

decompiled_code:
__int64 __fastcall ls_lowmem(char *s)
{
unsigned int v1; // er13
int v2; // eax
int v3; // er12
int v4; // ebp
_BYTE v6[32808]; // [rsp+0h] [rbp-8028h] BYREF

v1 = open(s, 0x10000);
if ( v1 == -1 )
goto LABEL_11;
while ( 1 )
{
v2 = syscall(78LL, v1, v6, 0x8000LL);
v3 = v2;
if ( v2 == -1 )
break;
if ( !v2 )
goto LABEL_9;
if ( v2 > 0 )
{
v4 = 0;
do
{
puts(&v6[v4 + 18]);
v4 += *(unsigned __int16 *)&v6[v4 + 16];
}
while ( v3 > v4 );
}
}
v3 = 1;
snprintf(error_message, 0x1000uLL, "getdents failed on %s", s);
LABEL_9:
if ( close(v1) == -1 )
{
LABEL_11:
v3 = 1;
perror(s);
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s)
{
unsigned int v1; // er13
int v2; // eax
int v3; // er12
int v4; // ebp
_BYTE v6[32808]; // [rsp+0h] [rbp-8028h] BYREF

v1 = open(s, 0x10000);
if ( v1 == -1 )
goto LABEL_11;
while ( 1 )
{
v2 = syscall(78LL, v1, v6, 0x8000LL);
v3 = v2;
if ( v2 == -1 )
break;
if ( !v2 )
goto LABEL_9;
if ( v2 > 0 )
{
v4 = 0;
do
{
puts(&v6[v4 + 18]);
v4 += *(unsigned __int16 *)&v6[v4 + 16];
}
while ( v3 > v4 );
}
}
v3 = 1;
snprintf(error_message, 0x1000uLL, "getdents failed on %s", s);
LABEL_9:
if ( close(v1) == -1 )
{
LABEL_11:
v3 = 1;
perror(s);
}
return (unsigned int)v3;
}

original_code:
static int ls_lowmem(const char *dirname) {
  int fd, nread, bpos, rc=0;
  char buf[32768];
  struct linux_dirent *d;
  fd = open(dirname, 00 | 0200000);
  if(fd == -1) {
    perror(dirname);
    return 1;
  }
  for(;;) {
    nread = syscall(78, fd, buf, sizeof(buf));
    if(nread == -1) {
      snprintf(error_message, sizeof(error_message), "getdents failed on %s", dirname);
      rc = 1;
      goto out;
    }
    if(nread == 0)
      break;
    for(bpos = 0; bpos < nread; bpos += d->d_reclen) {
      d = (struct linux_dirent *)(buf + bpos);
      printf("%s\n", d->d_name);
    }
  }
out:
  if(close(fd) == -1) {
    perror(dirname);
    rc = 1;
  }
  return rc;
}

canonical_original_code:
static int ls_lowmem(char *dirname) {
  int fd; int nread; int bpos; int rc = 0;
  char buf[32768];
  struct linux_dirent *d;
  fd = open(dirname, 00 | 0200000);
  if(fd == -1) {
    perror(dirname);
    return 1;
  }
  for(;;) {
    nread = syscall(78, fd, buf, sizeof(buf));
    if(nread == -1) {
      snprintf(error_message, sizeof(error_message), "getdents failed on %s", dirname);
      rc = 1;
      goto out;
    }
    if(nread == 0)
      break;
    for(bpos = 0; bpos < nread; bpos += d->d_reclen) {
      d = (struct linux_dirent *)(buf + bpos);
      printf("%s\n", d->d_name);
    }
  }
out:
  if(close(fd) == -1) {
    perror(dirname);
    rc = 1;
  }
  return rc;
}

variable_types:
dirname
char *

variable_types: fd int

variable_types: nread int

variable_types: bpos int

variable_types: rc int

variable_types:
buf
char [32768]

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

return_type: int


canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v4; // eax
const char *v5; // rsi
int v6; // er13
char **v7; // rbx
const char **v8; // r14
const char *v9; // rsi
char *v10; // r12
char *v11; // rdi

v4 = getopt(argc, (char *const *)argv, "hV");
if ( v4 != -1 )
{
if ( v4 != 86 )
{
v5 = *argv;
if ( v4 != 104 )
{
usage(stderr, v5);
exit(1);
}
usage(_bss_start, v5);
exit(0);
}
puts("ls-lowmem (lowmem-tools) 0.1.0");
exit(0);
}
if ( optind == argc )
{
ls_lowmem(".");
}
else if ( optind < argc )
{
v6 = 0;
v7 = (char **)&argv[optind];
v8 = &(&argv[optind])[(unsigned __int64)(unsigned int)(argc + ~optind) + 1];
do
{
while ( 1 )
{
v10 = *v7;
if ( argc <= 2 )
break;
v9 = *v7++;
printf("%s:\n", v9);
ls_lowmem(v10);
putchar(10);
if ( v7 == (char **)v8 )
goto LABEL_13;
}
v11 = *v7++;
v6 |= ls_lowmem(v11);
}
while ( v7 != (char **)v8 );
LABEL_13:
exit(v6 != 0);
}
v6 = 0;
goto LABEL_13;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v4; // eax
const char *v5; // rsi
int v6; // er13
char **v7; // rbx
const char **v8; // r14
const char *v9; // rsi
char *v10; // r12
char *v11; // rdi

v4 = getopt(argc, (char *const *)argv, "hV");
if ( v4 != -1 )
{
if ( v4 != 86 )
{
v5 = *argv;
if ( v4 != 104 )
{
func7(stderr, v5);
exit(1);
}
func7(_bss_start, v5);
exit(0);
}
puts("ls-lowmem (lowmem-tools) 0.1.0");
exit(0);
}
if ( optind == argc )
{
func8(".");
}
else if ( optind < argc )
{
v6 = 0;
v7 = (char **)&argv[optind];
v8 = &(&argv[optind])[(unsigned __int64)(unsigned int)(argc + ~optind) + 1];
do
{
while ( 1 )
{
v10 = *v7;
if ( argc <= 2 )
break;
v9 = *v7++;
printf("%s:\n", v9);
func8(v10);
putchar(10);
if ( v7 == (char **)v8 )
goto LABEL_13;
}
v11 = *v7++;
v6 |= func8(v11);
}
while ( v7 != (char **)v8 );
LABEL_13:
exit(v6 != 0);
}
v6 = 0;
goto LABEL_13;
}

original_code:
int main(int argc, char *argv[]) {
  int i, opt, fail=0;
  const char *dirname;
  while((opt = getopt(argc, argv, "hV")) != -1) {
    switch(opt) {
    case 'h':
      usage(stdout, argv[0]);
      exit(0);
    case 'V':
      printf("ls-lowmem (lowmem-tools) " "0.1.0" "\n");
      exit(0);
    default:
      usage(stderr, argv[0]);
      exit(1);
    }
  }
  if(optind == argc) {
    ls_lowmem(".");
  } else {
    for(i = optind; i < argc; ++i) {
      dirname = argv[i];
      if(argc > 2) {
        printf("%s:\n", dirname);
        ls_lowmem(dirname);
        printf("\n");
      } else {
        fail |= ls_lowmem(dirname);
      }
    }
  }
  exit(fail ? 1 : 0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int i; int opt; int fail = 0;
  char *dirname;
  while((opt = getopt(argc, argv, "hV")) != -1) {
    switch(opt) {
    case 'h':
      usage(stdout, argv[0]);
      exit(0);
    case 'V':
      printf("ls-lowmem (lowmem-tools) " "0.1.0" "\n");
      exit(0);
    default:
      usage(stderr, argv[0]);
      exit(1);
    }
  }
  if(optind == argc) {
    ls_lowmem(".");
  } else {
    for(i = optind; i < argc; ++i) {
      dirname = argv[i];
      if(argc > 2) {
        printf("%s:\n", dirname);
        ls_lowmem(dirname);
        printf("\n");
      } else {
        fail |= ls_lowmem(dirname);
      }
    }
  }
  exit(fail ? 1 : 0);
}

variable_types: argc int


repo: ScottDuckworth/mtpt

original_code:
static void * threadpool_consumer(void *arg) {
  struct threadpool *tp = arg;
  struct threadpool_task task;
  pthread_mutex_lock(&tp->mutex);
  while(1) {
    while(tp->qcount == 0) {
      if(tp->stop) {
        pthread_mutex_unlock(&tp->mutex);
        return ((void *)0);
      }
      pthread_cond_wait(&tp->consumer, &tp->mutex);
    }
    if(tp->qcount-- == tp->qmax)
      pthread_cond_signal(&tp->producer);
    if(tp->priority_cmp) {
      size_t c, p, l, r;
      task = tp->q[0];
      c = tp->qcount;
      if(c) {
        p = 0;
        while((l = (p << 1) | 1) < c) {
          r = (p << 1) + 2;
          if((*tp->priority_cmp)(&tp->q[l], &tp->q[c]) > 0) {
            if(r < c && (*tp->priority_cmp)(&tp->q[r], &tp->q[l]) > 0) {
              tp->q[p] = tp->q[r];
              p = r;
            } else {
              tp->q[p] = tp->q[l];
              p = l;
            }
          } else {
            if(r < c && (*tp->priority_cmp)(&tp->q[r], &tp->q[c]) > 0) {
              tp->q[p] = tp->q[r];
              p = r;
            } else {
              break;
            }
          }
        }
        tp->q[p] = tp->q[c];
      }
    } else {
      task = tp->q[tp->qhead];
      tp->qhead = (tp->qhead + 1) & (tp->qsize - 1);
    }
    ++tp->running;
    pthread_mutex_unlock(&tp->mutex);
    (*task.routine)(task.arg);
    pthread_mutex_lock(&tp->mutex);
    --tp->running;
  }
}

canonical_original_code:
static void *threadpool_consumer(void *arg) {
  struct threadpool *tp = arg;
  struct threadpool_task task;
  pthread_mutex_lock(&tp->mutex);
  while(1) {
    while(tp->qcount == 0) {
      if(tp->stop) {
        pthread_mutex_unlock(&tp->mutex);
        return ((void *)0);
      }
      pthread_cond_wait(&tp->consumer, &tp->mutex);
    }
    if(tp->qcount-- == tp->qmax)
      pthread_cond_signal(&tp->producer);
    if(tp->priority_cmp) {
      unsigned long c; unsigned long p; unsigned long l; unsigned long r;
      task = tp->q[0];
      c = tp->qcount;
      if(c) {
        p = 0;
        while((l = (p << 1) | 1) < c) {
          r = (p << 1) + 2;
          if((*tp->priority_cmp)(&tp->q[l], &tp->q[c]) > 0) {
            if(r < c && (*tp->priority_cmp)(&tp->q[r], &tp->q[l]) > 0) {
              tp->q[p] = tp->q[r];
              p = r;
            } else {
              tp->q[p] = tp->q[l];
              p = l;
            }
          } else {
            if(r < c && (*tp->priority_cmp)(&tp->q[r], &tp->q[c]) > 0) {
              tp->q[p] = tp->q[r];
              p = r;
            } else {
              break;
            }
          }
        }
        tp->q[p] = tp->q[c];
      }
    } else {
      task = tp->q[tp->qhead];
      tp->qhead = (tp->qhead + 1) & (tp->qsize - 1);
    }
    ++tp->running;
    pthread_mutex_unlock(&tp->mutex);
    (*task.routine)(task.arg);
    pthread_mutex_lock(&tp->mutex);
    --tp->running;
  }
}

variable_types:
arg
void *

variable_types: struct threadpool { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } producer; union pthread_cond_t consumer; int stop; unsigned long nthreads; unsigned long running; unsigned long *threads; int (*priority_cmp)(struct threadpool_task { void (*routine)(void *); void *arg; } *, struct threadpool_task *); struct threadpool_task *q; unsigned long qsize; unsigned long qhead; unsigned long qcount; unsigned long qmax; } *

variable_types:
c
unsigned long

variable_types:
p
unsigned long

variable_types:
l
unsigned long

variable_types:
r
unsigned long

return_type: void *

user_defined_types: struct threadpool { union pthread_mutex_t mutex; union pthread_cond_t producer; union pthread_cond_t consumer; int stop; unsigned long nthreads; unsigned long running; unsigned long *threads; int (*priority_cmp)(struct threadpool_task *, struct threadpool_task *); struct threadpool_task *q; unsigned long qsize; unsigned long qhead; unsigned long qcount; unsigned long qmax; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


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

if ( !a1 )
_assert_fail("val != 0", "threadpool.c", 0xA8u, "ilog2");
if ( a1 > 0x8000000000000000LL )
_assert_fail("val <= ~(((size_t)-1) >> 1)", "threadpool.c", 0xA9u, "ilog2");
LODWORD(result) = -1;
do
{
result = (unsigned int)(result + 1);
a1 >>= 1;
}
while ( a1 );
return result;
}

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

if ( !a1 )
_assert_fail("val != 0", "threadpool.c", 0xA8u, "ilog2");
if ( a1 > 0x8000000000000000LL )
_assert_fail("val <= ~(((size_t)-1) >> 1)", "threadpool.c", 0xA9u, "ilog2");
LODWORD(result) = -1;
do
{
result = (unsigned int)(result + 1);
a1 >>= 1;
}
while ( a1 );
return result;
}

original_code:
static inline int ilog2(size_t val) {
  int i;
  ((void) sizeof ((val != 0) ? 1 : 0), __extension__ ({ if (val != 0) ; else __assert_fail ("val != 0", "threadpool.c", 168, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((val <= ~(((size_t)-1) >> 1)) ? 1 : 0), __extension__ ({ if (val <= ~(((size_t)-1) >> 1)) ; else __assert_fail ("val <= ~(((size_t)-1) >> 1)", "threadpool.c", 169, __extension__ __PRETTY_FUNCTION__); }));
  for(i = -1; val; ++i) val >>= 1;
  return i;
}

canonical_original_code:
static inline int ilog2(unsigned long val) {
  int i;
  ((void) sizeof ((val != 0) ? 1 : 0), __extension__ ({ if (val != 0) ; else __assert_fail ("val != 0", "threadpool.c", 168, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((val <= ~(((unsigned long)-1) >> 1)) ? 1 : 0), __extension__ ({ if (val <= ~(((unsigned long)-1) >> 1)) ; else __assert_fail ("val <= ~(((size_t)-1) >> 1)", "threadpool.c", 169, __extension__ __PRETTY_FUNCTION__); }));
  for(i = -1; val; ++i) val >>= 1;
  return i;
}

variable_types:
val
unsigned long

variable_types: i int


decompiled_code:
__int64 __fastcall threadpool_add(pthread_mutex_t *mutex, __int64 a2, __int64 a3)
{
unsigned int v5; // er12
__int64 v6; // rax
unsigned __int64 v7; // rbx
struct __pthread_internal_list *v8; // rax
char *v9; // rax
unsigned __int64 v10; // r15
__int64 v11; // r15
unsigned __int64 v13; // rdx
__m128i *v14; // r15
unsigned __int64 v15; // rax
__m128i *v16; // rdi
struct __pthread_internal_list *v17; // rax
__m128i *v18; // rsi
struct __pthread_internal_list *v19; // rbx
unsigned __int64 v20; // rcx
struct __pthread_internal_list *v21; // rax
struct __pthread_internal_list *v22; // rdx
unsigned __int64 v24; // [rsp+8h] [rbp-50h]
__int64 v25[9]; // [rsp+10h] [rbp-48h] BYREF

v5 = pthread_mutex_lock(mutex);
if ( !v5 )
{
v5 = mutex[3].__kind;
if ( v5 )
{
v5 = 22;
goto LABEL_18;
}
v6 = *(&mutex[5].__align + 1);
v7 = mutex[5].__align;
if ( v6 && v6 == v7 )
{
do
{
pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex);
v7 = mutex[5].__align;
}
while ( v7 == *(&mutex[5].__align + 1) );
}
v8 = mutex[4].__list.__prev;
if ( *(&mutex[4].__align + 1) )
{
if ( (struct __pthread_internal_list *)v7 != v8 )
{
v9 = (char *)*(&mutex[4].__align + 2);
LABEL_9:
v25[0] = a2;
v25[1] = a3;
if ( !v7 )
{
*(_QWORD *)v9 = a2;
*((_QWORD *)v9 + 1) = a3;
mutex[5].__align = 1LL;
LABEL_15:
pthread_cond_signal((pthread_cond_t *)(&mutex[2].__align + 1));
pthread_mutex_unlock(mutex);
return v5;
}
do
{
v10 = v7;
v7 = (v7 - 1) >> 1;
v11 = 16 * v10;
if ( (*((int (__fastcall **)(__int64 *, char *))&mutex[4].__align + 1))(v25, &v9[16 * v7]) <= 0 )
{
v7 = mutex[5].__align;
v9 = (char *)(v11 + *(&mutex[4].__align + 2));
goto LABEL_14;
}
v9 = (char *)*(&mutex[4].__align + 2);
*(__m128i *)&v9[v11] = _mm_loadu_si128((const __m128i *)&v9[16 * v7]);
}
while ( v7 );
v7 = mutex[5].__align;
goto LABEL_14;
}
if ( v7 != 0x8000000000000000LL )
{
v9 = (char *)realloc(*((void **)&mutex[4].__align + 2), 32 * v7);
if ( v9 )
{
*(&mutex[4].__align + 2) = (__int64)v9;
v7 = mutex[5].__align;
mutex[4].__list.__prev = (struct __pthread_internal_list *)((__int64)mutex[4].__list.__prev * 2);
goto LABEL_9;
}
LABEL_33:
v5 = *_errno_location();
goto LABEL_18;
}
LABEL_26:
v5 = 12;
goto LABEL_18;
}
v13 = (unsigned __int64)&v8[-1].__next + 7;
if ( (struct __pthread_internal_list *)v7 == v8 )
{
v24 = (unsigned __int64)&v8[-1].__next + 7;
if ( v7 == 0x8000000000000000LL )
goto LABEL_26;
v14 = (__m128i *)malloc(32 * v7);
if ( !v14 )
goto LABEL_33;
v16 = (__m128i *)*(&mutex[4].__align + 2);
if ( v7 )
{
v17 = mutex[4].__list.__next;
v18 = v14;
v19 = (struct __pthread_internal_list *)((char *)v17 + v7);
do
{
++v18;
v20 = (unsigned __int64)v17 & v24;
v17 = (struct __pthread_internal_list *)((char *)v17 + 1);
v18[-1] = _mm_loadu_si128(&v16[v20]);
}
while ( v19 != v17 );
}
free(v16);
v21 = mutex[4].__list.__prev;
v7 = mutex[5].__align;
*(&mutex[4].__align + 2) = (__int64)v14;
mutex[4].__list.__next = 0LL;
v22 = (struct __pthread_internal_list *)(2LL * (_QWORD)v21);
v15 = v7;
mutex[4].__list.__prev = v22;
v13 = (unsigned __int64)&v22[-1].__next + 7;
}
else
{
v14 = (__m128i *)*(&mutex[4].__align + 2);
v15 = (unsigned __int64)mutex[4].__list.__next + v7;
}
v9 = v14[v15 & v13].m128i_i8;
LABEL_14:
*(_QWORD *)v9 = a2;
*((_QWORD *)v9 + 1) = a3;
mutex[5].__align = v7 + 1;
if ( !v7 )
goto LABEL_15;
LABEL_18:
pthread_mutex_unlock(mutex);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(pthread_mutex_t *mutex, __int64 a2, __int64 a3)
{
unsigned int v5; // er12
__int64 v6; // rax
unsigned __int64 v7; // rbx
struct __pthread_internal_list *v8; // rax
char *v9; // rax
unsigned __int64 v10; // r15
__int64 v11; // r15
unsigned __int64 v13; // rdx
__m128i *v14; // r15
unsigned __int64 v15; // rax
__m128i *v16; // rdi
struct __pthread_internal_list *v17; // rax
__m128i *v18; // rsi
struct __pthread_internal_list *v19; // rbx
unsigned __int64 v20; // rcx
struct __pthread_internal_list *v21; // rax
struct __pthread_internal_list *v22; // rdx
unsigned __int64 v24; // [rsp+8h] [rbp-50h]
__int64 v25[9]; // [rsp+10h] [rbp-48h] BYREF

v5 = pthread_mutex_lock(mutex);
if ( !v5 )
{
v5 = mutex[3].__kind;
if ( v5 )
{
v5 = 22;
goto LABEL_18;
}
v6 = *(&mutex[5].__align + 1);
v7 = mutex[5].__align;
if ( v6 && v6 == v7 )
{
do
{
pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex);
v7 = mutex[5].__align;
}
while ( v7 == *(&mutex[5].__align + 1) );
}
v8 = mutex[4].__list.__prev;
if ( *(&mutex[4].__align + 1) )
{
if ( (struct __pthread_internal_list *)v7 != v8 )
{
v9 = (char *)*(&mutex[4].__align + 2);
LABEL_9:
v25[0] = a2;
v25[1] = a3;
if ( !v7 )
{
*(_QWORD *)v9 = a2;
*((_QWORD *)v9 + 1) = a3;
mutex[5].__align = 1LL;
LABEL_15:
pthread_cond_signal((pthread_cond_t *)(&mutex[2].__align + 1));
pthread_mutex_unlock(mutex);
return v5;
}
do
{
v10 = v7;
v7 = (v7 - 1) >> 1;
v11 = 16 * v10;
if ( (*((int (__fastcall **)(__int64 *, char *))&mutex[4].__align + 1))(v25, &v9[16 * v7]) <= 0 )
{
v7 = mutex[5].__align;
v9 = (char *)(v11 + *(&mutex[4].__align + 2));
goto LABEL_14;
}
v9 = (char *)*(&mutex[4].__align + 2);
*(__m128i *)&v9[v11] = _mm_loadu_si128((const __m128i *)&v9[16 * v7]);
}
while ( v7 );
v7 = mutex[5].__align;
goto LABEL_14;
}
if ( v7 != 0x8000000000000000LL )
{
v9 = (char *)realloc(*((void **)&mutex[4].__align + 2), 32 * v7);
if ( v9 )
{
*(&mutex[4].__align + 2) = (__int64)v9;
v7 = mutex[5].__align;
mutex[4].__list.__prev = (struct __pthread_internal_list *)((__int64)mutex[4].__list.__prev * 2);
goto LABEL_9;
}
LABEL_33:
v5 = *_errno_location();
goto LABEL_18;
}
LABEL_26:
v5 = 12;
goto LABEL_18;
}
v13 = (unsigned __int64)&v8[-1].__next + 7;
if ( (struct __pthread_internal_list *)v7 == v8 )
{
v24 = (unsigned __int64)&v8[-1].__next + 7;
if ( v7 == 0x8000000000000000LL )
goto LABEL_26;
v14 = (__m128i *)malloc(32 * v7);
if ( !v14 )
goto LABEL_33;
v16 = (__m128i *)*(&mutex[4].__align + 2);
if ( v7 )
{
v17 = mutex[4].__list.__next;
v18 = v14;
v19 = (struct __pthread_internal_list *)((char *)v17 + v7);
do
{
++v18;
v20 = (unsigned __int64)v17 & v24;
v17 = (struct __pthread_internal_list *)((char *)v17 + 1);
v18[-1] = _mm_loadu_si128(&v16[v20]);
}
while ( v19 != v17 );
}
free(v16);
v21 = mutex[4].__list.__prev;
v7 = mutex[5].__align;
*(&mutex[4].__align + 2) = (__int64)v14;
mutex[4].__list.__next = 0LL;
v22 = (struct __pthread_internal_list *)(2LL * (_QWORD)v21);
v15 = v7;
mutex[4].__list.__prev = v22;
v13 = (unsigned __int64)&v22[-1].__next + 7;
}
else
{
v14 = (__m128i *)*(&mutex[4].__align + 2);
v15 = (unsigned __int64)mutex[4].__list.__next + v7;
}
v9 = v14[v15 & v13].m128i_i8;
LABEL_14:
*(_QWORD *)v9 = a2;
*((_QWORD *)v9 + 1) = a3;
mutex[5].__align = v7 + 1;
if ( !v7 )
goto LABEL_15;
LABEL_18:
pthread_mutex_unlock(mutex);
}
return v5;
}

original_code:
int threadpool_add(struct threadpool *tp, void (*routine)(void *), void *arg) {
  int rc, ret = 0;
  struct threadpool_task *task;
  rc = pthread_mutex_lock(&tp->mutex);
  if(rc) return rc;
  if(tp->stop) {
    ret = 22;
    goto out;
  }
  if(tp->qmax) {
    while(tp->qcount == tp->qmax) {
      pthread_cond_wait(&tp->producer, &tp->mutex);
    }
  }
  if(tp->priority_cmp) {
    size_t c, p;
    struct threadpool_task t;
    if(tp->qcount == tp->qsize) {
      if(tp->qsize == ~(((size_t)-1) >> 1)) {
        ret = 12;
        goto out;
      }
      task = realloc(tp->q, sizeof(struct threadpool_task) * (tp->qsize << 1));
      if(task == ((void *)0)) {
        ret = (*__errno_location ());
        goto out;
      }
      tp->q = task;
      tp->qsize <<= 1;
    }
    t.routine = routine;
    t.arg = arg;
    c = tp->qcount;
    while(c) {
      p = (c - 1) >> 1;
      rc = (*tp->priority_cmp)(&t, &tp->q[p]);
      if(rc <= 0) break;
      tp->q[c] = tp->q[p];
      c = p;
    }
    task = &tp->q[c];
  } else {
    size_t i, mask;
    mask = tp->qsize - 1;
    if(tp->qcount == tp->qsize) {
      if(tp->qsize == ~(((size_t)-1) >> 1)) {
        ret = 12;
        goto out;
      }
      task = malloc(sizeof(struct threadpool_task) * (tp->qsize << 1));
      if(task == ((void *)0)) {
        ret = (*__errno_location ());
        goto out;
      }
      for(i = 0; i < tp->qsize; ++i) {
        task[i] = tp->q[(tp->qhead + i) & mask];
      }
      free(tp->q);
      tp->q = task;
      tp->qsize <<= 1;
      tp->qhead = 0;
      mask = tp->qsize - 1;
    }
    task = &tp->q[(tp->qhead + tp->qcount) & mask];
  }
  task->routine = routine;
  task->arg = arg;
  if(tp->qcount++ == 0)
    pthread_cond_signal(&tp->consumer);
out:
  pthread_mutex_unlock(&tp->mutex);
  return ret;
}

canonical_original_code:
int threadpool_add(struct threadpool *tp, void (*routine)(void *), void *arg) {
  int rc; int ret = 0;
  struct threadpool_task *task;
  rc = pthread_mutex_lock(&tp->mutex);
  if(rc) return rc;
  if(tp->stop) {
    ret = 22;
    goto out;
  }
  if(tp->qmax) {
    while(tp->qcount == tp->qmax) {
      pthread_cond_wait(&tp->producer, &tp->mutex);
    }
  }
  if(tp->priority_cmp) {
    unsigned long c; unsigned long p;
    struct threadpool_task t;
    if(tp->qcount == tp->qsize) {
      if(tp->qsize == ~(((unsigned long)-1) >> 1)) {
        ret = 12;
        goto out;
      }
      task = realloc(tp->q, sizeof(struct threadpool_task) * (tp->qsize << 1));
      if(task == ((void *)0)) {
        ret = (*__errno_location ());
        goto out;
      }
      tp->q = task;
      tp->qsize <<= 1;
    }
    t.routine = routine;
    t.arg = arg;
    c = tp->qcount;
    while(c) {
      p = (c - 1) >> 1;
      rc = (*tp->priority_cmp)(&t, &tp->q[p]);
      if(rc <= 0) break;
      tp->q[c] = tp->q[p];
      c = p;
    }
    task = &tp->q[c];
  } else {
    unsigned long i; unsigned long mask;
    mask = tp->qsize - 1;
    if(tp->qcount == tp->qsize) {
      if(tp->qsize == ~(((unsigned long)-1) >> 1)) {
        ret = 12;
        goto out;
      }
      task = malloc(sizeof(struct threadpool_task) * (tp->qsize << 1));
      if(task == ((void *)0)) {
        ret = (*__errno_location ());
        goto out;
      }
      for(i = 0; i < tp->qsize; ++i) {
        task[i] = tp->q[(tp->qhead + i) & mask];
      }
      free(tp->q);
      tp->q = task;
      tp->qsize <<= 1;
      tp->qhead = 0;
      mask = tp->qsize - 1;
    }
    task = &tp->q[(tp->qhead + tp->qcount) & mask];
  }
  task->routine = routine;
  task->arg = arg;
  if(tp->qcount++ == 0)
    pthread_cond_signal(&tp->consumer);
out:
  pthread_mutex_unlock(&tp->mutex);
  return ret;
}

variable_types:
routine
void (*)(void *)

variable_types: ret int

variable_types: struct threadpool_task { void (*routine)(void *); void *arg; } *

variable_types:
i
unsigned long

variable_types:
mask
unsigned long

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall threadpool_init_prio(void *arg, __int64 a2, size_t a3, __int64 a4, __int64 a5)
{
unsigned int v8; // er15
size_t v10; // rdi
__int64 v11; // rax
void *v12; // rax
void *v13; // rax
__int64 v14; // r12
unsigned int v15; // eax
__int64 v16; // rbx
unsigned __int64 v17; // rbp
pthread_t v18; // rdi
int v19; // eax
pthread_cond_t *cond; // [rsp+8h] [rbp-80h]
pthread_attr_t attr; // [rsp+10h] [rbp-78h] BYREF

if ( !a2 )
_assert_fail("nthreads > 0", "threadpool.c", 0xB6u, "threadpool_init_prio");
v8 = pthread_mutex_init((pthread_mutex_t *)arg, 0LL);
if ( !v8 )
{
v8 = pthread_cond_init((pthread_cond_t *)((char *)arg + 40), 0LL);
if ( !v8 )
{
cond = (pthread_cond_t *)((char *)arg + 88);
v8 = pthread_cond_init((pthread_cond_t *)((char *)arg + 88), 0LL);
if ( !v8 )
{
v8 = pthread_attr_init(&attr);
if ( !v8 )
{
if ( a3 && (v19 = pthread_attr_setstacksize(&attr, a3)) != 0 )
{
v8 = v19;
}
else
{
*((_DWORD *)arg + 34) = 0;
*((_QWORD *)arg + 18) = a2;
*((_QWORD *)arg + 19) = 0LL;
*((_QWORD *)arg + 21) = a5;
if ( a4 )
{
v11 = 1 << (ilog2(a4 - 1) + 1);
v10 = 16 * v11;
}
else
{
v10 = 128LL;
v11 = 8LL;
}
*((_QWORD *)arg + 23) = v11;
*((_QWORD *)arg + 24) = 0LL;
*((_QWORD *)arg + 25) = 0LL;
*((_QWORD *)arg + 26) = a4;
v12 = malloc(v10);
*((_QWORD *)arg + 22) = v12;
if ( v12 )
{
v13 = malloc(8 * a2);
*((_QWORD *)arg + 20) = v13;
if ( v13 )
{
v14 = 0LL;
pthread_mutex_lock((pthread_mutex_t *)arg);
while ( 1 )
{
v8 = pthread_create((pthread_t *)(*((_QWORD *)arg + 20) + 8 * v14), &attr, threadpool_consumer, arg);
if ( v8 )
break;
if ( a2 == ++v14 )
{
pthread_mutex_unlock((pthread_mutex_t *)arg);
return v8;
}
}
pthread_mutex_unlock((pthread_mutex_t *)arg);
v15 = v14 - 1;
if ( (_DWORD)v14 )
{
v16 = 8LL * (int)v15;
v17 = 8 * ((int)v14 - (unsigned __int64)v15) - 16;
do
{
pthread_cancel(*(_QWORD *)(*((_QWORD *)arg + 20) + v16));
v18 = *(_QWORD *)(*((_QWORD *)arg + 20) + v16);
v16 -= 8LL;
pthread_join(v18, 0LL);
}
while ( v17 != v16 );
}
free(*((void **)arg + 20));
}
free(*((void **)arg + 22));
}
}
pthread_attr_destroy(&attr);
}
pthread_cond_destroy(cond);
}
pthread_cond_destroy((pthread_cond_t *)((char *)arg + 40));
}
pthread_mutex_destroy((pthread_mutex_t *)arg);
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *arg, __int64 a2, size_t a3, __int64 a4, __int64 a5)
{
unsigned int v8; // er15
size_t v10; // rdi
__int64 v11; // rax
void *v12; // rax
void *v13; // rax
__int64 v14; // r12
unsigned int v15; // eax
__int64 v16; // rbx
unsigned __int64 v17; // rbp
pthread_t v18; // rdi
int v19; // eax
pthread_cond_t *cond; // [rsp+8h] [rbp-80h]
pthread_attr_t attr; // [rsp+10h] [rbp-78h] BYREF

if ( !a2 )
_assert_fail("nthreads > 0", "threadpool.c", 0xB6u, "threadpool_init_prio");
v8 = pthread_mutex_init((pthread_mutex_t *)arg, 0LL);
if ( !v8 )
{
v8 = pthread_cond_init((pthread_cond_t *)((char *)arg + 40), 0LL);
if ( !v8 )
{
cond = (pthread_cond_t *)((char *)arg + 88);
v8 = pthread_cond_init((pthread_cond_t *)((char *)arg + 88), 0LL);
if ( !v8 )
{
v8 = pthread_attr_init(&attr);
if ( !v8 )
{
if ( a3 && (v19 = pthread_attr_setstacksize(&attr, a3)) != 0 )
{
v8 = v19;
}
else
{
*((_DWORD *)arg + 34) = 0;
*((_QWORD *)arg + 18) = a2;
*((_QWORD *)arg + 19) = 0LL;
*((_QWORD *)arg + 21) = a5;
if ( a4 )
{
v11 = 1 << (func1(a4 - 1) + 1);
v10 = 16 * v11;
}
else
{
v10 = 128LL;
v11 = 8LL;
}
*((_QWORD *)arg + 23) = v11;
*((_QWORD *)arg + 24) = 0LL;
*((_QWORD *)arg + 25) = 0LL;
*((_QWORD *)arg + 26) = a4;
v12 = malloc(v10);
*((_QWORD *)arg + 22) = v12;
if ( v12 )
{
v13 = malloc(8 * a2);
*((_QWORD *)arg + 20) = v13;
if ( v13 )
{
v14 = 0LL;
pthread_mutex_lock((pthread_mutex_t *)arg);
while ( 1 )
{
v8 = pthread_create((pthread_t *)(*((_QWORD *)arg + 20) + 8 * v14), &attr, threadpool_consumer, arg);
if ( v8 )
break;
if ( a2 == ++v14 )
{
pthread_mutex_unlock((pthread_mutex_t *)arg);
return v8;
}
}
pthread_mutex_unlock((pthread_mutex_t *)arg);
v15 = v14 - 1;
if ( (_DWORD)v14 )
{
v16 = 8LL * (int)v15;
v17 = 8 * ((int)v14 - (unsigned __int64)v15) - 16;
do
{
pthread_cancel(*(_QWORD *)(*((_QWORD *)arg + 20) + v16));
v18 = *(_QWORD *)(*((_QWORD *)arg + 20) + v16);
v16 -= 8LL;
pthread_join(v18, 0LL);
}
while ( v17 != v16 );
}
free(*((void **)arg + 20));
}
free(*((void **)arg + 22));
}
}
pthread_attr_destroy(&attr);
}
pthread_cond_destroy(cond);
}
pthread_cond_destroy((pthread_cond_t *)((char *)arg + 40));
}
pthread_mutex_destroy((pthread_mutex_t *)arg);
}
return v8;
}

original_code:
int threadpool_init_prio(struct threadpool *tp, size_t nthreads, size_t stacksize, size_t qmax, int (*priority_cmp)(const struct threadpool_task *, const struct threadpool_task *)) {
  pthread_attr_t attr;
  int i, rc;
  ((void) sizeof ((nthreads > 0) ? 1 : 0), __extension__ ({ if (nthreads > 0) ; else __assert_fail ("nthreads > 0", "threadpool.c", 182, __extension__ __PRETTY_FUNCTION__); }));
  rc = pthread_mutex_init(&tp->mutex, ((void *)0));
  if(rc) goto err0;
  rc = pthread_cond_init(&tp->producer, ((void *)0));
  if(rc) goto err1;
  rc = pthread_cond_init(&tp->consumer, ((void *)0));
  if(rc) goto err2;
  rc = pthread_attr_init(&attr);
  if(rc) goto err3;
  if(stacksize) {
    rc = pthread_attr_setstacksize(&attr, stacksize);
    if(rc) goto err4;
  }
  tp->stop = 0;
  tp->nthreads = nthreads;
  tp->running = 0;
  tp->priority_cmp = priority_cmp;
  tp->qsize = qmax == 0 ? 8 : 1 << (ilog2(qmax-1)+1);
  tp->qhead = 0;
  tp->qcount = 0;
  tp->qmax = qmax;
  tp->q = malloc(sizeof(struct threadpool_task) * tp->qsize);
  if(!tp->q) goto err4;
  tp->threads = malloc(sizeof(pthread_t) * nthreads);
  if(!tp->threads) goto err5;
  pthread_mutex_lock(&tp->mutex);
  for(i = 0; i < nthreads; ++i) {
    rc = pthread_create(&tp->threads[i], &attr, threadpool_consumer, tp);
    if(rc) goto err6;
  }
  pthread_mutex_unlock(&tp->mutex);
  return 0;
err6:
  pthread_mutex_unlock(&tp->mutex);
  for(--i; i >= 0; --i) {
    pthread_cancel(tp->threads[i]);
    pthread_join(tp->threads[i], ((void *)0));
  }
  free(tp->threads);
err5:
  free(tp->q);
err4:
  pthread_attr_destroy(&attr);
err3:
  pthread_cond_destroy(&tp->consumer);
err2:
  pthread_cond_destroy(&tp->producer);
err1:
  pthread_mutex_destroy(&tp->mutex);
err0:
  return rc;
}

canonical_original_code:
int threadpool_init_prio(struct threadpool *tp, unsigned long nthreads, unsigned long stacksize, unsigned long qmax, int (*priority_cmp)(struct threadpool_task *, struct threadpool_task *)) {
  union pthread_attr_t attr;
  int i; int rc;
  ((void) sizeof ((nthreads > 0) ? 1 : 0), __extension__ ({ if (nthreads > 0) ; else __assert_fail ("nthreads > 0", "threadpool.c", 182, __extension__ __PRETTY_FUNCTION__); }));
  rc = pthread_mutex_init(&tp->mutex, ((void *)0));
  if(rc) goto err0;
  rc = pthread_cond_init(&tp->producer, ((void *)0));
  if(rc) goto err1;
  rc = pthread_cond_init(&tp->consumer, ((void *)0));
  if(rc) goto err2;
  rc = pthread_attr_init(&attr);
  if(rc) goto err3;
  if(stacksize) {
    rc = pthread_attr_setstacksize(&attr, stacksize);
    if(rc) goto err4;
  }
  tp->stop = 0;
  tp->nthreads = nthreads;
  tp->running = 0;
  tp->priority_cmp = priority_cmp;
  tp->qsize = qmax == 0 ? 8 : 1 << (ilog2(qmax-1)+1);
  tp->qhead = 0;
  tp->qcount = 0;
  tp->qmax = qmax;
  tp->q = malloc(sizeof(struct threadpool_task) * tp->qsize);
  if(!tp->q) goto err4;
  tp->threads = malloc(sizeof(pthread_t) * nthreads);
  if(!tp->threads) goto err5;
  pthread_mutex_lock(&tp->mutex);
  for(i = 0; i < nthreads; ++i) {
    rc = pthread_create(&tp->threads[i], &attr, threadpool_consumer, tp);
    if(rc) goto err6;
  }
  pthread_mutex_unlock(&tp->mutex);
  return 0;
err6:
  pthread_mutex_unlock(&tp->mutex);
  for(--i; i >= 0; --i) {
    pthread_cancel(tp->threads[i]);
    pthread_join(tp->threads[i], ((void *)0));
  }
  free(tp->threads);
err5:
  free(tp->q);
err4:
  pthread_attr_destroy(&attr);
err3:
  pthread_cond_destroy(&tp->consumer);
err2:
  pthread_cond_destroy(&tp->producer);
err1:
  pthread_mutex_destroy(&tp->mutex);
err0:
  return rc;
}

variable_types:
nthreads
unsigned long

variable_types:
stacksize
unsigned long

variable_types:
qmax
unsigned long

variable_types: int (*)(struct threadpool_task *, struct threadpool_task *)

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types: rc int

user_defined_types: struct threadpool_task { void (*routine)(void *); void *arg; }


decompiled_code:
__int64 __fastcall threadpool_init(void *a1, __int64 a2, size_t a3, __int64 a4)
{
return threadpool_init_prio(a1, a2, a3, a4, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(void *a1, __int64 a2, size_t a3, __int64 a4)
{
return func3(a1, a2, a3, a4, 0LL);
}

original_code:
int threadpool_init(struct threadpool *tp, size_t nthreads, size_t stacksize, size_t qmax) {
  return threadpool_init_prio(tp, nthreads, stacksize, qmax, ((void *)0));
}

canonical_original_code:
int threadpool_init(struct threadpool *tp, unsigned long nthreads, unsigned long stacksize, unsigned long qmax) {
  return threadpool_init_prio(tp, nthreads, stacksize, qmax, ((void *)0));
}

variable_types: struct threadpool { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } producer; union pthread_cond_t consumer; int stop; unsigned long nthreads; unsigned long running; unsigned long *threads; int (*priority_cmp)(struct threadpool_task { void (*routine)(void *); void *arg; } *, struct threadpool_task *); struct threadpool_task *q; unsigned long qsize; unsigned long qhead; unsigned long qcount; unsigned long qmax; } *


decompiled_code:
int __fastcall threadpool_destroy(pthread_mutex_t *mutex)
{
__int64 v1; // rbx
int result; // eax

pthread_mutex_lock(mutex);
mutex[3].__kind = 1;
pthread_cond_broadcast((pthread_cond_t *)(&mutex[2].__align + 1));
pthread_mutex_unlock(mutex);
if ( mutex[3].__list.__prev )
{
v1 = 0LL;
while ( 1 )
{
result = pthread_join(*(_QWORD *)(mutex[4].__align + 8 * v1), 0LL);
if ( result )
break;
if ( mutex[3].__list.__prev <= (struct __pthread_internal_list *)++v1 )
goto LABEL_6;
}
}
else
{
LABEL_6:
free((void *)mutex[4].__align);
free(*((void **)&mutex[4].__align + 2));
result = pthread_cond_destroy((pthread_cond_t *)(&mutex[2].__align + 1));
if ( !result )
{
result = pthread_cond_destroy((pthread_cond_t *)&mutex[1]);
if ( !result )
result = pthread_mutex_destroy(mutex);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(pthread_mutex_t *mutex)
{
__int64 v1; // rbx
int result; // eax

pthread_mutex_lock(mutex);
mutex[3].__kind = 1;
pthread_cond_broadcast((pthread_cond_t *)(&mutex[2].__align + 1));
pthread_mutex_unlock(mutex);
if ( mutex[3].__list.__prev )
{
v1 = 0LL;
while ( 1 )
{
result = pthread_join(*(_QWORD *)(mutex[4].__align + 8 * v1), 0LL);
if ( result )
break;
if ( mutex[3].__list.__prev <= (struct __pthread_internal_list *)++v1 )
goto LABEL_6;
}
}
else
{
LABEL_6:
free((void *)mutex[4].__align);
free(*((void **)&mutex[4].__align + 2));
result = pthread_cond_destroy((pthread_cond_t *)(&mutex[2].__align + 1));
if ( !result )
{
result = pthread_cond_destroy((pthread_cond_t *)&mutex[1]);
if ( !result )
result = pthread_mutex_destroy(mutex);
}
}
return result;
}

original_code:
int threadpool_destroy(struct threadpool *tp) {
  int i, rc;
  pthread_mutex_lock(&tp->mutex);
  tp->stop = 1;
  pthread_cond_broadcast(&tp->consumer);
  pthread_mutex_unlock(&tp->mutex);
  for(i = 0; i < tp->nthreads; ++i) {
    rc = pthread_join(tp->threads[i], ((void *)0));
    if(rc) return rc;
  }
  free(tp->threads);
  free(tp->q);
  rc = pthread_cond_destroy(&tp->consumer);
  if(rc) return rc;
  rc = pthread_cond_destroy(&tp->producer);
  if(rc) return rc;
  rc = pthread_mutex_destroy(&tp->mutex);
  if(rc) return rc;
  return 0;
}

canonical_original_code:
int threadpool_destroy(struct threadpool *tp) {
  int i; int rc;
  pthread_mutex_lock(&tp->mutex);
  tp->stop = 1;
  pthread_cond_broadcast(&tp->consumer);
  pthread_mutex_unlock(&tp->mutex);
  for(i = 0; i < tp->nthreads; ++i) {
    rc = pthread_join(tp->threads[i], ((void *)0));
    if(rc) return rc;
  }
  free(tp->threads);
  free(tp->q);
  rc = pthread_cond_destroy(&tp->consumer);
  if(rc) return rc;
  rc = pthread_cond_destroy(&tp->producer);
  if(rc) return rc;
  rc = pthread_mutex_destroy(&tp->mutex);
  if(rc) return rc;
  return 0;
}


excluded

decompiled_code:
__int64 __fastcall excluded(__int64 a1, __int64 a2, const char *a3, int a4)
{
__int64 v5; // rbp
char *v6; // r15
size_t v7; // rax
size_t v8; // rbx
char v9; // al
const char *v10; // rbx
int v12; // [rsp+Ch] [rbp-103Ch]
char dest[4152]; // [rsp+10h] [rbp-1038h] BYREF

v12 = a4;
if ( !a2 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(char **)(a1 + 8 * v5);
v7 = strlen(v6);
v8 = v7 - 1;
if ( v6[v7 - 1] == 47 )
{
if ( !v12 )
return 0LL;
memcpy(dest, v6, v7 + 1);
v6 = dest;
dest[v8] = 0;
}
if ( *v6 == 47 )
{
if ( !fnmatch(v6 + 1, a3, 1) )
return 1LL;
goto LABEL_4;
}
if ( !fnmatch(v6, a3, 1) )
return 1LL;
v9 = *a3;
if ( *a3 )
break;
LABEL_4:
if ( a2 == ++v5 )
return 0LL;
}
v10 = a3;
while ( 1 )
{
++v10;
if ( v9 == 47 && !fnmatch(v6, v10, 1) )
return 1LL;
v9 = *v10;
if ( !*v10 )
goto LABEL_4;
}
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, const char *a3, int a4)
{
__int64 v5; // rbp
char *v6; // r15
size_t v7; // rax
size_t v8; // rbx
char v9; // al
const char *v10; // rbx
int v12; // [rsp+Ch] [rbp-103Ch]
char dest[4152]; // [rsp+10h] [rbp-1038h] BYREF

v12 = a4;
if ( !a2 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(char **)(a1 + 8 * v5);
v7 = strlen(v6);
v8 = v7 - 1;
if ( v6[v7 - 1] == 47 )
{
if ( !v12 )
return 0LL;
memcpy(dest, v6, v7 + 1);
v6 = dest;
dest[v8] = 0;
}
if ( *v6 == 47 )
{
if ( !fnmatch(v6 + 1, a3, 1) )
return 1LL;
goto LABEL_4;
}
if ( !fnmatch(v6, a3, 1) )
return 1LL;
v9 = *a3;
if ( *a3 )
break;
LABEL_4:
if ( a2 == ++v5 )
return 0LL;
}
v10 = a3;
while ( 1 )
{
++v10;
if ( v9 == 47 && !fnmatch(v6, v10, 1) )
return 1LL;
v9 = *v10;
if ( !*v10 )
goto LABEL_4;
}
}

original_code:
int excluded(
  const char * const *patterns,
  size_t npatterns,
  const char *path,
  int isdir
) {
  size_t i, l;
  const char *p, *tail;
  char pattern[4096];
  for(i = 0; i < npatterns; ++i) {
    p = patterns[i];
    l = strlen(p);
    if(p[l-1] == '/') {
      if(!isdir) return 0;
      strcpy(pattern, p);
      pattern[--l] = '\0';
      p = pattern;
    }
    if(p[0] == '/') {
      if(fnmatch(p+1, path, (1 << 0)) == 0) return 1;
    } else {
      if(fnmatch(p, path, (1 << 0)) == 0) return 1;
      tail = path;
      while(*tail) {
        if(*tail++ == '/') {
          if(fnmatch(p, tail, (1 << 0)) == 0) return 1;
        }
      }
    }
  }
  return 0;
}

canonical_original_code:
int excluded(char **patterns, unsigned long npatterns, char *path, int isdir) {
  unsigned long i; unsigned long l;
  char *p; char *tail;
  char pattern[4096];
  for(i = 0; i < npatterns; ++i) {
    p = patterns[i];
    l = strlen(p);
    if(p[l-1] == '/') {
      if(!isdir) return 0;
      strcpy(pattern, p);
      pattern[--l] = '\0';
      p = pattern;
    }
    if(p[0] == '/') {
      if(fnmatch(p+1, path, (1 << 0)) == 0) return 1;
    } else {
      if(fnmatch(p, path, (1 << 0)) == 0) return 1;
      tail = path;
      while(*tail) {
        if(*tail++ == '/') {
          if(fnmatch(p, tail, (1 << 0)) == 0) return 1;
        }
      }
    }
  }
  return 0;
}

variable_types:
patterns
char **

variable_types:
npatterns
unsigned long

variable_types:
path
char *

variable_types: isdir int

variable_types:
p
char *

variable_types:
tail
char *

variable_types:
pattern
char [4096]


FFDateToUnixTime

repo: ScottWales/fieldsfile

decompiled_code:
void __fastcall FFDateToUnixTime(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, __int64 a9, __int64 a10, __int64 a11, __int64 a12)
{
char *v12; // rbp
struct tm v13; // [rsp+0h] [rbp-58h] BYREF

*(_OWORD *)&v13.tm_wday = 0LL;
*(_OWORD *)&v13.tm_gmtoff = 0LL;
v13.tm_sec = a12;
v13.tm_min = a11;
v13.tm_hour = a10;
v13.tm_mday = a9;
v13.tm_mon = a8 - 1;
v13.tm_year = a7 - 1900;
v12 = getenv("TZ");
setenv("TZ", &value, 1);
tzset();
mktime(&v13);
if ( v12 )
setenv("TZ", v12, 1);
else
unsetenv("TZ");
tzset();
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, __int64 a9, __int64 a10, __int64 a11, __int64 a12)
{
char *v12; // rbp
struct tm v13; // [rsp+0h] [rbp-58h] BYREF

*(_OWORD *)&v13.tm_wday = 0LL;
*(_OWORD *)&v13.tm_gmtoff = 0LL;
v13.tm_sec = a12;
v13.tm_min = a11;
v13.tm_hour = a10;
v13.tm_mday = a9;
v13.tm_mon = a8 - 1;
v13.tm_year = a7 - 1900;
v12 = getenv("TZ");
setenv("TZ", &value, 1);
tzset();
mktime(&v13);
if ( v12 )
setenv("TZ", v12, 1);
else
unsetenv("TZ");
tzset();
}

original_code:
double FFDateToUnixTime(const struct FFDate date){
    struct tm tm = {
        .tm_sec = date.second,
        .tm_min = date.minute,
        .tm_hour = date.hour,
        .tm_mday = date.day,
        .tm_mon = date.month - 1,
        .tm_year = date.year - 1900,
        .tm_isdst = 0,
    };
    char * tz = getenv("TZ");
    setenv("TZ","",1);
    tzset();
    time_t time = mktime(&tm);
    if (tz) setenv("TZ",tz,1);
    else unsetenv("TZ");
    tzset();
    return time;
}

canonical_original_code:
double FFDateToUnixTime(struct FFDate date){
    struct tm tm = {
        .tm_sec = date.second,
        .tm_min = date.minute,
        .tm_hour = date.hour,
        .tm_mday = date.day,
        .tm_mon = date.month - 1,
        .tm_year = date.year - 1900,
        .tm_isdst = 0,
    };
    char *tz = getenv("TZ");
    setenv("TZ","",1);
    tzset();
    long time = mktime(&tm);
    if (tz) setenv("TZ",tz,1);
    else unsetenv("TZ");
    tzset();
    return time;
}

variable_types: struct FFDate { long year; long month; long day; long hour; long minute; long second; }

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:
tz
char *

variable_types: time long

return_type: double


ListAdd

decompiled_code:
void __fastcall ListAdd(double **a1, double a2)
{
double **v2; // rbp
double *i; // rbx
double *v4; // rax

v2 = a1;
for ( i = *a1; i; i = (double *)*((_QWORD *)i + 1) )
{
if ( *i > a2 )
break;
if ( *i == a2 )
return;
v2 = (double **)(i + 1);
}
v4 = (double *)malloc(0x10uLL);
*((_QWORD *)v4 + 1) = i;
*v4 = a2;
*v2 = v4;
}

canonical_decompiled_code:
void __fastcall func0(double **a1, double a2)
{
double **v2; // rbp
double *i; // rbx
double *v4; // rax

v2 = a1;
for ( i = *a1; i; i = (double *)*((_QWORD *)i + 1) )
{
if ( *i > a2 )
break;
if ( *i == a2 )
return;
v2 = (double **)(i + 1);
}
v4 = (double *)malloc(0x10uLL);
*((_QWORD *)v4 + 1) = i;
*v4 = a2;
*v2 = v4;
}

original_code:
void ListAdd(struct list ** list, double value) {
    if (*list == ((void *)0) || value < (*list)->value) {
        struct list * new = malloc(sizeof(**list));
        new->value = value;
        new->next = *list;
        *list = new;
    } else if (value != (*list)->value) {
        ListAdd(&((*list)->next),value);
    }
    return;
}

canonical_original_code:
void ListAdd(struct list **list, double value) {
    if (*list == ((void *)0) || value < (*list)->value) {
        struct list *new = malloc(sizeof(**list));
        new->value = value;
        new->next = *list;
        *list = new;
    } else if (value != (*list)->value) {
        ListAdd(&((*list)->next),value);
    }
    return;
}

variable_types: struct list { double value; struct list *next; } **

variable_types: value double

return_type: void


ListCount

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

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

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

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

original_code:
int ListCount(const struct list * list){
    int count = 0;
    while (list != ((void *)0)){
        count++;
        list = list->next;
    }
    return count;
}

canonical_original_code:
int ListCount(struct list *list){
    int count = 0;
    while (list != ((void *)0)){
        count++;
        list = list->next;
    }
    return count;
}

variable_types: struct list { double value; struct list *next; } *

variable_types: count int


ListToArray

decompiled_code:
char *__fastcall ListToArray(void **a1, __int64 a2)
{
__int64 *v2; // rbx
int v3; // eax
char *result; // rax
__int64 v5; // xmm0_8

v2 = (__int64 *)a2;
v3 = ListCount(a2);
result = (char *)realloc(*a1, 8LL * v3);
*a1 = result;
if ( a2 )
{
do
{
v5 = *v2;
v2 = (__int64 *)v2[1];
result += 8;
*((_QWORD *)result - 1) = v5;
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(void **a1, __int64 a2)
{
__int64 *v2; // rbx
int v3; // eax
char *result; // rax
__int64 v5; // xmm0_8

v2 = (__int64 *)a2;
v3 = func1(a2);
result = (char *)realloc(*a1, 8LL * v3);
*a1 = result;
if ( a2 )
{
do
{
v5 = *v2;
v2 = (__int64 *)v2[1];
result += 8;
*((_QWORD *)result - 1) = v5;
}
while ( v2 );
}
return result;
}

original_code:
void ListToArray(double ** array, const struct list * list){
    *array = realloc(*array,ListCount(list)*sizeof(**array));
    int i=0;
    while (list != ((void *)0)){
        (*array)[i++] = list->value;
        list = list->next;
    }
}

canonical_original_code:
void ListToArray(double **array, struct list *list){
    *array = realloc(*array,ListCount(list)*sizeof(**array));
    int i = 0;
    while (list != ((void *)0)){
        (*array)[i++] = list->value;
        list = list->next;
    }
}

variable_types:
array
double **

variable_types: i int

user_defined_types: struct list { double value; struct list *next; }


ListIndex

decompiled_code:
__int64 __fastcall ListIndex(__int64 a1, double a2)
{
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( a2 != *(double *)a1 )
{
a1 = *(_QWORD *)(a1 + 8);
result = (unsigned int)(result + 1);
if ( !a1 )
return 0xFFFFFFFFLL;
}
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( a2 != *(double *)a1 )
{
a1 = *(_QWORD *)(a1 + 8);
result = (unsigned int)(result + 1);
if ( !a1 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int ListIndex(const struct list * list, double value){
    int i=0;
    while (list != ((void *)0)){
        if (list->value == value) return i;
        ++i;
        list = list->next;
    }
    return -1;
}

canonical_original_code:
int ListIndex(struct list *list, double value){
    int i = 0;
    while (list != ((void *)0)){
        if (list->value == value) return i;
        ++i;
        list = list->next;
    }
    return -1;
}


ListFree

decompiled_code:
void __fastcall ListFree(_QWORD *a1)
{
if ( a1 )
ListFree(a1[1]);
free(a1);
}

canonical_decompiled_code:
void __fastcall func4(_QWORD *a1)
{
if ( a1 )
func4(a1[1]);
free(a1);
}

original_code:
void ListFree(struct list * list){
    if (list){
        ListFree(list->next);
    }
    free(list);
}

canonical_original_code:
void ListFree(struct list *list){
    if (list){
        ListFree(list->next);
    }
    free(list);
}


bintold

decompiled_code:
long double __fastcall bintold(const char *a1)
{
int v1; // eax
int v2; // er12
long double result; // fst7
int v4; // ebx
const char *i; // rbp
bool v6; // cf
char v7; // al

v1 = strlen(a1);
if ( v1 <= 0 )
return 0.0;
v2 = v1 - 1;
result = 0.0;
v4 = v1 - 1;
for ( i = &a1[v1 - 1]; ; --i )
{
while ( 1 )
{
while ( 1 )
{
v7 = *i;
if ( *i != 49 )
break;
--i;
result = result + pow(2.0, (double)(v2 - v4));
v6 = v4-- == 0;
if ( v6 )
return result;
}
if ( v4 != 1 || v7 != 98 )
break;
--i;
v4 = 0;
}
if ( v7 != 48 )
break;
v6 = v4-- == 0;
if ( v6 )
return result;
}
return nan(0LL);
}

canonical_decompiled_code:
long double __fastcall func0(const char *a1)
{
int v1; // eax
int v2; // er12
long double result; // fst7
int v4; // ebx
const char *i; // rbp
bool v6; // cf
char v7; // al

v1 = strlen(a1);
if ( v1 <= 0 )
return 0.0;
v2 = v1 - 1;
result = 0.0;
v4 = v1 - 1;
for ( i = &a1[v1 - 1]; ; --i )
{
while ( 1 )
{
while ( 1 )
{
v7 = *i;
if ( *i != 49 )
break;
--i;
result = result + pow(2.0, (double)(v2 - v4));
v6 = v4-- == 0;
if ( v6 )
return result;
}
if ( v4 != 1 || v7 != 98 )
break;
--i;
v4 = 0;
}
if ( v7 != 48 )
break;
v6 = v4-- == 0;
if ( v6 )
return result;
}
return nan(0LL);
}

original_code:
long double bintold(const char* restrict nptr) {
    long double result = 0;
    const int length = strlen(nptr);
    const int end = length - 1;
    for (int i = 0; i < length; i++) {
        char c = nptr[end - i];
        if (c == '1') {
            result += pow(2, i);
        } else if (!((c == 'b' && (end - i) == 1) || c == '0')) {
            return nan(((void *)0));
        }
    }
    return result;
}

canonical_original_code:
long double bintold(char *nptr) {
    long double result = 0;
    int length = strlen(nptr);
    int end = length - 1;
    for (int i = 0; i < length; i++) {
        char c = nptr[end - i];
        if (c == '1') {
            result += pow(2, i);
        } else if (!((c == 'b' && (end - i) == 1) || c == '0')) {
            return nan(((void *)0));
        }
    }
    return result;
}

variable_types:
nptr
char *

variable_types:
result
long double

variable_types: length int

variable_types: end int

variable_types: c char

return_type: long double


octtold

decompiled_code:
long double __fastcall octtold(const char *a1)
{
int v1; // eax
long double result; // fst7
int v3; // er13
int v4; // ebp
const char *v5; // r12
double v6; // xmm1_8
int v7; // ebx

v1 = strlen(a1);
if ( v1 <= 0 )
return 0.0;
result = 0.0;
v3 = v1;
v4 = 0;
v5 = &a1[v1 - 1];
while ( 1 )
{
v7 = *v5 - 48;
if ( (unsigned int)v7 > 7 )
break;
--v5;
v6 = (double)v4++;
result = result + (double)v7 * pow(8.0, v6);
if ( v3 == v4 )
return result;
}
return nan(0LL);
}

canonical_decompiled_code:
long double __fastcall func1(const char *a1)
{
int v1; // eax
long double result; // fst7
int v3; // er13
int v4; // ebp
const char *v5; // r12
double v6; // xmm1_8
int v7; // ebx

v1 = strlen(a1);
if ( v1 <= 0 )
return 0.0;
result = 0.0;
v3 = v1;
v4 = 0;
v5 = &a1[v1 - 1];
while ( 1 )
{
v7 = *v5 - 48;
if ( (unsigned int)v7 > 7 )
break;
--v5;
v6 = (double)v4++;
result = result + (double)v7 * pow(8.0, v6);
if ( v3 == v4 )
return result;
}
return nan(0LL);
}

original_code:
long double octtold(const char* restrict nptr) {
    long double result = 0;
    const int length = strlen(nptr);
    const int end = length - 1;
    for (int i = 0; i < length; i++) {
        int d = nptr[end - i] - '0';
        if (d >= 0 && d <= 7) {
            result += d * pow(8, i);
        } else {
            return nan(((void *)0));
        }
    }
    return result;
}

canonical_original_code:
long double octtold(char *nptr) {
    long double result = 0;
    int length = strlen(nptr);
    int end = length - 1;
    for (int i = 0; i < length; i++) {
        int d = nptr[end - i] - '0';
        if (d >= 0 && d <= 7) {
            result += d * pow(8, i);
        } else {
            return nan(((void *)0));
        }
    }
    return result;
}

variable_types: d int


hextold

decompiled_code:
long double __fastcall hextold(const char *a1)
{
int v1; // eax
int v2; // ebp
long double result; // fst7
int v4; // ebx
const char *i; // r13
int v6; // er12
char v8; // al

v1 = strlen(a1);
if ( v1 <= 0 )
return 0.0;
v2 = v1 - 1;
result = 0.0;
v4 = v1 - 1;
for ( i = &a1[v1 - 1]; ; --i )
{
while ( 1 )
{
v8 = *i;
if ( v4 != 1 || v8 != 120 )
break;
--i;
v4 = 0;
}
v6 = (char)(v8 - 48);
if ( (unsigned __int8)(v8 - 48) <= 9u )
goto LABEL_4;
if ( (unsigned __int8)(v8 - 65) > 5u )
break;
v6 = (char)(v8 - 55);
LABEL_4:
result = result + (double)v6 * pow(16.0, (double)(v2 - v4));
if ( v4-- == 0 )
return result;
}
if ( (unsigned __int8)(v8 - 97) <= 5u )
{
v6 = (char)(v8 - 87);
goto LABEL_4;
}
return nan(0LL);
}

canonical_decompiled_code:
long double __fastcall func2(const char *a1)
{
int v1; // eax
int v2; // ebp
long double result; // fst7
int v4; // ebx
const char *i; // r13
int v6; // er12
char v8; // al

v1 = strlen(a1);
if ( v1 <= 0 )
return 0.0;
v2 = v1 - 1;
result = 0.0;
v4 = v1 - 1;
for ( i = &a1[v1 - 1]; ; --i )
{
while ( 1 )
{
v8 = *i;
if ( v4 != 1 || v8 != 120 )
break;
--i;
v4 = 0;
}
v6 = (char)(v8 - 48);
if ( (unsigned __int8)(v8 - 48) <= 9u )
goto LABEL_4;
if ( (unsigned __int8)(v8 - 65) > 5u )
break;
v6 = (char)(v8 - 55);
LABEL_4:
result = result + (double)v6 * pow(16.0, (double)(v2 - v4));
if ( v4-- == 0 )
return result;
}
if ( (unsigned __int8)(v8 - 97) <= 5u )
{
v6 = (char)(v8 - 87);
goto LABEL_4;
}
return nan(0LL);
}

original_code:
long double hextold(const char* restrict nptr) {
    long double result = 0;
    const int length = strlen(nptr);
    const int end = length -1;
    for (int i = 0; i < length; i++) {
        char c = nptr[end - i];
        int d = 0;
        if (c == 'x' && (end - i) == 1) continue;
        if (c >= '0' && c <= '9') {
            d = c - '0';
        } else if (c >= 'A' && c <= 'F') {
            d = 10 + c - 'A';
        } else if (c >= 'a' && c <= 'f') {
            d = 10 + c - 'a';
        } else {
            return nan(((void *)0));
        }
        result += d * pow(16, i);
    }
    return result;
}

canonical_original_code:
long double hextold(char *nptr) {
    long double result = 0;
    int length = strlen(nptr);
    int end = length -1;
    for (int i = 0; i < length; i++) {
        char c = nptr[end - i];
        int d = 0;
        if (c == 'x' && (end - i) == 1) continue;
        if (c >= '0' && c <= '9') {
            d = c - '0';
        } else if (c >= 'A' && c <= 'F') {
            d = 10 + c - 'A';
        } else if (c >= 'a' && c <= 'f') {
            d = 10 + c - 'a';
        } else {
            return nan(((void *)0));
        }
        result += d * pow(16, i);
    }
    return result;
}


decompiled_code:
__int64 __fastcall yysyntax_error(unsigned __int64 *a1, const char **a2, __int16 *a3, int a4)
{
char *v6; // r15
_BYTE *v7; // rax
_BYTE *v8; // r14
__int64 v9; // rax
int v10; // eax
__int64 v11; // rbx
int v12; // er12
__int64 v13; // rbp
__int64 v14; // r13
char *v15; // rsi
_BYTE *v16; // rax
bool v17; // cf
__int64 v18; // rax
const char *v19; // rbx
unsigned __int64 v20; // rax
__int64 v21; // rcx
char *v22; // r12
char v23; // al
char v24; // dl
int v25; // er13
_BYTE *v26; // rax
__int64 result; // rax
_BYTE *v28; // [rsp+8h] [rbp-80h]
__int64 v30[13]; // [rsp+20h] [rbp-68h]

v6 = yytname[a4];
v7 = yytnamerr(0LL, v6);
v28 = v7;
if ( a4 == -2 )
{
v18 = 12LL;
LODWORD(v13) = 0;
v19 = "syntax error";
}
else
{
v8 = v7;
v9 = *a3;
v30[0] = (__int64)v6;
v10 = yypact[v9];
if ( (_BYTE)v10 == 0xF1 )
{
LABEL_16:
v18 = 27LL;
LODWORD(v13) = 1;
v19 = "syntax error, unexpected %s";
}
else
{
LODWORD(v11) = -v10;
if ( v10 >= 0 )
LODWORD(v11) = 0;
v12 = 125 - v10;
if ( 125 - v10 > 23 )
v12 = 23;
if ( (int)v11 >= v12 )
{
v8 = v28;
LABEL_38:
v28 = v8;
v18 = 27LL;
LODWORD(v13) = 1;
v19 = "syntax error, unexpected %s";
}
else
{
v11 = (int)v11;
v13 = 1LL;
v14 = (char)v10;
do
{
while ( yycheck[v14 + v11] != (_DWORD)v11 || (_DWORD)v11 == 1 )
{
if ( v12 <= (int)++v11 )
goto LABEL_15;
}
if ( (_DWORD)v13 == 5 )
goto LABEL_16;
v15 = yytname[v11];
v30[v13] = (__int64)v15;
v16 = yytnamerr(0LL, v15);
v17 = __CFADD__(v8, v16);
v8 = &v16[(_QWORD)v8];
if ( v17 )
return 2LL;
++v11;
v13 = (int)v13 + 1;
}
while ( v12 > (int)v11 );
LABEL_15:
switch ( (int)v13 )
{
case 1:
goto LABEL_38;
case 2:
v28 = v8;
v18 = 41LL;
v19 = "syntax error, unexpected %s, expecting %s";
break;
case 3:
v28 = v8;
v18 = 47LL;
v19 = "syntax error, unexpected %s, expecting %s or %s";
break;
case 4:
v28 = v8;
v18 = 53LL;
v19 = "syntax error, unexpected %s, expecting %s or %s or %s";
break;
case 5:
v28 = v8;
v18 = 59LL;
v19 = "syntax error, unexpected %s, expecting %s or %s or %s or %s";
break;
default:
v28 = v8;
v18 = 12LL;
v19 = "syntax error";
break;
}
}
}
}
v17 = __CFADD__(v28, v18);
v20 = (unsigned __int64)&v28[v18];
if ( v17 )
return 2LL;
if ( *a1 < v20 )
{
if ( 2 * v20 >= v20 )
*a1 = 2 * v20;
else
*a1 = -1LL;
result = 1LL;
}
else
{
v21 = 0LL;
v22 = (char *)*a2;
v23 = *v19;
for ( **a2 = *v19; v23; *v22 = *v19 )
{
while ( 1 )
{
v24 = v19[1];
if ( v23 == 37 && v24 == 115 && (int)v13 > (int)v21 )
break;
++v22;
v23 = *++v19;
*v22 = v24;
if ( !v24 )
goto LABEL_26;
}
v25 = v21 + 1;
v19 += 2;
v26 = yytnamerr(v22, (char *)v30[v21]);
v21 = v25;
v22 = &v22[(_QWORD)v26];
v23 = *v19;
}
LABEL_26:
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 *a1, const char **a2, __int16 *a3, int a4)
{
char *v6; // r15
_BYTE *v7; // rax
_BYTE *v8; // r14
__int64 v9; // rax
int v10; // eax
__int64 v11; // rbx
int v12; // er12
__int64 v13; // rbp
__int64 v14; // r13
char *v15; // rsi
_BYTE *v16; // rax
bool v17; // cf
__int64 v18; // rax
const char *v19; // rbx
unsigned __int64 v20; // rax
__int64 v21; // rcx
char *v22; // r12
char v23; // al
char v24; // dl
int v25; // er13
_BYTE *v26; // rax
__int64 result; // rax
_BYTE *v28; // [rsp+8h] [rbp-80h]
__int64 v30[13]; // [rsp+20h] [rbp-68h]

v6 = yytname[a4];
v7 = yytnamerr(0LL, v6);
v28 = v7;
if ( a4 == -2 )
{
v18 = 12LL;
LODWORD(v13) = 0;
v19 = "syntax error";
}
else
{
v8 = v7;
v9 = *a3;
v30[0] = (__int64)v6;
v10 = yypact[v9];
if ( (_BYTE)v10 == 0xF1 )
{
LABEL_16:
v18 = 27LL;
LODWORD(v13) = 1;
v19 = "syntax error, unexpected %s";
}
else
{
LODWORD(v11) = -v10;
if ( v10 >= 0 )
LODWORD(v11) = 0;
v12 = 125 - v10;
if ( 125 - v10 > 23 )
v12 = 23;
if ( (int)v11 >= v12 )
{
v8 = v28;
LABEL_38:
v28 = v8;
v18 = 27LL;
LODWORD(v13) = 1;
v19 = "syntax error, unexpected %s";
}
else
{
v11 = (int)v11;
v13 = 1LL;
v14 = (char)v10;
do
{
while ( yycheck[v14 + v11] != (_DWORD)v11 || (_DWORD)v11 == 1 )
{
if ( v12 <= (int)++v11 )
goto LABEL_15;
}
if ( (_DWORD)v13 == 5 )
goto LABEL_16;
v15 = yytname[v11];
v30[v13] = (__int64)v15;
v16 = yytnamerr(0LL, v15);
v17 = __CFADD__(v8, v16);
v8 = &v16[(_QWORD)v8];
if ( v17 )
return 2LL;
++v11;
v13 = (int)v13 + 1;
}
while ( v12 > (int)v11 );
LABEL_15:
switch ( (int)v13 )
{
case 1:
goto LABEL_38;
case 2:
v28 = v8;
v18 = 41LL;
v19 = "syntax error, unexpected %s, expecting %s";
break;
case 3:
v28 = v8;
v18 = 47LL;
v19 = "syntax error, unexpected %s, expecting %s or %s";
break;
case 4:
v28 = v8;
v18 = 53LL;
v19 = "syntax error, unexpected %s, expecting %s or %s or %s";
break;
case 5:
v28 = v8;
v18 = 59LL;
v19 = "syntax error, unexpected %s, expecting %s or %s or %s or %s";
break;
default:
v28 = v8;
v18 = 12LL;
v19 = "syntax error";
break;
}
}
}
}
v17 = __CFADD__(v28, v18);
v20 = (unsigned __int64)&v28[v18];
if ( v17 )
return 2LL;
if ( *a1 < v20 )
{
if ( 2 * v20 >= v20 )
*a1 = 2 * v20;
else
*a1 = -1LL;
result = 1LL;
}
else
{
v21 = 0LL;
v22 = (char *)*a2;
v23 = *v19;
for ( **a2 = *v19; v23; *v22 = *v19 )
{
while ( 1 )
{
v24 = v19[1];
if ( v23 == 37 && v24 == 115 && (int)v13 > (int)v21 )
break;
++v22;
v23 = *++v19;
*v22 = v24;
if ( !v24 )
goto LABEL_26;
}
v25 = v21 + 1;
v19 += 2;
v26 = yytnamerr(v22, (char *)v30[v21]);
v21 = v25;
v22 = &v22[(_QWORD)v26];
v23 = *v19;
}
LABEL_26:
result = 0LL;
}
return result;
}

original_code:
static int
yysyntax_error (long unsigned int *yymsg_alloc, char **yymsg,
                yytype_int16 *yyssp, int yytoken)
{
  long unsigned int yysize0 = yytnamerr (((void*)0), yytname[yytoken]);
  long unsigned int yysize = yysize0;
  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  const char *yyformat = ((void*)0);
  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  int yycount = 0;
  if (yytoken != (-2))
    {
      int yyn = yypact[*yyssp];
      yyarg[yycount++] = yytname[yytoken];
      if (!(!!((yyn) == (-15))))
        {
          int yyxbegin = yyn < 0 ? -yyn : 0;
          int yychecklim = 124 - yyn + 1;
          int yyxend = yychecklim < 23 ? yychecklim : 23;
          int yyx;
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
            if (yycheck[yyx + yyn] == yyx && yyx != 1
                && !0)
              {
                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
                  {
                    yycount = 1;
                    yysize = yysize0;
                    break;
                  }
                yyarg[yycount++] = yytname[yyx];
                {
                  long unsigned int yysize1 = yysize + yytnamerr (((void*)0), yytname[yyx]);
                  if (yysize <= yysize1 && yysize1 <= ((long unsigned int) -1))
                    yysize = yysize1;
                  else
                    return 2;
                }
              }
        }
    }
  switch (yycount)
    {
    default:
      case 0: yyformat = "syntax error"; break;
      case 1: yyformat = "syntax error, unexpected %s"; break;
      case 2: yyformat = "syntax error, unexpected %s, expecting %s"; break;
      case 3: yyformat = "syntax error, unexpected %s, expecting %s or %s"; break;
      case 4: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s"; break;
      case 5: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s or %s"; break;
    }
  {
    long unsigned int yysize1 = yysize + strlen (yyformat);
    if (yysize <= yysize1 && yysize1 <= ((long unsigned int) -1))
      yysize = yysize1;
    else
      return 2;
  }
  if (*yymsg_alloc < yysize)
    {
      *yymsg_alloc = 2 * yysize;
      if (! (yysize <= *yymsg_alloc
             && *yymsg_alloc <= ((long unsigned int) -1)))
        *yymsg_alloc = ((long unsigned int) -1);
      return 1;
    }
  {
    char *yyp = *yymsg;
    int yyi = 0;
    while ((*yyp = *yyformat) != '\0')
      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
        {
          yyp += yytnamerr (yyp, yyarg[yyi++]);
          yyformat += 2;
        }
      else
        {
          yyp++;
          yyformat++;
        }
  }
  return 0;
}

canonical_original_code:
static int yysyntax_error(unsigned long *yymsg_alloc, char **yymsg, short *yyssp, int yytoken)
{
  unsigned long yysize0 = yytnamerr (((void*)0), yytname[yytoken]);
  unsigned long yysize = yysize0;
  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  char *yyformat = ((void*)0);
  char *yyarg[-1];
  int yycount = 0;
  if (yytoken != (-2))
    {
      int yyn = yypact[*yyssp];
      yyarg[yycount++] = yytname[yytoken];
      if (!(!!((yyn) == (-15))))
        {
          int yyxbegin = yyn < 0 ? -yyn : 0;
          int yychecklim = 124 - yyn + 1;
          int yyxend = yychecklim < 23 ? yychecklim : 23;
          int yyx;
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
            if (yycheck[yyx + yyn] == yyx && yyx != 1
                && !0)
              {
                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
                  {
                    yycount = 1;
                    yysize = yysize0;
                    break;
                  }
                yyarg[yycount++] = yytname[yyx];
                {
                  unsigned long yysize1 = yysize + yytnamerr (((void*)0), yytname[yyx]);
                  if (yysize <= yysize1 && yysize1 <= ((unsigned long) -1))
                    yysize = yysize1;
                  else
                    return 2;
                }
              }
        }
    }
  switch (yycount)
    {
    default:
      case 0: yyformat = "syntax error"; break;
      case 1: yyformat = "syntax error, unexpected %s"; break;
      case 2: yyformat = "syntax error, unexpected %s, expecting %s"; break;
      case 3: yyformat = "syntax error, unexpected %s, expecting %s or %s"; break;
      case 4: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s"; break;
      case 5: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s or %s"; break;
    }
  {
    unsigned long yysize1 = yysize + strlen (yyformat);
    if (yysize <= yysize1 && yysize1 <= ((unsigned long) -1))
      yysize = yysize1;
    else
      return 2;
  }
  if (*yymsg_alloc < yysize)
    {
      *yymsg_alloc = 2 * yysize;
      if (! (yysize <= *yymsg_alloc
             && *yymsg_alloc <= ((unsigned long) -1)))
        *yymsg_alloc = ((unsigned long) -1);
      return 1;
    }
  {
    char *yyp = *yymsg;
    int yyi = 0;
    while ((*yyp = *yyformat) != '\0')
      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
        {
          yyp += yytnamerr (yyp, yyarg[yyi++]);
          yyformat += 2;
        }
      else
        {
          yyp++;
          yyformat++;
        }
  }
  return 0;
}

variable_types:
yymsg
char **

variable_types:
yyssp
short *

variable_types: yytoken int

variable_types:
yysize
unsigned long

variable_types:
yyformat
char *

variable_types:
yyarg
char *[-1]

variable_types: yycount int

variable_types: yyn int

variable_types: yyxbegin int

variable_types: yychecklim int

variable_types: yyxend int

variable_types: yyx int

variable_types:
yyp
char *

variable_types: yyi int