decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

parse_scanpara(argc, argv, &info);
signal(2, (__sighandler_t)sig_int);
if ( pthread_create(newthread, 0LL, (void *(*)(void *))&receiver, &info) )
{
perror("pthread_create error");
exit(-1);
}
if ( pthread_detach(newthread[0]) )
{
perror("pthread_detach error");
exit(-1);
}
sender(&info);
show_result();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

parse_scanpara(argc, argv, &info);
signal(2, (__sighandler_t)sig_int);
if ( pthread_create(newthread, 0LL, (void *(*)(void *))&receiver, &info) )
{
perror("pthread_create error");
exit(-1);
}
if ( pthread_detach(newthread[0]) )
{
perror("pthread_detach error");
exit(-1);
}
sender(&info);
func0();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 pthread_t rid;
 parse_scanpara(argc, argv, &info);
 if (signal(2, sig_int) < 0) {
  perror("signal error");
  exit(-1);
 }
 if (pthread_create(&rid, ((void *)0), receiver, &info) != 0) {
  perror("pthread_create error");
  exit(-1);
 }
 if (pthread_detach(rid) != 0) {
  perror("pthread_detach error");
  exit(-1);
 }
 sender(&info);
 show_result();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long rid;
 parse_scanpara(argc, argv, &info);
 if (signal(2, sig_int) < 0) {
  perror("signal error");
  exit(-1);
 }
 if (pthread_create(&rid, ((void *)0), receiver, &info) != 0) {
  perror("pthread_create error");
  exit(-1);
 }
 if (pthread_detach(rid) != 0) {
  perror("pthread_detach error");
  exit(-1);
 }
 sender(&info);
 show_result();
 return 0;
}

variable_types: argc int

variable_types:
rid
unsigned long


repo: wikimedia/analytics-kafkatee

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

for ( result = child_procs; result; result = *(_QWORD *)result )
{
if ( *(_DWORD *)(result + 16) == a1 )
break;
}
return result;
}

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

for ( result = child_procs; result; result = *(_QWORD *)result )
{
if ( *(_DWORD *)(result + 16) == a1 )
break;
}
return result;
}

original_code:
static struct child_proc *child_proc_find (pid_t pid) {
 struct child_proc *cp;
 for ((cp) = ((&child_procs)->lh_first); (cp); (cp) = ((cp)->link.le_next))
  if (cp->pid == pid)
   return cp;
 return ((void *)0);
}

canonical_original_code:
static struct child_proc *child_proc_find(int pid) {
 struct child_proc *cp;
 for ((cp) = ((&child_procs)->lh_first); (cp); (cp) = ((cp)->link.le_next))
  if (cp->pid == pid)
   return cp;
 return ((void *)0);
}

variable_types: pid int

variable_types: struct child_proc { struct { struct child_proc *le_next; struct child_proc **le_prev; } link; int pid; char *cmd; long t_start; int *statusp; } *


sigchld

decompiled_code:
void sigchld()
{
_InterlockedExchange(&do_child_proc_reap, 1);
}

canonical_decompiled_code:
void func2()
{
_InterlockedExchange(&do_child_proc_reap, 1);
}

original_code:
static void sigchld (int sig) {
 __sync_lock_test_and_set(&do_child_proc_reap,1);
}

canonical_original_code:
static void sigchld(int sig) {
 __sync_lock_test_and_set(&do_child_proc_reap,1);
}

variable_types: sig int

return_type: void


decompiled_code:
void __fastcall child_proc_del(void *ptr)
{
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
**((_QWORD **)ptr + 1) = *(_QWORD *)ptr;
free(*((void **)ptr + 3));
free(ptr);
_InterlockedSub(&child_proc_cnt, 1u);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
**((_QWORD **)ptr + 1) = *(_QWORD *)ptr;
free(*((void **)ptr + 3));
free(ptr);
_InterlockedSub(&child_proc_cnt, 1u);
}

original_code:
static void child_proc_del (struct child_proc *cp) {
 do { if ((cp)->link.le_next != ((void *)0)) (cp)->link.le_next->link.le_prev = (cp)->link.le_prev; *(cp)->link.le_prev = (cp)->link.le_next; } while ( 0);
 free(cp->cmd);
 free(cp);
 __sync_sub_and_fetch(&child_proc_cnt,1);
}

canonical_original_code:
static void child_proc_del(struct child_proc *cp) {
 do { if ((cp)->link.le_next != ((void *)0)) (cp)->link.le_next->link.le_prev = (cp)->link.le_prev; *(cp)->link.le_prev = (cp)->link.le_next; } while ( 0);
 free(cp->cmd);
 free(cp);
 __sync_sub_and_fetch(&child_proc_cnt,1);
}

user_defined_types: struct child_proc { struct { struct child_proc *le_next; struct child_proc **le_prev; } link; int pid; char *cmd; long t_start; int *statusp; }


