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

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; // rbx

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

canonical_name: main

repo: addisonw/mrsync-mac

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
unsigned int v7; // edi

v3 = -1;
v4 = -1;
catcher_path = 0;
verbose = 0;
while ( 2 )
{
v5 = getopt(argc, (char *const *)argv, "vm:s:n:r:p:A:P:T:LI:");
if ( v5 != -1 )
{
switch ( v5 )
{
case '?':
goto LABEL_6;
case 'A':
my_MCAST_ADDR = optarg;
continue;
case 'I':
my_IFname = (__int64)optarg;
continue;
case 'L':
my_LOOP = 1;
continue;
case 'P':
my_PORT = atoi(optarg);
my_FLOW_PORT = my_PORT - 1;
continue;
case 'T':
my_TTL = atoi(optarg);
continue;
case 'm':
machine = (__int64)optarg;
continue;
case 'n':
v4 = atoi(optarg);
continue;
case 'p':
strcpy(&catcher_path, optarg);
continue;
case 'r':
reshell = optarg;
continue;
case 's':
v3 = atoi(optarg);
if ( v3 > 64512 )
goto LABEL_6;
continue;
case 'v':
verbose = 1;
continue;
default:
continue;
}
}
break;
}
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);
LABEL_6:
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 )
{
v7 = i;
do_one_page(v7);
}
}
send_cmd(5LL, 0LL);
refresh_machine_status();
wait_for_ok(5LL);
do_badMachines_exit(&unk_1443, 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
unsigned int v7; // edi

v3 = -1;
v4 = -1;
catcher_path = 0;
verbose = 0;
while ( 2 )
{
v5 = getopt(argc, (char *const *)argv, "vm:s:n:r:p:A:P:T:LI:");
if ( v5 != -1 )
{
switch ( v5 )
{
case '?':
goto LABEL_6;
case 'A':
my_MCAST_ADDR = optarg;
continue;
case 'I':
my_IFname = (__int64)optarg;
continue;
case 'L':
my_LOOP = 1;
continue;
case 'P':
my_PORT = atoi(optarg);
my_FLOW_PORT = my_PORT - 1;
continue;
case 'T':
my_TTL = atoi(optarg);
continue;
case 'm':
machine = (__int64)optarg;
continue;
case 'n':
v4 = atoi(optarg);
continue;
case 'p':
strcpy(&catcher_path, optarg);
continue;
case 'r':
reshell = optarg;
continue;
case 's':
v3 = atoi(optarg);
if ( v3 > 64512 )
goto LABEL_6;
continue;
case 'v':
verbose = 1;
continue;
default:
continue;
}
}
break;
}
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);
LABEL_6:
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 )
{
v7 = i;
func2(v7);
}
}
send_cmd(5LL, 0LL);
refresh_machine_status();
wait_for_ok(5LL);
do_badMachines_exit(&unk_1443, 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

return_type: int


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

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

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

result = &unk_19B;
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

return_type: char *


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

return_type: void


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

return_type: unsigned int


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 v7; // al
__int64 result; // rax
__int64 v10; // rcx
__int64 v11; // rdx

v7 = *a1;
if ( a4 )
v7 = ~*a1;
result = v7 << a2;
if ( a3 > 0 )
{
v10 = a3;
v11 = 0LL;
do
{
while ( 1 )
{
if ( (result & 0x80u) != 0LL )
{
*(float *)(a5 + 4 * v11) = a7;
*(_BYTE *)(a6 + v11) = 1;
}
if ( a2 > 6 )
break;
result = (unsigned int)(2 * result);
++a2;
LABEL_6:
if ( v10 == ++v11 )
return result;
}
result = a1[1];
if ( !a4 )
{
++a1;
a2 = 0;
goto LABEL_6;
}
++v11;
++a1;
result = (unsigned int)~(_DWORD)result;
a2 = 0;
}
while ( v10 != v11 );
}
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 v7; // al
__int64 result; // rax
__int64 v10; // rcx
__int64 v11; // rdx

v7 = *a1;
if ( a4 )
v7 = ~*a1;
result = v7 << a2;
if ( a3 > 0 )
{
v10 = a3;
v11 = 0LL;
do
{
while ( 1 )
{
if ( (result & 0x80u) != 0LL )
{
*(float *)(a5 + 4 * v11) = a7;
*(_BYTE *)(a6 + v11) = 1;
}
if ( a2 > 6 )
break;
result = (unsigned int)(2 * result);
++a2;
LABEL_6:
if ( v10 == ++v11 )
return result;
}
result = a1[1];
if ( !a4 )
{
++a1;
a2 = 0;
goto LABEL_6;
}
++v11;
++a1;
result = (unsigned int)~(_DWORD)result;
a2 = 0;
}
while ( v10 != v11 );
}
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


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 *


original_code:
void construct_lon_bounds_array( int ny, float *lon ) {
     int i, j, k, ind;
     double tlat, tlon, tol, degtorad, sock, cpart, t1, t2, longitude, latitude;
     double pseudolat, pseudolon, cos_pseudolat, sin_pseudolat, factor;
     if ( header[3]<99 ) {
        for ( j=0; j<ny; j++ ) {
        for ( i=0; i<int_constants[5]; i++ ) {
            tlon = real_constants[3] + real_constants[0]*((double ) i);
            t1 = tlon - 0.5*real_constants[0];
            ind = j*int_constants[5] + i;
            lon[ind] = (float ) t1;
            ind += int_constants[5]*ny;
            lon[ind] = (float ) t1;
            t1 = tlon + 0.5*real_constants[0];
            ind += int_constants[5]*ny;
            lon[ind] = (float ) t1;
            ind += int_constants[5]*ny;
            lon[ind] = (float ) t1;
        }
        }
     } 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++) {
        for ( j=0; j<ny; j++) {
        for ( k=1; k<5; k++ ) {
            switch( k ){
                  case 1:
                       tlon = ( real_constants[3] + ((double ) i - 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j - 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 2:
                       tlon = ( real_constants[3] + ((double ) i - 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j + 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 3:
                       tlon = ( real_constants[3] + ((double ) i + 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j + 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 4:
                       tlon = ( real_constants[3] + ((double ) i + 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j - 0.5)*real_constants[1] )*degtorad;
                       break;
            }
            factor = 1.0;
            if ( (tlon>-1.0e-20) && (tlon<3.14159265358001) ) { factor = -1.0; }
            tlon = cos( tlon );
            cpart = 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)); }
            longitude = factor*longitude + sock;
            if ( longitude<0.0 ) { longitude += 2.0*3.1415926535898; }
            ind = (k-1)*ny*int_constants[5] + int_constants[5]*j + i;
            lon[ind] = (float ) (longitude / degtorad);
        }
        }
        }
     }
     return;
}

canonical_original_code:
void construct_lon_bounds_array(int ny, float *lon) {
     int i; int j; int k; 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; double cos_pseudolat; double sin_pseudolat; double factor;
     if ( header[3]<99 ) {
        for ( j=0; j<ny; j++ ) {
        for ( i=0; i<int_constants[5]; i++ ) {
            tlon = real_constants[3] + real_constants[0]*((double ) i);
            t1 = tlon - 0.5*real_constants[0];
            ind = j*int_constants[5] + i;
            lon[ind] = (float ) t1;
            ind += int_constants[5]*ny;
            lon[ind] = (float ) t1;
            t1 = tlon + 0.5*real_constants[0];
            ind += int_constants[5]*ny;
            lon[ind] = (float ) t1;
            ind += int_constants[5]*ny;
            lon[ind] = (float ) t1;
        }
        }
     } 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++) {
        for ( j=0; j<ny; j++) {
        for ( k=1; k<5; k++ ) {
            switch( k ){
                  case 1:
                       tlon = ( real_constants[3] + ((double ) i - 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j - 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 2:
                       tlon = ( real_constants[3] + ((double ) i - 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j + 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 3:
                       tlon = ( real_constants[3] + ((double ) i + 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j + 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 4:
                       tlon = ( real_constants[3] + ((double ) i + 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j - 0.5)*real_constants[1] )*degtorad;
                       break;
            }
            factor = 1.0;
            if ( (tlon>-1.0e-20) && (tlon<3.14159265358001) ) { factor = -1.0; }
            tlon = cos( tlon );
            cpart = 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)); }
            longitude = factor*longitude + sock;
            if ( longitude<0.0 ) { longitude += 2.0*3.1415926535898; }
            ind = (k-1)*ny*int_constants[5] + int_constants[5]*j + i;
            lon[ind] = (float ) (longitude / degtorad);
        }
        }
        }
     }
     return;
}

variable_types: i int

variable_types: k int

variable_types: factor double


original_code:
void construct_lat_bounds_array( int ny, float *lat ) {
     int i, j, k, ind;
     double tlat, tlon, degtorad, sock, cpart, t1, t2, 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);
            t1 = tlat - 0.5*real_constants[1];
            t2 = tlat + 0.5*real_constants[1];
            for ( i=0; i<int_constants[5]; i++ ) {
                ind = j*int_constants[5] + i;
                lat[ind] = (float ) t1;
                ind += int_constants[5]*ny;
                lat[ind] = (float ) t2;
                ind += int_constants[5]*ny;
                lat[ind] = (float ) t2;
                ind += int_constants[5]*ny;
                lat[ind] = (float ) t1;
            }
        }
     } 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++) {
        for ( j=0; j<ny; j++) {
        for ( k=1; k<5; k++ ) {
            switch( k ){
                  case 1:
                       tlon = ( real_constants[3] + ((double ) i - 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j - 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 2:
                       tlon = ( real_constants[3] + ((double ) i - 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j + 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 3:
                       tlon = ( real_constants[3] + ((double ) i + 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j + 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 4:
                       tlon = ( real_constants[3] + ((double ) i + 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j - 0.5)*real_constants[1] )*degtorad;
                       break;
            }
            tlon = cos( tlon );
            cpart = tlon*cos(tlat);
            latitude = asin( cos_pseudolat*cpart + sin_pseudolat*sin(tlat) );
            ind = (k-1)*ny*int_constants[5] + int_constants[5]*j + i;
            lat[ind] = (float ) (latitude / degtorad);
        }
        }
        }
     }
     return;
}

canonical_original_code:
void construct_lat_bounds_array(int ny, float *lat) {
     int i; int j; int k; int ind;
     double tlat; double tlon; double degtorad; double sock; double cpart; double t1; double t2; 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);
            t1 = tlat - 0.5*real_constants[1];
            t2 = tlat + 0.5*real_constants[1];
            for ( i=0; i<int_constants[5]; i++ ) {
                ind = j*int_constants[5] + i;
                lat[ind] = (float ) t1;
                ind += int_constants[5]*ny;
                lat[ind] = (float ) t2;
                ind += int_constants[5]*ny;
                lat[ind] = (float ) t2;
                ind += int_constants[5]*ny;
                lat[ind] = (float ) t1;
            }
        }
     } 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++) {
        for ( j=0; j<ny; j++) {
        for ( k=1; k<5; k++ ) {
            switch( k ){
                  case 1:
                       tlon = ( real_constants[3] + ((double ) i - 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j - 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 2:
                       tlon = ( real_constants[3] + ((double ) i - 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j + 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 3:
                       tlon = ( real_constants[3] + ((double ) i + 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j + 0.5)*real_constants[1] )*degtorad;
                       break;
                  case 4:
                       tlon = ( real_constants[3] + ((double ) i + 0.5)*real_constants[0] )*degtorad;
                       tlat = ( real_constants[2] + ((double ) j - 0.5)*real_constants[1] )*degtorad;
                       break;
            }
            tlon = cos( tlon );
            cpart = tlon*cos(tlat);
            latitude = asin( cos_pseudolat*cpart + sin_pseudolat*sin(tlat) );
            ind = (k-1)*ny*int_constants[5] + int_constants[5]*j + i;
            lat[ind] = (float ) (latitude / degtorad);
        }
        }
        }
     }
     return;
}

variable_types: ny int


decompiled_code:
void __fastcall construct_lat_lon_arrays(unsigned int a1)
{
__int64 v1; // rbx
void *v2; // r12
void *v3; // r12
int v4; // ebx
__int64 v5; // r13
void *v6; // r12
void *v7; // r12
unsigned int v8; // [rsp+0h] [rbp-38h] BYREF
unsigned int v9; // [rsp+4h] [rbp-34h] BYREF
__int64 v10[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = int_constants[6];
v2 = malloc(4 * (int)v1 * int_constants[5]);
construct_lon_array(v1, (__int64)v2);
nc_inq_varid(a1, "longitude", &v8);
nc_put_var_float(a1, v8, v2);
construct_lat_array(v1, (__int64)v2);
nc_inq_varid(a1, "latitude", &v8);
nc_put_var_float(a1, v8, v2);
free(v2);
v3 = malloc(16 * (int)v1 * int_constants[5]);
construct_lon_bounds_array(v1, (__int64)v3);
nc_inq_varid(a1, "longitude_cell_bnd", &v8);
nc_put_var_float(a1, v8, v3);
construct_lat_bounds_array(v1, (__int64)v3);
nc_inq_varid(a1, "latitude_cell_bnd", &v8);
nc_put_var_float(a1, v8, v3);
free(v3);
if ( !(unsigned int)nc_inq_dimid(a1, "rlat0", &v9) )
{
nc_inq_dimlen(a1, v9, v10);
v4 = v10[0];
v5 = SLODWORD(v10[0]);
v6 = malloc(4 * SLODWORD(v10[0]) * int_constants[5]);
construct_lon_array(v4, (__int64)v6);
nc_inq_varid(a1, "longitude0", &v8);
nc_put_var_float(a1, v8, v6);
construct_lat_array(v4, (__int64)v6);
nc_inq_varid(a1, "latitude0", &v8);
nc_put_var_float(a1, v8, v6);
free(v6);
v7 = malloc(16 * v5 * int_constants[5]);
construct_lon_bounds_array(v4, (__int64)v7);
nc_inq_varid(a1, "longitude_cell_bnd0", &v8);
nc_put_var_float(a1, v8, v7);
construct_lat_bounds_array(v4, (__int64)v7);
nc_inq_varid(a1, "latitude_cell_bnd0", &v8);
nc_put_var_float(a1, v8, v7);
free(v7);
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned int a1)
{
__int64 v1; // rbx
void *v2; // r12
void *v3; // r12
int v4; // ebx
__int64 v5; // r13
void *v6; // r12
void *v7; // r12
unsigned int v8; // [rsp+0h] [rbp-38h] BYREF
unsigned int v9; // [rsp+4h] [rbp-34h] BYREF
__int64 v10[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = int_constants[6];
v2 = malloc(4 * (int)v1 * int_constants[5]);
func0(v1, (__int64)v2);
nc_inq_varid(a1, "longitude", &v8);
nc_put_var_float(a1, v8, v2);
func1(v1, (__int64)v2);
nc_inq_varid(a1, "latitude", &v8);
nc_put_var_float(a1, v8, v2);
free(v2);
v3 = malloc(16 * (int)v1 * int_constants[5]);
func2(v1, (__int64)v3);
nc_inq_varid(a1, "longitude_cell_bnd", &v8);
nc_put_var_float(a1, v8, v3);
func3(v1, (__int64)v3);
nc_inq_varid(a1, "latitude_cell_bnd", &v8);
nc_put_var_float(a1, v8, v3);
free(v3);
if ( !(unsigned int)nc_inq_dimid(a1, "rlat0", &v9) )
{
nc_inq_dimlen(a1, v9, v10);
v4 = v10[0];
v5 = SLODWORD(v10[0]);
v6 = malloc(4 * SLODWORD(v10[0]) * int_constants[5]);
func0(v4, (__int64)v6);
nc_inq_varid(a1, "longitude0", &v8);
nc_put_var_float(a1, v8, v6);
func1(v4, (__int64)v6);
nc_inq_varid(a1, "latitude0", &v8);
nc_put_var_float(a1, v8, v6);
free(v6);
v7 = malloc(16 * v5 * int_constants[5]);
func2(v4, (__int64)v7);
nc_inq_varid(a1, "longitude_cell_bnd0", &v8);
nc_put_var_float(a1, v8, v7);
func3(v4, (__int64)v7);
nc_inq_varid(a1, "latitude_cell_bnd0", &v8);
nc_put_var_float(a1, v8, v7);
free(v7);
}
}

original_code:
void construct_lat_lon_arrays( int ncid ) {
     int varID, ierr, ny, dimid;
     float *buf;
     size_t dimlength;
     ny = (int ) int_constants[6];
     buf = (float *) malloc( int_constants[5]*ny*sizeof(float) );
     construct_lon_array( ny, buf );
     ierr = nc_inq_varid( ncid, "longitude", &varID );
     ierr = nc_put_var_float( ncid, varID, buf );
     construct_lat_array( ny, buf );
     ierr = nc_inq_varid( ncid, "latitude", &varID );
     ierr = nc_put_var_float( ncid, varID, buf );
     free( buf );
     buf = (float *) malloc( 4*int_constants[5]*ny*sizeof(float) );
     construct_lon_bounds_array( ny, buf );
     ierr = nc_inq_varid( ncid, "longitude_cell_bnd", &varID );
     ierr = nc_put_var_float( ncid, varID, buf );
     construct_lat_bounds_array( ny, buf );
     ierr = nc_inq_varid( ncid, "latitude_cell_bnd", &varID );
     ierr = nc_put_var_float( ncid, varID, buf );
     free( buf );
     ierr = nc_inq_dimid( ncid, "rlat0", &dimid );
     if ( ierr==0 ) {
        ierr = nc_inq_dimlen( ncid, dimid, &dimlength );
        ny = (int ) dimlength;
        buf = (float *) malloc( int_constants[5]*ny*sizeof(float) );
        construct_lon_array( ny, buf );
        ierr = nc_inq_varid( ncid, "longitude0", &varID );
        ierr = nc_put_var_float( ncid, varID, buf );
        construct_lat_array( ny, buf );
        ierr = nc_inq_varid( ncid, "latitude0", &varID );
        ierr = nc_put_var_float( ncid, varID, buf );
        free( buf );
        buf = (float *) malloc( 4*int_constants[5]*ny*sizeof(float) );
        construct_lon_bounds_array( ny, buf );
        ierr = nc_inq_varid( ncid, "longitude_cell_bnd0", &varID );
        ierr = nc_put_var_float( ncid, varID, buf );
        construct_lat_bounds_array( ny, buf );
        ierr = nc_inq_varid( ncid, "latitude_cell_bnd0", &varID );
        ierr = nc_put_var_float( ncid, varID, buf );
        free( buf );
     }
     return;
}

canonical_original_code:
void construct_lat_lon_arrays(int ncid) {
     int varID; int ierr; int ny; int dimid;
     float *buf;
     unsigned long dimlength;
     ny = (int ) int_constants[6];
     buf = (float *) malloc( int_constants[5]*ny*sizeof(float) );
     construct_lon_array( ny, buf );
     ierr = nc_inq_varid( ncid, "longitude", &varID );
     ierr = nc_put_var_float( ncid, varID, buf );
     construct_lat_array( ny, buf );
     ierr = nc_inq_varid( ncid, "latitude", &varID );
     ierr = nc_put_var_float( ncid, varID, buf );
     free( buf );
     buf = (float *) malloc( 4*int_constants[5]*ny*sizeof(float) );
     construct_lon_bounds_array( ny, buf );
     ierr = nc_inq_varid( ncid, "longitude_cell_bnd", &varID );
     ierr = nc_put_var_float( ncid, varID, buf );
     construct_lat_bounds_array( ny, buf );
     ierr = nc_inq_varid( ncid, "latitude_cell_bnd", &varID );
     ierr = nc_put_var_float( ncid, varID, buf );
     free( buf );
     ierr = nc_inq_dimid( ncid, "rlat0", &dimid );
     if ( ierr==0 ) {
        ierr = nc_inq_dimlen( ncid, dimid, &dimlength );
        ny = (int ) dimlength;
        buf = (float *) malloc( int_constants[5]*ny*sizeof(float) );
        construct_lon_array( ny, buf );
        ierr = nc_inq_varid( ncid, "longitude0", &varID );
        ierr = nc_put_var_float( ncid, varID, buf );
        construct_lat_array( ny, buf );
        ierr = nc_inq_varid( ncid, "latitude0", &varID );
        ierr = nc_put_var_float( ncid, varID, buf );
        free( buf );
        buf = (float *) malloc( 4*int_constants[5]*ny*sizeof(float) );
        construct_lon_bounds_array( ny, buf );
        ierr = nc_inq_varid( ncid, "longitude_cell_bnd0", &varID );
        ierr = nc_put_var_float( ncid, varID, buf );
        construct_lat_bounds_array( ny, buf );
        ierr = nc_inq_varid( ncid, "latitude_cell_bnd0", &varID );
        ierr = nc_put_var_float( ncid, varID, buf );
        free( buf );
     }
     return;
}

variable_types: ncid int

variable_types: varID int

variable_types: ierr int

variable_types: dimid int

variable_types:
buf
float *

variable_types:
dimlength
unsigned long


decompiled_code:
__int64 __fastcall set_soil_levels(unsigned int a1, int a2, int a3)
{
__int64 v3; // r12
char *v6; // rax
unsigned __int16 *v7; // rcx
void *v8; // r13
float *v9; // rdx
char *v10; // rsi
__int64 v11; // rdi
int v12; // eax
float v13; // xmm0_4
unsigned int v14; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v15; // [rsp+10h] [rbp-38h] BYREF
char s[52]; // [rsp+14h] [rbp-34h] BYREF

v3 = a3;
sprintf(s, "soil_level%d", (unsigned int)a2);
if ( !(unsigned int)nc_inq_dimid(a1, s, &v15) )
return v15;
nc_def_dim(a1, s, a2, &v15);
nc_def_var(a1, s, 5LL, 1LL, &v15, &v14);
nc_put_att_text(a1, v14, "standard_name", 5LL, "depth");
nc_put_att_text(a1, v14, "units", 6LL, "meters");
nc_put_att_text(a1, v14, "positive", 4LL, "down");
nc_put_att_text(a1, v14, "axis", 1LL, "Z");
nc_enddef(a1);
v6 = (char *)calloc(a2, 4uLL);
v8 = v6;
if ( a2 > 0 )
{
v9 = (float *)v6;
v10 = &v6[4 * a2];
v11 = *(_QWORD *)(level_constants + 24);
v7 = (unsigned __int16 *)(**(_QWORD **)(stored_um_vars + 144 * v3 + 128) + 2LL);
do
{
v12 = *v7;
++v9;
v7 += 80;
v13 = *(double *)(v11 + 8LL * (v12 - 1));
*(v9 - 1) = v13;
}
while ( v10 != (char *)v9 );
}
nc_put_var_float(a1, v14, v8, v7);
free(v8);
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2, int a3)
{
__int64 v3; // r12
char *v6; // rax
unsigned __int16 *v7; // rcx
void *v8; // r13
float *v9; // rdx
char *v10; // rsi
__int64 v11; // rdi
int v12; // eax
float v13; // xmm0_4
unsigned int v14; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v15; // [rsp+10h] [rbp-38h] BYREF
char s[52]; // [rsp+14h] [rbp-34h] BYREF

v3 = a3;
sprintf(s, "soil_level%d", (unsigned int)a2);
if ( !(unsigned int)nc_inq_dimid(a1, s, &v15) )
return v15;
nc_def_dim(a1, s, a2, &v15);
nc_def_var(a1, s, 5LL, 1LL, &v15, &v14);
nc_put_att_text(a1, v14, "standard_name", 5LL, "depth");
nc_put_att_text(a1, v14, "units", 6LL, "meters");
nc_put_att_text(a1, v14, "positive", 4LL, "down");
nc_put_att_text(a1, v14, "axis", 1LL, "Z");
nc_enddef(a1);
v6 = (char *)calloc(a2, 4uLL);
v8 = v6;
if ( a2 > 0 )
{
v9 = (float *)v6;
v10 = &v6[4 * a2];
v11 = *(_QWORD *)(level_constants + 24);
v7 = (unsigned __int16 *)(**(_QWORD **)(stored_um_vars + 144 * v3 + 128) + 2LL);
do
{
v12 = *v7;
++v9;
v7 += 80;
v13 = *(double *)(v11 + 8LL * (v12 - 1));
*(v9 - 1) = v13;
}
while ( v10 != (char *)v9 );
}
nc_put_var_float(a1, v14, v8, v7);
free(v8);
return v15;
}

original_code:
int set_soil_levels( int ncid, int n, int id ) {
     int ierr, i, var_id, dim_id[1], nn;
     char dim_name[12];
     float *buf;
     sprintf( dim_name, "soil_level%d", n );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr == 0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id,"standard_name", 5, "depth" );
     ierr = nc_put_att_text( ncid, var_id, "units", 6, "meters" );
     ierr = nc_put_att_text( ncid, var_id, "positive", 4, "down" );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
     ierr = nc_enddef( ncid );
     buf = (float *) calloc( n,sizeof(float) );
     for ( i=0; i<n; i++ ) {
         nn = (int ) (stored_um_vars[id].slices[0][i].level - 1);
         buf[i] = (float ) level_constants[3][nn];
     }
     ierr = nc_put_var_float( ncid, var_id, buf );
     free( buf );
     return dim_id[0];
}

canonical_original_code:
int set_soil_levels(int ncid, int n, int id) {
     int ierr; int i; int var_id; int dim_id[1]; int nn;
     char dim_name[12];
     float *buf;
     sprintf( dim_name, "soil_level%d", n );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr == 0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id,"standard_name", 5, "depth" );
     ierr = nc_put_att_text( ncid, var_id, "units", 6, "meters" );
     ierr = nc_put_att_text( ncid, var_id, "positive", 4, "down" );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
     ierr = nc_enddef( ncid );
     buf = (float *) calloc( n,sizeof(float) );
     for ( i=0; i<n; i++ ) {
         nn = (int ) (stored_um_vars[id].slices[0][i].level - 1);
         buf[i] = (float ) level_constants[3][nn];
     }
     ierr = nc_put_var_float( ncid, var_id, buf );
     free( buf );
     return dim_id[0];
}

variable_types: n int

variable_types: id int

variable_types: nn int


decompiled_code:
__int64 __fastcall set_pressure_levels(unsigned int a1, int a2, int a3)
{
__int64 v5; // rbx
__int64 v6; // r12
int v7; // eax
unsigned int v8; // [rsp+Ch] [rbp-4Ch] BYREF
unsigned int v9; // [rsp+10h] [rbp-48h] BYREF
float v10; // [rsp+14h] [rbp-44h] BYREF
__int64 v11; // [rsp+18h] [rbp-40h] BYREF
char s[50]; // [rsp+26h] [rbp-32h] BYREF

sprintf(s, "pressure%d", (unsigned int)a2);
if ( !(unsigned int)nc_inq_dimid(a1, s, &v9) )
return v9;
nc_def_dim(a1, s, a2, &v9);
nc_def_var(a1, s, 5LL, 1LL, &v9, &v8);
nc_put_att_text(a1, v8, "units", 2LL, "Pa");
nc_put_att_text(a1, v8, "axis", 1LL, "Z");
nc_put_att_text(a1, v8, "standard_name", 12LL, "air_pressure");
nc_put_att_text(a1, v8, "positive", 4LL, "down");
nc_put_att_text(a1, v8, "long_name", 23LL, "standard level pressure");
nc_enddef(a1);
if ( a2 <= 0 )
return v9;
v5 = 0LL;
v6 = 144LL * a3;
do
{
v7 = *(unsigned __int16 *)(**(_QWORD **)(stored_um_vars + v6 + 128) + 160 * v5 + 2);
v11 = v5++;
v10 = (float)v7;
nc_put_var1_float(a1, v8, &v11, &v10);
}
while ( a2 != v5 );
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2, int a3)
{
__int64 v5; // rbx
__int64 v6; // r12
int v7; // eax
unsigned int v8; // [rsp+Ch] [rbp-4Ch] BYREF
unsigned int v9; // [rsp+10h] [rbp-48h] BYREF
float v10; // [rsp+14h] [rbp-44h] BYREF
__int64 v11; // [rsp+18h] [rbp-40h] BYREF
char s[50]; // [rsp+26h] [rbp-32h] BYREF

sprintf(s, "pressure%d", (unsigned int)a2);
if ( !(unsigned int)nc_inq_dimid(a1, s, &v9) )
return v9;
nc_def_dim(a1, s, a2, &v9);
nc_def_var(a1, s, 5LL, 1LL, &v9, &v8);
nc_put_att_text(a1, v8, "units", 2LL, "Pa");
nc_put_att_text(a1, v8, "axis", 1LL, "Z");
nc_put_att_text(a1, v8, "standard_name", 12LL, "air_pressure");
nc_put_att_text(a1, v8, "positive", 4LL, "down");
nc_put_att_text(a1, v8, "long_name", 23LL, "standard level pressure");
nc_enddef(a1);
if ( a2 <= 0 )
return v9;
v5 = 0LL;
v6 = 144LL * a3;
do
{
v7 = *(unsigned __int16 *)(**(_QWORD **)(stored_um_vars + v6 + 128) + 160 * v5 + 2);
v11 = v5++;
v10 = (float)v7;
nc_put_var1_float(a1, v8, &v11, &v10);
}
while ( a2 != v5 );
return v9;
}

original_code:
int set_pressure_levels( int ncid, int n, int id ) {
     int i, ierr, var_id, dim_id[1];
     char dim_name[10];
     float pressure;
     size_t nc_index[1];
     sprintf( dim_name, "pressure%d", n );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr==0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id, "units", 2, "Pa" );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
     ierr = nc_put_att_text( ncid, var_id,"standard_name", 12, "air_pressure" );
     ierr = nc_put_att_text( ncid, var_id, "positive", 4, "down" );
     ierr = nc_put_att_text( ncid, var_id, "long_name", 23, "standard level pressure" );
     ierr = nc_enddef( ncid );
     for ( i=0; i<n; i++ ) {
         pressure = (float ) stored_um_vars[id].slices[0][i].level;
         nc_index[0] = (size_t) i;
         ierr = nc_put_var1_float( ncid, var_id, nc_index, &pressure );
     }
     return dim_id[0];
}

canonical_original_code:
int set_pressure_levels(int ncid, int n, int id) {
     int i; int ierr; int var_id; int dim_id[1];
     char dim_name[10];
     float pressure;
     unsigned long nc_index[1];
     sprintf( dim_name, "pressure%d", n );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr==0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id, "units", 2, "Pa" );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
     ierr = nc_put_att_text( ncid, var_id,"standard_name", 12, "air_pressure" );
     ierr = nc_put_att_text( ncid, var_id, "positive", 4, "down" );
     ierr = nc_put_att_text( ncid, var_id, "long_name", 23, "standard level pressure" );
     ierr = nc_enddef( ncid );
     for ( i=0; i<n; i++ ) {
         pressure = (float ) stored_um_vars[id].slices[0][i].level;
         nc_index[0] = (unsigned long) i;
         ierr = nc_put_var1_float( ncid, var_id, nc_index, &pressure );
     }
     return dim_id[0];
}

variable_types: pressure float


decompiled_code:
__int64 __fastcall set_altitude(unsigned int a1, int a2, int a3)
{
__int64 v5; // rbx
__int64 v6; // r12
int v7; // eax
unsigned int v8; // [rsp+Ch] [rbp-4Ch] BYREF
unsigned int v9; // [rsp+10h] [rbp-48h] BYREF
float v10; // [rsp+14h] [rbp-44h] BYREF
__int64 v11; // [rsp+18h] [rbp-40h] BYREF
char s[50]; // [rsp+26h] [rbp-32h] BYREF

sprintf(s, "altitude%d", (unsigned int)a2);
if ( !(unsigned int)nc_inq_dimid(a1, s, &v9) )
return v9;
nc_def_dim(a1, s, a2, &v9);
nc_def_var(a1, s, 5LL, 1LL, &v9, &v8);
nc_put_att_text(a1, v8, "units", 1LL, "m");
nc_put_att_text(a1, v8, "axis", 1LL, "Z");
nc_put_att_text(a1, v8, "standard_name", 8LL, "altitude");
nc_put_att_text(a1, v8, "positive", 2LL, "up");
nc_put_att_text(a1, v8, "long_name", 22LL, "height above sea level");
nc_enddef(a1);
if ( a2 <= 0 )
return v9;
v5 = 0LL;
v6 = 144LL * a3;
do
{
v7 = *(unsigned __int16 *)(**(_QWORD **)(stored_um_vars + v6 + 128) + 160 * v5 + 2);
v11 = v5++;
v10 = (float)v7;
nc_put_var1_float(a1, v8, &v11, &v10);
}
while ( a2 != v5 );
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2, int a3)
{
__int64 v5; // rbx
__int64 v6; // r12
int v7; // eax
unsigned int v8; // [rsp+Ch] [rbp-4Ch] BYREF
unsigned int v9; // [rsp+10h] [rbp-48h] BYREF
float v10; // [rsp+14h] [rbp-44h] BYREF
__int64 v11; // [rsp+18h] [rbp-40h] BYREF
char s[50]; // [rsp+26h] [rbp-32h] BYREF

sprintf(s, "altitude%d", (unsigned int)a2);
if ( !(unsigned int)nc_inq_dimid(a1, s, &v9) )
return v9;
nc_def_dim(a1, s, a2, &v9);
nc_def_var(a1, s, 5LL, 1LL, &v9, &v8);
nc_put_att_text(a1, v8, "units", 1LL, "m");
nc_put_att_text(a1, v8, "axis", 1LL, "Z");
nc_put_att_text(a1, v8, "standard_name", 8LL, "altitude");
nc_put_att_text(a1, v8, "positive", 2LL, "up");
nc_put_att_text(a1, v8, "long_name", 22LL, "height above sea level");
nc_enddef(a1);
if ( a2 <= 0 )
return v9;
v5 = 0LL;
v6 = 144LL * a3;
do
{
v7 = *(unsigned __int16 *)(**(_QWORD **)(stored_um_vars + v6 + 128) + 160 * v5 + 2);
v11 = v5++;
v10 = (float)v7;
nc_put_var1_float(a1, v8, &v11, &v10);
}
while ( a2 != v5 );
return v9;
}

original_code:
int set_altitude( int ncid, int n, int id ) {
     int i, ierr, var_id, dim_id[1];
     char dim_name[10];
     float height;
     size_t nc_index[1];
     sprintf( dim_name, "altitude%d", n );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr==0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id, "units", 1, "m" );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
     ierr = nc_put_att_text( ncid, var_id,"standard_name", 8, "altitude" );
     ierr = nc_put_att_text( ncid, var_id, "positive", 2, "up" );
     ierr = nc_put_att_text( ncid, var_id, "long_name", 22, "height above sea level" );
     ierr = nc_enddef( ncid );
     for ( i=0; i<n; i++ ) {
         height = (float ) stored_um_vars[id].slices[0][i].level;
         nc_index[0] = (size_t) i;
         ierr = nc_put_var1_float( ncid, var_id, nc_index, &height );
     }
     return dim_id[0];
}

canonical_original_code:
int set_altitude(int ncid, int n, int id) {
     int i; int ierr; int var_id; int dim_id[1];
     char dim_name[10];
     float height;
     unsigned long nc_index[1];
     sprintf( dim_name, "altitude%d", n );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr==0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id, "units", 1, "m" );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
     ierr = nc_put_att_text( ncid, var_id,"standard_name", 8, "altitude" );
     ierr = nc_put_att_text( ncid, var_id, "positive", 2, "up" );
     ierr = nc_put_att_text( ncid, var_id, "long_name", 22, "height above sea level" );
     ierr = nc_enddef( ncid );
     for ( i=0; i<n; i++ ) {
         height = (float ) stored_um_vars[id].slices[0][i].level;
         nc_index[0] = (unsigned long) i;
         ierr = nc_put_var1_float( ncid, var_id, nc_index, &height );
     }
     return dim_id[0];
}

