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

*a1 = 0LL;
++_gcov0_e3_hsm_create;
result = enter(a1, a2);
++qword_408;
return result;
}

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

*a1 = 0LL;
++_gcov0_e3_hsm_create;
result = func0(a1, a2);
++qword_408;
return result;
}

original_code:
void
e3_hsm_create(e3_hsm_t *hsm, const e3_hsm_state_t * const state) {
    hsm->state = 0;
    enter(hsm, state);
}

canonical_original_code:
void e3_hsm_create(struct e3_hsm *hsm, struct e3_hsm_state *state) {
    hsm->state = 0;
    enter(hsm, state);
}

user_defined_types: struct e3_hsm_state { struct e3_hsm_state *parent; unsigned long ancestry; struct e3_hsm_state *(*transition)(unsigned long signal); void (*enter)(void *cookie); void (*exit)(void *cookie); }


callback

decompiled_code:
void __fastcall callback(int a1, __int64 a2)
{
*(_DWORD *)(a2 + 72) += a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1, __int64 a2)
{
*(_DWORD *)(a2 + 72) += a1;
}

original_code:
static void
callback(void *cookie, void *args) {
    int amount = (int) cookie;
    test_t *test = (test_t *) args;
    test->count += amount;
}

canonical_original_code:
static void callback(void *cookie, void *args) {
    int amount = (int) cookie;
    struct test *test = (test_t *) args;
    test->count += amount;
}

variable_types:
cookie
void *

variable_types:
args
void *

variable_types: amount int

variable_types: struct test { struct e3_event { struct e3_event_listener { struct e3_event_listener *next; struct e3_event *event; void (*function)(void *hint, void *args); void *cookie; } *listeners; } e; struct e3_event_listener a; struct e3_event_listener b; int count; } *

return_type: void

user_defined_types: struct test { struct e3_event e; struct e3_event_listener a; struct e3_event_listener b; int count; }

user_defined_types: struct e3_event { struct e3_event_listener *listeners; }


