decompiled_code:
char *__fastcall alloc_kvnode(void *src, void *a2)
{
int v2; // er12
int v3; // ebp
char *v4; // rax
char *v5; // rbx

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)alloc_node(v2 + (__int64)v3 + 10);
v5 = v4;
if ( v4 )
{
memcpy(v4 + 24, src, v2 + 1);
v5[v2 + 24] = 0;
memcpy(&v5[v2 + 25], a2, v3 + 1);
*((_QWORD *)v5 + 2) = v2 + 9LL;
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func10(void *src, void *a2)
{
int v2; // er12
int v3; // ebp
char *v4; // rax
char *v5; // rbx

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)func4(v2 + (__int64)v3 + 10);
v5 = v4;
if ( v4 )
{
memcpy(v4 + 24, src, v2 + 1);
v5[v2 + 24] = 0;
memcpy(&v5[v2 + 25], a2, v3 + 1);
*((_QWORD *)v5 + 2) = v2 + 9LL;
}
return v5;
}

original_code:
static struct node *alloc_kvnode(const char *key, const char *value)
{
 struct node *node;
 int klen, vlen;
 klen = strlen(key);
 vlen = strlen(value);
 node = alloc_node(sizeof(size_t) + klen + 1 + vlen + 1);
 if (node != ((void *)0)) {
  memcpy(node->data + sizeof(size_t), key, klen + 1);
  node->data[sizeof(size_t) + klen] = '\0';
  memcpy(node->data + sizeof(size_t) + klen + 1, value, vlen + 1);
  *((size_t *)node->data) = sizeof(size_t) + klen + 1;
 }
 return node;
}

canonical_original_code:
static struct node *alloc_kvnode(char *key, char *value)
{
 struct node *node;
 int klen; int vlen;
 klen = strlen(key);
 vlen = strlen(value);
 node = alloc_node(sizeof(unsigned long) + klen + 1 + vlen + 1);
 if (node != ((void *)0)) {
  memcpy(node->data + sizeof(unsigned long), key, klen + 1);
  node->data[sizeof(unsigned long) + klen] = '\0';
  memcpy(node->data + sizeof(unsigned long) + klen + 1, value, vlen + 1);
  *((unsigned long *)node->data) = sizeof(unsigned long) + klen + 1;
 }
 return node;
}

variable_types:
key
char *

variable_types: klen int

variable_types: vlen int


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

result = (unsigned int)(verbosity_level + a1);
verbosity_level += a1;
return result;
}

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

result = (unsigned int)(verbosity_level + a1);
verbosity_level += a1;
return result;
}

original_code:
int verbose_adjust_level(int v)
{
 return verbosity_level += v;
}

variable_types: v int

return_type: int


verbose

decompiled_code:
int verbose(int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = (int)arg[0].reg_save_area;
if ( verbosity_level >= a1 )
result = vprintf(a2, arg);
return result;
}

canonical_decompiled_code:
int func1(int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = (int)arg[0].reg_save_area;
if ( verbosity_level >= a1 )
result = vprintf(a2, arg);
return result;
}

original_code:
void verbose(enum verbosity_level level, const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 if (verbosity_level >= level) {
  vprintf(fmt, ap);
 }
 __builtin_va_end(ap);
}

canonical_original_code:
void verbose(enum verbosity_level level, char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 if (verbosity_level >= level) {
  vprintf(fmt, ap);
 }
 __builtin_va_end(ap);
}

variable_types: enum verbosity_level { ERROR=-1, NORMAL=0, VERBOSE=1, FIREHOSE=2 }

variable_types:
fmt
char *

return_type: void


decompiled_code:
char __fastcall navi_link_hunter_element_end(int *a1, const char *a2)
{
bool v2; // zf
int v3; // eax

v2 = strcmp(a2, "div") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
v3 = *a1;
if ( *a1 )
*a1 = --v3;
}
return v3;
}

canonical_decompiled_code:
char __fastcall func2(int *a1, const char *a2)
{
bool v2; // zf
int v3; // eax

v2 = strcmp(a2, "div") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
v3 = *a1;
if ( *a1 )
*a1 = --v3;
}
return v3;
}

original_code:
static void navi_link_hunter_element_end(void *user_data, const char *element)
{
 struct navi_hunt_context *ctx = user_data;
 if (strcmp(element, "div") == 0 && ctx->in_navi_div) {
  ctx->in_navi_div--;
 }
}

canonical_original_code:
static void navi_link_hunter_element_end(void *user_data, char *element)
{
 struct navi_hunt_context *ctx = user_data;
 if (strcmp(element, "div") == 0 && ctx->in_navi_div) {
  ctx->in_navi_div--;
 }
}

variable_types:
element
char *

variable_types: struct navi_hunt_context { int in_navi_div; char **prevp; char **nextp; } *


decompiled_code:
const char *__fastcall attr_value(const char **a1, const char *a2)
{
const char *v3; // rdi
__int64 v4; // rbx

v3 = *a1;
if ( v3 )
{
v4 = 0LL;
while ( strcmp(v3, a2) )
{
v4 += 2LL;
v3 = a1[v4];
if ( !v3 )
return v3;
}
v3 = a1[v4 + 1];
}
return v3;
}

canonical_decompiled_code:
const char *__fastcall func3(const char **a1, const char *a2)
{
const char *v3; // rdi
__int64 v4; // rbx

v3 = *a1;
if ( v3 )
{
v4 = 0LL;
while ( strcmp(v3, a2) )
{
v4 += 2LL;
v3 = a1[v4];
if ( !v3 )
return v3;
}
v3 = a1[v4 + 1];
}
return v3;
}

original_code:
static const char *attr_value(const char **attrs, const char *name)
{
 const char *value;
 int i;
 for (i = 0, value = ((void *)0); attrs[i]; i += 2) {
  if (strcmp(attrs[i], name) == 0) {
   value = attrs[i+1];
   break;
  }
 }
 return value;
}

canonical_original_code:
static char *attr_value(char **attrs, char *name)
{
 char *value;
 int i;
 for (i = 0, value = ((void *)0); attrs[i]; i += 2) {
  if (strcmp(attrs[i], name) == 0) {
   value = attrs[i+1];
   break;
  }
 }
 return value;
}

variable_types:
attrs
char **

variable_types:
name
char *

variable_types:
value
char *

variable_types: i int

return_type: char *


decompiled_code:
_BOOL8 __fastcall attr_is(const char **a1, const char *a2, const char *a3)
{
const char *v4; // rdi
_BOOL8 result; // rax

v4 = attr_value(a1, a2);
result = 0LL;
if ( v4 )
result = strcmp(v4, a3) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char **a1, const char *a2, const char *a3)
{
const char *v4; // rdi
_BOOL8 result; // rax

v4 = func3(a1, a2);
result = 0LL;
if ( v4 )
result = strcmp(v4, a3) == 0;
return result;
}

original_code:
static int attr_is(const char **attrs, const char *name, const char *what)
{
 const char *value = attr_value(attrs, name);
 return value != ((void *)0) && strcmp(value, what) == 0;
}

canonical_original_code:
static int attr_is(char **attrs, char *name, char *what)
{
 char *value = attr_value(attrs, name);
 return value != ((void *)0) && strcmp(value, what) == 0;
}

variable_types:
what
char *