variable_types: height float


decompiled_code:
__int64 __fastcall set_hybrid_levels(unsigned int a1, int a2, int a3)
{
__int64 v3; // r13
__int64 v6; // r15
float *v7; // r12
__int64 v8; // rdi
float *v9; // rax
unsigned __int16 *v10; // rdx
__int64 v11; // rcx
float v12; // xmm0_4
__int64 v13; // rcx
float *v14; // rdx
__int64 v15; // rdi
unsigned __int16 *v16; // rcx
int v17; // eax
float v18; // xmm0_4
unsigned int v19; // [rsp+Ch] [rbp-4Ch] BYREF
unsigned int v20; // [rsp+10h] [rbp-48h] BYREF
char s[65]; // [rsp+17h] [rbp-41h] BYREF

v3 = 144LL * a3;
if ( *(_WORD *)(stored_um_vars + v3 + 88) == 1 )
sprintf(s, "hybridr%d", (unsigned int)a2);
else
sprintf(s, "hybridt%d", (unsigned int)a2);
if ( (unsigned int)nc_inq_dimid(a1, s, &v20) )
{
nc_def_dim(a1, s, a2, &v20);
nc_def_var(a1, s, 5LL, 1LL, &v20, &v19);
nc_put_att_text(a1, v19, "units", 6LL, "meters");
nc_put_att_text(a1, v19, "positive", 2LL, "up");
nc_put_att_text(a1, v19, "axis", 1LL, "Z");
v6 = v3 + stored_um_vars;
if ( (unsigned __int16)(*(_WORD *)(v3 + stored_um_vars + 88) - 1) > 1u )
{
printf("WARNING: unknown vertical mesh type for STASH_CODE=%hu\n", *(unsigned __int16 *)(v6 + 56));
puts(" setting to theta-point mesh by default");
v6 = v3 + stored_um_vars;
}
v7 = (float *)malloc(4LL * a2);
if ( *(_WORD *)(v6 + 88) == 1 )
{
nc_put_att_text(a1, v19, "long_name", 40LL, "height above sea level (rho levels used)");
if ( a2 > 0 )
{
v14 = v7;
v15 = *(_QWORD *)(level_constants + 48);
v16 = (unsigned __int16 *)(**(_QWORD **)(stored_um_vars + v3 + 128) + 2LL);
do
{
v17 = *v16;
++v14;
v16 += 80;
v18 = *(double *)(v15 + 8LL * (v17 - 1));
*(v14 - 1) = v18;
}
while ( &v7[a2] != v14 );
}
}
else
{
nc_put_att_text(a1, v19, "long_name", 42LL, "height above sea level (theta levels used)");
if ( a2 > 0 )
{
v8 = *(_QWORD *)(level_constants + 32);
v9 = v7;
v10 = (unsigned __int16 *)(**(_QWORD **)(stored_um_vars + v3 + 128) + 2LL);
do
{
v11 = *v10;
++v9;
v10 += 80;
v12 = *(double *)(v8 + 8 * v11);
*(v9 - 1) = v12;
}
while ( &v7[a2] != v9 );
}
}
nc_enddef(a1);
nc_put_var_float(a1, v19, v7, v13);
free(v7);
}
return v20;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2, int a3)
{
__int64 v3; // r13
__int64 v6; // r15
float *v7; // r12
__int64 v8; // rdi
float *v9; // rax
unsigned __int16 *v10; // rdx
__int64 v11; // rcx
float v12; // xmm0_4
__int64 v13; // rcx
float *v14; // rdx
__int64 v15; // rdi
unsigned __int16 *v16; // rcx
int v17; // eax
float v18; // xmm0_4
unsigned int v19; // [rsp+Ch] [rbp-4Ch] BYREF
unsigned int v20; // [rsp+10h] [rbp-48h] BYREF
char s[65]; // [rsp+17h] [rbp-41h] BYREF

v3 = 144LL * a3;
if ( *(_WORD *)(stored_um_vars + v3 + 88) == 1 )
sprintf(s, "hybridr%d", (unsigned int)a2);
else
sprintf(s, "hybridt%d", (unsigned int)a2);
if ( (unsigned int)nc_inq_dimid(a1, s, &v20) )
{
nc_def_dim(a1, s, a2, &v20);
nc_def_var(a1, s, 5LL, 1LL, &v20, &v19);
nc_put_att_text(a1, v19, "units", 6LL, "meters");
nc_put_att_text(a1, v19, "positive", 2LL, "up");
nc_put_att_text(a1, v19, "axis", 1LL, "Z");
v6 = v3 + stored_um_vars;
if ( (unsigned __int16)(*(_WORD *)(v3 + stored_um_vars + 88) - 1) > 1u )
{
printf("WARNING: unknown vertical mesh type for STASH_CODE=%hu\n", *(unsigned __int16 *)(v6 + 56));
puts(" setting to theta-point mesh by default");
v6 = v3 + stored_um_vars;
}
v7 = (float *)malloc(4LL * a2);
if ( *(_WORD *)(v6 + 88) == 1 )
{
nc_put_att_text(a1, v19, "long_name", 40LL, "height above sea level (rho levels used)");
if ( a2 > 0 )
{
v14 = v7;
v15 = *(_QWORD *)(level_constants + 48);
v16 = (unsigned __int16 *)(**(_QWORD **)(stored_um_vars + v3 + 128) + 2LL);
do
{
v17 = *v16;
++v14;
v16 += 80;
v18 = *(double *)(v15 + 8LL * (v17 - 1));
*(v14 - 1) = v18;
}
while ( &v7[a2] != v14 );
}
}
else
{
nc_put_att_text(a1, v19, "long_name", 42LL, "height above sea level (theta levels used)");
if ( a2 > 0 )
{
v8 = *(_QWORD *)(level_constants + 32);
v9 = v7;
v10 = (unsigned __int16 *)(**(_QWORD **)(stored_um_vars + v3 + 128) + 2LL);
do
{
v11 = *v10;
++v9;
v10 += 80;
v12 = *(double *)(v8 + 8 * v11);
*(v9 - 1) = v12;
}
while ( &v7[a2] != v9 );
}
}
nc_enddef(a1);
nc_put_var_float(a1, v19, v7, v13);
free(v7);
}
return v20;
}