original_code:
void
e3_event_test(jasmine_t *jasmine) {
    test_t test;
    for ((jasmine)->state = 0, (jasmine)->current = 0, (jasmine)->last = 0, puts("an event"); (3 == (jasmine)->state) ? (puts(""), 0) : 1; ) {
        for (; 0 == (jasmine)->state; (jasmine)->state = 1) {
            e3_event_create(&test.e);
            test.count = 0;
        }
        for (; 2 == (jasmine)->state; (jasmine)->state = ((jasmine)->current == (jasmine)->last) ? 3 : 0) {
            e3_event_delete(&test.e);
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 55 ? 55 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 55 && (55 == ((jasmine)->current = 55)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can have no listeners"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can have no listeners"), 1) : ((jasmine)->failed++, printf(" ✗ " "can have no listeners" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_fire(&test.e, 0);
            if (!(test.count == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 60 ? 60 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 60 && (60 == ((jasmine)->current = 60)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can have a single listener"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can have a single listener"), 1) : ((jasmine)->failed++, printf(" ✗ " "can have a single listener" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, callback, (void *) 1);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 66 ? 66 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 66 && (66 == ((jasmine)->current = 66)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can have multiple listeners"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can have multiple listeners"), 1) : ((jasmine)->failed++, printf(" ✗ " "can have multiple listeners" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, callback, (void *) 1);
            e3_event_listener_create(&test.b, &test.e, callback, (void *) 2);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 73 ? 73 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 73 && (73 == ((jasmine)->current = 73)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "will ignore invalid listeners"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "will ignore invalid listeners"), 1) : ((jasmine)->failed++, printf(" ✗ " "will ignore invalid listeners" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, 0, 0);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 79 ? 79 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 79 && (79 == ((jasmine)->current = 79)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can fire multiple times"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can fire multiple times"), 1) : ((jasmine)->failed++, printf(" ✗ " "can fire multiple times" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, callback, (void *) 1);
            e3_event_listener_create(&test.b, &test.e, callback, (void *) 2);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_event_fire(&test.e, &test);
            if (!(test.count == 6)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 6"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 88 ? 88 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 88 && (88 == ((jasmine)->current = 88)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can delete a listener"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can delete a listener"), 1) : ((jasmine)->failed++, printf(" ✗ " "can delete a listener" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, callback, (void *) 1);
            e3_event_listener_create(&test.b, &test.e, callback, (void *) 2);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_event_listener_delete(&test.b);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 4)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 4"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 98 ? 98 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 98 && (98 == ((jasmine)->current = 98)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "cannot fire once deleted"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "cannot fire once deleted"), 1) : ((jasmine)->failed++, printf(" ✗ " "cannot fire once deleted" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, callback, (void *) 1);
            e3_event_listener_create(&test.b, &test.e, callback, (void *) 2);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_event_delete(&test.e);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
    }
}

canonical_original_code:
void e3_event_test(struct jasmine *jasmine) {
    struct test test;
    for ((jasmine)->state = 0, (jasmine)->current = 0, (jasmine)->last = 0, puts("an event"); (3 == (jasmine)->state) ? (puts(""), 0) : 1; ) {
        for (; 0 == (jasmine)->state; (jasmine)->state = 1) {
            e3_event_create(&test.e);
            test.count = 0;
        }
        for (; 2 == (jasmine)->state; (jasmine)->state = ((jasmine)->current == (jasmine)->last) ? 3 : 0) {
            e3_event_delete(&test.e);
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 55 ? 55 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 55 && (55 == ((jasmine)->current = 55)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can have no listeners"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can have no listeners"), 1) : ((jasmine)->failed++, printf(" ✗ " "can have no listeners" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_fire(&test.e, 0);
            if (!(test.count == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 60 ? 60 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 60 && (60 == ((jasmine)->current = 60)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can have a single listener"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can have a single listener"), 1) : ((jasmine)->failed++, printf(" ✗ " "can have a single listener" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, callback, (void *) 1);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 66 ? 66 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 66 && (66 == ((jasmine)->current = 66)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can have multiple listeners"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can have multiple listeners"), 1) : ((jasmine)->failed++, printf(" ✗ " "can have multiple listeners" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, callback, (void *) 1);
            e3_event_listener_create(&test.b, &test.e, callback, (void *) 2);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 73 ? 73 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 73 && (73 == ((jasmine)->current = 73)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "will ignore invalid listeners"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "will ignore invalid listeners"), 1) : ((jasmine)->failed++, printf(" ✗ " "will ignore invalid listeners" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, 0, 0);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 79 ? 79 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 79 && (79 == ((jasmine)->current = 79)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can fire multiple times"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can fire multiple times"), 1) : ((jasmine)->failed++, printf(" ✗ " "can fire multiple times" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, callback, (void *) 1);
            e3_event_listener_create(&test.b, &test.e, callback, (void *) 2);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_event_fire(&test.e, &test);
            if (!(test.count == 6)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 6"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 88 ? 88 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 88 && (88 == ((jasmine)->current = 88)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can delete a listener"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can delete a listener"), 1) : ((jasmine)->failed++, printf(" ✗ " "can delete a listener" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, callback, (void *) 1);
            e3_event_listener_create(&test.b, &test.e, callback, (void *) 2);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_event_listener_delete(&test.b);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 4)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 4"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 98 ? 98 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 98 && (98 == ((jasmine)->current = 98)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "cannot fire once deleted"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "cannot fire once deleted"), 1) : ((jasmine)->failed++, printf(" ✗ " "cannot fire once deleted" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_event_listener_create(&test.a, &test.e, callback, (void *) 1);
            e3_event_listener_create(&test.b, &test.e, callback, (void *) 2);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_event_delete(&test.e);
            e3_event_fire(&test.e, &test);
            if (!(test.count == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.count == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
    }
}

variable_types: struct jasmine { char *reason; unsigned short state; unsigned short group; unsigned short current; unsigned short last; unsigned short passed; unsigned short failed; unsigned short ignored; unsigned short expects; } *

variable_types: struct test { struct e3_event { struct e3_event_listener { struct e3_event_listener *next; struct e3_event *event; void (*function)(void *hint, void *args); void *cookie; } *listeners; } e; struct e3_event_listener a; struct e3_event_listener b; int count; }


decompiled_code:
void __fastcall e3_event_fire(_QWORD **a1, __int64 a2)
{
_QWORD *v2; // rbx
_QWORD *v3; // rdx
void (__fastcall *v4)(_QWORD, __int64); // rax

v2 = *a1;
++_gcov0_e3_event_fire;
for ( ; v2; ++qword_370 )
{
while ( 1 )
{
v3 = v2;
v2 = (_QWORD *)*v2;
v4 = (void (__fastcall *)(_QWORD, __int64))v3[2];
if ( !v4 )
break;
++qword_368;
v4(v3[3], a2);
if ( !v2 )
goto LABEL_6;
}
}
LABEL_6:
++qword_378;
}

canonical_decompiled_code:
void __fastcall func2(_QWORD **a1, __int64 a2)
{
_QWORD *v2; // rbx
_QWORD *v3; // rdx
void (__fastcall *v4)(_QWORD, __int64); // rax

v2 = *a1;
++_gcov0_e3_event_fire;
for ( ; v2; ++qword_370 )
{
while ( 1 )
{
v3 = v2;
v2 = (_QWORD *)*v2;
v4 = (void (__fastcall *)(_QWORD, __int64))v3[2];
if ( !v4 )
break;
++qword_368;
v4(v3[3], a2);
if ( !v2 )
goto LABEL_6;
}
}
LABEL_6:
++qword_378;
}

original_code:
void
e3_event_fire(e3_event_t *event, void *args) {
    e3_event_listener_t *current;
    e3_event_listener_t *next;
    current = event->listeners;
    while (current) {
        next = current->next;
        if (current->function) {
            current->function(current->cookie, args);
        }
        current = next;
    }
}

canonical_original_code:
void e3_event_fire(struct e3_event *event, void *args) {
    struct e3_event_listener *current;
    struct e3_event_listener *next;
    current = event->listeners;
    while (current) {
        next = current->next;
        if (current->function) {
            current->function(current->cookie, args);
        }
        current = next;
    }
}

variable_types: struct e3_event { struct e3_event_listener { struct e3_event_listener *next; struct e3_event *event; void (*function)(void *hint, void *args); void *cookie; } *listeners; } *

variable_types: struct e3_event_listener { struct e3_event_listener *next; struct e3_event { struct e3_event_listener *listeners; } *event; void (*function)(void *hint, void *args); void *cookie; } *


repo: bamboolll/goitout

decompiled_code:
__int64 hash_rand()
{
__int64 v0; // rbx

v0 = (unsigned int)gg_urand();
return v0 | (gg_urand() << 32);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx

v0 = (unsigned int)gg_urand();
return v0 | (gg_urand() << 32);
}

original_code:
static Hashvalue
hash_rand(void)
{
  int i;
  Hashvalue h = 0;
  for (i = 0; 32*i < (int) (8*sizeof(Hashvalue)); i++)
    h |= (Hashvalue) gg_urand() << 32*i;
  return h;
}

canonical_original_code:
static unsigned long hash_rand()
{
  int i;
  unsigned long h = 0;
  for (i = 0; 32*i < (int) (8*sizeof(Hashvalue)); i++)
    h |= (unsigned long) gg_urand() << 32*i;
  return h;
}

variable_types: i int

variable_types:
h
unsigned long

return_type: unsigned long


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

if ( a2 > 0 )
{
v2 = a1;
do
{
v2 += 16LL;
*(_QWORD *)(v2 - 16) = hash_rand();
*(_QWORD *)(v2 - 8) = hash_rand();
}
while ( v2 != a1 + 16LL * (unsigned int)(a2 - 1) + 16 );
}
}

original_code:
void
hash_init_zobrist_array(Hash_data *array, int size)
{
  int i, j;
  for (i = 0; i < size; i++)
    for (j = 0; j < (1 + (64 - 1) / (8 * 4)); j++)
      array[i].hashval[j] = hash_rand();
}

canonical_original_code:
void hash_init_zobrist_array(struct Hash_data *array, int size)
{
  int i; int j;
  for (i = 0; i < size; i++)
    for (j = 0; j < (1 + (64 - 1) / (8 * 4)); j++)
      array[i].hashval[j] = hash_rand();
}

variable_types: struct Hash_data { unsigned long hashval[-1]; } *

variable_types: size int

variable_types: j int


decompiled_code:
void hash_init()
{
if ( !is_initialized_1 )
{
hash_init_zobrist_array((__int64)&black_hash, 400);
hash_init_zobrist_array((__int64)&white_hash, 400);
hash_init_zobrist_array((__int64)&ko_hash, 400);
hash_init_zobrist_array((__int64)&komaster_hash, 7);
hash_init_zobrist_array((__int64)&kom_pos_hash, 400);
hash_init_zobrist_array((__int64)&goal_hash, 400);
is_initialized_1 = 1;
}
}

canonical_decompiled_code:
void func2()
{
if ( !is_initialized_1 )
{
func1((__int64)&black_hash, 400);
func1((__int64)&white_hash, 400);
func1((__int64)&ko_hash, 400);
func1((__int64)&komaster_hash, 7);
func1((__int64)&kom_pos_hash, 400);
func1((__int64)&goal_hash, 400);
is_initialized_1 = 1;
}
}

original_code:
void
hash_init(void)
{
  static int is_initialized = 0;
  if (is_initialized)
    return;
  hash_init_zobrist_array(black_hash, (int) (sizeof(black_hash) / sizeof(black_hash[0])));
  hash_init_zobrist_array(white_hash, (int) (sizeof(white_hash) / sizeof(white_hash[0])));
  hash_init_zobrist_array(ko_hash, (int) (sizeof(ko_hash) / sizeof(ko_hash[0])));
  hash_init_zobrist_array(komaster_hash, (int) (sizeof(komaster_hash) / sizeof(komaster_hash[0])));
  hash_init_zobrist_array(kom_pos_hash, (int) (sizeof(kom_pos_hash) / sizeof(kom_pos_hash[0])));
  hash_init_zobrist_array(goal_hash, (int) (sizeof(goal_hash) / sizeof(goal_hash[0])));
  is_initialized = 1;
}

canonical_original_code:
void hash_init()
{
  static int is_initialized = 0;
  if (is_initialized)
    return;
  hash_init_zobrist_array(black_hash, (int) (sizeof(black_hash) / sizeof(black_hash[0])));
  hash_init_zobrist_array(white_hash, (int) (sizeof(white_hash) / sizeof(white_hash[0])));
  hash_init_zobrist_array(ko_hash, (int) (sizeof(ko_hash) / sizeof(ko_hash[0])));
  hash_init_zobrist_array(komaster_hash, (int) (sizeof(komaster_hash) / sizeof(komaster_hash[0])));
  hash_init_zobrist_array(kom_pos_hash, (int) (sizeof(kom_pos_hash) / sizeof(kom_pos_hash[0])));
  hash_init_zobrist_array(goal_hash, (int) (sizeof(goal_hash) / sizeof(goal_hash[0])));
  is_initialized = 1;
}


decompiled_code:
void __fastcall hashdata_clear(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

original_code:
void
hashdata_clear(Hash_data *hd)
{
  int i;
  for (i = 0; i < (1 + (64 - 1) / (8 * 4)); i++)
    hd->hashval[i] = 0;
}

canonical_original_code:
void hashdata_clear(struct Hash_data *hd)
{
  int i;
  for (i = 0; i < (1 + (64 - 1) / (8 * 4)); i++)
    hd->hashval[i] = 0;
}

user_defined_types: struct Hash_data { unsigned long hashval[-1]; }


decompiled_code:
__int64 __fastcall hashdata_recalc(_QWORD *a1, __int64 a2)
{
int v2; // edx
__int64 v3; // r8
__int64 result; // rax
_BYTE *v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8

hashdata_clear(a1);
v3 = v2;
result = 336LL;
v5 = (_BYTE *)(a2 + 21);
do
{
while ( *v5 == 1 )
{
v6 = *(__int64 *)((char *)&white_hash + result);
result += 16LL;
*a1 ^= v6;
++v5;
a1[1] ^= *(__int64 *)((char *)&qword_6918 + result);
if ( result == 6400 )
goto LABEL_7;
}
if ( *v5 == 2 )
{
*a1 ^= *(__int64 *)((char *)&black_hash + result);
a1[1] ^= *(__int64 *)((char *)&qword_5028 + result);
}
result += 16LL;
++v5;
}
while ( result != 6400 );
LABEL_7:
if ( (_DWORD)v3 )
{
v7 = 2 * v3;
*a1 ^= ko_hash[v7];
result = qword_3728[v7];
a1[1] ^= result;
}
return result;
}

original_code:
void
hashdata_recalc(Hash_data *hd, Intersection *p, int ko_pos)
{
  int pos;
  hashdata_clear(hd);
  for (pos = (19 + 2); pos < (19 + 1) * (19 + 1); pos++) {
    if (p[pos] == WHITE)
      do { (*hd).hashval[0] ^= (white_hash[pos]).hashval[0]; (*hd).hashval[1] ^= (white_hash[pos]).hashval[1]; } while (0);
    else if (p[pos] == BLACK)
      do { (*hd).hashval[0] ^= (black_hash[pos]).hashval[0]; (*hd).hashval[1] ^= (black_hash[pos]).hashval[1]; } while (0);
  }
  if (ko_pos != 0)
    do { (*hd).hashval[0] ^= (ko_hash[ko_pos]).hashval[0]; (*hd).hashval[1] ^= (ko_hash[ko_pos]).hashval[1]; } while (0);
}

canonical_original_code:
void hashdata_recalc(struct Hash_data *hd, unsigned char *p, int ko_pos)
{
  int pos;
  hashdata_clear(hd);
  for (pos = (19 + 2); pos < (19 + 1) * (19 + 1); pos++) {
    if (p[pos] == WHITE)
      do { (*hd).hashval[0] ^= (white_hash[pos]).hashval[0]; (*hd).hashval[1] ^= (white_hash[pos]).hashval[1]; } while (0);
    else if (p[pos] == BLACK)
      do { (*hd).hashval[0] ^= (black_hash[pos]).hashval[0]; (*hd).hashval[1] ^= (black_hash[pos]).hashval[1]; } while (0);
  }
  if (ko_pos != 0)
    do { (*hd).hashval[0] ^= (ko_hash[ko_pos]).hashval[0]; (*hd).hashval[1] ^= (ko_hash[ko_pos]).hashval[1]; } while (0);
}

variable_types:
p
unsigned char *

variable_types: pos int


decompiled_code:
unsigned __int64 __fastcall hashdata_calc_orientation_invariant(unsigned __int64 *a1, __int64 a2, unsigned int a3)
{
unsigned int i; // ebp
__int64 v6; // rbx
int v7; // eax
__int64 v8; // rdi
unsigned __int64 result; // rax
__m128i v10; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0; i != 8; ++i )
{
v6 = 21LL;
hashdata_clear(&v10);
do
{
while ( 1 )
{
result = *(unsigned __int8 *)(a2 + v6);
if ( (_BYTE)result != 1 )
break;
v7 = rotate1((unsigned int)v6, i);
v8 = (unsigned int)v6++;
v10.m128i_i64[0] ^= white_hash[2 * v7];
result = qword_6928[2 * (int)rotate1(v8, i)];
v10.m128i_i64[1] ^= result;
if ( v6 == 400 )
goto LABEL_8;
}
if ( (_BYTE)result == 2 )
{
v10.m128i_i64[0] ^= black_hash[2 * (int)rotate1((unsigned int)v6, i)];
result = qword_5028[2 * (int)rotate1((unsigned int)v6, i)];
v10.m128i_i64[1] ^= result;
}
++v6;
}
while ( v6 != 400 );
LABEL_8:
if ( a3 )
{
v10.m128i_i64[0] ^= ko_hash[2 * (int)rotate1(a3, i)];
result = qword_3728[2 * (int)rotate1(a3, i)];
v10.m128i_i64[1] ^= result;
}
if ( i )
{
result = *a1;
if ( v10.m128i_i64[0] >= *a1 )
{
if ( v10.m128i_i64[0] != *a1 )
continue;
result = a1[1];
if ( v10.m128i_i64[1] >= result )
continue;
}
}
*(__m128i *)a1 = _mm_loadu_si128(&v10);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(unsigned __int64 *a1, __int64 a2, unsigned int a3)
{
unsigned int i; // ebp
__int64 v6; // rbx
int v7; // eax
__int64 v8; // rdi
unsigned __int64 result; // rax
__m128i v10; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0; i != 8; ++i )
{
v6 = 21LL;
func3(&v10);
do
{
while ( 1 )
{
result = *(unsigned __int8 *)(a2 + v6);
if ( (_BYTE)result != 1 )
break;
v7 = rotate1((unsigned int)v6, i);
v8 = (unsigned int)v6++;
v10.m128i_i64[0] ^= white_hash[2 * v7];
result = qword_6928[2 * (int)rotate1(v8, i)];
v10.m128i_i64[1] ^= result;
if ( v6 == 400 )
goto LABEL_8;
}
if ( (_BYTE)result == 2 )
{
v10.m128i_i64[0] ^= black_hash[2 * (int)rotate1((unsigned int)v6, i)];
result = qword_5028[2 * (int)rotate1((unsigned int)v6, i)];
v10.m128i_i64[1] ^= result;
}
++v6;
}
while ( v6 != 400 );
LABEL_8:
if ( a3 )
{
v10.m128i_i64[0] ^= ko_hash[2 * (int)rotate1(a3, i)];
result = qword_3728[2 * (int)rotate1(a3, i)];
v10.m128i_i64[1] ^= result;
}
if ( i )
{
result = *a1;
if ( v10.m128i_i64[0] >= *a1 )
{
if ( v10.m128i_i64[0] != *a1 )
continue;
result = a1[1];
if ( v10.m128i_i64[1] >= result )
continue;
}
}
*(__m128i *)a1 = _mm_loadu_si128(&v10);
}
return result;
}

original_code:
void
hashdata_calc_orientation_invariant(Hash_data *hd, Intersection *p, int ko_pos)
{
  int pos;
  int rot;
  Hash_data hd_rot;
  for (rot = 0; rot < 8; rot++) {
    hashdata_clear(&hd_rot);
    for (pos = (19 + 2); pos < (19 + 1) * (19 + 1); pos++) {
      if (p[pos] == WHITE)
 do { (hd_rot).hashval[0] ^= (white_hash[rotate1(pos, rot)]).hashval[0]; (hd_rot).hashval[1] ^= (white_hash[rotate1(pos, rot)]).hashval[1]; } while (0);
      else if (p[pos] == BLACK)
 do { (hd_rot).hashval[0] ^= (black_hash[rotate1(pos, rot)]).hashval[0]; (hd_rot).hashval[1] ^= (black_hash[rotate1(pos, rot)]).hashval[1]; } while (0);
    }
    if (ko_pos != 0)
      do { (hd_rot).hashval[0] ^= (ko_hash[rotate1(ko_pos, rot)]).hashval[0]; (hd_rot).hashval[1] ^= (ko_hash[rotate1(ko_pos, rot)]).hashval[1]; } while (0);
    if (rot == 0 || ((hd_rot).hashval[0] < (*hd).hashval[0] || ((hd_rot).hashval[0] == (*hd).hashval[0] && (hd_rot).hashval[1] < (*hd).hashval[1])))
      *hd = hd_rot;
  }
}

canonical_original_code:
void hashdata_calc_orientation_invariant(struct Hash_data *hd, unsigned char *p, int ko_pos)
{
  int pos;
  int rot;
  struct Hash_data hd_rot;
  for (rot = 0; rot < 8; rot++) {
    hashdata_clear(&hd_rot);
    for (pos = (19 + 2); pos < (19 + 1) * (19 + 1); pos++) {
      if (p[pos] == WHITE)
 do { (hd_rot).hashval[0] ^= (white_hash[rotate1(pos, rot)]).hashval[0]; (hd_rot).hashval[1] ^= (white_hash[rotate1(pos, rot)]).hashval[1]; } while (0);
      else if (p[pos] == BLACK)
 do { (hd_rot).hashval[0] ^= (black_hash[rotate1(pos, rot)]).hashval[0]; (hd_rot).hashval[1] ^= (black_hash[rotate1(pos, rot)]).hashval[1]; } while (0);
    }
    if (ko_pos != 0)
      do { (hd_rot).hashval[0] ^= (ko_hash[rotate1(ko_pos, rot)]).hashval[0]; (hd_rot).hashval[1] ^= (ko_hash[rotate1(ko_pos, rot)]).hashval[1]; } while (0);
    if (rot == 0 || ((hd_rot).hashval[0] < (*hd).hashval[0] || ((hd_rot).hashval[0] == (*hd).hashval[0] && (hd_rot).hashval[1] < (*hd).hashval[1])))
      *hd = hd_rot;
  }
}

variable_types: rot int

variable_types: struct Hash_data { unsigned long hashval[-1]; }


original_code:
Hash_data
goal_to_hashvalue(const signed char *goal)
{
  int pos;
  Hash_data return_value;
  hashdata_clear(&return_value);
  for (pos = (19 + 2); pos < (19 + 1) * (19 + 1); pos++)
    if ((board[pos] != GRAY) && goal[pos])
      do { (return_value).hashval[0] ^= (goal_hash[pos]).hashval[0]; (return_value).hashval[1] ^= (goal_hash[pos]).hashval[1]; } while (0);
  return return_value;
}

canonical_original_code:
struct Hash_data goal_to_hashvalue(char *goal)
{
  int pos;
  struct Hash_data return_value;
  hashdata_clear(&return_value);
  for (pos = (19 + 2); pos < (19 + 1) * (19 + 1); pos++)
    if ((board[pos] != GRAY) && goal[pos])
      do { (return_value).hashval[0] ^= (goal_hash[pos]).hashval[0]; (return_value).hashval[1] ^= (goal_hash[pos]).hashval[1]; } while (0);
  return return_value;
}

variable_types:
goal
char *

return_type: struct Hash_data { unsigned long hashval[-1]; }


variable_types:
buffer
char [-1]

variable_types: n int

variable_types: k int

return_type: char *


decompiled_code:
void __fastcall sgffile_enddump(_BYTE *a1)
{
if ( a1 && *a1 && sgf_dumptree )
{
if ( (unsigned int)writesgf(*sgf_dumptree, a1) )
{
sgfFreeNode(*sgf_dumptree);
sgf_dumptree = 0LL;
}
}
}

canonical_decompiled_code:
void __fastcall func0(_BYTE *a1)
{
if ( a1 && *a1 && sgf_dumptree )
{
if ( (unsigned int)writesgf(*sgf_dumptree, a1) )
{
sgfFreeNode(*sgf_dumptree);
sgf_dumptree = 0LL;
}
}
}

original_code:
void
sgffile_enddump(const char *filename)
{
  if (filename && *filename && sgf_dumptree) {
    if (writesgf(sgf_dumptree->root, filename)) {
      sgfFreeNode(sgf_dumptree->root);
      sgf_dumptree = ((void *)0);
    }
  }
}

canonical_original_code:
void sgffile_enddump(char *filename)
{
  if (filename && *filename && sgf_dumptree) {
    if (writesgf(sgf_dumptree->root, filename)) {
      sgfFreeNode(sgf_dumptree->root);
      sgf_dumptree = ((void *)0);
    }
  }
}

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall sgffile_printboard(__int64 a1)
{
__int64 v1; // r14
int v2; // er15
int v3; // er13
__int64 v4; // rbx
int v5; // eax
int v6; // er13
int i; // er15
__int64 v8; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 8);
v2 = 0;
v3 = 21;
if ( board_size > 0 )
{
do
{
v4 = 0LL;
do
{
while ( *((_BYTE *)&board + v3 + v4) != 1 )
{
v5 = board_size;
if ( board_size <= (int)++v4 )
goto LABEL_7;
}
sgfAddStone(v1, 1LL, (unsigned int)v2, (unsigned int)v4);
v5 = board_size;
++v4;
}
while ( board_size > (int)v4 );
LABEL_7:
++v2;
v3 += 20;
}
while ( v5 > v2 );
if ( v5 > 0 )
{
v6 = 21;
for ( i = 0; i < v5; ++i )
{
v8 = 0LL;
do
{
while ( *((_BYTE *)&board + v6 + v8) != 2 )
{
if ( v5 <= (int)++v8 )
goto LABEL_14;
}
sgfAddStone(v1, 2LL, (unsigned int)i, (unsigned int)v8);
v5 = board_size;
++v8;
}
while ( board_size > (int)v8 );
LABEL_14:
v6 += 20;
}
}
}
result = sgftreeSetLastNode(a1, v1);
}
else
{
abortgo("msgffile.c", 201LL, "tree", 0LL);
result = sgffile_begindump();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r14
int v2; // er15
int v3; // er13
__int64 v4; // rbx
int v5; // eax
int v6; // er13
int i; // er15
__int64 v8; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 8);
v2 = 0;
v3 = 21;
if ( board_size > 0 )
{
do
{
v4 = 0LL;
do
{
while ( *((_BYTE *)&board + v3 + v4) != 1 )
{
v5 = board_size;
if ( board_size <= (int)++v4 )
goto LABEL_7;
}
sgfAddStone(v1, 1LL, (unsigned int)v2, (unsigned int)v4);
v5 = board_size;
++v4;
}
while ( board_size > (int)v4 );
LABEL_7:
++v2;
v3 += 20;
}
while ( v5 > v2 );
if ( v5 > 0 )
{
v6 = 21;
for ( i = 0; i < v5; ++i )
{
v8 = 0LL;
do
{
while ( *((_BYTE *)&board + v6 + v8) != 2 )
{
if ( v5 <= (int)++v8 )
goto LABEL_14;
}
sgfAddStone(v1, 2LL, (unsigned int)i, (unsigned int)v8);
v5 = board_size;
++v8;
}
while ( board_size > (int)v8 );
LABEL_14:
v6 += 20;
}
}
}
result = sgftreeSetLastNode(a1, v1);
}
else
{
abortgo("msgffile.c", 201LL, "tree", 0LL);
result = func2();
}
return result;
}

original_code:
void
sgffile_printboard(SGFTree *tree)
{
  int i, j;
  SGFNode *node;
  if (tree) ; else abortgo("msgffile.c", 201, "tree", 0);
  node = tree->lastnode;
  for (i = 0; i < board_size; i++) {
    for (j = 0; j < board_size; j++) {
      if (board[((19 + 2) + (i) * (19 + 1) + (j))] == WHITE)
 sgfAddStone(node, WHITE, i, j);
    }
  }
  for (i = 0; i < board_size; i++) {
    for (j = 0; j < board_size; j++) {
      if (board[((19 + 2) + (i) * (19 + 1) + (j))] == BLACK)
 sgfAddStone(node, BLACK, i, j);
    }
  }
  sgftreeSetLastNode(tree, node);
}

canonical_original_code:
void sgffile_printboard(struct SGFTree_t *tree)
{
  int i; int j;
  struct SGFNode_t *node;
  if (tree) ; else abortgo("msgffile.c", 201, "tree", 0);
  node = tree->lastnode;
  for (i = 0; i < board_size; i++) {
    for (j = 0; j < board_size; j++) {
      if (board[((19 + 2) + (i) * (19 + 1) + (j))] == WHITE)
 sgfAddStone(node, WHITE, i, j);
    }
  }
  for (i = 0; i < board_size; i++) {
    for (j = 0; j < board_size; j++) {
      if (board[((19 + 2) + (i) * (19 + 1) + (j))] == BLACK)
 sgfAddStone(node, BLACK, i, j);
    }
  }
  sgftreeSetLastNode(tree, node);
}

variable_types: struct SGFTree_t { struct SGFNode_t { struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; } *root; struct SGFNode_t *lastnode; } *

user_defined_types: struct SGFTree_t { struct SGFNode_t *root; struct SGFNode_t *lastnode; }

user_defined_types: struct SGFNode_t { struct SGFProperty_t *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; }


decompiled_code:
__int64 __fastcall sgffile_begindump(void *a1)
{
__int64 result; // rax

if ( sgf_dumptree )
{
abortgo("msgffile.c", 116LL, "sgf_dumptree == ((void *)0)", 0LL);
result = sgffile_recordboard();
}
else
{
if ( !a1 )
a1 = &local_tree_0;
sgf_dumptree = a1;
sgftree_clear();
sgftreeCreateHeaderNode(sgf_dumptree, board_size, handicap, komi);
result = sgffile_printboard(sgf_dumptree);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *a1)
{
__int64 result; // rax

if ( sgf_dumptree )
{
abortgo("msgffile.c", 116LL, "sgf_dumptree == ((void *)0)", 0LL);
result = func3();
}
else
{
if ( !a1 )
a1 = &local_tree_0;
sgf_dumptree = a1;
sgftree_clear();
sgftreeCreateHeaderNode(sgf_dumptree, board_size, handicap, komi);
result = func1(sgf_dumptree);
}
return result;
}

original_code:
void
sgffile_begindump(SGFTree *tree)
{
  static SGFTree local_tree;
  if (sgf_dumptree == ((void *)0)) ; else abortgo("msgffile.c", 116, "sgf_dumptree == ((void *)0)", 0);
  if (tree == ((void *)0))
    sgf_dumptree = &local_tree;
  else
    sgf_dumptree = tree;
  sgftree_clear(sgf_dumptree);
  sgftreeCreateHeaderNode(sgf_dumptree, board_size, komi, handicap);
  sgffile_printboard(sgf_dumptree);
}

canonical_original_code:
void sgffile_begindump(struct SGFTree_t *tree)
{
  static struct SGFTree_t local_tree;
  if (sgf_dumptree == ((void *)0)) ; else abortgo("msgffile.c", 116, "sgf_dumptree == ((void *)0)", 0);
  if (tree == ((void *)0))
    sgf_dumptree = &local_tree;
  else
    sgf_dumptree = tree;
  sgftree_clear(sgf_dumptree);
  sgftreeCreateHeaderNode(sgf_dumptree, board_size, komi, handicap);
  sgffile_printboard(sgf_dumptree);
}

variable_types: struct SGFTree_t { struct SGFNode_t { struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; } *root; struct SGFNode_t *lastnode; }


decompiled_code:
void __fastcall sgffile_recordboard(__int64 a1)
{
unsigned int v1; // er14
int v2; // er12
__int64 v3; // rbx
int v4; // eax

if ( a1 )
{
v1 = 0;
v2 = 21;
if ( board_size > 0 )
{
do
{
v3 = 0LL;
do
{
while ( *((_BYTE *)&board + v2 + v3) != 2 )
{
v4 = board_size;
if ( board_size <= (int)++v3 )
goto LABEL_7;
}
sgfAddStone(a1, 2LL, v1, (unsigned int)v3);
v4 = board_size;
++v3;
}
while ( board_size > (int)v3 );
LABEL_7:
++v1;
v2 += 20;
}
while ( v4 > (int)v1 );
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
unsigned int v1; // er14
int v2; // er12
__int64 v3; // rbx
int v4; // eax

if ( a1 )
{
v1 = 0;
v2 = 21;
if ( board_size > 0 )
{
do
{
v3 = 0LL;
do
{
while ( *((_BYTE *)&board + v2 + v3) != 2 )
{
v4 = board_size;
if ( board_size <= (int)++v3 )
goto LABEL_7;
}
sgfAddStone(a1, 2LL, v1, (unsigned int)v3);
v4 = board_size;
++v3;
}
while ( board_size > (int)v3 );
LABEL_7:
++v1;
v2 += 20;
}
while ( v4 > (int)v1 );
}
}
}

original_code:
void
sgffile_recordboard(SGFNode *node)
{
  int i, j;
  if (node)
    for (i = 0; i < board_size; i++)
      for (j = 0; j < board_size; j++)
        if (board[((19 + 2) + (i) * (19 + 1) + (j))] == BLACK)
          sgfAddStone(node, BLACK, i, j);
}

canonical_original_code:
void sgffile_recordboard(struct SGFNode_t *node)
{
  int i; int j;
  if (node)
    for (i = 0; i < board_size; i++)
      for (j = 0; j < board_size; j++)
        if (board[((19 + 2) + (i) * (19 + 1) + (j))] == BLACK)
          sgfAddStone(node, BLACK, i, j);
}

variable_types: struct SGFNode_t { struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; } *


decompiled_code:
__int64 __fastcall get_sgfmove(__int64 a1)
{
int v1; // ebx

v1 = get_moveX(a1, board_size);
return (unsigned int)get_moveY(a1, board_size) + 20 * v1 + 21;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // ebx

v1 = get_moveX(a1, board_size);
return (unsigned int)get_moveY(a1, board_size) + 20 * v1 + 21;
}

original_code:
int
get_sgfmove(SGFProperty *property)
{
  return ((19 + 2) + (get_moveX(property, board_size)) * (19 + 1) + (get_moveY(property, board_size)));
}

canonical_original_code:
int get_sgfmove(struct SGFProperty_t *property)
{
  return ((19 + 2) + (get_moveX(property, board_size)) * (19 + 1) + (get_moveY(property, board_size)));
}

variable_types: struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *

return_type: int


decompiled_code:
__int64 __fastcall sgftree_readfile(__int64 *a1, __int64 a2)
{
__int64 v2; // rbp
__int64 result; // rax

v2 = *a1;
result = readsgffile(a2);
*a1 = result;
if ( result )
{
sgfFreeNode(v2);
a1[1] = 0LL;
result = 1LL;
}
else
{
*a1 = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 a2)
{
__int64 v2; // rbp
__int64 result; // rax

v2 = *a1;
result = readsgffile(a2);
*a1 = result;
if ( result )
{
sgfFreeNode(v2);
a1[1] = 0LL;
result = 1LL;
}
else
{
*a1 = v2;
}
return result;
}

original_code:
int
sgftree_readfile(SGFTree *tree, const char *infilename)
{
  SGFNode *savetree = tree->root;
  tree->root = readsgffile(infilename);
  if (tree->root == ((void *)0)) {
    tree->root = savetree;
    return 0;
  }
  sgfFreeNode(savetree);
  tree->lastnode = ((void *)0);
  return 1;
}

canonical_original_code:
int sgftree_readfile(struct SGFTree_t *tree, char *infilename)
{
  struct SGFNode_t *savetree = tree->root;
  tree->root = readsgffile(infilename);
  if (tree->root == ((void *)0)) {
    tree->root = savetree;
    return 0;
  }
  sgfFreeNode(savetree);
  tree->lastnode = ((void *)0);
  return 1;
}

variable_types:
infilename
char *

user_defined_types: struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; }


sgftreeForward

decompiled_code:
__int64 __fastcall sgftreeForward(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = a1[1];
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 16);
if ( v2 )
{
a1[1] = v2;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
a1[1] = *a1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = a1[1];
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 16);
if ( v2 )
{
a1[1] = v2;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
a1[1] = *a1;
result = 1LL;
}
return result;
}

original_code:
int
sgftreeForward(SGFTree *tree)
{
  if (tree->lastnode) {
    if (tree->lastnode->child)
      tree->lastnode = tree->lastnode->child;
    else
      return 0;
  }
  else
    tree->lastnode = tree->root;
  return 1;
}

canonical_original_code:
int sgftreeForward(struct SGFTree_t *tree)
{
  if (tree->lastnode) {
    if (tree->lastnode->child)
      tree->lastnode = tree->lastnode->child;
    else
      return 0;
  }
  else
    tree->lastnode = tree->root;
  return 1;
}


sgftreeBack

decompiled_code:
__int64 __fastcall sgftreeBack(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = a1[1];
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 8);
if ( v2 )
{
a1[1] = v2;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
while ( (unsigned int)sgftreeForward(a1) )
;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = a1[1];
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 8);
if ( v2 )
{
a1[1] = v2;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
while ( (unsigned int)func2(a1) )
;
result = 1LL;
}
return result;
}

original_code:
int
sgftreeBack(SGFTree *tree)
{
  if (tree->lastnode) {
    if (tree->lastnode->parent)
      tree->lastnode = tree->lastnode->parent;
    else
      return 0;
  }
  else
    while (sgftreeForward(tree))
      ;
  return 1;
}

canonical_original_code:
int sgftreeBack(struct SGFTree_t *tree)
{
  if (tree->lastnode) {
    if (tree->lastnode->parent)
      tree->lastnode = tree->lastnode->parent;
    else
      return 0;
  }
  else
    while (sgftreeForward(tree))
      ;
  return 1;
}


sgftreeNodeCheck

decompiled_code:
__int64 __fastcall sgftreeNodeCheck(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // r8
__int64 v4; // rax

v1 = *a1;
if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0x6Bu, "sgftreeNodeCheck");
v2 = a1[1];
if ( !v2 )
{
do
{
v2 = v1;
v4 = *(_QWORD *)(v1 + 16);
if ( !v4 )
break;
v2 = v4;
v1 = *(_QWORD *)(v4 + 16);
}
while ( v1 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // r8
__int64 v4; // rax

v1 = *a1;
if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0x6Bu, "sgftreeNodeCheck");
v2 = a1[1];
if ( !v2 )
{
do
{
v2 = v1;
v4 = *(_QWORD *)(v1 + 16);
if ( !v4 )
break;
v2 = v4;
v1 = *(_QWORD *)(v4 + 16);
}
while ( v1 );
}
return v2;
}

original_code:
SGFNode *
sgftreeNodeCheck(SGFTree *tree)
{
  SGFNode *node = ((void *)0);
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 107, __extension__ __PRETTY_FUNCTION__); }));
  if (tree->lastnode)
    node = tree->lastnode;
  else {
    node = tree->root;
    while (node->child)
      node = node->child;
  }
  return node;
}

canonical_original_code:
struct SGFNode_t *sgftreeNodeCheck(struct SGFTree_t *tree)
{
  struct SGFNode_t *node = ((void *)0);
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 107, __extension__ __PRETTY_FUNCTION__); }));
  if (tree->lastnode)
    node = tree->lastnode;
  else {
    node = tree->root;
    while (node->child)
      node = node->child;
  }
  return node;
}