decompiled_code:
_BOOL8 __fastcall id_is(const char **a1, const char *a2)
{
return attr_is(a1, "id", a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(const char **a1, const char *a2)
{
return func4(a1, "id", a2);
}

original_code:
static int id_is(const char **attrs, const char *what)
{
 return attr_is(attrs, "id", what);
}

canonical_original_code:
static int id_is(char **attrs, char *what)
{
 return attr_is(attrs, "id", what);
}


decompiled_code:
__int64 __fastcall assert_link(char *s1, char *s2)
{
int v2; // eax

CU_assertImplementation(s1 != 0LL, 55LL, "CU_ASSERT_PTR_NOT_NULL_FATAL(parsed_link)", "suite_feed.c", &unk_551, 1LL);
v2 = strcmp(s1, s2);
return CU_assertImplementation(
v2 == 0,
56LL,
"CU_ASSERT_STRING_EQUAL(parsed_link,expected)",
"suite_feed.c",
&unk_551,
0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s1, char *s2)
{
int v2; // eax

CU_assertImplementation(s1 != 0LL, 55LL, "CU_ASSERT_PTR_NOT_NULL_FATAL(parsed_link)", "suite_feed.c", &unk_551, 1LL);
v2 = strcmp(s1, s2);
return CU_assertImplementation(
v2 == 0,
56LL,
"CU_ASSERT_STRING_EQUAL(parsed_link,expected)",
"suite_feed.c",
&unk_551,
0LL);
}

original_code:
static void assert_link(const char *parsed_link, const char *expected)
{
 { CU_assertImplementation((((void *)0) != (const void*)(parsed_link)), 55, ("CU_ASSERT_PTR_NOT_NULL_FATAL(" "parsed_link"")"), "suite_feed.c", "", 1); };
 { CU_assertImplementation(!(strcmp((const char*)(parsed_link), (const char*)(expected))), 56, ("CU_ASSERT_STRING_EQUAL(" "parsed_link" "," "expected" ")"), "suite_feed.c", "", 0); };
}

canonical_original_code:
static void assert_link(char *parsed_link, char *expected)
{
 { CU_assertImplementation((((void *)0) != (void *)(parsed_link)), 55, ("CU_ASSERT_PTR_NOT_NULL_FATAL(" "parsed_link"")"), "suite_feed.c", "", 1); };
 { CU_assertImplementation(!(strcmp((char *)(parsed_link), (char *)(expected))), 56, ("CU_ASSERT_STRING_EQUAL(" "parsed_link" "," "expected" ")"), "suite_feed.c", "", 0); };
}

variable_types:
expected
char *


decompiled_code:
char __fastcall navi_link_hunter_element_start(__int64 a1, const char *a2, const char **a3)
{
char *v4; // rax
bool v5; // zf
const char *v6; // rax
char **v7; // rbx
const char *v8; // rax
char **v9; // rbx

if ( !strcmp(a2, "div") && (LODWORD(v4) = class_is(a3, "navi"), (_DWORD)v4) )
{
++*(_DWORD *)a1;
}
else
{
v5 = strcmp(a2, "a") == 0;
LOBYTE(v4) = !v5;
if ( v5 && *(int *)a1 > 0 )
{
if ( id_is(a3, "prev") )
{
v8 = attr_value(a3, "href");
v9 = *(char ***)(a1 + 8);
v4 = strdup(v8);
*v9 = v4;
}
else
{
LODWORD(v4) = id_is(a3, "next");
if ( (_DWORD)v4 )
{
v6 = attr_value(a3, "href");
v7 = *(char ***)(a1 + 16);
v4 = strdup(v6);
*v7 = v4;
}
}
}
}
return (char)v4;
}

canonical_decompiled_code:
char __fastcall func8(__int64 a1, const char *a2, const char **a3)
{
char *v4; // rax
bool v5; // zf
const char *v6; // rax
char **v7; // rbx
const char *v8; // rax
char **v9; // rbx

if ( !strcmp(a2, "div") && (LODWORD(v4) = func5(a3, "navi"), (_DWORD)v4) )
{
++*(_DWORD *)a1;
}
else
{
v5 = strcmp(a2, "a") == 0;
LOBYTE(v4) = !v5;
if ( v5 && *(int *)a1 > 0 )
{
if ( func6(a3, "prev") )
{
v8 = func3(a3, "href");
v9 = *(char ***)(a1 + 8);
v4 = strdup(v8);
*v9 = v4;
}
else
{
LODWORD(v4) = func6(a3, "next");
if ( (_DWORD)v4 )
{
v6 = func3(a3, "href");
v7 = *(char ***)(a1 + 16);
v4 = strdup(v6);
*v7 = v4;
}
}
}
}
return (char)v4;
}

original_code:
static void navi_link_hunter_element_start(void *user_data,
        const char *element, const char **attrs)
{
 struct navi_hunt_context *ctx = user_data;
 if (strcmp(element, "div") == 0 && class_is(attrs, "navi")) {
  ctx->in_navi_div++;
 } else if (strcmp(element, "a") == 0) {
  if (ctx->in_navi_div > 0) {
   if (id_is(attrs, "prev")) {
    *ctx->prevp = strdup(attr_value(attrs, "href"));
   } else if (id_is(attrs, "next")) {
    *ctx->nextp = strdup(attr_value(attrs, "href"));
   }
  }
 }
}

canonical_original_code:
static void navi_link_hunter_element_start(void *user_data, char *element, char **attrs)
{
 struct navi_hunt_context *ctx = user_data;
 if (strcmp(element, "div") == 0 && class_is(attrs, "navi")) {
  ctx->in_navi_div++;
 } else if (strcmp(element, "a") == 0) {
  if (ctx->in_navi_div > 0) {
   if (id_is(attrs, "prev")) {
    *ctx->prevp = strdup(attr_value(attrs, "href"));
   } else if (id_is(attrs, "next")) {
    *ctx->nextp = strdup(attr_value(attrs, "href"));
   }
  }
 }
}

user_defined_types: struct navi_hunt_context { int in_navi_div; char **prevp; char **nextp; }


decompiled_code:
int __fastcall setup_pagination(int *a1, _DWORD *a2, __int64 a3)
{
const char *v4; // rax
const char *v5; // rax

*a1 = 1;
*a2 = 26;
v4 = (const char *)evhttp_find_header(a3, "start-index");
if ( v4 )
*a1 = atoi_limited(v4, 1, 1000000);
v5 = (const char *)evhttp_find_header(a3, "max-results");
if ( v5 )
{
LODWORD(v5) = atoi_limited(v5, 1, 50);
*a2 = (_DWORD)v5;
}
return (int)v5;
}

canonical_decompiled_code:
int __fastcall func6(int *a1, _DWORD *a2, __int64 a3)
{
const char *v4; // rax
const char *v5; // rax

*a1 = 1;
*a2 = 26;
v4 = (const char *)evhttp_find_header(a3, "start-index");
if ( v4 )
*a1 = func5(v4, 1, 1000000);
v5 = (const char *)evhttp_find_header(a3, "max-results");
if ( v5 )
{
LODWORD(v5) = func5(v5, 1, 50);
*a2 = (_DWORD)v5;
}
return (int)v5;
}

original_code:
static void setup_pagination(int *start, int *max, struct evkeyvalq *params)
{
 const char *raw;
 *start = 1;
 *max = 26;
 raw = evhttp_find_header(params, "start-index");
 if (raw != ((void *)0)) {
  *start = atoi_limited(raw, 1, 1000000);
 }
 raw = evhttp_find_header(params, "max-results");
 if (raw != ((void *)0)) {
  *max = atoi_limited(raw, 1, 50);
 }
}

canonical_original_code:
static void setup_pagination(int *start, int *max, struct evkeyvalq *params)
{
 char *raw;
 *start = 1;
 *max = 26;
 raw = evhttp_find_header(params, "start-index");
 if (raw != ((void *)0)) {
  *start = atoi_limited(raw, 1, 1000000);
 }
 raw = evhttp_find_header(params, "max-results");
 if (raw != ((void *)0)) {
  *max = atoi_limited(raw, 1, 50);
 }
}

variable_types:
start
int *

variable_types:
max
int *

variable_types: struct evkeyvalq { struct evkeyval { struct { struct evkeyval *tqe_next; struct evkeyval **tqe_prev; } next; char *key; char *value; } *tqh_first; struct evkeyval **tqh_last; } *

variable_types:
raw
char *

user_defined_types: struct evkeyvalq { struct evkeyval *tqh_first; struct evkeyval **tqh_last; }


interrupted

decompiled_code:
__int64 __fastcall interrupted(__int64 a1, __int64 a2, __int64 a3)
{
return event_base_loopexit(a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
return event_base_loopexit(a3, 0LL);
}

original_code:
static void interrupted(int fd, short events, void *base)
{
 event_base_loopexit(base, ((void *)0));
}

variable_types: fd int

variable_types: events short

variable_types:
base
void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
__int64 v6; // rax
__int64 v7; // rdi
__int64 v8; // rdi
int v9; // eax
int v10; // eax
char *v11; // rax
char *v12; // rax
char *v13; // rax
__int64 v14; // [rsp+0h] [rbp-58h] BYREF
__int64 v15; // [rsp+8h] [rbp-50h]
__int64 v16; // [rsp+10h] [rbp-48h]
__int64 v17; // [rsp+18h] [rbp-40h] BYREF
__int64 v18; // [rsp+20h] [rbp-38h] BYREF
__int64 v19; // [rsp+28h] [rbp-30h] BYREF
__int64 v20; // [rsp+30h] [rbp-28h]
__int64 v21; // [rsp+38h] [rbp-20h]

v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "np:v");
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'p':
LODWORD(v21) = atoi(optarg);
break;
case 'v':
verbose_adjust_level(1LL);
break;
case 'n':
HIDWORD(v21) = 1;
break;
default:
v4 = 1;
goto LABEL_7;
}
}
v6 = event_base_new();
v14 = v6;
if ( v6 )
{
v7 = event_new(v6, 2LL, 24LL, interrupted, v6);
v20 = v7;
if ( v7 )
{
event_add(v7, 0LL);
v8 = evhttp_new(v14);
v16 = v8;
if ( v8 )
{
v15 = evhttp_bind_socket_with_handle(v8, "localhost", (unsigned __int16)v21);
if ( v15 )
{
v9 = store_init(&v19, 10LL);
v4 = v9;
if ( v9 )
{
v11 = strerror(v9);
fprintf(stderr, "session_store_init(): %s\n", v11);
}
else if ( (unsigned int)https_engine_init(&v17, v14, HIDWORD(v21)) )
{
v4 = *_errno_location();
v12 = strerror(v4);
fprintf(stderr, "https_init(): %s\n", v12);
}
else
{
LODWORD(v21) = lport(v15);
v10 = auth_init(&v18, v17, (unsigned int)v21);
v4 = v10;
if ( v10 )
{
v13 = strerror(v10);
fprintf(stderr, "auth_init(): %s\n", v13);
}
else
{
printf("http://localhost:%d/\n", (unsigned int)v21);
evhttp_set_gencb(v16, handle_request, &v14);
event_base_dispatch(v14);
puts("Interrupted");
}
}
}
else
{
v4 = *_errno_location();
perror("evhttp_bind_socket()");
}
}
else
{
v4 = *_errno_location();
perror("evhttp_new()");
}
}
else
{
v4 = *_errno_location();
fwrite("Failed to trap SIGINT\n", 1uLL, 0x16uLL, stderr);
}
}
else
{
v4 = *_errno_location();
}
LABEL_7:
store_destroy(v19);
if ( v20 )
{
event_del();
event_free(v20);
v20 = 0LL;
}
auth_destroy(v18);
if ( v17 )
{
https_engine_destroy();
v17 = 0LL;
}
if ( v16 )
{
evhttp_free();
v16 = 0LL;
}
if ( v14 )
event_base_free();
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
__int64 v6; // rax
__int64 v7; // rdi
__int64 v8; // rdi
int v9; // eax
int v10; // eax
char *v11; // rax
char *v12; // rax
char *v13; // rax
__int64 v14; // [rsp+0h] [rbp-58h] BYREF
__int64 v15; // [rsp+8h] [rbp-50h]
__int64 v16; // [rsp+10h] [rbp-48h]
__int64 v17; // [rsp+18h] [rbp-40h] BYREF
__int64 v18; // [rsp+20h] [rbp-38h] BYREF
__int64 v19; // [rsp+28h] [rbp-30h] BYREF
__int64 v20; // [rsp+30h] [rbp-28h]
__int64 v21; // [rsp+38h] [rbp-20h]

v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "np:v");
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'p':
LODWORD(v21) = atoi(optarg);
break;
case 'v':
verbose_adjust_level(1LL);
break;
case 'n':
HIDWORD(v21) = 1;
break;
default:
v4 = 1;
goto LABEL_7;
}
}
v6 = event_base_new();
v14 = v6;
if ( v6 )
{
v7 = event_new(v6, 2LL, 24LL, interrupted, v6);
v20 = v7;
if ( v7 )
{
event_add(v7, 0LL);
v8 = evhttp_new(v14);
v16 = v8;
if ( v8 )
{
v15 = evhttp_bind_socket_with_handle(v8, "localhost", (unsigned __int16)v21);
if ( v15 )
{
v9 = store_init(&v19, 10LL);
v4 = v9;
if ( v9 )
{
v11 = strerror(v9);
fprintf(stderr, "session_store_init(): %s\n", v11);
}
else if ( (unsigned int)https_engine_init(&v17, v14, HIDWORD(v21)) )
{
v4 = *_errno_location();
v12 = strerror(v4);
fprintf(stderr, "https_init(): %s\n", v12);
}
else
{
LODWORD(v21) = func3(v15);
v10 = auth_init(&v18, v17, (unsigned int)v21);
v4 = v10;
if ( v10 )
{
v13 = strerror(v10);
fprintf(stderr, "auth_init(): %s\n", v13);
}
else
{
printf("http://localhost:%d/\n", (unsigned int)v21);
evhttp_set_gencb(v16, handle_request, &v14);
event_base_dispatch(v14);
puts("Interrupted");
}
}
}
else
{
v4 = *_errno_location();
perror("evhttp_bind_socket()");
}
}
else
{
v4 = *_errno_location();
perror("evhttp_new()");
}
}
else
{
v4 = *_errno_location();
fwrite("Failed to trap SIGINT\n", 1uLL, 0x16uLL, stderr);
}
}
else
{
v4 = *_errno_location();
}
LABEL_7:
store_destroy(v19);
if ( v20 )
{
event_del();
event_free(v20);
v20 = 0LL;
}
auth_destroy(v18);
if ( v17 )
{
https_engine_destroy();
v17 = 0LL;
}
if ( v16 )
{
evhttp_free();
v16 = 0LL;
}
if ( v14 )
event_base_free();
return v4;
}

original_code:
int main(int argc, char **argv)
{
 CU_ErrorCode cerr;
 int failed;
 if (argc > 1 && strcmp(argv[1], "-v") == 0) {
  verbose_adjust_level(+1);
 }
 if ((cerr = CU_initialize_registry() != CUE_SUCCESS)) {
  fprintf(stderr, "CU_initialize_registry() failed: %d\n", cerr);
  return 1;
 }
 if ((cerr = register_suites()) != CUE_SUCCESS) {
  fprintf(stderr, "CU_register_suites() failed: %d\n", cerr);
  return 1;
 }
 if (verbose_adjust_level(0) > NORMAL) {
  CU_basic_set_mode(CU_BRM_VERBOSE);
 }
 if ((cerr = CU_basic_run_tests()) != CUE_SUCCESS) {
  fprintf(stderr, "CU_basic_run_tests() failed: %d\n", cerr);
  return 1;
 }
 if (verbose_adjust_level(0) > NORMAL) {
  CU_basic_show_failures(CU_get_failure_list());
 }
 failed = CU_get_number_of_tests_failed();
 CU_cleanup_registry();
 return failed > 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 enum CU_ErrorCode cerr;
 int failed;
 if (argc > 1 && strcmp(argv[1], "-v") == 0) {
  verbose_adjust_level(+1);
 }
 if ((cerr = CU_initialize_registry() != CUE_SUCCESS)) {
  fprintf(stderr, "CU_initialize_registry() failed: %d\n", cerr);
  return 1;
 }
 if ((cerr = register_suites()) != CUE_SUCCESS) {
  fprintf(stderr, "CU_register_suites() failed: %d\n", cerr);
  return 1;
 }
 if (verbose_adjust_level(0) > NORMAL) {
  CU_basic_set_mode(CU_BRM_VERBOSE);
 }
 if ((cerr = CU_basic_run_tests()) != CUE_SUCCESS) {
  fprintf(stderr, "CU_basic_run_tests() failed: %d\n", cerr);
  return 1;
 }
 if (verbose_adjust_level(0) > NORMAL) {
  CU_basic_show_failures(CU_get_failure_list());
 }
 failed = CU_get_number_of_tests_failed();
 CU_cleanup_registry();
 return failed > 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: enum CU_ErrorCode { CUE_SUCCESS=0, CUE_NOMEMORY=1, CUE_NOREGISTRY=10, CUE_REGISTRY_EXISTS=11, CUE_NOSUITE=20, CUE_NO_SUITENAME=21, CUE_SINIT_FAILED=22, CUE_SCLEAN_FAILED=23, CUE_DUP_SUITE=24, CUE_SUITE_INACTIVE=25, CUE_NOTEST=30, CUE_NO_TESTNAME=31, CUE_DUP_TEST=32, CUE_TEST_NOT_IN_SUITE=33, CUE_TEST_INACTIVE=34, CUE_FOPEN_FAILED=40, CUE_FCLOSE_FAILED=41, CUE_BAD_FILENAME=42, CUE_WRITE_ERROR=43 }

variable_types: failed int


original_code:
static CU_ErrorCode register_suites()
{
 extern CU_SuiteInfo suite_feed;
 extern CU_SuiteInfo suite_store;
 CU_SuiteInfo suites[] = {
  suite_feed,
  suite_store,
  { ((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0) },
 };
 return CU_register_suites(suites);
}

canonical_original_code:
static enum CU_ErrorCode register_suites()
{
 extern struct CU_SuiteInfo suite_feed;
 extern struct CU_SuiteInfo suite_store;
 struct CU_SuiteInfo suites[] = {
  suite_feed,
  suite_store,
  { ((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0) },
 };
 return CU_register_suites(suites);
}

variable_types: struct CU_SuiteInfo { char *pName; int (*pInitFunc)(); int (*pCleanupFunc)(); void (*pSetUpFunc)(); void (*pTearDownFunc)(); struct CU_TestInfo { char *pName; void (*pTestFunc)(); } *pTests; } []

return_type: enum CU_ErrorCode { CUE_SUCCESS=0, CUE_NOMEMORY=1, CUE_NOREGISTRY=10, CUE_REGISTRY_EXISTS=11, CUE_NOSUITE=20, CUE_NO_SUITENAME=21, CUE_SINIT_FAILED=22, CUE_SCLEAN_FAILED=23, CUE_DUP_SUITE=24, CUE_SUITE_INACTIVE=25, CUE_NOTEST=30, CUE_NO_TESTNAME=31, CUE_DUP_TEST=32, CUE_TEST_NOT_IN_SUITE=33, CUE_TEST_INACTIVE=34, CUE_FOPEN_FAILED=40, CUE_FCLOSE_FAILED=41, CUE_BAD_FILENAME=42, CUE_WRITE_ERROR=43 }

user_defined_types: struct CU_SuiteInfo { char *pName; int (*pInitFunc)(); int (*pCleanupFunc)(); void (*pSetUpFunc)(); void (*pTearDownFunc)(); struct CU_TestInfo *pTests; }


decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
int v5; // ebx
int result; // eax
__int64 v7; // rax

if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
argv = (const char **)"-v";
if ( !strcmp(*(const char **)&argc, "-v") )
{
*(_QWORD *)&argc = 1LL;
verbose_adjust_level(1LL);
}
}
if ( (unsigned int)CU_initialize_registry(*(_QWORD *)&argc, argv, envp) )
{
fprintf(stderr, "CU_initialize_registry() failed: %d\n", 1LL);
result = 1;
}
else
{
v3 = register_suites();
if ( v3 )
{
fprintf(stderr, "CU_register_suites() failed: %d\n", v3);
result = 1;
}
else
{
if ( (int)verbose_adjust_level(0LL) > 0 )
CU_basic_set_mode(2LL);
v4 = CU_basic_run_tests();
if ( v4 )
{
fprintf(stderr, "CU_basic_run_tests() failed: %d\n", v4);
result = 1;
}
else
{
if ( (int)verbose_adjust_level(0LL) > 0 )
{
v7 = CU_get_failure_list();
CU_basic_show_failures(v7);
}
v5 = CU_get_number_of_tests_failed();
CU_cleanup_registry();
result = v5 > 0;
}
}
}
return result;
}

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

if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
argv = (const char **)"-v";
if ( !strcmp(*(const char **)&argc, "-v") )
{
*(_QWORD *)&argc = 1LL;
verbose_adjust_level(1LL);
}
}
if ( (unsigned int)CU_initialize_registry(*(_QWORD *)&argc, argv, envp) )
{
fprintf(stderr, "CU_initialize_registry() failed: %d\n", 1LL);
result = 1;
}
else
{
v3 = func0();
if ( v3 )
{
fprintf(stderr, "CU_register_suites() failed: %d\n", v3);
result = 1;
}
else
{
if ( (int)verbose_adjust_level(0LL) > 0 )
CU_basic_set_mode(2LL);
v4 = CU_basic_run_tests();
if ( v4 )
{
fprintf(stderr, "CU_basic_run_tests() failed: %d\n", v4);
result = 1;
}
else
{
if ( (int)verbose_adjust_level(0LL) > 0 )
{
v7 = CU_get_failure_list();
CU_basic_show_failures(v7);
}
v5 = CU_get_number_of_tests_failed();
CU_cleanup_registry();
result = v5 > 0;
}
}
}
return result;
}