original_code:
int set_hybrid_levels( int ncid, int n, int id ) {
     int i, ierr, var_id, dim_id[1], z_level;
     char dim_name[9];
     float *height;
     if ( stored_um_vars[id].level_type==1 ) { sprintf( dim_name, "hybridr%d", n ); }
     else { sprintf( dim_name, "hybridt%d", n ); }
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr==0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id, "units", 6, "meters" );
     ierr = nc_put_att_text( ncid, var_id, "positive", 2, "up" );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
    if ( (stored_um_vars[id].level_type!=1)&&(stored_um_vars[id].level_type!=2) ) {
       printf( "WARNING: unknown vertical mesh type for STASH_CODE=%hu\n", stored_um_vars[id].stash_code );
       printf( "         setting to theta-point mesh by default\n" );
    }
     height = (float *) malloc( n*sizeof(float) );
     if ( stored_um_vars[id].level_type==1 ) {
        ierr = nc_put_att_text( ncid, var_id, "long_name", 40, "height above sea level (rho levels used)" );
        for ( i=0; i<n; i++ ) {
            z_level = (int ) stored_um_vars[id].slices[0][i].level - 1;
            height[i] = (float ) level_constants[6][z_level];
         }
     }
     else {
        ierr = nc_put_att_text( ncid, var_id, "long_name", 42, "height above sea level (theta levels used)" );
        for ( i=0; i<n; i++ ) {
            z_level = (int ) stored_um_vars[id].slices[0][i].level;
            height[i] = (float ) level_constants[4][z_level];
         }
     }
     ierr = nc_enddef( ncid );
     ierr = nc_put_var_float( ncid, var_id, height );
     free( height );
     return dim_id[0];
}