variable_types: struct SGFTree_t { struct SGFNode_t *root; struct SGFNode_t *lastnode; } *

return_type: struct SGFNode_t { struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; } *


sgftreeAddStone

decompiled_code:
__int64 __fastcall sgftreeAddStone(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax

v6 = sgftreeNodeCheck(a1);
return sgfAddStone(v6, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax

v6 = func4(a1);
return sgfAddStone(v6, a2, a3, a4);
}

original_code:
void
sgftreeAddStone(SGFTree *tree, int color, int movex, int movey)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfAddStone(node, color, movex, movey);
}

canonical_original_code:
void sgftreeAddStone(struct SGFTree_t *tree, int color, int movex, int movey)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfAddStone(node, color, movex, movey);
}

variable_types: color int

variable_types: movex int

variable_types: movey int


sgftreeAddPlay

decompiled_code:
__int64 __fastcall sgftreeAddPlay(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 result; // rax

v6 = sgftreeNodeCheck(a1);
result = sgfAddPlay(v6, a2, a3, a4);
a1[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 result; // rax

v6 = func4(a1);
result = sgfAddPlay(v6, a2, a3, a4);
a1[1] = result;
return result;
}

original_code:
void
sgftreeAddPlay(SGFTree *tree, int color, int movex, int movey)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfAddPlay(node, color, movex, movey);
}

