original_code:
void window_create(Window id)
{
 window_t *window = malloc(sizeof(window_t));
 window->id = id;
 window->mapped = 0;
 window->dirty = 1;
 do { unsigned _ha_bkt; (window)->hh.next = ((void *)0); (window)->hh.key = (char*)(&((window)->id)); (window)->hh.keylen = (unsigned)(sizeof(Window)); if (!(window_map)) { window_map = (window); (window_map)->hh.prev = ((void *)0); do { (window_map)->hh.tbl = (UT_hash_table*)malloc(sizeof(UT_hash_table)); if (!((window_map)->hh.tbl)) { exit(-1); } memset((window_map)->hh.tbl, 0, sizeof(UT_hash_table)); (window_map)->hh.tbl->tail = &((window_map)->hh); (window_map)->hh.tbl->num_buckets = 32; (window_map)->hh.tbl->log2_num_buckets = 5; (window_map)->hh.tbl->hho = (char*)(&(window_map)->hh) - (char*)(window_map); (window_map)->hh.tbl->buckets = (UT_hash_bucket*)malloc(32*sizeof(struct UT_hash_bucket)); if (! (window_map)->hh.tbl->buckets) { exit(-1); } memset((window_map)->hh.tbl->buckets, 0, 32*sizeof(struct UT_hash_bucket)); ; (window_map)->hh.tbl->signature = 0xa0111fe1; } while(0); } else { (window_map)->hh.tbl->tail->next = (window); (window)->hh.prev = ((void*)(((char*)((window_map)->hh.tbl->tail)) - (((window_map)->hh.tbl)->hho))); (window_map)->hh.tbl->tail = &((window)->hh); } (window_map)->hh.tbl->num_items++; (window)->hh.tbl = (window_map)->hh.tbl; do { unsigned _hj_i,_hj_j,_hj_k; unsigned char *_hj_key=(unsigned char*)(&((window)->id)); (window)->hh.hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned)(sizeof(Window)); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) + ( (unsigned)_hj_key[2] << 16 ) + ( (unsigned)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) + ( (unsigned)_hj_key[6] << 16 ) + ( (unsigned)_hj_key[7] << 24 ) ); (window)->hh.hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) + ( (unsigned)_hj_key[10] << 16 ) + ( (unsigned)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 13 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 12 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 3 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } (window)->hh.hashv += sizeof(Window); switch ( _hj_k ) { case 11: (window)->hh.hashv += ( (unsigned)_hj_key[10] << 24 ); case 10: (window)->hh.hashv += ( (unsigned)_hj_key[9] << 16 ); case 9: (window)->hh.hashv += ( (unsigned)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 13 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 12 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 3 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 15 ); } while (0); _ha_bkt = (window)->hh.hashv & ((window_map)->hh.tbl->num_buckets-1); } while(0); do { (window_map)->hh.tbl->buckets[_ha_bkt].count++; (&(window)->hh)->hh_next = (window_map)->hh.tbl->buckets[_ha_bkt].hh_head; (&(window)->hh)->hh_prev = ((void *)0); if ((window_map)->hh.tbl->buckets[_ha_bkt].hh_head) { ((window_map)->hh.tbl->buckets[_ha_bkt]).hh_head->hh_prev = (&(window)->hh); } ((window_map)->hh.tbl->buckets[_ha_bkt]).hh_head=&(window)->hh; if ((window_map)->hh.tbl->buckets[_ha_bkt].count >= (((window_map)->hh.tbl->buckets[_ha_bkt].expand_mult+1) * 10) && (&(window)->hh)->tbl->noexpand != 1) { do { unsigned _he_bkt; unsigned _he_bkt_i; struct UT_hash_handle *_he_thh, *_he_hh_nxt; UT_hash_bucket *_he_new_buckets, *_he_newbkt; _he_new_buckets = (UT_hash_bucket*)malloc(2 * (&(window)->hh)->tbl->num_buckets * sizeof(struct UT_hash_bucket)); if (!_he_new_buckets) { exit(-1); } memset(_he_new_buckets, 0, 2 * (&(window)->hh)->tbl->num_buckets * sizeof(struct UT_hash_bucket)); (&(window)->hh)->tbl->ideal_chain_maxlen = ((&(window)->hh)->tbl->num_items >> ((&(window)->hh)->tbl->log2_num_buckets+1)) + (((&(window)->hh)->tbl->num_items & (((&(window)->hh)->tbl->num_buckets*2)-1)) ? 1 : 0); (&(window)->hh)->tbl->nonideal_items = 0; for(_he_bkt_i = 0; _he_bkt_i < (&(window)->hh)->tbl->num_buckets; _he_bkt_i++) { _he_thh = (&(window)->hh)->tbl->buckets[ _he_bkt_i ].hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; do { _he_bkt = ((_he_thh->hashv) & (((&(window)->hh)->tbl->num_buckets*2) - 1)); } while(0); _he_newbkt = &(_he_new_buckets[ _he_bkt ]); if (++(_he_newbkt->count) > (&(window)->hh)->tbl->ideal_chain_maxlen) { (&(window)->hh)->tbl->nonideal_items++; _he_newbkt->expand_mult = _he_newbkt->count / (&(window)->hh)->tbl->ideal_chain_maxlen; } _he_thh->hh_prev = ((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = _he_thh; _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } } free((&(window)->hh)->tbl->buckets); (&(window)->hh)->tbl->num_buckets *= 2; (&(window)->hh)->tbl->log2_num_buckets++; (&(window)->hh)->tbl->buckets = _he_new_buckets; (&(window)->hh)->tbl->ineff_expands = ((&(window)->hh)->tbl->nonideal_items > ((&(window)->hh)->tbl->num_items >> 1)) ? ((&(window)->hh)->tbl->ineff_expands+1) : 0; if ((&(window)->hh)->tbl->ineff_expands > 1) { (&(window)->hh)->tbl->noexpand=1; ; } ; } while(0); } } while(0); ; ; ; } while(0);
 window->prev = ((void *)0);
 window->next = ((void *)0);
 window->pixmap = 0L;
 window->picture = 0L;
 window_list_prepend(id);
}

canonical_original_code:
void window_create(unsigned long id)
{
 struct window_def *window = malloc(sizeof(window_t));
 window->id = id;
 window->mapped = 0;
 window->dirty = 1;
 do { unsigned int _ha_bkt; (window)->hh.next = ((void *)0); (window)->hh.key = (char *)(&((window)->id)); (window)->hh.keylen = (unsigned int)(sizeof(Window)); if (!(window_map)) { window_map = (window); (window_map)->hh.prev = ((void *)0); do { (window_map)->hh.tbl = (struct UT_hash_table *)malloc(sizeof(UT_hash_table)); if (!((window_map)->hh.tbl)) { exit(-1); } memset((window_map)->hh.tbl, 0, sizeof(UT_hash_table)); (window_map)->hh.tbl->tail = &((window_map)->hh); (window_map)->hh.tbl->num_buckets = 32; (window_map)->hh.tbl->log2_num_buckets = 5; (window_map)->hh.tbl->hho = (char *)(&(window_map)->hh) - (char *)(window_map); (window_map)->hh.tbl->buckets = (struct UT_hash_bucket *)malloc(32*sizeof(struct UT_hash_bucket)); if (! (window_map)->hh.tbl->buckets) { exit(-1); } memset((window_map)->hh.tbl->buckets, 0, 32*sizeof(struct UT_hash_bucket)); ; (window_map)->hh.tbl->signature = 0xa0111fe1; } while(0); } else { (window_map)->hh.tbl->tail->next = (window); (window)->hh.prev = ((void *)(((char *)((window_map)->hh.tbl->tail)) - (((window_map)->hh.tbl)->hho))); (window_map)->hh.tbl->tail = &((window)->hh); } (window_map)->hh.tbl->num_items++; (window)->hh.tbl = (window_map)->hh.tbl; do { unsigned int _hj_i; unsigned int _hj_j; unsigned int _hj_k; unsigned char *_hj_key = (unsigned char*)(&((window)->id)); (window)->hh.hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned int)(sizeof(Window)); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned int)_hj_key[1] << 8 ) + ( (unsigned int)_hj_key[2] << 16 ) + ( (unsigned int)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned int)_hj_key[5] << 8 ) + ( (unsigned int)_hj_key[6] << 16 ) + ( (unsigned int)_hj_key[7] << 24 ) ); (window)->hh.hashv += (_hj_key[8] + ( (unsigned int)_hj_key[9] << 8 ) + ( (unsigned int)_hj_key[10] << 16 ) + ( (unsigned int)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 13 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 12 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 3 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } (window)->hh.hashv += sizeof(Window); switch ( _hj_k ) { case 11: (window)->hh.hashv += ( (unsigned int)_hj_key[10] << 24 ); case 10: (window)->hh.hashv += ( (unsigned int)_hj_key[9] << 16 ); case 9: (window)->hh.hashv += ( (unsigned int)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned int)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned int)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned int)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned int)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned int)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned int)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 13 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 12 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= (window)->hh.hashv; _hj_i ^= ( (window)->hh.hashv >> 3 ); _hj_j -= (window)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); (window)->hh.hashv -= _hj_i; (window)->hh.hashv -= _hj_j; (window)->hh.hashv ^= ( _hj_j >> 15 ); } while (0); _ha_bkt = (window)->hh.hashv & ((window_map)->hh.tbl->num_buckets-1); } while(0); do { (window_map)->hh.tbl->buckets[_ha_bkt].count++; (&(window)->hh)->hh_next = (window_map)->hh.tbl->buckets[_ha_bkt].hh_head; (&(window)->hh)->hh_prev = ((void *)0); if ((window_map)->hh.tbl->buckets[_ha_bkt].hh_head) { ((window_map)->hh.tbl->buckets[_ha_bkt]).hh_head->hh_prev = (&(window)->hh); } ((window_map)->hh.tbl->buckets[_ha_bkt]).hh_head=&(window)->hh; if ((window_map)->hh.tbl->buckets[_ha_bkt].count >= (((window_map)->hh.tbl->buckets[_ha_bkt].expand_mult+1) * 10) && (&(window)->hh)->tbl->noexpand != 1) { do { unsigned int _he_bkt; unsigned int _he_bkt_i; struct UT_hash_handle *_he_thh; struct UT_hash_handle *_he_hh_nxt; struct UT_hash_bucket *_he_new_buckets; struct UT_hash_bucket *_he_newbkt; _he_new_buckets = (struct UT_hash_bucket *)malloc(2 * (&(window)->hh)->tbl->num_buckets * sizeof(struct UT_hash_bucket)); if (!_he_new_buckets) { exit(-1); } memset(_he_new_buckets, 0, 2 * (&(window)->hh)->tbl->num_buckets * sizeof(struct UT_hash_bucket)); (&(window)->hh)->tbl->ideal_chain_maxlen = ((&(window)->hh)->tbl->num_items >> ((&(window)->hh)->tbl->log2_num_buckets+1)) + (((&(window)->hh)->tbl->num_items & (((&(window)->hh)->tbl->num_buckets*2)-1)) ? 1 : 0); (&(window)->hh)->tbl->nonideal_items = 0; for(_he_bkt_i = 0; _he_bkt_i < (&(window)->hh)->tbl->num_buckets; _he_bkt_i++) { _he_thh = (&(window)->hh)->tbl->buckets[ _he_bkt_i ].hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; do { _he_bkt = ((_he_thh->hashv) & (((&(window)->hh)->tbl->num_buckets*2) - 1)); } while(0); _he_newbkt = &(_he_new_buckets[ _he_bkt ]); if (++(_he_newbkt->count) > (&(window)->hh)->tbl->ideal_chain_maxlen) { (&(window)->hh)->tbl->nonideal_items++; _he_newbkt->expand_mult = _he_newbkt->count / (&(window)->hh)->tbl->ideal_chain_maxlen; } _he_thh->hh_prev = ((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = _he_thh; _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } } free((&(window)->hh)->tbl->buckets); (&(window)->hh)->tbl->num_buckets *= 2; (&(window)->hh)->tbl->log2_num_buckets++; (&(window)->hh)->tbl->buckets = _he_new_buckets; (&(window)->hh)->tbl->ineff_expands = ((&(window)->hh)->tbl->nonideal_items > ((&(window)->hh)->tbl->num_items >> 1)) ? ((&(window)->hh)->tbl->ineff_expands+1) : 0; if ((&(window)->hh)->tbl->ineff_expands > 1) { (&(window)->hh)->tbl->noexpand=1; ; } ; } while(0); } } while(0); ; ; ; } while(0);
 window->prev = ((void *)0);
 window->next = ((void *)0);
 window->pixmap = 0L;
 window->picture = 0L;
 window_list_prepend(id);
}