user_defined_types: enum CU_ErrorCode { CUE_SUCCESS=0, CUE_NOMEMORY=1, CUE_NOREGISTRY=10, CUE_REGISTRY_EXISTS=11, CUE_NOSUITE=20, CUE_NO_SUITENAME=21, CUE_SINIT_FAILED=22, CUE_SCLEAN_FAILED=23, CUE_DUP_SUITE=24, CUE_SUITE_INACTIVE=25, CUE_NOTEST=30, CUE_NO_TESTNAME=31, CUE_DUP_TEST=32, CUE_TEST_NOT_IN_SUITE=33, CUE_TEST_INACTIVE=34, CUE_FOPEN_FAILED=40, CUE_FCLOSE_FAILED=41, CUE_BAD_FILENAME=42, CUE_WRITE_ERROR=43 }


motion

repo: jimlawton/GLSL-Shaders

decompiled_code:
__int64 __fastcall motion(int a1, int a2)
{
int v2; // edx
__int64 result; // rax

if ( xLast == -1 )
{
result = (unsigned int)yLast;
if ( yLast != -1 )
{
xLastIncr = a1 + 1;
yLastIncr = a2 - yLast;
}
}
else
{
v2 = a1 - xLast;
xLastIncr = a1 - xLast;
result = (unsigned int)(a2 - yLast);
yLastIncr = a2 - yLast;
if ( (bmModifiers & 2) != 0 )
{
*(float *)&fZDiff = (float)v2 + *(float *)&fZDiff;
*(float *)&fScale = (float)((float)(int)result * 0.0099999998) + *(float *)&fScale;
}
else
{
*(float *)&fXDiff = (float)v2 + *(float *)&fXDiff;
*(float *)&fYDiff = (float)(int)result + *(float *)&fYDiff;
}
}
xLast = a1;
yLast = a2;
return result;
}

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

if ( xLast == -1 )
{
result = (unsigned int)yLast;
if ( yLast != -1 )
{
xLastIncr = a1 + 1;
yLastIncr = a2 - yLast;
}
}
else
{
v2 = a1 - xLast;
xLastIncr = a1 - xLast;
result = (unsigned int)(a2 - yLast);
yLastIncr = a2 - yLast;
if ( (bmModifiers & 2) != 0 )
{
*(float *)&fZDiff = (float)v2 + *(float *)&fZDiff;
*(float *)&fScale = (float)((float)(int)result * 0.0099999998) + *(float *)&fScale;
}
else
{
*(float *)&fXDiff = (float)v2 + *(float *)&fXDiff;
*(float *)&fYDiff = (float)(int)result + *(float *)&fYDiff;
}
}
xLast = a1;
yLast = a2;
return result;
}

original_code:
static
void motion(int x, int y)
{
   if ((xLast != -1) || (yLast != -1))
   {
      xLastIncr = x - xLast;
      yLastIncr = y - yLast;
      if (bmModifiers & 0x0002)
      {
         if (xLast != -1)
         {
            fZDiff += xLastIncr;
            fScale += (yLastIncr)*0.01f;
         }
      }
      else
      {
         if (xLast != -1)
         {
            fXDiff += xLastIncr;
            fYDiff += yLastIncr;
         }
      }
   }
   xLast = x;
   yLast = y;
}

variable_types: x int

variable_types: y int


special

decompiled_code:
void __fastcall special(int a1)
{
switch ( a1 )
{
case 'd':
*(float *)&fXDiff = *(float *)&fXDiff - 1.0;
break;
case 'e':
*(float *)&fYDiff = *(float *)&fYDiff - 1.0;
break;
case 'f':
*(float *)&fXDiff = *(float *)&fXDiff + 1.0;
break;
case 'g':
*(float *)&fYDiff = *(float *)&fYDiff + 1.0;
break;
case 'j':
fXDiff = 0;
fYDiff = 1108082688;
fZDiff = 0;
xLastIncr = 0;
yLastIncr = 0;
fXInertia = -1090519040;
fYInertia = 0;
fScale = 1065353216;
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
switch ( a1 )
{
case 'd':
*(float *)&fXDiff = *(float *)&fXDiff - 1.0;
break;
case 'e':
*(float *)&fYDiff = *(float *)&fYDiff - 1.0;
break;
case 'f':
*(float *)&fXDiff = *(float *)&fXDiff + 1.0;
break;
case 'g':
*(float *)&fYDiff = *(float *)&fYDiff + 1.0;
break;
case 'j':
fXDiff = 0;
fYDiff = 1108082688;
fZDiff = 0;
xLastIncr = 0;
yLastIncr = 0;
fXInertia = -1090519040;
fYInertia = 0;
fScale = 1065353216;
break;
default:
return;
}
}

original_code:
static
void special(int key, int x, int y)
{
    switch (key)
    {
        case 0x006A:
            fXDiff = 0;
            fYDiff = 35;
            fZDiff = 0;
            xLastIncr = 0;
            yLastIncr = 0;
            fXInertia = -0.5;
            fYInertia = 0;
            fScale = 1.0;
        break;
        case 0x0064:
           fXDiff--;
        break;
        case 0x0066:
           fXDiff++;
        break;
        case 0x0065:
           fYDiff--;
        break;
        case 0x0067:
           fYDiff++;
        break;
    }
}

variable_types: key int


timer

decompiled_code:
__int64 timer()
{
*(float *)&ftime = *(float *)&ftime + 0.0099999998;
if ( Rotate )
{
*(float *)&fXDiff = *(float *)&fXDiff + *(float *)&fXInertia;
*(float *)&fYDiff = *(float *)&fYDiff + *(float *)&fYInertia;
}
return glutTimerFunc(20LL, timer, 0LL);
}

canonical_decompiled_code:
__int64 func2()
{
*(float *)&ftime = *(float *)&ftime + 0.0099999998;
if ( Rotate )
{
*(float *)&fXDiff = *(float *)&fXDiff + *(float *)&fXInertia;
*(float *)&fYDiff = *(float *)&fYDiff + *(float *)&fYInertia;
}
return glutTimerFunc(20LL, timer, 0LL);
}

original_code:
static
void timer(int value)
{
    ftime += 0.01f;
    if (Rotate)
    {
        fXDiff = (fXDiff + fXInertia);
        fYDiff = (fYDiff + fYInertia);
    }
    glutTimerFunc(20 , timer, 0);
}

variable_types: value int


mouse

decompiled_code:
__int64 __fastcall mouse(int a1, int a2)
{
__int64 result; // rax
float v3; // xmm0_4
float v4; // xmm0_4

result = glutGetModifiers();
bmModifiers = result;
if ( !a1 )
{
if ( a2 == 1 )
{
xLast = -1;
yLast = -1;
v3 = (float)xLastIncr;
if ( (float)xLastIncr > 1.0 )
*(float *)&fXInertia = (float)(v3 - 1.0) * 0.5;
if ( (float)-xLastIncr > 1.0 )
*(float *)&fXInertia = (float)(v3 + 1.0) * 0.5;
v4 = (float)yLastIncr;
if ( (float)yLastIncr > 1.0 )
*(float *)&fYInertia = (float)(v4 - 1.0) * 0.5;
result = (unsigned int)-yLastIncr;
if ( (float)(int)result > 1.0 )
*(float *)&fYInertia = (float)(v4 + 1.0) * 0.5;
}
else
{
fXInertia = 0;
fYInertia = 0;
}
xLastIncr = 0;
yLastIncr = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
__int64 result; // rax
float v3; // xmm0_4
float v4; // xmm0_4

result = glutGetModifiers();
bmModifiers = result;
if ( !a1 )
{
if ( a2 == 1 )
{
xLast = -1;
yLast = -1;
v3 = (float)xLastIncr;
if ( (float)xLastIncr > 1.0 )
*(float *)&fXInertia = (float)(v3 - 1.0) * 0.5;
if ( (float)-xLastIncr > 1.0 )
*(float *)&fXInertia = (float)(v3 + 1.0) * 0.5;
v4 = (float)yLastIncr;
if ( (float)yLastIncr > 1.0 )
*(float *)&fYInertia = (float)(v4 - 1.0) * 0.5;
result = (unsigned int)-yLastIncr;
if ( (float)(int)result > 1.0 )
*(float *)&fYInertia = (float)(v4 + 1.0) * 0.5;
}
else
{
fXInertia = 0;
fYInertia = 0;
}
xLastIncr = 0;
yLastIncr = 0;
}
return result;
}

original_code:
static
void mouse(int button, int state, int x, int y)
{
   bmModifiers = glutGetModifiers();
   if (button == 0x0000)
   {
      if (state == 0x0001)
      {
         xLast = -1;
         yLast = -1;
         if (xLastIncr > 1.0f)
            fXInertia = (xLastIncr - 1.0f)*0.5f;
         if (-xLastIncr > 1.0f)
            fXInertia = (xLastIncr + 1.0f)*0.5f;
         if (yLastIncr > 1.0f)
            fYInertia = (yLastIncr - 1.0f)*0.5f;
         if (-yLastIncr > 1.0f)
            fYInertia = (yLastIncr + 1.0f)*0.5f;
      }
      else
      {
         fXInertia = 0;
         fYInertia = 0;
      }
      xLastIncr = 0;
      yLastIncr = 0;
   }
}

variable_types: button int

variable_types: state int


reshape

decompiled_code:
__int64 __fastcall reshape(int a1, int a2)
{
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glFrustum(
-0.800000011920929,
0.800000011920929,
(float)(-0.80000001 / (float)((float)a1 / (float)a2)),
(float)(0.80000001 / (float)((float)a1 / (float)a2)),
3.0,
10.0);
glMatrixMode(5888LL);
glLoadIdentity();
return glTranslatef(0.0, 0.0, -5.0);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glFrustum(
-0.800000011920929,
0.800000011920929,
(float)(-0.80000001 / (float)((float)a1 / (float)a2)),
(float)(0.80000001 / (float)((float)a1 / (float)a2)),
3.0,
10.0);
glMatrixMode(5888LL);
glLoadIdentity();
return glTranslatef(0.0, 0.0, -5.0);
}

original_code:
static
void reshape(int wid, int ht)
{
    float vp = 0.8f;
    float aspect = (float) wid / (float) ht;
    glViewport(0, 0, wid, ht);
    glMatrixMode(0x1701);
    glLoadIdentity();
    glViewport(0, 0, wid, ht);
    glMatrixMode(0x1701);
    glLoadIdentity();
    glFrustum(-vp, vp, -vp / aspect, vp / aspect, 3, 10.0);
    glMatrixMode(0x1700);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -5.0);
}

variable_types: wid int

variable_types: ht int

variable_types: vp float

variable_types: aspect float


display

decompiled_code:
__int64 display()
{
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);
glRotatef(*(float *)&fYDiff, 1.0, 0.0);
glRotatef(*(float *)&fXDiff, 0.0, COERCE_DOUBLE((unsigned __int64)LC4));
glRotatef(*(float *)&fZDiff, 0.0, 0.0);
glScalef(*(float *)&fScale, *(float *)&fScale, *(float *)&fScale, 1.0);
glClear(16640LL);
if ( gleModel == 2 )
{
glutSolidSphere(64LL, 64LL, 0.6000000238418579);
}
else if ( (unsigned int)gleModel > 2 )
{
if ( gleModel == 3 )
glutSolidTorus(64LL, 64LL, 0.2000000029802322, 0.6000000238418579);
}
else if ( gleModel )
{
glutSolidTeapot(0.6000000238418579);
}
else
{
drawCube();
}
glFlush();
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func5()
{
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);
glRotatef(*(float *)&fYDiff, 1.0, 0.0);
glRotatef(*(float *)&fXDiff, 0.0, COERCE_DOUBLE((unsigned __int64)LC4));
glRotatef(*(float *)&fZDiff, 0.0, 0.0);
glScalef(*(float *)&fScale, *(float *)&fScale, *(float *)&fScale, 1.0);
glClear(16640LL);
if ( gleModel == 2 )
{
glutSolidSphere(64LL, 64LL, 0.6000000238418579);
}
else if ( (unsigned int)gleModel > 2 )
{
if ( gleModel == 3 )
glutSolidTorus(64LL, 64LL, 0.2000000029802322, 0.6000000238418579);
}
else if ( gleModel )
{
glutSolidTeapot(0.6000000238418579);
}
else
{
drawCube();
}
glFlush();
return glutSwapBuffers();
}

original_code:
static
void display(void)
{
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -5.0);
    glRotatef(fYDiff, 1,0,0);
    glRotatef(fXDiff, 0,1,0);
    glRotatef(fZDiff, 0,0,1);
    glScalef(fScale, fScale, fScale);
    glClear(0x00004000 | 0x00000100);
    switch( gleModel )
    {
        case EModelTeapot:
            glutSolidTeapot(0.6f);
            break;
        case EModelTorus:
            glutSolidTorus(0.2f, 0.6f, 64, 64);
            break;
        case EModelSphere:
            glutSolidSphere(0.6f, 64, 64);
            break;
        case EModelCube:
            drawCube();
            break;
    }
    glFlush();
    glutSwapBuffers();
}

canonical_original_code:
static void display()
{
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -5.0);
    glRotatef(fYDiff, 1,0,0);
    glRotatef(fXDiff, 0,1,0);
    glRotatef(fZDiff, 0,0,1);
    glScalef(fScale, fScale, fScale);
    glClear(0x00004000 | 0x00000100);
    switch( gleModel )
    {
        case EModelTeapot:
            glutSolidTeapot(0.6f);
            break;
        case EModelTorus:
            glutSolidTorus(0.2f, 0.6f, 64, 64);
            break;
        case EModelSphere:
            glutSolidSphere(0.6f, 64, 64);
            break;
        case EModelCube:
            drawCube();
            break;
    }
    glFlush();
    glutSwapBuffers();
}


play