canonical_original_code:
void sgftreeAddPlay(struct SGFTree_t *tree, int color, int movex, int movey)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfAddPlay(node, color, movex, movey);
}


sgftreeAddPlayLast

decompiled_code:
__int64 __fastcall sgftreeAddPlayLast(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 result; // rax

v6 = sgftreeNodeCheck(a1);
result = sgfAddPlayLast(v6, a2, a3, a4);
a1[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 result; // rax

v6 = func4(a1);
result = sgfAddPlayLast(v6, a2, a3, a4);
a1[1] = result;
return result;
}

original_code:
void
sgftreeAddPlayLast(SGFTree *tree, int color, int movex, int movey)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfAddPlayLast(node, color, movex, movey);
}

canonical_original_code:
void sgftreeAddPlayLast(struct SGFTree_t *tree, int color, int movex, int movey)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfAddPlayLast(node, color, movex, movey);
}


sgftreeAddComment

decompiled_code:
__int64 __fastcall sgftreeAddComment(__int64 *a1, __int64 a2)
{
__int64 v2; // rax

if ( !a1 || !*a1 )
_assert_fail("tree && tree->root", "msgftree.c", 0xB4u, "sgftreeAddComment");
v2 = sgftreeNodeCheck(a1);
return sgfAddComment(v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, __int64 a2)
{
__int64 v2; // rax

if ( !a1 || !*a1 )
_assert_fail("tree && tree->root", "msgftree.c", 0xB4u, "sgftreeAddComment");
v2 = func4(a1);
return sgfAddComment(v2, a2);
}

original_code:
void
sgftreeAddComment(SGFTree *tree, const char *comment)
{
  SGFNode *node;
  ((void) sizeof ((tree && tree->root) ? 1 : 0), __extension__ ({ if (tree && tree->root) ; else __assert_fail ("tree && tree->root", "msgftree.c", 180, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfAddComment(node, comment);
}

canonical_original_code:
void sgftreeAddComment(struct SGFTree_t *tree, char *comment)
{
  struct SGFNode_t *node;
  ((void) sizeof ((tree && tree->root) ? 1 : 0), __extension__ ({ if (tree && tree->root) ; else __assert_fail ("tree && tree->root", "msgftree.c", 180, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfAddComment(node, comment);
}

variable_types:
comment
char *


sgftreeBoardText

decompiled_code:
__int64 __fastcall sgftreeBoardText(__int64 *a1, unsigned int a2, unsigned int a3, __int64 a4)
{
__int64 v6; // rax

if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0xC3u, "sgftreeBoardText");
v6 = sgftreeNodeCheck(a1);
return sgfBoardText(v6, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1, unsigned int a2, unsigned int a3, __int64 a4)
{
__int64 v6; // rax

if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0xC3u, "sgftreeBoardText");
v6 = func4(a1);
return sgfBoardText(v6, a2, a3, a4);
}

original_code:
void
sgftreeBoardText(SGFTree *tree, int i, int j, const char *text)
{
  SGFNode *node;
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 195, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfBoardText(node, i, j, text);
}

canonical_original_code:
void sgftreeBoardText(struct SGFTree_t *tree, int i, int j, char *text)
{
  struct SGFNode_t *node;
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 195, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfBoardText(node, i, j, text);
}

variable_types: i int

variable_types: j int

variable_types:
text
char *


sgftreeBoardChar

decompiled_code:
__int64 __fastcall sgftreeBoardChar(__int64 *a1, unsigned int a2, unsigned int a3, char a4)
{
__int64 v6; // rax

if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0xD2u, "sgftreeBoardChar");
v6 = sgftreeNodeCheck(a1);
return sgfBoardChar(v6, a2, a3, (unsigned int)a4);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, unsigned int a2, unsigned int a3, char a4)
{
__int64 v6; // rax

if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0xD2u, "sgftreeBoardChar");
v6 = func4(a1);
return sgfBoardChar(v6, a2, a3, (unsigned int)a4);
}

original_code:
void
sgftreeBoardChar(SGFTree *tree, int i, int j, char c)
{
  SGFNode *node;
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 210, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfBoardChar(node, i, j, c);
}

canonical_original_code:
void sgftreeBoardChar(struct SGFTree_t *tree, int i, int j, char c)
{
  struct SGFNode_t *node;
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 210, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfBoardChar(node, i, j, c);
}

variable_types: c char


sgftreeBoardNumber

decompiled_code:
__int64 __fastcall sgftreeBoardNumber(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax

v6 = sgftreeNodeCheck(a1);
return sgfBoardNumber(v6, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax

v6 = func4(a1);
return sgfBoardNumber(v6, a2, a3, a4);
}

original_code:
void
sgftreeBoardNumber(SGFTree *tree, int i, int j, int number)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfBoardNumber(node, i, j, number);
}

canonical_original_code:
void sgftreeBoardNumber(struct SGFTree_t *tree, int i, int j, int number)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfBoardNumber(node, i, j, number);
}

variable_types: number int


sgftreeTriangle

decompiled_code:
__int64 __fastcall sgftreeTriangle(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = sgftreeNodeCheck(a1);
return sgfTriangle(v4, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = func4(a1);
return sgfTriangle(v4, a2, a3);
}

original_code:
void
sgftreeTriangle(SGFTree *tree, int i, int j)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfTriangle(node, i, j);
}

canonical_original_code:
void sgftreeTriangle(struct SGFTree_t *tree, int i, int j)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfTriangle(node, i, j);
}


sgftreeCircle

decompiled_code:
__int64 __fastcall sgftreeCircle(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = sgftreeNodeCheck(a1);
return sgfCircle(v4, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = func4(a1);
return sgfCircle(v4, a2, a3);
}

original_code:
void
sgftreeCircle(SGFTree *tree, int i, int j)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfCircle(node, i, j);
}

canonical_original_code:
void sgftreeCircle(struct SGFTree_t *tree, int i, int j)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfCircle(node, i, j);
}


sgftreeSquare

decompiled_code:
__int64 __fastcall sgftreeSquare(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = sgftreeNodeCheck(a1);
return sgfSquare(v4, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = func4(a1);
return sgfSquare(v4, a2, a3);
}

original_code:
void
sgftreeSquare(SGFTree *tree, int i, int j)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfSquare(node, i, j);
}

canonical_original_code:
void sgftreeSquare(struct SGFTree_t *tree, int i, int j)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfSquare(node, i, j);
}


sgftreeMark

decompiled_code:
__int64 __fastcall sgftreeMark(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = sgftreeNodeCheck(a1);
return sgfMark(v4, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = func4(a1);
return sgfMark(v4, a2, a3);
}

original_code:
void
sgftreeMark(SGFTree *tree, int i, int j)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfMark(node, i, j);
}

canonical_original_code:
void sgftreeMark(struct SGFTree_t *tree, int i, int j)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfMark(node, i, j);
}


sgftreeStartVariant

decompiled_code:
__int64 __fastcall sgftreeStartVariant(__int64 *a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = sgftreeNodeCheck(a1);
result = sgfStartVariant(v1);
a1[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 *a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = func4(a1);
result = sgfStartVariant(v1);
a1[1] = result;
return result;
}

original_code:
void
sgftreeStartVariant(SGFTree *tree)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfStartVariant(node);
}

canonical_original_code:
void sgftreeStartVariant(struct SGFTree_t *tree)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfStartVariant(node);
}