variable_types: struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } *

variable_types: struct UT_hash_bucket { struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } *hh_head; unsigned int count; unsigned int expand_mult; } *


repo: nowylie/space

decompiled_code:
int window_list_populate()
{
int result; // eax
signed int v1; // ebx
__int64 v2; // rbp
unsigned int v3; // [rsp+4h] [rbp-34h] BYREF
Window *v4; // [rsp+8h] [rbp-30h] BYREF
Window v5; // [rsp+10h] [rbp-28h] BYREF
Window v6[4]; // [rsp+18h] [rbp-20h] BYREF

result = XQueryTree(conn, conn->screens[(__int64)conn->default_screen].root, v6, &v5, &v4, &v3);
v1 = v3 - 1;
if ( (int)(v3 - 1) >= 0 )
{
v2 = v1;
do
{
result = window_create(v4[v2--]);
--v1;
}
while ( v1 >= 0 );
}
if ( v4 )
result = XFree(v4);
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
signed int v1; // ebx
__int64 v2; // rbp
unsigned int v3; // [rsp+4h] [rbp-34h] BYREF
Window *v4; // [rsp+8h] [rbp-30h] BYREF
Window v5; // [rsp+10h] [rbp-28h] BYREF
Window v6[4]; // [rsp+18h] [rbp-20h] BYREF

result = XQueryTree(conn, conn->screens[(__int64)conn->default_screen].root, v6, &v5, &v4, &v3);
v1 = v3 - 1;
if ( (int)(v3 - 1) >= 0 )
{
v2 = v1;
do
{
result = func7(v4[v2--]);
--v1;
}
while ( v1 >= 0 );
}
if ( v4 )
result = XFree(v4);
return result;
}

original_code:
void window_list_populate()
{
 Window root, parent, *children;
 unsigned num_children;
 int i;
 XQueryTree(conn, ((&((_XPrivDisplay)(conn))->screens[(((_XPrivDisplay)(conn))->default_screen)])->root), &root, &parent, &children, &num_children);
 for (i = num_children - 1; i >= 0; i--) {
  window_create(children[i]);
 }
 if (children != ((void *)0))
  XFree(children);
}

canonical_original_code:
void window_list_populate()
{
 unsigned long root; unsigned long parent; unsigned long *children;
 unsigned int num_children;
 int i;
 XQueryTree(conn, ((&((_XPrivDisplay)(conn))->screens[(((_XPrivDisplay)(conn))->default_screen)])->root), &root, &parent, &children, &num_children);
 for (i = num_children - 1; i >= 0; i--) {
  window_create(children[i]);
 }
 if (children != ((void *)0))
  XFree(children);
}

variable_types:
root
unsigned long

variable_types:
parent
unsigned long

variable_types:
children
unsigned long *

variable_types: i int

return_type: void


decompiled_code:
__int64 __fastcall window_set_mapped(__int64 a1, char a2)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp
Pixmap v5; // rsi
__int64 v6; // rax
_DWORD v7[26]; // [rsp+0h] [rbp-68h] BYREF

result = window_get(a1);
if ( result )
{
v3 = result;
*(_BYTE *)(result + 40) = a2;
if ( a2 == 1 )
{
v4 = XRenderFindVisualFormat(conn, visual);
v7[11] = 1;
if ( *(_QWORD *)(v3 + 32) )
XRenderFreePicture(conn);
v5 = *(_QWORD *)(v3 + 24);
if ( v5 )
XFreePixmap(conn, v5);
v6 = XCompositeNameWindowPixmap(conn, a1);
*(_QWORD *)(v3 + 24) = v6;
*(_QWORD *)(v3 + 32) = XRenderCreatePicture(conn, v6, v4, 256LL, v7);
XDamageCreate(conn, *(_QWORD *)(v3 + 24), 3LL);
window_list_remove(a1);
result = window_list_append(a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, char a2)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp
Pixmap v5; // rsi
__int64 v6; // rax
_DWORD v7[26]; // [rsp+0h] [rbp-68h] BYREF

result = func0(a1);
if ( result )
{
v3 = result;
*(_BYTE *)(result + 40) = a2;
if ( a2 == 1 )
{
v4 = XRenderFindVisualFormat(conn, visual);
v7[11] = 1;
if ( *(_QWORD *)(v3 + 32) )
XRenderFreePicture(conn);
v5 = *(_QWORD *)(v3 + 24);
if ( v5 )
XFreePixmap(conn, v5);
v6 = XCompositeNameWindowPixmap(conn, a1);
*(_QWORD *)(v3 + 24) = v6;
*(_QWORD *)(v3 + 32) = XRenderCreatePicture(conn, v6, v4, 256LL, v7);
XDamageCreate(conn, *(_QWORD *)(v3 + 24), 3LL);
func1(a1);
result = func3(a1);
}
}
return result;
}

original_code:
void window_set_mapped(Window id, bool mapped)
{
 window_t *window = window_get(id);
 if (window == ((void *)0))
  return;
 window->mapped = mapped;
 if (mapped == 1) {
  XRenderPictFormat *format;
  XRenderPictureAttributes pa;
  format = XRenderFindVisualFormat(conn, visual);
  pa.subwindow_mode = 1;
  if (window->picture != 0L)
   XRenderFreePicture(conn, window->picture);
  if (window->pixmap != 0L)
   XFreePixmap(conn, window->pixmap);
  window->pixmap = XCompositeNameWindowPixmap(conn, id);
  window->picture = XRenderCreatePicture(conn, window->pixmap,
    format, (1 << 8), &pa);
  XDamageCreate(conn, window->pixmap, 3);
  window_list_remove(id);
  window_list_append(id);
 }
}

canonical_original_code:
void window_set_mapped(unsigned long id, char mapped)
{
 struct window_def *window = window_get(id);
 if (window == ((void *)0))
  return;
 window->mapped = mapped;
 if (mapped == 1) {
  struct XRenderPictFormat *format;
  struct _XRenderPictureAttributes pa;
  format = XRenderFindVisualFormat(conn, visual);
  pa.subwindow_mode = 1;
  if (window->picture != 0L)
   XRenderFreePicture(conn, window->picture);
  if (window->pixmap != 0L)
   XFreePixmap(conn, window->pixmap);
  window->pixmap = XCompositeNameWindowPixmap(conn, id);
  window->picture = XRenderCreatePicture(conn, window->pixmap,
    format, (1 << 8), &pa);
  XDamageCreate(conn, window->pixmap, 3);
  window_list_remove(id);
  window_list_append(id);
 }
}

variable_types:
id
unsigned long

variable_types: mapped char

variable_types: struct window_def { unsigned long id; int x; unsigned int width; unsigned long pixmap; unsigned long picture; char mapped; char dirty; struct window_def *prev; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *

variable_types: struct XRenderPictFormat { unsigned long id; int type; int depth; struct XRenderDirectFormat { short red; short redMask; short green; short greenMask; short blue; short blueMask; short alpha; short alphaMask; } direct; unsigned long colormap; } *

variable_types: struct _XRenderPictureAttributes { int repeat; unsigned long alpha_map; int alpha_x_origin; int alpha_y_origin; int clip_x_origin; int clip_y_origin; unsigned long clip_mask; int graphics_exposures; int subwindow_mode; int poly_edge; int poly_mode; unsigned long dither; int component_alpha; }

user_defined_types: struct window_def { unsigned long id; int x; unsigned int width; unsigned long pixmap; unsigned long picture; char mapped; char dirty; struct window_def *prev; struct UT_hash_handle hh; }

user_defined_types: struct XRenderPictFormat { unsigned long id; int type; int depth; struct XRenderDirectFormat direct; unsigned long colormap; }

user_defined_types: struct UT_hash_handle { struct UT_hash_table *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; }

user_defined_types: struct UT_hash_table { struct UT_hash_bucket *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; }


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

result = window_get(a1);
if ( result )
*(_BYTE *)(result + 41) = 1;
return result;
}

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

result = func0(a1);
if ( result )
*(_BYTE *)(result + 41) = 1;
return result;
}

original_code:
void window_damaged(Window id)
{
 window_t *window = window_get(id);
 if (window == ((void *)0))
  return;
 window->dirty = 1;
}

canonical_original_code:
void window_damaged(unsigned long id)
{
 struct window_def *window = window_get(id);
 if (window == ((void *)0))
  return;
 window->dirty = 1;
}

user_defined_types: struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; }


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

result = window_get(a1);
if ( result )
result = XRenderComposite(
conn,
1LL,
*(_QWORD *)(result + 32),
0LL,
a2,
0LL,
0LL,
0LL,
0LL,
*(unsigned int *)(result + 8),
*(unsigned int *)(result + 12),
*(unsigned int *)(result + 16),
*(unsigned int *)(result + 20));
return result;
}

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

result = func0(a1);
if ( result )
result = XRenderComposite(
conn,
1LL,
*(_QWORD *)(result + 32),
0LL,
a2,
0LL,
0LL,
0LL,
0LL,
*(unsigned int *)(result + 8),
*(unsigned int *)(result + 12),
*(unsigned int *)(result + 16),
*(unsigned int *)(result + 20));
return result;
}

original_code:
void window_draw(Window id, Picture surface)
{
 window_t *window = window_get(id);
 if (window == ((void *)0))
  return;
 XRenderComposite(conn, 1, window->picture, 0L, surface, 0, 0,
   0, 0, window->x, window->y, window->width, window->height);
}

canonical_original_code:
void window_draw(unsigned long id, unsigned long surface)
{
 struct window_def *window = window_get(id);
 if (window == ((void *)0))
  return;
 XRenderComposite(conn, 1, window->picture, 0L, surface, 0, 0,
   0, 0, window->x, window->y, window->width, window->height);
}

variable_types:
surface
unsigned long


decompiled_code:
__int64 __fastcall window_list_draw(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = window_list; i; i = *(_QWORD *)(i + 56) )
{
if ( *(_BYTE *)(i + 40) == 1 )
result = window_draw(*(_QWORD *)i, a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = window_list; i; i = *(_QWORD *)(i + 56) )
{
if ( *(_BYTE *)(i + 40) == 1 )
result = func13(*(_QWORD *)i, a1);
}
return result;
}

original_code:
void window_list_draw(Picture surface)
{
 window_t *window = window_list;
 while (window != ((void *)0))
 {
  if (window->mapped == 1) {
   window_draw(window->id, surface);
  }
  window = window->next;
 }
}

canonical_original_code:
void window_list_draw(unsigned long surface)
{
 struct window_def *window = window_list;
 while (window != ((void *)0))
 {
  if (window->mapped == 1) {
   window_draw(window->id, surface);
  }
  window = window->next;
 }
}