decompiled_code:
__int64 play()
{
int v0; // eax

v0 = glutGet(700LL);
*(float *)&RotL = (float)((float)(v0 - LastTime) * -0.001) + *(float *)&RotL;
LastTime = v0;
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax

v0 = glutGet(700LL);
*(float *)&RotL = (float)((float)(v0 - LastTime) * -0.001) + *(float *)&RotL;
LastTime = v0;
return glutPostRedisplay();
}

original_code:
static
void play(void)
{
    int thisTime = glutGet(0x02BC);
    RotL += (thisTime - LastTime) * -0.001f;
    LastTime = thisTime;
    glutPostRedisplay();
}

canonical_original_code:
static void play()
{
    int thisTime = glutGet(0x02BC);
    RotL += (thisTime - LastTime) * -0.001f;
    LastTime = thisTime;
    glutPostRedisplay();
}

variable_types: thisTime int


NextClearColor

decompiled_code:
__int64 NextClearColor()
{
int v0; // eax
__int64 result; // rax

v0 = color_0++;
if ( !v0 )
return glClearColor(0.0, 0.0, 0.0, 1.0);
if ( v0 == 1 )
return glClearColor(
COERCE_DOUBLE((unsigned __int64)LC17),
COERCE_DOUBLE((unsigned __int64)LC17),
COERCE_DOUBLE((unsigned __int64)LC16),
1.0);
result = glClearColor(
COERCE_DOUBLE((unsigned __int64)LC18),
COERCE_DOUBLE((unsigned __int64)LC18),
COERCE_DOUBLE((unsigned __int64)LC18),
1.0);
color_0 = 0;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
__int64 result; // rax

v0 = color_0++;
if ( !v0 )
return glClearColor(0.0, 0.0, 0.0, 1.0);
if ( v0 == 1 )
return glClearColor(
COERCE_DOUBLE((unsigned __int64)LC17),
COERCE_DOUBLE((unsigned __int64)LC17),
COERCE_DOUBLE((unsigned __int64)LC16),
1.0);
result = glClearColor(
COERCE_DOUBLE((unsigned __int64)LC18),
COERCE_DOUBLE((unsigned __int64)LC18),
COERCE_DOUBLE((unsigned __int64)LC18),
1.0);
color_0 = 0;
return result;
}

original_code:
static void NextClearColor(void)
{
    static int color = 0;
    switch( color++ )
    {
        case 0: glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
             break;
        case 1: glClearColor(0.2f, 0.2f, 0.3f, 1.0f);
             break;
        default: glClearColor(0.7f, 0.7f, 0.7f, 1.0f);
             color = 0;
             break;
    }
}

canonical_original_code:
static void NextClearColor()
{
    static int color = 0;
    switch( color++ )
    {
        case 0: glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
             break;
        case 1: glClearColor(0.2f, 0.2f, 0.3f, 1.0f);
             break;
        default: glClearColor(0.7f, 0.7f, 0.7f, 1.0f);
             color = 0;
             break;
    }
}

variable_types: color int


key

decompiled_code:
void __fastcall key(unsigned __int8 a1)
{
int v1; // eax
bool v2; // zf

if ( a1 == 45 )
{
*(float *)&fScale = *(float *)&fScale - 0.5;
return;
}
if ( a1 > 0x2Du )
{
if ( a1 != 113 )
{
if ( a1 == 116 )
{
v1 = 0;
if ( (unsigned int)gleModel <= 2 )
v1 = gleModel + 1;
gleModel = v1;
return;
}
if ( a1 == 98 )
{
NextClearColor();
return;
}
LABEL_22:
fwrite(
"\n"
"Keyboard commands:\n"
"\n"
"b - Toggle among background clear colors\n"
"q, <esc> - Quit\n"
"t - Toggle among models to render\n"
"? - Help\n"
"<home> - reset zoom and rotation\n"
"<space> or <click> - stop rotation\n"
"<+>, <-> or <ctrl + drag> - zoom model\n"
"<arrow keys> or <drag> - rotate model\n"
"\n",
1uLL,
0x119uLL,
stderr);
return;
}
LABEL_12:
exit(0);
}
if ( a1 != 32 )
{
if ( a1 == 43 )
{
*(float *)&fScale = *(float *)&fScale + 0.5;
return;
}
if ( a1 != 27 )
goto LABEL_22;
goto LABEL_12;
}
v2 = Rotate == 0;
Rotate = Rotate == 0;
if ( v2 )
{
fXInertia = fXInertiaOld;
fYInertia = fYInertiaOld;
if ( *(float *)&fYInertiaOld == 0.0 && *(float *)&fXInertiaOld == 0.0 )
fXInertia = -1090519040;
}
else
{
fXInertiaOld = fXInertia;
fYInertiaOld = fYInertia;
}
}

canonical_decompiled_code:
void __fastcall func8(unsigned __int8 a1)
{
int v1; // eax
bool v2; // zf

if ( a1 == 45 )
{
*(float *)&fScale = *(float *)&fScale - 0.5;
return;
}
if ( a1 > 0x2Du )
{
if ( a1 != 113 )
{
if ( a1 == 116 )
{
v1 = 0;
if ( (unsigned int)gleModel <= 2 )
v1 = gleModel + 1;
gleModel = v1;
return;
}
if ( a1 == 98 )
{
func7();
return;
}
LABEL_22:
fwrite(
"\n"
"Keyboard commands:\n"
"\n"
"b - Toggle among background clear colors\n"
"q, <esc> - Quit\n"
"t - Toggle among models to render\n"
"? - Help\n"
"<home> - reset zoom and rotation\n"
"<space> or <click> - stop rotation\n"
"<+>, <-> or <ctrl + drag> - zoom model\n"
"<arrow keys> or <drag> - rotate model\n"
"\n",
1uLL,
0x119uLL,
stderr);
return;
}
LABEL_12:
exit(0);
}
if ( a1 != 32 )
{
if ( a1 == 43 )
{
*(float *)&fScale = *(float *)&fScale + 0.5;
return;
}
if ( a1 != 27 )
goto LABEL_22;
goto LABEL_12;
}
v2 = Rotate == 0;
Rotate = Rotate == 0;
if ( v2 )
{
fXInertia = fXInertiaOld;
fYInertia = fYInertiaOld;
if ( *(float *)&fYInertiaOld == 0.0 && *(float *)&fXInertiaOld == 0.0 )
fXInertia = -1090519040;
}
else
{
fXInertiaOld = fXInertia;
fYInertiaOld = fYInertia;
}
}

original_code:
static
void key(unsigned char keyPressed, int x, int y)
{
    switch(keyPressed)
    {
        case 'b':
            NextClearColor();
            break;
        case 'q':
        case 27:
            exit(0);
            break;
        case 't':
            if (gleModel >= EModelLast)
                gleModel = EModelFirst;
            else
                gleModel = (EModelType) ((int) gleModel + 1);
            break;
        case ' ':
            Rotate = !Rotate;
            if (!Rotate)
            {
                fXInertiaOld = fXInertia;
                fYInertiaOld = fYInertia;
            }
            else
            {
                fXInertia = fXInertiaOld;
                fYInertia = fYInertiaOld;
                if ((fXInertia == 0.0) && (fYInertia == 0.0))
                    fXInertia = -0.5;
            }
            break;
        case '+':
            fScale += 0.5f;
            break;
        case '-':
            fScale -= 0.5f;
            break;
        default:
            fprintf(stderr, "\nKeyboard commands:\n\n"
            "b - Toggle among background clear colors\n"
            "q, <esc> - Quit\n"
            "t - Toggle among models to render\n"
            "? - Help\n"
            "<home>     - reset zoom and rotation\n"
            "<space> or <click>        - stop rotation\n"
            "<+>, <-> or <ctrl + drag> - zoom model\n"
            "<arrow keys> or <drag>    - rotate model\n\n");
            break;
    }
}

variable_types:
keyPressed
unsigned char


printOglError

decompiled_code:
__int64 __fastcall printOglError(const char *a1, unsigned int a2)
{
unsigned int v3; // eax
__int64 v4; // rdi
const char *v5; // rax
unsigned int v6; // eax

v3 = glGetError();
v4 = v3;
if ( !v3 )
return 0LL;
do
{
v5 = (const char *)gluErrorString(v4);
printf("glError in file %s @ line %d: %s\n", a1, a2, v5);
v6 = glGetError();
v4 = v6;
}
while ( v6 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, unsigned int a2)
{
unsigned int v3; // eax
__int64 v4; // rdi
const char *v5; // rax
unsigned int v6; // eax

v3 = glGetError();
v4 = v3;
if ( !v3 )
return 0LL;
do
{
v5 = (const char *)gluErrorString(v4);
printf("glError in file %s @ line %d: %s\n", a1, a2, v5);
v6 = glGetError();
v4 = v6;
}
while ( v6 );
return 1LL;
}

original_code:
int printOglError(char *file, int line)
{
    GLenum glErr;
    int retCode = 0;
    glErr = glGetError();
    while (glErr != 0)
    {
        printf("glError in file %s @ line %d: %s\n", file, line, gluErrorString(glErr));
        retCode = 1;
        glErr = glGetError();
    }
    return retCode;
}

canonical_original_code:
int printOglError(char *file, int line)
{
    unsigned int glErr;
    int retCode = 0;
    glErr = glGetError();
    while (glErr != 0)
    {
        printf("glError in file %s @ line %d: %s\n", file, line, gluErrorString(glErr));
        retCode = 1;
        glErr = glGetError();
    }
    return retCode;
}

variable_types:
file
char *

variable_types: line int

variable_types:
glErr
unsigned int

variable_types: retCode int


getGlVersion

decompiled_code:
size_t __fastcall getGlVersion(_DWORD *a1, _DWORD *a2)
{
__int64 v2; // rax
size_t result; // rax

v2 = glGetString(7938LL);
if ( !v2 || (result = _isoc99_sscanf(v2, "%d.%d", a1, a2), (_DWORD)result != 2) )
{
*a2 = 0;
*a1 = 0;
result = fwrite("Invalid GL_VERSION format!!!\n", 1uLL, 0x1DuLL, stderr);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func10(_DWORD *a1, _DWORD *a2)
{
__int64 v2; // rax
size_t result; // rax

v2 = glGetString(7938LL);
if ( !v2 || (result = _isoc99_sscanf(v2, "%d.%d", a1, a2), (_DWORD)result != 2) )
{
*a2 = 0;
*a1 = 0;
result = fwrite("Invalid GL_VERSION format!!!\n", 1uLL, 0x1DuLL, stderr);
}
return result;
}

original_code:
void getGlVersion( int *major, int *minor )
{
    const char* verstr = (const char*)glGetString( 0x1F02 );
    if( (verstr == ((void *)0)) || (sscanf( verstr, "%d.%d", major, minor ) != 2) )
    {
        *major = *minor = 0;
        fprintf( stderr, "Invalid GL_VERSION format!!!\n" );
    }
}

canonical_original_code:
void getGlVersion(int *major, int *minor)
{
    char *verstr = (const char*)glGetString( 0x1F02 );
    if( (verstr == ((void *)0)) || (sscanf( verstr, "%d.%d", major, minor ) != 2) )
    {
        *major = *minor = 0;
        fprintf( stderr, "Invalid GL_VERSION format!!!\n" );
    }
}

variable_types:
major
int *

variable_types:
minor
int *

variable_types:
verstr
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rsi
__int64 v4; // rdx
int v6[3]; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v7; // [rsp+18h] [rbp-20h] BYREF
__int64 v8; // [rsp+20h] [rbp-18h] BYREF
unsigned int v9; // [rsp+28h] [rbp-10h] BYREF
unsigned int v10[3]; // [rsp+2Ch] [rbp-Ch] BYREF

v6[0] = argc;
glutInit(v6, argv, envp);
glutInitDisplayMode(18LL);
glutInitWindowSize(500LL, 500LL);
glutCreateWindow("3Dlabs Brick Shader");
glutIdleFunc(play);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutReshapeFunc(reshape);
glutMotionFunc(motion);
glutMouseFunc(mouse);
glutSpecialFunc(special);
glutTimerFunc(20LL, timer, 0LL);
glewInit();
getGlVersion(v10, &v9);
printf("GL_VERSION major=%d minor=%d\n", v10[0], v9);
v3 = v10[0];
if ( (int)v10[0] <= 1 )
{
printf("GL_VERSION major=%d minor=%d\n", v10[0], v9);
puts("Support for OpenGL 2.0 is required for this demo...exiting");
exit(1);
}
glDepthFunc(513LL);
glEnable("or=%d minor=%d\n", v3, v4);
NextClearColor();
key(0x3Fu);
readShaderSource("brick", &v8, &v7);
if ( (unsigned int)installBrickShaders(v8, v7) )
glutMainLoop();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rsi
__int64 v4; // rdx
int v6[3]; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v7; // [rsp+18h] [rbp-20h] BYREF
__int64 v8; // [rsp+20h] [rbp-18h] BYREF
unsigned int v9; // [rsp+28h] [rbp-10h] BYREF
unsigned int v10[3]; // [rsp+2Ch] [rbp-Ch] BYREF

v6[0] = argc;
glutInit(v6, argv, envp);
glutInitDisplayMode(18LL);
glutInitWindowSize(500LL, 500LL);
glutCreateWindow("3Dlabs Brick Shader");
glutIdleFunc(play);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutReshapeFunc(reshape);
glutMotionFunc(motion);
glutMouseFunc(mouse);
glutSpecialFunc(special);
glutTimerFunc(20LL, timer, 0LL);
glewInit();
func10(v10, &v9);
printf("GL_VERSION major=%d minor=%d\n", v10[0], v9);
v3 = v10[0];
if ( (int)v10[0] <= 1 )
{
printf("GL_VERSION major=%d minor=%d\n", v10[0], v9);
puts("Support for OpenGL 2.0 is required for this demo...exiting");
exit(1);
}
glDepthFunc(513LL);
glEnable("or=%d minor=%d\n", v3, v4);
func7();
func8(0x3Fu);
readShaderSource("brick", &v8, &v7);
if ( (unsigned int)installBrickShaders(v8, v7) )
glutMainLoop();
return 0;
}

original_code:
int main( int argc, char **argv )
{
    int success = 0;
    int gl_major, gl_minor;
    GLchar *VertexShaderSource, *FragmentShaderSource;
    glutInit( &argc, argv );
    glutInitDisplayMode( 0x0000 | 0x0010 | 0x0002);
    glutInitWindowSize(500, 500);
    window = glutCreateWindow( "3Dlabs Brick Shader");
    glutIdleFunc(play);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutSpecialFunc(special);
    glutTimerFunc(20 , timer, 0);
    glewInit();
    getGlVersion(&gl_major, &gl_minor);
    printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);
    if (gl_major < 2)
    {
        printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);
        printf("Support for OpenGL 2.0 is required for this demo...exiting\n");
        exit(1);
    }
    glDepthFunc(0x0201);
    glEnable(0x0B71);
    NextClearColor();
    key('?', 0, 0);
    readShaderSource("brick", &VertexShaderSource, &FragmentShaderSource);
    success = installBrickShaders(VertexShaderSource, FragmentShaderSource);
    if (success)
        glutMainLoop();
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int success = 0;
    int gl_major; int gl_minor;
    char *VertexShaderSource; char *FragmentShaderSource;
    glutInit( &argc, argv );
    glutInitDisplayMode( 0x0000 | 0x0010 | 0x0002);
    glutInitWindowSize(500, 500);
    window = glutCreateWindow( "3Dlabs Brick Shader");
    glutIdleFunc(play);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutSpecialFunc(special);
    glutTimerFunc(20 , timer, 0);
    glewInit();
    getGlVersion(&gl_major, &gl_minor);
    printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);
    if (gl_major < 2)
    {
        printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);
        printf("Support for OpenGL 2.0 is required for this demo...exiting\n");
        exit(1);
    }
    glDepthFunc(0x0201);
    glEnable(0x0B71);
    NextClearColor();
    key('?', 0, 0);
    readShaderSource("brick", &VertexShaderSource, &FragmentShaderSource);
    success = installBrickShaders(VertexShaderSource, FragmentShaderSource);
    if (success)
        glutMainLoop();
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: success int