sgftreeStartVariantFirst

decompiled_code:
__int64 __fastcall sgftreeStartVariantFirst(__int64 *a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = sgftreeNodeCheck(a1);
result = sgfStartVariantFirst(v1);
a1[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 *a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = func4(a1);
result = sgfStartVariantFirst(v1);
a1[1] = result;
return result;
}

original_code:
void
sgftreeStartVariantFirst(SGFTree *tree)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfStartVariantFirst(node);
}

canonical_original_code:
void sgftreeStartVariantFirst(struct SGFTree_t *tree)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfStartVariantFirst(node);
}


sgftreeWriteResult

decompiled_code:
__int64 __fastcall sgftreeWriteResult(_QWORD *a1)
{
if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0x134u, "sgftreeWriteResult");
return sgfWriteResult();
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1)
{
if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0x134u, "sgftreeWriteResult");
return sgfWriteResult();
}

original_code:
void
sgftreeWriteResult(SGFTree *tree, float score, int overwrite)
{
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 308, __extension__ __PRETTY_FUNCTION__); }));
  sgfWriteResult(tree->root, score, overwrite);
}

canonical_original_code:
void sgftreeWriteResult(struct SGFTree_t *tree, float score, int overwrite)
{
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 308, __extension__ __PRETTY_FUNCTION__); }));
  sgfWriteResult(tree->root, score, overwrite);
}

variable_types: score float

variable_types: overwrite int


sgftreeSetLastNode

decompiled_code:
void __fastcall sgftreeSetLastNode(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

original_code:
void
sgftreeSetLastNode(SGFTree *tree, SGFNode *last_node)
{
  tree->lastnode = last_node;
}

canonical_original_code:
void sgftreeSetLastNode(struct SGFTree_t *tree, struct SGFNode_t *last_node)
{
  tree->lastnode = last_node;
}

variable_types: struct SGFTree_t { struct SGFNode_t { struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; } *root; struct SGFNode_t *lastnode; } *


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

v2 = *(_QWORD *)(a1 + 16);
if ( strlen((const char *)v2) <= 1 || (result = (unsigned int)(toupper(*(char *)(v2 + 1)) - 65), (int)result >= a2) )
result = 0xFFFFFFFFLL;
return result;
}

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

v2 = *(_QWORD *)(a1 + 16);
if ( strlen((const char *)v2) <= 1 || (result = (unsigned int)(toupper(*(char *)(v2 + 1)) - 65), (int)result >= a2) )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
get_moveX(SGFProperty *property, int boardsize)
{
  int i;
  if (strlen(property->value) < 2)
    return -1;
  i = toupper((int) property->value[1]) - 'A';
  if (i >= boardsize)
    return -1;
  return i;
}

canonical_original_code:
int get_moveX(struct SGFProperty_t *property, int boardsize)
{
  int i;
  if (strlen(property->value) < 2)
    return -1;
  i = toupper((int) property->value[1]) - 'A';
  if (i >= boardsize)
    return -1;
  return i;
}

variable_types: boardsize int


decompiled_code:
__int64 __fastcall get_moveY(__int64 a1, int a2)
{
const char *v2; // rbx
__int64 result; // rax

v2 = *(const char **)(a1 + 16);
if ( strlen(v2) <= 1 || (result = (unsigned int)(toupper(*v2) - 65), (int)result >= a2) )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
const char *v2; // rbx
__int64 result; // rax

v2 = *(const char **)(a1 + 16);
if ( strlen(v2) <= 1 || (result = (unsigned int)(toupper(*v2) - 65), (int)result >= a2) )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
get_moveY(SGFProperty *property, int boardsize)
{
  int j;
  if (strlen(property->value) < 2)
    return -1;
  j = toupper((int) property->value[0]) - 'A';
  if (j >= boardsize)
    return -1;
  return j;
}

canonical_original_code:
int get_moveY(struct SGFProperty_t *property, int boardsize)
{
  int j;
  if (strlen(property->value) < 2)
    return -1;
  j = toupper((int) property->value[0]) - 'A';
  if (j >= boardsize)
    return -1;
  return j;
}


decompiled_code:
_BOOL8 __fastcall get_moveXY(__int64 a1, _DWORD *a2, _DWORD *a3, int a4)
{
int v6; // eax

*a2 = get_moveX(a1, a4);
v6 = get_moveY(a1, a4);
*a3 = v6;
return (*a2 & v6) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, _DWORD *a2, _DWORD *a3, int a4)
{
int v6; // eax

*a2 = func0(a1, a4);
v6 = func1(a1, a4);
*a3 = v6;
return (*a2 & v6) != -1;
}

original_code:
int
get_moveXY(SGFProperty *property, int *i, int *j, int boardsize)
{
  *i = get_moveX(property, boardsize);
  *j = get_moveY(property, boardsize);
  if (*i == -1 && *j == -1)
    return 0;
  return 1;
}

canonical_original_code:
int get_moveXY(struct SGFProperty_t *property, int *i, int *j, int boardsize)
{
  *i = get_moveX(property, boardsize);
  *j = get_moveY(property, boardsize);
  if (*i == -1 && *j == -1)
    return 0;
  return 1;
}

variable_types:
i
int *

variable_types:
j
int *


decompiled_code:
__int64 __fastcall show_sgf_properties(__int64 **a1)
{
unsigned int v1; // er12
__int64 *v2; // rbx

v1 = 0;
printf("P: ");
v2 = *a1;
if ( *a1 )
{
do
{
++v1;
printf("%c%c ", (unsigned __int8)*((_WORD *)v2 + 4), (unsigned __int8)HIBYTE(*((_WORD *)v2 + 4)));
v2 = (__int64 *)*v2;
}
while ( v2 );
printf("(%d) ", v1);
if ( a1[3] )
putchar(110);
if ( a1[2] )
putchar(99);
putchar(10);
}
else
{
puts("None");
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 **a1)
{
unsigned int v1; // er12
__int64 *v2; // rbx

v1 = 0;
printf("P: ");
v2 = *a1;
if ( *a1 )
{
do
{
++v1;
printf("%c%c ", (unsigned __int8)*((_WORD *)v2 + 4), (unsigned __int8)HIBYTE(*((_WORD *)v2 + 4)));
v2 = (__int64 *)*v2;
}
while ( v2 );
printf("(%d) ", v1);
if ( a1[3] )
putchar(110);
if ( a1[2] )
putchar(99);
putchar(10);
}
else
{
puts("None");
}
return v1;
}

original_code:
int
show_sgf_properties(SGFNode *node)
{
  SGFProperty *sgf_prop;
  int propcount;
  propcount = 0;
  printf("P: ");
  if (!node->props) {
    printf("None\n");
    return propcount;
  }
  else {
    sgf_prop = node->props;
    while (sgf_prop) {
      printf("%c%c ", sgf_prop->name & 0x00FF, (sgf_prop->name & 0xFF00)>>8);
      sgf_prop = sgf_prop->next;
      propcount++;
    }
    printf("(%d) ", propcount);
    if (node->next)
      printf("n");
    if (node->child)
      printf("c");
    printf("\n");
  }
  return propcount;
}

canonical_original_code:
int show_sgf_properties(struct SGFNode_t *node)
{
  struct SGFProperty_t *sgf_prop;
  int propcount;
  propcount = 0;
  printf("P: ");
  if (!node->props) {
    printf("None\n");
    return propcount;
  }
  else {
    sgf_prop = node->props;
    while (sgf_prop) {
      printf("%c%c ", sgf_prop->name & 0x00FF, (sgf_prop->name & 0xFF00)>>8);
      sgf_prop = sgf_prop->next;
      propcount++;
    }
    printf("(%d) ", propcount);
    if (node->next)
      printf("n");
    if (node->child)
      printf("c");
    printf("\n");
  }
  return propcount;
}

variable_types: struct SGFNode_t { struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; } *

variable_types: propcount int


decompiled_code:
__int64 __fastcall show_sgf_tree(__int64 a1)
{
unsigned int v1; // er12
int v3; // eax

v1 = 0;
do
{
show_sgf_properties((__int64 **)a1);
v3 = 1;
if ( *(_QWORD *)(a1 + 16) )
v3 = show_sgf_tree() + 1;
a1 = *(_QWORD *)(a1 + 24);
v1 += v3;
}
while ( a1 );
return v1;
}

original_code:
int
show_sgf_tree(SGFNode *node)
{
  int n = 0;
  n++;
  show_sgf_properties(node);
  if (node->child)
    n += show_sgf_tree(node->child);
  if (node->next)
    n += show_sgf_tree(node->next);
  return n;
}

canonical_original_code:
int show_sgf_tree(struct SGFNode_t *node)
{
  int n = 0;
  n++;
  show_sgf_properties(node);
  if (node->child)
    n += show_sgf_tree(node->child);
  if (node->next)
    n += show_sgf_tree(node->next);
  return n;
}

variable_types: n int


original_code:
int
is_markup_node(SGFNode *node)
{
  SGFProperty *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 21059:
    case 20819:
    case 21076:
    case 16717:
    case 19778:
    case 20292:
    case 21577:
    case 17748:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}

canonical_original_code:
int is_markup_node(struct SGFNode_t *node)
{
  struct SGFProperty_t *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 21059:
    case 20819:
    case 21076:
    case 16717:
    case 19778:
    case 20292:
    case 21577:
    case 17748:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}

variable_types: struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *


decompiled_code:
__int64 __fastcall is_move_node(__int64 *a1)
{
__int64 result; // rax
__int16 v2; // dx

result = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v2 = *(_WORD *)(result + 8);
if ( v2 == 8258 || v2 == 8279 )
break;
result = *(_QWORD *)result;
if ( !result )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1)
{
__int64 result; // rax
__int16 v2; // dx

result = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v2 = *(_WORD *)(result + 8);
if ( v2 == 8258 || v2 == 8279 )
break;
result = *(_QWORD *)result;
if ( !result )
return result;
}
return 1LL;
}

original_code:
int
is_move_node(SGFNode *node)
{
  SGFProperty *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
    case 8279:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}

canonical_original_code:
int is_move_node(struct SGFNode_t *node)
{
  struct SGFProperty_t *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
    case 8279:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}


decompiled_code:
_BOOL8 __fastcall is_pass_node(__int64 *a1, int a2)
{
__int64 v2; // rdi
__int16 v3; // ax
int v5; // [rsp+0h] [rbp-10h] BYREF
int v6[3]; // [rsp+4h] [rbp-Ch] BYREF

v2 = *a1;
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = *(_WORD *)(v2 + 8);
if ( v3 == 8258 || v3 == 8279 )
break;
v2 = *(_QWORD *)v2;
if ( !v2 )
return 0LL;
}
return !get_moveXY(v2, &v5, v6, a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 *a1, int a2)
{
__int64 v2; // rdi
__int16 v3; // ax
int v5; // [rsp+0h] [rbp-10h] BYREF
int v6[3]; // [rsp+4h] [rbp-Ch] BYREF

v2 = *a1;
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = *(_WORD *)(v2 + 8);
if ( v3 == 8258 || v3 == 8279 )
break;
v2 = *(_QWORD *)v2;
if ( !v2 )
return 0LL;
}
return !func2(v2, &v5, v6, a2);
}