original_code:
void window_destroy(Window id)
{
 window_t *window;
 window = window_list_remove(id);
 do { unsigned _hd_bkt; struct UT_hash_handle *_hd_hh_del; if ( ((window)->hh.prev == ((void *)0)) && ((window)->hh.next == ((void *)0)) ) { free((window_map)->hh.tbl->buckets); ; free((window_map)->hh.tbl); window_map = ((void *)0); } else { _hd_hh_del = &((window)->hh); if ((window) == ((void*)(((char*)((window_map)->hh.tbl->tail)) - (((window_map)->hh.tbl)->hho)))) { (window_map)->hh.tbl->tail = (UT_hash_handle*)((ptrdiff_t)((window)->hh.prev) + (window_map)->hh.tbl->hho); } if ((window)->hh.prev) { ((UT_hash_handle*)((ptrdiff_t)((window)->hh.prev) + (window_map)->hh.tbl->hho))->next = (window)->hh.next; } else { do { (window_map) = (__typeof(window_map))((window)->hh.next); } while(0); } if (_hd_hh_del->next) { ((UT_hash_handle*)((ptrdiff_t)_hd_hh_del->next + (window_map)->hh.tbl->hho))->prev = _hd_hh_del->prev; } do { _hd_bkt = ((_hd_hh_del->hashv) & (((window_map)->hh.tbl->num_buckets) - 1)); } while(0); ((window_map)->hh.tbl->buckets[_hd_bkt]).count--; if (((window_map)->hh.tbl->buckets[_hd_bkt]).hh_head == _hd_hh_del) { ((window_map)->hh.tbl->buckets[_hd_bkt]).hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { _hd_hh_del->hh_prev->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { _hd_hh_del->hh_next->hh_prev = _hd_hh_del->hh_prev; }; (window_map)->hh.tbl->num_items--; } ; } while (0);
 free(window);
}

canonical_original_code:
void window_destroy(unsigned long id)
{
 struct window_def *window;
 window = window_list_remove(id);
 do { unsigned int _hd_bkt; struct UT_hash_handle *_hd_hh_del; if ( ((window)->hh.prev == ((void *)0)) && ((window)->hh.next == ((void *)0)) ) { free((window_map)->hh.tbl->buckets); ; free((window_map)->hh.tbl); window_map = ((void *)0); } else { _hd_hh_del = &((window)->hh); if ((window) == ((void *)(((char *)((window_map)->hh.tbl->tail)) - (((window_map)->hh.tbl)->hho)))) { (window_map)->hh.tbl->tail = (struct UT_hash_handle *)((long)((window)->hh.prev) + (window_map)->hh.tbl->hho); } if ((window)->hh.prev) { ((struct UT_hash_handle *)((long)((window)->hh.prev) + (window_map)->hh.tbl->hho))->next = (window)->hh.next; } else { do { (window_map) = (__typeof(window_map))((window)->hh.next); } while(0); } if (_hd_hh_del->next) { ((struct UT_hash_handle *)((long)_hd_hh_del->next + (window_map)->hh.tbl->hho))->prev = _hd_hh_del->prev; } do { _hd_bkt = ((_hd_hh_del->hashv) & (((window_map)->hh.tbl->num_buckets) - 1)); } while(0); ((window_map)->hh.tbl->buckets[_hd_bkt]).count--; if (((window_map)->hh.tbl->buckets[_hd_bkt]).hh_head == _hd_hh_del) { ((window_map)->hh.tbl->buckets[_hd_bkt]).hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { _hd_hh_del->hh_prev->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { _hd_hh_del->hh_next->hh_prev = _hd_hh_del->hh_prev; }; (window_map)->hh.tbl->num_items--; } ; } while (0);
 free(window);
}


decompiled_code:
void process_opts()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void process_opts(int argc, char** argv)
{
}

canonical_original_code:
void process_opts(int argc, char **argv)
{
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall allow_input_passthrough(__int64 a1)
{
__int64 v1; // rbx

v1 = XFixesCreateRegion(conn, 0LL, 0LL);
XFixesSetWindowShapeRegion(conn, a1, 0LL, 0LL, 0LL, 0LL);
XFixesSetWindowShapeRegion(conn, a1, 2LL, 0LL, 0LL, v1);
return XFixesDestroyRegion(conn, v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx

v1 = XFixesCreateRegion(conn, 0LL, 0LL);
XFixesSetWindowShapeRegion(conn, a1, 0LL, 0LL, 0LL, 0LL);
XFixesSetWindowShapeRegion(conn, a1, 2LL, 0LL, 0LL, v1);
return XFixesDestroyRegion(conn, v1);
}

original_code:
void allow_input_passthrough(Window overlay)
{
 XserverRegion region = XFixesCreateRegion(conn, ((void *)0), 0);
 XFixesSetWindowShapeRegion(conn, overlay, 0, 0, 0, 0);
 XFixesSetWindowShapeRegion(conn, overlay, 2, 0, 0, region);
 XFixesDestroyRegion(conn, region);
}

canonical_original_code:
void allow_input_passthrough(unsigned long overlay)
{
 unsigned long region = XFixesCreateRegion(conn, ((void *)0), 0);
 XFixesSetWindowShapeRegion(conn, overlay, 0, 0, 0, 0);
 XFixesSetWindowShapeRegion(conn, overlay, 2, 0, 0, region);
 XFixesDestroyRegion(conn, region);
}

variable_types:
overlay
unsigned long

variable_types:
region
unsigned long


original_code:
frame_t * frame_get( Window id )
{
   frame_t *frame;
   do { unsigned _hf_bkt,_hf_hashv; frame=((void *)0); if (frame_map) { do { unsigned _hj_i,_hj_j,_hj_k; unsigned char *_hj_key=(unsigned char*)(&id); _hf_hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned)(sizeof(Window)); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) + ( (unsigned)_hj_key[2] << 16 ) + ( (unsigned)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) + ( (unsigned)_hj_key[6] << 16 ) + ( (unsigned)_hj_key[7] << 24 ) ); _hf_hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) + ( (unsigned)_hj_key[10] << 16 ) + ( (unsigned)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } _hf_hashv += sizeof(Window); switch ( _hj_k ) { case 11: _hf_hashv += ( (unsigned)_hj_key[10] << 24 ); case 10: _hf_hashv += ( (unsigned)_hj_key[9] << 16 ); case 9: _hf_hashv += ( (unsigned)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hf_bkt = _hf_hashv & ((frame_map)->hh.tbl->num_buckets-1); } while(0); if ((1)) { do { if ((frame_map)->hh.tbl->buckets[ _hf_bkt ].hh_head) do { (frame) = (__typeof(frame))(((void*)(((char*)((frame_map)->hh.tbl->buckets[ _hf_bkt ].hh_head)) - (((frame_map)->hh.tbl)->hho)))); } while(0); else frame=((void *)0); while (frame) { if ((frame)->hh.keylen == sizeof(Window)) { if ((memcmp((frame)->hh.key,&id,sizeof(Window))) == 0) break; } if ((frame)->hh.hh_next) do { (frame) = (__typeof(frame))(((void*)(((char*)((frame)->hh.hh_next)) - (((frame_map)->hh.tbl)->hho)))); } while(0); else frame = ((void *)0); } } while(0); } } } while (0);
   return frame;
}

canonical_original_code:
struct frame_t *frame_get(unsigned long id)
{
   struct frame_t *frame;
   do { unsigned int _hf_bkt; unsigned int _hf_hashv; frame=((void *)0); if (frame_map) { do { unsigned int _hj_i; unsigned int _hj_j; unsigned int _hj_k; unsigned char *_hj_key = (unsigned char*)(&id); _hf_hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned int)(sizeof(Window)); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned int)_hj_key[1] << 8 ) + ( (unsigned int)_hj_key[2] << 16 ) + ( (unsigned int)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned int)_hj_key[5] << 8 ) + ( (unsigned int)_hj_key[6] << 16 ) + ( (unsigned int)_hj_key[7] << 24 ) ); _hf_hashv += (_hj_key[8] + ( (unsigned int)_hj_key[9] << 8 ) + ( (unsigned int)_hj_key[10] << 16 ) + ( (unsigned int)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } _hf_hashv += sizeof(Window); switch ( _hj_k ) { case 11: _hf_hashv += ( (unsigned int)_hj_key[10] << 24 ); case 10: _hf_hashv += ( (unsigned int)_hj_key[9] << 16 ); case 9: _hf_hashv += ( (unsigned int)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned int)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned int)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned int)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned int)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned int)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned int)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hf_bkt = _hf_hashv & ((frame_map)->hh.tbl->num_buckets-1); } while(0); if ((1)) { do { if ((frame_map)->hh.tbl->buckets[ _hf_bkt ].hh_head) do { (frame) = (__typeof(frame))(((void *)(((char *)((frame_map)->hh.tbl->buckets[ _hf_bkt ].hh_head)) - (((frame_map)->hh.tbl)->hho)))); } while(0); else frame=((void *)0); while (frame) { if ((frame)->hh.keylen == sizeof(Window)) { if ((memcmp((frame)->hh.key,&id,sizeof(Window))) == 0) break; } if ((frame)->hh.hh_next) do { (frame) = (__typeof(frame))(((void *)(((char *)((frame)->hh.hh_next)) - (((frame_map)->hh.tbl)->hho)))); } while(0); else frame = ((void *)0); } } while(0); } } } while (0);
   return frame;
}