decompiled_code:
__int64 __fastcall kt_popen(char *s, _BYTE *a2, int *a3, _DWORD *a4, char *a5, size_t a6)
{
int v10; // eax
unsigned int v11; // ebx
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
__pid_t v17; // eax
__int64 v18; // rcx
struct sigaction *v19; // rdi
int i; // ebx
struct sigaction v22; // [rsp+10h] [rbp-D8h] BYREF
int pipedes[2]; // [rsp+A8h] [rbp-40h] BYREF

if ( pipe2(pipedes, 0x80000) == -1 )
{
v11 = -1;
v13 = _errno_location();
v14 = strerror(*v13);
snprintf(a5, a6, "pipe failed: %s", v14);
}
else
{
pthread_mutex_lock(&child_proc_lock);
v10 = fork();
v11 = v10;
if ( v10 == -1 )
{
pthread_mutex_unlock(&child_proc_lock);
v15 = _errno_location();
v16 = strerror(*v15);
snprintf(a5, a6, "fork failed: %s", v16);
close(pipedes[0]);
close(pipedes[1]);
}
else
{
if ( !v10 )
{
pthread_mutex_unlock(&child_proc_lock);
v17 = getpid();
setpgid(0, v17);
if ( *a2 == 119 )
{
close(pipedes[1]);
if ( pipedes[0] )
{
dup2(pipedes[0], 0);
close(pipedes[0]);
}
}
else
{
close(pipedes[0]);
if ( pipedes[1] != 1 )
{
dup2(pipedes[1], 1);
close(pipedes[1]);
}
}
v18 = 38LL;
v19 = &v22;
while ( v18 )
{
LODWORD(v19->sa_handler) = 0;
v19 = (struct sigaction *)((char *)v19 + 4);
--v18;
}
sigemptyset(&v22.sa_mask);
for ( i = 1; i != 65; ++i )
sigaction(i, &v22, 0LL);
ezd_thread_sigmask(1LL, 0LL, 0xFFFFFFFFLL);
execl("/bin/sh", "sh", "-c", s, 0LL);
exit(127);
}
*a3 = v10;
child_proc_add(s, v10, a4);
pthread_mutex_unlock(&child_proc_lock);
if ( *a2 == 119 )
{
close(pipedes[0]);
v11 = pipedes[1];
}
else
{
close(pipedes[1]);
v11 = pipedes[0];
}
}
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s, _BYTE *a2, int *a3, _DWORD *a4, char *a5, size_t a6)
{
int v10; // eax
unsigned int v11; // ebx
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
__pid_t v17; // eax
__int64 v18; // rcx
struct sigaction *v19; // rdi
int i; // ebx
struct sigaction v22; // [rsp+10h] [rbp-D8h] BYREF
int pipedes[2]; // [rsp+A8h] [rbp-40h] BYREF

if ( pipe2(pipedes, 0x80000) == -1 )
{
v11 = -1;
v13 = _errno_location();
v14 = strerror(*v13);
snprintf(a5, a6, "pipe failed: %s", v14);
}
else
{
pthread_mutex_lock(&child_proc_lock);
v10 = fork();
v11 = v10;
if ( v10 == -1 )
{
pthread_mutex_unlock(&child_proc_lock);
v15 = _errno_location();
v16 = strerror(*v15);
snprintf(a5, a6, "fork failed: %s", v16);
close(pipedes[0]);
close(pipedes[1]);
}
else
{
if ( !v10 )
{
pthread_mutex_unlock(&child_proc_lock);
v17 = getpid();
setpgid(0, v17);
if ( *a2 == 119 )
{
close(pipedes[1]);
if ( pipedes[0] )
{
dup2(pipedes[0], 0);
close(pipedes[0]);
}
}
else
{
close(pipedes[0]);
if ( pipedes[1] != 1 )
{
dup2(pipedes[1], 1);
close(pipedes[1]);
}
}
v18 = 38LL;
v19 = &v22;
while ( v18 )
{
LODWORD(v19->sa_handler) = 0;
v19 = (struct sigaction *)((char *)v19 + 4);
--v18;
}
sigemptyset(&v22.sa_mask);
for ( i = 1; i != 65; ++i )
sigaction(i, &v22, 0LL);
ezd_thread_sigmask(1LL, 0LL, 0xFFFFFFFFLL);
execl("/bin/sh", "sh", "-c", s, 0LL);
exit(127);
}
*a3 = v10;
func1(s, v10, a4);
pthread_mutex_unlock(&child_proc_lock);
if ( *a2 == 119 )
{
close(pipedes[0]);
v11 = pipedes[1];
}
else
{
close(pipedes[1]);
v11 = pipedes[0];
}
}
}
return v11;
}

original_code:
int kt_popen (const char *cmdstring, const char *rw,
       pid_t *pidp, int *statusp,
       char *errstr, size_t errstr_size) {
 int pfd[2], i;
 pid_t pid;
 struct sigaction sig_action;
 if (pipe2(pfd, 02000000) == -1) {
  snprintf(errstr, errstr_size,
    "pipe failed: %s", strerror((*__errno_location ())));
  return -1;
 }
 pthread_mutex_lock(&child_proc_lock);
 if ((pid = fork()) == -1) {
  pthread_mutex_unlock(&child_proc_lock);
  snprintf(errstr, errstr_size,
    "fork failed: %s", strerror((*__errno_location ())));
  close(pfd[0]);
  close(pfd[1]);
  return -1;
 }
 if (pid != 0) {
  *pidp = pid;
  child_proc_add(cmdstring, pid, statusp);
  pthread_mutex_unlock(&child_proc_lock);
  if (*rw == 'w') {
   close(pfd[0]);
   return pfd[1];
  } else {
   close(pfd[1]);
   return pfd[0];
  }
 }
 pthread_mutex_unlock(&child_proc_lock);
 setpgid(0, getpid());
 if (*rw == 'w') {
  close(pfd[1]);
  if (pfd[0] != 0) {
   dup2(pfd[0], 0);
   close(pfd[0]);
  }
 } else {
  close(pfd[0]);
  if (pfd[1] != 1) {
   dup2(pfd[1], 1);
   close(pfd[1]);
  }
 }
 memset(&sig_action, 0, sizeof(sig_action));
 sig_action.__sigaction_handler.sa_handler = ((__sighandler_t) 0);
 sig_action.sa_flags = 0;
 sigemptyset(&sig_action.sa_mask);
 for (i = 1 ; i < (64 + 1) ; i++) {
  sigaction(i, &sig_action, ((void *)0));
 }
 ezd_thread_sigmask(1, 0, -1);
 execl("/bin/sh", "sh", "-c", cmdstring, ((void *)0));
 _exit(127);
}

canonical_original_code:
int kt_popen(char *cmdstring, char *rw, int *pidp, int *statusp, char *errstr, unsigned long errstr_size) {
 int pfd[2]; int i;
 int pid;
 struct sigaction sig_action;
 if (pipe2(pfd, 02000000) == -1) {
  snprintf(errstr, errstr_size,
    "pipe failed: %s", strerror((*__errno_location ())));
  return -1;
 }
 pthread_mutex_lock(&child_proc_lock);
 if ((pid = fork()) == -1) {
  pthread_mutex_unlock(&child_proc_lock);
  snprintf(errstr, errstr_size,
    "fork failed: %s", strerror((*__errno_location ())));
  close(pfd[0]);
  close(pfd[1]);
  return -1;
 }
 if (pid != 0) {
  *pidp = pid;
  child_proc_add(cmdstring, pid, statusp);
  pthread_mutex_unlock(&child_proc_lock);
  if (*rw == 'w') {
   close(pfd[0]);
   return pfd[1];
  } else {
   close(pfd[1]);
   return pfd[0];
  }
 }
 pthread_mutex_unlock(&child_proc_lock);
 setpgid(0, getpid());
 if (*rw == 'w') {
  close(pfd[1]);
  if (pfd[0] != 0) {
   dup2(pfd[0], 0);
   close(pfd[0]);
  }
 } else {
  close(pfd[0]);
  if (pfd[1] != 1) {
   dup2(pfd[1], 1);
   close(pfd[1]);
  }
 }
 memset(&sig_action, 0, sizeof(sig_action));
 sig_action.__sigaction_handler.sa_handler = ((void (*)(int)) 0);
 sig_action.sa_flags = 0;
 sigemptyset(&sig_action.sa_mask);
 for (i = 1 ; i < (64 + 1) ; i++) {
  sigaction(i, &sig_action, ((void *)0));
 }
 ezd_thread_sigmask(1, 0, -1);
 execl("/bin/sh", "sh", "-c", cmdstring, ((void *)0));
 _exit(127);
}

variable_types:
cmdstring
char *

variable_types:
rw
char *

variable_types:
pidp
int *

variable_types:
statusp
int *

variable_types:
errstr
char *

variable_types:
pfd
int [2]

variable_types: i int

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

return_type: int

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

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


decompiled_code:
char *__fastcall exec_exitstatus(unsigned int a1)
{
if ( (a1 & 0x7F) != 0 )
{
if ( __OFSUB__((a1 & 0x7F) + 1, 1) || (a1 & 0x7F) == 0 )
{
snprintf((char *)&ret_0 + __readfsqword(0), 0x80uLL, "exited with code %i", a1);
}
else if ( (a1 & 0x80u) == 0 )
{
snprintf((char *)&ret_0 + __readfsqword(0), 0x80uLL, "terminated by signal %i", a1 & 0x7F);
}
else
{
strcpy((char *)&ret_0, "core dumped");
}
}
else if ( BYTE1(a1) == 127 )
{
strcpy((char *)&ret_0, "could not execute command");
}
else
{
snprintf((char *)&ret_0 + __readfsqword(0), 0x80uLL, "exited with status %i", BYTE1(a1));
}
return (char *)&ret_0 + __readfsqword(0);
}

canonical_decompiled_code:
char *__fastcall func5(unsigned int a1)
{
if ( (a1 & 0x7F) != 0 )
{
if ( __OFSUB__((a1 & 0x7F) + 1, 1) || (a1 & 0x7F) == 0 )
{
snprintf((char *)&ret_0 + __readfsqword(0), 0x80uLL, "exited with code %i", a1);
}
else if ( (a1 & 0x80u) == 0 )
{
snprintf((char *)&ret_0 + __readfsqword(0), 0x80uLL, "terminated by signal %i", a1 & 0x7F);
}
else
{
strcpy((char *)&ret_0, "core dumped");
}
}
else if ( BYTE1(a1) == 127 )
{
strcpy((char *)&ret_0, "could not execute command");
}
else
{
snprintf((char *)&ret_0 + __readfsqword(0), 0x80uLL, "exited with status %i", BYTE1(a1));
}
return (char *)&ret_0 + __readfsqword(0);
}

original_code:
const char *exec_exitstatus (int status) {
 static __thread char ret[128];
 if ((((status) & 0x7f) == 0)) {
  if ((((status) & 0xff00) >> 8) == 127)
   snprintf(ret, sizeof(ret),
     "could not execute command");
  else
   snprintf(ret, sizeof(ret), "exited with status %i",
     (((status) & 0xff00) >> 8));
 } else if ((((signed char) (((status) & 0x7f) + 1) >> 1) > 0)) {
  if (((status) & 0x80))
   snprintf(ret, sizeof(ret), "core dumped");
  else
   snprintf(ret, sizeof(ret), "terminated by signal %i",
     ((status) & 0x7f));
 } else
  snprintf(ret, sizeof(ret), "exited with code %i", status);
 return ret;
}

canonical_original_code:
char *exec_exitstatus(int status) {
 static __thread char ret[128];
 if ((((status) & 0x7f) == 0)) {
  if ((((status) & 0xff00) >> 8) == 127)
   snprintf(ret, sizeof(ret),
     "could not execute command");
  else
   snprintf(ret, sizeof(ret), "exited with status %i",
     (((status) & 0xff00) >> 8));
 } else if ((((char) (((status) & 0x7f) + 1) >> 1) > 0)) {
  if (((status) & 0x80))
   snprintf(ret, sizeof(ret), "core dumped");
  else
   snprintf(ret, sizeof(ret), "terminated by signal %i",
     ((status) & 0x7f));
 } else
  snprintf(ret, sizeof(ret), "exited with code %i", status);
 return ret;
}

variable_types: status int

variable_types:
ret
char [128]

return_type: char *


decompiled_code:
int child_proc_reap()
{
int v0; // eax
unsigned int v1; // ebp
__int64 v2; // rbx
unsigned int v3; // er12
char *v4; // rax
char *v5; // rax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

_InterlockedExchange(&do_child_proc_reap, 0);
pthread_mutex_lock(&child_proc_lock);
while ( 1 )
{
v0 = waitpid(-1, stat_loc, 1);
v1 = v0;
if ( v0 <= 0 )
break;
v2 = child_proc_find(v0);
if ( v2 )
{
v3 = time(0LL) - *(_DWORD *)(v2 + 32);
v4 = exec_exitstatus(stat_loc[0]);
syslog(6, "Child process \"%s\" (%i) %s: ran for %i seconds", *(const char **)(v2 + 24), v1, v4, v3);
_InterlockedExchange(*(volatile __int32 **)(v2 + 40), stat_loc[0]);
child_proc_del((void *)v2);
}
else
{
v5 = exec_exitstatus(stat_loc[0]);
syslog(4, "Unknown child process (%i) %s", v1, v5);
}
}
return pthread_mutex_unlock(&child_proc_lock);
}

canonical_decompiled_code:
int func6()
{
int v0; // eax
unsigned int v1; // ebp
__int64 v2; // rbx
unsigned int v3; // er12
char *v4; // rax
char *v5; // rax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

_InterlockedExchange(&do_child_proc_reap, 0);
pthread_mutex_lock(&child_proc_lock);
while ( 1 )
{
v0 = waitpid(-1, stat_loc, 1);
v1 = v0;
if ( v0 <= 0 )
break;
v2 = func0(v0);
if ( v2 )
{
v3 = time(0LL) - *(_DWORD *)(v2 + 32);
v4 = func5(stat_loc[0]);
syslog(6, "Child process \"%s\" (%i) %s: ran for %i seconds", *(const char **)(v2 + 24), v1, v4, v3);
_InterlockedExchange(*(volatile __int32 **)(v2 + 40), stat_loc[0]);
func3((void *)v2);
}
else
{
v5 = func5(stat_loc[0]);
syslog(4, "Unknown child process (%i) %s", v1, v5);
}
}
return pthread_mutex_unlock(&child_proc_lock);
}

original_code:
static void child_proc_reap (void) {
 pid_t pid;
 int st;
 __sync_lock_test_and_set(&do_child_proc_reap,0);
 pthread_mutex_lock(&child_proc_lock);
 while ((pid = waitpid(-1, &st, 1)) > 0) {
  struct child_proc *cp;
  cp = child_proc_find(pid);
  if (__builtin_expect((cp != ((void *)0)),1))
   syslog(6, "Child process \"%s\" (%i) %s: " "ran for %i seconds", cp->cmd, pid, exec_exitstatus(st), (int)(time(((void *)0)) - cp->t_start));
  else
   syslog(4, "Unknown child process (%i) %s", pid, exec_exitstatus(st));
  if (!cp)
   continue;
  __sync_lock_test_and_set(cp->statusp,st);
  child_proc_del(cp);
 }
 pthread_mutex_unlock(&child_proc_lock);
}

canonical_original_code:
static void child_proc_reap() {
 int pid;
 int st;
 __sync_lock_test_and_set(&do_child_proc_reap,0);
 pthread_mutex_lock(&child_proc_lock);
 while ((pid = waitpid(-1, &st, 1)) > 0) {
  struct child_proc *cp;
  cp = child_proc_find(pid);
  if (__builtin_expect((cp != ((void *)0)),1))
   syslog(6, "Child process \"%s\" (%i) %s: " "ran for %i seconds", cp->cmd, pid, exec_exitstatus(st), (int)(time(((void *)0)) - cp->t_start));
  else
   syslog(4, "Unknown child process (%i) %s", pid, exec_exitstatus(st));
  if (!cp)
   continue;
  __sync_lock_test_and_set(cp->statusp,st);
  child_proc_del(cp);
 }
 pthread_mutex_unlock(&child_proc_lock);
}

variable_types: st int


decompiled_code:
void *__fastcall exec_main(void *a1)
{
time_t v1; // rbx
__int64 i; // rbx
__int64 v4; // rcx

ezd_thread_sigmask(0LL, 0LL, 0xFFFFFFFFLL);
ezd_thread_sigmask(1LL, 17LL, 0xFFFFFFFFLL);
signal(17, (__sighandler_t)sigchld);
v1 = 0LL;
while ( 1 )
{
if ( conf[19] )
goto LABEL_3;
if ( child_proc_cnt <= 0 )
break;
if ( v1 )
{
if ( time(0LL) > v1 )
break;
}
else
{
v1 = time(0LL) + 10;
if ( conf[22] > 6 )
{
printf("Waiting %i seconds for %i child processes to terminate", 10LL, (unsigned int)child_proc_cnt);
putchar(10);
}
}
LABEL_3:
if ( do_child_proc_reap )
child_proc_reap();
usleep(0x7A120u);
}
pthread_mutex_lock(&child_proc_lock);
for ( i = child_procs; i; i = *(_QWORD *)i )
{
v4 = *(unsigned int *)(i + 16);
if ( (int)v4 > 0 )
{
syslog(4, "Child process \"%s\" (%i) did not terminate in %is: killing", *(const char **)(i + 24), v4, 10LL);
kill(*(_DWORD *)(i + 16), 15);
sleep(1u);
kill(*(_DWORD *)(i + 16), 9);
}
}
pthread_mutex_unlock(&child_proc_lock);
child_proc_reap();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
time_t v1; // rbx
__int64 i; // rbx
__int64 v4; // rcx

ezd_thread_sigmask(0LL, 0LL, 0xFFFFFFFFLL);
ezd_thread_sigmask(1LL, 17LL, 0xFFFFFFFFLL);
signal(17, (__sighandler_t)sigchld);
v1 = 0LL;
while ( 1 )
{
if ( conf[19] )
goto LABEL_3;
if ( child_proc_cnt <= 0 )
break;
if ( v1 )
{
if ( time(0LL) > v1 )
break;
}
else
{
v1 = time(0LL) + 10;
if ( conf[22] > 6 )
{
printf("Waiting %i seconds for %i child processes to terminate", 10LL, (unsigned int)child_proc_cnt);
putchar(10);
}
}
LABEL_3:
if ( do_child_proc_reap )
func6();
usleep(0x7A120u);
}
pthread_mutex_lock(&child_proc_lock);
for ( i = child_procs; i; i = *(_QWORD *)i )
{
v4 = *(unsigned int *)(i + 16);
if ( (int)v4 > 0 )
{
syslog(4, "Child process \"%s\" (%i) did not terminate in %is: killing", *(const char **)(i + 24), v4, 10LL);
kill(*(_DWORD *)(i + 16), 15);
sleep(1u);
kill(*(_DWORD *)(i + 16), 9);
}
}
pthread_mutex_unlock(&child_proc_lock);
func6();
return 0LL;
}

original_code:
static void *exec_main (void *ignore) {
 time_t hard_timeout = 0;
 const int gracetime = 10;
 struct child_proc *cp;
 ezd_thread_sigmask(0, 0 , -1 );
 ezd_thread_sigmask(1, 17, -1 );
 signal(17, sigchld);
 while (conf.run || child_proc_cnt > 0) {
  if (!conf.run) {
   if (!hard_timeout) {
    hard_timeout = time(((void *)0)) + gracetime;
    do { if (conf.log_level > 6) { printf("Waiting %i seconds for " "%i child processes to terminate", gracetime, child_proc_cnt); printf("\n"); } } while (0);
   } else if (hard_timeout < time(((void *)0)))
    break;
  }
  if (do_child_proc_reap)
   child_proc_reap();
  usleep(500000);
 }
 pthread_mutex_lock(&child_proc_lock);
 for ((cp) = ((&child_procs)->lh_first); (cp); (cp) = ((cp)->link.le_next)) {
  if (cp->pid <= 0)
   continue;
  syslog(4, "Child process \"%s\" (%i) did not " "terminate in %is: killing", cp->cmd, (int)cp->pid, gracetime);
  kill(cp->pid, 15);
  sleep(1);
  kill(cp->pid, 9);
 }
 pthread_mutex_unlock(&child_proc_lock);
 child_proc_reap();
 return ((void *)0);
}

canonical_original_code:
static void *exec_main(void *ignore) {
 long hard_timeout = 0;
 int gracetime = 10;
 struct child_proc *cp;
 ezd_thread_sigmask(0, 0 , -1 );
 ezd_thread_sigmask(1, 17, -1 );
 signal(17, sigchld);
 while (conf.run || child_proc_cnt > 0) {
  if (!conf.run) {
   if (!hard_timeout) {
    hard_timeout = time(((void *)0)) + gracetime;
    do { if (conf.log_level > 6) { printf("Waiting %i seconds for " "%i child processes to terminate", gracetime, child_proc_cnt); printf("\n"); } } while (0);
   } else if (hard_timeout < time(((void *)0)))
    break;
  }
  if (do_child_proc_reap)
   child_proc_reap();
  usleep(500000);
 }
 pthread_mutex_lock(&child_proc_lock);
 for ((cp) = ((&child_procs)->lh_first); (cp); (cp) = ((cp)->link.le_next)) {
  if (cp->pid <= 0)
   continue;
  syslog(4, "Child process \"%s\" (%i) did not " "terminate in %is: killing", cp->cmd, (int)cp->pid, gracetime);
  kill(cp->pid, 15);
  sleep(1);
  kill(cp->pid, 9);
 }
 pthread_mutex_unlock(&child_proc_lock);
 child_proc_reap();
 return ((void *)0);
}

variable_types:
ignore
void *

variable_types: gracetime int

return_type: void *


decompiled_code:
int exec_term()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

return pthread_join(exec_thread, &thread_return);
}

canonical_decompiled_code:
int func8()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

return pthread_join(exec_thread, &thread_return);
}

original_code:
void exec_term (void) {
 void *ignore;
 pthread_join(exec_thread, &ignore);
}

canonical_original_code:
void exec_term() {
 void *ignore;
 pthread_join(exec_thread, &ignore);
}