variable_types:
VertexShaderSource
char *

variable_types:
FragmentShaderSource
char *


shaderSize

decompiled_code:
__int64 __fastcall shaderSize(char *src, int a2)
{
int v2; // eax
int v3; // ebx
unsigned int v4; // ebp
char v6[136]; // [rsp+0h] [rbp-88h] BYREF

strcpy(v6, src);
if ( a2 )
{
if ( a2 != 1 )
{
puts("ERROR: unknown shader file type");
exit(1);
}
strcat(v6, ".frag");
}
else
{
strcat(v6, ".vert");
}
v2 = open(v6, 0);
v3 = v2;
if ( v2 == -1 )
return (unsigned int)-1;
v4 = lseek(v2, 0LL, 2) + 1;
close(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src, int a2)
{
int v2; // eax
int v3; // ebx
unsigned int v4; // ebp
char v6[136]; // [rsp+0h] [rbp-88h] BYREF

strcpy(v6, src);
if ( a2 )
{
if ( a2 != 1 )
{
puts("ERROR: unknown shader file type");
exit(1);
}
strcat(v6, ".frag");
}
else
{
strcat(v6, ".vert");
}
v2 = open(v6, 0);
v3 = v2;
if ( v2 == -1 )
return (unsigned int)-1;
v4 = lseek(v2, 0LL, 2) + 1;
close(v3);
return v4;
}

original_code:
static
int shaderSize(char *fileName, EShaderType shaderType)
{
    int fd;
    char name[100];
    int count = -1;
    strcpy(name, fileName);
    switch (shaderType)
    {
        case EVertexShader:
            strcat(name, ".vert");
            break;
        case EFragmentShader:
            strcat(name, ".frag");
            break;
        default:
            printf("ERROR: unknown shader file type\n");
            exit(1);
            break;
    }
    fd = open(name, 00);
    if (fd != -1)
    {
        count = lseek(fd, 0, 2) + 1;
        close(fd);
    }
    return count;
}

canonical_original_code:
static int shaderSize(char *fileName, enum EShaderType shaderType)
{
    int fd;
    char name[100];
    int count = -1;
    strcpy(name, fileName);
    switch (shaderType)
    {
        case EVertexShader:
            strcat(name, ".vert");
            break;
        case EFragmentShader:
            strcat(name, ".frag");
            break;
        default:
            printf("ERROR: unknown shader file type\n");
            exit(1);
            break;
    }
    fd = open(name, 00);
    if (fd != -1)
    {
        count = lseek(fd, 0, 2) + 1;
        close(fd);
    }
    return count;
}

variable_types:
fileName
char *

variable_types: enum EShaderType { EVertexShader=0, EFragmentShader=1 }

variable_types: fd int

variable_types:
name
char [100]

variable_types: count int


getUniLoc

decompiled_code:
__int64 __fastcall getUniLoc(__int64 a1, const char *a2)
{
unsigned int v2; // ebx

v2 = _glewGetUniformLocation();
if ( v2 == -1 )
printf("No such uniform named \"%s\"\n", a2);
printOglError("shader.c", 57LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
unsigned int v2; // ebx

v2 = _glewGetUniformLocation();
if ( v2 == -1 )
printf("No such uniform named \"%s\"\n", a2);
printOglError("shader.c", 57LL);
return v2;
}

original_code:
static
GLint getUniLoc(GLuint program, const GLchar *name)
{
    GLint loc;
    loc = __glewGetUniformLocation(program, name);
    if (loc == -1)
        printf("No such uniform named \"%s\"\n", name);
    printOglError("shader.c", 57);
    return loc;
}

canonical_original_code:
static int getUniLoc(unsigned int program, char *name)
{
    int loc;
    loc = __glewGetUniformLocation(program, name);
    if (loc == -1)
        printf("No such uniform named \"%s\"\n", name);
    printOglError("shader.c", 57);
    return loc;
}

variable_types:
program
unsigned int

variable_types:
name
char *

variable_types: loc int


printShaderInfoLog

decompiled_code:
__int64 __fastcall printShaderInfoLog(unsigned int a1)
{
unsigned int v1; // er12
char *v2; // rax
char *v3; // rbp
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
v5 = 0;
printOglError("shader.c", 71LL);
_glewGetShaderiv(a1, 35716LL, v6);
printOglError("shader.c", 75LL);
v1 = v6[0];
if ( v6[0] > 0 )
{
v2 = (char *)malloc(v6[0]);
v3 = v2;
if ( !v2 )
{
puts("ERROR: Could not allocate InfoLog buffer");
exit(1);
}
_glewGetShaderInfoLog(a1, v1, &v5, v2);
printf("Shader InfoLog:\n%s\n\n", v3);
free(v3);
}
return printOglError("shader.c", 89LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
unsigned int v1; // er12
char *v2; // rax
char *v3; // rbp
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
v5 = 0;
printOglError("shader.c", 71LL);
_glewGetShaderiv(a1, 35716LL, v6);
printOglError("shader.c", 75LL);
v1 = v6[0];
if ( v6[0] > 0 )
{
v2 = (char *)malloc(v6[0]);
v3 = v2;
if ( !v2 )
{
puts("ERROR: Could not allocate InfoLog buffer");
exit(1);
}
_glewGetShaderInfoLog(a1, v1, &v5, v2);
printf("Shader InfoLog:\n%s\n\n", v3);
free(v3);
}
return printOglError("shader.c", 89LL);
}

original_code:
static
void printShaderInfoLog(GLuint shader)
{
    int infologLength = 0;
    int charsWritten = 0;
    GLchar *infoLog;
    printOglError("shader.c", 71);
    __glewGetShaderiv(shader, 0x8B84, &infologLength);
    printOglError("shader.c", 75);
    if (infologLength > 0)
    {
        infoLog = (GLchar *)malloc(infologLength);
        if (infoLog == ((void *)0))
        {
            printf("ERROR: Could not allocate InfoLog buffer\n");
            exit(1);
        }
        __glewGetShaderInfoLog(shader, infologLength, &charsWritten, infoLog);
        printf("Shader InfoLog:\n%s\n\n", infoLog);
        free(infoLog);
    }
    printOglError("shader.c", 89);
}

canonical_original_code:
static void printShaderInfoLog(unsigned int shader)
{
    int infologLength = 0;
    int charsWritten = 0;
    char *infoLog;
    printOglError("shader.c", 71);
    __glewGetShaderiv(shader, 0x8B84, &infologLength);
    printOglError("shader.c", 75);
    if (infologLength > 0)
    {
        infoLog = (char *)malloc(infologLength);
        if (infoLog == ((void *)0))
        {
            printf("ERROR: Could not allocate InfoLog buffer\n");
            exit(1);
        }
        __glewGetShaderInfoLog(shader, infologLength, &charsWritten, infoLog);
        printf("Shader InfoLog:\n%s\n\n", infoLog);
        free(infoLog);
    }
    printOglError("shader.c", 89);
}

variable_types:
shader
unsigned int

variable_types: infologLength int

variable_types: charsWritten int

variable_types:
infoLog
char *


printProgramInfoLog

decompiled_code:
__int64 __fastcall printProgramInfoLog(unsigned int a1)
{
unsigned int v1; // er12
char *v2; // rax
char *v3; // rbp
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
v5 = 0;
printOglError("shader.c", 103LL);
_glewGetProgramiv(a1, 35716LL, v6);
printOglError("shader.c", 107LL);
v1 = v6[0];
if ( v6[0] > 0 )
{
v2 = (char *)malloc(v6[0]);
v3 = v2;
if ( !v2 )
{
puts("ERROR: Could not allocate InfoLog buffer");
exit(1);
}
_glewGetProgramInfoLog(a1, v1, &v5, v2);
printf("Program InfoLog:\n%s\n\n", v3);
free(v3);
}
return printOglError("shader.c", 121LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
unsigned int v1; // er12
char *v2; // rax
char *v3; // rbp
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
v5 = 0;
printOglError("shader.c", 103LL);
_glewGetProgramiv(a1, 35716LL, v6);
printOglError("shader.c", 107LL);
v1 = v6[0];
if ( v6[0] > 0 )
{
v2 = (char *)malloc(v6[0]);
v3 = v2;
if ( !v2 )
{
puts("ERROR: Could not allocate InfoLog buffer");
exit(1);
}
_glewGetProgramInfoLog(a1, v1, &v5, v2);
printf("Program InfoLog:\n%s\n\n", v3);
free(v3);
}
return printOglError("shader.c", 121LL);
}

original_code:
static
void printProgramInfoLog(GLuint program)
{
    int infologLength = 0;
    int charsWritten = 0;
    GLchar *infoLog;
    printOglError("shader.c", 103);
    __glewGetProgramiv(program, 0x8B84, &infologLength);
    printOglError("shader.c", 107);
    if (infologLength > 0)
    {
        infoLog = (GLchar *)malloc(infologLength);
        if (infoLog == ((void *)0))
        {
            printf("ERROR: Could not allocate InfoLog buffer\n");
            exit(1);
        }
        __glewGetProgramInfoLog(program, infologLength, &charsWritten, infoLog);
        printf("Program InfoLog:\n%s\n\n", infoLog);
        free(infoLog);
    }
    printOglError("shader.c", 121);
}

canonical_original_code:
static void printProgramInfoLog(unsigned int program)
{
    int infologLength = 0;
    int charsWritten = 0;
    char *infoLog;
    printOglError("shader.c", 103);
    __glewGetProgramiv(program, 0x8B84, &infologLength);
    printOglError("shader.c", 107);
    if (infologLength > 0)
    {
        infoLog = (char *)malloc(infologLength);
        if (infoLog == ((void *)0))
        {
            printf("ERROR: Could not allocate InfoLog buffer\n");
            exit(1);
        }
        __glewGetProgramInfoLog(program, infologLength, &charsWritten, infoLog);
        printf("Program InfoLog:\n%s\n\n", infoLog);
        free(infoLog);
    }
    printOglError("shader.c", 121);
}


readShaderSource

decompiled_code:
__int64 __fastcall readShaderSource(char *src, void **a2, void **a3)
{
int v4; // ebp
int v5; // eax
int v6; // er12
unsigned int v7; // ebp

v4 = shaderSize(src, 0);
v5 = shaderSize(src, 1);
if ( v4 == -1 || (v6 = v5, v5 == -1) )
{
printf("Cannot determine size of the shader %s\n", src);
v7 = 0;
}
else
{
*a2 = malloc(v4);
*a3 = malloc(v6);
v7 = readShader(src, 0, *a2, v4);
if ( v7 )
{
v7 = readShader(src, 1, *a3, v6);
if ( v7 )
v7 = 1;
else
printf("Cannot read the file %s.frag\n", src);
}
else
{
printf("Cannot read the file %s.vert\n", src);
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *src, void **a2, void **a3)
{
int v4; // ebp
int v5; // eax
int v6; // er12
unsigned int v7; // ebp

v4 = func0(src, 0);
v5 = func0(src, 1);
if ( v4 == -1 || (v6 = v5, v5 == -1) )
{
printf("Cannot determine size of the shader %s\n", src);
v7 = 0;
}
else
{
*a2 = malloc(v4);
*a3 = malloc(v6);
v7 = func1(src, 0, *a2, v4);
if ( v7 )
{
v7 = func1(src, 1, *a3, v6);
if ( v7 )
v7 = 1;
else
printf("Cannot read the file %s.frag\n", src);
}
else
{
printf("Cannot read the file %s.vert\n", src);
}
}
return v7;
}

original_code:
int readShaderSource(char *fileName, GLchar **vertexShader, GLchar **fragmentShader)
{
    int vSize, fSize;
    vSize = shaderSize(fileName, EVertexShader);
    fSize = shaderSize(fileName, EFragmentShader);
    if ((vSize == -1) || (fSize == -1))
    {
        printf("Cannot determine size of the shader %s\n", fileName);
        return 0;
    }
    *vertexShader = (GLchar *) malloc(vSize);
    *fragmentShader = (GLchar *) malloc(fSize);
    if (!readShader(fileName, EVertexShader, *vertexShader, vSize))
    {
        printf("Cannot read the file %s.vert\n", fileName);
        return 0;
    }
    if (!readShader(fileName, EFragmentShader, *fragmentShader, fSize))
    {
        printf("Cannot read the file %s.frag\n", fileName);
        return 0;
    }
    return 1;
}

canonical_original_code:
int readShaderSource(char *fileName, char **vertexShader, char **fragmentShader)
{
    int vSize; int fSize;
    vSize = shaderSize(fileName, EVertexShader);
    fSize = shaderSize(fileName, EFragmentShader);
    if ((vSize == -1) || (fSize == -1))
    {
        printf("Cannot determine size of the shader %s\n", fileName);
        return 0;
    }
    *vertexShader = (char *) malloc(vSize);
    *fragmentShader = (char *) malloc(fSize);
    if (!readShader(fileName, EVertexShader, *vertexShader, vSize))
    {
        printf("Cannot read the file %s.vert\n", fileName);
        return 0;
    }
    if (!readShader(fileName, EFragmentShader, *fragmentShader, fSize))
    {
        printf("Cannot read the file %s.frag\n", fileName);
        return 0;
    }
    return 1;
}

variable_types:
vertexShader
char **

variable_types:
fragmentShader
char **

variable_types: vSize int

variable_types: fSize int


installBrickShaders

decompiled_code:
__int64 __fastcall installBrickShaders(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebx
__int64 result; // rax
__int64 v5; // r12
void (__fastcall *v6)(_QWORD, float, float, float); // rbx
unsigned int v7; // eax
void (__fastcall *v8)(_QWORD, float, float, float); // rbx
unsigned int v9; // eax
void (__fastcall *v10)(_QWORD, float, float); // rbx
unsigned int v11; // eax
void (__fastcall *v12)(_QWORD, float, float); // rbx
unsigned int v13; // eax
void (__fastcall *v14)(_QWORD, float, float, float); // rbx
unsigned int v15; // eax
__int64 v16; // [rsp+0h] [rbp-38h] BYREF
__int64 v17; // [rsp+8h] [rbp-30h] BYREF
unsigned int v18; // [rsp+14h] [rbp-24h] BYREF
unsigned int v19; // [rsp+18h] [rbp-20h] BYREF
unsigned int v20[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v17 = a1;
v16 = a2;
v2 = _glewCreateShader(35633LL);
v3 = _glewCreateShader(35632LL);
_glewShaderSource(v2, 1LL, &v17, 0LL);
_glewShaderSource(v3, 1LL, &v16, 0LL);
_glewCompileShader(v2);
printOglError("shader.c", 292LL);
_glewGetShaderiv(v2, 35713LL, v20);
printShaderInfoLog(v2);
_glewCompileShader(v3);
printOglError("shader.c", 300LL);
_glewGetShaderiv(v3, 35713LL, &v19);
printShaderInfoLog(v3);
result = v20[0];
if ( v20[0] )
{
result = v19;
if ( v19 )
{
v5 = (unsigned int)_glewCreateProgram();
_glewAttachShader(v5, v2);
_glewAttachShader((unsigned int)v5, v3);
_glewLinkProgram((unsigned int)v5);
printOglError("shader.c", 316LL);
_glewGetProgramiv((unsigned int)v5, 35714LL, &v18);
printProgramInfoLog(v5);
result = v18;
if ( v18 )
{
_glewUseProgram((unsigned int)v5);
v6 = (void (__fastcall *)(_QWORD, float, float, float))_glewUniform3f;
v7 = getUniLoc((unsigned int)v5, "BrickColor");
v6(v7, 1.0, 0.30000001, 0.2);
v8 = (void (__fastcall *)(_QWORD, float, float, float))_glewUniform3f;
v9 = getUniLoc((unsigned int)v5, "MortarColor");
v8(v9, 0.85000002, 0.86000001, 0.83999997);
v10 = (void (__fastcall *)(_QWORD, float, float))_glewUniform2f;
v11 = getUniLoc((unsigned int)v5, "BrickSize");
v10(v11, 0.30000001, 0.15000001);
v12 = (void (__fastcall *)(_QWORD, float, float))_glewUniform2f;
v13 = getUniLoc((unsigned int)v5, "BrickPct");
v12(v13, 0.89999998, 0.85000002);
v14 = (void (__fastcall *)(_QWORD, float, float, float))_glewUniform3f;
v15 = getUniLoc((unsigned int)v5, "LightPosition");
v14(v15, 0.0, 0.0, 4.0);
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebx
__int64 result; // rax
__int64 v5; // r12
void (__fastcall *v6)(_QWORD, float, float, float); // rbx
unsigned int v7; // eax
void (__fastcall *v8)(_QWORD, float, float, float); // rbx
unsigned int v9; // eax
void (__fastcall *v10)(_QWORD, float, float); // rbx
unsigned int v11; // eax
void (__fastcall *v12)(_QWORD, float, float); // rbx
unsigned int v13; // eax
void (__fastcall *v14)(_QWORD, float, float, float); // rbx
unsigned int v15; // eax
__int64 v16; // [rsp+0h] [rbp-38h] BYREF
__int64 v17; // [rsp+8h] [rbp-30h] BYREF
unsigned int v18; // [rsp+14h] [rbp-24h] BYREF
unsigned int v19; // [rsp+18h] [rbp-20h] BYREF
unsigned int v20[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v17 = a1;
v16 = a2;
v2 = _glewCreateShader(35633LL);
v3 = _glewCreateShader(35632LL);
_glewShaderSource(v2, 1LL, &v17, 0LL);
_glewShaderSource(v3, 1LL, &v16, 0LL);
_glewCompileShader(v2);
printOglError("shader.c", 292LL);
_glewGetShaderiv(v2, 35713LL, v20);
func3(v2);
_glewCompileShader(v3);
printOglError("shader.c", 300LL);
_glewGetShaderiv(v3, 35713LL, &v19);
func3(v3);
result = v20[0];
if ( v20[0] )
{
result = v19;
if ( v19 )
{
v5 = (unsigned int)_glewCreateProgram();
_glewAttachShader(v5, v2);
_glewAttachShader((unsigned int)v5, v3);
_glewLinkProgram((unsigned int)v5);
printOglError("shader.c", 316LL);
_glewGetProgramiv((unsigned int)v5, 35714LL, &v18);
func4(v5);
result = v18;
if ( v18 )
{
_glewUseProgram((unsigned int)v5);
v6 = (void (__fastcall *)(_QWORD, float, float, float))_glewUniform3f;
v7 = func2((unsigned int)v5, "BrickColor");
v6(v7, 1.0, 0.30000001, 0.2);
v8 = (void (__fastcall *)(_QWORD, float, float, float))_glewUniform3f;
v9 = func2((unsigned int)v5, "MortarColor");
v8(v9, 0.85000002, 0.86000001, 0.83999997);
v10 = (void (__fastcall *)(_QWORD, float, float))_glewUniform2f;
v11 = func2((unsigned int)v5, "BrickSize");
v10(v11, 0.30000001, 0.15000001);
v12 = (void (__fastcall *)(_QWORD, float, float))_glewUniform2f;
v13 = func2((unsigned int)v5, "BrickPct");
v12(v13, 0.89999998, 0.85000002);
v14 = (void (__fastcall *)(_QWORD, float, float, float))_glewUniform3f;
v15 = func2((unsigned int)v5, "LightPosition");
v14(v15, 0.0, 0.0, 4.0);
result = 1LL;
}
}
}
return result;
}

original_code:
int installBrickShaders(const GLchar *brickVertex,
                        const GLchar *brickFragment)
{
    GLuint brickVS, brickFS, brickProg;
    GLint vertCompiled, fragCompiled;
    GLint linked;
    brickVS = __glewCreateShader(0x8B31);
    brickFS = __glewCreateShader(0x8B30);
    __glewShaderSource(brickVS, 1, &brickVertex, ((void *)0));
    __glewShaderSource(brickFS, 1, &brickFragment, ((void *)0));
    __glewCompileShader(brickVS);
    printOglError("shader.c", 292);
    __glewGetShaderiv(brickVS, 0x8B81, &vertCompiled);
    printShaderInfoLog(brickVS);
    __glewCompileShader(brickFS);
    printOglError("shader.c", 300);
    __glewGetShaderiv(brickFS, 0x8B81, &fragCompiled);
    printShaderInfoLog(brickFS);
    if (!vertCompiled || !fragCompiled)
        return 0;
    brickProg = __glewCreateProgram();
    __glewAttachShader(brickProg, brickVS);
    __glewAttachShader(brickProg, brickFS);
    __glewLinkProgram(brickProg);
    printOglError("shader.c", 316);
    __glewGetProgramiv(brickProg, 0x8B82, &linked);
    printProgramInfoLog(brickProg);
    if (!linked)
        return 0;
    __glewUseProgram(brickProg);
    __glewUniform3f(getUniLoc(brickProg, "BrickColor"), 1.0, 0.3, 0.2);
    __glewUniform3f(getUniLoc(brickProg, "MortarColor"), 0.85, 0.86, 0.84);
    __glewUniform2f(getUniLoc(brickProg, "BrickSize"), 0.30, 0.15);
    __glewUniform2f(getUniLoc(brickProg, "BrickPct"), 0.90, 0.85);
    __glewUniform3f(getUniLoc(brickProg, "LightPosition"), 0.0, 0.0, 4.0);
    return 1;
}

canonical_original_code:
int installBrickShaders(char *brickVertex, char *brickFragment)
{
    unsigned int brickVS; unsigned int brickFS; unsigned int brickProg;
    int vertCompiled; int fragCompiled;
    int linked;
    brickVS = __glewCreateShader(0x8B31);
    brickFS = __glewCreateShader(0x8B30);
    __glewShaderSource(brickVS, 1, &brickVertex, ((void *)0));
    __glewShaderSource(brickFS, 1, &brickFragment, ((void *)0));
    __glewCompileShader(brickVS);
    printOglError("shader.c", 292);
    __glewGetShaderiv(brickVS, 0x8B81, &vertCompiled);
    printShaderInfoLog(brickVS);
    __glewCompileShader(brickFS);
    printOglError("shader.c", 300);
    __glewGetShaderiv(brickFS, 0x8B81, &fragCompiled);
    printShaderInfoLog(brickFS);
    if (!vertCompiled || !fragCompiled)
        return 0;
    brickProg = __glewCreateProgram();
    __glewAttachShader(brickProg, brickVS);
    __glewAttachShader(brickProg, brickFS);
    __glewLinkProgram(brickProg);
    printOglError("shader.c", 316);
    __glewGetProgramiv(brickProg, 0x8B82, &linked);
    printProgramInfoLog(brickProg);
    if (!linked)
        return 0;
    __glewUseProgram(brickProg);
    __glewUniform3f(getUniLoc(brickProg, "BrickColor"), 1.0, 0.3, 0.2);
    __glewUniform3f(getUniLoc(brickProg, "MortarColor"), 0.85, 0.86, 0.84);
    __glewUniform2f(getUniLoc(brickProg, "BrickSize"), 0.30, 0.15);
    __glewUniform2f(getUniLoc(brickProg, "BrickPct"), 0.90, 0.85);
    __glewUniform3f(getUniLoc(brickProg, "LightPosition"), 0.0, 0.0, 4.0);
    return 1;
}

variable_types:
brickVertex
char *

variable_types:
brickFragment
char *

variable_types:
brickVS
unsigned int

variable_types:
brickFS
unsigned int

variable_types:
brickProg
unsigned int

variable_types: vertCompiled int

variable_types: fragCompiled int

variable_types: linked int


drawCube

original_code:
void drawCube(void)
{
    float size = 1.0f;
    float scale = 0.2f;
    float delta = 0.1f;
    float A[3] = { size, size, size * scale + delta };
    float B[3] = { size, size, -size * scale + delta };
    float C[3] = { size, -size, -size * scale };
    float D[3] = { size, -size, size * scale };
    float E[3] = {-size, size, size * scale + delta };
    float F[3] = {-size, size, -size * scale + delta };
    float G[3] = {-size, -size, -size * scale };
    float H[3] = {-size, -size, size * scale };
    float I[3] = { 1.0f, 0.0f, 0.0f};
    float K[3] = {-1.0f, 0.0f, 0.0f};
    float L[3] = { 0.0f, 0.0f, -1.0f};
    float M[3] = { 0.0f, 0.0f, 1.0f};
    float N[3] = { 0.0f, 1.0f, 0.0f};
    float O[3] = { 0.0f, -1.0f, 0.0f};
    glBegin(0x0007);
    glNormal3fv(I);
    glTexCoord2f(1,1);
    glVertex3fv(D);
    glTexCoord2f(0,1);
    glVertex3fv(C);
    glTexCoord2f(0,0);
    glVertex3fv(B);
    glTexCoord2f(1,0);
    glVertex3fv(A);
    glNormal3fv(K);
    glTexCoord2f(1,1);
    glVertex3fv(G);
    glTexCoord2f(0,1);
    glVertex3fv(H);
    glTexCoord2f(0,0);
    glVertex3fv(E);
    glTexCoord2f(1,0);
    glVertex3fv(F);
    glNormal3fv(L);
    glTexCoord2f(1,1);
    glVertex3fv(C);
    glTexCoord2f(0,1);
    glVertex3fv(G);
    glTexCoord2f(0,0);
    glVertex3fv(F);
    glTexCoord2f(1,0);
    glVertex3fv(B);
    glNormal3fv(M);
    glTexCoord2f(1,1);
    glVertex3fv(H);
    glTexCoord2f(0,1);
    glVertex3fv(D);
    glTexCoord2f(0,0);
    glVertex3fv(A);
    glTexCoord2f(1,0);
    glVertex3fv(E);
    glNormal3fv(N);
    glTexCoord2f(1,1);
    glVertex3fv(E);
    glTexCoord2f(0,1);
    glVertex3fv(A);
    glTexCoord2f(0,0);
    glVertex3fv(B);
    glTexCoord2f(1,0);
    glVertex3fv(F);
    glNormal3fv(O);
    glTexCoord2f(1,1);
    glVertex3fv(G);
    glTexCoord2f(0,1);
    glVertex3fv(C);
    glTexCoord2f(0,0);
    glVertex3fv(D);
    glTexCoord2f(1,0);
    glVertex3fv(H);
    glEnd();
}

canonical_original_code:
void drawCube()
{
    float size = 1.0f;
    float scale = 0.2f;
    float delta = 0.1f;
    float A[3] = { size, size, size * scale + delta };
    float B[3] = { size, size, -size * scale + delta };
    float C[3] = { size, -size, -size * scale };
    float D[3] = { size, -size, size * scale };
    float E[3] = {-size, size, size * scale + delta };
    float F[3] = {-size, size, -size * scale + delta };
    float G[3] = {-size, -size, -size * scale };
    float H[3] = {-size, -size, size * scale };
    float I[3] = { 1.0f, 0.0f, 0.0f};
    float K[3] = {-1.0f, 0.0f, 0.0f};
    float L[3] = { 0.0f, 0.0f, -1.0f};
    float M[3] = { 0.0f, 0.0f, 1.0f};
    float N[3] = { 0.0f, 1.0f, 0.0f};
    float O[3] = { 0.0f, -1.0f, 0.0f};
    glBegin(0x0007);
    glNormal3fv(I);
    glTexCoord2f(1,1);
    glVertex3fv(D);
    glTexCoord2f(0,1);
    glVertex3fv(C);
    glTexCoord2f(0,0);
    glVertex3fv(B);
    glTexCoord2f(1,0);
    glVertex3fv(A);
    glNormal3fv(K);
    glTexCoord2f(1,1);
    glVertex3fv(G);
    glTexCoord2f(0,1);
    glVertex3fv(H);
    glTexCoord2f(0,0);
    glVertex3fv(E);
    glTexCoord2f(1,0);
    glVertex3fv(F);
    glNormal3fv(L);
    glTexCoord2f(1,1);
    glVertex3fv(C);
    glTexCoord2f(0,1);
    glVertex3fv(G);
    glTexCoord2f(0,0);
    glVertex3fv(F);
    glTexCoord2f(1,0);
    glVertex3fv(B);
    glNormal3fv(M);
    glTexCoord2f(1,1);
    glVertex3fv(H);
    glTexCoord2f(0,1);
    glVertex3fv(D);
    glTexCoord2f(0,0);
    glVertex3fv(A);
    glTexCoord2f(1,0);
    glVertex3fv(E);
    glNormal3fv(N);
    glTexCoord2f(1,1);
    glVertex3fv(E);
    glTexCoord2f(0,1);
    glVertex3fv(A);
    glTexCoord2f(0,0);
    glVertex3fv(B);
    glTexCoord2f(1,0);
    glVertex3fv(F);
    glNormal3fv(O);
    glTexCoord2f(1,1);
    glVertex3fv(G);
    glTexCoord2f(0,1);
    glVertex3fv(C);
    glTexCoord2f(0,0);
    glVertex3fv(D);
    glTexCoord2f(1,0);
    glVertex3fv(H);
    glEnd();
}

variable_types: size float

variable_types: scale float

variable_types: delta float

variable_types:
A
float [3]

variable_types:
B
float [3]

variable_types:
C
float [3]

variable_types:
D
float [3]

variable_types:
E
float [3]

variable_types:
F
float [3]

variable_types:
G
float [3]

variable_types:
H
float [3]

variable_types:
I
float [3]

variable_types:
K
float [3]

variable_types:
L
float [3]

variable_types:
M
float [3]

variable_types:
N
float [3]

variable_types:
O
float [3]


displaySetLevel

decompiled_code:
void __fastcall displaySetLevel(int a1)
{
displayLevel = a1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
displayLevel = a1;
}

original_code:
void displaySetLevel(int level)
{
    displayLevel = level;
}

variable_types: level int


displayBytes

decompiled_code:
int __fastcall displayBytes(int a1, const char *a2, unsigned __int8 *a3, int a4)
{
int result; // eax
unsigned __int8 *v7; // rbx
__int64 v8; // rbp

result = (int)intermediateValueFile;
if ( intermediateValueFile && displayLevel >= a1 )
{
fprintf(intermediateValueFile, "%s:\n", a2);
if ( a4 )
{
v7 = a3;
v8 = (__int64)&a3[a4 - 1 + 1];
do
fprintf(intermediateValueFile, "%02X ", *v7++);
while ( v7 != (unsigned __int8 *)v8 );
}
fputc(10, intermediateValueFile);
result = fputc(10, intermediateValueFile);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, const char *a2, unsigned __int8 *a3, int a4)
{
int result; // eax
unsigned __int8 *v7; // rbx
__int64 v8; // rbp

result = (int)intermediateValueFile;
if ( intermediateValueFile && displayLevel >= a1 )
{
fprintf(intermediateValueFile, "%s:\n", a2);
if ( a4 )
{
v7 = a3;
v8 = (__int64)&a3[a4 - 1 + 1];
do
fprintf(intermediateValueFile, "%02X ", *v7++);
while ( v7 != (unsigned __int8 *)v8 );
}
fputc(10, intermediateValueFile);
result = fputc(10, intermediateValueFile);
}
return result;
}

original_code:
void displayBytes(int level, const char *text, const unsigned char *bytes, unsigned int size)
{
    unsigned int i;
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, "%s:\n", text);
        for(i=0; i<size; i++)
            fprintf(intermediateValueFile, "%02X ", bytes[i]);
        fprintf(intermediateValueFile, "\n");
        fprintf(intermediateValueFile, "\n");
    }
}

canonical_original_code:
void displayBytes(int level, char *text, unsigned char *bytes, unsigned int size)
{
    unsigned int i;
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, "%s:\n", text);
        for(i=0; i<size; i++)
            fprintf(intermediateValueFile, "%02X ", bytes[i]);
        fprintf(intermediateValueFile, "\n");
        fprintf(intermediateValueFile, "\n");
    }
}

variable_types:
text
char *

variable_types:
bytes
unsigned char *

variable_types:
size
unsigned int

variable_types:
i
unsigned int


displayBits

decompiled_code:
int __fastcall displayBits(int a1, const char *a2, __int64 a3, int a4, int a5)
{
int result; // eax
unsigned int v9; // ebx
unsigned int v10; // eax
char v11; // cl

result = (int)intermediateValueFile;
if ( intermediateValueFile && displayLevel >= a1 )
{
fprintf(intermediateValueFile, "%s:\n", a2);
if ( a4 )
{
v9 = 0;
do
{
v10 = v9 >> 3;
v11 = v9 & 7;
if ( a5 )
fprintf(intermediateValueFile, "%d ", ((unsigned int)(*(unsigned __int8 *)(a3 + v10) << v11) >> 7) & 1);
else
fprintf(intermediateValueFile, "%d ", ((int)*(unsigned __int8 *)(a3 + v10) >> v11) & 1);
++v9;
}
while ( a4 != v9 );
}
fputc(10, intermediateValueFile);
result = fputc(10, intermediateValueFile);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1, const char *a2, __int64 a3, int a4, int a5)
{
int result; // eax
unsigned int v9; // ebx
unsigned int v10; // eax
char v11; // cl

result = (int)intermediateValueFile;
if ( intermediateValueFile && displayLevel >= a1 )
{
fprintf(intermediateValueFile, "%s:\n", a2);
if ( a4 )
{
v9 = 0;
do
{
v10 = v9 >> 3;
v11 = v9 & 7;
if ( a5 )
fprintf(intermediateValueFile, "%d ", ((unsigned int)(*(unsigned __int8 *)(a3 + v10) << v11) >> 7) & 1);
else
fprintf(intermediateValueFile, "%d ", ((int)*(unsigned __int8 *)(a3 + v10) >> v11) & 1);
++v9;
}
while ( a4 != v9 );
}
fputc(10, intermediateValueFile);
result = fputc(10, intermediateValueFile);
}
return result;
}

original_code:
void displayBits(int level, const char *text, const unsigned char *data, unsigned int size, int MSBfirst)
{
    unsigned int i, iByte, iBit;
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, "%s:\n", text);
        for(i=0; i<size; i++) {
            iByte = i/8;
            iBit = i%8;
            if (MSBfirst)
                fprintf(intermediateValueFile, "%d ", ((data[iByte] << iBit) & 0x80) != 0);
            else
                fprintf(intermediateValueFile, "%d ", ((data[iByte] >> iBit) & 0x01) != 0);
        }
        fprintf(intermediateValueFile, "\n");
        fprintf(intermediateValueFile, "\n");
    }
}

canonical_original_code:
void displayBits(int level, char *text, unsigned char *data, unsigned int size, int MSBfirst)
{
    unsigned int i; unsigned int iByte; unsigned int iBit;
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, "%s:\n", text);
        for(i=0; i<size; i++) {
            iByte = i/8;
            iBit = i%8;
            if (MSBfirst)
                fprintf(intermediateValueFile, "%d ", ((data[iByte] << iBit) & 0x80) != 0);
            else
                fprintf(intermediateValueFile, "%d ", ((data[iByte] >> iBit) & 0x01) != 0);
        }
        fprintf(intermediateValueFile, "\n");
        fprintf(intermediateValueFile, "\n");
    }
}

variable_types:
data
unsigned char *

variable_types: MSBfirst int

variable_types:
iByte
unsigned int

variable_types:
iBit
unsigned int


displayStateAsBytes

decompiled_code:
int __fastcall displayStateAsBytes(int a1, const char *a2, unsigned __int8 *a3)
{
return displayBytes(a1, a2, a3, 200);
}

canonical_decompiled_code:
int __fastcall func4(int a1, const char *a2, unsigned __int8 *a3)
{
return func2(a1, a2, a3, 200);
}

original_code:
void displayStateAsBytes(int level, const char *text, const unsigned char *state)
{
    displayBytes(level, text, state, 1600/8);
}

canonical_original_code:
void displayStateAsBytes(int level, char *text, unsigned char *state)
{
    displayBytes(level, text, state, 1600/8);
}

variable_types:
state
unsigned char *


decompiled_code:
int __fastcall displayStateAs32bitWords(int a1, const char *a2, __int64 a3)
{
int result; // eax
__int64 i; // rbx

result = (int)intermediateValueFile;
if ( intermediateValueFile && displayLevel >= a1 )
{
fprintf(intermediateValueFile, "%s:\n", a2);
for ( i = 0LL; i != 25; ++i )
{
fprintf(intermediateValueFile, "%08X:%08X", *(unsigned int *)(a3 + 8 * i), *(unsigned int *)(a3 + 8 * i + 4));
if ( (unsigned int)i % 5 == 4 )
result = fputc(10, intermediateValueFile);
else
result = fputc(32, intermediateValueFile);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1, const char *a2, __int64 a3)
{
int result; // eax
__int64 i; // rbx

result = (int)intermediateValueFile;
if ( intermediateValueFile && displayLevel >= a1 )
{
fprintf(intermediateValueFile, "%s:\n", a2);
for ( i = 0LL; i != 25; ++i )
{
fprintf(intermediateValueFile, "%08X:%08X", *(unsigned int *)(a3 + 8 * i), *(unsigned int *)(a3 + 8 * i + 4));
if ( (unsigned int)i % 5 == 4 )
result = fputc(10, intermediateValueFile);
else
result = fputc(32, intermediateValueFile);
}
}
return result;
}

original_code:
void displayStateAs32bitWords(int level, const char *text, const unsigned int *state)
{
    unsigned int i;
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, "%s:\n", text);
        for(i=0; i<1600/64; i++) {
            fprintf(intermediateValueFile, "%08X:%08X", (unsigned int)state[2*i+0], (unsigned int)state[2*i+1]);
            if ((i%5) == 4)
                fprintf(intermediateValueFile, "\n");
            else
                fprintf(intermediateValueFile, " ");
        }
    }
}

canonical_original_code:
void displayStateAs32bitWords(int level, char *text, unsigned int *state)
{
    unsigned int i;
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, "%s:\n", text);
        for(i=0; i<1600/64; i++) {
            fprintf(intermediateValueFile, "%08X:%08X", (unsigned int)state[2*i+0], (unsigned int)state[2*i+1]);
            if ((i%5) == 4)
                fprintf(intermediateValueFile, "\n");
            else
                fprintf(intermediateValueFile, " ");
        }
    }
}

variable_types:
state
unsigned int *


decompiled_code:
int __fastcall displayStateAs64bitWords(int a1, const char *a2, __int64 a3)
{
int result; // eax
__int64 i; // rbx

result = (int)intermediateValueFile;
if ( intermediateValueFile && displayLevel >= a1 )
{
fprintf(intermediateValueFile, "%s:\n", a2);
for ( i = 0LL; i != 25; ++i )
{
fprintf(intermediateValueFile, "%08X", *(unsigned int *)(a3 + 8 * i + 4));
fprintf(intermediateValueFile, "%08X", *(unsigned int *)(a3 + 8 * i));
if ( (unsigned int)i % 5 == 4 )
result = fputc(10, intermediateValueFile);
else
result = fputc(32, intermediateValueFile);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int a1, const char *a2, __int64 a3)
{
int result; // eax
__int64 i; // rbx

result = (int)intermediateValueFile;
if ( intermediateValueFile && displayLevel >= a1 )
{
fprintf(intermediateValueFile, "%s:\n", a2);
for ( i = 0LL; i != 25; ++i )
{
fprintf(intermediateValueFile, "%08X", *(unsigned int *)(a3 + 8 * i + 4));
fprintf(intermediateValueFile, "%08X", *(unsigned int *)(a3 + 8 * i));
if ( (unsigned int)i % 5 == 4 )
result = fputc(10, intermediateValueFile);
else
result = fputc(32, intermediateValueFile);
}
}
return result;
}

original_code:
void displayStateAs64bitWords(int level, const char *text, const unsigned long long int *state)
{
    unsigned int i;
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, "%s:\n", text);
        for(i=0; i<1600/64; i++) {
            fprintf(intermediateValueFile, "%08X", (unsigned int)(state[i] >> 32));
            fprintf(intermediateValueFile, "%08X", (unsigned int)(state[i] & 0xFFFFFFFFULL));
            if ((i%5) == 4)
                fprintf(intermediateValueFile, "\n");
            else
                fprintf(intermediateValueFile, " ");
        }
    }
}

canonical_original_code:
void displayStateAs64bitWords(int level, char *text, unsigned long long *state)
{
    unsigned int i;
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, "%s:\n", text);
        for(i=0; i<1600/64; i++) {
            fprintf(intermediateValueFile, "%08X", (unsigned int)(state[i] >> 32));
            fprintf(intermediateValueFile, "%08X", (unsigned int)(state[i] & 0xFFFFFFFFULL));
            if ((i%5) == 4)
                fprintf(intermediateValueFile, "\n");
            else
                fprintf(intermediateValueFile, " ");
        }
    }
}

variable_types:
state
unsigned long long *


displayRoundNumber

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

if ( intermediateValueFile )
{
if ( displayLevel >= a1 )
{
fputc(10, intermediateValueFile);
fprintf(intermediateValueFile, "--- Round %d ---\n", a2);
result = fputc(10, intermediateValueFile);
}
}
return result;
}

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