original_code:
int
is_pass_node(SGFNode *node, int boardsize)
{
  SGFProperty *sgf_prop;
  int i, j;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
    case 8279:
      return !get_moveXY(sgf_prop, &i, &j, boardsize);
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}

canonical_original_code:
int is_pass_node(struct SGFNode_t *node, int boardsize)
{
  struct SGFProperty_t *sgf_prop;
  int i; int j;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
    case 8279:
      return !get_moveXY(sgf_prop, &i, &j, boardsize);
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall find_move(__int64 *a1)
{
__int64 result; // rax
__int16 v2; // dx

result = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v2 = *(_WORD *)(result + 8);
if ( v2 == 8258 )
break;
if ( v2 == 8279 )
return 1LL;
result = *(_QWORD *)result;
if ( !result )
return result;
}
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1)
{
__int64 result; // rax
__int16 v2; // dx

result = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v2 = *(_WORD *)(result + 8);
if ( v2 == 8258 )
break;
if ( v2 == 8279 )
return 1LL;
result = *(_QWORD *)result;
if ( !result )
return result;
}
return 2LL;
}

original_code:
int
find_move(SGFNode *node)
{
  SGFProperty *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
      return 2;
      break;
    case 8279:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}

canonical_original_code:
int find_move(struct SGFNode_t *node)
{
  struct SGFProperty_t *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
      return 2;
      break;
    case 8279:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}


decompiled_code:
__int64 iterate_tgfsr()
{
int *v0; // rdx
unsigned int v1; // eax
const char *v2; // rdx
__int64 result; // rax

v0 = &x;
do
{
v1 = v0[7] ^ ((unsigned int)*v0 >> 1);
if ( (*v0 & 1) != 0 )
v1 = v0[7] ^ ((unsigned int)*v0 >> 1) ^ 0x8EBFD028;
*v0++ = v1;
}
while ( v0 != (int *)&unk_268 );
v2 = (const char *)&unk_268;
do
{
result = (unsigned int)(*((_DWORD *)v2 - 18) ^ (*(_DWORD *)v2 >> 1));
if ( (*(_DWORD *)v2 & 1) != 0 )
result = *((_DWORD *)v2 - 18) ^ (*(_DWORD *)v2 >> 1) ^ 0x8EBFD028;
v2 += 4;
*((_DWORD *)v2 - 1) = result;
}
while ( "mrandom.c" != v2 );
return result;
}


decompiled_code:
__int64 next_rand()
{
int v0; // eax
int v1; // eax

if ( !rand_initialized )
_assert_fail("rand_initialized", "mrandom.c", 0x5Bu, "next_rand");
v0 = k + 1;
k = v0;
if ( v0 == 25 )
{
iterate_tgfsr();
v0 = 0;
k = 0;
}
v1 = x[v0] ^ (x[v0] << 7) & 0x2B5B2500;
return (v1 << 15) & 0xDB8B0000 ^ v1;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
int v1; // eax

if ( !rand_initialized )
_assert_fail("rand_initialized", "mrandom.c", 0x5Bu, "next_rand");
v0 = k + 1;
k = v0;
if ( v0 == 25 )
{
func0();
v0 = 0;
k = 0;
}
v1 = x[v0] ^ (x[v0] << 7) & 0x2B5B2500;
return (v1 << 15) & 0xDB8B0000 ^ v1;
}

original_code:
static unsigned int
next_rand(void)
{
  int y;
  if (!rand_initialized) {
    ((void) sizeof ((rand_initialized) ? 1 : 0), __extension__ ({ if (rand_initialized) ; else __assert_fail ("rand_initialized", "mrandom.c", 91, __extension__ __PRETTY_FUNCTION__); }));
    gg_srand(1);
  }
  if (++k == 25) {
    iterate_tgfsr();
    k = 0;
  }
  y = x[k] ^ ((x[k] << s) & b);
  y ^= ((y << t) & c);
  return y;
}

canonical_original_code:
static unsigned int next_rand()
{
  int y;
  if (!rand_initialized) {
    ((void) sizeof ((rand_initialized) ? 1 : 0), __extension__ ({ if (rand_initialized) ; else __assert_fail ("rand_initialized", "mrandom.c", 91, __extension__ __PRETTY_FUNCTION__); }));
    gg_srand(1);
  }
  if (++k == 25) {
    iterate_tgfsr();
    k = 0;
  }
  y = x[k] ^ ((x[k] << s) & b);
  y ^= ((y << t) & c);
  return y;
}

variable_types: y int

return_type: unsigned int


decompiled_code:
char *__fastcall gg_srand(int a1)
{
char *result; // rax

result = (char *)x;
do
{
*(_DWORD *)result = a1;
result += 4;
a1 = 1313 * a1 + 88897;
}
while ( result != "mrandom.c" );
k = 24;
rand_initialized = 1;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
char *result; // rax

result = (char *)x;
do
{
*(_DWORD *)result = a1;
result += 4;
a1 = 1313 * a1 + 88897;
}
while ( result != "mrandom.c" );
k = 24;
rand_initialized = 1;
return result;
}

original_code:
void
gg_srand(unsigned int seed)
{
  int i;
  for (i = 0; i < 25; i++) {
    x[i] = seed;
    seed *= 1313;
    seed += 88897;
  }
  k = 25 -1;
  rand_initialized = 1;
}

variable_types:
seed
unsigned int


decompiled_code:
__int64 gg_rand()
{
return next_rand() & 0x7FFFFFFF;
}

canonical_decompiled_code:
__int64 func3()
{
return func1() & 0x7FFFFFFF;
}

original_code:
int
gg_rand(void)
{
  return (int) (next_rand() & 0x7fffffff);
}

canonical_original_code:
int gg_rand()
{
  return (int) (next_rand() & 0x7fffffff);
}


decompiled_code:
// attributes: thunk
__int64 gg_urand()
{
return next_rand();
}

canonical_decompiled_code:
__int64 func4()
{
return func1();
}

original_code:
unsigned int
gg_urand(void)
{
  return next_rand();
}

canonical_original_code:
unsigned int gg_urand()
{
  return next_rand();
}


decompiled_code:
double gg_drand()
{
return (double)(int)next_rand() * 2.328306436538696e-10;
}

original_code:
double
gg_drand(void)
{
  return next_rand() * 2.328306436538696e-10;
}

return_type: double


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

for ( i = 0LL; i != 25; ++i )
*(_DWORD *)(a1 + i * 4) = x[i];
result = (unsigned int)k;
*(_DWORD *)(a1 + 100) = k;
return result;
}

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

for ( i = 0LL; i != 25; ++i )
*(_DWORD *)(a1 + i * 4) = x[i];
result = (unsigned int)k;
*(_DWORD *)(a1 + 100) = k;
return result;
}

original_code:
void
gg_get_rand_state(struct gg_rand_state *state)
{
  int i;
  for (i = 0; i < 25; i++)
    state->x[i] = x[i];
  state->k = k;
}

variable_types: struct gg_rand_state { unsigned int x[25]; int k; } *

variable_types: i int


decompiled_code:
__int64 __fastcall gg_set_rand_state(__int64 a1)
{
__int64 i; // rax
int v2; // edx
__int64 result; // rax

for ( i = 0LL; i != 25; dword_21C[i] = v2 )
{
v2 = *(_DWORD *)(a1 + i * 4);
++i;
}
result = *(unsigned int *)(a1 + 100);
k = *(_DWORD *)(a1 + 100);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 i; // rax
int v2; // edx
__int64 result; // rax

for ( i = 0LL; i != 25; dword_21C[i] = v2 )
{
v2 = *(_DWORD *)(a1 + i * 4);
++i;
}
result = *(unsigned int *)(a1 + 100);
k = *(_DWORD *)(a1 + 100);
return result;
}