variable_types: struct frame_t { unsigned long id; int x; int y; unsigned int width; unsigned int height; struct window_t { unsigned long id; char *name; char *icon_name; long flags; int min_width; int min_height; int max_width; int max_height; int width_inc; int height_inc; int base_width; int base_height; } *child; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *

user_defined_types: struct frame_t { unsigned long id; int x; int y; unsigned int width; unsigned int height; struct window_t *child; struct UT_hash_handle hh; }


nul

decompiled_code:
void nul()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void nul(long word) {
}

canonical_original_code:
void nul(long word) {
}

variable_types: word long


SHORT

decompiled_code:
int __fastcall SHORT(__int64 a1)
{
int result; // eax

last = (__int64)"yellow";
if ( (a1 & 0x10) != 0 )
result = printf("0x%X", a1 >> 5);
else
result = printf("%i", a1 >> 5);
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
int result; // eax

last = (__int64)"yellow";
if ( (a1 & 0x10) != 0 )
result = printf("0x%X", a1 >> 5);
else
result = printf("%i", a1 >> 5);
return result;
}

original_code:
void SHORT(long word) {
 last="yellow";
 if((word >> 4) & 1)
  printf("0x%X",word >> 5);
 else
  printf("%i",word >> 5);
}


cSHORT

decompiled_code:
int __fastcall cSHORT(__int64 a1)
{
int result; // eax

last = (__int64)"green";
if ( (a1 & 0x10) != 0 )
result = printf("0x%X", a1 >> 5);
else
result = printf("%i", a1 >> 5);
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int result; // eax

last = (__int64)"green";
if ( (a1 & 0x10) != 0 )
result = printf("0x%X", a1 >> 5);
else
result = printf("%i", a1 >> 5);
return result;
}

original_code:
void cSHORT(long word) {
 last="green";
 if((word >> 4) & 1)
  printf("0x%X",word >> 5);
 else
  printf("%i",word >> 5);
}


unpack

original_code:
char *unpack(long word) {
 static char buf[8];
 int i;
 for(i=0;i<7;i++) {
  if(word & 0x80000000) {
   word = word << 1;
   if(word & 0x80000000) {
    word = word << 1;
    buf[i] = chars[((word >> 27) & 0x1F)+16];
    word = word << 5;
   } else {
    buf[i] = chars[((word >> 28) & 7)+8];
    word = word << 4;
   }
  } else {
   buf[i] = chars[(word >> 28) & 7];
   word = word << 4;
  }
 }
 for(i=6;i>=0;i--) {
  if(buf[i] == ' ')
   buf[i] = 0;
  else
   break;
 }
 buf[7] = 0;
 return buf;
}

variable_types:
buf
char [8]

return_type: char *


exten

decompiled_code:
void __fastcall exten(int a1)
{
__int64 v1; // rdi
const char *v2; // rax

v1 = a1 & 0xFFFFFFF0;
if ( (_DWORD)v1 )
{
v2 = (const char *)unpack(v1);
printf("%s", (const char *)last, v2);
}
}

canonical_decompiled_code:
void __fastcall func11(int a1)
{
__int64 v1; // rdi
const char *v2; // rax

v1 = a1 & 0xFFFFFFF0;
if ( (_DWORD)v1 )
{
v2 = (const char *)func10(v1);
printf("%s", (const char *)last, v2);
}
}

original_code:
void exten(long word) {
 if(word & 0xFFFFFFF0) {
  printf("%s",last,unpack(word & 0xFFFFFFF0));
 } else {
 }
}


execute

decompiled_code:
int __fastcall execute(int a1)
{
const char *v1; // rax

last = (__int64)"yellow";
v1 = (const char *)unpack(a1 & 0xFFFFFFF0);
return printf("%s", v1);
}

canonical_decompiled_code:
int __fastcall func12(int a1)
{
const char *v1; // rax

last = (__int64)"yellow";
v1 = (const char *)func10(a1 & 0xFFFFFFF0);
return printf("%s", v1);
}

original_code:
void execute(long word) {
 last="yellow";
 printf("%s",unpack(word & 0xFFFFFFF0));
}


comment

decompiled_code:
int __fastcall comment(int a1)
{
const char *v1; // rax

last = (__int64)"black";
v1 = (const char *)unpack(a1 & 0xFFFFFFF0);
return printf("%s", v1);
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
const char *v1; // rax

last = (__int64)"black";
v1 = (const char *)func10(a1 & 0xFFFFFFF0);
return printf("%s", v1);
}

original_code:
void comment(long word) {
 last="black";
 printf("%s",unpack(word & 0xFFFFFFF0));
}


red

decompiled_code:
int __fastcall red(int a1)
{
const char *v1; // rax

last = (__int64)"red";
v1 = (const char *)unpack(a1 & 0xFFFFFFF0);
return printf("
%s", v1);
}

canonical_decompiled_code:
int __fastcall func14(int a1)
{
const char *v1; // rax

last = (__int64)"red";
v1 = (const char *)func10(a1 & 0xFFFFFFF0);
return printf("
%s", v1);
}

original_code:
void red(long word) {
 last="red";
 printf("
%s",unpack(word & 0xFFFFFFF0));
}


qCOMPILE

decompiled_code:
int __fastcall qCOMPILE(int a1)
{
const char *v1; // rax

last = (__int64)"green";
v1 = (const char *)unpack(a1 & 0xFFFFFFF0);
return printf("%s", v1);
}

canonical_decompiled_code:
int __fastcall func15(int a1)
{
const char *v1; // rax

last = (__int64)"green";
v1 = (const char *)func10(a1 & 0xFFFFFFF0);
return printf("%s", v1);
}

original_code:
void qCOMPILE(long word) {
 last="green";
 printf("%s",unpack(word & 0xFFFFFFF0));
}


COMPILE

decompiled_code:
int __fastcall COMPILE(int a1)
{
const char *v1; // rax

last = (__int64)"cyan";
v1 = (const char *)unpack(a1 & 0xFFFFFFF0);
return printf("%s", v1);
}

canonical_decompiled_code:
int __fastcall func16(int a1)
{
const char *v1; // rax

last = (__int64)"cyan";
v1 = (const char *)func10(a1 & 0xFFFFFFF0);
return printf("%s", v1);
}

original_code:
void COMPILE(long word) {
 last="cyan";
 printf("%s",unpack(word & 0xFFFFFFF0));
}


doit

decompiled_code:
void __fastcall doit(char a1)
{
typetbl[a1 & 0xF]();
}

canonical_decompiled_code:
void __fastcall func17(char a1)
{
typetbl[a1 & 0xF]();
}

original_code:
void doit(long int word) {
 typetbl[word & 0x0F](word);
}

canonical_original_code:
void doit(long word) {
 typetbl[word & 0x0F](word);
}


getword

decompiled_code:
__int64 getword()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 v2; // rbx
int v3; // eax

v0 = (unsigned __int8)fgetc(STREAM);
v1 = v0 + (unsigned __int16)((unsigned __int16)fgetc(STREAM) << 8);
v2 = ((fgetc(STREAM) << 16) & 0xFF0000) + v1;
v3 = fgetc(STREAM);
++count;
return v2 + (v3 << 24);
}

canonical_decompiled_code:
__int64 func18()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 v2; // rbx
int v3; // eax

v0 = (unsigned __int8)fgetc(STREAM);
v1 = v0 + (unsigned __int16)((unsigned __int16)fgetc(STREAM) << 8);
v2 = ((fgetc(STREAM) << 16) & 0xFF0000) + v1;
v3 = fgetc(STREAM);
++count;
return v2 + (v3 << 24);
}

original_code:
long getword(void) {
 long int word;
 word = fgetc(STREAM) & 0xFF;
 word += (fgetc(STREAM) & 0xFF) <<8;
 word += (fgetc(STREAM) & 0xFF) <<16;
 word += (fgetc(STREAM) & 0xFF) <<24;
 count++;
 return word;
}

canonical_original_code:
long getword() {
 long word;
 word = fgetc(STREAM) & 0xFF;
 word += (fgetc(STREAM) & 0xFF) <<8;
 word += (fgetc(STREAM) & 0xFF) <<16;
 word += (fgetc(STREAM) & 0xFF) <<24;
 count++;
 return word;
}

return_type: long


NUM

decompiled_code:
int __fastcall NUM(char a1)
{
__int64 v1; // rax
int result; // eax

last = (__int64)"yellow";
v1 = getword();
if ( (a1 & 0x10) != 0 )
result = printf("0x%X", v1);
else
result = printf("%i", v1);
return result;
}

canonical_decompiled_code:
int __fastcall func19(char a1)
{
__int64 v1; // rax
int result; // eax

last = (__int64)"yellow";
v1 = func18();
if ( (a1 & 0x10) != 0 )
result = printf("0x%X", v1);
else
result = printf("%i", v1);
return result;
}

original_code:
void NUM(long word) {
 last="yellow";
 if((word >> 4) & 1)
  printf("0x%X",getword());
 else
  printf("%i",getword());
}


cNUM

decompiled_code:
int __fastcall cNUM(char a1)
{
__int64 v1; // rax
int result; // eax

last = (__int64)"green";
v1 = getword();
if ( (a1 & 0x10) != 0 )
result = printf("0x%X", v1);
else
result = printf("%i", v1);
return result;
}

canonical_decompiled_code:
int __fastcall func20(char a1)
{
__int64 v1; // rax
int result; // eax

last = (__int64)"green";
v1 = func18();
if ( (a1 & 0x10) != 0 )
result = printf("0x%X", v1);
else
result = printf("%i", v1);
return result;
}

original_code:
void cNUM(long word) {
 last="green";
 if((word >> 4) & 1)
  printf("0x%X",getword());
 else
  printf("%i",getword());
}


variable

decompiled_code:
int __fastcall variable(int a1)
{
__int64 v1; // rbp
const char *v2; // rax

last = (__int64)"magenta";
v1 = getword();
v2 = (const char *)unpack(a1 & 0xFFFFFFF0);
return printf("%s %u", v2, v1);
}

canonical_decompiled_code:
int __fastcall func21(int a1)
{
__int64 v1; // rbp
const char *v2; // rax

last = (__int64)"magenta";
v1 = func18();
v2 = (const char *)func10(a1 & 0xFFFFFFF0);
return printf("%s %u", v2, v1);
}

original_code:
void variable(long word) {
 last="magenta";
 printf("%s %u",unpack(word & 0xFFFFFFF0),getword());
}


gotoblock

decompiled_code:
int __fastcall gotoblock(int a1)
{
return fseek(STREAM, (a1 - 12) << 10, 0);
}

canonical_decompiled_code:
int __fastcall func22(int a1)
{
return fseek(STREAM, (a1 - 12) << 10, 0);
}

original_code:
void gotoblock(int block) {
 fseek(STREAM,-12*1024+block*1024,0);
}

variable_types: block int


dumpblock

decompiled_code:
void dumpblock()
{
char v0; // bl

count = 0;
do
{
v0 = getword();
if ( (v0 & 0xF) != 0 )
printf("  ");
doit(v0);
}
while ( count <= 255 );
}

canonical_decompiled_code:
void func23()
{
char v0; // bl

count = 0;
do
{
v0 = func18();
if ( (v0 & 0xF) != 0 )
printf("  ");
func17(v0);
}
while ( count <= 255 );
}

original_code:
void dumpblock(void) {
 long word;
 for(count = 0; count < 256;) {
  word = getword();
  if((word & 0x0F) != 0) {
   printf("  ");
  }
  doit(word);
 }
}

canonical_original_code:
void dumpblock() {
 long word;
 for(count = 0; count < 256;) {
  word = getword();
  if((word & 0x0F) != 0) {
   printf("  ");
  }
  doit(word);
 }
}


main

canonical_name: main

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

if ( argc != 3 )
{
fwrite("Usage: blk2html <.blk file> <block number>\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
STREAM = fopen(argv[1], "r");
if ( !STREAM )
{
fprintf(stderr, "Couldn't open .blk file \"%s\"!\n", argv[1]);
exit(1);
}
v3 = atoi(argv[2]);
gotoblock(v3);
last = (__int64)"black";
dumpblock();
fclose(STREAM);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax

if ( argc != 3 )
{
fwrite("Usage: blk2html <.blk file> <block number>\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
STREAM = fopen(argv[1], "r");
if ( !STREAM )
{
fprintf(stderr, "Couldn't open .blk file \"%s\"!\n", argv[1]);
exit(1);
}
v3 = atoi(argv[2]);
func22(v3);
last = (__int64)"black";
func23();
fclose(STREAM);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 if(argc != 3) {
  fprintf(stderr,"Usage: blk2html <.blk file> <block number>\n");
  exit(1);
 }
 STREAM = fopen(argv[1],"r");
 if(!STREAM) {
  fprintf(stderr,"Couldn't open .blk file \"%s\"!\n",argv[1]);
  exit(1);
 }
 gotoblock(atoi(argv[2]));
 last = "black";
 dumpblock();
 fclose(STREAM);
 return 0;
}

variable_types:
argv
char *[]

return_type: int


original_code:
static inline double chi2_intrinsic_double(int n, const double* x, const double* y) {
    double result=0;
    const __m128d eps = _mm_set1_pd(((double)2.22507385850720138309023271733240406e-308L));
    const __m128d zero = _mm_setzero_pd();
    __m128d chi2 = _mm_setzero_pd();
    for ( ; n>1; n-=2) {
        const __m128d a = _mm_loadu_pd(x);
        const __m128d b = _mm_loadu_pd(y);
 x+=2;
 y+=2;
        const __m128d a_plus_b = _mm_add_pd(a,b);
        const __m128d a_plus_b_plus_eps = _mm_add_pd(a_plus_b,eps);
        const __m128d a_minus_b = _mm_sub_pd(a,b);
        const __m128d a_minus_b_sq = _mm_mul_pd(a_minus_b, a_minus_b);
        const __m128d quotient = _mm_div_pd(a_minus_b_sq, a_plus_b_plus_eps);
        chi2 = _mm_add_pd(chi2, quotient);
    }
    const __m128d shuffle = ((__m128d)__builtin_ia32_shufpd ((__v2df)(__m128d)(chi2), (__v2df)(__m128d)(chi2), (int)((((0) << 1) | (1)))));
    const __m128d sum = _mm_add_pd(chi2, shuffle);
    _mm_store_sd(&result,sum);
    _mm_empty();
    if (n)
        result += chi2_baseline_double(n, x, y);
    return result;
}

canonical_original_code:
static inline double chi2_intrinsic_double(int n, double *x, double *y) {
    double result = 0;
    double eps = _mm_set1_pd(((double)2.22507385850720138309023271733240406e-308L));
    double zero = _mm_setzero_pd();
    double chi2 = _mm_setzero_pd();
    for ( ; n>1; n-=2) {
        double a = _mm_loadu_pd(x);
        double b = _mm_loadu_pd(y);
 x+=2;
 y+=2;
        double a_plus_b = _mm_add_pd(a,b);
        double a_plus_b_plus_eps = _mm_add_pd(a_plus_b,eps);
        double a_minus_b = _mm_sub_pd(a,b);
        double a_minus_b_sq = _mm_mul_pd(a_minus_b, a_minus_b);
        double quotient = _mm_div_pd(a_minus_b_sq, a_plus_b_plus_eps);
        chi2 = _mm_add_pd(chi2, quotient);
    }
    double shuffle = ((__m128d)__builtin_ia32_shufpd ((__v2df)(__m128d)(chi2), (__v2df)(__m128d)(chi2), (int)((((0) << 1) | (1)))));
    double sum = _mm_add_pd(chi2, shuffle);
    _mm_store_sd(&result,sum);
    _mm_empty();
    if (n)
        result += chi2_baseline_double(n, x, y);
    return result;
}

variable_types: n int

variable_types:
x
double *

variable_types:
y
double *

variable_types: result double

variable_types: eps double

variable_types: zero double

variable_types: a double

variable_types: b double

variable_types: quotient double

variable_types: shuffle double

variable_types: sum double

return_type: double


decompiled_code:
double __fastcall chi2_double(int a1, __int64 a2, __int64 a3)
{
return chi2_intrinsic_double(a1, a2, a3);
}

canonical_decompiled_code:
double __fastcall func9(int a1, __int64 a2, __int64 a3)
{
return func8(a1, a2, a3);
}

original_code:
double chi2_double(const int dim, const double* const x, const double* const y) {
    double (*chi2_double)(const int, const double*, const double*) = chi2_baseline_double;
    chi2_double = chi2_intrinsic_double;
    return chi2_double(dim, x, y);
}

canonical_original_code:
double chi2_double(int dim, double *x, double *y) {
    double (*chi2_double)(int, double *, double *) = chi2_baseline_double;
    chi2_double = chi2_intrinsic_double;
    return chi2_double(dim, x, y);
}

variable_types: dim int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
void *v4; // rbx
void *v5; // r12
int v6; // er13
__int64 i; // rax
__int64 j; // rax
int v9; // eax
int v10; // er14
double v11; // r13
int v12; // eax
int result; // eax

v3 = memalign(0x10uLL, 0x16E3600uLL);
v4 = memalign(0x10uLL, 0x2DC6C00uLL);
v5 = malloc(0xF42400uLL);
if ( v4 == 0LL || v3 == 0LL || !v5 )
{
free(v3);
free(v4);
free(v5);
result = 1;
}
else
{
v6 = clock();
for ( i = 0LL; i != 3000000; ++i )
*((double *)v3 + i) = 1.0 / ((double)(int)i + 1.0);
for ( j = 0LL; j != 6000000; ++j )
*((double *)v4 + j) = 1.0 / ((double)(int)j + 1.0);
v9 = clock();
printf("init time: %8.4f\n", (double)(v9 - v6) * 0.000001);
v10 = clock();
v11 = chi2_distance_double(3000, 1000, (__int64)v3, 2000, (__int64)v4, (__int64)v5);
v12 = clock();
printf("chi2 time: %8.4f\n", (double)(v12 - v10) * 0.000001);
printf("result: %e\n", v11);
free(v3);
free(v4);
free(v5);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
void *v4; // rbx
void *v5; // r12
int v6; // er13
__int64 i; // rax
__int64 j; // rax
int v9; // eax
int v10; // er14
double v11; // r13
int v12; // eax
int result; // eax

v3 = memalign(0x10uLL, 0x16E3600uLL);
v4 = memalign(0x10uLL, 0x2DC6C00uLL);
v5 = malloc(0xF42400uLL);
if ( v4 == 0LL || v3 == 0LL || !v5 )
{
free(v3);
free(v4);
free(v5);
result = 1;
}
else
{
v6 = clock();
for ( i = 0LL; i != 3000000; ++i )
*((double *)v3 + i) = 1.0 / ((double)(int)i + 1.0);
for ( j = 0LL; j != 6000000; ++j )
*((double *)v4 + j) = 1.0 / ((double)(int)j + 1.0);
v9 = clock();
printf("init time: %8.4f\n", (double)(v9 - v6) * 0.000001);
v10 = clock();
v11 = func11(3000, 1000, (__int64)v3, 2000, (__int64)v4, (__int64)v5);
v12 = clock();
printf("chi2 time: %8.4f\n", (double)(v12 - v10) * 0.000001);
printf("result: %e\n", v11);
free(v3);
free(v4);
free(v5);
result = 0;
}
return result;
}

original_code:
int main()
{
    const int dim=3000;
    const int n1=1000;
    const int n2=2000;
    int i,j;
    double *data1 = (double*)memalign(16,dim*n1*sizeof(double));
    double *data2 = (double*)memalign(16,dim*n2*sizeof(double));
    double *K = (double*)malloc(n1*n2*sizeof(double));
    if ((!data1) || (!data2) || (!K)) {
       free(data1);
       free(data2);
       free(K);
       return 1;
    }
    const clock_t before_init=clock();
    for (i=0;i<n1*dim;i++)
     data1[i]=1./(double)(i+1.);
    for (i=0;i<n2*dim;i++)
     data2[i]=1./(double)(i+1.);
    const clock_t after_init=clock();
    printf("init time: %8.4f\n",(after_init-before_init)*1./((__clock_t) 1000000));
    const clock_t before_chi2=clock();
    const double mean_K = chi2_distance_double(dim, n1, data1, n2, data2, K);
    const clock_t after_chi2=clock();
    printf("chi2 time: %8.4f\n",(after_chi2-before_chi2)*1./((__clock_t) 1000000));
    printf("result: %e\n",mean_K);
    free(data1);
    free(data2);
    free(K);
    return 0;
}

canonical_original_code:
int main()
{
    int dim = 3000;
    int n1 = 1000;
    int n2 = 2000;
    int i; int j;
    double *data1 = (double*)memalign(16,dim*n1*sizeof(double));
    double *data2 = (double*)memalign(16,dim*n2*sizeof(double));
    double *K = (double*)malloc(n1*n2*sizeof(double));
    if ((!data1) || (!data2) || (!K)) {
       free(data1);
       free(data2);
       free(K);
       return 1;
    }
    long before_init = clock();
    for (i=0;i<n1*dim;i++)
     data1[i]=1./(double)(i+1.);
    for (i=0;i<n2*dim;i++)
     data2[i]=1./(double)(i+1.);
    long after_init = clock();
    printf("init time: %8.4f\n",(after_init-before_init)*1./((long) 1000000));
    long before_chi2 = clock();
    double mean_K = chi2_distance_double(dim, n1, data1, n2, data2, K);
    long after_chi2 = clock();
    printf("chi2 time: %8.4f\n",(after_chi2-before_chi2)*1./((long) 1000000));
    printf("result: %e\n",mean_K);
    free(data1);
    free(data2);
    free(K);
    return 0;
}

variable_types: i int

variable_types: j int

variable_types:
K
double *


repo: nqv/aranea

decompiled_code:
__int64 init_conf()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
static
int init_conf() {
    return 0;
}

canonical_original_code:
static int init_conf() {
    return 0;
}


decompiled_code:
void __fastcall __noreturn print_help(const char *a1)
{
fprintf(stdout, "Usage: %s [OPTION]...\n", a1);
fprintf(
stdout,
"Options:\n%s",
" -d Run as daemon (background) mode\n"
" -p PORT Server listening port\n"
" -r DOCUMENT_ROOT Server root (absolute path)\n");
fprintf(stdout, "Version: %s (AUTH=%d CGI=%d CHROOT=%d VFORK=%d)\n", "0.1", 0LL, 0LL, 0LL, 0LL);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stdout, "Usage: %s [OPTION]...\n", a1);
fprintf(
stdout,
"Options:\n%s",
" -d Run as daemon (background) mode\n"
" -p PORT Server listening port\n"
" -r DOCUMENT_ROOT Server root (absolute path)\n");
fprintf(stdout, "Version: %s (AUTH=%d CGI=%d CHROOT=%d VFORK=%d)\n", "0.1", 0LL, 0LL, 0LL, 0LL);
exit(0);
}

original_code:
static
void print_help(const char *name) {
    fprintf(stdout, "Usage: %s [OPTION]...\n", name);
    fprintf(stdout, "Options:\n%s",
            "  -d                   Run as daemon (background) mode\n"
            "  -p PORT              Server listening port\n"
            "  -r DOCUMENT_ROOT     Server root (absolute path)\n"
            );
    fprintf(stdout, "Version: %s (AUTH=%d CGI=%d CHROOT=%d VFORK=%d)\n",
            "0.1", 0, 0, 0, 0);
    exit(0);
}

canonical_original_code:
static void print_help(char *name) {
    fprintf(stdout, "Usage: %s [OPTION]...\n", name);
    fprintf(stdout, "Options:\n%s",
            "  -d                   Run as daemon (background) mode\n"
            "  -p PORT              Server listening port\n"
            "  -r DOCUMENT_ROOT     Server root (absolute path)\n"
            );
    fprintf(stdout, "Version: %s (AUTH=%d CGI=%d CHROOT=%d VFORK=%d)\n",
            "0.1", 0, 0, 0, 0);
    exit(0);
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall parse_options(int a1, const char **a2)
{
int v2; // er8
char v3; // r9
int v4; // eax
__int64 v5; // rcx
const char *v6; // rdx
char v7; // dl
const char *v8; // rdx

g_server[1] = "8080";
g_config = (__int64)".";
if ( a1 <= 1 )
return 0LL;
v2 = flags_;
v3 = 0;
v4 = 1;
while ( 1 )
{
v5 = v4;
v6 = a2[v5];
if ( *v6 != 45 )
goto LABEL_4;
v7 = v6[1];
if ( v7 == 112 )
break;
if ( v7 > 112 )
{
if ( v7 == 114 )
{
++v4;
if ( !a2[v5 + 1] )
{
if ( v3 )
flags_ = v2;
fprintf(stderr, "Option %c requires an argument.\n", 114LL);
return 0xFFFFFFFFLL;
}
g_config = (__int64)a2[v5 + 1];
}
}
else if ( v7 == 100 )
{
v2 |= 2u;
v3 = 1;
}
else if ( v7 == 104 )
{
if ( v3 )
flags_ = v2;
print_help(*a2);
}
LABEL_4:
if ( a1 <= ++v4 )
{
if ( v3 )
flags_ = v2;
return 0LL;
}
}
++v4;
v8 = a2[v5 + 1];
if ( v8 )
{
g_server[1] = v8;
goto LABEL_4;
}
if ( v3 )
flags_ = v2;
fprintf(stderr, "Option %c requires an argument.\n", 112LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, const char **a2)
{
int v2; // er8
char v3; // r9
int v4; // eax
__int64 v5; // rcx
const char *v6; // rdx
char v7; // dl
const char *v8; // rdx

g_server[1] = "8080";
g_config = (__int64)".";
if ( a1 <= 1 )
return 0LL;
v2 = flags_;
v3 = 0;
v4 = 1;
while ( 1 )
{
v5 = v4;
v6 = a2[v5];
if ( *v6 != 45 )
goto LABEL_4;
v7 = v6[1];
if ( v7 == 112 )
break;
if ( v7 > 112 )
{
if ( v7 == 114 )
{
++v4;
if ( !a2[v5 + 1] )
{
if ( v3 )
flags_ = v2;
fprintf(stderr, "Option %c requires an argument.\n", 114LL);
return 0xFFFFFFFFLL;
}
g_config = (__int64)a2[v5 + 1];
}
}
else if ( v7 == 100 )
{
v2 |= 2u;
v3 = 1;
}
else if ( v7 == 104 )
{
if ( v3 )
flags_ = v2;
func1(*a2);
}
LABEL_4:
if ( a1 <= ++v4 )
{
if ( v3 )
flags_ = v2;
return 0LL;
}
}
++v4;
v8 = a2[v5 + 1];
if ( v8 )
{
g_server[1] = v8;
goto LABEL_4;
}
if ( v3 )
flags_ = v2;
fprintf(stderr, "Option %c requires an argument.\n", 112LL);
return 0xFFFFFFFFLL;
}

original_code:
static
int parse_options(int argc, char **argv) {
    int i;
    g_server.port = "8080";
    g_config.root = ".";
    for (i = 1; i < argc; ++i) {
        if (argv[i][0] == '-') {
            switch (argv[i][1]) {
            case 'd':
                flags_ |= FLAG_DAEMON;
                break;
            case 'h':
                print_help(argv[0]);
                break;
            case 'p':
                ++i;
                do { if ((argv[i]) == ((void *)0)) { fprintf(stderr, "Option %c requires an argument.\n", 'p'); return -1; } } while (0);
                g_server.port = argv[i];
                break;
            case 'r':
                ++i;
                do { if ((argv[i]) == ((void *)0)) { fprintf(stderr, "Option %c requires an argument.\n", 'r'); return -1; } } while (0);
                g_config.root = argv[i];
                break;
            }
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 init_signal()
{
int *v1; // rax
char *v2; // rax
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

memset(&v3, 0, sizeof(v3));
sigemptyset(&v3.sa_mask);
v3.sa_handler = (__sighandler_t)handle_signal;
if ( sigaction(17, &v3, 0LL) >= 0 && sigaction(3, &v3, 0LL) >= 0 )
return 0LL;
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "sigaction %s\n", v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func4()
{
int *v1; // rax
char *v2; // rax
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

memset(&v3, 0, sizeof(v3));
sigemptyset(&v3.sa_mask);
v3.sa_handler = (__sighandler_t)handle_signal;
if ( sigaction(17, &v3, 0LL) >= 0 && sigaction(3, &v3, 0LL) >= 0 )
return 0LL;
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "sigaction %s\n", v2);
return 0xFFFFFFFFLL;
}

original_code:
static
int init_signal() {
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sigemptyset(&sa.sa_mask);
    sa.__sigaction_handler.sa_handler = &handle_signal;
    if (sigaction(17, &sa, ((void *)0)) < 0
            || sigaction(3, &sa, ((void *)0)) < 0) {
        fprintf(stderr, "sigaction %s" "\n", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

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

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

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


decompiled_code:
void __fastcall handle_signal(int a1)
{
if ( a1 == 3 )
{
flags_ |= 1u;
}
else if ( a1 == 17 )
{
while ( waitpid(-1, 0LL, 1) > 0 )
;
}
}

canonical_decompiled_code:
void __fastcall func5(int a1)
{
if ( a1 == 3 )
{
flags_ |= 1u;
}
else if ( a1 == 17 )
{
while ( waitpid(-1, 0LL, 1) > 0 )
;
}
}

original_code:
static
void handle_signal(int sig) {
    switch (sig) {
    case 17:
        while (waitpid(-1, ((void *)0), 1) > 0);
        break;
    case 3:
        flags_ |= FLAG_QUIT;
        break;
    }
}

variable_types: sig int


cleanup

decompiled_code:
__int64 cleanup()
{
_QWORD *v0; // rbx
void *v1; // rbp

v0 = (_QWORD *)g_server[2];
while ( v0 )
{
v1 = v0;
v0 = (_QWORD *)v0[159];
client_close(v1);
free(v1);
}
return clientpool_cleanup();
}

canonical_decompiled_code:
__int64 func6()
{
_QWORD *v0; // rbx
void *v1; // rbp

v0 = (_QWORD *)g_server[2];
while ( v0 )
{
v1 = v0;
v0 = (_QWORD *)v0[159];
client_close(v1);
free(v1);
}
return clientpool_cleanup();
}

original_code:
static
void cleanup() {
    struct client_t *c, *tc;
    for (c = g_server.clients; c != ((void *)0); ) {
        tc = c;
        c = c->next;
        client_close(tc);
        free(tc);
    }
    clientpool_cleanup();
}

canonical_original_code:
static void cleanup() {
    struct client_t *c; struct client_t *tc;
    for (c = g_server.clients; c != ((void *)0); ) {
        tc = c;
        c = c->next;
        client_close(tc);
        free(tc);
    }
    clientpool_cleanup();
}

variable_types: struct client_t { int remote_fd; int local_rfd; long timeout; int state; char ip[40]; struct request_t { char *header[-1]; char *method; char *url; char *query_string; char *version; char *range_from; char *range_to; long header_length; } request; char data[1024]; long data_length; long data_sent; struct response_t { int status_code; char *content_type; long total_length; long content_length; long content_from; long last_mod; } response; long file_sent; unsigned int flags; struct client_t *next; struct client_t **prev; } *

user_defined_types: struct client_t { int remote_fd; int local_rfd; long timeout; int state; char ip[40]; struct request_t request; char data[1024]; long data_length; long data_sent; struct response_t response; long file_sent; unsigned int flags; struct client_t *next; struct client_t **prev; }


main

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

v3 = 1;
if ( !(unsigned int)parse_options(argc, argv) )
{
if ( (flags_ & 2) != 0 )
daemonize();
v3 = 1;
if ( !(unsigned int)init_conf() && !(unsigned int)init_signal() )
{
v3 = server_init(g_server);
if ( v3 )
{
v3 = 1;
}
else
{
while ( (flags_ & 1) == 0 )
server_poll(g_server);
cleanup();
}
}
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp

v3 = 1;
if ( !(unsigned int)func2(argc, argv) )
{
if ( (flags_ & 2) != 0 )
func3();
v3 = 1;
if ( !(unsigned int)func0() && !(unsigned int)func4() )
{
v3 = server_init(g_server);
if ( v3 )
{
v3 = 1;
}
else
{
while ( (flags_ & 1) == 0 )
server_poll(g_server);
func6();
}
}
}
return v3;
}

original_code:
int main(int argc, char **argv) {
    if (parse_options(argc, argv) != 0) {
        return 1;
    }
    if (flags_ & FLAG_DAEMON) {
        daemonize(argv);
    }
    if (init_conf() != 0) {
        return 1;
    }
    if (init_signal() != 0) {
        return 1;
    }
    if (server_init(&g_server) != 0) {
        return 1;
    }
    while (!(flags_ & FLAG_QUIT)) {
        server_poll(&g_server);
    }
    cleanup();
    return 0;
}


decompiled_code:
void *clientpool_alloc()
{
void *v0; // rbx

v0 = poolclient_;
if ( !poolclient_ )
return malloc(0x508uLL);
client_detach(poolclient_);
--poolclient_len_;
return v0;
}

canonical_decompiled_code:
void *func0()
{
void *v0; // rbx

v0 = poolclient_;
if ( !poolclient_ )
return malloc(0x508uLL);
client_detach(poolclient_);
--poolclient_len_;
return v0;
}

original_code:
struct client_t *clientpool_alloc() {
    struct client_t *cli;
    if (poolclient_ != ((void *)0)) {
        cli = poolclient_;
        client_detach(cli);
        --poolclient_len_;
    } else {
        cli = malloc(sizeof(struct client_t));
    }
    return cli;
}

return_type: struct client_t { int remote_fd; int local_rfd; long timeout; int state; char ip[40]; struct request_t { char *header[-1]; char *method; char *url; char *query_string; char *version; char *range_from; char *range_to; long header_length; } request; char data[1024]; long data_length; long data_sent; struct response_t { int status_code; char *content_type; long total_length; long content_length; long content_from; long last_mod; } response; long file_sent; unsigned int flags; struct client_t *next; struct client_t **prev; } *


decompiled_code:
void __fastcall clientpool_free(void *a1)
{
if ( poolclient_len_ <= 4 )
{
client_add(a1, &poolclient_);
++poolclient_len_;
}
else
{
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
if ( poolclient_len_ <= 4 )
{
client_add(a1, &poolclient_);
++poolclient_len_;
}
else
{
free(a1);
}
}

original_code:
void clientpool_free(struct client_t *cli) {
    if (poolclient_len_ > 4) {
        free(cli);
    } else {
        client_add(cli, &poolclient_);
        ++poolclient_len_;
    }
}

user_defined_types: struct request_t { char *header[-1]; char *method; char *url; char *query_string; char *version; char *range_from; char *range_to; long header_length; }

user_defined_types: struct response_t { int status_code; char *content_type; long total_length; long content_length; long content_from; long last_mod; }


decompiled_code:
void clientpool_cleanup()
{
void *v0; // rbx
void *v1; // rdi

v0 = poolclient_;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 159);
free(v1);
}
}

canonical_decompiled_code:
void func2()
{
void *v0; // rbx
void *v1; // rdi

v0 = poolclient_;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 159);
free(v1);
}
}

original_code:
void clientpool_cleanup() {
 struct client_t *c, *tc;
    for (c = poolclient_; c != ((void *)0); ) {
        tc = c;
        c = c->next;
        free(tc);
    }
}

canonical_original_code:
void clientpool_cleanup() {
 struct client_t *c; struct client_t *tc;
    for (c = poolclient_; c != ((void *)0); ) {
        tc = c;
        c = c->next;
        free(tc);
    }
}


decompiled_code:
__int64 __fastcall client_open_file(__int64 a1, const char *a2)
{
int v2; // eax
unsigned int v3; // ebp
__off_t v4; // rax
int *v6; // r13
char *v7; // rax
int v8; // eax
int *v9; // rax
char *v10; // rax
struct stat v11; // [rsp+0h] [rbp-B8h] BYREF

v2 = open(a2, 2048);
v3 = v2;
*(_DWORD *)(a1 + 4) = v2;
if ( v2 != -1 )
{
if ( fstat(v2, &v11) == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "stat: %s\n", v10);
*(_DWORD *)(a1 + 1208) = 500;
}
else
{
if ( (v11.st_mode & 0xF000) == 0x8000 )
{
*(_QWORD *)(a1 + 1248) = v11.st_mtim.tv_sec;
v4 = v11.st_size;
*(_QWORD *)(a1 + 1224) = v11.st_size;
*(_QWORD *)(a1 + 1232) = v4;
*(_QWORD *)(a1 + 1216) = mimetype_get(a2);
*(_QWORD *)(a1 + 1240) = 0LL;
return 0;
}
fprintf(stderr, "not a regular file 0x%x\n", v11.st_mode);
*(_DWORD *)(a1 + 1208) = 403;
}
close(*(_DWORD *)(a1 + 4));
*(_DWORD *)(a1 + 4) = -1;
return (unsigned int)-1;
}
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "open: %s %s\n", a2, v7);
if ( *v6 == 2 )
{
*(_DWORD *)(a1 + 1208) = 404;
}
else
{
v8 = 500;
if ( *v6 == 13 )
v8 = 403;
*(_DWORD *)(a1 + 1208) = v8;
}
return v3;
}

original_code:
static
int client_open_file(struct client_t *self, const char *path) {
    struct stat st;
    self->local_rfd = open(path, 00 | 04000);
    if (self->local_rfd == -1) {
        fprintf(stderr, "open: %s %s" "\n", path, strerror((*__errno_location ())));
        switch ((*__errno_location ())) {
        case 13:
            self->response.status_code = HTTP_STATUS_FORBIDDEN;
            break;
        case 2:
            self->response.status_code = HTTP_STATUS_NOTFOUND;
            break;
        default:
            self->response.status_code = HTTP_STATUS_SERVERERROR;
            break;
        }
        return -1;
    }
    if (fstat(self->local_rfd, &st) == -1) {
        fprintf(stderr, "stat: %s" "\n", strerror((*__errno_location ())));
        self->response.status_code = HTTP_STATUS_SERVERERROR;
        goto err;
    }
    if (((((st.st_mode)) & 0170000) == (0040000)) || !((((st.st_mode)) & 0170000) == (0100000))) {
        fprintf(stderr, "not a regular file 0x%x" "\n", st.st_mode);
        self->response.status_code = HTTP_STATUS_FORBIDDEN;
        goto err;
    }
    self->response.last_mod = st.st_mtim.tv_sec;
    self->response.total_length = st.st_size;
    self->response.content_length = st.st_size;
    self->response.content_type = mimetype_get(path);
    self->response.content_from = 0;
    return 0;
err:
    do { close(self->local_rfd); self->local_rfd = -1; } while (0);
    return -1;
}

canonical_original_code:
static int client_open_file(struct client_t *self, char *path) {
    struct stat st;
    self->local_rfd = open(path, 00 | 04000);
    if (self->local_rfd == -1) {
        fprintf(stderr, "open: %s %s" "\n", path, strerror((*__errno_location ())));
        switch ((*__errno_location ())) {
        case 13:
            self->response.status_code = HTTP_STATUS_FORBIDDEN;
            break;
        case 2:
            self->response.status_code = HTTP_STATUS_NOTFOUND;
            break;
        default:
            self->response.status_code = HTTP_STATUS_SERVERERROR;
            break;
        }
        return -1;
    }
    if (fstat(self->local_rfd, &st) == -1) {
        fprintf(stderr, "stat: %s" "\n", strerror((*__errno_location ())));
        self->response.status_code = HTTP_STATUS_SERVERERROR;
        goto err;
    }
    if (((((st.st_mode)) & 0170000) == (0040000)) || !((((st.st_mode)) & 0170000) == (0100000))) {
        fprintf(stderr, "not a regular file 0x%x" "\n", st.st_mode);
        self->response.status_code = HTTP_STATUS_FORBIDDEN;
        goto err;
    }
    self->response.last_mod = st.st_mtim.tv_sec;
    self->response.total_length = st.st_size;
    self->response.content_length = st.st_size;
    self->response.content_type = mimetype_get(path);
    self->response.content_from = 0;
    return 0;
err:
    do { close(self->local_rfd); self->local_rfd = -1; } while (0);
    return -1;
}

variable_types:
path
char *

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

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


decompiled_code:
__int64 __fastcall client_check_filemod(__int64 a1)
{
__int64 result; // rax
struct tm *v2; // rax
int v3; // eax
char v4[40]; // [rsp-28h] [rbp-28h] BYREF

result = 1LL;
if ( *(_QWORD *)(a1 + 104) )
{
v2 = gmtime((const time_t *)(a1 + 1248));
v3 = strftime(v4, 0x20uLL, "%a, %d %b %Y %H:%M:%S GMT", v2);
result = (unsigned int)-(strncmp(*(const char **)(a1 + 104), v4, v3) != 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
struct tm *v2; // rax
int v3; // eax
char v4[40]; // [rsp-28h] [rbp-28h] BYREF

result = 1LL;
if ( *(_QWORD *)(a1 + 104) )
{
v2 = gmtime((const time_t *)(a1 + 1248));
v3 = strftime(v4, 0x20uLL, "%a, %d %b %Y %H:%M:%S GMT", v2);
result = (unsigned int)-(strncmp(*(const char **)(a1 + 104), v4, v3) != 0);
}
return result;
}

original_code:
static
int client_check_filemod(struct client_t *self) {
    char date[32];
    int len;
    if (self->request.header[HEADER_IFMODIFIEDSINCE] == ((void *)0)) {
        return 1;
    }
    len = strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S GMT",
            gmtime(&self->response.last_mod));
    if (strncmp(self->request.header[HEADER_IFMODIFIEDSINCE], date, len) == 0) {
        return 0;
    }
    return -1;
}

variable_types:
date
char [32]

variable_types: len int


original_code:
static
int client_check_filerange(struct client_t *self) {
    off_t pos;
    if (self->request.range_from != ((void *)0)) {
        self->response.content_from = strtol(self->request.range_from, ((void *)0), 10);
        if (self->response.content_from >= self->response.content_length) {
            goto err;
        }
        if (self->request.range_to != ((void *)0)) {
            pos = strtol(self->request.range_to, ((void *)0), 10);
            if (pos < self->response.content_from) {
                goto err;
            }
            self->response.content_length = pos - self->response.content_from + 1;
        } else {
            self->response.content_length -= self->response.content_from - 1;
        }
    } else {
        if (self->request.range_to != ((void *)0)) {
            pos = strtol(self->request.range_to, ((void *)0), 10);
            if (pos >= self->response.content_length) {
                goto err;
            }
            self->response.content_from = self->response.content_length - pos;
            self->response.content_length = pos;
        } else {
            return 1;
        }
    }
    ;
    return 0;
err:
    self->response.status_code = HTTP_STATUS_RANGENOTSATISFIABLE;
    return -1;
}

canonical_original_code:
static int client_check_filerange(struct client_t *self) {
    long pos;
    if (self->request.range_from != ((void *)0)) {
        self->response.content_from = strtol(self->request.range_from, ((void *)0), 10);
        if (self->response.content_from >= self->response.content_length) {
            goto err;
        }
        if (self->request.range_to != ((void *)0)) {
            pos = strtol(self->request.range_to, ((void *)0), 10);
            if (pos < self->response.content_from) {
                goto err;
            }
            self->response.content_length = pos - self->response.content_from + 1;
        } else {
            self->response.content_length -= self->response.content_from - 1;
        }
    } else {
        if (self->request.range_to != ((void *)0)) {
            pos = strtol(self->request.range_to, ((void *)0), 10);
            if (pos >= self->response.content_length) {
                goto err;
            }
            self->response.content_from = self->response.content_length - pos;
            self->response.content_length = pos;
        } else {
            return 1;
        }
    }
    ;
    return 0;
err:
    self->response.status_code = HTTP_STATUS_RANGENOTSATISFIABLE;
    return -1;
}

variable_types: pos long


original_code:
static
int client_respond(struct client_t *self) {
    int len;
    char path[512];
    http_decode_url(self->request.url);
    http_sanitize_url(self->request.url);
    len = http_get_realpath(self->request.url, path);
    if (self->request.header[HEADER_CONNECTION] != ((void *)0)
            && strcmp("keep-alive", self->request.header[HEADER_CONNECTION]) == 0) {
        self->flags |= CLIENT_FLAG_KEEPALIVE;
    }
    if (client_open_file(self, path) != 0) {
        return -1;
    }
    if (client_check_filemod(self) == 0) {
        do { close(self->local_rfd); self->local_rfd = -1; } while (0);
        self->response.status_code = HTTP_STATUS_NOTMODIFIED;
        self->data_length = http_gen_header(&self->response, self->data,
                sizeof(self->data), HTTP_FLAG_END);
        self->state = STATE_SEND_HEADER;
        return 0;
    }
    len = client_check_filerange(self);
    if (len < 0) {
        do { close(self->local_rfd); self->local_rfd = -1; } while (0);
        return -1;
    }
    if (len == 0) {
        self->response.status_code = HTTP_STATUS_PARTIALCONTENT;
        self->data_length = http_gen_header(&self->response, self->data,
                sizeof(self->data), HTTP_FLAG_ACCEPT | HTTP_FLAG_CONTENT
                | HTTP_FLAG_RANGE | HTTP_FLAG_END);
        self->state = STATE_SEND_HEADER;
        return 0;
    }
    if (self->flags & CLIENT_FLAG_HEADERONLY) {
        do { close(self->local_rfd); self->local_rfd = -1; } while (0);
    }
    self->response.status_code = HTTP_STATUS_OK;
    self->data_length = http_gen_header(&self->response, self->data,
            sizeof(self->data), HTTP_FLAG_ACCEPT | HTTP_FLAG_CONTENT
            | HTTP_FLAG_END);
    self->state = STATE_SEND_HEADER;
    return 0;
}

variable_types:
path
char [512]


original_code:
void client_add(struct client_t *self, struct client_t **list) {
    if (*list == ((void *)0)) {
        self->next = ((void *)0);
    } else {
        self->next = *list;
        (*list)->prev = &self->next;
    }
    *list = self;
    self->prev = list;
}

variable_types:
list
struct client_t **


decompiled_code:
int __fastcall client_close(int *a1)
{
int v2; // edi
int v3; // edi
int result; // eax

v2 = *a1;
if ( v2 != -1 )
{
result = close(v2);
*a1 = -1;
}
v3 = a1[1];
if ( v3 != -1 )
{
result = close(v3);
a1[1] = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int *a1)
{
int v2; // edi
int v3; // edi
int result; // eax

v2 = *a1;
if ( v2 != -1 )
{
result = close(v2);
*a1 = -1;
}
v3 = a1[1];
if ( v3 != -1 )
{
result = close(v3);
a1[1] = -1;
}
return result;
}

original_code:
void client_close(struct client_t *self) {
    if (self->remote_fd != -1) {
        do { close(self->remote_fd); self->remote_fd = -1; } while (0);
    }
    if (self->local_rfd != -1) {
        do { close(self->local_rfd); self->local_rfd = -1; } while (0);
    }
}


original_code:
void client_reset(struct client_t *self) {
    self->data_length = 0;
    self->data_sent = 0;
    self->file_sent = 0;
    self->flags = 0;
    memset(&self->request, 0, sizeof(self->request));
    memset(&self->response, 0, sizeof(self->response));
}


original_code:
void client_init(struct client_t *self) {
    self->remote_fd = -1;
    self->local_rfd = -1;
    self->ip[0] = '\0';
    self->state = STATE_NONE;
    client_reset(self);
}


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

if ( (unsigned int)http_parse(a1 + 64, a1 + 168, *(unsigned int *)(a1 + 1192))
|| !*(_QWORD *)(a1 + 112)
|| !*(_QWORD *)(a1 + 120)
|| !*(_QWORD *)(a1 + 136) )
{
*(_DWORD *)(a1 + 1208) = 400;
goto LABEL_10;
}
if ( !strcmp(*(const char **)(a1 + 112), "GET") )
{
result = client_respond(a1);
}
else if ( !strcmp(*(const char **)(a1 + 112), "HEAD") )
{
*(_DWORD *)(a1 + 1264) |= 1u;
result = client_respond(a1);
}
else
{
if ( strcmp(*(const char **)(a1 + 112), "POST") )
{
*(_DWORD *)(a1 + 1208) = 501;
LABEL_10:
result = (int)http_gen_errorpage(a1 + 1208, a1 + 168, 1024LL);
*(_QWORD *)(a1 + 1192) = (int)result;
*(_DWORD *)(a1 + 16) = 2;
return result;
}
*(_DWORD *)(a1 + 1264) |= 2u;
result = client_respond(a1);
}
if ( (_DWORD)result )
goto LABEL_10;
return result;
}

original_code:
void client_process(struct client_t *self) {
    int ret;
    if (http_parse(&self->request, self->data, self->data_length) != 0
            || self->request.method == ((void *)0) || self->request.url == ((void *)0)
            || self->request.version == ((void *)0)) {
        self->response.status_code = HTTP_STATUS_BADREQUEST;
        ret = -1;
    } else if (strcmp(self->request.method, "GET") == 0) {
        ret = client_respond(self);
    } else if (strcmp(self->request.method, "HEAD") == 0) {
        self->flags |= CLIENT_FLAG_HEADERONLY;
        ret = client_respond(self);
    } else if (strcmp(self->request.method, "POST") == 0) {
        self->flags |= CLIENT_FLAG_POST;
        ret = client_respond(self);
    } else {
        self->response.status_code = HTTP_STATUS_NOTIMPLEMENTED;
        ret = -1;
    }
    if (ret != 0) {
        self->data_length = http_gen_errorpage(&self->response, self->data,
                sizeof(self->data));
        self->state = STATE_SEND_HEADER;
    }
}

variable_types: ret int


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

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 65) <= 5u )
return (unsigned int)(a1 - 55);
result = (unsigned int)(a1 - 87);
if ( (unsigned __int8)(a1 - 97) >= 6u )
result = 0LL;
return result;
}

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

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 65) <= 5u )
return (unsigned int)(a1 - 55);
result = (unsigned int)(a1 - 87);
if ( (unsigned __int8)(a1 - 97) >= 6u )
result = 0LL;
return result;
}

original_code:
static
int hex_to_int(const char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    if (c >= 'A' && c <= 'F') {
        return c - 'A' + 10;
    }
    if (c >= 'a' && c <= 'f') {
        return c - 'a' + 10;
    }
    return 0;
}

variable_types: c char


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

result = strchr(a1, 63);
if ( result )
*result++ = 0;
return result;
}

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

result = strchr(a1, 63);
if ( result )
*result++ = 0;
return result;
}

