main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
struct sigaction v4; // [rsp+0h] [rbp-F8h] BYREF
struct sigevent evp; // [rsp+A0h] [rbp-58h] BYREF
int v6; // [rsp+ECh] [rbp-Ch]

v6 = 0;
evp.sigev_value.sival_ptr = 0LL;
*(_QWORD *)&evp.sigev_signo = 0LL;
*(_OWORD *)evp._sigev_un._pad = 0uLL;
*((_OWORD *)&evp._sigev_un._sigev_thread + 1) = 0uLL;
*((_OWORD *)&evp._sigev_un._sigev_thread + 2) = 0uLL;
memset(&v4, 0, sizeof(v4));
fd_gpio = open("/sys/class/gpio/gpio38/value", 1052674, envp);
if ( fd_gpio < 0 )
perror("open");
evp.sigev_signo = 10;
evp.sigev_notify = 0;
v4.sa_handler = (__sighandler_t)timer_on_handler;
if ( sigaction(10, &v4, 0LL) == -1 )
perror("sigaction");
if ( timer_create(0, &evp, &on_timer) == -1 )
perror("timer_create");
new_time.it_interval.tv_nsec = time_on;
new_time.it_value.tv_nsec = time_on;
if ( timer_settime(on_timer, 0, &new_time, &old_time) == -1 )
perror("timer_setttime");
printf("Finished setting timer, starting PWM at 50 percent. Enter new val 1-100 for");
while ( 1 )
{
__isoc99_scanf();
if ( (unsigned int)(v6 - 1) <= 0x63 )
{
v3 = pthread_mutex_lock(&mtx);
gpio_val = 1;
if ( v3 )
perror("pthread_mutex_lock");
time_on = (unsigned int)(int)((double)v6 / 100.0 * 1000000.0);
time_off = (unsigned int)(int)((1.0 - (double)v6 / 100.0) * 1000000.0);
if ( timer_settime(on_timer, 0, &new_time, &old_time) == -1 )
perror("timer_setttime");
if ( pthread_mutex_unlock(&mtx) )
perror("pthread_mutex_unlock");
}
v6 = 0;
}
}

original_code:
int main ()
{
    char user_input[10]= {0};
    int user_val = 0, ret_val = 0;
    struct timespec res;
    struct sigevent on_event = {0};
    struct sigaction on_action = {0};
    fd_gpio = open("/sys/class/gpio/gpio38/value",02 | 04010000);
    if ( fd_gpio < 0)
       perror("open");
    on_event.sigev_signo = 10;
    on_event.sigev_notify = SIGEV_SIGNAL;
    on_action.__sigaction_handler.sa_handler = timer_on_handler;
    if(-1 == sigaction(10,&on_action,((void *)0)))
        perror("sigaction");
    if (-1 == timer_create(0 ,&on_event, &on_timer))
        perror("timer_create");
    new_time.it_interval.tv_nsec = time_on;
    new_time.it_value.tv_nsec = time_on;
    if (-1 == timer_settime(on_timer, 0, &new_time,&old_time))
        perror("timer_setttime");
    printf("Finished setting timer, starting PWM at 50 percent. Enter new val 1-100 for",
   "new modulation value\n");
    while (1)
    {
        scanf("%d",&user_val);
        if (0 < user_val && user_val <= 100)
        {
   ret_val = pthread_mutex_lock(&mtx);
   gpio_val = 1;
   if (0 != ret_val)
    perror("pthread_mutex_lock");
            if(0)printf("User val is %d\n",user_val);
            time_on = (unsigned int)(1000000.0 * (user_val/100.0));
            time_off = (unsigned int)(1000000.0 * (1 - user_val/100.0));
            if(0)printf("Calculated time periods time_on: %lu, time_off %lu\n",time_on,time_off);
            if (-1 == timer_settime(on_timer, 0, &new_time,&old_time))
                perror("timer_setttime");
   ret_val = pthread_mutex_unlock(&mtx);
   if (0 != ret_val)
    perror("pthread_mutex_unlock");
        }
        user_val = 0;
    };
    return 0;
}

canonical_original_code:
int main()
{
    char user_input[10] = {0};
    int user_val = 0; int ret_val = 0;
    struct timespec res;
    struct sigevent on_event = {0};
    struct sigaction on_action = {0};
    fd_gpio = open("/sys/class/gpio/gpio38/value",02 | 04010000);
    if ( fd_gpio < 0)
       perror("open");
    on_event.sigev_signo = 10;
    on_event.sigev_notify = SIGEV_SIGNAL;
    on_action.__sigaction_handler.sa_handler = timer_on_handler;
    if(-1 == sigaction(10,&on_action,((void *)0)))
        perror("sigaction");
    if (-1 == timer_create(0 ,&on_event, &on_timer))
        perror("timer_create");
    new_time.it_interval.tv_nsec = time_on;
    new_time.it_value.tv_nsec = time_on;
    if (-1 == timer_settime(on_timer, 0, &new_time,&old_time))
        perror("timer_setttime");
    printf("Finished setting timer, starting PWM at 50 percent. Enter new val 1-100 for",
   "new modulation value\n");
    while (1)
    {
        scanf("%d",&user_val);
        if (0 < user_val && user_val <= 100)
        {
   ret_val = pthread_mutex_lock(&mtx);
   gpio_val = 1;
   if (0 != ret_val)
    perror("pthread_mutex_lock");
            if(0)printf("User val is %d\n",user_val);
            time_on = (unsigned int)(1000000.0 * (user_val/100.0));
            time_off = (unsigned int)(1000000.0 * (1 - user_val/100.0));
            if(0)printf("Calculated time periods time_on: %lu, time_off %lu\n",time_on,time_off);
            if (-1 == timer_settime(on_timer, 0, &new_time,&old_time))
                perror("timer_setttime");
   ret_val = pthread_mutex_unlock(&mtx);
   if (0 != ret_val)
    perror("pthread_mutex_unlock");
        }
        user_val = 0;
    };
    return 0;
}

variable_types: struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; }

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)(); }

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }

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; }


repo: addisonw/mrsync-mac

decompiled_code:
__int64 __fastcall init_missingPages(int a1)
{
int v1; // ebx
__int64 v2; // rax

nPages = a1;
if ( missingPages )
free(missingPages);
v1 = nPages;
missingPages = malloc(nPages);
if ( v1 > 0 )
{
v2 = 0LL;
do
*((_BYTE *)missingPages + v2++) = 0;
while ( nPages > (int)v2 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ebx
__int64 v2; // rax

nPages = a1;
if ( missingPages )
free(missingPages);
v1 = nPages;
missingPages = malloc(nPages);
if ( v1 > 0 )
{
v2 = 0LL;
do
*((_BYTE *)missingPages + v2++) = 0;
while ( nPages > (int)v2 );
}
return 0LL;
}

original_code:
int init_missingPages(int n)
{
  int i;
  nPages = n;
  if (missingPages != ((void *)0)) free(missingPages);
  missingPages = malloc(sizeof(char) * nPages);
  for(i=0; i < nPages; ++i)
    missingPages[i] = '\0';
  return 0;
}

variable_types: n int

variable_types: i int

return_type: int


decompiled_code:
__int64 get_total_pages()
{
return (unsigned int)nPages;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)nPages;
}

original_code:
int get_total_pages()
{
  return nPages;
}


decompiled_code:
__int64 missing_pages()
{
_BYTE *v0; // rax
unsigned int v1; // edx

if ( nPages <= 0 )
return 0;
v0 = missingPages;
v1 = 0;
do
v1 += *v0++ == 0;
while ( v0 != (char *)missingPages + (unsigned int)(nPages - 1) + 1 );
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
_BYTE *v0; // rax
unsigned int v1; // edx

if ( nPages <= 0 )
return 0;
v0 = missingPages;
v1 = 0;
do
v1 += *v0++ == 0;
while ( v0 != (char *)missingPages + (unsigned int)(nPages - 1) + 1 );
return v1;
}

original_code:
int missing_pages()
{
  int result;
  int i;
  result = 0;
  for(i=0; i < nPages; ++i)
    if ((missingPages[i]) == '\0') ++result;
  return result;
}

variable_types: result int


decompiled_code:
_BOOL8 __fastcall is_missing(int a1)
{
return *((_BYTE *)missingPages + a1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return *((_BYTE *)missingPages + a1) == 0;
}

original_code:
int is_missing(int page)
{
  return (missingPages[page] == '\0') ? 1 : 0;
}

variable_types: page int


decompiled_code:
__int64 ask_for_missing_page()
{
unsigned int v0; // er12
__int64 v1; // rbx
int v2; // ebp
__int64 v3; // rdi

v0 = missing_pages();
if ( v0 )
{
if ( nPages <= 0 )
{
v0 = 1;
}
else
{
v1 = 0LL;
v2 = 0;
do
{
if ( !*((_BYTE *)missingPages + v1) )
{
++v2;
v3 = 500LL;
if ( v0 == v2 )
v3 = 600LL;
send_complaint(v3, (unsigned int)(v1 + 1));
usleep(0x1F40u);
}
++v1;
}
while ( nPages > (int)v1 );
v0 = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // er12
__int64 v1; // rbx
int v2; // ebp
__int64 v3; // rdi

v0 = func2();
if ( v0 )
{
if ( nPages <= 0 )
{
v0 = 1;
}
else
{
v1 = 0LL;
v2 = 0;
do
{
if ( !*((_BYTE *)missingPages + v1) )
{
++v2;
v3 = 500LL;
if ( v0 == v2 )
v3 = 600LL;
send_complaint(v3, (unsigned int)(v1 + 1));
usleep(0x1F40u);
}
++v1;
}
while ( nPages > (int)v1 );
v0 = 1;
}
}
return v0;
}

original_code:
int ask_for_missing_page()
{
  int i;
  int n, count;
  n = missing_pages();
  if (n == 0) {
    return 0;
  }
  count = 0;
  for(i=0; i < nPages; ++i) {
    if ( missingPages[i] == '\0' ) {
      ++count;
      send_complaint((count==n) ? 600 : 500, i+1);
      usleep(8000);
    }
  }
  return 1;
}

canonical_original_code:
int ask_for_missing_page()
{
  int i;
  int n; int count;
  n = missing_pages();
  if (n == 0) {
    return 0;
  }
  count = 0;
  for(i=0; i < nPages; ++i) {
    if ( missingPages[i] == '\0' ) {
      ++count;
      send_complaint((count==n) ? 600 : 500, i+1);
      usleep(8000);
    }
  }
  return 1;
}

variable_types: count int


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

if ( verbose > 1 )
fwrite("in send_socket_ip\n", 1uLL, 0x12uLL, stderr);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_WORD *)a1 = 2;
*(_WORD *)(a1 + 2) = _bswap_16(a2);
result = socket(2, 2, 0);
if ( result < 0 )
{
perror("Send socket");
exit(1);
}
return result;
}

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

if ( verbose > 1 )
fwrite("in send_socket_ip\n", 1uLL, 0x12uLL, stderr);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_WORD *)a1 = 2;
*(_WORD *)(a1 + 2) = func0(a2);
result = socket(2, 2, 0);
if ( result < 0 )
{
perror("Send socket");
exit(1);
}
return result;
}