decompiled_code:
int exec_init()
{
int result; // eax
char *v1; // rax

result = pthread_create(&exec_thread, 0LL, exec_main, 0LL);
if ( result )
{
v1 = strerror(result);
syslog(3, "Failed to create exec_main thread: %s", v1);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func9()
{
int result; // eax
char *v1; // rax

result = pthread_create(&exec_thread, 0LL, exec_main, 0LL);
if ( result )
{
v1 = strerror(result);
syslog(3, "Failed to create exec_main thread: %s", v1);
exit(1);
}
return result;
}

original_code:
void exec_init (void) {
 int err;
 if ((err = pthread_create(&exec_thread, ((void *)0), exec_main, ((void *)0)))) {
  syslog(3, "Failed to create exec_main thread: %s", strerror(err));
  exit(1);
 }
}

canonical_original_code:
void exec_init() {
 int err;
 if ((err = pthread_create(&exec_thread, ((void *)0), exec_main, ((void *)0)))) {
  syslog(3, "Failed to create exec_main thread: %s", strerror(err));
  exit(1);
 }
}

variable_types: err int


ltrim

decompiled_code:
char *__fastcall ltrim(char *a1)
{
const unsigned __int16 *v2; // rdx

v2 = *_ctype_b_loc();
while ( (v2[*a1] & 0x2000) != 0 )
++a1;
return a1;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1)
{
const unsigned __int16 *v2; // rdx

v2 = *_ctype_b_loc();
while ( (v2[*a1] & 0x2000) != 0 )
++a1;
return a1;
}

original_code:
static char *ltrim (const char *s) {
 while (((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace))
  s++;
 return (char *)s;
}

canonical_original_code:
static char *ltrim(char *s) {
 while (((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace))
  s++;
 return (char *)s;
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall kv_parse(const char **a1, const char **a2, _QWORD *a3)
{
const char *v3; // rbx
const unsigned __int16 *v5; // rcx
unsigned int v6; // edx
char *v7; // rax
char *v8; // rax

v3 = *a1;
if ( !*a1 )
return 0;
v5 = *_ctype_b_loc();
while ( (v5[*v3] & 0x2000) != 0 )
++v3;
v6 = 0;
if ( *v3 )
{
v7 = strchr(v3, 61);
if ( v7 )
{
*v7 = 0;
*a2 = v3;
*a3 = v7 + 1;
v8 = strchr(v7 + 1, 44);
if ( v8 )
{
*v8 = 0;
*a1 = v8 + 1;
}
else
{
*a1 = 0LL;
}
v6 = 1;
}
else
{
*a2 = v3;
*a3 = &unk_DD8;
*a1 = 0LL;
v6 = 1;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char **a1, const char **a2, _QWORD *a3)
{
const char *v3; // rbx
const unsigned __int16 *v5; // rcx
unsigned int v6; // edx
char *v7; // rax
char *v8; // rax

v3 = *a1;
if ( !*a1 )
return 0;
v5 = *_ctype_b_loc();
while ( (v5[*v3] & 0x2000) != 0 )
++v3;
v6 = 0;
if ( *v3 )
{
v7 = strchr(v3, 61);
if ( v7 )
{
*v7 = 0;
*a2 = v3;
*a3 = v7 + 1;
v8 = strchr(v7 + 1, 44);
if ( v8 )
{
*v8 = 0;
*a1 = v8 + 1;
}
else
{
*a1 = 0LL;
}
v6 = 1;
}
else
{
*a2 = v3;
*a3 = &unk_DD8;
*a1 = 0LL;
v6 = 1;
}
}
return v6;
}

original_code:
static int kv_parse (char **strp, const char **namep, const char **valp) {
 char *s;
 char *str = *strp;
 if (!str)
  return 0;
 while (((*__ctype_b_loc ())[(int) (((int)*str))] & (unsigned short int) _ISspace))
  str++;
 if (!*str)
  return 0;
 if (!(s = strchr(str, '='))) {
  *namep = str;
  *valp = " ";
  *strp = ((void *)0);
  return 1;
 }
 *s = '\0';
 *namep = str;
 *valp = s+1;
 if ((s = strchr(*valp, ','))) {
  *s = '\0';
  *strp = s+1;
 } else
  *strp = ((void *)0);
 return 1;
}

canonical_original_code:
static int kv_parse(char **strp, char **namep, char **valp) {
 char *s;
 char *str = *strp;
 if (!str)
  return 0;
 while (((*__ctype_b_loc ())[(int) (((int)*str))] & (unsigned short) _ISspace))
  str++;
 if (!*str)
  return 0;
 if (!(s = strchr(str, '='))) {
  *namep = str;
  *valp = " ";
  *strp = ((void *)0);
  return 1;
 }
 *s = '\0';
 *namep = str;
 *valp = s+1;
 if ((s = strchr(*valp, ','))) {
  *s = '\0';
  *strp = s+1;
 } else
  *strp = ((void *)0);
 return 1;
}

variable_types:
strp
char **

variable_types:
namep
char **

variable_types:
valp
char **

variable_types:
str
char *


decompiled_code:
int __fastcall encoding_parse(char *s1)
{
int result; // eax

result = strcasecmp(s1, "string");
if ( result )
result = strcasecmp(s1, "json") == 0 ? 1 : -1;
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1)
{
int result; // eax

result = strcasecmp(s1, "string");
if ( result )
result = strcasecmp(s1, "json") == 0 ? 1 : -1;
return result;
}

original_code:
static encoding_t encoding_parse (const char *val) {
 if (!strcasecmp(val, "string"))
  return ENC_STRING;
 else if (!strcasecmp(val, "json"))
  return ENC_JSON;
 else
  return ENC_ERROR;
}

canonical_original_code:
static enum encoding_t encoding_parse(char *val) {
 if (!strcasecmp(val, "string"))
  return ENC_STRING;
 else if (!strcasecmp(val, "json"))
  return ENC_JSON;
 else
  return ENC_ERROR;
}

variable_types:
val
char *

return_type: enum encoding_t { ENC_ERROR=-1, ENC_STRING=0, ENC_JSON=1 }


decompiled_code:
char *__fastcall str_unescape(char *a1)
{
char *v1; // rbp
char *i; // rbx
char v3; // al
size_t v4; // rax
bool v5; // zf

v1 = a1;
if ( *a1 )
{
for ( i = a1; *i; ++i )
{
if ( !memcmp(i, "\\n", 2uLL) )
{
v3 = 10;
}
else if ( !memcmp(i, "\\r", 2uLL) )
{
v3 = 13;
}
else if ( !memcmp(i, "\\t", 2uLL) )
{
v3 = 9;
}
else
{
v5 = memcmp(i, "\\0", 2uLL) == 0;
v3 = !v5;
if ( !v5 )
continue;
}
*i = v3;
v4 = strlen(i + 2);
memmove(i + 1, i + 2, v4 + 1);
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func3(char *a1)
{
char *v1; // rbp
char *i; // rbx
char v3; // al
size_t v4; // rax
bool v5; // zf

v1 = a1;
if ( *a1 )
{
for ( i = a1; *i; ++i )
{
if ( !memcmp(i, "\\n", 2uLL) )
{
v3 = 10;
}
else if ( !memcmp(i, "\\r", 2uLL) )
{
v3 = 13;
}
else if ( !memcmp(i, "\\t", 2uLL) )
{
v3 = 9;
}
else
{
v5 = memcmp(i, "\\0", 2uLL) == 0;
v3 = !v5;
if ( !v5 )
continue;
}
*i = v3;
v4 = strlen(i + 2);
memmove(i + 1, i + 2, v4 + 1);
}
}
return v1;
}

original_code:
static char *str_unescape (char *str) {
 char *s = str;
 while (*s) {
  int esc = -1;
  if (!strncmp(s, "\\n", 2))
   esc = '\n';
  else if (!strncmp(s, "\\r", 2))
   esc = '\r';
  else if (!strncmp(s, "\\t", 2))
   esc = '\t';
  else if (!strncmp(s, "\\0", 2))
   esc = '\0';
  if (esc != -1) {
   *s = esc;
   memmove(s+1, s+2, strlen(s+2)+1);
  }
  s++;
 }
 return str;
}

canonical_original_code:
static char *str_unescape(char *str) {
 char *s = str;
 while (*s) {
  int esc = -1;
  if (!strncmp(s, "\\n", 2))
   esc = '\n';
  else if (!strncmp(s, "\\r", 2))
   esc = '\r';
  else if (!strncmp(s, "\\t", 2))
   esc = '\t';
  else if (!strncmp(s, "\\0", 2))
   esc = '\0';
  if (esc != -1) {
   *s = esc;
   memmove(s+1, s+2, strlen(s+2)+1);
  }
  s++;
 }
 return str;
}

variable_types: esc int


decompiled_code:
__int64 __fastcall conf_tof(char *s1)
{
int v1; // eax
int v2; // edx
__int64 result; // rax
int v4; // edx
int v5; // edx
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = strtoul(s1, &endptr, 0);
if ( endptr > s1 )
return v1 != 0;
v2 = strcasecmp(s1, "yes");
result = 1LL;
if ( v2 )
{
v4 = strcasecmp(s1, "true");
result = 1LL;
if ( v4 )
{
v5 = strcasecmp(s1, "on");
result = 1LL;
if ( v5 )
result = *s1 == 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s1)
{
int v1; // eax
int v2; // edx
__int64 result; // rax
int v4; // edx
int v5; // edx
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = strtoul(s1, &endptr, 0);
if ( endptr > s1 )
return v1 != 0;
v2 = strcasecmp(s1, "yes");
result = 1LL;
if ( v2 )
{
v4 = strcasecmp(s1, "true");
result = 1LL;
if ( v4 )
{
v5 = strcasecmp(s1, "on");
result = 1LL;
if ( v5 )
result = *s1 == 0;
}
}
return result;
}

original_code:
static int conf_tof (const char *val) {
 char *end;
 int i;
 i = strtoul(val, &end, 0);
 if (end > val)
  return !!i;
 if (!strcasecmp(val, "yes") ||
     !strcasecmp(val, "true") ||
     !strcasecmp(val, "on") ||
     !*val )
  return 1;
 else
  return 0;
}

canonical_original_code:
static int conf_tof(char *val) {
 char *end;
 int i;
 i = strtoul(val, &end, 0);
 if (end > val)
  return !!i;
 if (!strcasecmp(val, "yes") ||
     !strcasecmp(val, "true") ||
     !strcasecmp(val, "on") ||
     !*val )
  return 1;
 else
  return 0;
}

variable_types:
end
char *


decompiled_code:
__int64 __fastcall conf_set(char *s1, char *a2, char *s, size_t maxlen)
{
unsigned int v8; // ebx
void *v9; // rdi
size_t v11; // r12
void *v12; // rsp
size_t v13; // r12
void *v14; // rsp
char *v15; // rax
size_t v16; // r12
void *v17; // rsp
size_t v18; // rbx
void *v19; // rsp
size_t v20; // r13
void *v21; // rsp
int v22; // eax
int v23; // ebx
void *v24; // rsp
int v25; // er13
size_t v26; // r12
void *v27; // rsp
size_t v28; // r12
void *v29; // rsp
size_t v30; // r12
void *v31; // rsp
unsigned int v32; // eax
size_t v33; // r12
void *v34; // rsp
size_t v35; // r12
void *v36; // rsp
unsigned int v37; // eax
int v38; // eax
char *v39; // rax
bool v40; // zf
void *v41; // rdi
void *v42; // rdi
size_t v43; // [rsp+0h] [rbp-E0h] BYREF
unsigned __int64 v44; // [rsp+8h] [rbp-D8h]
unsigned int v45; // [rsp+18h] [rbp-C8h] BYREF
unsigned int v46; // [rsp+1Ch] [rbp-C4h] BYREF
void *v47; // [rsp+20h] [rbp-C0h] BYREF
size_t v48; // [rsp+28h] [rbp-B8h]
void *src; // [rsp+30h] [rbp-B0h]
size_t n; // [rsp+38h] [rbp-A8h]
void *v51; // [rsp+40h] [rbp-A0h]
size_t v52; // [rsp+48h] [rbp-98h]
void *v53; // [rsp+50h] [rbp-90h]
size_t v54; // [rsp+58h] [rbp-88h]
void *v55; // [rsp+70h] [rbp-70h]
size_t v56; // [rsp+78h] [rbp-68h]
void *v57; // [rsp+90h] [rbp-50h]
size_t v58; // [rsp+98h] [rbp-48h]

if ( !memcmp(s1, "kafka.", 6uLL) )
{
if ( !memcmp(s1 + 6, "topic.", 6uLL) )
v8 = rd_kafka_topic_conf_set(*(&conf + 22), s1 + 12, a2, s, maxlen);
else
v8 = rd_kafka_conf_set(*(&conf + 21), s1 + 6, a2, s, maxlen);
if ( !v8 )
return v8;
if ( v8 != -2 )
return (unsigned int)-1;
}
if ( a2 )
{
v8 = strcmp(s1, "output.format") != 0;
if ( v8 )
{
v8 = strcmp(s1, "output.encoding") != 0;
if ( v8 )
{
v8 = strcmp(s1, "output.delimiter") != 0;
if ( v8 )
{
v8 = strcmp(s1, "output.queue.size") != 0;
if ( v8 )
{
v8 = strcmp(s1, "log.level") != 0;
if ( v8 )
{
v8 = strcmp(s1, "log.statistics.file") != 0;
if ( v8 )
{
v8 = strcmp(s1, "log.statistics.interval") != 0;
if ( v8 )
{
v8 = strcmp(s1, "log.rate.max") != 0;
if ( v8 )
{
v8 = strcmp(s1, "log.rate.period") != 0;
if ( v8 )
{
v8 = strcmp(s1, "daemonize") != 0;
if ( v8 )
{
v40 = strcmp(s1, "pid.file.path") == 0;
v8 = !v40;
if ( v40 )
{
free(*(&conf + 16));
*(&conf + 16) = strdup(a2);
}
else
{
v8 = strcmp(s1, "command.init");
if ( v8 )
{
v8 = strcmp(s1, "command.term");
if ( v8 )
{
v8 = strncmp(s1, "env.", 4uLL);
if ( v8 )
{
snprintf(s, maxlen, "Unknown configuration property \"%s\"\n", s1);
v8 = -1;
}
else if ( *a2 )
{
setenv(s1 + 4, a2, 1);
}
else
{
unsetenv(s1 + 4);
}
}
else
{
v42 = *(&conf + 18);
if ( v42 )
free(v42);
*(&conf + 18) = strdup(a2);
}
}
else
{
v41 = *(&conf + 17);
if ( v41 )
free(v41);
*(&conf + 17) = strdup(a2);
}
}
}
else
{
*((_DWORD *)&conf + 25) = conf_tof(a2);
}
}
else
{
*((_DWORD *)&conf + 24) = atoi(a2);
}
}
else
{
*((_DWORD *)&conf + 23) = atoi(a2);
}
}
else
{
*((_DWORD *)&conf + 26) = atoi(a2);
}
}
else
{
free(*(&conf + 14));
*(&conf + 14) = strdup(a2);
}
}
else
{
*((_DWORD *)&conf + 22) = atoi(a2);
}
}
else
{
*((_DWORD *)&conf + 16) = atoi(a2);
}
}
else
{
if ( conf )
free(conf);
v39 = strdup(a2);
conf = str_unescape(v39);
*((_DWORD *)&conf + 2) = strlen((const char *)conf);
}
}
else
{
v38 = encoding_parse(a2);
LODWORD(v44) = v38;
*((_DWORD *)&conf + 4) = v38;
if ( v38 == -1 )
{
snprintf(s, maxlen, "Unknown %s value \"%s\"", s1, a2);
v8 = v44;
}
}
}
else
{
v9 = *(&conf + 7);
if ( v9 )
free(v9);
*(&conf + 7) = strdup(a2);
}
return v8;
}
if ( (unsigned int)ezd_regmatch("^input +(\\[([^\\]+)\\] +)?pipe +(.+)$", s1, &v47, 3LL) == 3 )
{
v45 = 0;
v46 = 0;
if ( src )
{
v11 = n;
v12 = alloca(n + 9);
memcpy(&v43, src, n);
*((_BYTE *)&v43 + v11) = 0;
if ( (unsigned int)input_kvs_parse((const char *)&v43, &v45, &v46, s, maxlen) == -1 )
return -1;
}
v13 = v52;
v14 = alloca(v52 + 9);
memcpy(&v43, v51, v52);
*((_BYTE *)&v43 + v13) = 0;
v15 = ltrim((char *)&v43);
v8 = 0;
if ( !input_add(0LL, v45, v46, v15, 0LL, 0LL, s, maxlen) )
return -1;
return v8;
}
if ( (int)ezd_regmatch(
"^input +(\\[([^\\]+)\\] +)?kafka +topic +([^ ]+) +partition +([0-9]+)(-([0-9]+))?( +from +(beginning|end|stored|[0-9]+))$",
s1,
&v47,
8LL) <= 3 )
{
if ( (unsigned int)ezd_regmatch("^output +pipe +([0-9]+) +(.+)$", s1, &v47, 2LL) == 2 )
{
v28 = n;
v29 = alloca(16 * ((n + 24) / 0x10));
memcpy(&v43, src, n);
*((_BYTE *)&v43 + v28) = 0;
v30 = v48;
v31 = alloca(16 * ((v48 + 24) / 0x10));
memcpy(&v43, v47, v48);
*((_BYTE *)&v43 + v30) = 0;
v32 = atoi((const char *)&v43);
output_add(0LL, v32, &v43);
v8 = 0;
}
else if ( (unsigned int)ezd_regmatch("^output +file +([0-9]+) +(.+)$", s1, &v47, 2LL) == 2 )
{
v33 = n;
v34 = alloca(16 * ((n + 24) / 0x10));
memcpy(&v43, src, n);
*((_BYTE *)&v43 + v33) = 0;
v35 = v48;
v36 = alloca(16 * ((v48 + 24) / 0x10));
memcpy(&v43, v47, v48);
*((_BYTE *)&v43 + v35) = 0;
v37 = atoi((const char *)&v43);
output_add(1LL, v37, &v43);
v8 = 0;
}
else
{
snprintf(s, maxlen, "Unknown configuration directive \"%s\"", s1);
v8 = -1;
}
return v8;
}
v45 = 0;
v46 = 0;
if ( src )
{
v16 = n;
v17 = alloca(n + 9);
memcpy(&v43, src, n);
*((_BYTE *)&v43 + v16) = 0;
if ( (unsigned int)input_kvs_parse((const char *)&v43, &v45, &v46, s, maxlen) == -1 )
return (unsigned int)-1;
}
v44 = -1000LL;
if ( v57 )
{
v44 = -2LL;
if ( memcmp(v57, "beginning", 9uLL) )
{
v44 = -1LL;
if ( memcmp(v57, "end", 3uLL) )
{
v44 = -1000LL;
if ( memcmp(v57, "stored", 6uLL) )
{
v26 = v58;
v27 = alloca(v58 + 9);
memcpy(&v43, v57, v58);
*((_BYTE *)&v43 + v26) = 0;
v44 = strtoull((const char *)&v43, 0LL, 10);
}
}
}
}
v18 = v52;
v19 = alloca(16 * ((v52 + 24) / 0x10));
memcpy(&v43, v51, v52);
*((_BYTE *)&v43 + v18) = 0;
v20 = v54;
v21 = alloca(16 * ((v54 + 24) / 0x10));
memcpy(&v43, v53, v54);
*((_BYTE *)&v43 + v20) = 0;
v22 = atoi((const char *)&v43);
v23 = v22;
if ( !v55 )
{
v25 = v22;
LABEL_28:
while ( input_add(1LL, v45, v46, &v43, (unsigned int)v23, v44, s, maxlen) )
{
if ( ++v23 > v25 )
return 0;
}
return (unsigned int)-1;
}
v24 = alloca(v56 + 9);
v43 = v56;
memcpy(&v43, v55, v56);
*((_BYTE *)&v43 + v43) = 0;
v25 = atoi((const char *)&v43);
if ( v23 <= v25 )
goto LABEL_28;
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s1, char *a2, char *s, size_t maxlen)
{
unsigned int v8; // ebx
void *v9; // rdi
size_t v11; // r12
void *v12; // rsp
size_t v13; // r12
void *v14; // rsp
char *v15; // rax
size_t v16; // r12
void *v17; // rsp
size_t v18; // rbx
void *v19; // rsp
size_t v20; // r13
void *v21; // rsp
int v22; // eax
int v23; // ebx
void *v24; // rsp
int v25; // er13
size_t v26; // r12
void *v27; // rsp
size_t v28; // r12
void *v29; // rsp
size_t v30; // r12
void *v31; // rsp
unsigned int v32; // eax
size_t v33; // r12
void *v34; // rsp
size_t v35; // r12
void *v36; // rsp
unsigned int v37; // eax
int v38; // eax
char *v39; // rax
bool v40; // zf
void *v41; // rdi
void *v42; // rdi
size_t v43; // [rsp+0h] [rbp-E0h] BYREF
unsigned __int64 v44; // [rsp+8h] [rbp-D8h]
unsigned int v45; // [rsp+18h] [rbp-C8h] BYREF
unsigned int v46; // [rsp+1Ch] [rbp-C4h] BYREF
void *v47; // [rsp+20h] [rbp-C0h] BYREF
size_t v48; // [rsp+28h] [rbp-B8h]
void *src; // [rsp+30h] [rbp-B0h]
size_t n; // [rsp+38h] [rbp-A8h]
void *v51; // [rsp+40h] [rbp-A0h]
size_t v52; // [rsp+48h] [rbp-98h]
void *v53; // [rsp+50h] [rbp-90h]
size_t v54; // [rsp+58h] [rbp-88h]
void *v55; // [rsp+70h] [rbp-70h]
size_t v56; // [rsp+78h] [rbp-68h]
void *v57; // [rsp+90h] [rbp-50h]
size_t v58; // [rsp+98h] [rbp-48h]

if ( !memcmp(s1, "kafka.", 6uLL) )
{
if ( !memcmp(s1 + 6, "topic.", 6uLL) )
v8 = rd_kafka_topic_conf_set(*(&conf + 22), s1 + 12, a2, s, maxlen);
else
v8 = rd_kafka_conf_set(*(&conf + 21), s1 + 6, a2, s, maxlen);
if ( !v8 )
return v8;
if ( v8 != -2 )
return (unsigned int)-1;
}
if ( a2 )
{
v8 = strcmp(s1, "output.format") != 0;
if ( v8 )
{
v8 = strcmp(s1, "output.encoding") != 0;
if ( v8 )
{
v8 = strcmp(s1, "output.delimiter") != 0;
if ( v8 )
{
v8 = strcmp(s1, "output.queue.size") != 0;
if ( v8 )
{
v8 = strcmp(s1, "log.level") != 0;
if ( v8 )
{
v8 = strcmp(s1, "log.statistics.file") != 0;
if ( v8 )
{
v8 = strcmp(s1, "log.statistics.interval") != 0;
if ( v8 )
{
v8 = strcmp(s1, "log.rate.max") != 0;
if ( v8 )
{
v8 = strcmp(s1, "log.rate.period") != 0;
if ( v8 )
{
v8 = strcmp(s1, "daemonize") != 0;
if ( v8 )
{
v40 = strcmp(s1, "pid.file.path") == 0;
v8 = !v40;
if ( v40 )
{
free(*(&conf + 16));
*(&conf + 16) = strdup(a2);
}
else
{
v8 = strcmp(s1, "command.init");
if ( v8 )
{
v8 = strcmp(s1, "command.term");
if ( v8 )
{
v8 = strncmp(s1, "env.", 4uLL);
if ( v8 )
{
snprintf(s, maxlen, "Unknown configuration property \"%s\"\n", s1);
v8 = -1;
}
else if ( *a2 )
{
setenv(s1 + 4, a2, 1);
}
else
{
unsetenv(s1 + 4);
}
}
else
{
v42 = *(&conf + 18);
if ( v42 )
free(v42);
*(&conf + 18) = strdup(a2);
}
}
else
{
v41 = *(&conf + 17);
if ( v41 )
free(v41);
*(&conf + 17) = strdup(a2);
}
}
}
else
{
*((_DWORD *)&conf + 25) = func4(a2);
}
}
else
{
*((_DWORD *)&conf + 24) = atoi(a2);
}
}
else
{
*((_DWORD *)&conf + 23) = atoi(a2);
}
}
else
{
*((_DWORD *)&conf + 26) = atoi(a2);
}
}
else
{
free(*(&conf + 14));
*(&conf + 14) = strdup(a2);
}
}
else
{
*((_DWORD *)&conf + 22) = atoi(a2);
}
}
else
{
*((_DWORD *)&conf + 16) = atoi(a2);
}
}
else
{
if ( conf )
free(conf);
v39 = strdup(a2);
conf = func3(v39);
*((_DWORD *)&conf + 2) = strlen((const char *)conf);
}
}
else
{
v38 = func2(a2);
LODWORD(v44) = v38;
*((_DWORD *)&conf + 4) = v38;
if ( v38 == -1 )
{
snprintf(s, maxlen, "Unknown %s value \"%s\"", s1, a2);
v8 = v44;
}
}
}
else
{
v9 = *(&conf + 7);
if ( v9 )
free(v9);
*(&conf + 7) = strdup(a2);
}
return v8;
}
if ( (unsigned int)ezd_regmatch("^input +(\\[([^\\]+)\\] +)?pipe +(.+)$", s1, &v47, 3LL) == 3 )
{
v45 = 0;
v46 = 0;
if ( src )
{
v11 = n;
v12 = alloca(n + 9);
memcpy(&v43, src, n);
*((_BYTE *)&v43 + v11) = 0;
if ( (unsigned int)func5((const char *)&v43, &v45, &v46, s, maxlen) == -1 )
return -1;
}
v13 = v52;
v14 = alloca(v52 + 9);
memcpy(&v43, v51, v52);
*((_BYTE *)&v43 + v13) = 0;
v15 = func0((char *)&v43);
v8 = 0;
if ( !input_add(0LL, v45, v46, v15, 0LL, 0LL, s, maxlen) )
return -1;
return v8;
}
if ( (int)ezd_regmatch(
"^input +(\\[([^\\]+)\\] +)?kafka +topic +([^ ]+) +partition +([0-9]+)(-([0-9]+))?( +from +(beginning|end|stored|[0-9]+))$",
s1,
&v47,
8LL) <= 3 )
{
if ( (unsigned int)ezd_regmatch("^output +pipe +([0-9]+) +(.+)$", s1, &v47, 2LL) == 2 )
{
v28 = n;
v29 = alloca(16 * ((n + 24) / 0x10));
memcpy(&v43, src, n);
*((_BYTE *)&v43 + v28) = 0;
v30 = v48;
v31 = alloca(16 * ((v48 + 24) / 0x10));
memcpy(&v43, v47, v48);
*((_BYTE *)&v43 + v30) = 0;
v32 = atoi((const char *)&v43);
output_add(0LL, v32, &v43);
v8 = 0;
}
else if ( (unsigned int)ezd_regmatch("^output +file +([0-9]+) +(.+)$", s1, &v47, 2LL) == 2 )
{
v33 = n;
v34 = alloca(16 * ((n + 24) / 0x10));
memcpy(&v43, src, n);
*((_BYTE *)&v43 + v33) = 0;
v35 = v48;
v36 = alloca(16 * ((v48 + 24) / 0x10));
memcpy(&v43, v47, v48);
*((_BYTE *)&v43 + v35) = 0;
v37 = atoi((const char *)&v43);
output_add(1LL, v37, &v43);
v8 = 0;
}
else
{
snprintf(s, maxlen, "Unknown configuration directive \"%s\"", s1);
v8 = -1;
}
return v8;
}
v45 = 0;
v46 = 0;
if ( src )
{
v16 = n;
v17 = alloca(n + 9);
memcpy(&v43, src, n);
*((_BYTE *)&v43 + v16) = 0;
if ( (unsigned int)func5((const char *)&v43, &v45, &v46, s, maxlen) == -1 )
return (unsigned int)-1;
}
v44 = -1000LL;
if ( v57 )
{
v44 = -2LL;
if ( memcmp(v57, "beginning", 9uLL) )
{
v44 = -1LL;
if ( memcmp(v57, "end", 3uLL) )
{
v44 = -1000LL;
if ( memcmp(v57, "stored", 6uLL) )
{
v26 = v58;
v27 = alloca(v58 + 9);
memcpy(&v43, v57, v58);
*((_BYTE *)&v43 + v26) = 0;
v44 = strtoull((const char *)&v43, 0LL, 10);
}
}
}
}
v18 = v52;
v19 = alloca(16 * ((v52 + 24) / 0x10));
memcpy(&v43, v51, v52);
*((_BYTE *)&v43 + v18) = 0;
v20 = v54;
v21 = alloca(16 * ((v54 + 24) / 0x10));
memcpy(&v43, v53, v54);
*((_BYTE *)&v43 + v20) = 0;
v22 = atoi((const char *)&v43);
v23 = v22;
if ( !v55 )
{
v25 = v22;
LABEL_28:
while ( input_add(1LL, v45, v46, &v43, (unsigned int)v23, v44, s, maxlen) )
{
if ( ++v23 > v25 )
return 0;
}
return (unsigned int)-1;
}
v24 = alloca(v56 + 9);
v43 = v56;
memcpy(&v43, v55, v56);
*((_BYTE *)&v43 + v43) = 0;
v25 = atoi((const char *)&v43);
if ( v23 <= v25 )
goto LABEL_28;
return 0;
}

original_code:
int conf_set (const char *name, const char *val,
       char *errstr, size_t errstr_size,
       void *opaque) {
 rd_kafka_conf_res_t res;
 if (!strncmp(name, "kafka.", strlen("kafka."))) {
  name += strlen("kafka.");
  if (!strncmp(name, "topic.", strlen("topic.")))
   res = rd_kafka_topic_conf_set(conf.rkt_conf,
            name+strlen("topic."),
            val,
            errstr, errstr_size);
  else
   res = rd_kafka_conf_set(conf.rk_conf, name,
      val, errstr, errstr_size);
  if (res == RD_KAFKA_CONF_OK)
   return 0;
  else if (res != RD_KAFKA_CONF_UNKNOWN)
   return -1;
  name -= strlen("kafka.");
 }
 if (!val) {
  struct iovec arg[8+1];
  if (ezd_regmatch("^input +(\\[([^\\]+)\\] +)?pipe +(.+)$",
     name, arg, 3) == 3) {
   encoding_t enc = ENC_STRING;
   int flags = 0;
   if (arg[1].iov_base) {
    if (input_kvs_parse(({ struct iovec *_v = (&arg[1]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }),
          &enc, &flags,
          errstr, errstr_size) == -1)
     return -1;
   }
   if (!input_add(INPUT_PIPE, enc, flags,
           ltrim(({ struct iovec *_v = (&arg[2]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; })), 0, 0,
           errstr, errstr_size))
    return -1;
  } else if (ezd_regmatch("^input +(\\[([^\\]+)\\] +)?kafka +"
     "topic +([^ ]+) +"
     "partition +([0-9]+)(-([0-9]+))?"
     "( +from "
     "+(beginning|end|stored|[0-9]+))"
     "$",
     name, arg, 8) >= 4) {
   int part_lo, part_hi;
   char *topic;
   int64_t offset = -1000;
   encoding_t enc = ENC_STRING;
   int flags = 0;
   if (arg[1].iov_base) {
    if (input_kvs_parse(({ struct iovec *_v = (&arg[1]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }),
          &enc, &flags,
          errstr, errstr_size) == -1)
     return -1;
   }
   if (arg[7].iov_base) {
    if (!strncmp(arg[7].iov_base, "beginning", 9))
     offset = -2;
    else if (!strncmp(arg[7].iov_base, "end", 3))
     offset = -1;
    else if (!strncmp(arg[7].iov_base, "stored", 6))
     offset = -1000;
    else
     offset = strtoull(({ struct iovec *_v = (&arg[7]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }),
         ((void *)0), 10);
   }
   topic = ({ struct iovec *_v = (&arg[2]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; });
   part_lo = atoi(({ struct iovec *_v = (&arg[3]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }));
   if (arg[5].iov_base)
    part_hi = atoi(({ struct iovec *_v = (&arg[5]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }));
   else
    part_hi = part_lo;
   for ( ; part_lo <= part_hi ; part_lo++)
    if (!input_add(INPUT_KAFKA, enc, flags,
            topic, part_lo,
            offset, errstr, errstr_size))
     return -1;
  } else if (ezd_regmatch("^output +pipe +([0-9]+) +(.+)$",
     name, arg, 2) == 2) {
   output_add(OUTPUT_PIPE, atoi(({ struct iovec *_v = (&arg[0]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; })),
       ({ struct iovec *_v = (&arg[1]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }));
  } else if (ezd_regmatch("^output +file +([0-9]+) +(.+)$",
     name, arg, 2) == 2) {
   output_add(OUTPUT_FILE, atoi(({ struct iovec *_v = (&arg[0]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; })),
       ({ struct iovec *_v = (&arg[1]); char *_s = __builtin_alloca (_v->iov_len+1) ; memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }));
  } else {
   snprintf(errstr, errstr_size,
     "Unknown configuration directive \"%s\"",
     name);
   return -1;
  }
  return 0;
 }
 if (!strcmp(name, "output.format")) {
  if (conf.fconf.format)
   free(conf.fconf.format);
  conf.fconf.format = strdup(val);
 } else if (!strcmp(name, "output.encoding")) {
  if ((conf.fconf.encoding =
       encoding_parse(val)) == ENC_ERROR) {
   snprintf(errstr, errstr_size,
     "Unknown %s value \"%s\"", name, val);
   return -1;
  }
 } else if (!strcmp(name, "output.delimiter")) {
  if (conf.output_delimiter)
   free(conf.output_delimiter);
  conf.output_delimiter = str_unescape(strdup(val));
  conf.output_delimiter_len = strlen(conf.output_delimiter);
 } else if (!strcmp(name, "output.queue.size")) {
  conf.output_queue_size = atoi(val);
 } else if (!strcmp(name, "log.level"))
  conf.log_level = atoi(val);
 else if (!strcmp(name, "log.statistics.file")) {
  free(conf.stats_file);
  conf.stats_file = strdup(val);
 } else if (!strcmp(name, "log.statistics.interval"))
  conf.stats_interval = atoi(val);
 else if (!strcmp(name, "log.rate.max"))
  conf.log_rate = atoi(val);
 else if (!strcmp(name, "log.rate.period"))
  conf.log_rate_period = atoi(val);
 else if (!strcmp(name, "daemonize"))
  conf.daemonize = conf_tof(val);
 else if (!strcmp(name, "pid.file.path")) {
  free(conf.pid_file_path);
  conf.pid_file_path = strdup(val);
 } else if (!strcmp(name, "command.init")) {
  if (conf.cmd_init)
   free(conf.cmd_init);
  conf.cmd_init = strdup(val);
 } else if (!strcmp(name, "command.term")) {
  if (conf.cmd_term)
   free(conf.cmd_term);
  conf.cmd_term = strdup(val);
 } else if (!strncmp(name, "env.", strlen("env."))) {
  if (*val)
   setenv(name+strlen("env."), val, 1);
  else
   unsetenv(name+strlen("env."));
 } else {
  snprintf(errstr, errstr_size,
    "Unknown configuration property \"%s\"\n", name);
  return -1;
 }
 return 0;
}

canonical_original_code:
int conf_set(char *name, char *val, char *errstr, unsigned long errstr_size, void *opaque) {
 enum rd_kafka_conf_res_t res;
 if (!strncmp(name, "kafka.", strlen("kafka."))) {
  name += strlen("kafka.");
  if (!strncmp(name, "topic.", strlen("topic.")))
   res = rd_kafka_topic_conf_set(conf.rkt_conf,
            name+strlen("topic."),
            val,
            errstr, errstr_size);
  else
   res = rd_kafka_conf_set(conf.rk_conf, name,
      val, errstr, errstr_size);
  if (res == RD_KAFKA_CONF_OK)
   return 0;
  else if (res != RD_KAFKA_CONF_UNKNOWN)
   return -1;
  name -= strlen("kafka.");
 }
 if (!val) {
  struct iovec arg[-1];
  if (ezd_regmatch("^input +(\\[([^\\]+)\\] +)?pipe +(.+)$",
     name, arg, 3) == 3) {
   enum encoding_t enc = ENC_STRING;
   int flags = 0;
   if (arg[1].iov_base) {
    if (input_kvs_parse(({ struct iovec *_v = (&arg[1]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }),
          &enc, &flags,
          errstr, errstr_size) == -1)
     return -1;
   }
   if (!input_add(INPUT_PIPE, enc, flags,
           ltrim(({ struct iovec *_v = (&arg[2]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; })), 0, 0,
           errstr, errstr_size))
    return -1;
  } else if (ezd_regmatch("^input +(\\[([^\\]+)\\] +)?kafka +"
     "topic +([^ ]+) +"
     "partition +([0-9]+)(-([0-9]+))?"
     "( +from "
     "+(beginning|end|stored|[0-9]+))"
     "$",
     name, arg, 8) >= 4) {
   int part_lo; int part_hi;
   char *topic;
   long offset = -1000;
   enum encoding_t enc = ENC_STRING;
   int flags = 0;
   if (arg[1].iov_base) {
    if (input_kvs_parse(({ struct iovec *_v = (&arg[1]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }),
          &enc, &flags,
          errstr, errstr_size) == -1)
     return -1;
   }
   if (arg[7].iov_base) {
    if (!strncmp(arg[7].iov_base, "beginning", 9))
     offset = -2;
    else if (!strncmp(arg[7].iov_base, "end", 3))
     offset = -1;
    else if (!strncmp(arg[7].iov_base, "stored", 6))
     offset = -1000;
    else
     offset = strtoull(({ struct iovec *_v = (&arg[7]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }),
         ((void *)0), 10);
   }
   topic = ({ struct iovec *_v = (&arg[2]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; });
   part_lo = atoi(({ struct iovec *_v = (&arg[3]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }));
   if (arg[5].iov_base)
    part_hi = atoi(({ struct iovec *_v = (&arg[5]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }));
   else
    part_hi = part_lo;
   for ( ; part_lo <= part_hi ; part_lo++)
    if (!input_add(INPUT_KAFKA, enc, flags,
            topic, part_lo,
            offset, errstr, errstr_size))
     return -1;
  } else if (ezd_regmatch("^output +pipe +([0-9]+) +(.+)$",
     name, arg, 2) == 2) {
   output_add(OUTPUT_PIPE, atoi(({ struct iovec *_v = (&arg[0]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; })),
       ({ struct iovec *_v = (&arg[1]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }));
  } else if (ezd_regmatch("^output +file +([0-9]+) +(.+)$",
     name, arg, 2) == 2) {
   output_add(OUTPUT_FILE, atoi(({ struct iovec *_v = (&arg[0]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; })),
       ({ struct iovec *_v = (&arg[1]); char *_s = __builtin_alloca (_v->iov_len+1); memcpy(_s, _v->iov_base, _v->iov_len); _s[_v->iov_len] = '\0'; _s; }));
  } else {
   snprintf(errstr, errstr_size,
     "Unknown configuration directive \"%s\"",
     name);
   return -1;
  }
  return 0;
 }
 if (!strcmp(name, "output.format")) {
  if (conf.fconf.format)
   free(conf.fconf.format);
  conf.fconf.format = strdup(val);
 } else if (!strcmp(name, "output.encoding")) {
  if ((conf.fconf.encoding =
       encoding_parse(val)) == ENC_ERROR) {
   snprintf(errstr, errstr_size,
     "Unknown %s value \"%s\"", name, val);
   return -1;
  }
 } else if (!strcmp(name, "output.delimiter")) {
  if (conf.output_delimiter)
   free(conf.output_delimiter);
  conf.output_delimiter = str_unescape(strdup(val));
  conf.output_delimiter_len = strlen(conf.output_delimiter);
 } else if (!strcmp(name, "output.queue.size")) {
  conf.output_queue_size = atoi(val);
 } else if (!strcmp(name, "log.level"))
  conf.log_level = atoi(val);
 else if (!strcmp(name, "log.statistics.file")) {
  free(conf.stats_file);
  conf.stats_file = strdup(val);
 } else if (!strcmp(name, "log.statistics.interval"))
  conf.stats_interval = atoi(val);
 else if (!strcmp(name, "log.rate.max"))
  conf.log_rate = atoi(val);
 else if (!strcmp(name, "log.rate.period"))
  conf.log_rate_period = atoi(val);
 else if (!strcmp(name, "daemonize"))
  conf.daemonize = conf_tof(val);
 else if (!strcmp(name, "pid.file.path")) {
  free(conf.pid_file_path);
  conf.pid_file_path = strdup(val);
 } else if (!strcmp(name, "command.init")) {
  if (conf.cmd_init)
   free(conf.cmd_init);
  conf.cmd_init = strdup(val);
 } else if (!strcmp(name, "command.term")) {
  if (conf.cmd_term)
   free(conf.cmd_term);
  conf.cmd_term = strdup(val);
 } else if (!strncmp(name, "env.", strlen("env."))) {
  if (*val)
   setenv(name+strlen("env."), val, 1);
  else
   unsetenv(name+strlen("env."));
 } else {
  snprintf(errstr, errstr_size,
    "Unknown configuration property \"%s\"\n", name);
  return -1;
 }
 return 0;
}

variable_types:
name
char *

variable_types:
errstr
char *

variable_types:
opaque
void *

variable_types: enum rd_kafka_conf_res_t { RD_KAFKA_CONF_UNKNOWN=-2, RD_KAFKA_CONF_INVALID=-1, RD_KAFKA_CONF_OK=0 }

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [-1]

variable_types: enum encoding_t { ENC_ERROR=-1, ENC_STRING=0, ENC_JSON=1 }

variable_types: flags int

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } *

variable_types:
topic
char *

variable_types: offset long


decompiled_code:
int outputs_term()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

return pthread_join(outputs_thread, &thread_return);
}

canonical_decompiled_code:
int func10()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

return pthread_join(outputs_thread, &thread_return);
}

original_code:
void outputs_term (void) {
 void *ignore;
 pthread_join(outputs_thread, &ignore);
}

canonical_original_code:
void outputs_term() {
 void *ignore;
 pthread_join(outputs_thread, &ignore);
}

variable_types:
ignore
void *


decompiled_code:
int outputs_start()
{
int result; // eax
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax

outputs_epoll_fd = epoll_create1(0x80000);
if ( outputs_epoll_fd == -1 )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "Failed to create epoll fd: %s", v2);
exit(1);
}
result = pthread_create(&outputs_thread, 0LL, outputs_main, 0LL);
if ( result == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "Failed to create outputs thread: %s", v4);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func11()
{
int result; // eax
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax

outputs_epoll_fd = epoll_create1(0x80000);
if ( outputs_epoll_fd == -1 )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "Failed to create epoll fd: %s", v2);
exit(1);
}
result = pthread_create(&outputs_thread, 0LL, outputs_main, 0LL);
if ( result == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "Failed to create outputs thread: %s", v4);
exit(1);
}
return result;
}

original_code:
void outputs_start (void) {
 outputs_epoll_fd = epoll_create1(EPOLL_CLOEXEC);
 if (outputs_epoll_fd == -1) {
  syslog(2, "Failed to create epoll fd: %s", strerror((*__errno_location ())));
  exit(1);
 }
 if (pthread_create(&outputs_thread, ((void *)0), outputs_main, ((void *)0)) == -1) {
  syslog(2, "Failed to create outputs thread: %s", strerror((*__errno_location ())));
  exit(1);
 }
}

canonical_original_code:
void outputs_start() {
 outputs_epoll_fd = epoll_create1(EPOLL_CLOEXEC);
 if (outputs_epoll_fd == -1) {
  syslog(2, "Failed to create epoll fd: %s", strerror((*__errno_location ())));
  exit(1);
 }
 if (pthread_create(&outputs_thread, ((void *)0), outputs_main, ((void *)0)) == -1) {
  syslog(2, "Failed to create outputs thread: %s", strerror((*__errno_location ())));
  exit(1);
 }
}


sighup

decompiled_code:
void sighup()
{
conf[21] = ++rotate_version_0;
}

canonical_decompiled_code:
void func0()
{
conf[21] = ++rotate_version_0;
}

original_code:
static void sighup (int sig) {
 static int rotate_version = 0;
 conf.rotate = ++rotate_version;
}

canonical_original_code:
static void sighup(int sig) {
 static int rotate_version = 0;
 conf.rotate = ++rotate_version;
}

variable_types: sig int


term

decompiled_code:
void __fastcall term(unsigned int a1)
{
syslog(5, "Received signal %i: terminating", a1);
if ( !conf[19] )
{
syslog(4, "Forced termination");
exit(0);
}
_InterlockedExchange(&conf[19], 0);
}

canonical_decompiled_code:
void __fastcall func2(unsigned int a1)
{
syslog(5, "Received signal %i: terminating", a1);
if ( !conf[19] )
{
syslog(4, "Forced termination");
exit(0);
}
_InterlockedExchange(&conf[19], 0);
}

original_code:
static void term (int sig) {
 syslog(5, "Received signal %i: terminating", sig);
 if (!conf.run) {
  syslog(4, "Forced termination");
  exit(0);
 }
 __sync_lock_test_and_set(&conf.run,0);
}

canonical_original_code:
static void term(int sig) {
 syslog(5, "Received signal %i: terminating", sig);
 if (!conf.run) {
  syslog(4, "Forced termination");
  exit(0);
 }
 __sync_lock_test_and_set(&conf.run,0);
}


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(
stderr,
"kafkatee version %s\n"
"Kafka consumer with multiple inputs and outputs\n"
"\n"
"Usage: %s [options]\n"
"\n"
"Options:\n"
" -c <path> Configuration file path (%s)\n"
" -p <path> Pid file path (%s)\n"
" -d Enable debugging\n"
" -D Do not daemonize\n"
" -e Exit on EOF:\n"
" Exit when all inputs have reached their\n"
" EOF and all output queues are empty.\n"
" -x Exit on input or output failure.\n"
" (exit code 2)\n"
"\n",
"978c5d",
a1,
"/etc/kafkatee.conf",
"/run/kafkatee.pid");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
fprintf(
stderr,
"kafkatee version %s\n"
"Kafka consumer with multiple inputs and outputs\n"
"\n"
"Usage: %s [options]\n"
"\n"
"Options:\n"
" -c <path> Configuration file path (%s)\n"
" -p <path> Pid file path (%s)\n"
" -d Enable debugging\n"
" -D Do not daemonize\n"
" -e Exit on EOF:\n"
" Exit when all inputs have reached their\n"
" EOF and all output queues are empty.\n"
" -x Exit on input or output failure.\n"
" (exit code 2)\n"
"\n",
"978c5d",
a1,
"/etc/kafkatee.conf",
"/run/kafkatee.pid");
exit(1);
}

original_code:
static void usage (const char *argv0) {
 fprintf(stderr,
  "kafkatee version %s\n"
  "Kafka consumer with multiple inputs and outputs\n"
  "\n"
  "Usage: %s [options]\n"
  "\n"
  "Options:\n"
  "  -c <path>          Configuration file path (%s)\n"
  "  -p <path>          Pid file path (%s)\n"
  "  -d                 Enable debugging\n"
  "  -D                 Do not daemonize\n"
  "  -e                 Exit on EOF:\n"
  "                     Exit when all inputs have reached their\n"
  "                     EOF and all output queues are empty.\n"
  "  -x                 Exit on input or output failure.\n"
  "                     (exit code 2)\n"
  "\n",
  "978c5d",
  argv0,
  "/etc/kafkatee.conf",
  "/run/kafkatee.pid");
 exit(1);
}

canonical_original_code:
static void usage(char *argv0) {
 fprintf(stderr,
  "kafkatee version %s\n"
  "Kafka consumer with multiple inputs and outputs\n"
  "\n"
  "Usage: %s [options]\n"
  "\n"
  "Options:\n"
  "  -c <path>          Configuration file path (%s)\n"
  "  -p <path>          Pid file path (%s)\n"
  "  -d                 Enable debugging\n"
  "  -D                 Do not daemonize\n"
  "  -e                 Exit on EOF:\n"
  "                     Exit when all inputs have reached their\n"
  "                     EOF and all output queues are empty.\n"
  "  -x                 Exit on input or output failure.\n"
  "                     (exit code 2)\n"
  "\n",
  "978c5d",
  argv0,
  "/etc/kafkatee.conf",
  "/run/kafkatee.pid");
 exit(1);
}


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

result = fclose(*(FILE **)&conf[30]);
*(_QWORD *)&conf[30] = 0LL;
return result;
}

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

result = fclose(*(FILE **)&conf[30]);
*(_QWORD *)&conf[30] = 0LL;
return result;
}

original_code:
static void stats_close (void) {
 stats_print();
 fclose(conf.stats_fp);
 conf.stats_fp = ((void *)0);
}

canonical_original_code:
static void stats_close() {
 stats_print();
 fclose(conf.stats_fp);
 conf.stats_fp = ((void *)0);
}


decompiled_code:
__int64 stats_open()
{
FILE *v0; // rax
int *v2; // rax
char *v3; // rax

if ( *(_QWORD *)&conf[30] )
stats_close();
v0 = fopen(*(const char **)&conf[28], "a");
*(_QWORD *)&conf[30] = v0;
if ( v0 )
return 0LL;
v2 = _errno_location();
v3 = strerror(*v2);
syslog(3, "Failed to open statistics log file %s: %s", *(const char **)&conf[28], v3);
return 0xFFFFFFFFLL;
}

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

if ( *(_QWORD *)&conf[30] )
func5();
v0 = fopen(*(const char **)&conf[28], "a");
*(_QWORD *)&conf[30] = v0;
if ( v0 )
return 0LL;
v2 = _errno_location();
v3 = strerror(*v2);
syslog(3, "Failed to open statistics log file %s: %s", *(const char **)&conf[28], v3);
return 0xFFFFFFFFLL;
}

original_code:
static int stats_open (void) {
 if (conf.stats_fp)
  stats_close();
 if (!(conf.stats_fp = fopen(conf.stats_file, "a"))) {
  syslog(3, "Failed to open statistics log file %s: %s", conf.stats_file, strerror((*__errno_location ())));
  return -1;
 }
 return 0;
}

canonical_original_code:
static int stats_open() {
 if (conf.stats_fp)
  stats_close();
 if (!(conf.stats_fp = fopen(conf.stats_file, "a"))) {
  syslog(3, "Failed to open statistics log file %s: %s", conf.stats_file, strerror((*__errno_location ())));
  return -1;
 }
 return 0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
char *v4; // r12
char v5; // al
__int64 v6; // rsi
__int64 v7; // rdi
const char *v8; // rdi
int *v9; // rax
char *v10; // rax
const char *v11; // rdi
char v13[32]; // [rsp+0h] [rbp-238h] BYREF
char v14[536]; // [rsp+20h] [rbp-218h] BYREF

*(_QWORD *)&conf[32] = strdup("/run/kafkatee.pid");
conf[19] = 1;
conf[39] = 0;
conf[22] = 6;
conf[25] = 1;
conf[26] = 60;
*(_QWORD *)&conf[28] = strdup("/tmp/kafkatee.stats.json");
conf[18] = 10240;
*(_QWORD *)conf = strdup("\n");
conf[2] = strlen(*(const char **)conf);
conf[16] = 100000;
v3 = rd_kafka_conf_new();
*(_QWORD *)&conf[42] = v3;
rd_kafka_conf_set(v3, "client.id", "kafkatee", 0LL, 0LL);
((void (__fastcall *)(_QWORD, void (__fastcall *)(__int64, unsigned int, const char *)))rd_kafka_conf_set_error_cb)(
*(_QWORD *)&conf[42],
kafka_error_cb);
*(_QWORD *)&conf[44] = ((__int64 (*)(void))rd_kafka_topic_conf_new)();
v4 = "/etc/kafkatee.conf";
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "hc:p:dDex");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'D':
conf[25] = 0;
break;
case 'c':
v4 = optarg;
break;
case 'd':
conf[22] = 7;
break;
case 'e':
conf[38] |= 1u;
break;
case 'h':
usage(*argv);
case 'p':
*(_QWORD *)&conf[32] = strdup(optarg);
break;
case 'x':
conf[38] |= 2u;
break;
default:
usage(*argv);
}
}
openlog("kafkatee", 33, 24);
if ( (unsigned int)ezd_conf_file_read(v4, &conf_set, v14, 512LL, 0LL) != -1 )
{
if ( conf[25] )
{
if ( (unsigned int)ezd_daemon(10LL, v14, 512LL) == -1 )
{
syslog(3, "%s", v14);
exit(1);
}
if ( (unsigned int)ezd_pidfile_open(*(_QWORD *)&conf[32], v14, 512LL) == -1 )
{
syslog(3, "%s", v14);
exit(1);
}
}
v6 = *(_QWORD *)&conf[14];
if ( v6 )
{
if ( conf[4] )
{
syslog(3, "Output formatting only supported for output.encoding = string");
if ( conf[25] )
ezd_pidfile_close();
exit(1);
}
if ( (unsigned int)format_parse((unsigned int)((_DWORD)conf + 16), v6, v14, 512LL) == -1 )
{
syslog(3, "Failed to parse format string: %s\n%s", *(const char **)&conf[14], v14);
if ( conf[25] )
ezd_pidfile_close();
exit(1);
}
}
if ( conf[26] )
{
if ( (unsigned int)stats_open() == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
syslog(3, "Failed to open statistics log file %s: %s", *(const char **)&conf[28], v10);
if ( conf[25] )
ezd_pidfile_close();
exit(1);
}
snprintf(v13, 0x1EuLL, "%i", (unsigned int)(1000 * conf[26]));
rd_kafka_conf_set_stats_cb(*(_QWORD *)&conf[42], kafka_stats_cb);
rd_kafka_conf_set(*(_QWORD *)&conf[42], "statistics.interval.ms", v13, 0LL, 0LL);
}
v7 = rd_kafka_new(1LL, *(_QWORD *)&conf[42], v14, 512LL);
*(_QWORD *)&conf[40] = v7;
if ( v7 )
{
rd_kafka_set_log_level(v7, (unsigned int)conf[22]);
exec_init();
if ( conf[25] )
ezd_daemon_started();
v8 = *(const char **)&conf[34];
if ( v8 && system(v8) )
syslog(3, "\"command.init\" execution of \"%s\" failed with exit code %i", *(const char **)&conf[34], 1LL);
ezd_thread_sigmask(0LL, 0LL, 0xFFFFFFFFLL);
outputs_start();
inputs_start();
ezd_thread_sigmask(1LL, 1LL, 2LL);
signal(1, (__sighandler_t)sighup);
signal(2, (__sighandler_t)term);
signal(15, (__sighandler_t)term);
syslog(6, "kafkatee starting");
while ( conf[19] )
{
rd_kafka_poll(*(_QWORD *)&conf[40], 1000LL);
if ( conf[21] != our_rotate_version_1 )
{
our_rotate_version_1 = conf[21];
if ( conf[26] )
stats_open();
}
}
inputs_term();
outputs_term();
exec_term();
rd_kafka_destroy(*(_QWORD *)&conf[40]);
rd_kafka_wait_destroyed(5000LL);
if ( *(_QWORD *)&conf[30] )
stats_close();
free(*(void **)&conf[28]);
v11 = *(const char **)&conf[36];
if ( v11 && system(v11) )
syslog(3, "\"command.term\" execution of \"%s\" failed with exit code %i", *(const char **)&conf[36], 1LL);
if ( conf[25] )
ezd_pidfile_close();
syslog(6, "kafkatee exiting");
exit(conf[39]);
}
syslog(3, "Failed to create kafka handle: %s", v14);
if ( conf[25] )
ezd_pidfile_close();
exit(1);
}
syslog(3, "%s", v14);
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
char *v4; // r12
char v5; // al
__int64 v6; // rsi
__int64 v7; // rdi
const char *v8; // rdi
int *v9; // rax
char *v10; // rax
const char *v11; // rdi
char v13[32]; // [rsp+0h] [rbp-238h] BYREF
char v14[536]; // [rsp+20h] [rbp-218h] BYREF

*(_QWORD *)&conf[32] = strdup("/run/kafkatee.pid");
conf[19] = 1;
conf[39] = 0;
conf[22] = 6;
conf[25] = 1;
conf[26] = 60;
*(_QWORD *)&conf[28] = strdup("/tmp/kafkatee.stats.json");
conf[18] = 10240;
*(_QWORD *)conf = strdup("\n");
conf[2] = strlen(*(const char **)conf);
conf[16] = 100000;
v3 = rd_kafka_conf_new();
*(_QWORD *)&conf[42] = v3;
rd_kafka_conf_set(v3, "client.id", "kafkatee", 0LL, 0LL);
((void (__fastcall *)(_QWORD, void (__fastcall *)(__int64, unsigned int, const char *)))rd_kafka_conf_set_error_cb)(
*(_QWORD *)&conf[42],
kafka_error_cb);
*(_QWORD *)&conf[44] = ((__int64 (*)(void))rd_kafka_topic_conf_new)();
v4 = "/etc/kafkatee.conf";
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "hc:p:dDex");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'D':
conf[25] = 0;
break;
case 'c':
v4 = optarg;
break;
case 'd':
conf[22] = 7;
break;
case 'e':
conf[38] |= 1u;
break;
case 'h':
func3(*argv);
case 'p':
*(_QWORD *)&conf[32] = strdup(optarg);
break;
case 'x':
conf[38] |= 2u;
break;
default:
func3(*argv);
}
}
openlog("kafkatee", 33, 24);
if ( (unsigned int)ezd_conf_file_read(v4, &conf_set, v14, 512LL, 0LL) != -1 )
{
if ( conf[25] )
{
if ( (unsigned int)ezd_daemon(10LL, v14, 512LL) == -1 )
{
syslog(3, "%s", v14);
exit(1);
}
if ( (unsigned int)ezd_pidfile_open(*(_QWORD *)&conf[32], v14, 512LL) == -1 )
{
syslog(3, "%s", v14);
exit(1);
}
}
v6 = *(_QWORD *)&conf[14];
if ( v6 )
{
if ( conf[4] )
{
syslog(3, "Output formatting only supported for output.encoding = string");
if ( conf[25] )
ezd_pidfile_close();
exit(1);
}
if ( (unsigned int)format_parse((unsigned int)((_DWORD)conf + 16), v6, v14, 512LL) == -1 )
{
syslog(3, "Failed to parse format string: %s\n%s", *(const char **)&conf[14], v14);
if ( conf[25] )
ezd_pidfile_close();
exit(1);
}
}
if ( conf[26] )
{
if ( (unsigned int)func6() == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
syslog(3, "Failed to open statistics log file %s: %s", *(const char **)&conf[28], v10);
if ( conf[25] )
ezd_pidfile_close();
exit(1);
}
snprintf(v13, 0x1EuLL, "%i", (unsigned int)(1000 * conf[26]));
rd_kafka_conf_set_stats_cb(*(_QWORD *)&conf[42], kafka_stats_cb);
rd_kafka_conf_set(*(_QWORD *)&conf[42], "statistics.interval.ms", v13, 0LL, 0LL);
}
v7 = rd_kafka_new(1LL, *(_QWORD *)&conf[42], v14, 512LL);
*(_QWORD *)&conf[40] = v7;
if ( v7 )
{
rd_kafka_set_log_level(v7, (unsigned int)conf[22]);
exec_init();
if ( conf[25] )
ezd_daemon_started();
v8 = *(const char **)&conf[34];
if ( v8 && system(v8) )
syslog(3, "\"command.init\" execution of \"%s\" failed with exit code %i", *(const char **)&conf[34], 1LL);
ezd_thread_sigmask(0LL, 0LL, 0xFFFFFFFFLL);
outputs_start();
inputs_start();
ezd_thread_sigmask(1LL, 1LL, 2LL);
signal(1, (__sighandler_t)sighup);
signal(2, (__sighandler_t)term);
signal(15, (__sighandler_t)term);
syslog(6, "kafkatee starting");
while ( conf[19] )
{
rd_kafka_poll(*(_QWORD *)&conf[40], 1000LL);
if ( conf[21] != our_rotate_version_1 )
{
our_rotate_version_1 = conf[21];
if ( conf[26] )
func6();
}
}
inputs_term();
outputs_term();
exec_term();
rd_kafka_destroy(*(_QWORD *)&conf[40]);
rd_kafka_wait_destroyed(5000LL);
if ( *(_QWORD *)&conf[30] )
func5();
free(*(void **)&conf[28]);
v11 = *(const char **)&conf[36];
if ( v11 && system(v11) )
syslog(3, "\"command.term\" execution of \"%s\" failed with exit code %i", *(const char **)&conf[36], 1LL);
if ( conf[25] )
ezd_pidfile_close();
syslog(6, "kafkatee exiting");
exit(conf[39]);
}
syslog(3, "Failed to create kafka handle: %s", v14);
if ( conf[25] )
ezd_pidfile_close();
exit(1);
}
syslog(3, "%s", v14);
exit(1);
}

original_code:
int main (int argc, char **argv) {
 const char *conf_file_path = "/etc/kafkatee.conf";
 char errstr[512];
 char c;
 int r;
 static int our_rotate_version = 0;
 conf.pid_file_path = strdup("/run/kafkatee.pid");
 conf.run = 1;
 conf.exit_code = 0;
 conf.log_level = 6;
 conf.daemonize = 1;
 conf.stats_interval = 60;
 conf.stats_file = strdup("/tmp/kafkatee.stats.json");
 conf.input_buf_size = 1024 * 10;
 conf.output_delimiter = strdup("\n");
 conf.output_delimiter_len = strlen(conf.output_delimiter);
 conf.output_queue_size = 100000;
 conf.rk_conf = rd_kafka_conf_new();
 rd_kafka_conf_set(conf.rk_conf, "client.id", "kafkatee", ((void *)0), 0);
 rd_kafka_conf_set_error_cb(conf.rk_conf, kafka_error_cb);
 conf.rkt_conf = rd_kafka_topic_conf_new();
 while ((c = getopt(argc, argv, "hc:p:dDex")) != -1) {
  switch (c) {
  case 'h':
   usage(argv[0]);
   break;
  case 'c':
   conf_file_path = optarg;
   break;
  case 'p':
   conf.pid_file_path = strdup(optarg);
   break;
  case 'd':
   conf.log_level = 7;
   break;
  case 'D':
   conf.daemonize = 0;
   break;
  case 'e':
   conf.flags |= 0x1;
   break;
  case 'x':
   conf.flags |= 0x2;
   break;
  default:
   usage(argv[0]);
   break;
  }
 }
 openlog("kafkatee", 0x01|0x20, (3<<3));
 if (ezd_conf_file_read(conf_file_path, conf_set,
          errstr, sizeof(errstr), ((void *)0)) == -1) {
  syslog(3, "%s", errstr);
  exit(1);
 }
 if (conf.daemonize) {
  if (ezd_daemon(10, errstr, sizeof(errstr)) == -1) {
   syslog(3, "%s", errstr);
   exit(1);
  }
  if (ezd_pidfile_open(conf.pid_file_path,
         errstr, sizeof(errstr)) == -1) {
   syslog(3, "%s", errstr);
   exit(1);
  }
 }
 if (conf.fconf.format) {
  if (conf.fconf.encoding != ENC_STRING) {
   syslog(3, "Output formatting only supported for " "output.encoding = string");
   if (conf.daemonize)
    ezd_pidfile_close();
   exit(1);
  }
  if (format_parse(&conf.fconf, conf.fconf.format,
     errstr, sizeof(errstr)) == -1) {
   syslog(3, "Failed to parse format string: %s\n%s", conf.fconf.format, errstr);
   if (conf.daemonize)
    ezd_pidfile_close();
   exit(1);
  }
 }
 if (conf.stats_interval) {
  char tmp[30];
  if (stats_open() == -1) {
   syslog(3, "Failed to open statistics log file %s: %s", conf.stats_file, strerror((*__errno_location ())));
   if (conf.daemonize)
    ezd_pidfile_close();
   exit(1);
  }
  snprintf(tmp, sizeof(tmp), "%i", conf.stats_interval*1000);
  rd_kafka_conf_set_stats_cb(conf.rk_conf, kafka_stats_cb);
  rd_kafka_conf_set(conf.rk_conf, "statistics.interval.ms", tmp,
      ((void *)0), 0);
 }
 if (!(conf.rk = rd_kafka_new(RD_KAFKA_CONSUMER, conf.rk_conf,
         errstr, sizeof(errstr)))) {
  syslog(3, "Failed to create kafka handle: %s", errstr);
  if (conf.daemonize)
   ezd_pidfile_close();
  exit(1);
 }
 rd_kafka_set_log_level(conf.rk, conf.log_level);
 exec_init();
 if (conf.daemonize)
  ezd_daemon_started();
 if (conf.cmd_init) {
  if ((r = system(conf.cmd_init) != 0))
   syslog(3, "\"command.init\" execution of \"%s\" failed " "with exit code %i", conf.cmd_init, r);
 }
 ezd_thread_sigmask(0, 0 , -1 );
 outputs_start();
 inputs_start();
 ezd_thread_sigmask(1, 1, 2, 15, -1);
 signal(1, sighup);
 signal(2, term);
 signal(15, term);
 syslog(6, "kafkatee starting");
 while (conf.run) {
  rd_kafka_poll(conf.rk, 1000);
  if (__builtin_expect((conf.rotate != our_rotate_version),0)) {
   our_rotate_version = conf.rotate;
   if (conf.stats_interval)
    stats_open();
  }
 }
 inputs_term();
 outputs_term();
 exec_term();
 rd_kafka_destroy(conf.rk);
 rd_kafka_wait_destroyed(5000);
 if (conf.stats_fp)
  stats_close();
 free(conf.stats_file);
 if (conf.cmd_term) {
  if ((r = system(conf.cmd_term) != 0))
   syslog(3, "\"command.term\" execution of \"%s\" failed " "with exit code %i", conf.cmd_term, r);
 }
 if (conf.daemonize)
  ezd_pidfile_close();
 syslog(6, "kafkatee exiting");
 exit(conf.exit_code);
}

canonical_original_code:
int main(int argc, char **argv) {
 char *conf_file_path = "/etc/kafkatee.conf";
 char errstr[512];
 char c;
 int r;
 static int our_rotate_version = 0;
 conf.pid_file_path = strdup("/run/kafkatee.pid");
 conf.run = 1;
 conf.exit_code = 0;
 conf.log_level = 6;
 conf.daemonize = 1;
 conf.stats_interval = 60;
 conf.stats_file = strdup("/tmp/kafkatee.stats.json");
 conf.input_buf_size = 1024 * 10;
 conf.output_delimiter = strdup("\n");
 conf.output_delimiter_len = strlen(conf.output_delimiter);
 conf.output_queue_size = 100000;
 conf.rk_conf = rd_kafka_conf_new();
 rd_kafka_conf_set(conf.rk_conf, "client.id", "kafkatee", ((void *)0), 0);
 rd_kafka_conf_set_error_cb(conf.rk_conf, kafka_error_cb);
 conf.rkt_conf = rd_kafka_topic_conf_new();
 while ((c = getopt(argc, argv, "hc:p:dDex")) != -1) {
  switch (c) {
  case 'h':
   usage(argv[0]);
   break;
  case 'c':
   conf_file_path = optarg;
   break;
  case 'p':
   conf.pid_file_path = strdup(optarg);
   break;
  case 'd':
   conf.log_level = 7;
   break;
  case 'D':
   conf.daemonize = 0;
   break;
  case 'e':
   conf.flags |= 0x1;
   break;
  case 'x':
   conf.flags |= 0x2;
   break;
  default:
   usage(argv[0]);
   break;
  }
 }
 openlog("kafkatee", 0x01|0x20, (3<<3));
 if (ezd_conf_file_read(conf_file_path, conf_set,
          errstr, sizeof(errstr), ((void *)0)) == -1) {
  syslog(3, "%s", errstr);
  exit(1);
 }
 if (conf.daemonize) {
  if (ezd_daemon(10, errstr, sizeof(errstr)) == -1) {
   syslog(3, "%s", errstr);
   exit(1);
  }
  if (ezd_pidfile_open(conf.pid_file_path,
         errstr, sizeof(errstr)) == -1) {
   syslog(3, "%s", errstr);
   exit(1);
  }
 }
 if (conf.fconf.format) {
  if (conf.fconf.encoding != ENC_STRING) {
   syslog(3, "Output formatting only supported for " "output.encoding = string");
   if (conf.daemonize)
    ezd_pidfile_close();
   exit(1);
  }
  if (format_parse(&conf.fconf, conf.fconf.format,
     errstr, sizeof(errstr)) == -1) {
   syslog(3, "Failed to parse format string: %s\n%s", conf.fconf.format, errstr);
   if (conf.daemonize)
    ezd_pidfile_close();
   exit(1);
  }
 }
 if (conf.stats_interval) {
  char tmp[30];
  if (stats_open() == -1) {
   syslog(3, "Failed to open statistics log file %s: %s", conf.stats_file, strerror((*__errno_location ())));
   if (conf.daemonize)
    ezd_pidfile_close();
   exit(1);
  }
  snprintf(tmp, sizeof(tmp), "%i", conf.stats_interval*1000);
  rd_kafka_conf_set_stats_cb(conf.rk_conf, kafka_stats_cb);
  rd_kafka_conf_set(conf.rk_conf, "statistics.interval.ms", tmp,
      ((void *)0), 0);
 }
 if (!(conf.rk = rd_kafka_new(RD_KAFKA_CONSUMER, conf.rk_conf,
         errstr, sizeof(errstr)))) {
  syslog(3, "Failed to create kafka handle: %s", errstr);
  if (conf.daemonize)
   ezd_pidfile_close();
  exit(1);
 }
 rd_kafka_set_log_level(conf.rk, conf.log_level);
 exec_init();
 if (conf.daemonize)
  ezd_daemon_started();
 if (conf.cmd_init) {
  if ((r = system(conf.cmd_init) != 0))
   syslog(3, "\"command.init\" execution of \"%s\" failed " "with exit code %i", conf.cmd_init, r);
 }
 ezd_thread_sigmask(0, 0 , -1 );
 outputs_start();
 inputs_start();
 ezd_thread_sigmask(1, 1, 2, 15, -1);
 signal(1, sighup);
 signal(2, term);
 signal(15, term);
 syslog(6, "kafkatee starting");
 while (conf.run) {
  rd_kafka_poll(conf.rk, 1000);
  if (__builtin_expect((conf.rotate != our_rotate_version),0)) {
   our_rotate_version = conf.rotate;
   if (conf.stats_interval)
    stats_open();
  }
 }
 inputs_term();
 outputs_term();
 exec_term();
 rd_kafka_destroy(conf.rk);
 rd_kafka_wait_destroyed(5000);
 if (conf.stats_fp)
  stats_close();
 free(conf.stats_file);
 if (conf.cmd_term) {
  if ((r = system(conf.cmd_term) != 0))
   syslog(3, "\"command.term\" execution of \"%s\" failed " "with exit code %i", conf.cmd_term, r);
 }
 if (conf.daemonize)
  ezd_pidfile_close();
 syslog(6, "kafkatee exiting");
 exit(conf.exit_code);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
errstr
char [512]

variable_types: c char

variable_types: r int

variable_types:
tmp
char [30]


decompiled_code:
void do_timeout()
{
run = 0;
fclose(stdin);
}

canonical_decompiled_code:
void func7()
{
run = 0;
fclose(stdin);
}

original_code:
static void do_timeout (int sig) {
 run = 0;
 fclose(stdin);
}

canonical_original_code:
static void do_timeout(int sig) {
 run = 0;
 fclose(stdin);
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
int v5; // er13
unsigned int v6; // ebx
int v7; // ebp
char v8[4136]; // [rsp+0h] [rbp-1028h] BYREF

if ( argc <= 2 )
{
printf("Usage: %s <expected-number-of-lines-to-read> <timeout> [<sleep-time-after-expected-reached>]\n", *argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
alarm(v4);
signal(14, (__sighandler_t)do_timeout);
v5 = 5;
if ( argc == 4 )
v5 = atoi(argv[3]);
v6 = run;
if ( run )
{
v7 = 0;
v6 = 0;
do
{
if ( !fgets(v8, 4095, stdin) )
break;
if ( v3 <= (int)++v6 )
{
if ( v7 )
{
if ( time(0LL) >= v7 )
break;
}
else
{
v7 = v5 + time(0LL);
}
}
}
while ( run );
}
printf("%i lines read, %i expected\n", v6, (unsigned int)v3);
if ( v6 != v3 )
exit(2);
exit(0);
}

original_code:
int main (int argc, char **argv) {
 int cnt = 0;
 int expected;
 int sleeptime = 5;
 int endtime = 0;
 char buf[4096];
 if (argc < 3) {
  printf("Usage: %s <expected-number-of-lines-to-read> "
         " <timeout> "
         " [<sleep-time-after-expected-reached>]\n", argv[0]);
  exit(1);
 }
 expected = atoi(argv[1]);
 alarm(atoi(argv[2]));
 signal(14, do_timeout);
 if (argc == 4)
  sleeptime = atoi(argv[3]);
 while (run && fgets(buf, sizeof(buf)-1, stdin)) {
  cnt++;
  if (cnt >= expected) {
   if (!endtime)
    endtime = time(((void *)0)) + sleeptime;
   else if (time(((void *)0)) >= endtime)
    break;
  }
 }
 printf("%i lines read, %i expected\n", cnt, expected);
 if (cnt == expected)
  exit(0);
 else
  exit(2);
}

canonical_original_code:
int main(int argc, char **argv) {
 int cnt = 0;
 int expected;
 int sleeptime = 5;
 int endtime = 0;
 char buf[4096];
 if (argc < 3) {
  printf("Usage: %s <expected-number-of-lines-to-read> "
         " <timeout> "
         " [<sleep-time-after-expected-reached>]\n", argv[0]);
  exit(1);
 }
 expected = atoi(argv[1]);
 alarm(atoi(argv[2]));
 signal(14, do_timeout);
 if (argc == 4)
  sleeptime = atoi(argv[3]);
 while (run && fgets(buf, sizeof(buf)-1, stdin)) {
  cnt++;
  if (cnt >= expected) {
   if (!endtime)
    endtime = time(((void *)0)) + sleeptime;
   else if (time(((void *)0)) >= endtime)
    break;
  }
 }
 printf("%i lines read, %i expected\n", cnt, expected);
 if (cnt == expected)
  exit(0);
 else
  exit(2);
}

variable_types: cnt int

variable_types: expected int

variable_types: sleeptime int

variable_types: endtime int

variable_types:
buf
char [4096]


repo: willcast/nsboot

decompiled_code:
__int64 __fastcall ts_open(const char *a1)
{
unsigned int v1; // edx
int *v3; // rax
char *v4; // rax

ts_fd = open(a1, 0);
v1 = 0;
if ( ts_fd < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
logprintf("2%s: %s", "error opening touchscreen event device", v4);
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v1; // edx
int *v3; // rax
char *v4; // rax

ts_fd = open(a1, 0);
v1 = 0;
if ( ts_fd < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
logprintf("2%s: %s", "error opening touchscreen event device", v4);
v1 = 1;
}
return v1;
}

original_code:
int ts_open(char *dev_file) {
 ts_fd = open(dev_file, 00);
 if (ts_fd < 0) {
  logprintf("2%s: %s", "error opening touchscreen event device", strerror((*__errno_location ())));
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall gpio_keys_open(const char *a1)
{
unsigned int v1; // edx
int *v3; // rax
char *v4; // rax

gpio_keys_fd = open(a1, 0);
v1 = 0;
if ( gpio_keys_fd < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
logprintf("2%s: %s", "error opening GPIO key event device", v4);
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
unsigned int v1; // edx
int *v3; // rax
char *v4; // rax

gpio_keys_fd = open(a1, 0);
v1 = 0;
if ( gpio_keys_fd < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
logprintf("2%s: %s", "error opening GPIO key event device", v4);
v1 = 1;
}
return v1;
}

original_code:
int gpio_keys_open(char *dev_file) {
 gpio_keys_fd = open(dev_file, 00);
 if (gpio_keys_fd < 0) {
  logprintf("2%s: %s", "error opening GPIO key event device", strerror((*__errno_location ())));
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall pmic_keys_open(const char *a1)
{
unsigned int v1; // edx
int *v3; // rax
char *v4; // rax

pmic_keys_fd = open(a1, 1);
v1 = 0;
if ( pmic_keys_fd < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
logprintf("2%s: %s", "error opening PMIC key event device", v4);
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
unsigned int v1; // edx
int *v3; // rax
char *v4; // rax

pmic_keys_fd = open(a1, 1);
v1 = 0;
if ( pmic_keys_fd < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
logprintf("2%s: %s", "error opening PMIC key event device", v4);
v1 = 1;
}
return v1;
}

original_code:
int pmic_keys_open(char *dev_file) {
 pmic_keys_fd = open(dev_file, 01);
 if (pmic_keys_fd < 0) {
  logprintf("2%s: %s", "error opening PMIC key event device", strerror((*__errno_location ())));
  return 1;
 }
 return 0;
}


decompiled_code:
int __fastcall vibrator_open(const char *a1)
{
int result; // eax
int *v2; // rax
char *v3; // rax

result = open(a1, 1);
vibrator_fd = result;
if ( result < 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
result = logprintf("2%s: %s", "error opening vibrator sysfs file", v3);
}
else
{
vibrator_usable = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(const char *a1)
{
int result; // eax
int *v2; // rax
char *v3; // rax

result = open(a1, 1);
vibrator_fd = result;
if ( result < 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
result = logprintf("2%s: %s", "error opening vibrator sysfs file", v3);
}
else
{
vibrator_usable = 1;
}
return result;
}

original_code:
void vibrator_open(char *dev_file) {
 vibrator_fd = open(dev_file, 01);
 if (vibrator_fd < 0)
  logprintf("2%s: %s", "error opening vibrator sysfs file", strerror((*__errno_location ())));
 else
  vibrator_usable = 1;
}


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

if ( ts_usable )
{
result = close(ts_fd);
ts_usable = 0;
}
return result;
}

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

if ( ts_usable )
{
result = close(ts_fd);
ts_usable = 0;
}
return result;
}

original_code:
void ts_close(void) {
 if (ts_usable) {
  close(ts_fd);
  ts_usable = 0;
 }
}

canonical_original_code:
void ts_close() {
 if (ts_usable) {
  close(ts_fd);
  ts_usable = 0;
 }
}


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

if ( gpio_keys_usable )
{
result = close(gpio_keys_fd);
gpio_keys_usable = 0;
}
return result;
}

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

if ( gpio_keys_usable )
{
result = close(gpio_keys_fd);
gpio_keys_usable = 0;
}
return result;
}

original_code:
void gpio_keys_close(void) {
 if (gpio_keys_usable) {
  close(gpio_keys_fd);
  gpio_keys_usable = 0;
 }
}

canonical_original_code:
void gpio_keys_close() {
 if (gpio_keys_usable) {
  close(gpio_keys_fd);
  gpio_keys_usable = 0;
 }
}


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

if ( pmic_keys_usable )
{
result = close(pmic_keys_fd);
pmic_keys_usable = 0;
}
return result;
}

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

if ( pmic_keys_usable )
{
result = close(pmic_keys_fd);
pmic_keys_usable = 0;
}
return result;
}

original_code:
void pmic_keys_close(void) {
 if (pmic_keys_usable) {
  close(pmic_keys_fd);
  pmic_keys_usable = 0;
 }
}

canonical_original_code:
void pmic_keys_close() {
 if (pmic_keys_usable) {
  close(pmic_keys_fd);
  pmic_keys_usable = 0;
 }
}


decompiled_code:
__int64 input_close()
{
ts_close();
gpio_keys_close();
pmic_keys_close();
return qfprintf("/sys/devices/platform/cy8ctma395/vdd", "0");
}

canonical_decompiled_code:
__int64 func8()
{
func5();
func6();
func7();
return qfprintf("/sys/devices/platform/cy8ctma395/vdd", "0");
}

original_code:
void input_close(void) {
 ts_close();
 gpio_keys_close();
 pmic_keys_close();
 qfprintf("/sys/devices/platform/cy8ctma395/vdd", "0");
}

canonical_original_code:
void input_close() {
 ts_close();
 gpio_keys_close();
 pmic_keys_close();
 qfprintf("/sys/devices/platform/cy8ctma395/vdd", "0");
}


decompiled_code:
__int64 __fastcall input_open(const char *a1)
{
int v1; // er12
char *v2; // rax
char *v3; // rbx
char *v4; // rax
char *v5; // rbx
char *v6; // rax
char *v7; // rbx
__int64 result; // rax
char v9[4120]; // [rsp+0h] [rbp-1018h] BYREF

v1 = 0;
while ( 1 )
{
usleep(0x51615u);
logprintf("0locating touch screen (attempt %d)", (unsigned int)++v1);
v2 = name_to_event_dev("HPTouchpad");
v3 = v2;
if ( v2 )
break;
if ( v1 == 5 )
{
logprintf("3unable to detect touch screen!");
goto LABEL_7;
}
}
snprintf(v9, 0x1000uLL, "%s/%s", a1, v2);
free(v3);
logprintf("0trying to open touch screen at %s", v9);
if ( !(unsigned int)ts_open(v9) )
ts_usable = 1;
LABEL_7:
v4 = name_to_event_dev("gpio-keys");
v5 = v4;
if ( v4 )
{
snprintf(v9, 0x1000uLL, "%s/%s", a1, v4);
free(v5);
logprintf("0trying to open GPIO keys at %s", v9);
if ( !(unsigned int)gpio_keys_open(v9) )
gpio_keys_usable = 1;
}
else
{
logprintf("3unable to detect GPIO keys!");
}
v6 = name_to_event_dev("pmic8058_pwrkey");
v7 = v6;
if ( v6 )
{
snprintf(v9, 0x1000uLL, "%s/%s", a1, v6);
free(v7);
logprintf("0trying to open PMIC keys at %s", v9);
if ( !(unsigned int)pmic_keys_open(v9) )
pmic_keys_usable = 1;
}
else
{
logprintf("3unable to detect PMIC keys!");
}
if ( ts_usable || gpio_keys_usable && pmic_keys_usable )
{
last_input = 0uLL;
*((_QWORD *)&last_input + 2) = 0LL;
*((_QWORD *)&last_input + 3) = 0LL;
cur_input = 0uLL;
*((_QWORD *)&cur_input + 2) = 0LL;
*((_QWORD *)&cur_input + 3) = 0LL;
diff_input = 0LL;
*(&diff_input + 1) = 0LL;
*(&diff_input + 2) = 0LL;
*(&diff_input + 3) = 0LL;
result = 0LL;
}
else
{
logprintf("3no usable input devices!");
input_close();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
int v1; // er12
char *v2; // rax
char *v3; // rbx
char *v4; // rax
char *v5; // rbx
char *v6; // rax
char *v7; // rbx
__int64 result; // rax
char v9[4120]; // [rsp+0h] [rbp-1018h] BYREF

v1 = 0;
while ( 1 )
{
usleep(0x51615u);
logprintf("0locating touch screen (attempt %d)", (unsigned int)++v1);
v2 = func0("HPTouchpad");
v3 = v2;
if ( v2 )
break;
if ( v1 == 5 )
{
logprintf("3unable to detect touch screen!");
goto LABEL_7;
}
}
snprintf(v9, 0x1000uLL, "%s/%s", a1, v2);
free(v3);
logprintf("0trying to open touch screen at %s", v9);
if ( !(unsigned int)func1(v9) )
ts_usable = 1;
LABEL_7:
v4 = func0("gpio-keys");
v5 = v4;
if ( v4 )
{
snprintf(v9, 0x1000uLL, "%s/%s", a1, v4);
free(v5);
logprintf("0trying to open GPIO keys at %s", v9);
if ( !(unsigned int)func2(v9) )
gpio_keys_usable = 1;
}
else
{
logprintf("3unable to detect GPIO keys!");
}
v6 = func0("pmic8058_pwrkey");
v7 = v6;
if ( v6 )
{
snprintf(v9, 0x1000uLL, "%s/%s", a1, v6);
free(v7);
logprintf("0trying to open PMIC keys at %s", v9);
if ( !(unsigned int)func3(v9) )
pmic_keys_usable = 1;
}
else
{
logprintf("3unable to detect PMIC keys!");
}
if ( ts_usable || gpio_keys_usable && pmic_keys_usable )
{
last_input = 0uLL;
*((_QWORD *)&last_input + 2) = 0LL;
*((_QWORD *)&last_input + 3) = 0LL;
cur_input = 0uLL;
*((_QWORD *)&cur_input + 2) = 0LL;
*((_QWORD *)&cur_input + 3) = 0LL;
diff_input = 0LL;
*(&diff_input + 1) = 0LL;
*(&diff_input + 2) = 0LL;
*(&diff_input + 3) = 0LL;
result = 0LL;
}
else
{
logprintf("3no usable input devices!");
func8();
result = 1LL;
}
return result;
}

original_code:
int input_open(char *uinput_dir) {
 char dev_path[4096];
 char *dev_name = ((void *)0);
 int attempt;
 for (attempt = 0; attempt < 5; ++attempt) {
  usleep(333333);
  logprintf("0locating touch screen (attempt %d)", attempt + 1);
  dev_name = name_to_event_dev("HPTouchpad");
  if (dev_name != ((void *)0))
   break;
 }
 if (attempt == 5) {
  logprintf("3unable to detect touch screen!");
 } else {
  snprintf(dev_path, sizeof(dev_path), "%s/%s", uinput_dir, dev_name);
  free(dev_name);
  logprintf("0trying to open touch screen at %s", dev_path);
  if (!ts_open(dev_path))
   ts_usable = 1;
 }
 dev_name = name_to_event_dev("gpio-keys");
 if (dev_name == ((void *)0)) {
  logprintf("3unable to detect GPIO keys!");
 } else {
  snprintf(dev_path, sizeof(dev_path), "%s/%s", uinput_dir, dev_name);
  free(dev_name);
  logprintf("0trying to open GPIO keys at %s", dev_path);
  if (!gpio_keys_open(dev_path))
   gpio_keys_usable = 1;
 }
 dev_name = name_to_event_dev("pmic8058_pwrkey");
 if (dev_name == ((void *)0)) {
  logprintf("3unable to detect PMIC keys!");
 } else {
  snprintf(dev_path, sizeof(dev_path), "%s/%s", uinput_dir, dev_name);
  free(dev_name);
  logprintf("0trying to open PMIC keys at %s", dev_path);
  if (!pmic_keys_open(dev_path))
   pmic_keys_usable = 1;
 }
 if (!ts_usable && !(gpio_keys_usable && pmic_keys_usable)) {
  logprintf("3no usable input devices!");
  input_close();
  return 1;
 }
 memset(&last_input, 0, sizeof(last_input));
 memset(&cur_input, 0, sizeof(last_input));
 memset(&diff_input, 0, sizeof(last_input));
 return 0;
}

variable_types: attempt int


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

if ( vibrator_usable )
{
result = close(vibrator_fd);
vibrator_usable = 0;
}
return result;
}

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

if ( vibrator_usable )
{
result = close(vibrator_fd);
vibrator_usable = 0;
}
return result;
}

original_code:
void vibrator_close(void) {
 if (vibrator_usable) {
  close(vibrator_fd);
  vibrator_usable = 0;
 }
}

canonical_original_code:
void vibrator_close() {
 if (vibrator_usable) {
  close(vibrator_fd);
  vibrator_usable = 0;
 }
}


vibrate

decompiled_code:
void __fastcall vibrate(unsigned int a1)
{
int *v1; // rax
char *v2; // rax
char s[16]; // [rsp+0h] [rbp-10h] BYREF

if ( vibrator_usable )
{
snprintf(s, 8uLL, "%d\n", a1);
if ( write(vibrator_fd, s, 8uLL) <= 1 )
{
v1 = _errno_location();
v2 = strerror(*v1);
logprintf("2%s: %s", "can't write to vibrator", v2);
}
}
}

canonical_decompiled_code:
void __fastcall func14(unsigned int a1)
{
int *v1; // rax
char *v2; // rax
char s[16]; // [rsp+0h] [rbp-10h] BYREF

if ( vibrator_usable )
{
snprintf(s, 8uLL, "%d\n", a1);
if ( write(vibrator_fd, s, 8uLL) <= 1 )
{
v1 = _errno_location();
v2 = strerror(*v1);
logprintf("2%s: %s", "can't write to vibrator", v2);
}
}
}

original_code:
void vibrate(int ms) {
 char str_ms[8];
 if (!vibrator_usable)
  return;
 snprintf(str_ms, sizeof(str_ms), "%d\n", ms);
 if (write(vibrator_fd, str_ms, 8) < 2)
  logprintf("2%s: %s", "can't write to vibrator", strerror((*__errno_location ())));
}

variable_types: ms int