original_code:
static
char *http_parse_querystring(char *url) {
    char *p;
    p = strchr(url, '?');
    if (p == ((void *)0)) {
        return ((void *)0);
    }
    *p = '\0';
    return p + 1;
}

variable_types:
url
char *

variable_types:
p
char *


decompiled_code:
int __fastcall http_parse_range(__int64 a1, const char *a2)
{
const char *v4; // rbx
char *v5; // rax
char *v6; // rax

if ( !memcmp(a2, "bytes=", 6uLL) )
{
v4 = a2 + 6;
v5 = strchr(a2 + 6, 45);
if ( v5 )
{
if ( v4 == v5 )
{
*(_QWORD *)(a1 + 80) = 0LL;
}
else
{
*v5 = 0;
*(_QWORD *)(a1 + 80) = v4;
}
*(_QWORD *)(a1 + 88) = v5 + 1;
v6 = strchr(v5 + 1, 44);
if ( v6 )
*v6 = 0;
}
else
{
LODWORD(v6) = fprintf(stderr, "no hyphen: %s\n", v4);
}
}
else
{
LODWORD(v6) = fprintf(stderr, "ranges are not in bytes: %s\n", a2);
}
return (int)v6;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, const char *a2)
{
const char *v4; // rbx
char *v5; // rax
char *v6; // rax

if ( !memcmp(a2, "bytes=", 6uLL) )
{
v4 = a2 + 6;
v5 = strchr(a2 + 6, 45);
if ( v5 )
{
if ( v4 == v5 )
{
*(_QWORD *)(a1 + 80) = 0LL;
}
else
{
*v5 = 0;
*(_QWORD *)(a1 + 80) = v4;
}
*(_QWORD *)(a1 + 88) = v5 + 1;
v6 = strchr(v5 + 1, 44);
if ( v6 )
*v6 = 0;
}
else
{
LODWORD(v6) = fprintf(stderr, "no hyphen: %s\n", v4);
}
}
else
{
LODWORD(v6) = fprintf(stderr, "ranges are not in bytes: %s\n", a2);
}
return (int)v6;
}