original_code:
int complaint_socket(struct sockaddr_in *addr, int port)
{
  int fd, sockaddr_len;
  sa_family_t family;
  if (verbose>=2) fprintf(stderr, "in send_socket_ip\n");
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  if ((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Send socket");
    exit(1);
  }
  return fd;
}

canonical_original_code:
int complaint_socket(struct sockaddr_in *addr, int port)
{
  int fd; int sockaddr_len;
  unsigned short family;
  if (verbose>=2) fprintf(stderr, "in send_socket_ip\n");
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  if ((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Send socket");
    exit(1);
  }
  return fd;
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: port int

variable_types: fd int

variable_types:
family
unsigned short

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
__int64 __fastcall send_socket(struct sockaddr *addr, char *cp, unsigned int a3)
{
int v4; // eax
unsigned int v5; // ebp
char v7[104]; // [rsp+0h] [rbp-68h] BYREF

if ( verbose > 1 )
fwrite("in send_socket\n", 1uLL, 0xFuLL, stderr);
*(_QWORD *)&addr->sa_family = 0LL;
*(_QWORD *)&addr->sa_data[6] = 0LL;
addr->sa_family = 2;
*(_WORD *)addr->sa_data = _bswap_16(a3);
inet_pton(2, cp, &addr->sa_data[2]);
inet_ntop(2, &addr->sa_data[2], v7, 0x32u);
if ( verbose > 1 )
fprintf(stderr, "Creating a send socket to %s:%d\n", v7, a3);
v4 = socket(2, 2, 0);
v5 = v4;
if ( v4 < 0 )
{
perror("Send socket");
exit(1);
}
if ( bind(v4, addr, 0x10u) < 0 )
{
perror("in send_socket(): bind error (need to change MCAST_ADDR)");
exit(1);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(struct sockaddr *addr, char *cp, unsigned int a3)
{
int v4; // eax
unsigned int v5; // ebp
char v7[104]; // [rsp+0h] [rbp-68h] BYREF

if ( verbose > 1 )
fwrite("in send_socket\n", 1uLL, 0xFuLL, stderr);
*(_QWORD *)&addr->sa_family = 0LL;
*(_QWORD *)&addr->sa_data[6] = 0LL;
addr->sa_family = 2;
*(_WORD *)addr->sa_data = func0(a3);
inet_pton(2, cp, &addr->sa_data[2]);
inet_ntop(2, &addr->sa_data[2], v7, 0x32u);
if ( verbose > 1 )
fprintf(stderr, "Creating a send socket to %s:%d\n", v7, a3);
v4 = socket(2, 2, 0);
v5 = v4;
if ( v4 < 0 )
{
perror("Send socket");
exit(1);
}
if ( bind(v4, addr, 0x10u) < 0 )
{
perror("in send_socket(): bind error (need to change MCAST_ADDR)");
exit(1);
}
return v5;
}

original_code:
int send_socket(struct sockaddr_in *addr, char * cp, int port)
{
  int fd, sockaddr_len;
  sa_family_t family;
  char buf[50];
  if (verbose>=2) fprintf(stderr, "in send_socket\n");
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  inet_pton(2, cp, &addr->sin_addr);
  inet_ntop(2, &addr->sin_addr, buf, 50);
  if (verbose>=2)
    fprintf(stderr, "Creating a send socket to %s:%d\n", buf, port);
  if ((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Send socket");
    exit(1);
  }
  if ((bind(fd, (const struct sockaddr *)addr, sockaddr_len)) < 0){
       perror("in send_socket(): bind error (need to change MCAST_ADDR)");
       exit(1);
     }
  return fd;
}

canonical_original_code:
int send_socket(struct sockaddr_in *addr, char *cp, int port)
{
  int fd; int sockaddr_len;
  unsigned short family;
  char buf[50];
  if (verbose>=2) fprintf(stderr, "in send_socket\n");
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  inet_pton(2, cp, &addr->sin_addr);
  inet_ntop(2, &addr->sin_addr, buf, 50);
  if (verbose>=2)
    fprintf(stderr, "Creating a send socket to %s:%d\n", buf, port);
  if ((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Send socket");
    exit(1);
  }
  if ((bind(fd, (struct sockaddr *)addr, sockaddr_len)) < 0){
       perror("in send_socket(): bind error (need to change MCAST_ADDR)");
       exit(1);
     }
  return fd;
}

variable_types:
cp
char *

variable_types:
buf
char [50]

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall rec_socket(struct sockaddr *addr, unsigned int a2)
{
int v2; // eax
unsigned int v3; // ebp

*(_QWORD *)&addr->sa_data[6] = 0LL;
addr->sa_family = 2;
*(_WORD *)addr->sa_data = _bswap_16(a2);
*(_DWORD *)&addr->sa_data[2] = _bswap_32(0);
v2 = socket(2, 2, 0);
if ( v2 < 0 )
{
perror("Socket create");
exit(1);
}
v3 = v2;
setsockopt(v2, 1, 2, 0LL, 0);
if ( verbose > 1 )
fprintf(stderr, "Creating receive socket on port %d\n", a2);
if ( bind(v3, addr, 0x10u) < 0 )
{
perror("in rec_socket(): bind error (need to change PORT)");
exit(1);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(struct sockaddr *addr, unsigned int a2)
{
int v2; // eax
unsigned int v3; // ebp

*(_QWORD *)&addr->sa_data[6] = 0LL;
addr->sa_family = 2;
*(_WORD *)addr->sa_data = func0(a2);
*(_DWORD *)&addr->sa_data[2] = func1(0);
v2 = socket(2, 2, 0);
if ( v2 < 0 )
{
perror("Socket create");
exit(1);
}
v3 = v2;
setsockopt(v2, 1, 2, 0LL, 0);
if ( verbose > 1 )
fprintf(stderr, "Creating receive socket on port %d\n", a2);
if ( bind(v3, addr, 0x10u) < 0 )
{
perror("in rec_socket(): bind error (need to change PORT)");
exit(1);
}
return v3;
}

original_code:
int rec_socket(struct sockaddr_in *addr, int port)
{
  int fd, sockaddr_len;
  sa_family_t family;
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  addr->sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  if((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Socket create");
    exit(1);
  }
  setsockopt(fd, 1, 2, ((void *)0), 0);
  if (verbose>=2)
    fprintf(stderr, "Creating receive socket on port %d\n", port);
  if ((bind(fd, (const struct sockaddr *)addr, sockaddr_len)) < 0){
    perror("in rec_socket(): bind error (need to change PORT)");
    exit(1);
  }
  return fd;
}

canonical_original_code:
int rec_socket(struct sockaddr_in *addr, int port)
{
  int fd; int sockaddr_len;
  unsigned short family;
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  addr->sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  if((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Socket create");
    exit(1);
  }
  setsockopt(fd, 1, 2, ((void *)0), 0);
  if (verbose>=2)
    fprintf(stderr, "Creating receive socket on port %d\n", port);
  if ((bind(fd, (struct sockaddr *)addr, sockaddr_len)) < 0){
    perror("in rec_socket(): bind error (need to change PORT)");
    exit(1);
  }
  return fd;
}


decompiled_code:
int __fastcall set_delay(unsigned int a1, unsigned int a2)
{
int result; // eax

if ( verbose > 1 )
{
if ( a2 == -1 )
result = fwrite("Timeout: set to infinite\n", 1uLL, 0x19uLL, stderr);
else
result = fprintf(stderr, "Timeout: set to %d sec + %d usec\n", a1, a2);
}
delay_sec = a1;
delay_usec = a2;
return result;
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1, unsigned int a2)
{
int result; // eax

if ( verbose > 1 )
{
if ( a2 == -1 )
result = fwrite("Timeout: set to infinite\n", 1uLL, 0x19uLL, stderr);
else
result = fprintf(stderr, "Timeout: set to %d sec + %d usec\n", a1, a2);
}
delay_sec = a1;
delay_usec = a2;
return result;
}

original_code:
void set_delay(int secs, int usecs)
{
  if (verbose>=2) {
    if (usecs == -1)
      fprintf(stderr, "Timeout: set to infinite\n");
    else
      fprintf(stderr, "Timeout: set to %d sec + %d usec\n", secs, usecs);
  }
  delay_sec = secs;
  delay_usec = usecs;
}

variable_types: secs int

variable_types: usecs int

return_type: void


readable

decompiled_code:
int __fastcall readable(int a1)
{
fd_set v2; // [rsp+0h] [rbp-98h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-18h] BYREF

memset(&v2, 0, sizeof(v2));
v2.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
if ( delay_usec == -1 )
return select(a1 + 1, &v2, 0LL, 0LL, 0LL);
timeout.tv_sec = delay_sec;
timeout.tv_usec = delay_usec;
return select(a1 + 1, &v2, 0LL, 0LL, &timeout);
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
fd_set v2; // [rsp+0h] [rbp-98h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-18h] BYREF

memset(&v2, 0, sizeof(v2));
v2.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
if ( delay_usec == -1 )
return select(a1 + 1, &v2, 0LL, 0LL, 0LL);
timeout.tv_sec = delay_sec;
timeout.tv_usec = delay_usec;
return select(a1 + 1, &v2, 0LL, 0LL, &timeout);
}

original_code:
int readable(int fd)
{
  struct timeval delay_tv;
  fd_set rset;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rset)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
  if (delay_usec == -1){
    return(select(fd + 1, &rset, ((void *)0), ((void *)0), ((void *)0)));
  } else {
    delay_tv.tv_sec = delay_sec;
    delay_tv.tv_usec = delay_usec;
    return (select(fd + 1, &rset, ((void *)0), ((void *)0), &delay_tv));
  }
}

canonical_original_code:
int readable(int fd)
{
  struct timeval delay_tv;
  struct fd_set rset;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rset)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
  if (delay_usec == -1){
    return(select(fd + 1, &rset, ((void *)0), ((void *)0), ((void *)0)));
  } else {
    delay_tv.tv_sec = delay_sec;
    delay_tv.tv_usec = delay_usec;
    return (select(fd + 1, &rset, ((void *)0), ((void *)0), &delay_tv));
  }
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
rset
struct fd_set { long __fds_bits[-1]; }


decompiled_code:
void refresh_timer()
{
usec_acc = 0LL;
sec_acc = 0LL;
}

canonical_decompiled_code:
void func0()
{
usec_acc = 0LL;
sec_acc = 0LL;
}

original_code:
void refresh_timer()
{
  usec_acc = 0;
  sec_acc = 0;
}


decompiled_code:
int start_timer()
{
struct timezone tz; // [rsp+8h] [rbp-10h] BYREF

return gettimeofday(&tv0, &tz);
}

canonical_decompiled_code:
int func1()
{
struct timezone tz; // [rsp+8h] [rbp-10h] BYREF

return gettimeofday(&tv0, &tz);
}

original_code:
void start_timer()
{
  struct timezone tz;
  gettimeofday(&tv0, &tz);
}

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


decompiled_code:
int end_timer()
{
struct timezone tz; // [rsp+8h] [rbp-10h] BYREF

return gettimeofday(&tv1, &tz);
}

canonical_decompiled_code:
int func2()
{
struct timezone tz; // [rsp+8h] [rbp-10h] BYREF

return gettimeofday(&tv1, &tz);
}

original_code:
void end_timer()
{
  struct timezone tz;
  gettimeofday(&tv1, &tz);
}

user_defined_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


decompiled_code:
__suseconds_t update_time_accumulator()
{
__suseconds_t v0; // rax
__suseconds_t v1; // rdx
__suseconds_t result; // rax

v0 = tv1.tv_usec;
v1 = tv0.tv_usec;
if ( v0 >= v1 )
{
sec_acc += tv1.tv_sec - tv0.tv_sec;
result = v0 - v1;
}
else
{
sec_acc = tv1.tv_sec - tv0.tv_sec + sec_acc - 1;
result = v0 + 1000000 - v1;
}
usec_acc += result;
return result;
}

canonical_decompiled_code:
__suseconds_t func3()
{
__suseconds_t v0; // rax
__suseconds_t v1; // rdx
__suseconds_t result; // rax

v0 = tv1.tv_usec;
v1 = tv0.tv_usec;
if ( v0 >= v1 )
{
sec_acc += tv1.tv_sec - tv0.tv_sec;
result = v0 - v1;
}
else
{
sec_acc = tv1.tv_sec - tv0.tv_sec + sec_acc - 1;
result = v0 + 1000000 - v1;
}
usec_acc += result;
return result;
}

original_code:
void update_time_accumulator()
{
  if (tv1.tv_usec<tv0.tv_usec) {
    sec_acc += (tv1.tv_sec - tv0.tv_sec - 1);
    usec_acc += (1000000 + tv1.tv_usec - tv0.tv_usec);
  } else {
    sec_acc += (tv1.tv_sec - tv0.tv_sec);
    usec_acc += (tv1.tv_usec - tv0.tv_usec);
  }
}


decompiled_code:
double get_accumulated_time()
{
double v0; // xmm1_8
double v1; // xmm0_8
double v3; // xmm0_8

if ( sec_acc < 0 )
{
v3 = (double)(int)(sec_acc & 1 | ((unsigned __int64)sec_acc >> 1));
v0 = v3 + v3;
}
else
{
v0 = (double)(int)sec_acc;
}
if ( usec_acc < 0 )
v1 = (double)(int)(usec_acc & 1 | ((unsigned __int64)usec_acc >> 1))
+ (double)(int)(usec_acc & 1 | ((unsigned __int64)usec_acc >> 1));
else
v1 = (double)(int)usec_acc;
return v1 / 1000000.0 + v0;
}

canonical_decompiled_code:
double func4()
{
double v0; // xmm1_8
double v1; // xmm0_8
double v3; // xmm0_8

if ( sec_acc < 0 )
{
v3 = (double)(int)(sec_acc & 1 | ((unsigned __int64)sec_acc >> 1));
v0 = v3 + v3;
}
else
{
v0 = (double)(int)sec_acc;
}
if ( usec_acc < 0 )
v1 = (double)(int)(usec_acc & 1 | ((unsigned __int64)usec_acc >> 1))
+ (double)(int)(usec_acc & 1 | ((unsigned __int64)usec_acc >> 1));
else
v1 = (double)(int)usec_acc;
return v1 / 1000000.0 + v0;
}

original_code:
double get_accumulated_time()
{
  double sec = sec_acc;
  sec += (usec_acc / 1e6);
  return sec;
}

variable_types: sec double

return_type: double


decompiled_code:
double get_accumulated_usec()
{
double v0; // xmm1_8
double v1; // xmm0_8
double v3; // xmm0_8

if ( usec_acc < 0 )
{
v3 = (double)(int)(usec_acc & 1 | ((unsigned __int64)usec_acc >> 1));
v0 = v3 + v3;
}
else
{
v0 = (double)(int)usec_acc;
}
if ( sec_acc < 0 )
v1 = (double)(int)(sec_acc & 1 | ((unsigned __int64)sec_acc >> 1))
+ (double)(int)(sec_acc & 1 | ((unsigned __int64)sec_acc >> 1));
else
v1 = (double)(int)sec_acc;
return v1 * 1000000.0 + v0;
}

canonical_decompiled_code:
double func5()
{
double v0; // xmm1_8
double v1; // xmm0_8
double v3; // xmm0_8

if ( usec_acc < 0 )
{
v3 = (double)(int)(usec_acc & 1 | ((unsigned __int64)usec_acc >> 1));
v0 = v3 + v3;
}
else
{
v0 = (double)(int)usec_acc;
}
if ( sec_acc < 0 )
v1 = (double)(int)(sec_acc & 1 | ((unsigned __int64)sec_acc >> 1))
+ (double)(int)(sec_acc & 1 | ((unsigned __int64)sec_acc >> 1));
else
v1 = (double)(int)sec_acc;
return v1 * 1000000.0 + v0;
}

original_code:
double get_accumulated_usec()
{
  double usec = usec_acc;
  usec += (sec_acc*1e6);
  return usec;
}

variable_types: usec double


decompiled_code:
int *init_rtt_hist()
{
int *result; // rax

result = &rtt_hist;
do
*result++ = 0;
while ( result != (int *)(unsigned int)((_DWORD)&rtt_hist + 2004) );
return result;
}

canonical_decompiled_code:
int *func6()
{
int *result; // rax

result = &rtt_hist;
do
*result++ = 0;
while ( result != (int *)(unsigned int)((_DWORD)&rtt_hist + 2004) );
return result;
}

original_code:
void init_rtt_hist()
{
  int i;
  for(i=0; i<501; ++i) rtt_hist[i] = 0;
}

variable_types: i int


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

LODWORD(result) = 500;
if ( a1 <= 0x7A11F )
LODWORD(result) = a1 / 0x3E8;
result = (unsigned int)result;
++rtt_hist[(unsigned int)result];
return result;
}

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

LODWORD(result) = 500;
if ( a1 <= 0x7A11F )
LODWORD(result) = a1 / 0x3E8;
result = (unsigned int)result;
++rtt_hist[(unsigned int)result];
return result;
}

original_code:
void update_rtt_hist(unsigned int rtt)
{
  unsigned int index;
  index = rtt / 1000;
  if (index>(501 -2)) index = 501 -1;
  rtt_hist[index]++;
}

variable_types:
rtt
unsigned int

variable_types:
index
unsigned int


decompiled_code:
int pr_rtt_hist()
{
int result; // eax
__int64 i; // rbx
__int64 v2; // rcx

fwrite("rtt histogram\n", 1uLL, 0xEuLL, stderr);
fwrite("msec counts\n", 1uLL, 0xCuLL, stderr);
result = fwrite("---- --------\n", 1uLL, 0xEuLL, stderr);
for ( i = 0LL; i != 501; ++i )
{
if ( verbose > 1 || (int)i <= 10 )
{
v2 = (unsigned int)rtt_hist[i];
if ( (_DWORD)v2 )
result = fprintf(stderr, "%4d %u\n", (unsigned int)i, v2);
}
}
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
__int64 i; // rbx
__int64 v2; // rcx

fwrite("rtt histogram\n", 1uLL, 0xEuLL, stderr);
fwrite("msec counts\n", 1uLL, 0xCuLL, stderr);
result = fwrite("---- --------\n", 1uLL, 0xEuLL, stderr);
for ( i = 0LL; i != 501; ++i )
{
if ( verbose > 1 || (int)i <= 10 )
{
v2 = (unsigned int)rtt_hist[i];
if ( (_DWORD)v2 )
result = fprintf(stderr, "%4d %u\n", (unsigned int)i, v2);
}
}
return result;
}

original_code:
void pr_rtt_hist()
{
  int i;
  fprintf(stderr, "rtt histogram\n");
  fprintf(stderr, "msec counts\n");
  fprintf(stderr, "---- --------\n");
  for(i=0; i<501; ++i) {
    if (verbose<=1 && i>10) continue;
    if (rtt_hist[i] != 0) {
      fprintf(stderr, "%4d %u\n", i, rtt_hist[i]);
    }
  }
}


decompiled_code:
__int64 pages_wo_ack()
{
return (unsigned int)rtt_hist[500];
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)rtt_hist[500];
}

original_code:
unsigned int pages_wo_ack()
{
  return rtt_hist[501 -1];
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall init_synclist(char *filename, const char *a2)
{
__int64 result; // rax
char v3[4104]; // [rsp+0h] [rbp-1008h] BYREF

nEntries = 0;
strcpy(basedir, a2);
fd = fopen64(filename, "r");
if ( fd )
{
while ( fgets(v3, 4096, fd) )
++nEntries;
if ( nEntries )
{
rewind(fd);
cur_entry = 0;
total_pages = 0;
total_bytes = 0LL;
}
else
{
fclose(fd);
fprintf(stderr, "Empty entires in synclist file = %s\n", filename);
}
result = 1LL;
}
else
{
fprintf(stderr, "Cannot open synclist file = %s \n", filename);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *filename, const char *a2)
{
__int64 result; // rax
char v3[4104]; // [rsp+0h] [rbp-1008h] BYREF

nEntries = 0;
strcpy(basedir, a2);
fd = fopen64(filename, "r");
if ( fd )
{
while ( fgets(v3, 4096, fd) )
++nEntries;
if ( nEntries )
{
rewind(fd);
cur_entry = 0;
total_pages = 0;
total_bytes = 0LL;
}
else
{
fclose(fd);
fprintf(stderr, "Empty entires in synclist file = %s\n", filename);
}
result = 1LL;
}
else
{
fprintf(stderr, "Cannot open synclist file = %s \n", filename);
result = 0LL;
}
return result;
}

original_code:
int init_synclist(char * synclist_path, char *bdir)
{
  char line[4096];
  nEntries = 0;
  strcpy(basedir, bdir);
  if ((fd = fopen(synclist_path, "r")) == ((void *)0)) {
    fprintf(stderr, "Cannot open synclist file = %s \n", synclist_path);
    return (0);
  }
  while (fgets(line, 4096, fd) != ((void *)0)) nEntries++;
  if (nEntries == 0) {
    fclose(fd);
    fprintf(stderr, "Empty entires in synclist file = %s\n", synclist_path);
    return (1);
  }
  rewind(fd);
  cur_entry = 0;
  total_pages = 0;
  total_bytes = 0;
  return (1);
}

canonical_original_code:
int init_synclist(char *synclist_path, char *bdir)
{
  char line[4096];
  nEntries = 0;
  strcpy(basedir, bdir);
  if ((fd = fopen(synclist_path, "r")) == ((void *)0)) {
    fprintf(stderr, "Cannot open synclist file = %s \n", synclist_path);
    return (0);
  }
  while (fgets(line, 4096, fd) != ((void *)0)) nEntries++;
  if (nEntries == 0) {
    fclose(fd);
    fprintf(stderr, "Empty entires in synclist file = %s\n", synclist_path);
    return (1);
  }
  rewind(fd);
  cur_entry = 0;
  total_pages = 0;
  total_bytes = 0;
  return (1);
}

variable_types:
bdir
char *

variable_types:
line
char [4096]


decompiled_code:
__int64 pages_for_file()
{
unsigned int v0; // edx
__off_t v2; // rsi

v0 = isDelete;
if ( isDelete )
return (unsigned int)-1;
if ( (st.st_mode & 0xF000) == 0x8000 && st.st_nlink <= 1 )
{
v2 = st.st_size;
v0 = v2 / 64512;
if ( v2 == 64512 * (v2 / 64512) )
{
last_bytes = 64512;
}
else
{
last_bytes = v2 % 64512;
v0 = v2 / 64512 + 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // edx
__off_t v2; // rsi

v0 = isDelete;
if ( isDelete )
return (unsigned int)-1;
if ( (st.st_mode & 0xF000) == 0x8000 && st.st_nlink <= 1 )
{
v2 = st.st_size;
v0 = v2 / 64512;
if ( v2 == 64512 * (v2 / 64512) )
{
last_bytes = 64512;
}
else
{
last_bytes = v2 % 64512;
v0 = v2 / 64512 + 1;
}
}
return v0;
}

original_code:
int pages_for_file()
{
  if (isDelete) {
    return (-1);
  }
  if (((((st.st_mode)) & 0170000) == (0100000))){
    int n;
    if (st.st_nlink > 1) return 0;
    n = (int)((st.st_size)/(off_t)64512);
    if ((st.st_size)%((off_t)64512) == 0) {
      last_bytes = (unsigned int)(64512);
      return n;
    } else {
      last_bytes = (unsigned int)(st.st_size - (off_t)n * (off_t)64512);
      return n+1;
    }
  }
  if (((((st.st_mode)) & 0170000) == (0120000))){
    return 0;
  }
  return 0;
}

canonical_original_code:
int pages_for_file()
{
  if (isDelete) {
    return (-1);
  }
  if (((((st.st_mode)) & 0170000) == (0100000))){
    int n;
    if (st.st_nlink > 1) return 0;
    n = (int)((st.st_size)/(long)64512);
    if ((st.st_size)%((long)64512) == 0) {
      last_bytes = (unsigned int)(64512);
      return n;
    } else {
      last_bytes = (unsigned int)(st.st_size - (long)n * (long)64512);
      return n+1;
    }
  }
  if (((((st.st_mode)) & 0170000) == (0120000))){
    return 0;
  }
  return 0;
}

variable_types: n int


decompiled_code:
__off_t bytes_for_file()
{
return st.st_size;
}

canonical_decompiled_code:
__off_t func2()
{
return st.st_size;
}

canonical_original_code:
long bytes_for_file()
{
  return st.st_size;
}

return_type: long


decompiled_code:
__int64 get_nPages()
{
return (unsigned int)nPages;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)nPages;
}

original_code:
unsigned int get_nPages()
{
  return nPages;
}


decompiled_code:
_BOOL8 same_stat_for_file()
{
_BOOL8 result; // rax
struct stat64 v1; // [rsp+0h] [rbp-98h] BYREF

if ( lstat64(fullname, &v1) < 0 )
{
result = 0LL;
if ( verbose > 0 )
{
perror(fullname);
result = 0LL;
}
}
else
{
result = 0LL;
if ( v1.st_size == st.st_size && v1.st_mode == st.st_mode )
result = v1.st_mtim.tv_sec == st.st_mtim.tv_sec;
}
return result;
}

canonical_decompiled_code:
_BOOL8 func5()
{
_BOOL8 result; // rax
struct stat64 v1; // [rsp+0h] [rbp-98h] BYREF

if ( lstat64(fullname, &v1) < 0 )
{
result = 0LL;
if ( verbose > 0 )
{
perror(fullname);
result = 0LL;
}
}
else
{
result = 0LL;
if ( v1.st_size == st.st_size && v1.st_mode == st.st_mode )
result = v1.st_mtim.tv_sec == st.st_mtim.tv_sec;
}
return result;
}

original_code:
int same_stat_for_file()
{
  struct stat st1;
  if(lstat(fullname, &st1) < 0) {
    if (verbose >=1) perror(fullname);
    return (0);
  }
  if (st1.st_size != st.st_size || st1.st_mode != st.st_mode ||
      st1.st_mtim.tv_sec != st.st_mtim.tv_sec) {
    return (0);
  }
  return (1);
}

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

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


decompiled_code:
__int64 __fastcall is_hardlink_line(char *src)
{
char v2[4096]; // [rsp+0h] [rbp-1098h] BYREF
struct stat64 buf; // [rsp+1000h] [rbp-98h] BYREF

strcpy(v2, basedir);
*(_WORD *)&v2[strlen(v2)] = 47;
strcat(v2, src);
return (unsigned int)lstat64(v2, &buf) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src)
{
char v2[4096]; // [rsp+0h] [rbp-1098h] BYREF
struct stat64 buf; // [rsp+1000h] [rbp-98h] BYREF

strcpy(v2, basedir);
*(_WORD *)&v2[strlen(v2)] = 47;
strcat(v2, src);
return (unsigned int)lstat64(v2, &buf) >> 31;
}

original_code:
int is_hardlink_line(char * line)
{
  struct stat st;
  char fn[4096];
  strcpy(fn, basedir);
  strcat(fn, "/");
  strcat(fn, line);
  return (lstat(fn, &st) < 0);
}

canonical_original_code:
int is_hardlink_line(char *line)
{
  struct stat st;
  char fn[4096];
  strcpy(fn, basedir);
  strcat(fn, "/");
  strcat(fn, line);
  return (lstat(fn, &st) < 0);
}

variable_types:
line
char *

variable_types:
fn
char [4096]


decompiled_code:
__int64 __fastcall get_next_entry(int a1)
{
char *v1; // rbx
int v2; // eax
__int64 result; // rax
int v4; // edx
char v5[4096]; // [rsp+0h] [rbp-2018h] BYREF
char s[9]; // [rsp+1000h] [rbp-1018h] BYREF
char src[4111]; // [rsp+1009h] [rbp-100Fh] BYREF

cur_entry = a1;
isDelete = 0;
isHardlink = 0;
fgets(s, 4096, fd);
strip(s);
if ( a1 == nEntries )
{
fclose(fd);
if ( verbose <= 1 )
goto LABEL_4;
fwrite("no more entry in synclist.\n", 1uLL, 0x1BuLL, stderr);
}
if ( verbose > 1 )
{
fprintf(stderr, "Got current entry = %d (total= %d)\n", (unsigned int)cur_entry, (unsigned int)nEntries);
fprintf(stderr, "%s\n", s);
}
LABEL_4:
strcpy(fullname, basedir);
*(_WORD *)&fullname[strlen(fullname)] = 47;
if ( !memcmp(s, "deleting ", 9uLL) )
{
isDelete = 1;
nPages = -1;
strcat(fullname, src);
strcpy(filename, src);
v4 = needBackup(fullname);
result = 1LL;
if ( v4 )
cur_entry = -cur_entry;
}
else
{
v1 = strchr(s, 32);
if ( v1 && (unsigned int)is_hardlink_line(s) )
{
isHardlink = 1;
strncpy(v5, s, v1 - s);
v5[v1 - s] = 0;
strcat(fullname, v5);
strcpy(filename, v5);
strcpy(linktar, v1 + 1);
}
else
{
strcat(fullname, s);
strcpy(filename, s);
}
if ( lstat64(fullname, &st) < 0 )
{
result = 0LL;
if ( verbose > 0 )
{
perror(fullname);
result = 0LL;
}
}
else
{
if ( (st.st_mode & 0xF000) == 40960 )
{
linktar[(int)readlink(fullname, linktar, 0x1000uLL)] = 0;
}
else if ( st.st_nlink > 1 && !isHardlink )
{
st.st_nlink = 1LL;
}
v2 = pages_for_file();
nPages = v2;
if ( v2 )
{
total_pages += v2;
total_bytes += st.st_size;
}
if ( (unsigned int)needBackup(fullname) )
cur_entry = -cur_entry;
file_changed = 0;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
char *v1; // rbx
int v2; // eax
__int64 result; // rax
int v4; // edx
char v5[4096]; // [rsp+0h] [rbp-2018h] BYREF
char s[9]; // [rsp+1000h] [rbp-1018h] BYREF
char src[4111]; // [rsp+1009h] [rbp-100Fh] BYREF

cur_entry = a1;
isDelete = 0;
isHardlink = 0;
fgets(s, 4096, fd);
func4(s);
if ( a1 == nEntries )
{
fclose(fd);
if ( verbose <= 1 )
goto LABEL_4;
fwrite("no more entry in synclist.\n", 1uLL, 0x1BuLL, stderr);
}
if ( verbose > 1 )
{
fprintf(stderr, "Got current entry = %d (total= %d)\n", (unsigned int)cur_entry, (unsigned int)nEntries);
fprintf(stderr, "%s\n", s);
}
LABEL_4:
strcpy(fullname, basedir);
*(_WORD *)&fullname[strlen(fullname)] = 47;
if ( !memcmp(s, "deleting ", 9uLL) )
{
isDelete = 1;
nPages = -1;
strcat(fullname, src);
strcpy(filename, src);
v4 = needBackup(fullname);
result = 1LL;
if ( v4 )
cur_entry = -cur_entry;
}
else
{
v1 = strchr(s, 32);
if ( v1 && (unsigned int)func6(s) )
{
isHardlink = 1;
strncpy(v5, s, v1 - s);
v5[v1 - s] = 0;
strcat(fullname, v5);
strcpy(filename, v5);
strcpy(linktar, v1 + 1);
}
else
{
strcat(fullname, s);
strcpy(filename, s);
}
if ( lstat64(fullname, &st) < 0 )
{
result = 0LL;
if ( verbose > 0 )
{
perror(fullname);
result = 0LL;
}
}
else
{
if ( (st.st_mode & 0xF000) == 40960 )
{
linktar[(int)readlink(fullname, linktar, 0x1000uLL)] = 0;
}
else if ( st.st_nlink > 1 && !isHardlink )
{
st.st_nlink = 1LL;
}
v2 = func1();
nPages = v2;
if ( v2 )
{
total_pages += v2;
total_bytes += st.st_size;
}
if ( (unsigned int)needBackup(fullname) )
cur_entry = -cur_entry;
file_changed = 0;
result = 1LL;
}
}
return result;
}

original_code:
int get_next_entry(int current_file_id)
{
  char *c;
  char line[4096];
  cur_entry = current_file_id;
  isDelete = 0;
  isHardlink = 0;
  fgets(line, 4096, fd);
  strip(line);
  if (current_file_id == nEntries) {
    fclose(fd);
    if (verbose>=2) fprintf(stderr, "no more entry in synclist.\n");
  }
  if (verbose>=2) {
    fprintf(stderr, "Got current entry = %d (total= %d)\n", cur_entry, nEntries);
    fprintf(stderr, "%s\n", line);
  }
  strcpy(fullname, basedir);
  strcat(fullname, "/");
  if (strncmp(line, "deleting ", 9)==0) {
    isDelete = 1;
    nPages = -1;
    strcat(fullname, &line[9]);
    strcpy(filename, &line[9]);
    if (needBackup(fullname)) cur_entry = -cur_entry;
    return (1);
  } else if ((c = strchr(line, ' '))!=((void *)0) && is_hardlink_line(line)) {
    char fn[4096];
    isHardlink = 1;
    strncpy(fn, line, (c - line));
    fn[c-line] = '\0';
    strcat(fullname, fn);
    strcpy(filename, fn);
    strcpy(linktar, c+1);
  } else {
    strcat(fullname, line);
    strcpy(filename, line);
  }
  if(lstat(fullname, &st) < 0) {
    if (verbose >=1) perror(fullname);
    return (0);
  }
  if (((((st.st_mode)) & 0170000) == (0120000))) {
    int linklen;
    linklen = readlink(fullname, linktar, 4096);
    *(linktar + linklen) = '\0';
  } else if (st.st_nlink>1 && !isHardlink) {
    st.st_nlink = 1;
  }
  nPages = pages_for_file();
  if (nPages > 0) {
    total_pages += nPages;
    total_bytes += st.st_size;
  }
  if (needBackup(fullname)) cur_entry = -cur_entry;
  file_changed = 0;
  return (1);
}

variable_types:
c
char *

variable_types: linklen int


decompiled_code:
__off_t adjust_totals()
{
__off_t result; // rax

result = (unsigned int)nPages;
if ( nPages )
{
total_pages -= nPages;
result = st.st_size;
total_bytes -= result;
}
return result;
}

canonical_decompiled_code:
__off_t func8()
{
__off_t result; // rax

result = (unsigned int)nPages;
if ( nPages )
{
total_pages -= nPages;
result = st.st_size;
total_bytes -= result;
}
return result;
}

original_code:
void adjust_totals()
{
  if (nPages > 0) {
    total_pages -= nPages;
    total_bytes -= st.st_size;
  }
}


decompiled_code:
__int64 total_entries()
{
return (unsigned int)nEntries;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)nEntries;
}

original_code: unsigned int total_entries() { return nEntries; }


decompiled_code:
__int64 current_entry()
{
return (unsigned int)cur_entry;
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned int)cur_entry;
}

original_code: int current_entry() { return cur_entry; }


decompiled_code:
_BOOL8 is_softlink()
{
return (st.st_mode & 0xF000) == 40960;
}


decompiled_code:
__int64 is_hardlink()
{
return (unsigned int)isHardlink;
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned int)isHardlink;
}

original_code: int is_hardlink() { return isHardlink; }


decompiled_code:
_BOOL8 is_directory()
{
return (st.st_mode & 0xF000) == 0x4000;
}

canonical_decompiled_code:
_BOOL8 func13()
{
return (st.st_mode & 0xF000) == 0x4000;
}


getFilename

decompiled_code:
char *getFilename()
{
return filename;
}

canonical_decompiled_code:
char *func14()
{
return filename;
}

original_code: char * getFilename() { return &filename[0]; }

canonical_original_code: char *getFilename() { return &filename[0]; }

return_type: char *


getFullname

decompiled_code:
char *getFullname()
{
return fullname;
}

canonical_decompiled_code:
char *func15()
{
return fullname;
}

original_code: char * getFullname() { return &fullname[0]; }

canonical_original_code: char *getFullname() { return &fullname[0]; }


decompiled_code:
__int64 __fastcall fill_in_stat(char *s)
{
if ( isDelete )
strcpy(s, "0 0 0 0 0 0 0 0");
else
sprintf(
s,
"%u %u %u %u %llu %lu %lu %d",
st.st_mode,
st.st_nlink,
st.st_uid,
st.st_gid,
st.st_size,
st.st_atim.tv_sec,
st.st_mtim.tv_sec,
(unsigned int)toRmFirst);
return (unsigned int)strlen(s) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *s)
{
if ( isDelete )
strcpy(s, "0 0 0 0 0 0 0 0");
else
sprintf(
s,
"%u %u %u %u %llu %lu %lu %d",
st.st_mode,
st.st_nlink,
st.st_uid,
st.st_gid,
st.st_size,
st.st_atim.tv_sec,
st.st_mtim.tv_sec,
(unsigned int)toRmFirst);
return (unsigned int)strlen(s) + 1;
}

original_code:
unsigned int fill_in_stat(char *buf)
{
  if (isDelete)
    sprintf(buf, "0 0 0 0 0 0 0 0");
  else {
    sprintf(buf, "%u %u %u %u %llu %lu %lu %d", st.st_mode, st.st_nlink,
     st.st_uid, st.st_gid, st.st_size, st.st_atim.tv_sec, st.st_mtim.tv_sec,
     toRmFirst);
  }
  return strlen(buf)+1;
}

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall fill_in_filename(char *s)
{
strcpy(s, filename);
return (unsigned int)strlen(s) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func17(char *s)
{
strcpy(s, filename);
return (unsigned int)strlen(s) + 1;
}

original_code:
unsigned int fill_in_filename(char * buf)
{
  strcpy(buf, filename);
  return strlen(buf)+1;
}

canonical_original_code:
unsigned int fill_in_filename(char *buf)
{
  strcpy(buf, filename);
  return strlen(buf)+1;
}


decompiled_code:
__int64 __fastcall fill_in_linktar(char *s)
{
strcpy(s, linktar);
return (unsigned int)strlen(s) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func18(char *s)
{
strcpy(s, linktar);
return (unsigned int)strlen(s) + 1;
}

original_code:
unsigned int fill_in_linktar(char *buf)
{
  strcpy(buf, linktar);
  return strlen(buf)+1;
}


strip

decompiled_code:
const char *__fastcall strip(const char *a1)
{
const char *result; // rax

result = &a1[strlen(a1) - 1];
if ( *result == 32 || *result == 10 )
{
do
{
do
*result-- = 0;
while ( *result == 32 );
}
while ( *result == 10 );
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1)
{
const char *result; // rax

result = &a1[strlen(a1) - 1];
if ( *result == 32 || *result == 10 )
{
do
{
do
*result-- = 0;
while ( *result == 32 );
}
while ( *result == 10 );
}
return result;
}

original_code:
void strip(char * str)
{
  char *pc = &str[strlen(str)-1];
  while (*pc == ' ' || *pc == '\n') {
    *(pc--) = '\0';
  }
}

canonical_original_code:
void strip(char *str)
{
  char *pc = &str[strlen(str)-1];
  while (*pc == ' ' || *pc == '\n') {
    *(pc--) = '\0';
  }
}

variable_types:
str
char *

variable_types:
pc
char *


decompiled_code:
void *__fastcall init_string_list(__int64 a1, int a2)
{
void *result; // rax

result = malloc(8LL * a2);
*(_QWORD *)(a1 + 16) = result;
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

result = malloc(8LL * a2);
*(_QWORD *)(a1 + 16) = result;
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void init_string_list(struct string_list * str_ptr, int n)
{
  str_ptr->str = malloc(n * sizeof(void*));
  str_ptr->capacity = n;
  str_ptr->endp = str_ptr->str;
}

canonical_original_code:
void init_string_list(struct string_list *str_ptr, int n)
{
  str_ptr->str = malloc(n * sizeof(void *));
  str_ptr->capacity = n;
  str_ptr->endp = str_ptr->str;
}

variable_types: struct string_list { int capacity; char **endp; char **str; } *


decompiled_code:
void __fastcall grow_string_list(__int64 a1)
{
int v1; // er12
_QWORD *v2; // r13
void *v3; // rax
void *v4; // rbp
unsigned __int64 v5; // rcx
_QWORD *v6; // rdx
_QWORD *v7; // rax
unsigned __int64 v8; // r14

v1 = 2 * *(_DWORD *)a1;
v2 = *(_QWORD **)(a1 + 16);
v3 = malloc(8LL * v1);
v4 = v3;
v5 = *(_QWORD *)(a1 + 8);
if ( (unsigned __int64)v2 >= v5 )
{
v8 = (unsigned __int64)v3;
}
else
{
v6 = v3;
v7 = v2;
do
*v6++ = *v7++;
while ( (unsigned __int64)v7 < v5 );
v8 = (unsigned __int64)v4 + 8 * ((v5 - 1 - (unsigned __int64)v2) >> 3) + 8;
}
free(v2);
*(_QWORD *)(a1 + 16) = v4;
*(_QWORD *)(a1 + 8) = v8;
*(_DWORD *)a1 = v1;
}

original_code:
void grow_string_list(struct string_list * slp)
{
  int new_capacity = 2 * slp->capacity;
  char ** old_ptrs = slp->str;
  char ** new_ptrs;
  char ** newp = malloc(new_capacity * sizeof(void *));
  new_ptrs = newp;
  while (old_ptrs < slp->endp) {
    *new_ptrs++ = *old_ptrs++;
  }
  free(slp->str);
  slp->str = newp;
  slp->endp= new_ptrs;
  slp->capacity = new_capacity;
}

canonical_original_code:
void grow_string_list(struct string_list *slp)
{
  int new_capacity = 2 * slp->capacity;
  char **old_ptrs = slp->str;
  char **new_ptrs;
  char **newp = malloc(new_capacity * sizeof(void *));
  new_ptrs = newp;
  while (old_ptrs < slp->endp) {
    *new_ptrs++ = *old_ptrs++;
  }
  free(slp->str);
  slp->str = newp;
  slp->endp= new_ptrs;
  slp->capacity = new_capacity;
}

variable_types:
newp
char **

user_defined_types: struct string_list { int capacity; char **endp; char **str; }


decompiled_code:
char *__fastcall append_string_list(char *s, __int64 a2)
{
char **v2; // r12
char *result; // rax

if ( (__int64)(*(_QWORD *)(a2 + 8) - *(_QWORD *)(a2 + 16)) >> 3 == *(_DWORD *)a2 )
grow_string_list(a2);
v2 = *(char ***)(a2 + 8);
result = strdup(s);
*v2 = result;
*(_QWORD *)(a2 + 8) += 8LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *s, __int64 a2)
{
char **v2; // r12
char *result; // rax

if ( (__int64)(*(_QWORD *)(a2 + 8) - *(_QWORD *)(a2 + 16)) >> 3 == *(_DWORD *)a2 )
func1(a2);
v2 = *(char ***)(a2 + 8);
result = strdup(s);
*v2 = result;
*(_QWORD *)(a2 + 8) += 8LL;
return result;
}

original_code:
void append_string_list(char * str, struct string_list * slp)
{
  if (slp->endp - slp->str == slp->capacity) grow_string_list(slp);
  *slp->endp = strdup(str);
  (slp->endp)++;
}

canonical_original_code:
void append_string_list(char *str, struct string_list *slp)
{
  if (slp->endp - slp->str == slp->capacity) grow_string_list(slp);
  *slp->endp = strdup(str);
  (slp->endp)++;
}


decompiled_code:
__int64 __fastcall find_string(char *s2, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // r13
__int64 i; // rbx
unsigned int v6; // er14

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = (unsigned int)(v3 - 1);
for ( i = 0LL; ; ++i )
{
v6 = i;
if ( !strcmp(*(const char **)(v2 + 8 * i), s2) )
break;
if ( i == v4 )
return (unsigned int)-1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // r13
__int64 i; // rbx
unsigned int v6; // er14

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = (unsigned int)(v3 - 1);
for ( i = 0LL; ; ++i )
{
v6 = i;
if ( !strcmp(*(const char **)(v2 + 8 * i), s2) )
break;
if ( i == v4 )
return (unsigned int)-1;
}
return v6;
}

original_code:
int find_string(char * str, struct string_list * slp)
{
  int i;
  int n = slp->endp - slp->str;
  for(i=0; i<n; ++i) {
    if (strcmp((slp->str)[i], str)==0) return i;
  }
  return -1;
}

canonical_original_code:
int find_string(char *str, struct string_list *slp)
{
  int i;
  int n = slp->endp - slp->str;
  for(i=0; i<n; ++i) {
    if (strcmp((slp->str)[i], str)==0) return i;
  }
  return -1;
}


decompiled_code:
__int64 __fastcall has_sub_string(char *s1, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rax
__int64 v4; // r15
__int64 i; // rbx
unsigned int v6; // er14
const char *v7; // rbp
size_t v8; // rax

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = (unsigned int)(v3 - 1);
for ( i = 0LL; ; ++i )
{
v6 = i;
v7 = *(const char **)(v2 + 8 * i);
v8 = strlen(v7);
if ( !strncmp(s1, v7, v8) )
break;
if ( i == v4 )
return (unsigned int)-1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s1, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rax
__int64 v4; // r15
__int64 i; // rbx
unsigned int v6; // er14
const char *v7; // rbp
size_t v8; // rax

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = (unsigned int)(v3 - 1);
for ( i = 0LL; ; ++i )
{
v6 = i;
v7 = *(const char **)(v2 + 8 * i);
v8 = strlen(v7);
if ( !strncmp(s1, v7, v8) )
break;
if ( i == v4 )
return (unsigned int)-1;
}
return v6;
}

original_code:
int has_sub_string(char * str, struct string_list *slp)
{
  int i;
  int n = slp->endp - slp->str;
  for(i=0; i<n; ++i) {
    if (strncmp(str, (slp->str)[i], strlen((slp->str)[i]))==0) return i;
  }
  return -1;
}

canonical_original_code:
int has_sub_string(char *str, struct string_list *slp)
{
  int i;
  int n = slp->endp - slp->str;
  for(i=0; i<n; ++i) {
    if (strncmp(str, (slp->str)[i], strlen((slp->str)[i]))==0) return i;
  }
  return -1;
}


decompiled_code:
__int64 __fastcall has_newdir(char *s2, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rbx
size_t v4; // r12
__int64 v5; // r15
__int64 i; // rbx
unsigned int v7; // er14

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = strlen(s2);
v5 = (unsigned int)(v3 - 1);
for ( i = 0LL; ; ++i )
{
v7 = i;
if ( !strncmp(*(const char **)(v2 + 8 * i), s2, v4) )
break;
if ( i == v5 )
return (unsigned int)-1;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rbx
size_t v4; // r12
__int64 v5; // r15
__int64 i; // rbx
unsigned int v7; // er14

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = strlen(s2);
v5 = (unsigned int)(v3 - 1);
for ( i = 0LL; ; ++i )
{
v7 = i;
if ( !strncmp(*(const char **)(v2 + 8 * i), s2, v4) )
break;
if ( i == v5 )
return (unsigned int)-1;
}
return v7;
}

original_code:
int has_newdir(char *str, struct string_list *slp)
{
  int i;
  int n = slp->endp - slp->str;
  for(i=0; i<n; ++i) {
    if (strncmp((slp->str)[i],str, strlen(str))==0) return i;
  }
  return -1;
}


decompiled_code:
void *__fastcall init_uint_list(__int64 a1, int a2)
{
void *result; // rax

result = malloc(4LL * a2);
*(_QWORD *)(a1 + 16) = result;
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, int a2)
{
void *result; // rax

result = malloc(4LL * a2);
*(_QWORD *)(a1 + 16) = result;
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void init_uint_list(struct uint_list * uil_ptr, int n)
{
  uil_ptr->d = malloc(n * sizeof(unsigned int));
  uil_ptr->capacity = n;
  uil_ptr->endp = uil_ptr->d;
}

canonical_original_code:
void init_uint_list(struct uint_list *uil_ptr, int n)
{
  uil_ptr->d = malloc(n * sizeof(unsigned int));
  uil_ptr->capacity = n;
  uil_ptr->endp = uil_ptr->d;
}

variable_types: struct uint_list { int capacity; unsigned int *endp; unsigned int *d; } *


original_code:
void grow_uint_list(struct uint_list * uilp)
{
  int new_capacity = 2 * uilp->capacity;
  unsigned int * old_ptrs = uilp->d;
  unsigned int * new_ptrs;
  unsigned int * newp = malloc(new_capacity * sizeof(unsigned int));
  new_ptrs = newp;
  while (old_ptrs < uilp->endp) {
    *new_ptrs++ = *old_ptrs++;
  }
  free(uilp->d);
  uilp->d = newp;
  uilp->endp= new_ptrs;
  uilp->capacity = new_capacity;
}

canonical_original_code:
void grow_uint_list(struct uint_list *uilp)
{
  int new_capacity = 2 * uilp->capacity;
  unsigned int *old_ptrs = uilp->d;
  unsigned int *new_ptrs;
  unsigned int *newp = malloc(new_capacity * sizeof(unsigned int));
  new_ptrs = newp;
  while (old_ptrs < uilp->endp) {
    *new_ptrs++ = *old_ptrs++;
  }
  free(uilp->d);
  uilp->d = newp;
  uilp->endp= new_ptrs;
  uilp->capacity = new_capacity;
}

variable_types:
newp
unsigned int *

user_defined_types: struct uint_list { int capacity; unsigned int *endp; unsigned int *d; }


decompiled_code:
__int64 __fastcall find_unit(int a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rax
__int64 v4; // rsi
__int64 i; // rax
unsigned int v6; // edx

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 2;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = (unsigned int)(v3 - 1);
for ( i = 0LL; ; ++i )
{
v6 = i;
if ( *(_DWORD *)(v2 + 4 * i) == a1 )
break;
if ( i == v4 )
return (unsigned int)-1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rax
__int64 v4; // rsi
__int64 i; // rax
unsigned int v6; // edx

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 2;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = (unsigned int)(v3 - 1);
for ( i = 0LL; ; ++i )
{
v6 = i;
if ( *(_DWORD *)(v2 + 4 * i) == a1 )
break;
if ( i == v4 )
return (unsigned int)-1;
}
return v6;
}

original_code:
int find_unit(unsigned int data, struct uint_list * uilp)
{
  int i;
  int n = uilp->endp - uilp->d;
  for(i=0; i<n; ++i) {
    if ((uilp->d)[i] == data) return i;
  }
  return -1;
}

canonical_original_code:
int find_unit(unsigned int data, struct uint_list *uilp)
{
  int i;
  int n = uilp->endp - uilp->d;
  for(i=0; i<n; ++i) {
    if ((uilp->d)[i] == data) return i;
  }
  return -1;
}

variable_types:
data
unsigned int

variable_types: i int


decompiled_code:
void output_subs()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void output_subs(char * str)
{
  return;
}

canonical_original_code:
void output_subs(char *str)
{
  return;
}


decompiled_code:
const char *__fastcall strip(const char *a1)
{
char *v1; // rbx
const char *result; // rax
char i; // dl

v1 = (char *)a1;
result = &a1[strlen(a1) - 1];
if ( *result == 32 || *result == 10 )
{
do
{
do
*result-- = 0;
while ( *result == 32 );
}
while ( *result == 10 );
}
if ( *a1 == 32 )
{
result = a1;
do
++result;
while ( *result == 32 );
if ( a1 != result )
{
for ( i = *result; *result; i = *result )
{
++result;
*v1++ = i;
}
*v1 = 0;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func9(const char *a1)
{
char *v1; // rbx
const char *result; // rax
char i; // dl

v1 = (char *)a1;
result = &a1[strlen(a1) - 1];
if ( *result == 32 || *result == 10 )
{
do
{
do
*result-- = 0;
while ( *result == 32 );
}
while ( *result == 10 );
}
if ( *a1 == 32 )
{
result = a1;
do
++result;
while ( *result == 32 );
if ( a1 != result )
{
for ( i = *result; *result; i = *result )
{
++result;
*v1++ = i;
}
*v1 = 0;
}
}
return result;
}

variable_types:
pt
char *


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

result = pArray_ptr;
fill_ptr = pArray_ptr;
return result;
}

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

result = pArray_ptr;
fill_ptr = pArray_ptr;
return result;
}

original_code:
void init_fill_ptr()
{
  fill_ptr = pArray_ptr;
}


decompiled_code:
__int64 __fastcall update_complaint_address(__int64 a1)
{
return sock_set_addr(&complaint_addr, 16LL, a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return sock_set_addr(&complaint_addr, 16LL, a1 + 4);
}

original_code:
void update_complaint_address(struct sockaddr_in *sa)
{
  sock_set_addr((struct sockaddr *) &complaint_addr,
  sizeof(complaint_addr), (void*)&sa->sin_addr);
}

canonical_original_code:
void update_complaint_address(struct sockaddr_in *sa)
{
  sock_set_addr((struct sockaddr *) &complaint_addr,
  sizeof(complaint_addr), (void *)&sa->sin_addr);
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *


signal

decompiled_code:
__int64 __fastcall signal(int sig, void (*a2)(int))
{
int v2; // eax
bool v3; // sf
__int64 result; // rax
struct sigaction v5; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-A8h] BYREF

v6.sa_handler = a2;
sigemptyset(&v6.sa_mask);
v2 = 0x20000000;
if ( sig != 14 )
v2 = 0x10000000;
v6.sa_flags = v2;
v3 = sigaction(sig, &v6, &v5) < 0;
result = -1LL;
if ( !v3 )
result = (__int64)v5.sa_handler;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int sig, void (*a2)(int))
{
int v2; // eax
bool v3; // sf
__int64 result; // rax
struct sigaction v5; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-A8h] BYREF

v6.sa_handler = a2;
sigemptyset(&v6.sa_mask);
v2 = 0x20000000;
if ( sig != 14 )
v2 = 0x10000000;
v6.sa_flags = v2;
v3 = sigaction(sig, &v6, &v5) < 0;
result = -1LL;
if ( !v3 )
result = (__int64)v5.sa_handler;
return result;
}

original_code:
Sigfunc * signal(int signo, Sigfunc *func)
{
 struct sigaction act, oact;
 act.__sigaction_handler.sa_handler = func;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if (signo == 14) {
  act.sa_flags |= 0x20000000;
 } else {
  act.sa_flags |= 0x10000000;
 }
 if (sigaction(signo, &act, &oact) < 0)
  return(((__sighandler_t) -1));
 return(oact.__sigaction_handler.sa_handler);
}

canonical_original_code:
void (*signal(int signo, void (*func)(int)))(int)
{
 struct sigaction act; struct sigaction oact;
 act.__sigaction_handler.sa_handler = func;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if (signo == 14) {
  act.sa_flags |= 0x20000000;
 } else {
  act.sa_flags |= 0x10000000;
 }
 if (sigaction(signo, &act, &oact) < 0)
  return(((__sighandler_t) -1));
 return(oact.__sigaction_handler.sa_handler);
}

variable_types: signo int

variable_types:
func
void (*)(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: void (*)(int)


Signal

decompiled_code:
__int64 __fastcall Signal(int a1, void (*a2)(int))
{
__int64 v2; // rbx

v2 = signal(a1, a2);
if ( v2 == -1 )
perror("signal error");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, void (*a2)(int))
{
__int64 v2; // rbx

v2 = func0(a1, a2);
if ( v2 == -1 )
perror("signal error");
return v2;
}

original_code:
Sigfunc * Signal(int signo, Sigfunc *func)
{
 Sigfunc *sigfunc;
 if ( (sigfunc = signal(signo, func)) == ((__sighandler_t) -1))
  perror("signal error");
 return(sigfunc);
}

canonical_original_code:
void (*Signal(int signo, void (*func)(int)))(int)
{
 void (*sigfunc)(int);
 if ( (sigfunc = signal(signo, func)) == ((__sighandler_t) -1))
  perror("signal error");
 return(sigfunc);
}

variable_types:
sigfunc
void (*)(int)


Fcntl

decompiled_code:
__int64 Fcntl()
{
unsigned int v0; // ebx

v0 = fcntl64();
if ( v0 == -1 )
perror("fcntl error");
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx

v0 = fcntl64();
if ( v0 == -1 )
perror("fcntl error");
return v0;
}

original_code:
int Fcntl(int fd, int cmd, int arg)
{
 int n;
 if ( (n = fcntl(fd, cmd, arg)) == -1)
  perror("fcntl error");
 return(n);
}

variable_types: fd int

variable_types: cmd int

variable_types: arg int

variable_types: n int


Ioctl

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

v2 = ioctl(a1, a2);
if ( v2 == -1 )
perror("ioctl error");
return v2;
}

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

v2 = ioctl(a1, a2);
if ( v2 == -1 )
perror("ioctl error");
return v2;
}

original_code:
int Ioctl(int fd, int request, void *arg)
{
 int n;
 if ( (n = ioctl(fd, request, arg)) == -1)
  perror("ioctl error");
 return(n);
}

variable_types: request int

variable_types:
arg
void *


Sigemptyset

decompiled_code:
void __fastcall Sigemptyset(sigset_t *a1)
{
if ( sigemptyset(a1) == -1 )
perror("sigemptyset error");
}

canonical_decompiled_code:
void __fastcall func4(sigset_t *a1)
{
if ( sigemptyset(a1) == -1 )
perror("sigemptyset error");
}

original_code:
void Sigemptyset(sigset_t *set)
{
 if (sigemptyset(set) == -1)
  perror("sigemptyset error");
}

canonical_original_code:
void Sigemptyset(struct __sigset_t *set)
{
 if (sigemptyset(set) == -1)
  perror("sigemptyset error");
}

variable_types: struct __sigset_t { unsigned long __val[-1]; } *


Sigaddset

decompiled_code:
void __fastcall Sigaddset(sigset_t *a1, int a2)
{
if ( sigaddset(a1, a2) == -1 )
perror("sigaddset error");
}

canonical_decompiled_code:
void __fastcall func5(sigset_t *a1, int a2)
{
if ( sigaddset(a1, a2) == -1 )
perror("sigaddset error");
}

original_code:
void Sigaddset(sigset_t *set, int signo)
{
 if (sigaddset(set, signo) == -1)
  perror("sigaddset error");
}

canonical_original_code:
void Sigaddset(struct __sigset_t *set, int signo)
{
 if (sigaddset(set, signo) == -1)
  perror("sigaddset error");
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


Sigprocmask

decompiled_code:
void __fastcall Sigprocmask(int a1, const sigset_t *a2, sigset_t *a3)
{
if ( sigprocmask(a1, a2, a3) == -1 )
perror("sigprocmask error");
}

canonical_decompiled_code:
void __fastcall func6(int a1, const sigset_t *a2, sigset_t *a3)
{
if ( sigprocmask(a1, a2, a3) == -1 )
perror("sigprocmask error");
}

original_code:
void Sigprocmask(int how, const sigset_t *set, sigset_t *oset)
{
 if (sigprocmask(how, set, oset) == -1)
  perror("sigprocmask error");
}

canonical_original_code:
void Sigprocmask(int how, struct __sigset_t *set, struct __sigset_t *oset)
{
 if (sigprocmask(how, set, oset) == -1)
  perror("sigprocmask error");
}

variable_types: how int

variable_types:
oset
struct __sigset_t *


needBackup

decompiled_code:
__int64 __fastcall needBackup(__int64 a1)
{
__int64 result; // rax
int v2; // ebp
const char *v3; // r12
__int64 v4; // rbx

result = (unsigned int)backup;
if ( backup )
{
v2 = nPattern;
result = 1LL;
if ( nPattern )
{
v3 = (const char *)(a1 + strlen(pattern_baseDir) + 1);
if ( v2 <= 0 )
{
result = 0LL;
}
else
{
v4 = 0LL;
do
{
if ( !regexec(*(const regex_t **)(fPatterns + 8 * v4), v3, 0LL, 0LL, 0) )
return 1LL;
++v4;
}
while ( nPattern > (int)v4 );
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
int v2; // ebp
const char *v3; // r12
__int64 v4; // rbx

result = (unsigned int)backup;
if ( backup )
{
v2 = nPattern;
result = 1LL;
if ( nPattern )
{
v3 = (const char *)(a1 + strlen(pattern_baseDir) + 1);
if ( v2 <= 0 )
{
result = 0LL;
}
else
{
v4 = 0LL;
do
{
if ( !regexec(*(const regex_t **)(fPatterns + 8 * v4), v3, 0LL, 0LL, 0) )
return 1LL;
++v4;
}
while ( nPattern > (int)v4 );
result = 0LL;
}
}
}
return result;
}

original_code:
int needBackup(char * filename)
{
  int i;
  char *p;
  if (!backup) return 0;
  if (nPattern==0) return 1;
  p = filename + strlen(pattern_baseDir) + 1;
  for(i=0; i<nPattern; ++i) {
    if (regexec(fPatterns[i], p, (size_t)0, ((void *)0), 0)!=0)
      continue;
    return 1;
  }
  return 0;
}

canonical_original_code:
int needBackup(char *filename)
{
  int i;
  char *p;
  if (!backup) return 0;
  if (nPattern==0) return 1;
  p = filename + strlen(pattern_baseDir) + 1;
  for(i=0; i<nPattern; ++i) {
    if (regexec(fPatterns[i], p, (unsigned long)0, ((void *)0), 0)!=0)
      continue;
    return 1;
  }
  return 0;
}

variable_types:
filename
char *

variable_types:
p
char *


decompiled_code:
unsigned __int8 __fastcall get_dirname_of_rtt(char *dest, const char *a2)
{
char *v2; // rax
bool v3; // zf
unsigned __int8 result; // al
char *v5; // rax
char v6[4104]; // [rsp+0h] [rbp-1008h] BYREF

strcpy(v6, a2);
v2 = dirname(v6);
strcpy(dest, v2);
v3 = strcmp(dest, ".") == 0;
result = !v3;
if ( v3 )
{
v5 = getcwd(v6, 0x1000uLL);
result = (unsigned __int8)strcpy(dest, v5);
}
return result;
}

canonical_decompiled_code:
unsigned __int8 __fastcall func1(char *dest, const char *a2)
{
char *v2; // rax
bool v3; // zf
unsigned __int8 result; // al
char *v5; // rax
char v6[4104]; // [rsp+0h] [rbp-1008h] BYREF

strcpy(v6, a2);
v2 = dirname(v6);
strcpy(dest, v2);
v3 = strcmp(dest, ".") == 0;
result = !v3;
if ( v3 )
{
v5 = getcwd(v6, 0x1000uLL);
result = (unsigned __int8)strcpy(dest, v5);
}
return result;
}

original_code:
void get_dirname_of_rtt(char *dname, char *rtt_path)
{
  char path[4096];
  strcpy(path, rtt_path);
  strcpy(dname, dirname(path));
  if (strcmp(dname, ".")==0) {
    strcpy(dname, getcwd(path, 4096));
  }
}

variable_types:
dname
char *

variable_types:
path
char [4096]


usage

decompiled_code:
int usage()
{
return fprintf(
stderr,
"rtt (to measure rount trip time to a target version %s\n"
" Option list:\n"
" [ -v flag to turn on verbose]\n"
" [ -r <remote shell, default=%s> ]\n"
" [ -p <PATH for remote rttcatcher, default=%s> ]\n"
" -------- essential options ----------------------------------\n"
" -m <destination machine_name>\n"
" -n <num Of Pages>\n"
" -s <page_size in bytes; max=64512>\n"
" -------- mcast options --------------------------------------\n"
" [ -A <my_mcast_address default=%s)> ]\n"
" [ -P <my_PORT default=%d> ]\n"
" [ -T <my_TTL default=%d> ]\n"
" [ -L flag turn on mcast_LOOP. default is off ]\n"
" [ -I <my_MCAST_IF default=NULL> ]\n",
"3.1.0",
reshell,
&catcher_path,
my_MCAST_ADDR,
(unsigned int)my_PORT,
(unsigned int)my_TTL);
}

canonical_decompiled_code:
int func0()
{
return fprintf(
stderr,
"rtt (to measure rount trip time to a target version %s\n"
" Option list:\n"
" [ -v flag to turn on verbose]\n"
" [ -r <remote shell, default=%s> ]\n"
" [ -p <PATH for remote rttcatcher, default=%s> ]\n"
" -------- essential options ----------------------------------\n"
" -m <destination machine_name>\n"
" -n <num Of Pages>\n"
" -s <page_size in bytes; max=64512>\n"
" -------- mcast options --------------------------------------\n"
" [ -A <my_mcast_address default=%s)> ]\n"
" [ -P <my_PORT default=%d> ]\n"
" [ -T <my_TTL default=%d> ]\n"
" [ -L flag turn on mcast_LOOP. default is off ]\n"
" [ -I <my_MCAST_IF default=NULL> ]\n",
"3.1.0",
reshell,
&catcher_path,
my_MCAST_ADDR,
(unsigned int)my_PORT,
(unsigned int)my_TTL);
}

original_code:
void usage()
{
  fprintf(stderr,
   "rtt (to measure rount trip time to a target version %s\n"
   "   Option list:\n"
   "   [ -v flag to turn on verbose]\n"
   "   [ -r <remote shell, default=%s> ]\n"
   "   [ -p <PATH for remote rttcatcher, default=%s> ]\n"
   "   -------- essential options ----------------------------------\n"
   "     -m <destination machine_name>\n"
   "     -n <num Of Pages>\n"
   "     -s <page_size in bytes; max=64512>\n"
   "   -------- mcast options --------------------------------------\n"
   "   [ -A <my_mcast_address default=%s)> ]\n"
   "   [ -P <my_PORT default=%d> ]\n"
   "   [ -T <my_TTL default=%d> ]\n"
   "   [ -L flag turn on mcast_LOOP. default is off ]\n"
   "   [ -I <my_MCAST_IF default=NULL> ]\n",
   "3.1.0", reshell, catcher_path, my_MCAST_ADDR, my_PORT, my_TTL);
}


decompiled_code:
size_t __fastcall do_one_page(unsigned int a1)
{
size_t result; // rax
double v2; // xmm0_8
unsigned __int64 v3; // rbp

refresh_timer();
start_timer();
send_page(a1);
if ( (unsigned int)read_handle_complaint() )
{
end_timer();
update_time_accumulator();
v2 = get_accumulated_usec();
if ( v2 >= 9.223372036854776e18 )
v3 = (unsigned int)(int)(v2 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v3 = (unsigned int)(int)v2;
if ( verbose > 1 )
printf("rtt(p = %d) = %ld (usec)\n", a1, v3);
result = update_rtt_hist((unsigned int)v3);
no_feedback_count = 0;
}
else
{
if ( verbose )
fprintf(stderr, "no ack for page = %d\n", a1);
++no_feedback_count;
result = update_rtt_hist(999999LL);
if ( no_feedback_count > 5 )
{
result = fwrite("Consecutive non_feedback exceeds limit. Continue with next page...\n", 1uLL, 0x43uLL, stderr);
no_feedback_count = 0;
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(unsigned int a1)
{
size_t result; // rax
double v2; // xmm0_8
unsigned __int64 v3; // rbp

refresh_timer();
start_timer();
send_page(a1);
if ( (unsigned int)read_handle_complaint() )
{
end_timer();
update_time_accumulator();
v2 = get_accumulated_usec();
if ( v2 >= 9.223372036854776e18 )
v3 = (unsigned int)(int)(v2 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v3 = (unsigned int)(int)v2;
if ( verbose > 1 )
printf("rtt(p = %d) = %ld (usec)\n", a1, v3);
result = update_rtt_hist((unsigned int)v3);
no_feedback_count = 0;
}
else
{
if ( verbose )
fprintf(stderr, "no ack for page = %d\n", a1);
++no_feedback_count;
result = update_rtt_hist(999999LL);
if ( no_feedback_count > 5 )
{
result = fwrite("Consecutive non_feedback exceeds limit. Continue with next page...\n", 1uLL, 0x43uLL, stderr);
no_feedback_count = 0;
}
}
return result;
}

original_code:
void do_one_page(int page)
{
  unsigned long rtt;
  refresh_timer();
  start_timer();
  send_page(page);
  if (read_handle_complaint()==0) {
    if (verbose) fprintf(stderr, "no ack for page = %d\n", page);
    ++no_feedback_count;
    update_rtt_hist(999999);
    if (no_feedback_count>5) {
      fprintf(stderr, "Consecutive non_feedback exceeds limit. Continue with next page...\n");
      no_feedback_count = 0;
    }
  } else {
    end_timer();
    update_time_accumulator();
    rtt = get_accumulated_usec();
    if (verbose>=2) printf("rtt(p = %d) = %ld (usec)\n", page, rtt);
    update_rtt_hist(rtt);
    no_feedback_count = 0;
  }
}

variable_types: page int

variable_types:
rtt
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
int v5; // eax
unsigned int i; // ebx
int result; // eax

verbose = 0;
catcher_path = 0;
v3 = -1;
v4 = -1;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "vm:s:n:r:p:A:P:T:LI:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case '?':
usage();
exit(-1);
case 'A':
my_MCAST_ADDR = optarg;
break;
case 'I':
my_IFname = (__int64)optarg;
break;
case 'L':
my_LOOP = 1;
break;
case 'P':
my_PORT = atoi(optarg);
my_FLOW_PORT = my_PORT - 1;
break;
case 'T':
my_TTL = atoi(optarg);
break;
case 'm':
machine = (__int64)optarg;
break;
case 'n':
v4 = atoi(optarg);
break;
case 'p':
strcpy(&catcher_path, optarg);
break;
case 'r':
reshell = optarg;
break;
case 's':
v3 = atoi(optarg);
if ( v3 > 64512 )
{
usage();
exit(-1);
}
return result;
case 'v':
verbose = 1;
break;
default:
continue;
}
}
if ( !catcher_path )
get_dirname_of_rtt(&catcher_path, *argv);
if ( v4 == -1 || v3 == -1 || !machine )
{
fwrite("Essential options (-n -m -s) should be specified. \n", 1uLL, 0x33uLL, stderr);
usage();
exit(-1);
}
init_sends((unsigned int)v3);
init_complaints();
Signal(2LL, &do_cntl_c);
remote_pid = invoke_catcher((const char *)machine);
fprintf(stderr, "remote pid = %d\n", (unsigned int)remote_pid);
sleep(1u);
init_missing_page_flag((unsigned int)v4);
send_cmd(4LL, (unsigned int)v4);
refresh_machine_status();
wait_for_ok(4LL);
do_badMachines_exit(machine, (unsigned int)remote_pid);
fwrite("Sending data...\n", 1uLL, 0x10uLL, stderr);
set_mode(2LL);
set_delay(0LL, 400000LL);
no_feedback_count = 0;
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
do_one_page(i);
}
send_cmd(5LL, 0LL);
refresh_machine_status();
wait_for_ok(5LL);
do_badMachines_exit(&unk_1745, 0xFFFFFFFFLL);
free_missing_page_flag();
send_done_and_pr_msgs();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
int v5; // eax
unsigned int i; // ebx
int result; // eax

verbose = 0;
catcher_path = 0;
v3 = -1;
v4 = -1;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "vm:s:n:r:p:A:P:T:LI:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case '?':
func0();
exit(-1);
case 'A':
my_MCAST_ADDR = optarg;
break;
case 'I':
my_IFname = (__int64)optarg;
break;
case 'L':
my_LOOP = 1;
break;
case 'P':
my_PORT = atoi(optarg);
my_FLOW_PORT = my_PORT - 1;
break;
case 'T':
my_TTL = atoi(optarg);
break;
case 'm':
machine = (__int64)optarg;
break;
case 'n':
v4 = atoi(optarg);
break;
case 'p':
strcpy(&catcher_path, optarg);
break;
case 'r':
reshell = optarg;
break;
case 's':
v3 = atoi(optarg);
if ( v3 > 64512 )
{
func0();
exit(-1);
}
return result;
case 'v':
verbose = 1;
break;
default:
continue;
}
}
if ( !catcher_path )
func1(&catcher_path, *argv);
if ( v4 == -1 || v3 == -1 || !machine )
{
fwrite("Essential options (-n -m -s) should be specified. \n", 1uLL, 0x33uLL, stderr);
func0();
exit(-1);
}
init_sends((unsigned int)v3);
init_complaints();
Signal(2LL, &do_cntl_c);
remote_pid = func3((const char *)machine);
fprintf(stderr, "remote pid = %d\n", (unsigned int)remote_pid);
sleep(1u);
init_missing_page_flag((unsigned int)v4);
send_cmd(4LL, (unsigned int)v4);
refresh_machine_status();
wait_for_ok(4LL);
do_badMachines_exit(machine, (unsigned int)remote_pid);
fwrite("Sending data...\n", 1uLL, 0x10uLL, stderr);
set_mode(2LL);
set_delay(0LL, 400000LL);
no_feedback_count = 0;
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
func2(i);
}
send_cmd(5LL, 0LL);
refresh_machine_status();
wait_for_ok(5LL);
do_badMachines_exit(&unk_1745, 0xFFFFFFFFLL);
free_missing_page_flag();
send_done_and_pr_msgs();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int c;
  int nPages =-1, pageSize=-1, ipage;
  verbose = 0;
  catcher_path[0] = '\0';
  while ((c = getopt(argc, argv, "vm:s:n:r:p:A:P:T:LI:")) != (-1)) {
    switch (c) {
    case 'v':
      verbose = 1;
      break;
    case 'r':
      reshell = optarg;
      break;
    case 'p':
      strcpy(catcher_path, optarg);
      break;
    case 'A':
      my_MCAST_ADDR = optarg;
      break;
    case 'P':
      my_PORT = atoi(optarg);
      my_FLOW_PORT = my_PORT -1;
      break;
    case 'T':
      my_TTL = atoi(optarg);
      break;
    case 'L':
      my_LOOP = 1;
      break;
    case 'I':
      my_IFname = optarg;
      break;
    case 'n' :
      nPages = atoi(optarg);
      break;
    case 'm':
      machine = optarg;
      break;
    case 's':
      pageSize = atoi(optarg);
      if (pageSize>64512) {
 usage();
 exit(-1);
      }
      break;
    case '?':
      usage();
      exit(-1);
    }
  }
  if (strlen(catcher_path)==0) {
    get_dirname_of_rtt(catcher_path, argv[0]);
  }
  if (nPages == -1 || pageSize == -1 || machine == ((void *)0)) {
    fprintf(stderr, "Essential options (-n -m -s) should be specified. \n");
    usage();
    exit(-1);
  }
  init_sends(pageSize);
  init_complaints();
  Signal(2, do_cntl_c);
  remote_pid = invoke_catcher(machine);
  fprintf(stderr, "remote pid = %d\n", remote_pid);
  sleep(1);
  init_missing_page_flag(nPages);
  send_cmd(4, nPages);
  refresh_machine_status();
  wait_for_ok(4);
  do_badMachines_exit(machine, remote_pid);
  fprintf(stderr, "Sending data...\n");
  set_mode(2);
  set_delay(0, 8000*50);
  no_feedback_count = 0;
  for (ipage = 0; ipage < nPages; ipage++){
    do_one_page(ipage);
  }
  send_cmd(5, 0);
  refresh_machine_status();
  wait_for_ok(5);
  do_badMachines_exit("", -1);
  free_missing_page_flag();
  send_done_and_pr_msgs();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int c;
  int nPages = -1; int pageSize = -1; int ipage;
  verbose = 0;
  catcher_path[0] = '\0';
  while ((c = getopt(argc, argv, "vm:s:n:r:p:A:P:T:LI:")) != (-1)) {
    switch (c) {
    case 'v':
      verbose = 1;
      break;
    case 'r':
      reshell = optarg;
      break;
    case 'p':
      strcpy(catcher_path, optarg);
      break;
    case 'A':
      my_MCAST_ADDR = optarg;
      break;
    case 'P':
      my_PORT = atoi(optarg);
      my_FLOW_PORT = my_PORT -1;
      break;
    case 'T':
      my_TTL = atoi(optarg);
      break;
    case 'L':
      my_LOOP = 1;
      break;
    case 'I':
      my_IFname = optarg;
      break;
    case 'n' :
      nPages = atoi(optarg);
      break;
    case 'm':
      machine = optarg;
      break;
    case 's':
      pageSize = atoi(optarg);
      if (pageSize>64512) {
 usage();
 exit(-1);
      }
      break;
    case '?':
      usage();
      exit(-1);
    }
  }
  if (strlen(catcher_path)==0) {
    get_dirname_of_rtt(catcher_path, argv[0]);
  }
  if (nPages == -1 || pageSize == -1 || machine == ((void *)0)) {
    fprintf(stderr, "Essential options (-n -m -s) should be specified. \n");
    usage();
    exit(-1);
  }
  init_sends(pageSize);
  init_complaints();
  Signal(2, do_cntl_c);
  remote_pid = invoke_catcher(machine);
  fprintf(stderr, "remote pid = %d\n", remote_pid);
  sleep(1);
  init_missing_page_flag(nPages);
  send_cmd(4, nPages);
  refresh_machine_status();
  wait_for_ok(4);
  do_badMachines_exit(machine, remote_pid);
  fprintf(stderr, "Sending data...\n");
  set_mode(2);
  set_delay(0, 8000*50);
  no_feedback_count = 0;
  for (ipage = 0; ipage < nPages; ipage++){
    do_one_page(ipage);
  }
  send_cmd(5, 0);
  refresh_machine_status();
  wait_for_ok(5);
  do_badMachines_exit("", -1);
  free_missing_page_flag();
  send_done_and_pr_msgs();
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: nPages int

variable_types: pageSize int

variable_types: ipage int


decompiled_code:
void *__fastcall id2name(int a1)
{
void *result; // rax

result = &unk_15B;
if ( machine_names )
result = *(void **)(machine_names + 8LL * a1);
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
void *result; // rax

result = &unk_15B;
if ( machine_names )
result = *(void **)(machine_names + 8LL * a1);
return result;
}

original_code:
char * id2name(int id)
{
  return (machine_names) ? machine_names[id] : "";
}

canonical_original_code:
char *id2name(int id)
{
  return (machine_names) ? machine_names[id] : "";
}

variable_types: id int


decompiled_code:
void free_missing_page_flag()
{
free(missing_page_flag);
missing_page_flag = 0LL;
}

canonical_decompiled_code:
void func4()
{
free(missing_page_flag);
missing_page_flag = 0LL;
}

original_code:
void free_missing_page_flag()
{
  free(missing_page_flag);
  missing_page_flag = ((void *)0);
}


decompiled_code:
_BOOL8 __fastcall is_it_missing(int a1)
{
return *((_BYTE *)missing_page_flag + a1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(int a1)
{
return *((_BYTE *)missing_page_flag + a1) == 0;
}

original_code:
int is_it_missing(int page)
{
  return (missing_page_flag[page]=='\0') ? 1 : 0;
}


decompiled_code:
int kill_pid()
{
char v1[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v1, "%s %s 'kill -9 %d'", reshell, machine, remote_pid);
fwrite("To make sure we clean up the process on remote machine,\n", 1uLL, 0x38uLL, stderr);
fprintf(stderr, "%s\n", v1);
return system(v1);
}

canonical_decompiled_code:
int func14()
{
char v1[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v1, "%s %s 'kill -9 %d'", reshell, machine, remote_pid);
fwrite("To make sure we clean up the process on remote machine,\n", 1uLL, 0x38uLL, stderr);
fprintf(stderr, "%s\n", v1);
return system(v1);
}

original_code:
void kill_pid()
{
  char cmd[100];
  sprintf(cmd, "%s %s 'kill -9 %d'", reshell, machine, remote_pid);
  fprintf(stderr, "To make sure we clean up the process on remote machine,\n");
  fprintf(stderr, "%s\n", cmd);
  system(cmd);
}

variable_types:
cmd
char [100]


getbits

original_code:
static inline
uint32_t getbits(unsigned char* bp, int pos, int nbits)
{
   ((void) sizeof ((pos < 8 && nbits <= 32) ? 1 : 0), __extension__ ({ if (pos < 8 && nbits <= 32) ; else __assert_fail ("pos < 8 && nbits <= 32", "wgdos.c", 42, __extension__ __PRETTY_FUNCTION__); }));
   uint32_t res = 0;
   int more = nbits;
   while (1) {
      int bits = ((8 - pos) < more) ? 8 - pos : more;
      uint8_t mask = ((1 << bits) - 1) << (8 - pos - bits);
      uint8_t val = (*bp & mask) >> (8 - pos - bits);
      more -= bits;
      res |= val << more;
      if (!more) break;
      bp++; pos = 0;
   }
   return res;
}

canonical_original_code:
static inline unsigned int getbits(unsigned char *bp, int pos, int nbits)
{
   ((void) sizeof ((pos < 8 && nbits <= 32) ? 1 : 0), __extension__ ({ if (pos < 8 && nbits <= 32) ; else __assert_fail ("pos < 8 && nbits <= 32", "wgdos.c", 42, __extension__ __PRETTY_FUNCTION__); }));
   unsigned int res = 0;
   int more = nbits;
   while (1) {
      int bits = ((8 - pos) < more) ? 8 - pos : more;
      unsigned char mask = ((1 << bits) - 1) << (8 - pos - bits);
      unsigned char val = (*bp & mask) >> (8 - pos - bits);
      more -= bits;
      res |= val << more;
      if (!more) break;
      bp++; pos = 0;
   }
   return res;
}

variable_types:
bp
unsigned char *

variable_types: pos int

variable_types: nbits int

variable_types:
res
unsigned int

variable_types: more int

variable_types: bits int

variable_types:
mask
unsigned char

variable_types:
val
unsigned char


decompiled_code:
__int64 __fastcall byteswap32(_DWORD *a1)
{
int v1; // eax

v1 = (*a1 << 24) | HIBYTE(*a1);
BYTE1(v1) = BYTE2(*a1);
return ((unsigned __int8)BYTE1(*a1) << 16) | v1 & 0xFF00FFFF;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
int v1; // eax

v1 = (*a1 << 24) | HIBYTE(*a1);
BYTE1(v1) = BYTE2(*a1);
return ((unsigned __int8)BYTE1(*a1) << 16) | v1 & 0xFF00FFFF;
}

original_code:
uint32_t byteswap32(unsigned char bytes[4])
{
   W32 in;
   memcpy(&in.b, bytes, 4);
   unsigned char tmp = in.b[0];
   in.b[0] = in.b[3];
   in.b[3] = tmp;
   tmp = in.b[1];
   in.b[1] = in.b[2];
   in.b[2] = tmp;
   return in.w;
}

canonical_original_code:
unsigned int byteswap32(unsigned char bytes[4])
{
   union W32 in;
   memcpy(&in.b, bytes, 4);
   unsigned char tmp = in.b[0];
   in.b[0] = in.b[3];
   in.b[3] = tmp;
   tmp = in.b[1];
   in.b[1] = in.b[2];
   in.b[2] = tmp;
   return in.w;
}

variable_types:
bytes
unsigned char [4]

variable_types: union W32 { unsigned int w; unsigned char b[4]; }

variable_types:
tmp
unsigned char


decompiled_code:
__int16 __fastcall byteswap16(_WORD *a1)
{
__int16 result; // ax

LOBYTE(result) = HIBYTE(*a1);
HIBYTE(result) = *a1;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func2(_WORD *a1)
{
__int16 result; // ax

LOBYTE(result) = HIBYTE(*a1);
HIBYTE(result) = *a1;
return result;
}

original_code:
uint16_t byteswap16(unsigned char bytes[2])
{
   W16 in;
   memcpy(&in.b, bytes, 2);
   unsigned char tmp = in.b[0];
   in.b[0] = in.b[1];
   in.b[1] = tmp;
   return in.w;
}

canonical_original_code:
unsigned short byteswap16(unsigned char bytes[2])
{
   union W16 in;
   memcpy(&in.b, bytes, 2);
   unsigned char tmp = in.b[0];
   in.b[0] = in.b[1];
   in.b[1] = tmp;
   return in.w;
}

variable_types:
bytes
unsigned char [2]

variable_types: union W16 { unsigned short w; unsigned char b[2]; }

return_type: unsigned short


readBitmap

decompiled_code:
__int64 __fastcall readBitmap(unsigned __int8 *a1, int a2, int a3, char a4, __int64 a5, __int64 a6, float a7)
{
unsigned __int8 v8; // al
__int64 result; // rax
__int64 v10; // rcx
__int64 i; // rdx

v8 = *a1;
if ( a4 )
v8 = ~*a1;
result = v8 << a2;
if ( a3 > 0 )
{
v10 = (unsigned int)a3;
for ( i = 0LL; i != v10; ++i )
{
if ( (result & 0x80u) != 0LL )
{
*(float *)(a5 + 4 * i) = a7;
*(_BYTE *)(a6 + i) = 1;
}
if ( a2 > 6 )
{
result = a1[1];
if ( a4 )
result = (unsigned int)~(_DWORD)result;
++a1;
a2 = 0;
}
else
{
result = (unsigned int)(2 * result);
++a2;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1, int a2, int a3, char a4, __int64 a5, __int64 a6, float a7)
{
unsigned __int8 v8; // al
__int64 result; // rax
__int64 v10; // rcx
__int64 i; // rdx

v8 = *a1;
if ( a4 )
v8 = ~*a1;
result = v8 << a2;
if ( a3 > 0 )
{
v10 = (unsigned int)a3;
for ( i = 0LL; i != v10; ++i )
{
if ( (result & 0x80u) != 0LL )
{
*(float *)(a5 + 4 * i) = a7;
*(_BYTE *)(a6 + i) = 1;
}
if ( a2 > 6 )
{
result = a1[1];
if ( a4 )
result = (unsigned int)~(_DWORD)result;
++a1;
a2 = 0;
}
else
{
result = (unsigned int)(2 * result);
++a2;
}
}
}
return result;
}

original_code:
void readBitmap(unsigned char* bp, int start, int cols, _Bool reverse, float value, float data[], _Bool bmap[])
{
   int i, pos;
   unsigned char byte;
   byte = *bp;
   if (reverse) byte = ~byte;
   byte <<= start;
   pos = start;
   for ( i=0; i < cols; ++i) {
      if (byte & 0x80) {
         data[i] = value;
         bmap[i] = 1;
      }
      if (pos < 7) {
         byte <<= 1;
         pos++;
      } else {
         byte = *++bp;
         if (reverse) byte = ~byte;
         pos = 0;
      }
   }
}

canonical_original_code:
void readBitmap(unsigned char *bp, int start, int cols, _Bool reverse, float value, float data[], _Bool bmap[])
{
   int i; int pos;
   unsigned char byte;
   byte = *bp;
   if (reverse) byte = ~byte;
   byte <<= start;
   pos = start;
   for ( i=0; i < cols; ++i) {
      if (byte & 0x80) {
         data[i] = value;
         bmap[i] = 1;
      }
      if (pos < 7) {
         byte <<= 1;
         pos++;
      } else {
         byte = *++bp;
         if (reverse) byte = ~byte;
         pos = 0;
      }
   }
}

variable_types: start int

variable_types: cols int

variable_types: value float

variable_types:
data
float []

variable_types:
bmap
_Bool []

variable_types: i int

variable_types:
byte
unsigned char


original_code:
void construct_lon_array( int ny, float *lon ) {
     int i, j, ind;
     double tlat, tlon, tol, degtorad, sock, cpart, t1, t2, longitude, latitude;
     double pseudolat, pseudolon;
     if ( header[3]<99 ) {
        for ( j=0; j<ny; j++ ) {
        for ( i=0; i<int_constants[5]; i++ ) {
            ind = j*int_constants[5] + i;
            tlon = real_constants[3] + real_constants[0]*((double ) i);
            lon[ind] = (float ) tlon;
        }
        }
     } else {
        degtorad=3.1415926535898/180.0;
        pseudolat = real_constants[4] * degtorad;
        pseudolon = real_constants[5] * degtorad;
        for ( j=0; j<ny; j++ ) {
        for ( i=0; i<int_constants[5]; i++ ) {
             tlat = (real_constants[2] + real_constants[1]*((double ) j))*degtorad;
             tlon = (real_constants[3] + real_constants[0]*((double ) i))*degtorad;
             sock = pseudolon - 3.1415926535898;
             tol = pseudolon*pseudolon;
             if ( tol<1.0e-20 ) { sock = 0; }
             cpart = cos(tlon) * cos(tlat);
             latitude = asin((cos(pseudolat)*cpart)+(sin(pseudolat)*sin(tlat)));
             t1 = -cos(pseudolat)*sin(tlat);
             t2 = sin(pseudolat)*cpart;
             tol = (cos(latitude)+(t1+t2)) * (cos(latitude)+(t1+t2));
             if ( tol<=1.0e-16 ) { longitude = 3.1415926535898; }
             else { longitude = -acos((t1+t2)/cos(latitude)); }
             if ( (tlon>-1.0e-20) && (tlon<3.1415926535898001) ) { longitude = -1.0*longitude; }
             longitude += sock;
             if ( longitude<0.0 ) { longitude += 2.0*3.1415926535898; }
             lon[i+int_constants[5]*j] = (float ) (longitude / degtorad);
        }
        }
     }
     return;
}

canonical_original_code:
void construct_lon_array(int ny, float *lon) {
     int i; int j; int ind;
     double tlat; double tlon; double tol; double degtorad; double sock; double cpart; double t1; double t2; double longitude; double latitude;
     double pseudolat; double pseudolon;
     if ( header[3]<99 ) {
        for ( j=0; j<ny; j++ ) {
        for ( i=0; i<int_constants[5]; i++ ) {
            ind = j*int_constants[5] + i;
            tlon = real_constants[3] + real_constants[0]*((double ) i);
            lon[ind] = (float ) tlon;
        }
        }
     } else {
        degtorad=3.1415926535898/180.0;
        pseudolat = real_constants[4] * degtorad;
        pseudolon = real_constants[5] * degtorad;
        for ( j=0; j<ny; j++ ) {
        for ( i=0; i<int_constants[5]; i++ ) {
             tlat = (real_constants[2] + real_constants[1]*((double ) j))*degtorad;
             tlon = (real_constants[3] + real_constants[0]*((double ) i))*degtorad;
             sock = pseudolon - 3.1415926535898;
             tol = pseudolon*pseudolon;
             if ( tol<1.0e-20 ) { sock = 0; }
             cpart = cos(tlon) * cos(tlat);
             latitude = asin((cos(pseudolat)*cpart)+(sin(pseudolat)*sin(tlat)));
             t1 = -cos(pseudolat)*sin(tlat);
             t2 = sin(pseudolat)*cpart;
             tol = (cos(latitude)+(t1+t2)) * (cos(latitude)+(t1+t2));
             if ( tol<=1.0e-16 ) { longitude = 3.1415926535898; }
             else { longitude = -acos((t1+t2)/cos(latitude)); }
             if ( (tlon>-1.0e-20) && (tlon<3.1415926535898001) ) { longitude = -1.0*longitude; }
             longitude += sock;
             if ( longitude<0.0 ) { longitude += 2.0*3.1415926535898; }
             lon[i+int_constants[5]*j] = (float ) (longitude / degtorad);
        }
        }
     }
     return;
}

variable_types: ny int

variable_types:
lon
float *

variable_types: j int

variable_types: ind int

variable_types: tlat double

variable_types: tlon double

variable_types: tol double

variable_types: degtorad double

variable_types: sock double

variable_types: cpart double

variable_types: longitude double

variable_types: latitude double

variable_types: pseudolat double

variable_types: pseudolon double


decompiled_code:
void __fastcall construct_lat_array(int a1, __int64 a2)
{
int j; // ecx
__int64 v3; // rax
__int64 v4; // rdx
float v5; // xmm0_4
__int64 v6; // r12
__int64 i; // rbx
float v8; // xmm0_4
double v9; // [rsp+8h] [rbp-60h]
double v10; // [rsp+10h] [rbp-58h]
double v11; // [rsp+18h] [rbp-50h]
double cosx; // [rsp+20h] [rbp-48h] BYREF
double sinx[8]; // [rsp+28h] [rbp-40h] BYREF

if ( header[3] > 98 )
{
sincos(0.01745329251994333 * real_constants[4], sinx, &cosx);
v10 = cosx;
v11 = sinx[0];
if ( int_constants[5] > 0 )
{
v6 = 0LL;
do
{
v9 = cos(((double)(int)v6 * real_constants[0] + real_constants[3]) * 0.01745329251994333);
if ( a1 > 0 )
{
for ( i = 0LL; i != a1; *(float *)(a2 + 4 * (v6 + int_constants[5] * i++)) = v8 )
{
sincos(((double)(int)i * real_constants[1] + real_constants[2]) * 0.01745329251994333, sinx, &cosx);
v8 = asin(v9 * cosx * v10 + v11 * sinx[0]) / 0.01745329251994333;
}
}
++v6;
}
while ( v6 < int_constants[5] );
}
}
else if ( a1 > 0 )
{
for ( j = 0; j != a1; ++j )
{
v3 = int_constants[5];
if ( v3 > 0 )
{
v4 = 0LL;
v5 = (double)j * real_constants[1] + real_constants[2];
do
{
*(float *)(a2 + 4LL * ((int)v4 + j * (int)v3)) = v5;
v3 = int_constants[5];
++v4;
}
while ( v3 > v4 );
}
}
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, __int64 a2)
{
int j; // ecx
__int64 v3; // rax
__int64 v4; // rdx
float v5; // xmm0_4
__int64 v6; // r12
__int64 i; // rbx
float v8; // xmm0_4
double v9; // [rsp+8h] [rbp-60h]
double v10; // [rsp+10h] [rbp-58h]
double v11; // [rsp+18h] [rbp-50h]
double cosx; // [rsp+20h] [rbp-48h] BYREF
double sinx[8]; // [rsp+28h] [rbp-40h] BYREF

if ( header[3] > 98 )
{
sincos(0.01745329251994333 * real_constants[4], sinx, &cosx);
v10 = cosx;
v11 = sinx[0];
if ( int_constants[5] > 0 )
{
v6 = 0LL;
do
{
v9 = cos(((double)(int)v6 * real_constants[0] + real_constants[3]) * 0.01745329251994333);
if ( a1 > 0 )
{
for ( i = 0LL; i != a1; *(float *)(a2 + 4 * (v6 + int_constants[5] * i++)) = v8 )
{
sincos(((double)(int)i * real_constants[1] + real_constants[2]) * 0.01745329251994333, sinx, &cosx);
v8 = asin(v9 * cosx * v10 + v11 * sinx[0]) / 0.01745329251994333;
}
}
++v6;
}
while ( v6 < int_constants[5] );
}
}
else if ( a1 > 0 )
{
for ( j = 0; j != a1; ++j )
{
v3 = int_constants[5];
if ( v3 > 0 )
{
v4 = 0LL;
v5 = (double)j * real_constants[1] + real_constants[2];
do
{
*(float *)(a2 + 4LL * ((int)v4 + j * (int)v3)) = v5;
v3 = int_constants[5];
++v4;
}
while ( v3 > v4 );
}
}
}
}

original_code:
void construct_lat_array( int ny, float *lat ) {
     int i, j, ind;
     double tlat, tlon, degtorad, sock, cpart, latitude;
     double pseudolat, pseudolon, cos_pseudolat, sin_pseudolat;
     if ( header[3]<99 ) {
        for ( j=0; j<ny; j++ ) {
            tlat = real_constants[2] + real_constants[1]*((double ) j);
            for ( i=0; i<int_constants[5]; i++ ) {
                ind = j*int_constants[5] + i;
                lat[ind] = (float ) tlat;
            }
        }
     } else {
        degtorad=3.1415926535898/180.0;
        pseudolat = real_constants[4] * degtorad;
        pseudolon = real_constants[5] * degtorad;
        cos_pseudolat = cos( pseudolat );
        sin_pseudolat = sin( pseudolat );
        if ( pseudolon==0 ) { sock = 0.0; }
        else { sock = pseudolon - 3.1415926535898; }
        for ( i=0; i<int_constants[5]; i++) {
            tlon = ( real_constants[3] + ((double ) i)*real_constants[0] )*degtorad;
            tlon = cos( tlon );
            for ( j=0; j<ny; j++) {
                tlat = ( real_constants[2] + ((double ) j)*real_constants[1] )*degtorad;
                cpart = tlon*cos(tlat);
                latitude = asin( cos_pseudolat*cpart + sin_pseudolat*sin(tlat) );
                lat[i+int_constants[5]*j] = (float ) (latitude / degtorad);
            }
        }
     }
     return;
}

canonical_original_code:
void construct_lat_array(int ny, float *lat) {
     int i; int j; int ind;
     double tlat; double tlon; double degtorad; double sock; double cpart; double latitude;
     double pseudolat; double pseudolon; double cos_pseudolat; double sin_pseudolat;
     if ( header[3]<99 ) {
        for ( j=0; j<ny; j++ ) {
            tlat = real_constants[2] + real_constants[1]*((double ) j);
            for ( i=0; i<int_constants[5]; i++ ) {
                ind = j*int_constants[5] + i;
                lat[ind] = (float ) tlat;
            }
        }
     } else {
        degtorad=3.1415926535898/180.0;
        pseudolat = real_constants[4] * degtorad;
        pseudolon = real_constants[5] * degtorad;
        cos_pseudolat = cos( pseudolat );
        sin_pseudolat = sin( pseudolat );
        if ( pseudolon==0 ) { sock = 0.0; }
        else { sock = pseudolon - 3.1415926535898; }
        for ( i=0; i<int_constants[5]; i++) {
            tlon = ( real_constants[3] + ((double ) i)*real_constants[0] )*degtorad;
            tlon = cos( tlon );
            for ( j=0; j<ny; j++) {
                tlat = ( real_constants[2] + ((double ) j)*real_constants[1] )*degtorad;
                cpart = tlon*cos(tlat);
                latitude = asin( cos_pseudolat*cpart + sin_pseudolat*sin(tlat) );
                lat[i+int_constants[5]*j] = (float ) (latitude / degtorad);
            }
        }
     }
     return;
}

variable_types:
lat
float *