canonical_original_code:
int set_hybrid_levels(int ncid, int n, int id) {
     int i; int ierr; int var_id; int dim_id[1]; int z_level;
     char dim_name[9];
     float *height;
     if ( stored_um_vars[id].level_type==1 ) { sprintf( dim_name, "hybridr%d", n ); }
     else { sprintf( dim_name, "hybridt%d", n ); }
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr==0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id, "units", 6, "meters" );
     ierr = nc_put_att_text( ncid, var_id, "positive", 2, "up" );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
    if ( (stored_um_vars[id].level_type!=1)&&(stored_um_vars[id].level_type!=2) ) {
       printf( "WARNING: unknown vertical mesh type for STASH_CODE=%hu\n", stored_um_vars[id].stash_code );
       printf( "         setting to theta-point mesh by default\n" );
    }
     height = (float *) malloc( n*sizeof(float) );
     if ( stored_um_vars[id].level_type==1 ) {
        ierr = nc_put_att_text( ncid, var_id, "long_name", 40, "height above sea level (rho levels used)" );
        for ( i=0; i<n; i++ ) {
            z_level = (int ) stored_um_vars[id].slices[0][i].level - 1;
            height[i] = (float ) level_constants[6][z_level];
         }
     }
     else {
        ierr = nc_put_att_text( ncid, var_id, "long_name", 42, "height above sea level (theta levels used)" );
        for ( i=0; i<n; i++ ) {
            z_level = (int ) stored_um_vars[id].slices[0][i].level;
            height[i] = (float ) level_constants[4][z_level];
         }
     }
     ierr = nc_enddef( ncid );
     ierr = nc_put_var_float( ncid, var_id, height );
     free( height );
     return dim_id[0];
}