original_code:
static
void http_parse_range(struct request_t *self, char *val) {
    char *delim;
    if (strncmp(val, "bytes=", 6) != 0) {
        fprintf(stderr, "ranges are not in bytes: %s" "\n", val);
        return;
    }
    val += 6;
    delim = strchr(val, '-');
    if (delim == ((void *)0)) {
        fprintf(stderr, "no hyphen: %s" "\n", val);
        return;
    }
    if (delim == val) {
        self->range_from = ((void *)0);
    } else {
        *delim = '\0';
        self->range_from = val;
    }
    self->range_to = delim + 1;
    delim = strchr(self->range_to, ',');
    if (delim != ((void *)0)) {
        *delim = '\0';
    }
}

variable_types: struct request_t { char *header[-1]; char *method; char *url; char *query_string; char *version; char *range_from; char *range_to; long header_length; } *

variable_types:
val
char *

variable_types:
delim
char *


decompiled_code:
int __fastcall http_save_header(__int64 a1, const char *a2, const char *a3)
{
__int64 v4; // rbx
int v5; // ebp
int result; // eax

v4 = 0LL;
while ( 1 )
{
v5 = v4;
result = strcasecmp(a2, HTTP_REQUEST_HEADERS[v4]);
if ( !result )
break;
v5 = ++v4;
if ( v4 == 6 )
goto LABEL_4;
}
result = v4;
*(_QWORD *)(a1 + 8LL * (int)v4) = a3;
LABEL_4:
if ( v5 == 2 )
result = http_parse_range(a1, a3);
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2, const char *a3)
{
__int64 v4; // rbx
int v5; // ebp
int result; // eax

v4 = 0LL;
while ( 1 )
{
v5 = v4;
result = strcasecmp(a2, HTTP_REQUEST_HEADERS[v4]);
if ( !result )
break;
v5 = ++v4;
if ( v4 == 6 )
goto LABEL_4;
}
result = v4;
*(_QWORD *)(a1 + 8LL * (int)v4) = a3;
LABEL_4:
if ( v5 == 2 )
result = func2(a1, a3);
return result;
}