if ( intermediateValueFile )
{
if ( displayLevel >= a1 )
{
fputc(10, intermediateValueFile);
fprintf(intermediateValueFile, "--- Round %d ---\n", a2);
result = fputc(10, intermediateValueFile);
}
}
return result;
}

original_code:
void displayRoundNumber(int level, unsigned int i)
{
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, "\n");
        fprintf(intermediateValueFile, "--- Round %d ---\n", i);
        fprintf(intermediateValueFile, "\n");
    }
}


displayText

decompiled_code:
int __fastcall displayText(int a1, const char *a2)
{
int result; // eax

result = (int)intermediateValueFile;
if ( intermediateValueFile )
{
if ( displayLevel >= a1 )
{
fprintf(intermediateValueFile, a2);
fputc(10, intermediateValueFile);
result = fputc(10, intermediateValueFile);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, const char *a2)
{
int result; // eax

result = (int)intermediateValueFile;
if ( intermediateValueFile )
{
if ( displayLevel >= a1 )
{
fprintf(intermediateValueFile, a2);
fputc(10, intermediateValueFile);
result = fputc(10, intermediateValueFile);
}
}
return result;
}

original_code:
void displayText(int level, const char *text)
{
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, text);
        fprintf(intermediateValueFile, "\n");
        fprintf(intermediateValueFile, "\n");
    }
}