variable_types:
height
float *


decompiled_code:
__int64 __fastcall set_surface_levels(unsigned int a1, int a2)
{
__int64 v3; // rcx
float *v4; // r12
__int64 i; // rax
unsigned int v6; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v7; // [rsp+10h] [rbp-38h] BYREF
char s[49]; // [rsp+17h] [rbp-31h] BYREF

sprintf(s, "surface%d", (unsigned int)a2);
if ( !(unsigned int)nc_inq_dimid(a1, s, &v7) )
return v7;
nc_def_dim(a1, s, a2, &v7);
nc_def_var(a1, s, 5LL, 1LL, &v7, &v6);
nc_put_att_text(a1, v6, "axis", 1LL, "Z");
nc_enddef(a1);
v4 = (float *)malloc(4LL * a2);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
v4[i] = (float)(int)i;
}
nc_put_var_float(a1, v6, v4, v3);
free(v4);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, int a2)
{
__int64 v3; // rcx
float *v4; // r12
__int64 i; // rax
unsigned int v6; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v7; // [rsp+10h] [rbp-38h] BYREF
char s[49]; // [rsp+17h] [rbp-31h] BYREF

sprintf(s, "surface%d", (unsigned int)a2);
if ( !(unsigned int)nc_inq_dimid(a1, s, &v7) )
return v7;
nc_def_dim(a1, s, a2, &v7);
nc_def_var(a1, s, 5LL, 1LL, &v7, &v6);
nc_put_att_text(a1, v6, "axis", 1LL, "Z");
nc_enddef(a1);
v4 = (float *)malloc(4LL * a2);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
v4[i] = (float)(int)i;
}
nc_put_var_float(a1, v6, v4, v3);
free(v4);
return v7;
}

original_code:
int set_surface_levels( int ncid, int n, int id ) {
     int i, ierr, var_id, dim_id[1];
     char dim_name[9];
     float *buf;
     sprintf( dim_name, "surface%d", n );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr==0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
     ierr = nc_enddef( ncid );
     buf = (float *) malloc( n*sizeof(float) );
     for ( i=0; i<n; i++ ) { buf[i] = (float ) i; }
     ierr = nc_put_var_float( ncid, var_id, buf );
     free( buf );
     return dim_id[0];
}

canonical_original_code:
int set_surface_levels(int ncid, int n, int id) {
     int i; int ierr; int var_id; int dim_id[1];
     char dim_name[9];
     float *buf;
     sprintf( dim_name, "surface%d", n );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr==0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
     ierr = nc_enddef( ncid );
     buf = (float *) malloc( n*sizeof(float) );
     for ( i=0; i<n; i++ ) { buf[i] = (float ) i; }
     ierr = nc_put_var_float( ncid, var_id, buf );
     free( buf );
     return dim_id[0];
}


decompiled_code:
__int64 __fastcall set_sea_surface_levels(unsigned int a1, int a2)
{
__int64 v3; // rcx
float *v4; // r12
__int64 i; // rax
unsigned int v6; // [rsp+8h] [rbp-40h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-3Ch] BYREF
char s[53]; // [rsp+13h] [rbp-35h] BYREF

sprintf(s, "sea_surface%d", (unsigned int)a2);
if ( !(unsigned int)nc_inq_dimid(a1, s, &v7) )
return v7;
nc_def_dim(a1, s, a2, &v7);
nc_def_var(a1, s, 5LL, 1LL, &v7, &v6);
nc_put_att_text(a1, v6, "units", 6LL, "meters");
nc_put_att_text(a1, v6, "positive", 2LL, "up");
nc_put_att_text(a1, v6, "axis", 1LL, "Z");
nc_enddef(a1);
v4 = (float *)malloc(4LL * a2);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
v4[i] = (float)(int)i;
}
nc_put_var_float(a1, v6, v4, v3);
free(v4);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, int a2)
{
__int64 v3; // rcx
float *v4; // r12
__int64 i; // rax
unsigned int v6; // [rsp+8h] [rbp-40h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-3Ch] BYREF
char s[53]; // [rsp+13h] [rbp-35h] BYREF

sprintf(s, "sea_surface%d", (unsigned int)a2);
if ( !(unsigned int)nc_inq_dimid(a1, s, &v7) )
return v7;
nc_def_dim(a1, s, a2, &v7);
nc_def_var(a1, s, 5LL, 1LL, &v7, &v6);
nc_put_att_text(a1, v6, "units", 6LL, "meters");
nc_put_att_text(a1, v6, "positive", 2LL, "up");
nc_put_att_text(a1, v6, "axis", 1LL, "Z");
nc_enddef(a1);
v4 = (float *)malloc(4LL * a2);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
v4[i] = (float)(int)i;
}
nc_put_var_float(a1, v6, v4, v3);
free(v4);
return v7;
}

original_code:
int set_sea_surface_levels( int ncid, int n, int id ) {
     int i, ierr, var_id, dim_id[1];
     char dim_name[13];
     float *buf;
     sprintf( dim_name, "sea_surface%d", n );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr==0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id, "units", 6, "meters" );
     ierr = nc_put_att_text( ncid, var_id, "positive", 2, "up" );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
     ierr = nc_enddef( ncid );
     buf = (float *) malloc( n*sizeof(float) );
     for ( i=0; i<n; i++ ) { buf[i] = (float ) i; }
     ierr = nc_put_var_float( ncid, var_id, buf );
     free( buf );
     return dim_id[0];
}

canonical_original_code:
int set_sea_surface_levels(int ncid, int n, int id) {
     int i; int ierr; int var_id; int dim_id[1];
     char dim_name[13];
     float *buf;
     sprintf( dim_name, "sea_surface%d", n );
     ierr = nc_inq_dimid( ncid, dim_name, &dim_id[0] );
     if ( ierr==0 ) { return dim_id[0]; }
     ierr = nc_def_dim( ncid, dim_name, n, &dim_id[0] );
     ierr = nc_def_var( ncid, dim_name, 5, 1, dim_id, &var_id );
     ierr = nc_put_att_text( ncid, var_id, "units", 6, "meters" );
     ierr = nc_put_att_text( ncid, var_id, "positive", 2, "up" );
     ierr = nc_put_att_text( ncid, var_id, "axis", 1, "Z" );
     ierr = nc_enddef( ncid );
     buf = (float *) malloc( n*sizeof(float) );
     for ( i=0; i<n; i++ ) { buf[i] = (float ) i; }
     ierr = nc_put_var_float( ncid, var_id, buf );
     free( buf );
     return dim_id[0];
}