original_code:
static
void http_save_header(struct request_t *self, char *key, char *val) {
    int i;
    for (i = 0; i < NUM_REQUEST_HEADER; ++i) {
        if (strcasecmp(key, HTTP_REQUEST_HEADERS[i]) == 0) {
            self->header[i] = val;
            break;
        }
    }
    if (i == HEADER_CONTENTRANGE) {
        http_parse_range(self, val);
    }
}

variable_types:
key
char *

variable_types: i int


decompiled_code:
int __fastcall http_put_headerrange(_QWORD *a1, char *a2, int a3)
{
return snprintf(a2, a3, "Content-Range: bytes %ld-%ld/%ld\r\n", a1[4], a1[3] + a1[4] - 1LL, a1[2]);
}

canonical_decompiled_code:
int __fastcall func5(_QWORD *a1, char *a2, int a3)
{
return snprintf(a2, a3, "Content-Range: bytes %ld-%ld/%ld\r\n", a1[4], a1[3] + a1[4] - 1LL, a1[2]);
}

original_code:
static
int http_put_headerrange(struct response_t *self, char *data, int sz) {
    off_t to;
    to = self->content_from + self->content_length - 1;
    return snprintf(data, sz, "Content-Range: bytes %ld-%ld/%ld\r\n",
            self->content_from, to, self->total_length);
}