canonical_original_code:
void displayText(int level, char *text)
{
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, text);
        fprintf(intermediateValueFile, "\n");
        fprintf(intermediateValueFile, "\n");
    }
}


main

repo: jimmycao/slurm-client

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx

operation("get total nodes and slots", argv, envp);
operation("get available nodes and slots", argv, v3);
operation("deallocate slurm_jobid=418 job_return_code=0:slurm_jobid=417 job_return_code=-1", argv, v4);
return 0;
}

original_code:
int main(void)
{
  char *query_total = "get total nodes and slots";
  operation(query_total);
  char *query_available = "get available nodes and slots";
  operation(query_available);
  char *deallocate = "deallocate slurm_jobid=418 job_return_code=0:slurm_jobid=417 job_return_code=-1";
        operation(deallocate);
        return 0;
}

canonical_original_code:
int main()
{
  char *query_total = "get total nodes and slots";
  operation(query_total);
  char *query_available = "get available nodes and slots";
  operation(query_available);
  char *deallocate = "deallocate slurm_jobid=418 job_return_code=0:slurm_jobid=417 job_return_code=-1";
        operation(deallocate);
        return 0;
}

variable_types:
deallocate
char *


operation

decompiled_code:
__int64 __fastcall operation(void *buf)
{
int v1; // eax
int v2; // ebx
size_t v3; // rax
__int64 result; // rax
char v5[8192]; // [rsp+0h] [rbp-2048h] BYREF
struct sockaddr addr; // [rsp+2000h] [rbp-48h] BYREF
__int16 v7; // [rsp+201Ch] [rbp-2Ch] BYREF
char cp[40]; // [rsp+2020h] [rbp-28h] BYREF

get_IP_PORT(cp, &v7);
v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("ERROR: socket");
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
*(_WORD *)addr.sa_data = _bswap_16(v7);
if ( connect(v2, &addr, 0x10u) < 0 )
{
perror("ERROR: connect");
result = 0xFFFFFFFFLL;
}
else
{
v3 = strlen((const char *)buf);
if ( send(v2, buf, v3 + 1, 0) < 0 )
{
perror("ERROR: send");
result = 0xFFFFFFFFLL;
}
else if ( recv(v2, v5, 0x2000uLL, 0) < 0 )
{
perror("ERROR: recv");
result = 0xFFFFFFFFLL;
}
else
{
close(v2);
printf("recv_buf = %s\n", v5);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *buf)
{
int v1; // eax
int v2; // ebx
size_t v3; // rax
__int64 result; // rax
char v5[8192]; // [rsp+0h] [rbp-2048h] BYREF
struct sockaddr addr; // [rsp+2000h] [rbp-48h] BYREF
__int16 v7; // [rsp+201Ch] [rbp-2Ch] BYREF
char cp[40]; // [rsp+2020h] [rbp-28h] BYREF

get_IP_PORT(cp, &v7);
v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("ERROR: socket");
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
*(_WORD *)addr.sa_data = func0(v7);
if ( connect(v2, &addr, 0x10u) < 0 )
{
perror("ERROR: connect");
result = 0xFFFFFFFFLL;
}
else
{
v3 = strlen((const char *)buf);
if ( send(v2, buf, v3 + 1, 0) < 0 )
{
perror("ERROR: send");
result = 0xFFFFFFFFLL;
}
else if ( recv(v2, v5, 0x2000uLL, 0) < 0 )
{
perror("ERROR: recv");
result = 0xFFFFFFFFLL;
}
else
{
close(v2);
printf("recv_buf = %s\n", v5);
result = 0LL;
}
}
}
return result;
}

original_code:
int operation(char *cmd_str)
{
 char IP[16];
 uint32_t PORT;
 struct sockaddr_in address;
 int socket_fd;
 char recv_buf[8192];
 get_IP_PORT(IP, &PORT);
 if(socket_fd = socket(2, SOCK_STREAM, 0), socket_fd < 0){
  perror("ERROR: socket");
  return -1;
 }
 bzero(&address, sizeof(address));
 address.sin_family = 2;
 address.sin_addr.s_addr = inet_addr(IP);
 address.sin_port = htons(PORT);
 if(connect(socket_fd, (struct sockaddr*)&address, sizeof(address)) < 0){
  perror("ERROR: connect");
  return -1;
 }
 if(send(socket_fd, cmd_str, strlen(cmd_str) + 1, 0) < 0){
  perror("ERROR: send");
  return -1;
 }
 if(recv(socket_fd, recv_buf, 8192, 0) < 0){
  perror("ERROR: recv");
  return -1;
 }
 close(socket_fd);
 printf("recv_buf = %s\n", recv_buf);
 return 0;
}

canonical_original_code:
int operation(char *cmd_str)
{
 char IP[16];
 unsigned int PORT;
 struct sockaddr_in address;
 int socket_fd;
 char recv_buf[8192];
 get_IP_PORT(IP, &PORT);
 if(socket_fd = socket(2, SOCK_STREAM, 0), socket_fd < 0){
  perror("ERROR: socket");
  return -1;
 }
 bzero(&address, sizeof(address));
 address.sin_family = 2;
 address.sin_addr.s_addr = inet_addr(IP);
 address.sin_port = htons(PORT);
 if(connect(socket_fd, (struct sockaddr *)&address, sizeof(address)) < 0){
  perror("ERROR: connect");
  return -1;
 }
 if(send(socket_fd, cmd_str, strlen(cmd_str) + 1, 0) < 0){
  perror("ERROR: send");
  return -1;
 }
 if(recv(socket_fd, recv_buf, 8192, 0) < 0){
  perror("ERROR: recv");
  return -1;
 }
 close(socket_fd);
 printf("recv_buf = %s\n", recv_buf);
 return 0;
}

variable_types:
IP
char [16]

variable_types:
PORT
unsigned int

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

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

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


repo: jimstudt/ook-decoder

original_code:
int ook_add_pulse( struct ook_burst *burst, uint32_t hiNs, uint32_t lowNs, int32_t freqOffsetHz)
{
    if ( burst->pulses < burst->allocatedPulses) {
 burst->pulse[burst->pulses].hiNanoseconds = hiNs;
 burst->pulse[burst->pulses].lowNanoseconds = lowNs;
 burst->pulse[burst->pulses].frequencyOffsetHz = freqOffsetHz;
 burst->pulses++;
 return 0;
    }
    return -1;
}

canonical_original_code:
int ook_add_pulse(struct ook_burst *burst, unsigned int hiNs, unsigned int lowNs, int freqOffsetHz)
{
    if ( burst->pulses < burst->allocatedPulses) {
 burst->pulse[burst->pulses].hiNanoseconds = hiNs;
 burst->pulse[burst->pulses].lowNanoseconds = lowNs;
 burst->pulse[burst->pulses].frequencyOffsetHz = freqOffsetHz;
 burst->pulses++;
 return 0;
    }
    return -1;
}

variable_types: struct ook_burst { unsigned long positionNanoseconds; unsigned int pulses; unsigned int allocatedPulses; struct ook_pulse { unsigned int hiNanoseconds; unsigned int lowNanoseconds; int frequencyOffsetHz; } pulse[]; } *

variable_types:
hiNs
unsigned int

variable_types:
lowNs
unsigned int

variable_types: freqOffsetHz int

user_defined_types: struct ook_burst { unsigned long positionNanoseconds; unsigned int pulses; unsigned int allocatedPulses; struct ook_pulse pulse[]; }


original_code:
int ook_encode( struct ook_burst *burst, void **dataReturn, size_t *sizeReturn)
{
    size_t maxSize = sizeof(*burst) + sizeof(burst->pulse[0])*burst->pulses + 64 ;
    void *data = malloc( maxSize);
    if ( data == 0) return -1;
    void *thumb = data;
    size_t left = maxSize;
    uint32_t vers = 0x36360001;
    { if ( left < 4) goto Overflow; memcpy( thumb, &(vers), 4); thumb+=4; left-=4; };
    { if ( left < 8) goto Overflow; memcpy( thumb, &(burst->positionNanoseconds), 8); thumb+=8; left-=8; };
    { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulses), 4); thumb+=4; left-=4; };
    for ( int i = 0; i < burst->pulses; i++) {
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].hiNanoseconds), 4); thumb+=4; left-=4; };
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].lowNanoseconds), 4); thumb+=4; left-=4; };
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].frequencyOffsetHz), 4); thumb+=4; left-=4; };
    }
    *dataReturn = data;
    *sizeReturn = thumb-data;
    return 0;
  Overflow:
    return -1;
}