decompiled_code:
__int64 __fastcall set_vertical_dimensions(unsigned int a1)
{
__int64 v1; // rdx
__int64 v2; // rbx
__int16 v3; // r12
__int64 v4; // rsi
bool v5; // cc
__int64 v6; // rbp
unsigned __int16 *v7; // rax
int v8; // er8
int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( num_stored_um_fields > 0 )
{
v1 = stored_um_vars;
v2 = 0LL;
v3 = 0;
do
{
while ( 1 )
{
v6 = 144 * v2;
v7 = (unsigned __int16 *)(v1 + 144 * v2);
v8 = v7[31];
v10[0] = v8;
if ( v8 > 1 )
break;
v5 = num_stored_um_fields <= (int)++v2;
v7[41] = 999;
if ( v5 )
goto LABEL_11;
}
v4 = v7[34];
if ( (_WORD)v4 == 65 )
{
v3 = set_hybrid_levels(a1, v8, v2);
}
else if ( (unsigned __int16)v4 > 0x41u )
{
if ( (_WORD)v4 == 128 )
{
v3 = set_sea_surface_levels(a1, v8);
goto LABEL_8;
}
if ( (_WORD)v4 != 129 )
{
LABEL_18:
printf("ERROR: unknown vertical coordinate (%hu) for STASH CODE=%d\n\n", v4, v7[28]);
goto LABEL_8;
}
v3 = set_surface_levels(a1, v8);
}
else
{
switch ( (_WORD)v4 )
{
case 6:
v3 = set_soil_levels(a1, v8, v2);
break;
case 8:
v3 = set_pressure_levels(a1, v8, v2);
break;
case 1:
v3 = set_altitude(a1, v8, v2);
break;
default:
goto LABEL_18;
}
}
LABEL_8:
v1 = stored_um_vars;
v5 = num_stored_um_fields <= (int)++v2;
*(_WORD *)(stored_um_vars + v6 + 82) = v3;
}
while ( !v5 );
}
LABEL_11:
nc_def_dim(a1, "num_etaT_levels", header[110], v10);
return nc_def_dim(a1, "num_etaR_levels", header[110] - 1LL, v10);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 v1; // rdx
__int64 v2; // rbx
__int16 v3; // r12
__int64 v4; // rsi
bool v5; // cc
__int64 v6; // rbp
unsigned __int16 *v7; // rax
int v8; // er8
int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( num_stored_um_fields > 0 )
{
v1 = stored_um_vars;
v2 = 0LL;
v3 = 0;
do
{
while ( 1 )
{
v6 = 144 * v2;
v7 = (unsigned __int16 *)(v1 + 144 * v2);
v8 = v7[31];
v10[0] = v8;
if ( v8 > 1 )
break;
v5 = num_stored_um_fields <= (int)++v2;
v7[41] = 999;
if ( v5 )
goto LABEL_11;
}
v4 = v7[34];
if ( (_WORD)v4 == 65 )
{
v3 = func3(a1, v8, v2);
}
else if ( (unsigned __int16)v4 > 0x41u )
{
if ( (_WORD)v4 == 128 )
{
v3 = func5(a1, v8);
goto LABEL_8;
}
if ( (_WORD)v4 != 129 )
{
LABEL_18:
printf("ERROR: unknown vertical coordinate (%hu) for STASH CODE=%d\n\n", v4, v7[28]);
goto LABEL_8;
}
v3 = func4(a1, v8);
}
else
{
switch ( (_WORD)v4 )
{
case 6:
v3 = func0(a1, v8, v2);
break;
case 8:
v3 = func1(a1, v8, v2);
break;
case 1:
v3 = func2(a1, v8, v2);
break;
default:
goto LABEL_18;
}
}
LABEL_8:
v1 = stored_um_vars;
v5 = num_stored_um_fields <= (int)++v2;
*(_WORD *)(stored_um_vars + v6 + 82) = v3;
}
while ( !v5 );
}
LABEL_11:
nc_def_dim(a1, "num_etaT_levels", header[110], v10);
return nc_def_dim(a1, "num_etaR_levels", header[110] - 1LL, v10);
}

original_code:
void set_vertical_dimensions( int ncid, int rflag ) {
     int i, num_instances, dimID=0;
     for ( i=0; i<num_stored_um_fields; i++ ) {
         num_instances = stored_um_vars[i].nz;
         if ( num_instances>1 ) {
            switch ( stored_um_vars[i].lbvc ) {
                 case 1:
                      dimID = set_altitude( ncid, num_instances, i );
                      break;
                 case 6:
                      dimID = set_soil_levels( ncid, num_instances, i );
                      break;
                 case 8:
                      dimID = set_pressure_levels( ncid, num_instances, i );
                      break;
                 case 65:
                      dimID = set_hybrid_levels( ncid, num_instances, i );
                      break;
                 case 128:
                      dimID = set_sea_surface_levels( ncid, num_instances, i );
                      break;
                 case 129:
                      dimID = set_surface_levels( ncid, num_instances, i );
                      break;
                 default:
                      printf( "ERROR: unknown vertical coordinate (%hu) for STASH CODE=%d\n\n",
                              stored_um_vars[i].lbvc, stored_um_vars[i].stash_code );
                      break;
            }
            stored_um_vars[i].z_dim = (unsigned short int ) dimID;
         } else {
            stored_um_vars[i].z_dim = 999;
         }
     }
     i = nc_def_dim( ncid, "num_etaT_levels", (size_t ) header[110],
                    &num_instances );
     i = nc_def_dim( ncid, "num_etaR_levels", (size_t ) (header[110]-1),
                    &num_instances );
     return;
}

canonical_original_code:
void set_vertical_dimensions(int ncid, int rflag) {
     int i; int num_instances; int dimID = 0;
     for ( i=0; i<num_stored_um_fields; i++ ) {
         num_instances = stored_um_vars[i].nz;
         if ( num_instances>1 ) {
            switch ( stored_um_vars[i].lbvc ) {
                 case 1:
                      dimID = set_altitude( ncid, num_instances, i );
                      break;
                 case 6:
                      dimID = set_soil_levels( ncid, num_instances, i );
                      break;
                 case 8:
                      dimID = set_pressure_levels( ncid, num_instances, i );
                      break;
                 case 65:
                      dimID = set_hybrid_levels( ncid, num_instances, i );
                      break;
                 case 128:
                      dimID = set_sea_surface_levels( ncid, num_instances, i );
                      break;
                 case 129:
                      dimID = set_surface_levels( ncid, num_instances, i );
                      break;
                 default:
                      printf( "ERROR: unknown vertical coordinate (%hu) for STASH CODE=%d\n\n",
                              stored_um_vars[i].lbvc, stored_um_vars[i].stash_code );
                      break;
            }
            stored_um_vars[i].z_dim = (unsigned short ) dimID;
         } else {
            stored_um_vars[i].z_dim = 999;
         }
     }
     i = nc_def_dim( ncid, "num_etaT_levels", (unsigned long ) header[110],
                    &num_instances );
     i = nc_def_dim( ncid, "num_etaR_levels", (unsigned long ) (header[110]-1),
                    &num_instances );
     return;
}

variable_types: rflag int

variable_types: dimID int