canonical_original_code:
static int http_put_headerrange(struct response_t *self, char *data, int sz) {
    long to;
    to = self->content_from + self->content_length - 1;
    return snprintf(data, sz, "Content-Range: bytes %ld-%ld/%ld\r\n",
            self->content_from, to, self->total_length);
}

variable_types: struct response_t { int status_code; char *content_type; long total_length; long content_length; long content_from; long last_mod; } *

variable_types:
data
char *

variable_types: sz int

variable_types: to long


decompiled_code:
__int64 __fastcall http_put_headercontent(__int64 a1, char *a2, int a3)
{
int v3; // ebx
__int64 v4; // rcx
int v5; // ebp
const char *v6; // rcx
int v7; // eax
int v9; // eax
struct tm *v10; // rax
int v11; // eax

v3 = a3;
v4 = *(_QWORD *)(a1 + 24);
v5 = 0;
if ( v4 >= 0 )
{
v9 = snprintf(a2, a3, "Content-Length: %ld\r\n", v4);
v5 = v9;
if ( v9 < 0 || v3 <= v9 )
return (unsigned int)-1;
v3 -= v9;
}
v6 = *(const char **)(a1 + 8);
if ( v6 )
{
v7 = snprintf(&a2[v5], v3, "Content-Type: %s\r\n", v6);
if ( v7 < 0 || v3 <= v7 )
return (unsigned int)-1;
v3 -= v7;
v5 += v7;
}
if ( *(__int64 *)(a1 + 40) >= 0 )
{
v10 = gmtime((const time_t *)(a1 + 40));
v11 = strftime(&a2[v5], v3, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT\r\n", v10);
if ( v11 < 0 || v3 <= v11 )
v5 = -1;
else
v5 += v11;
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2, int a3)
{
int v3; // ebx
__int64 v4; // rcx
int v5; // ebp
const char *v6; // rcx
int v7; // eax
int v9; // eax
struct tm *v10; // rax
int v11; // eax

v3 = a3;
v4 = *(_QWORD *)(a1 + 24);
v5 = 0;
if ( v4 >= 0 )
{
v9 = snprintf(a2, a3, "Content-Length: %ld\r\n", v4);
v5 = v9;
if ( v9 < 0 || v3 <= v9 )
return (unsigned int)-1;
v3 -= v9;
}
v6 = *(const char **)(a1 + 8);
if ( v6 )
{
v7 = snprintf(&a2[v5], v3, "Content-Type: %s\r\n", v6);
if ( v7 < 0 || v3 <= v7 )
return (unsigned int)-1;
v3 -= v7;
v5 += v7;
}
if ( *(__int64 *)(a1 + 40) >= 0 )
{
v10 = gmtime((const time_t *)(a1 + 40));
v11 = strftime(&a2[v5], v3, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT\r\n", v10);
if ( v11 < 0 || v3 <= v11 )
v5 = -1;
else
v5 += v11;
}
return (unsigned int)v5;
}

original_code:
static
int http_put_headercontent(struct response_t *self, char *data, int sz) {
    int len, i;
    len = 0;
    if (self->content_length >= 0) {
        i = snprintf(data, sz, "Content-Length: %ld\r\n",
                self->content_length);
        if (i < 0 || i >= sz) {
            return -1;
        }
        sz -= i;
        len += i;
    }
    if (self->content_type != ((void *)0)) {
        i = snprintf(data + len, sz, "Content-Type: %s\r\n",
                self->content_type);
        if (i < 0 || i >= sz) {
            return -1;
        }
        sz -= i;
        len += i;
    }
    if (self->last_mod >= 0) {
        i = strftime(data + len, sz, "Last-Modified: " "%a, %d %b %Y %H:%M:%S GMT" "\r\n",
                gmtime(&self->last_mod));
        if (i < 0 || i >= sz) {
            return -1;
        }
        sz -= i;
        len += i;
    }
    return len;
}

canonical_original_code:
static int http_put_headercontent(struct response_t *self, char *data, int sz) {
    int len; int i;
    len = 0;
    if (self->content_length >= 0) {
        i = snprintf(data, sz, "Content-Length: %ld\r\n",
                self->content_length);
        if (i < 0 || i >= sz) {
            return -1;
        }
        sz -= i;
        len += i;
    }
    if (self->content_type != ((void *)0)) {
        i = snprintf(data + len, sz, "Content-Type: %s\r\n",
                self->content_type);
        if (i < 0 || i >= sz) {
            return -1;
        }
        sz -= i;
        len += i;
    }
    if (self->last_mod >= 0) {
        i = strftime(data + len, sz, "Last-Modified: " "%a, %d %b %Y %H:%M:%S GMT" "\r\n",
                gmtime(&self->last_mod));
        if (i < 0 || i >= sz) {
            return -1;
        }
        sz -= i;
        len += i;
    }
    return len;
}

variable_types: len int


decompiled_code:
__int64 __fastcall http_parse(_QWORD *a1, const void *a2, unsigned int a3)
{
_BYTE *v4; // rax
_BYTE *v5; // rbx
signed int v6; // ebp
__int64 result; // rax
_BYTE *v8; // rax

v4 = http_parse_request(a1, a2, a3);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = v4;
v6 = a3 - ((_DWORD)v4 - (_DWORD)a2);
result = 0LL;
if ( v6 > 0 )
{
while ( *v5 != 10 )
{
if ( *v5 == 13 && v6 > 1 && v5[1] == 10 )
return 0LL;
v8 = http_parse_header((__int64)a1, v5, v6);
if ( !v8 )
return 0xFFFFFFFFLL;
v6 -= (_DWORD)v8 - (_DWORD)v5;
if ( v6 <= 0 )
return 0LL;
v5 = v8;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, const void *a2, unsigned int a3)
{
_BYTE *v4; // rax
_BYTE *v5; // rbx
signed int v6; // ebp
__int64 result; // rax
_BYTE *v8; // rax

v4 = http_parse_request(a1, a2, a3);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = v4;
v6 = a3 - ((_DWORD)v4 - (_DWORD)a2);
result = 0LL;
if ( v6 > 0 )
{
while ( *v5 != 10 )
{
if ( *v5 == 13 && v6 > 1 && v5[1] == 10 )
return 0LL;
v8 = http_parse_header((__int64)a1, v5, v6);
if ( !v8 )
return 0xFFFFFFFFLL;
v6 -= (_DWORD)v8 - (_DWORD)v5;
if ( v6 <= 0 )
return 0LL;
v5 = v8;
}
result = 0LL;
}
return result;
}

original_code:
int http_parse(struct request_t *self, char *data, int len) {
    char *p;
    p = http_parse_request(self, data, len);
    if (p == ((void *)0)) {
        return -1;
    }
    len -= p - data;
    data = p;
    while ((len > 0) && !((data[0] == '\n')
            || (len >= 2 && data[0] == '\r' && data[1] == '\n'))) {
        p = http_parse_header(self, data, len);
        if (p == ((void *)0)) {
            return -1;
        }
        len -= p - data;
        data = p;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall http_decode_url(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbp
__int64 result; // rax
unsigned __int8 *v3; // r12
unsigned __int8 *v4; // rdx
char v5; // di
char v6; // r13
char v7; // bl

v1 = a1;
result = *a1;
if ( (_BYTE)result )
{
v3 = a1 + 1;
do
{
if ( (_BYTE)result == 37 && (v5 = v1[1]) != 0 && (v6 = v1[2]) != 0 )
{
v7 = hex_to_int(v5);
LOBYTE(result) = 16 * v7 + hex_to_int(v6);
v4 = v3;
v1 += 2;
}
else
{
v4 = v3;
++v1;
}
*(v3 - 1) = result;
result = *v1;
++v3;
}
while ( (_BYTE)result );
}
else
{
v4 = a1;
}
*v4 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbp
__int64 result; // rax
unsigned __int8 *v3; // r12
unsigned __int8 *v4; // rdx
char v5; // di
char v6; // r13
char v7; // bl

v1 = a1;
result = *a1;
if ( (_BYTE)result )
{
v3 = a1 + 1;
do
{
if ( (_BYTE)result == 37 && (v5 = v1[1]) != 0 && (v6 = v1[2]) != 0 )
{
v7 = func0(v5);
LOBYTE(result) = 16 * v7 + func0(v6);
v4 = v3;
v1 += 2;
}
else
{
v4 = v3;
++v1;
}
*(v3 - 1) = result;
result = *v1;
++v3;
}
while ( (_BYTE)result );
}
else
{
v4 = a1;
}
*v4 = 0;
return result;
}

variable_types:
out
char *


decompiled_code:
__int64 __fastcall http_sanitize_url(unsigned __int8 *a1)
{
unsigned __int8 *i; // rcx
__int64 result; // rax

for ( i = a1; ; ++i )
{
result = *a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 47 )
{
if ( a1 != i )
*i = 47;
if ( a1[1] == 46 )
{
++a1;
do
++a1;
while ( *a1 == 46 );
}
else
{
++a1;
}
}
else
{
if ( a1 != i )
*i = result;
++a1;
}
}
if ( a1 != i )
*i = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1)
{
unsigned __int8 *i; // rcx
__int64 result; // rax

for ( i = a1; ; ++i )
{
result = *a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 47 )
{
if ( a1 != i )
*i = 47;
if ( a1[1] == 46 )
{
++a1;
do
++a1;
while ( *a1 == 46 );
}
else
{
++a1;
}
}
else
{
if ( a1 != i )
*i = result;
++a1;
}
}
if ( a1 != i )
*i = 0;
return result;
}

original_code:
void http_sanitize_url(char *url) {
    char *out;
    char c;
    out = url;
    for (;;) {
        c = *url;
        switch (c) {
        case '/':
            if (out != url) {
                *out = c;
            }
            ++out;
            ++url;
            while ('.' == *url) {
                ++url;
            }
            break;
        case '\0':
            if (out != url) {
                *out = c;
            }
            return;
        default:
            if (out != url) {
                *out = c;
            }
            ++out;
            ++url;
            break;
        }
    }
}


decompiled_code:
__int64 __fastcall http_get_realpath(const char *a1, char *a2)
{
int v2; // eax
int v3; // ebx

v2 = snprintf(a2, 0x200uLL, "%s%s", g_config, a1);
v3 = 511;
if ( v2 <= 511 )
v3 = v2;
if ( a2[v3 - 1] == 47 )
{
snprintf(&a2[v3], 512 - v3, "%s", "index.html");
v3 += 10;
if ( v3 > 511 )
v3 = 511;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, char *a2)
{
int v2; // eax
int v3; // ebx

v2 = snprintf(a2, 0x200uLL, "%s%s", g_config, a1);
v3 = 511;
if ( v2 <= 511 )
v3 = v2;
if ( a2[v3 - 1] == 47 )
{
snprintf(&a2[v3], 512 - v3, "%s", "index.html");
v3 += 10;
if ( v3 > 511 )
v3 = 511;
}
return (unsigned int)v3;
}

original_code:
int http_get_realpath(const char *url, char *path) {
    int len;
    len = snprintf(path, 512, "%s%s", g_config.root, url);
    if (len >= 512) {
        len = 512 - 1;
    }
    if (path[len - 1] == '/') {
        len += snprintf(path + len, 512 - len, "%s", "index.html");
        if (len >= 512) {
            len = 512 - 1;
        }
    }
    return len;
}

canonical_original_code:
int http_get_realpath(char *url, char *path) {
    int len;
    len = snprintf(path, 512, "%s%s", g_config.root, url);
    if (len >= 512) {
        len = 512 - 1;
    }
    if (path[len - 1] == '/') {
        len += snprintf(path + len, 512 - len, "%s", "index.html");
        if (len >= 512) {
            len = 512 - 1;
        }
    }
    return len;
}

variable_types:
path
char *