canonical_original_code:
int ook_encode(struct ook_burst *burst, void **dataReturn, unsigned long *sizeReturn)
{
    unsigned long maxSize = sizeof(*burst) + sizeof(burst->pulse[0])*burst->pulses + 64;
    void *data = malloc( maxSize);
    if ( data == 0) return -1;
    void *thumb = data;
    unsigned long left = maxSize;
    unsigned int vers = 0x36360001;
    { if ( left < 4) goto Overflow; memcpy( thumb, &(vers), 4); thumb+=4; left-=4; };
    { if ( left < 8) goto Overflow; memcpy( thumb, &(burst->positionNanoseconds), 8); thumb+=8; left-=8; };
    { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulses), 4); thumb+=4; left-=4; };
    for ( int i = 0; i < burst->pulses; i++) {
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].hiNanoseconds), 4); thumb+=4; left-=4; };
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].lowNanoseconds), 4); thumb+=4; left-=4; };
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].frequencyOffsetHz), 4); thumb+=4; left-=4; };
    }
    *dataReturn = data;
    *sizeReturn = thumb-data;
    return 0;
  Overflow:
    return -1;
}

variable_types:
dataReturn
void **

variable_types:
sizeReturn
unsigned long *

variable_types:
maxSize
unsigned long

variable_types:
data
void *

variable_types:
thumb
void *

variable_types:
left
unsigned long

variable_types:
vers
unsigned int

variable_types: i int

user_defined_types: struct ook_pulse { unsigned int hiNanoseconds; unsigned int lowNanoseconds; int frequencyOffsetHz; }


original_code:
int ook_decode_from_socket( int sock, struct ook_burst **burstReturn, struct sockaddr *from, socklen_t *fromLen, int verbose)
{
    struct ook_burst *burst = 0;
    unsigned char buf[65536];
    int e=0;
    do {
 e = recvfrom( sock, buf, sizeof(buf), 0, from, fromLen);
 if ( e == -1 && ((*__errno_location ()) == 11 || (*__errno_location ()) == 4)) continue;
 if ( e == -1) return -1;
    } while(0);
    if ( verbose) fprintf(stderr,"Received %u bytes\n", e);
    uint32_t left = e;
    unsigned char *thumb = buf;
    uint32_t vers = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
    if ( vers != 0x36360001) goto Fail;
    uint64_t pos = ({ uint64_t v; if ( left<8) goto Fail; memcpy(&v,thumb,8); thumb+=8; left -= 8; v; });
    uint32_t pulses = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
    burst = ook_allocate_burst( pulses);
    if ( !burst) goto Fail;
    burst->positionNanoseconds = pos;
    for ( int i = 0; i < pulses; i++) {
 uint32_t hi = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 uint32_t low = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 int32_t freq = ({ int32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 if ( ook_add_pulse( burst, hi, low, freq) < 0) goto Fail;
    }
    if ( left > 0) goto Fail;
    *burstReturn = burst;
    return 1;
  Fail:
    *burstReturn = 0;
    if (burst) free(burst);
    return 0;
}

canonical_original_code:
int ook_decode_from_socket(int sock, struct ook_burst **burstReturn, struct sockaddr *from, unsigned int *fromLen, int verbose)
{
    struct ook_burst *burst = 0;
    unsigned char buf[65536];
    int e = 0;
    do {
 e = recvfrom( sock, buf, sizeof(buf), 0, from, fromLen);
 if ( e == -1 && ((*__errno_location ()) == 11 || (*__errno_location ()) == 4)) continue;
 if ( e == -1) return -1;
    } while(0);
    if ( verbose) fprintf(stderr,"Received %u bytes\n", e);
    unsigned int left = e;
    unsigned char *thumb = buf;
    unsigned int vers = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
    if ( vers != 0x36360001) goto Fail;
    unsigned long pos = ({ uint64_t v; if ( left<8) goto Fail; memcpy(&v,thumb,8); thumb+=8; left -= 8; v; });
    unsigned int pulses = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
    burst = ook_allocate_burst( pulses);
    if ( !burst) goto Fail;
    burst->positionNanoseconds = pos;
    for ( int i = 0; i < pulses; i++) {
 unsigned int hi = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 unsigned int low = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 int freq = ({ int32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 if ( ook_add_pulse( burst, hi, low, freq) < 0) goto Fail;
    }
    if ( left > 0) goto Fail;
    *burstReturn = burst;
    return 1;
  Fail:
    *burstReturn = 0;
    if (burst) free(burst);
    return 0;
}

variable_types: sock int

variable_types: struct ook_burst { unsigned long positionNanoseconds; unsigned int pulses; unsigned int allocatedPulses; struct ook_pulse { unsigned int hiNanoseconds; unsigned int lowNanoseconds; int frequencyOffsetHz; } pulse[]; } **

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

variable_types:
fromLen
unsigned int *

variable_types: verbose int

variable_types:
buf
unsigned char [65536]

variable_types: e int

variable_types:
left
unsigned int

variable_types:
thumb
unsigned char *

variable_types:
pos
unsigned long

variable_types:
pulses
unsigned int

variable_types:
hi
unsigned int

variable_types:
low
unsigned int

variable_types: freq int