decompiled_code:
void __fastcall construct_um_variables(unsigned int a1, int a2)
{
int v2; // eax
unsigned int v4; // er15
__int64 v5; // r14
char *v6; // rax
__int64 v7; // rdx
__int64 v8; // rcx
char *v9; // r13
__int64 v10; // rsi
unsigned __int16 *v11; // rax
unsigned __int16 v12; // dx
unsigned __int16 v13; // dx
const char *v14; // r8
__int64 v15; // rcx
__int64 v16; // rax
__int64 v17; // r12
__int64 v18; // r12
char *v19; // rax
size_t v20; // r14
_QWORD *v21; // rax
_QWORD *v22; // r12
__int64 v23; // rax
__int64 v24; // rax
void *v25; // r12
int i; // [rsp+4h] [rbp-44h] BYREF
unsigned int v27; // [rsp+8h] [rbp-40h] BYREF
int v28[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = 0;
for ( i = 0; i < num_stored_um_fields; v2 = ++i )
{
v18 = stored_um_vars + 144LL * v2;
if ( *(_WORD *)(v18 + 62) > 1u )
{
v4 = 4;
v5 = 4LL;
v6 = (char *)malloc(0x10uLL);
v7 = 12LL;
v8 = 8LL;
v9 = v6;
*(_DWORD *)v6 = *(unsigned __int16 *)(v18 + 80);
*((_DWORD *)v6 + 1) = *(unsigned __int16 *)(v18 + 82);
}
else
{
v4 = 3;
v5 = 3LL;
v19 = (char *)malloc(0xCuLL);
v7 = 8LL;
v8 = 4LL;
v9 = v19;
*(_DWORD *)v19 = *(unsigned __int16 *)(v18 + 80);
}
*(_DWORD *)&v9[v8] = *(unsigned __int16 *)(v18 + 84);
*(_DWORD *)&v9[v7] = *(unsigned __int16 *)(v18 + 86);
nc_def_var(a1, v18, *(unsigned int *)(v18 + 136), v4, v9, &v27);
free(v9);
if ( !netcdf3_flag )
{
v20 = v5;
v21 = malloc(v20 * 8);
*v21 = 1LL;
v22 = v21;
v23 = stored_um_vars + 144LL * i;
v22[v20 - 1] = *(unsigned __int16 *)(v23 + 64);
if ( a2 )
v24 = int_constants[6];
else
v24 = *(unsigned __int16 *)(v23 + 66);
v22[v20 - 2] = v24;
if ( v4 == 4 )
v22[1] = 1LL;
nc_def_var_chunking(a1, v27, 0LL, v22);
free(v22);
nc_def_var_deflate(a1, v27, 1LL, 1LL, 3LL);
}
v10 = v27;
v11 = (unsigned __int16 *)(stored_um_vars + 144LL * i);
v12 = v11[37];
if ( v12 == 101 )
{
nc_put_att_text(a1, v27, "grid_mapping", 12LL, "rotated_pole");
v10 = v27;
}
else if ( v12 != 1 )
{
goto LABEL_7;
}
nc_put_att_text(a1, v10, "coordinates", 18LL, "latitude longitude");
v10 = v27;
v11 = (unsigned __int16 *)(stored_um_vars + 144LL * i);
LABEL_7:
v13 = v11[39];
if ( !v13 )
goto LABEL_14;
v14 = "longitude:derivative";
v15 = 20LL;
if ( v13 != 8 )
{
v14 = "latitude:derivative";
v15 = 19LL;
if ( v13 != 16 )
{
v14 = "longitude:mean";
v15 = 14LL;
if ( v13 != 64 )
{
if ( v13 == 128 )
{
if ( v11[36] )
{
v14 = "time:sum";
LABEL_21:
v15 = 8LL;
goto LABEL_22;
}
v14 = "time:mean";
v15 = 9LL;
}
else
{
v14 = "time:min";
if ( v13 == 4096 )
goto LABEL_21;
if ( v13 != 0x2000 )
{
LABEL_14:
v16 = v11[29];
if ( (_WORD)v16 == 9999 )
goto LABEL_23;
goto LABEL_15;
}
v14 = "time:max";
v15 = 8LL;
}
}
}
}
LABEL_22:
nc_put_att_text(a1, v10, "cell_method", v15, v14);
v10 = v27;
v16 = *(unsigned __int16 *)(stored_um_vars + 144LL * i + 58);
if ( (_WORD)v16 == 9999 )
{
LABEL_23:
i = 1;
nc_put_att_int(a1, v10, "stash_model", 4LL, 1LL, &i);
i = *(unsigned __int16 *)(stored_um_vars + 144LL * i + 56) / 0x3E8u;
nc_put_att_int(a1, v27, "stash_section", 4LL, 1LL, &i);
i = *(unsigned __int16 *)(stored_um_vars + 144LL * i + 56) - i;
nc_put_att_int(a1, v27, "stash_item", 4LL, 1LL, &i);
v28[0] = 1120403456;
nc_put_att_float(a1, v27, "valid_max", 5LL, 1LL, v28);
v28[0] = 0;
nc_put_att_float(a1, v27, "valid_min", 5LL, 1LL, v28);
nc_put_att_text(a1, v27, "long_name", 16LL, "unknown UM field");
nc_put_att_text(a1, v27, "standard_name", 16LL, "unknown_UM_field");
nc_put_att_text(a1, v27, "units", 7LL, "unknown");
continue;
}
LABEL_15:
v17 = 292 * v16;
nc_put_att_int(a1, v10, "stash_model", 4LL, 1LL, (char *)um_vars + 292 * v16 + 4);
nc_put_att_int(a1, v27, "stash_section", 4LL, 1LL, (char *)um_vars + v17 + 8);
nc_put_att_int(a1, v27, "stash_item", 4LL, 1LL, (char *)um_vars + v17);
nc_put_att_float(a1, v27, "valid_max", 5LL, 1LL, (char *)um_vars + v17 + 24);
nc_put_att_float(a1, v27, "valid_min", 5LL, 1LL, (char *)um_vars + v17 + 28);
nc_put_att_text(a1, v27, "long_name", 100LL, (char *)um_vars + v17 + 89);
nc_put_att_text(a1, v27, "standard_name", 75LL, (char *)um_vars + v17 + 189);
nc_put_att_text(a1, v27, "units", 25LL, (char *)um_vars + v17 + 264);
}
v25 = malloc(4uLL);
nc_inq_dimid(a1, "num_etaT_levels", v25);
nc_def_var(a1, "eta_theta", 5LL, 1LL, v25, &v27);
nc_inq_dimid(a1, "num_etaR_levels", v25);
nc_def_var(a1, "eta_rho", 5LL, 1LL, v25, &v27);
free(v25);
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1, int a2)
{
int v2; // eax
unsigned int v4; // er15
__int64 v5; // r14
char *v6; // rax
__int64 v7; // rdx
__int64 v8; // rcx
char *v9; // r13
__int64 v10; // rsi
unsigned __int16 *v11; // rax
unsigned __int16 v12; // dx
unsigned __int16 v13; // dx
const char *v14; // r8
__int64 v15; // rcx
__int64 v16; // rax
__int64 v17; // r12
__int64 v18; // r12
char *v19; // rax
size_t v20; // r14
_QWORD *v21; // rax
_QWORD *v22; // r12
__int64 v23; // rax
__int64 v24; // rax
void *v25; // r12
int i; // [rsp+4h] [rbp-44h] BYREF
unsigned int v27; // [rsp+8h] [rbp-40h] BYREF
int v28[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = 0;
for ( i = 0; i < num_stored_um_fields; v2 = ++i )
{
v18 = stored_um_vars + 144LL * v2;
if ( *(_WORD *)(v18 + 62) > 1u )
{
v4 = 4;
v5 = 4LL;
v6 = (char *)malloc(0x10uLL);
v7 = 12LL;
v8 = 8LL;
v9 = v6;
*(_DWORD *)v6 = *(unsigned __int16 *)(v18 + 80);
*((_DWORD *)v6 + 1) = *(unsigned __int16 *)(v18 + 82);
}
else
{
v4 = 3;
v5 = 3LL;
v19 = (char *)malloc(0xCuLL);
v7 = 8LL;
v8 = 4LL;
v9 = v19;
*(_DWORD *)v19 = *(unsigned __int16 *)(v18 + 80);
}
*(_DWORD *)&v9[v8] = *(unsigned __int16 *)(v18 + 84);
*(_DWORD *)&v9[v7] = *(unsigned __int16 *)(v18 + 86);
nc_def_var(a1, v18, *(unsigned int *)(v18 + 136), v4, v9, &v27);
free(v9);
if ( !netcdf3_flag )
{
v20 = v5;
v21 = malloc(v20 * 8);
*v21 = 1LL;
v22 = v21;
v23 = stored_um_vars + 144LL * i;
v22[v20 - 1] = *(unsigned __int16 *)(v23 + 64);
if ( a2 )
v24 = int_constants[6];
else
v24 = *(unsigned __int16 *)(v23 + 66);
v22[v20 - 2] = v24;
if ( v4 == 4 )
v22[1] = 1LL;
nc_def_var_chunking(a1, v27, 0LL, v22);
free(v22);
nc_def_var_deflate(a1, v27, 1LL, 1LL, 3LL);
}
v10 = v27;
v11 = (unsigned __int16 *)(stored_um_vars + 144LL * i);
v12 = v11[37];
if ( v12 == 101 )
{
nc_put_att_text(a1, v27, "grid_mapping", 12LL, "rotated_pole");
v10 = v27;
}
else if ( v12 != 1 )
{
goto LABEL_7;
}
nc_put_att_text(a1, v10, "coordinates", 18LL, "latitude longitude");
v10 = v27;
v11 = (unsigned __int16 *)(stored_um_vars + 144LL * i);
LABEL_7:
v13 = v11[39];
if ( !v13 )
goto LABEL_14;
v14 = "longitude:derivative";
v15 = 20LL;
if ( v13 != 8 )
{
v14 = "latitude:derivative";
v15 = 19LL;
if ( v13 != 16 )
{
v14 = "longitude:mean";
v15 = 14LL;
if ( v13 != 64 )
{
if ( v13 == 128 )
{
if ( v11[36] )
{
v14 = "time:sum";
LABEL_21:
v15 = 8LL;
goto LABEL_22;
}
v14 = "time:mean";
v15 = 9LL;
}
else
{
v14 = "time:min";
if ( v13 == 4096 )
goto LABEL_21;
if ( v13 != 0x2000 )
{
LABEL_14:
v16 = v11[29];
if ( (_WORD)v16 == 9999 )
goto LABEL_23;
goto LABEL_15;
}
v14 = "time:max";
v15 = 8LL;
}
}
}
}
LABEL_22:
nc_put_att_text(a1, v10, "cell_method", v15, v14);
v10 = v27;
v16 = *(unsigned __int16 *)(stored_um_vars + 144LL * i + 58);
if ( (_WORD)v16 == 9999 )
{
LABEL_23:
i = 1;
nc_put_att_int(a1, v10, "stash_model", 4LL, 1LL, &i);
i = *(unsigned __int16 *)(stored_um_vars + 144LL * i + 56) / 0x3E8u;
nc_put_att_int(a1, v27, "stash_section", 4LL, 1LL, &i);
i = *(unsigned __int16 *)(stored_um_vars + 144LL * i + 56) - i;
nc_put_att_int(a1, v27, "stash_item", 4LL, 1LL, &i);
v28[0] = 1120403456;
nc_put_att_float(a1, v27, "valid_max", 5LL, 1LL, v28);
v28[0] = 0;
nc_put_att_float(a1, v27, "valid_min", 5LL, 1LL, v28);
nc_put_att_text(a1, v27, "long_name", 16LL, "unknown UM field");
nc_put_att_text(a1, v27, "standard_name", 16LL, "unknown_UM_field");
nc_put_att_text(a1, v27, "units", 7LL, "unknown");
continue;
}
LABEL_15:
v17 = 292 * v16;
nc_put_att_int(a1, v10, "stash_model", 4LL, 1LL, (char *)um_vars + 292 * v16 + 4);
nc_put_att_int(a1, v27, "stash_section", 4LL, 1LL, (char *)um_vars + v17 + 8);
nc_put_att_int(a1, v27, "stash_item", 4LL, 1LL, (char *)um_vars + v17);
nc_put_att_float(a1, v27, "valid_max", 5LL, 1LL, (char *)um_vars + v17 + 24);
nc_put_att_float(a1, v27, "valid_min", 5LL, 1LL, (char *)um_vars + v17 + 28);
nc_put_att_text(a1, v27, "long_name", 100LL, (char *)um_vars + v17 + 89);
nc_put_att_text(a1, v27, "standard_name", 75LL, (char *)um_vars + v17 + 189);
nc_put_att_text(a1, v27, "units", 25LL, (char *)um_vars + v17 + 264);
}
v25 = malloc(4uLL);
nc_inq_dimid(a1, "num_etaT_levels", v25);
nc_def_var(a1, "eta_theta", 5LL, 1LL, v25, &v27);
nc_inq_dimid(a1, "num_etaR_levels", v25);
nc_def_var(a1, "eta_rho", 5LL, 1LL, v25, &v27);
free(v25);
}

original_code:
void construct_um_variables( int ncid, int iflag ) {
     int i, ierr, *dim_ids, ndim, varID, loc;
     size_t *chunksize;
     float tmp;
     for ( i=0; i<num_stored_um_fields; i++ ) {
         if ( stored_um_vars[i].nz>1 ) { ndim = 4; }
         else { ndim = 3; }
         dim_ids = (int *) malloc( ndim*sizeof(int) );
         dim_ids[0] = stored_um_vars[i].t_dim;
         if ( ndim==4 ) { dim_ids[1] = stored_um_vars[i].z_dim; }
         dim_ids[ndim-2] = stored_um_vars[i].y_dim;
         dim_ids[ndim-1] = stored_um_vars[i].x_dim;
         ierr = nc_def_var( ncid, stored_um_vars[i].name, stored_um_vars[i].vartype,
                            ndim, dim_ids, &varID );
         free( dim_ids );
         if ( netcdf3_flag==0 ) {
            chunksize = (size_t* ) malloc( ndim*sizeof(size_t) );
            chunksize[0] = 1;
            chunksize[ndim-1] = stored_um_vars[i].nx;
            if ( iflag==0 ) { chunksize[ndim-2] = stored_um_vars[i].ny; }
            else { chunksize[ndim-2] = int_constants[6]; }
            if ( ndim==4 ) { chunksize[1] = 1; }
            ierr = nc_def_var_chunking( ncid, varID, 0, chunksize );
            free( chunksize );
            ierr = nc_def_var_deflate( ncid, varID, 1, 1, 3 );
         }
         if ( stored_um_vars[i].coordinates==101 ) {
            ierr = nc_put_att_text( ncid, varID, "grid_mapping", 12, "rotated_pole" );
            ierr = nc_put_att_text( ncid, varID, "coordinates", 18, "latitude longitude" );
         }
         else if ( stored_um_vars[i].coordinates==1 ) {
            ierr = nc_put_att_text( ncid, varID, "coordinates", 18, "latitude longitude" );
         }
        if ( stored_um_vars[i].lbproc>0 ) {
           if ( stored_um_vars[i].lbproc==8 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 20, "longitude:derivative" ); }
           else if ( stored_um_vars[i].lbproc==16 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 19, "latitude:derivative" ); }
           else if ( stored_um_vars[i].lbproc==64 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 14, "longitude:mean" ); }
           else if ( stored_um_vars[i].lbproc==128 ) {
                if ( stored_um_vars[i].accum==0 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 9, "time:mean" ); }
                else { ierr = nc_put_att_text( ncid, varID, "cell_method", 8, "time:sum" ); }
           }
           else if ( stored_um_vars[i].lbproc==4096 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 8, "time:min" ); }
           else if ( stored_um_vars[i].lbproc==8192 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 8, "time:max" ); }
        }
        if ( stored_um_vars[i].xml_index!=9999 ) {
           loc = stored_um_vars[i].xml_index;
           ierr = nc_put_att_int( ncid, varID, "stash_model", 4, 1, &
                                  um_vars[loc].model );
           ierr = nc_put_att_int( ncid, varID, "stash_section", 4, 1, &
                                  um_vars[loc].section );
           ierr = nc_put_att_int( ncid, varID, "stash_item", 4, 1, &
                                  um_vars[loc].code );
           ierr = nc_put_att_float( ncid, varID, "valid_max", 5, 1, &
                                    um_vars[loc].validmax );
           ierr = nc_put_att_float( ncid, varID, "valid_min", 5, 1, &
                                    um_vars[loc].validmin );
           ierr = nc_put_att_text( ncid, varID, "long_name", 100, um_vars[loc].longname );
           ierr = nc_put_att_text( ncid, varID, "standard_name", 75, um_vars[loc].stdname );
           ierr = nc_put_att_text( ncid, varID, "units", 25, um_vars[loc].units );
        } else {
           i = 1;
           ierr = nc_put_att_int( ncid, varID, "stash_model", 4, 1, &i );
           i = (int ) (stored_um_vars[i].stash_code/1000);
           ierr = nc_put_att_int( ncid, varID, "stash_section", 4, 1, &i );
           i = (int ) (stored_um_vars[i].stash_code - i);
           ierr = nc_put_att_int( ncid, varID, "stash_item", 4, 1, &i );
           tmp = 100.0;
           ierr = nc_put_att_float( ncid, varID, "valid_max", 5, 1, &tmp );
           tmp = 0.0;
           ierr = nc_put_att_float( ncid, varID, "valid_min", 5, 1, &tmp );
           ierr = nc_put_att_text( ncid, varID, "long_name", 16, "unknown UM field" );
           ierr = nc_put_att_text( ncid, varID, "standard_name", 16, "unknown_UM_field" );
           ierr = nc_put_att_text( ncid, varID, "units", 7, "unknown" );
        }
     }
     ndim = 1;
     dim_ids = (int *) malloc( ndim*sizeof(int) );
     ierr = nc_inq_dimid( ncid, "num_etaT_levels", &dim_ids[0] );
     ierr = nc_def_var( ncid, "eta_theta", 5, ndim, dim_ids, &varID );
     ierr = nc_inq_dimid( ncid, "num_etaR_levels", &dim_ids[0] );
     ierr = nc_def_var( ncid, "eta_rho", 5, ndim, dim_ids, &varID );
     free( dim_ids );
     return;
}