original_code:
void
gg_set_rand_state(struct gg_rand_state *state)
{
  int i;
  for (i = 0; i < 25; i++)
    x[i] = state->x[i];
  k = state->k;
}

user_defined_types: struct gg_rand_state { unsigned int x[25]; int k; }


decompiled_code:
void gg_init_color()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void
gg_init_color()
{
}

canonical_original_code:
void gg_init_color()
{
}


decompiled_code:
int __fastcall write_color_char_no_space(__int64 a1, int a2)
{
return fputc(a2, stderr);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
return fputc(a2, stderr);
}

original_code:
void
write_color_char_no_space(int c, int x)
{
  fprintf(stderr, "%c", x);
}

variable_types: c int

variable_types: x int


decompiled_code:
int __fastcall write_color_string(unsigned int a1, char *a2)
{
_BYTE *v2; // rbx
int v3; // esi
int result; // eax

v2 = a2;
v3 = *a2;
if ( (_BYTE)v3 )
{
do
{
++v2;
result = write_color_char_no_space(a1, v3);
v3 = (char)*v2;
}
while ( *v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, char *a2)
{
_BYTE *v2; // rbx
int v3; // esi
int result; // eax

v2 = a2;
v3 = *a2;
if ( (_BYTE)v3 )
{
do
{
++v2;
result = func1(a1, v3);
v3 = (char)*v2;
}
while ( *v2 );
}
return result;
}

original_code:
void
write_color_string(int c, const char *str)
{
  while (*str)
    write_color_char_no_space(c, *str++);
}

canonical_original_code:
void write_color_string(int c, char *str)
{
  while (*str)
    write_color_char_no_space(c, *str++);
}

variable_types:
str
char *


decompiled_code:
int __fastcall write_color_char(unsigned int a1, int a2)
{
fputc(32, stderr);
return write_color_char_no_space(a1, a2);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, int a2)
{
fputc(32, stderr);
return func1(a1, a2);
}

original_code:
void
write_color_char(int c, int x)
{
  fprintf(stderr, " ");
  write_color_char_no_space(c, x);
}


decompiled_code:
int __fastcall gg_vsnprintf(char *a1, __int64 a2, const char *a3, void *a4)
{
return vsprintf(a1, a3, a4);
}

canonical_decompiled_code:
int __fastcall func4(char *a1, __int64 a2, const char *a3, void *a4)
{
return vsprintf(a1, a3, a4);
}

original_code:
void
gg_vsnprintf(char *dest, unsigned long len, const char *fmt, va_list args)
{
  (void)len;
  vsprintf(dest, fmt, args);
}

canonical_original_code:
void gg_vsnprintf(char *dest, unsigned long len, char *fmt, __builtin_va_list args)
{
  (void)len;
  vsprintf(dest, fmt, args);
}

variable_types:
dest
char *

variable_types:
len
unsigned long

variable_types:
fmt
char *


decompiled_code:
int gg_snprintf(char *a1, __int64 a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return gg_vsnprintf(a1, a2, a3, va);
}

canonical_decompiled_code:
int func5(char *a1, __int64 a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return func4(a1, a2, a3, va);
}

original_code:
void
gg_snprintf(char *dest, unsigned long len, const char *fmt, ...)
{
  va_list args;
  __builtin_va_start(args,fmt);
  gg_vsnprintf(dest, len, fmt, args);
  __builtin_va_end(args);
}

canonical_original_code:
void gg_snprintf(char *dest, unsigned long len, char *fmt, ...)
{
  __builtin_va_list args;
  __builtin_va_start(args,fmt);
  gg_vsnprintf(dest, len, fmt, args);
  __builtin_va_end(args);
}


decompiled_code:
void *gg_version()
{
return &unk_590;
}

canonical_decompiled_code:
void *func6()
{
return &unk_590;
}

original_code:
const char *
gg_version(void)
{
  return "3.8";
}

canonical_original_code:
char *gg_version()
{
  return "3.8";
}


decompiled_code:
float __fastcall gg_normalize_float(float a1, float a2)
{
return (float)(int)((float)(a1 / a2) + 0.5) * a2;
}

canonical_decompiled_code:
float __fastcall func7(float a1, float a2)
{
return (float)(int)((float)(a1 / a2) + 0.5) * a2;
}

original_code:
float
gg_normalize_float(float x, float a)
{
  return a * ((int) (0.5 + x / a));
}

variable_types: x float

variable_types: a float

return_type: float


decompiled_code:
__int64 __fastcall gg_normalize_float2int(float a1, float a2)
{
return (unsigned int)(int)((float)(a1 / a2) + 0.5);
}

canonical_decompiled_code:
__int64 __fastcall func8(float a1, float a2)
{
return (unsigned int)(int)((float)(a1 / a2) + 0.5);
}

original_code:
int
gg_normalize_float2int(float x, float a)
{
  return ((int) (0.5 + x / a));
}


original_code:
void
gg_sort(void *base, size_t nel, size_t width,
 int (*cmp)(const void *, const void *))
{
  int gap = nel;
  int swap_made;
  char *end = (char *) base + width * (nel - 1);
  do {
    char *a, *b;
    swap_made = 0;
    gap = (10 * gap + 3) / 13;
    for (a = base, b = a + gap * width; b <= end; a += width, b += width) {
      if (cmp((void *) a, (void *) b) > 0) {
 char *c = a;
 char *d = b;
 size_t size = width;
 while (size-- > 0) {
   char tmp = *c;
   *c++ = *d;
   *d++ = tmp;
 }
 swap_made = 1;
      }
    }
  } while (gap > 1 || swap_made);
}

canonical_original_code:
void gg_sort(void *base, unsigned long nel, unsigned long width, int (*cmp)(void *, void *))
{
  int gap = nel;
  int swap_made;
  char *end = (char *) base + width * (nel - 1);
  do {
    char *a; char *b;
    swap_made = 0;
    gap = (10 * gap + 3) / 13;
    for (a = base, b = a + gap * width; b <= end; a += width, b += width) {
      if (cmp((void *) a, (void *) b) > 0) {
 char *c = a;
 char *d = b;
 unsigned long size = width;
 while (size-- > 0) {
   char tmp = *c;
   *c++ = *d;
   *d++ = tmp;
 }
 swap_made = 1;
      }
    }
  } while (gap > 1 || swap_made);
}

variable_types:
base
void *

variable_types:
nel
unsigned long

variable_types:
width
unsigned long

variable_types:
cmp
int (*)(void *, void *)

variable_types: gap int

variable_types:
end
char *

variable_types:
a
char *

variable_types:
b
char *

variable_types:
c
char *

variable_types:
d
char *

variable_types:
size
unsigned long

variable_types: tmp char


decompiled_code:
float __fastcall gg_interpolate(float *a1, float a2)
{
float v2; // xmm2_4
float v3; // xmm3_4
__int64 v4; // rax
float v6; // xmm0_4

v2 = a1[1];
if ( v2 > a2 )
return a1[3];
v3 = a1[2];
v4 = *(int *)a1;
if ( a2 > v3 )
return a1[v4 + 3];
v6 = (float)((float)(a2 - v2) * (float)(int)v4) / (float)(v3 - v2);
return (float)((float)(1.0 - (float)(v6 - (float)(int)v6)) * a1[(int)v6 + 3])
+ (float)((float)(v6 - (float)(int)v6) * a1[(int)v6 + 4]);
}

canonical_decompiled_code:
float __fastcall func10(float *a1, float a2)
{
float v2; // xmm2_4
float v3; // xmm3_4
__int64 v4; // rax
float v6; // xmm0_4

v2 = a1[1];
if ( v2 > a2 )
return a1[3];
v3 = a1[2];
v4 = *(int *)a1;
if ( a2 > v3 )
return a1[v4 + 3];
v6 = (float)((float)(a2 - v2) * (float)(int)v4) / (float)(v3 - v2);
return (float)((float)(1.0 - (float)(v6 - (float)(int)v6)) * a1[(int)v6 + 3])
+ (float)((float)(v6 - (float)(int)v6) * a1[(int)v6 + 4]);
}

original_code:
float
gg_interpolate(struct interpolation_data *f, float x)
{
  int i;
  float ratio;
  float diff;
  if (x < f->range_lowerbound)
    return f->values[0];
  else if (x > f->range_upperbound)
    return f->values[f->sections];
  else {
    ratio = ((float) f->sections) * (x - f->range_lowerbound)
              / (f->range_upperbound - f->range_lowerbound);
    i = (int) ratio;
    diff = ratio - ((float) i);
    if (0)
      fprintf(stderr, "Floating point Ratio: %f, integer: %d, diff %f",
       ratio, i, diff);
    return ((1 - diff) * f->values[i] + diff * f->values[i+1]);
  }
}

variable_types: struct interpolation_data { int sections; float range_lowerbound; float range_upperbound; float values[-1]; } *

variable_types: i int

variable_types: ratio float

variable_types: diff float


original_code:
float
soft_cap(float a, float b)
{
  return ((a * b) / (a + b));
}

variable_types: a float

variable_types: b float


rotate

decompiled_code:
__int64 __fastcall rotate(int a1, int a2, int *a3, int *a4, int a5, unsigned int a6)
{
__int64 result; // rax
int v7; // er8

if ( a5 <= 0 )
_assert_fail("bs > 0", "mgg_utils.c", 0x1AFu, "rotate");
if ( !a3 || !a4 )
_assert_fail("ri != NULL && rj != NULL", "mgg_utils.c", 0x1B0u, "rotate");
if ( a6 > 7 )
_assert_fail("rot >= 0 && rot < 8", "mgg_utils.c", 0x1B1u, "rotate");
result = a2 & (unsigned int)a1;
if ( (_DWORD)result == -1 )
goto LABEL_11;
if ( a1 < 0 || a5 <= a1 )
_assert_fail("i >= 0 && i < bs", "mgg_utils.c", 0x1B9u, "rotate");
if ( a2 < 0 || a5 <= a2 )
_assert_fail("j >= 0 && j < bs", "mgg_utils.c", 0x1BAu, "rotate");
if ( a6 )
{
v7 = a5 - 1;
switch ( a6 )
{
case 1u:
*a3 = v7 - a2;
*a4 = a1;
break;
case 2u:
result = (unsigned int)(v7 - a1);
*a3 = result;
*a4 = v7 - a2;
break;
case 3u:
*a3 = a2;
*a4 = v7 - a1;
break;
case 4u:
*a3 = a2;
*a4 = a1;
break;
case 5u:
*a3 = v7 - a1;
*a4 = a2;
break;
default:
result = (unsigned int)(v7 - a2);
if ( a6 == 6 )
{
*a3 = result;
*a4 = v7 - a1;
}
else
{
*a3 = a1;
*a4 = result;
}
break;
}
}
else
{
LABEL_11:
*a3 = a1;
*a4 = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2, int *a3, int *a4, int a5, unsigned int a6)
{
__int64 result; // rax
int v7; // er8

if ( a5 <= 0 )
_assert_fail("bs > 0", "mgg_utils.c", 0x1AFu, "rotate");
if ( !a3 || !a4 )
_assert_fail("ri != NULL && rj != NULL", "mgg_utils.c", 0x1B0u, "rotate");
if ( a6 > 7 )
_assert_fail("rot >= 0 && rot < 8", "mgg_utils.c", 0x1B1u, "rotate");
result = a2 & (unsigned int)a1;
if ( (_DWORD)result == -1 )
goto LABEL_11;
if ( a1 < 0 || a5 <= a1 )
_assert_fail("i >= 0 && i < bs", "mgg_utils.c", 0x1B9u, "rotate");
if ( a2 < 0 || a5 <= a2 )
_assert_fail("j >= 0 && j < bs", "mgg_utils.c", 0x1BAu, "rotate");
if ( a6 )
{
v7 = a5 - 1;
switch ( a6 )
{
case 1u:
*a3 = v7 - a2;
*a4 = a1;
break;
case 2u:
result = (unsigned int)(v7 - a1);
*a3 = result;
*a4 = v7 - a2;
break;
case 3u:
*a3 = a2;
*a4 = v7 - a1;
break;
case 4u:
*a3 = a2;
*a4 = a1;
break;
case 5u:
*a3 = v7 - a1;
*a4 = a2;
break;
default:
result = (unsigned int)(v7 - a2);
if ( a6 == 6 )
{
*a3 = result;
*a4 = v7 - a1;
}
else
{
*a3 = a1;
*a4 = result;
}
break;
}
}
else
{
LABEL_11:
*a3 = a1;
*a4 = a2;
}
return result;
}

original_code:
void
rotate(int i, int j, int *ri, int *rj, int bs, int rot)
{
  int bs1;
  ((void) sizeof ((bs > 0) ? 1 : 0), __extension__ ({ if (bs > 0) ; else __assert_fail ("bs > 0", "mgg_utils.c", 431, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((ri != ((void *)0) && rj != ((void *)0)) ? 1 : 0), __extension__ ({ if (ri != ((void *)0) && rj != ((void *)0)) ; else __assert_fail ("ri != NULL && rj != NULL", "mgg_utils.c", 432, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((rot >= 0 && rot < 8) ? 1 : 0), __extension__ ({ if (rot >= 0 && rot < 8) ; else __assert_fail ("rot >= 0 && rot < 8", "mgg_utils.c", 433, __extension__ __PRETTY_FUNCTION__); }));
  if (i == -1 && j == -1) {
    *ri = i;
    *rj = j;
    return;
  }
  ((void) sizeof ((i >= 0 && i < bs) ? 1 : 0), __extension__ ({ if (i >= 0 && i < bs) ; else __assert_fail ("i >= 0 && i < bs", "mgg_utils.c", 441, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((j >= 0 && j < bs) ? 1 : 0), __extension__ ({ if (j >= 0 && j < bs) ; else __assert_fail ("j >= 0 && j < bs", "mgg_utils.c", 442, __extension__ __PRETTY_FUNCTION__); }));
  bs1 = bs - 1;
  if (rot == 0) {
    *ri = i;
    *rj = j;
  }
  else if (rot == 1) {
    *ri = bs1 - j;
    *rj = i;
  }
  else if (rot == 2) {
    *ri = bs1 - i;
    *rj = bs1 - j;
  }
  else if (rot == 3) {
    *ri = j;
    *rj = bs1 - i;
  }
  else if (rot == 4) {
    *ri = j;
    *rj = i;
  }
  else if (rot == 5) {
    *ri = bs1 - i;
    *rj = j;
  }
  else if (rot == 6) {
    *ri = bs1 - j;
    *rj = bs1 - i;
  }
  else if (rot == 7) {
    *ri = i;
    *rj = bs1 - j;
  }
}

variable_types: j int

variable_types:
ri
int *

variable_types:
rj
int *

variable_types: bs int

variable_types: rot int


decompiled_code:
__int64 __fastcall inv_rotate(int a1, int a2, int *a3, int *a4, int a5, unsigned int a6)
{
if ( a6 == 1 )
{
a6 = 3;
}
else if ( a6 == 3 )
{
a6 = 1;
}
return rotate(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2, int *a3, int *a4, int a5, unsigned int a6)
{
if ( a6 == 1 )
{
a6 = 3;
}
else if ( a6 == 3 )
{
a6 = 1;
}
return func12(a1, a2, a3, a4, a5, a6);
}

original_code:
void
inv_rotate(int i, int j, int *ri, int *rj, int bs, int rot)
{
  if (rot == 1)
    rotate(i, j, ri, rj, bs, 3);
  else if (rot == 3)
    rotate(i, j, ri, rj, bs, 1);
  else
    rotate(i, j, ri, rj, bs, rot);
}


decompiled_code:
__int64 get_random_seed()
{
return (unsigned int)random_seed;
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned int)random_seed;
}

original_code:
unsigned int
get_random_seed()
{
  return random_seed;
}


decompiled_code:
__int64 __fastcall set_random_seed(int a1)
{
random_seed = a1;
return gg_srand();
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
random_seed = a1;
return gg_srand();
}

original_code:
void
set_random_seed(unsigned int seed)
{
  random_seed = seed;
  gg_srand(seed);
}

variable_types:
seed
unsigned int


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

gg_srand((unsigned int)random_seed);
v0 = gg_rand();
if ( v0 )
{
random_seed = v0;
result = gg_srand(v0);
}
else
{
random_seed = 1;
result = gg_srand(1LL);
}
return result;
}

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

gg_srand((unsigned int)random_seed);
v0 = gg_rand();
if ( v0 )
{
random_seed = v0;
result = gg_srand(v0);
}
else
{
random_seed = 1;
result = gg_srand(1LL);
}
return result;
}

original_code:
void
update_random_seed(void)
{
  gg_srand(random_seed);
  random_seed = gg_rand();
  if (random_seed == 0)
    random_seed = 1;
  gg_srand(random_seed);
}

canonical_original_code:
void update_random_seed()
{
  gg_srand(random_seed);
  random_seed = gg_rand();
  if (random_seed == 0)
    random_seed = 1;
  gg_srand(random_seed);
}


decompiled_code:
__int64 reuse_random_seed()
{
return gg_srand((unsigned int)random_seed);
}

canonical_decompiled_code:
__int64 func17()
{
return gg_srand((unsigned int)random_seed);
}

original_code:
void
reuse_random_seed()
{
  gg_srand(random_seed);
}


decompiled_code:
__int64 __fastcall place_fixed_handicap(int a1)
{
int v1; // ebp
int v2; // ebx
int v3; // er12
__int64 v4; // r13
int v5; // edx
int v6; // eax

v1 = (board_size > 11) + 2;
if ( a1 > 1 )
{
if ( board_size % 2 == 1 && board_size > 8 )
{
v2 = 9;
}
else
{
if ( board_size <= 6 )
{
handicap = 0;
if ( (a1 & 0xFFFFFFFD) == 5 )
add_stone((unsigned int)(21 * (board_size / 2) + 21), 2LL);
return handicap;
}
v2 = 4;
}
if ( v2 > a1 )
v2 = a1;
handicap = v2;
v3 = board_size / 2;
if ( (a1 & 0xFFFFFFFD) == 5 )
{
--v2;
add_stone((unsigned int)(21 * v3 + 21), 2LL);
if ( v2 <= 0 )
return handicap;
}
v4 = 0LL;
v5 = -2;
v6 = 2;
while ( 1 )
{
if ( v6 == 2 )
{
v6 = v1;
if ( v5 == 2 )
goto LABEL_21;
}
else
{
if ( v6 )
{
if ( v6 == -2 )
v6 = board_size + ~v1;
}
else
{
v6 = v3;
}
if ( v5 == 2 )
{
LABEL_21:
v5 = v1;
goto LABEL_17;
}
}
if ( v5 )
{
if ( v5 == -2 )
v5 = board_size + ~v1;
}
else
{
v5 = v3;
}
LABEL_17:
++v4;
add_stone((unsigned int)(v5 + 20 * v6 + 21), 2LL);
if ( v2 <= (int)v4 )
return handicap;
v6 = places[2 * v4];
v5 = dword_264[2 * v4];
}
}
handicap = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ebp
int v2; // ebx
int v3; // er12
__int64 v4; // r13
int v5; // edx
int v6; // eax

v1 = (board_size > 11) + 2;
if ( a1 > 1 )
{
if ( board_size % 2 == 1 && board_size > 8 )
{
v2 = 9;
}
else
{
if ( board_size <= 6 )
{
handicap = 0;
if ( (a1 & 0xFFFFFFFD) == 5 )
add_stone((unsigned int)(21 * (board_size / 2) + 21), 2LL);
return handicap;
}
v2 = 4;
}
if ( v2 > a1 )
v2 = a1;
handicap = v2;
v3 = board_size / 2;
if ( (a1 & 0xFFFFFFFD) == 5 )
{
--v2;
add_stone((unsigned int)(21 * v3 + 21), 2LL);
if ( v2 <= 0 )
return handicap;
}
v4 = 0LL;
v5 = -2;
v6 = 2;
while ( 1 )
{
if ( v6 == 2 )
{
v6 = v1;
if ( v5 == 2 )
goto LABEL_21;
}
else
{
if ( v6 )
{
if ( v6 == -2 )
v6 = board_size + ~v1;
}
else
{
v6 = v3;
}
if ( v5 == 2 )
{
LABEL_21:
v5 = v1;
goto LABEL_17;
}
}
if ( v5 )
{
if ( v5 == -2 )
v5 = board_size + ~v1;
}
else
{
v5 = v3;
}
LABEL_17:
++v4;
add_stone((unsigned int)(v5 + 20 * v6 + 21), 2LL);
if ( v2 <= (int)v4 )
return handicap;
v6 = places[2 * v4];
v5 = dword_264[2 * v4];
}
}
handicap = 0;
return 0LL;
}

original_code:
int
place_fixed_handicap(int desired_handicap)
{
  int r;
  int max_handicap;
  int remaining_stones;
  int three = board_size > 11 ? 3 : 2;
  int mid = board_size/2;
  if (desired_handicap < 2) {
    handicap = 0;
    return 0;
  }
  if ((board_size % 2 == 1) && (board_size >= 9))
    max_handicap = 9;
  else if (board_size >= 7)
    max_handicap = 4;
  else
    max_handicap = 0;
  if (desired_handicap > max_handicap)
    handicap = max_handicap;
  else
    handicap = desired_handicap;
  remaining_stones = handicap;
  if (desired_handicap == 5 || desired_handicap == 7) {
    add_stone(((19 + 2) + (mid) * (19 + 1) + (mid)), BLACK);
    remaining_stones--;
  }
  for (r = 0; r < remaining_stones; r++) {
    int i = places[r][0];
    int j = places[r][1];
    if (i == 2)
      i = three;
    else if (i == 0)
      i = mid;
    else if (i == -2)
      i = board_size - 1 - three;
    if (j == 2)
      j = three;
    else if (j == 0)
      j = mid;
    else if (j == -2)
      j = board_size - 1 - three;
    add_stone(((19 + 2) + (i) * (19 + 1) + (j)), BLACK);
  }
  return handicap;
}

variable_types: r int

variable_types: three int

variable_types: mid int


decompiled_code:
__int64 free_handicap_remaining_stones()
{
abortgo("mhandicap.c", 430LL, "remaining_handicap_stones >= 0", 0LL);
return free_handicap_total_stones();
}

canonical_decompiled_code:
__int64 func1()
{
abortgo("mhandicap.c", 430LL, "remaining_handicap_stones >= 0", 0LL);
return func2();
}

original_code:
int
free_handicap_remaining_stones()
{
  if (remaining_handicap_stones >= 0) ; else abortgo("mhandicap.c", 430, "remaining_handicap_stones >= 0", 0);
  return remaining_handicap_stones;
}


decompiled_code:
void free_handicap_total_stones()
{
abortgo("mhandicap.c", 437LL, "total_handicap_stones >= 0", 0LL);
JUMPOUT(0x1FALL);
}

canonical_decompiled_code:
void func2()
{
abortgo("mhandicap.c", 437LL, "total_handicap_stones >= 0", 0LL);
JUMPOUT(0x1FALL);
}

original_code:
int
free_handicap_total_stones()
{
  if (total_handicap_stones >= 0) ; else abortgo("mhandicap.c", 437, "total_handicap_stones >= 0", 0);
  return total_handicap_stones;
}