canonical_original_code:
void construct_um_variables(int ncid, int iflag) {
     int i; int ierr; int *dim_ids; int ndim; int varID; int loc;
     unsigned long *chunksize;
     float tmp;
     for ( i=0; i<num_stored_um_fields; i++ ) {
         if ( stored_um_vars[i].nz>1 ) { ndim = 4; }
         else { ndim = 3; }
         dim_ids = (int *) malloc( ndim*sizeof(int) );
         dim_ids[0] = stored_um_vars[i].t_dim;
         if ( ndim==4 ) { dim_ids[1] = stored_um_vars[i].z_dim; }
         dim_ids[ndim-2] = stored_um_vars[i].y_dim;
         dim_ids[ndim-1] = stored_um_vars[i].x_dim;
         ierr = nc_def_var( ncid, stored_um_vars[i].name, stored_um_vars[i].vartype,
                            ndim, dim_ids, &varID );
         free( dim_ids );
         if ( netcdf3_flag==0 ) {
            chunksize = (unsigned long * ) malloc( ndim*sizeof(unsigned long) );
            chunksize[0] = 1;
            chunksize[ndim-1] = stored_um_vars[i].nx;
            if ( iflag==0 ) { chunksize[ndim-2] = stored_um_vars[i].ny; }
            else { chunksize[ndim-2] = int_constants[6]; }
            if ( ndim==4 ) { chunksize[1] = 1; }
            ierr = nc_def_var_chunking( ncid, varID, 0, chunksize );
            free( chunksize );
            ierr = nc_def_var_deflate( ncid, varID, 1, 1, 3 );
         }
         if ( stored_um_vars[i].coordinates==101 ) {
            ierr = nc_put_att_text( ncid, varID, "grid_mapping", 12, "rotated_pole" );
            ierr = nc_put_att_text( ncid, varID, "coordinates", 18, "latitude longitude" );
         }
         else if ( stored_um_vars[i].coordinates==1 ) {
            ierr = nc_put_att_text( ncid, varID, "coordinates", 18, "latitude longitude" );
         }
        if ( stored_um_vars[i].lbproc>0 ) {
           if ( stored_um_vars[i].lbproc==8 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 20, "longitude:derivative" ); }
           else if ( stored_um_vars[i].lbproc==16 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 19, "latitude:derivative" ); }
           else if ( stored_um_vars[i].lbproc==64 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 14, "longitude:mean" ); }
           else if ( stored_um_vars[i].lbproc==128 ) {
                if ( stored_um_vars[i].accum==0 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 9, "time:mean" ); }
                else { ierr = nc_put_att_text( ncid, varID, "cell_method", 8, "time:sum" ); }
           }
           else if ( stored_um_vars[i].lbproc==4096 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 8, "time:min" ); }
           else if ( stored_um_vars[i].lbproc==8192 ) { ierr = nc_put_att_text( ncid, varID, "cell_method", 8, "time:max" ); }
        }
        if ( stored_um_vars[i].xml_index!=9999 ) {
           loc = stored_um_vars[i].xml_index;
           ierr = nc_put_att_int( ncid, varID, "stash_model", 4, 1, &
                                  um_vars[loc].model );
           ierr = nc_put_att_int( ncid, varID, "stash_section", 4, 1, &
                                  um_vars[loc].section );
           ierr = nc_put_att_int( ncid, varID, "stash_item", 4, 1, &
                                  um_vars[loc].code );
           ierr = nc_put_att_float( ncid, varID, "valid_max", 5, 1, &
                                    um_vars[loc].validmax );
           ierr = nc_put_att_float( ncid, varID, "valid_min", 5, 1, &
                                    um_vars[loc].validmin );
           ierr = nc_put_att_text( ncid, varID, "long_name", 100, um_vars[loc].longname );
           ierr = nc_put_att_text( ncid, varID, "standard_name", 75, um_vars[loc].stdname );
           ierr = nc_put_att_text( ncid, varID, "units", 25, um_vars[loc].units );
        } else {
           i = 1;
           ierr = nc_put_att_int( ncid, varID, "stash_model", 4, 1, &i );
           i = (int ) (stored_um_vars[i].stash_code/1000);
           ierr = nc_put_att_int( ncid, varID, "stash_section", 4, 1, &i );
           i = (int ) (stored_um_vars[i].stash_code - i);
           ierr = nc_put_att_int( ncid, varID, "stash_item", 4, 1, &i );
           tmp = 100.0;
           ierr = nc_put_att_float( ncid, varID, "valid_max", 5, 1, &tmp );
           tmp = 0.0;
           ierr = nc_put_att_float( ncid, varID, "valid_min", 5, 1, &tmp );
           ierr = nc_put_att_text( ncid, varID, "long_name", 16, "unknown UM field" );
           ierr = nc_put_att_text( ncid, varID, "standard_name", 16, "unknown_UM_field" );
           ierr = nc_put_att_text( ncid, varID, "units", 7, "unknown" );
        }
     }
     ndim = 1;
     dim_ids = (int *) malloc( ndim*sizeof(int) );
     ierr = nc_inq_dimid( ncid, "num_etaT_levels", &dim_ids[0] );
     ierr = nc_def_var( ncid, "eta_theta", 5, ndim, dim_ids, &varID );
     ierr = nc_inq_dimid( ncid, "num_etaR_levels", &dim_ids[0] );
     ierr = nc_def_var( ncid, "eta_rho", 5, ndim, dim_ids, &varID );
     free( dim_ids );
     return;
}

variable_types: iflag int

variable_types: i int

variable_types: ndim int

variable_types: loc int

variable_types:
chunksize
unsigned long *

variable_types: tmp float