decompiled_code:
unsigned __int64 __fastcall DBG_dump(__int64 a1, __int64 a2, __int64 a3)
{
unsigned __int64 v5; // [rsp+8h] [rbp-20h]

v5 = __readfsqword(0x28u);
if ( a1 )
llog(3145728LL, &global_logger, &LC0, a1);
llog_dump(3145728LL, &global_logger, a2, a3);
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
unsigned __int64 v5; // [rsp+8h] [rbp-20h]

v5 = __readfsqword(0x28u);
if ( a1 )
llog(3145728LL, &global_logger, &LC0, a1);
llog_dump(3145728LL, &global_logger, a2, a3);
return v5 - __readfsqword(0x28u);
}

original_code:
void DBG_dump(const char *label, const void *p, size_t len)
{
 if (label != ((void *)0)) {
  llog(DEBUG_STREAM, &global_logger, "%s", label);
 }
 llog_dump(DEBUG_STREAM, &global_logger, p, len);
}

canonical_original_code:
void DBG_dump(char *label, void *p, unsigned long len)
{
 if (label != ((void *)0)) {
  llog(DEBUG_STREAM, &global_logger, "%s", label);
 }
 llog_dump(DEBUG_STREAM, &global_logger, p, len);
}

variable_types:
label
char *

variable_types:
p
void *

variable_types:
len
unsigned long


repo: libreswan/libreswan

decompiled_code:
unsigned __int64 init_root_certs()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
init_oneshot_timer(6LL, free_root_certs);
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func4()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
init_oneshot_timer(6LL, free_root_certs);
return v1 - __readfsqword(0x28u);
}

original_code:
void init_root_certs(void)
{
 init_oneshot_timer(EVENT_FREE_ROOT_CERTS, free_root_certs);
}

canonical_original_code:
void init_root_certs()
{
 init_oneshot_timer(EVENT_FREE_ROOT_CERTS, free_root_certs);
}

return_type: void


decompiled_code:
unsigned __int64 unbound_ctx_free()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
if ( dns_ctx )
{
ub_ctx_delete();
dns_ctx = 0LL;
}
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func1()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
if ( dns_ctx )
{
ub_ctx_delete();
dns_ctx = 0LL;
}
return v1 - __readfsqword(0x28u);
}

original_code:
void unbound_ctx_free(void)
{
 if (dns_ctx != ((void *)0)) {
  ub_ctx_delete(dns_ctx);
  dns_ctx = ((void *)0);
 }
}

canonical_original_code:
void unbound_ctx_free()
{
 if (dns_ctx != ((void *)0)) {
  ub_ctx_delete(dns_ctx);
  dns_ctx = ((void *)0);
 }
}


decompiled_code:
__int64 __fastcall hash_spd_route_remote_client(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx

v1 = shunk2(a1 + 8, 16LL);
return hash_bytes(v1, v2, zero_hash);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx

v1 = shunk2(a1 + 8, 16LL);
return hash_bytes(v1, v2, zero_hash);
}

original_code:
static hash_t hash_spd_route_remote_client(const ip_selector *sr)
{
 return ({ shunk_t h_ = shunk2(&(sr->bytes), sizeof(sr->bytes)); hash_bytes(h_.ptr, h_.len, zero_hash); });
}

canonical_original_code:
static struct hash_t hash_spd_route_remote_client(struct ip_selector *sr)
{
 return ({ struct shunk h_ = shunk2(&(sr->bytes), sizeof(sr->bytes)); hash_bytes(h_.ptr, h_.len, zero_hash); });
}

variable_types: struct ip_selector { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes { unsigned char byte[16]; } bytes; unsigned int maskbits; unsigned int ipproto; int hport; } *

variable_types: struct shunk { void *ptr; unsigned long len; }

return_type: struct hash_t { unsigned int hash; }

user_defined_types: struct ip_selector { _Bool is_set; enum ip_version version; struct ip_bytes bytes; unsigned int maskbits; unsigned int ipproto; int hport; }


decompiled_code:
__int64 __fastcall lsw_alias_cmp(char *s2, char *s)
{
char *v2; // rbx
size_t v3; // r14
const char *v4; // rbx
size_t v5; // rax
size_t v6; // rbp

if ( !s )
return 0LL;
v2 = s;
v3 = strlen(s2);
while ( 1 )
{
v4 = &v2[strspn(v2, " \t")];
if ( !*v4 )
break;
v5 = strcspn(v4, " \t");
v6 = v5;
if ( v3 == v5 && !strncmp(v4, s2, v5) )
return 1LL;
v2 = (char *)&v4[v6];
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2, char *s)
{
char *v2; // rbx
size_t v3; // r14
const char *v4; // rbx
size_t v5; // rax
size_t v6; // rbp

if ( !s )
return 0LL;
v2 = s;
v3 = strlen(s2);
while ( 1 )
{
v4 = &v2[strspn(v2, " \t")];
if ( !*v4 )
break;
v5 = strcspn(v4, " \t");
v6 = v5;
if ( v3 == v5 && !strncmp(v4, s2, v5) )
return 1LL;
v2 = (char *)&v4[v6];
}
return 0LL;
}

original_code:
_Bool lsw_alias_cmp(const char *name, const char *aliases)
{
 if (aliases == ((void *)0))
  return 0;
 size_t nlen = strlen(name);
 for (const char *s = aliases;;) {
  s += strspn(s, " \t");
  if (*s == '\0')
   return 0;
  size_t aw = strcspn(s, " \t");
  if (aw == nlen && (strncmp((s), (name), (nlen)) == 0))
   return 1;
  s += aw;
 }
}

canonical_original_code:
_Bool lsw_alias_cmp(char *name, char *aliases)
{
 if (aliases == ((void *)0))
  return 0;
 unsigned long nlen = strlen(name);
 for (char *s = aliases;;) {
  s += strspn(s, " \t");
  if (*s == '\0')
   return 0;
  unsigned long aw = strcspn(s, " \t");
  if (aw == nlen && (strncmp((s), (name), (nlen)) == 0))
   return 1;
  s += aw;
 }
}

variable_types:
name
char *

variable_types:
aliases
char *

variable_types:
nlen
unsigned long

variable_types:
s
char *

variable_types:
aw
unsigned long


ttobool

decompiled_code:
const char *__fastcall ttobool(char *s1, _BYTE *a2)
{
const char *result; // rax

if ( !strcasecmp(s1, "1") || !strcasecmp(s1, "yes") || !strcasecmp(s1, "true") || !strcasecmp(s1, "on") )
{
*a2 = 1;
result = 0LL;
}
else if ( !strcasecmp(s1, "0") || !strcasecmp(s1, "no") || !strcasecmp(s1, "false") || !strcasecmp(s1, "off") )
{
*a2 = 0;
result = 0LL;
}
else
{
*a2 = 0;
result = "invalid";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(char *s1, _BYTE *a2)
{
const char *result; // rax

if ( !strcasecmp(s1, "1") || !strcasecmp(s1, "yes") || !strcasecmp(s1, "true") || !strcasecmp(s1, "on") )
{
*a2 = 1;
result = 0LL;
}
else if ( !strcasecmp(s1, "0") || !strcasecmp(s1, "no") || !strcasecmp(s1, "false") || !strcasecmp(s1, "off") )
{
*a2 = 0;
result = 0LL;
}
else
{
*a2 = 0;
result = "invalid";
}
return result;
}

original_code:
err_t ttobool(const char *t, _Bool *b)
{
 if ((strcasecmp((t), ("1")) == 0) ||
     (strcasecmp((t), ("yes")) == 0) ||
     (strcasecmp((t), ("true")) == 0) ||
     (strcasecmp((t), ("on")) == 0)) {
  *b = 1;
  return ((void *)0);
 }
 if ((strcasecmp((t), ("0")) == 0) ||
     (strcasecmp((t), ("no")) == 0) ||
     (strcasecmp((t), ("false")) == 0) ||
     (strcasecmp((t), ("off")) == 0)) {
  *b = 0;
  return ((void *)0);
 }
 *b = 0;
 return "invalid";
}

variable_types:
t
char *

variable_types:
b
_Bool *

return_type: char *


decompiled_code:
unsigned __int64 __fastcall dbg_ref(const char *a1, const char *a2, const void *a3, __int64 a4, __int64 a5, __int64 a6)
{
unsigned __int64 v7; // [rsp+8h] [rbp-10h]

v7 = __readfsqword(0x28u);
if ( (cur_debugging & 4) != 0 )
DBG_log(
"%sref %s@%p(%u->%u) (%s() +%lu %s)",
a1,
a2,
a3,
a5,
a6,
*(const char **)a4,
*(_QWORD *)(a4 + 16),
*(const char **)(a4 + 8));
return v7 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(const char *a1, const char *a2, const void *a3, __int64 a4, __int64 a5, __int64 a6)
{
unsigned __int64 v7; // [rsp+8h] [rbp-10h]

v7 = __readfsqword(0x28u);
if ( (cur_debugging & 4) != 0 )
DBG_log(
"%sref %s@%p(%u->%u) (%s() +%lu %s)",
a1,
a2,
a3,
a5,
a6,
*(const char **)a4,
*(_QWORD *)(a4 + 16),
*(const char **)(a4 + 8));
return v7 - __readfsqword(0x28u);
}

original_code:
static void dbg_ref(const char *why, const char *what,
      const void *pointer, where_t where,
      int old_count, int new_count)
{
 if ((cur_debugging & (((lset_t)1 << (DBG_REFCNT_IX))))) {
  DBG_log("%sref %s@%p(%u->%u) ""(%s() +%lu %s)""",
   why, what, pointer, old_count, new_count,
   (where)->func, (where)->line, (where)->file);
 }
}

canonical_original_code:
static void dbg_ref(char *why, char *what, void *pointer, struct where *where, int old_count, int new_count)
{
 if ((cur_debugging & (((unsigned long)1 << (DBG_REFCNT_IX))))) {
  DBG_log("%sref %s@%p(%u->%u) ""(%s() +%lu %s)""",
   why, what, pointer, old_count, new_count,
   (where)->func, (where)->line, (where)->file);
 }
}

variable_types:
why
char *

variable_types:
what
char *

variable_types:
pointer
void *

variable_types: struct where { char *func; char *file; long line; } *


decompiled_code:
unsigned __int64 __fastcall dbg_alloc(const char *a1, const void *a2, __int64 a3)
{
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
dbg_ref("new", a1, a2, a3, 0LL, 1LL);
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(const char *a1, const void *a2, __int64 a3)
{
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
func0("new", a1, a2, a3, 0LL, 1LL);
return v4 - __readfsqword(0x28u);
}

original_code:
void dbg_alloc(const char *what, const void *pointer, where_t where)
{
 dbg_ref("new", what, pointer, where, 0, 1);
}

canonical_original_code:
void dbg_alloc(char *what, void *pointer, struct where *where)
{
 dbg_ref("new", what, pointer, where, 0, 1);
}

user_defined_types: struct where { char *func; char *file; long line; }


decompiled_code:
unsigned __int64 __fastcall dbg_free(const char *a1, const void *a2, __int64 a3)
{
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
dbg_ref("del", a1, a2, a3, 1LL, 0LL);
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(const char *a1, const void *a2, __int64 a3)
{
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
func0("del", a1, a2, a3, 1LL, 0LL);
return v4 - __readfsqword(0x28u);
}

original_code:
void dbg_free(const char *what, const void *pointer, where_t where)
{
 dbg_ref("del", what, pointer, where, 1, 0);
}

canonical_original_code:
void dbg_free(char *what, void *pointer, struct where *where)
{
 dbg_ref("del", what, pointer, where, 1, 0);
}


decompiled_code:
unsigned __int64 __fastcall refcnt_init(const void *a1, int *a2, const char **a3, __int64 a4)
{
unsigned int v6; // er14
unsigned int v7; // er15
unsigned __int64 v9; // [rsp+8h] [rbp-40h]

v9 = __readfsqword(0x28u);
pthread_mutex_lock(&refcnt_mutex);
v6 = (*a2)++;
*((_QWORD *)a2 + 1) = a3;
v7 = *a2;
pthread_mutex_unlock(&refcnt_mutex);
if ( v6 || v7 != 1 )
llog_pexpect(&global_logger, a4, "refcnt for %s@%p should have been 0 initialized", *a3, a1);
dbg_ref("new", **((const char ***)a2 + 1), a1, a4, v6, v7);
return v9 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(const void *a1, int *a2, const char **a3, __int64 a4)
{
unsigned int v6; // er14
unsigned int v7; // er15
unsigned __int64 v9; // [rsp+8h] [rbp-40h]

v9 = __readfsqword(0x28u);
pthread_mutex_lock(&refcnt_mutex);
v6 = (*a2)++;
*((_QWORD *)a2 + 1) = a3;
v7 = *a2;
pthread_mutex_unlock(&refcnt_mutex);
if ( v6 || v7 != 1 )
llog_pexpect(&global_logger, a4, "refcnt for %s@%p should have been 0 initialized", *a3, a1);
func0("new", **((const char ***)a2 + 1), a1, a4, v6, v7);
return v9 - __readfsqword(0x28u);
}

original_code:
void refcnt_init(const void *pointer, struct refcnt *refcnt,
   const struct refcnt_base *base,
   const struct where *where)
{
 unsigned old, new;
 pthread_mutex_lock(&refcnt_mutex);
 {
  old = refcnt->count;
  refcnt->count++;
  refcnt->base = base;
  new = refcnt->count;
 }
 pthread_mutex_unlock(&refcnt_mutex);
 if (old != 0 || new != 1) {
  llog_pexpect(&global_logger, where, "refcnt for %s@%p should have been 0 initialized",
       base->what, pointer);
 }
 dbg_ref("new", refcnt->base->what, pointer, where, old, new);
}

canonical_original_code:
void refcnt_init(void *pointer, struct refcnt *refcnt, struct refcnt_base *base, struct where *where)
{
 unsigned int old; unsigned int new;
 pthread_mutex_lock(&refcnt_mutex);
 {
  old = refcnt->count;
  refcnt->count++;
  refcnt->base = base;
  new = refcnt->count;
 }
 pthread_mutex_unlock(&refcnt_mutex);
 if (old != 0 || new != 1) {
  llog_pexpect(&global_logger, where, "refcnt for %s@%p should have been 0 initialized",
       base->what, pointer);
 }
 dbg_ref("new", refcnt->base->what, pointer, where, old, new);
}

variable_types: struct refcnt { unsigned int count; struct refcnt_base { char *what; } *base; } *

variable_types:
base
struct refcnt_base *

variable_types:
old
unsigned int

variable_types:
new
unsigned int

user_defined_types: struct refcnt { unsigned int count; struct refcnt_base *base; }


decompiled_code:
unsigned __int64 __fastcall refcnt_addref_where(const char *a1, const void *a2, int *a3, __int64 a4)
{
unsigned int v6; // er14
unsigned int v7; // er15
unsigned __int64 v9; // [rsp+8h] [rbp-40h]

v9 = __readfsqword(0x28u);
if ( a2 )
{
pthread_mutex_lock(&refcnt_mutex);
v6 = (*a3)++;
v7 = *a3;
pthread_mutex_unlock(&refcnt_mutex);
if ( !v6 )
llog_pexpect(&global_logger, a4, "refcnt for %s@%p should have been non-0", a1, a2);
dbg_ref("add", **((const char ***)a3 + 1), a2, a4, v6, v7);
}
else if ( (cur_debugging & 1) != 0 )
{
DBG_log("addref %s@NULL (%s() +%lu %s)", a1, *(const char **)a4, *(_QWORD *)(a4 + 16), *(const char **)(a4 + 8));
}
return v9 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(const char *a1, const void *a2, int *a3, __int64 a4)
{
unsigned int v6; // er14
unsigned int v7; // er15
unsigned __int64 v9; // [rsp+8h] [rbp-40h]

v9 = __readfsqword(0x28u);
if ( a2 )
{
pthread_mutex_lock(&refcnt_mutex);
v6 = (*a3)++;
v7 = *a3;
pthread_mutex_unlock(&refcnt_mutex);
if ( !v6 )
llog_pexpect(&global_logger, a4, "refcnt for %s@%p should have been non-0", a1, a2);
func0("add", **((const char ***)a3 + 1), a2, a4, v6, v7);
}
else if ( (cur_debugging & 1) != 0 )
{
DBG_log("addref %s@NULL (%s() +%lu %s)", a1, *(const char **)a4, *(_QWORD *)(a4 + 16), *(const char **)(a4 + 8));
}
return v9 - __readfsqword(0x28u);
}

original_code:
void refcnt_addref_where(const char *what, const void *pointer,
    refcnt_t *refcnt, where_t where)
{
 if (pointer == ((void *)0)) {
  { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("addref %s@NULL ""(%s() +%lu %s)""", what, (where)->func, (where)->line, (where)->file); } };
  return;
 }
 unsigned old, new;
 pthread_mutex_lock(&refcnt_mutex);
 {
  old = refcnt->count;
  refcnt->count++;
  new = refcnt->count;
 }
 pthread_mutex_unlock(&refcnt_mutex);
 if (old == 0) {
  llog_pexpect(&global_logger, where, "refcnt for %s@%p should have been non-0",
       what, pointer);
 }
 dbg_ref("add", refcnt->base->what, pointer, where, old, new);
}

canonical_original_code:
void refcnt_addref_where(char *what, void *pointer, struct refcnt *refcnt, struct where *where)
{
 if (pointer == ((void *)0)) {
  { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("addref %s@NULL ""(%s() +%lu %s)""", what, (where)->func, (where)->line, (where)->file); } };
  return;
 }
 unsigned int old; unsigned int new;
 pthread_mutex_lock(&refcnt_mutex);
 {
  old = refcnt->count;
  refcnt->count++;
  new = refcnt->count;
 }
 pthread_mutex_unlock(&refcnt_mutex);
 if (old == 0) {
  llog_pexpect(&global_logger, where, "refcnt for %s@%p should have been non-0",
       what, pointer);
 }
 dbg_ref("add", refcnt->base->what, pointer, where, old, new);
}


decompiled_code:
__int64 __fastcall refcnt_peek(unsigned int *a1)
{
unsigned int v1; // ebx

pthread_mutex_lock(&refcnt_mutex);
v1 = *a1;
pthread_mutex_unlock(&refcnt_mutex);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
unsigned int v1; // ebx

pthread_mutex_lock(&refcnt_mutex);
v1 = *a1;
pthread_mutex_unlock(&refcnt_mutex);
return v1;
}

original_code:
unsigned refcnt_peek(const refcnt_t *refcnt)
{
 unsigned val;
 pthread_mutex_lock(&refcnt_mutex);
 {
  val = refcnt->count;
 }
 pthread_mutex_unlock(&refcnt_mutex);
 return val;
}

canonical_original_code:
unsigned int refcnt_peek(struct refcnt *refcnt)
{
 unsigned int val;
 pthread_mutex_lock(&refcnt_mutex);
 {
  val = refcnt->count;
 }
 pthread_mutex_unlock(&refcnt_mutex);
 return val;
}

variable_types:
val
unsigned int

return_type: unsigned int


decompiled_code:
char *__fastcall nl_addattr_nest(_DWORD *a1, unsigned __int16 a2, __int16 a3)
{
char *v3; // rbx

v3 = (char *)a1 + ((*a1 + 3) & 0xFFFFFFFC);
nl_addattr_l(a1, a2, a3, 0LL, 0);
return v3;
}

canonical_decompiled_code:
char *__fastcall func1(_DWORD *a1, unsigned __int16 a2, __int16 a3)
{
char *v3; // rbx

v3 = (char *)a1 + ((*a1 + 3) & 0xFFFFFFFC);
func0(a1, a2, a3, 0LL, 0);
return v3;
}

original_code:
struct rtattr *nl_addattr_nest(struct nlmsghdr *n, int maxlen, int type)
{
 struct rtattr *nest = ((struct rtattr *) (((void *) (n)) + ( (((n)->nlmsg_len)+4U -1) & ~(4U -1) )));
 nl_addattr_l(n, maxlen, type, ((void *)0), 0);
 return nest;
}

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types: maxlen int

variable_types: type int

variable_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; } *


decompiled_code:
unsigned __int64 __fastcall nl_addattr_nest_end(_WORD *a1, _WORD *a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
*a2 = ((*a1 + 3) & 0xFFFC) + (_WORD)a1 - (_WORD)a2;
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(_WORD *a1, _WORD *a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
*a2 = ((*a1 + 3) & 0xFFFC) + (_WORD)a1 - (_WORD)a2;
return v3 - __readfsqword(0x28u);
}

original_code:
void nl_addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest)
{
 nest->rta_len = (void *)((struct rtattr *) (((void *) (n)) + ( (((n)->nlmsg_len)+4U -1) & ~(4U -1) ))) - (void *)nest;
}

user_defined_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; }

user_defined_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; }


decompiled_code:
unsigned __int64 __fastcall nl_addattrstrz(_DWORD *a1, unsigned __int16 a2, __int16 a3, const char *a4)
{
int v6; // eax
unsigned __int64 v8; // [rsp+8h] [rbp-30h]

v8 = __readfsqword(0x28u);
v6 = strlen(a4);
nl_addattr_l(a1, a2, a3, a4, v6 + 1);
return v8 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(_DWORD *a1, unsigned __int16 a2, __int16 a3, const char *a4)
{
int v6; // eax
unsigned __int64 v8; // [rsp+8h] [rbp-30h]

v8 = __readfsqword(0x28u);
v6 = strlen(a4);
func0(a1, a2, a3, a4, v6 + 1);
return v8 - __readfsqword(0x28u);
}

original_code:
void nl_addattrstrz(struct nlmsghdr *n, int maxlen, int type, const char *str )
{
 nl_addattr_l(n, maxlen, type, str, strlen(str)+1);
}

canonical_original_code:
void nl_addattrstrz(struct nlmsghdr *n, int maxlen, int type, char *str)
{
 nl_addattr_l(n, maxlen, type, str, strlen(str)+1);
}

variable_types:
str
char *


decompiled_code:
unsigned __int64 __fastcall nl_addattr32(_DWORD *a1, unsigned __int16 a2, __int16 a3, int a4)
{
int v5[3]; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned __int64 v6; // [rsp+18h] [rbp-10h]

v5[0] = a4;
v6 = __readfsqword(0x28u);
nl_addattr_l(a1, a2, a3, v5, 4);
return v6 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(_DWORD *a1, unsigned __int16 a2, __int16 a3, int a4)
{
int v5[3]; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned __int64 v6; // [rsp+18h] [rbp-10h]

v5[0] = a4;
v6 = __readfsqword(0x28u);
func0(a1, a2, a3, v5, 4);
return v6 - __readfsqword(0x28u);
}

original_code:
void nl_addattr32(struct nlmsghdr *n, int maxlen, int type, const uint32_t data)
{
 nl_addattr_l(n, maxlen, type, &data, sizeof(uint32_t));
}

canonical_original_code:
void nl_addattr32(struct nlmsghdr *n, int maxlen, int type, unsigned int data)
{
 nl_addattr_l(n, maxlen, type, &data, sizeof(unsigned int));
}

variable_types:
data
unsigned int


decompiled_code:
unsigned __int64 __fastcall jam_va_nss_error_code(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
unsigned __int64 v7; // [rsp+8h] [rbp-30h]

v7 = __readfsqword(0x28u);
jam(a1, "NSS: ");
jam_va_list(a1, a3, a4);
jam(a1, ": ");
jam_nss_error_code(a1, a2);
return v7 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
unsigned __int64 v7; // [rsp+8h] [rbp-30h]

v7 = __readfsqword(0x28u);
jam(a1, "NSS: ");
jam_va_list(a1, a3, a4);
jam(a1, ": ");
jam_nss_error_code(a1, a2);
return v7 - __readfsqword(0x28u);
}

original_code:
__attribute__((format(printf, 3, 0)))
static void jam_va_nss_error_code(struct jambuf *buf, PRErrorCode code,
      const char *message, va_list ap)
{
 jam(buf, "NSS: ");
 jam_va_list(buf, message, ap);
 __builtin_va_end(ap);
 jam(buf, ": ");
 jam_nss_error_code(buf, code);
}

canonical_original_code:
static void jam_va_nss_error_code(struct jambuf *buf, int code, char *message, __builtin_va_list ap)
{
 jam(buf, "NSS: ");
 jam_va_list(buf, message, ap);
 __builtin_va_end(ap);
 jam(buf, ": ");
 jam_nss_error_code(buf, code);
}

variable_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; } *

variable_types: code int

variable_types:
message
char *


decompiled_code:
void *__fastcall bool_str(char a1)
{
void *result; // rax

result = &LC0;
if ( !a1 )
result = &LC1;
return result;
}

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

result = &LC0;
if ( !a1 )
result = &LC1;
return result;
}

original_code:
const char *bool_str(_Bool b)
{
 return b ? "yes" : "no";
}


decompiled_code:
unsigned __int64 init_constants()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
check_enum_names(&en_checklist, 64LL);
enum_enum_table(&v2_transform_ID_enums, -42LL);
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func3()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
check_enum_names(&en_checklist, 64LL);
enum_enum_table(&v2_transform_ID_enums, -42LL);
return v1 - __readfsqword(0x28u);
}

original_code:
void init_constants(void)
{
 check_enum_names((en_checklist), (sizeof(en_checklist) / sizeof(*(en_checklist))));
 (void) enum_enum_table(&v2_transform_ID_enums, -42UL);
}

canonical_original_code:
void init_constants()
{
 check_enum_names((en_checklist), (sizeof(en_checklist) / sizeof(*(en_checklist))));
 (void) enum_enum_table(&v2_transform_ID_enums, -42UL);
}


decompiled_code:
void __fastcall libreswan_bad_case(const char *a1, __int64 a2, __int64 a3)
{
llog_passert(&global_logger, a3, "switch (%s) case %ld (0x%lx) unexpected", a1, a2, a2);
JUMPOUT(0x33LL);
}

canonical_decompiled_code:
void __fastcall func0(const char *a1, __int64 a2, __int64 a3)
{
llog_passert(&global_logger, a3, "switch (%s) case %ld (0x%lx) unexpected", a1, a2, a2);
JUMPOUT(0x33LL);
}

original_code:
void libreswan_bad_case(const char *expression, long value, where_t where)
{
 llog_passert(&global_logger, where,
       "switch (%s) case %ld (0x%lx) unexpected",
       expression, value, value);
}

canonical_original_code:
void libreswan_bad_case(char *expression, long value, struct where *where)
{
 llog_passert(&global_logger, where,
       "switch (%s) case %ld (0x%lx) unexpected",
       expression, value, value);
}

variable_types:
expression
char *

variable_types: value long


decompiled_code:
__int64 __fastcall all_zero(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rsi

if ( !a2 )
return 1LL;
v2 = a1;
v3 = &a1[a2];
while ( !*v2 )
{
if ( ++v2 == v3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rsi

if ( !a2 )
return 1LL;
v2 = a1;
v3 = &a1[a2];
while ( !*v2 )
{
if ( ++v2 == v3 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool all_zero(const unsigned char *m, size_t len)
{
 size_t i;
 for (i = 0; i != len; i++)
  if (m[i] != '\0')
   return 0;
 return 1;
}

canonical_original_code:
_Bool all_zero(unsigned char *m, unsigned long len)
{
 unsigned long i;
 for (i = 0; i != len; i++)
  if (m[i] != '\0')
   return 0;
 return 1;
}

variable_types:
m
unsigned char *

variable_types:
len
unsigned long

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall fuzz_rekey_margin(__int64 a1, unsigned int a2, int a3)
{
int v3; // eax

if ( a2 == 1 )
{
v3 = get_rnd_uintmax((unsigned int)(a3 + 1));
deltatime_scale(a1, (unsigned int)(v3 + 100), 100LL);
}
else
{
if ( a2 != 2 )
libreswan_bad_case("role", a2, here_6);
deltatime_scale(a1, 1LL, 2LL);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, int a3)
{
int v3; // eax

if ( a2 == 1 )
{
v3 = get_rnd_uintmax((unsigned int)(a3 + 1));
deltatime_scale(a1, (unsigned int)(v3 + 100), 100LL);
}
else
{
if ( a2 != 2 )
libreswan_bad_case("role", a2, here_6);
deltatime_scale(a1, 1LL, 2LL);
}
return a1;
}

original_code:
deltatime_t fuzz_rekey_margin(enum sa_role role, deltatime_t marg, unsigned fuzz_percent)
{
 switch (role) {
 case SA_INITIATOR:
  return deltatime_scale(marg,
           100 + get_rnd_uintmax( fuzz_percent + 1),
           100);
 case SA_RESPONDER:
  return deltatime_scale(marg, 1, 2);
 default:
  libreswan_bad_case("role", (role), ({ static const struct where here = { .func = __func__, .file = "programs/pluto/rekeyfuzz.c", .line = 55, }; &here; }));
 }
}

canonical_original_code:
struct deltatime_t fuzz_rekey_margin(enum sa_role role, struct deltatime_t marg, unsigned int fuzz_percent)
{
 switch (role) {
 case SA_INITIATOR:
  return deltatime_scale(marg,
           100 + get_rnd_uintmax( fuzz_percent + 1),
           100);
 case SA_RESPONDER:
  return deltatime_scale(marg, 1, 2);
 default:
  libreswan_bad_case("role", (role), ({ static struct where here = { .func = __func__, .file = "programs/pluto/rekeyfuzz.c", .line = 55, }; &here; }));
 }
}

variable_types: enum sa_role { SA_INITIATOR=1, SA_RESPONDER=2 }

variable_types:
marg
struct deltatime_t

variable_types: struct where { char *func; char *file; long line; }

return_type: struct deltatime_t { struct timeval { long tv_sec; long tv_usec; } dt; _Bool is_set; }

user_defined_types: struct deltatime_t { struct timeval dt; _Bool is_set; }


decompiled_code:
__int64 __fastcall create_ppk_id_payload(const __m128i *a1, __int64 a2)
{
*(_DWORD *)a2 = 2;
*(__m128i *)(a2 + 8) = _mm_loadu_si128(a1);
return 1LL;
}

original_code:
_Bool create_ppk_id_payload(chunk_t *ppk_id, struct ppk_id_payload *payl)
{
 payl->type = PPK_ID_FIXED;
 payl->ppk_id = *ppk_id;
 return 1;
}

canonical_original_code:
_Bool create_ppk_id_payload(struct chunk_t *ppk_id, struct ppk_id_payload *payl)
{
 payl->type = PPK_ID_FIXED;
 payl->ppk_id = *ppk_id;
 return 1;
}

variable_types: struct chunk_t { unsigned char *ptr; unsigned long len; } *

variable_types: struct ppk_id_payload { enum ikev2_ppk_id_type { PPK_ID_OPAQUE=1, PPK_ID_FIXED=2 } type; struct chunk_t ppk_id; } *

user_defined_types: struct ppk_id_payload { enum ikev2_ppk_id_type type; struct chunk_t ppk_id; }


decompiled_code:
__int64 __fastcall jam_port_range(__int64 a1, __int64 a2, unsigned int a3)
{
if ( !(_BYTE)a2 )
return jam(a1, "<unset-port-range>");
if ( HIDWORD(a2) == a3 )
return jam(a1, "%u", HIDWORD(a2));
return jam(a1, "%u-%u", HIDWORD(a2), a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3)
{
if ( !(_BYTE)a2 )
return jam(a1, "<unset-port-range>");
if ( HIDWORD(a2) == a3 )
return jam(a1, "%u", HIDWORD(a2));
return jam(a1, "%u-%u", HIDWORD(a2), a3);
}

original_code:
size_t jam_port_range(struct jambuf *buf, ip_port_range r)
{
 if (!r.is_set) {
  return jam(buf, "<unset-port-range>");
 }
 if (r.lo == r.hi) {
  return jam(buf, "%u", r.lo);
 } else {
  return jam(buf, "%u-%u", r.lo, r.hi);
 }
}

canonical_original_code:
unsigned long jam_port_range(struct jambuf *buf, struct ip_port_range r)
{
 if (!r.is_set) {
  return jam(buf, "<unset-port-range>");
 }
 if (r.lo == r.hi) {
  return jam(buf, "%u", r.lo);
 } else {
  return jam(buf, "%u-%u", r.lo, r.hi);
 }
}

variable_types: struct ip_port_range { _Bool is_set; unsigned int lo; unsigned int hi; }

return_type: unsigned long

user_defined_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; }


decompiled_code:
__int64 __fastcall str_port_range(__int64 a1, unsigned int a2, __int64 a3)
{
char v5[40]; // [rsp+10h] [rbp-48h] BYREF
unsigned __int64 v6; // [rsp+38h] [rbp-20h]

v6 = __readfsqword(0x28u);
array_as_jambuf(v5, a3, 13LL);
jam_port_range((__int64)v5, a1, a2);
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, __int64 a3)
{
char v5[40]; // [rsp+10h] [rbp-48h] BYREF
unsigned __int64 v6; // [rsp+38h] [rbp-20h]

v6 = __readfsqword(0x28u);
array_as_jambuf(v5, a3, 13LL);
func1((__int64)v5, a1, a2);
return a3;
}

original_code:
const char *str_port_range(ip_port_range port, port_range_buf *buf)
{
 struct jambuf jambuf = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_port_range(&jambuf, port);
 return buf->buf;
}

canonical_original_code:
char *str_port_range(struct ip_port_range port, struct port_range_buf *buf)
{
 struct jambuf jambuf = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_port_range(&jambuf, port);
 return buf->buf;
}

variable_types: struct port_range_buf { char buf[-1]; } *

variable_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; }

user_defined_types: struct ip_port_range { _Bool is_set; unsigned int lo; unsigned int hi; }


decompiled_code:
__int64 __fastcall vid_is_oppo(void *s1, size_t n)
{
const void *v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // edx
const void *v7; // rsi
int v8; // eax

v2 = (const void *)shunk_from_vendorid(66LL);
v4 = v3;
v5 = 0;
if ( n == v4 )
{
v7 = v2;
v8 = memcmp(s1, v2, n);
v5 = 0;
if ( !v8 )
{
v5 = 1;
if ( (cur_debugging & 1) != 0 )
{
DBG_log("VID_OPPORTUNISTIC received", v7, 1LL);
v5 = 1;
}
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *s1, size_t n)
{
const void *v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // edx
const void *v7; // rsi
int v8; // eax

v2 = (const void *)shunk_from_vendorid(66LL);
v4 = v3;
v5 = 0;
if ( n == v4 )
{
v7 = v2;
v8 = memcmp(s1, v2, n);
v5 = 0;
if ( !v8 )
{
v5 = 1;
if ( (cur_debugging & 1) != 0 )
{
DBG_log("VID_OPPORTUNISTIC received", v7, 1LL);
v5 = 1;
}
}
}
return v5;
}

original_code:
_Bool vid_is_oppo(const char *vid, size_t len)
{
 shunk_t oppo = shunk_from_vendorid(VID_OPPORTUNISTIC);
 if (oppo.len == len && (memcmp((vid), (oppo.ptr), (len)) == 0)) {
  { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("VID_OPPORTUNISTIC received"); } };
  return 1;
 } else {
  return 0;
 }
}

canonical_original_code:
_Bool vid_is_oppo(char *vid, unsigned long len)
{
 struct shunk oppo = shunk_from_vendorid(VID_OPPORTUNISTIC);
 if (oppo.len == len && (memcmp((vid), (oppo.ptr), (len)) == 0)) {
  { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("VID_OPPORTUNISTIC received"); } };
  return 1;
 } else {
  return 0;
 }
}

variable_types:
vid
char *

variable_types: struct shunk { void *ptr; unsigned long len; }


decompiled_code:
__int64 __fastcall str_protoport(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
_QWORD v4[9]; // [rsp+0h] [rbp-48h] BYREF

v4[5] = __readfsqword(0x28u);
v2 = array_as_jambuf(v4, a2, 67LL);
jam_protoport((__int64)v4, a1, v2);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
_QWORD v4[9]; // [rsp+0h] [rbp-48h] BYREF

v4[5] = __readfsqword(0x28u);
v2 = array_as_jambuf(v4, a2, 67LL);
func1((__int64)v4, a1, v2);
return a2;
}

original_code:
const char *str_protoport(const ip_protoport *protoport, protoport_buf *buf)
{
 struct jambuf jambuf = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_protoport(&jambuf, protoport);
 return buf->buf;
}

canonical_original_code:
char *str_protoport(struct ip_protoport *protoport, struct protoport_buf *buf)
{
 struct jambuf jambuf = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_protoport(&jambuf, protoport);
 return buf->buf;
}

variable_types: struct ip_protoport { _Bool is_set; _Bool has_port_wildcard; unsigned int hport; unsigned int ipproto; } *

variable_types: struct protoport_buf { char buf[-1]; } *


decompiled_code:
__int64 __fastcall jam_nss_secitem(__int64 a1, __int64 a2)
{
if ( !a2 )
return jam_string(a1, "(SECItem*)NULL");
jam_nss_secitemtype(a1, *(_DWORD *)a2);
jam(a1, ": ");
jam_dump_bytes(a1, *(_QWORD *)(a2 + 8), *(unsigned int *)(a2 + 16));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
if ( !a2 )
return jam_string(a1, "(SECItem*)NULL");
func0(a1, *(_DWORD *)a2);
jam(a1, ": ");
jam_dump_bytes(a1, *(_QWORD *)(a2 + 8), *(unsigned int *)(a2 + 16));
return 0LL;
}

original_code:
size_t jam_nss_secitem(struct jambuf *buf, const SECItem *secitem)
{
 size_t size = 0;
 if (secitem == ((void *)0)) {
  size = jam_string(buf, "(SECItem*)NULL");
 } else {
  jam_nss_secitemtype(buf, secitem->type);
  jam(buf, ": ");
  jam_dump_bytes(buf, secitem->data, secitem->len);
 }
 return size;
}

canonical_original_code:
unsigned long jam_nss_secitem(struct jambuf *buf, struct SECItemStr *secitem)
{
 unsigned long size = 0;
 if (secitem == ((void *)0)) {
  size = jam_string(buf, "(SECItem*)NULL");
 } else {
  jam_nss_secitemtype(buf, secitem->type);
  jam(buf, ": ");
  jam_dump_bytes(buf, secitem->data, secitem->len);
 }
 return size;
}

variable_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; } *

variable_types: struct SECItemStr { enum SECItemType { siBuffer=0, siClearDataBuffer=1, siCipherDataBuffer=2, siDERCertBuffer=3, siEncodedCertBuffer=4, siDERNameBuffer=5, siEncodedNameBuffer=6, siAsciiNameString=7, siAsciiString=8, siDEROID=9, siUnsignedInteger=10, siUTCTime=11, siGeneralizedTime=12, siVisibleString=13, siUTF8String=14, siBMPString=15 } type; unsigned char *data; unsigned int len; } *

variable_types:
size
unsigned long

user_defined_types: struct SECItemStr { enum SECItemType type; unsigned char *data; unsigned int len; }


decompiled_code:
unsigned __int64 __fastcall free_messages(__int64 *a1)
{
__int64 i; // rbx
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
for ( i = *a1; *a1; i = *a1 )
{
*a1 = *(_QWORD *)(i + 16);
free_chunk_content(i);
pfree(i);
}
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 *a1)
{
__int64 i; // rbx
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
for ( i = *a1; *a1; i = *a1 )
{
*a1 = *(_QWORD *)(i + 16);
free_chunk_content(i);
pfree(i);
}
return v3 - __readfsqword(0x28u);
}

original_code:
static void free_messages(struct message **messages)
{
 while (*messages != ((void *)0)) {
  struct message *m = (*messages);
  *messages = m->next;
  free_chunk_content(&m->body);
  pfree(m);
 }
}

variable_types: struct message { struct chunk_t { unsigned char *ptr; unsigned long len; } body; struct message *next; } **

user_defined_types: struct message { struct chunk_t body; struct message *next; }


decompiled_code:
__int64 gng_vh_start()
{
__int64 v0; // rax
__int64 v2; // [rsp+0h] [rbp-18h]

fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 2LL, 16LL, 16LL, 32LL, v2);
bg_tilemap = v0;
if ( !v0 || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 3;
*(_DWORD *)(v0 + 136) = 255;
*(_DWORD *)(v0 + 140) = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 v2; // [rsp+0h] [rbp-18h]

fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 2LL, 16LL, 16LL, 32LL, v2);
bg_tilemap = v0;
if ( !v0 || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 3;
*(_DWORD *)(v0 + 136) = 255;
*(_DWORD *)(v0 + 140) = 1;
return 0LL;
}

original_code:
int gng_vh_start(void)
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x02, 16,16,32,32);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 3;
 bg_tilemap->transmask[0] = 0xff;
 bg_tilemap->transmask[1] = 0x01;
 return 0;
}

canonical_original_code:
int gng_vh_start()
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x02, 16,16,32,32);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 3;
 bg_tilemap->transmask[0] = 0xff;
 bg_tilemap->transmask[1] = 0x01;
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall gng_bgscrollx_w(int a1, char a2)
{
scrollx_2[a1] = a2;
return tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned __int8)scrollx_2[0] + ((unsigned __int8)byte_CF3 << 8));
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, char a2)
{
scrollx_2[a1] = a2;
return tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned __int8)scrollx_2[0] + ((unsigned __int8)byte_CF3 << 8));
}

original_code:
void gng_bgscrollx_w(offs_t offset,data_t data)
{
 static unsigned char scrollx[2];
 scrollx[offset] = data;
 tilemap_set_scrollx( bg_tilemap, 0, scrollx[0] + 256 * scrollx[1] );
}

canonical_original_code:
void gng_bgscrollx_w(unsigned int offset, unsigned int data)
{
 static unsigned char scrollx[2];
 scrollx[offset] = data;
 tilemap_set_scrollx( bg_tilemap, 0, scrollx[0] + 256 * scrollx[1] );
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types:
scrollx
unsigned char [2]


decompiled_code:
__int64 __fastcall gng_bgscrolly_w(int a1, char a2)
{
scrolly_1[a1] = a2;
return tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned __int8)scrolly_1[0] + ((unsigned __int8)byte_CF1 << 8));
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, char a2)
{
scrolly_1[a1] = a2;
return tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned __int8)scrolly_1[0] + ((unsigned __int8)byte_CF1 << 8));
}

original_code:
void gng_bgscrolly_w(offs_t offset,data_t data)
{
 static unsigned char scrolly[2];
 scrolly[offset] = data;
 tilemap_set_scrolly( bg_tilemap, 0, scrolly[0] + 256 * scrolly[1] );
}

canonical_original_code:
void gng_bgscrolly_w(unsigned int offset, unsigned int data)
{
 static unsigned char scrolly[2];
 scrolly[offset] = data;
 tilemap_set_scrolly( bg_tilemap, 0, scrolly[0] + 256 * scrolly[1] );
}

variable_types:
scrolly
unsigned char [2]


decompiled_code:
__int64 __fastcall gng_flipscreen_w(__int64 a1, char a2)
{
flipscreen = (a2 & 1) == 0;
return tilemap_set_flip(0LL, -flipscreen & 3);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
flipscreen = (a2 & 1) == 0;
return tilemap_set_flip(0LL, -flipscreen & 3);
}

original_code:
void gng_flipscreen_w(offs_t offset,data_t data)
{
 flipscreen = ~data & 1;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
}

canonical_original_code:
void gng_flipscreen_w(unsigned int offset, unsigned int data)
{
 flipscreen = ~data & 1;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
}


decompiled_code:
__int64 __fastcall gng_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
draw_sprites(a1);
tilemap_draw(a1, bg_tilemap, 64LL);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
func6(a1);
tilemap_draw(a1, bg_tilemap, 64LL);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

original_code:
void gng_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0x20);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,0x40);
 tilemap_draw(bitmap,fg_tilemap,0);
}

canonical_original_code:
void gng_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0x20);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,0x40);
 tilemap_draw(bitmap,fg_tilemap,0);
}

variable_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *


decompiled_code:
void *__fastcall gng_bankswitch_w(__int64 a1, int a2)
{
void *result; // rax
unsigned int v3; // eax

cpu_bankbase[1] = bank_0[a2] + memory_region(129LL);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, int a2)
{
void *result; // rax
unsigned int v3; // eax

cpu_bankbase[1] = bank_0[a2] + memory_region(129LL);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
void gng_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 static int bank[] = { 0x10000, 0x12000, 0x14000, 0x16000, 0x04000, 0x18000 };
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bank[data]]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
void gng_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 static int bank[] = { 0x10000, 0x12000, 0x14000, 0x16000, 0x04000, 0x18000 };
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bank[data]]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
RAM
unsigned char *

variable_types:
bank
int []


decompiled_code:
void *__fastcall get_fg_tile_info(int a1)
{
__int64 v1; // rax
unsigned __int8 v2; // cl
__int64 v3; // rsi
int v4; // edi
signed int v5; // edx
__int64 v6; // rax
int v7; // ecx
void *result; // rax

v1 = a1;
v2 = *(_BYTE *)(gng_fgcolorram + a1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = v2;
v5 = (*(unsigned __int8 *)(gng_fgvideoram + v1) + ((4 * v2) & 0x300u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v5;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0xF);
v6 = *(_QWORD *)(v3 + 32);
v7 = 0;
if ( v6 )
v7 = *(_DWORD *)(v6 + 4LL * v5);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v7;
*((_DWORD *)&tile_info + 5) = (v4 >> 4) & 3;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
__int64 v1; // rax
unsigned __int8 v2; // cl
__int64 v3; // rsi
int v4; // edi
signed int v5; // edx
__int64 v6; // rax
int v7; // ecx
void *result; // rax

v1 = a1;
v2 = *(_BYTE *)(gng_fgcolorram + a1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = v2;
v5 = (*(unsigned __int8 *)(gng_fgvideoram + v1) + ((4 * v2) & 0x300u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v5;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0xF);
v6 = *(_QWORD *)(v3 + 32);
v7 = 0;
if ( v6 )
v7 = *(_DWORD *)(v6 + 4LL * v5);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v7;
*((_DWORD *)&tile_info + 5) = (v4 >> 4) & 3;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = gng_fgcolorram[tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (gng_fgvideoram[tile_index] + ((attr & 0xc0) << 2)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x0f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0x30) >> 4);
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = gng_fgcolorram[tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (gng_fgvideoram[tile_index] + ((attr & 0xc0) << 2)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x0f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0x30) >> 4);
}

variable_types:
attr
unsigned char

variable_types: struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; } *


decompiled_code:
__int64 __fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rax
unsigned __int8 v2; // cl
__int64 v3; // rdi
int v4; // esi
signed int v5; // edx
__int64 v6; // rcx
int v7; // eax
__int64 result; // rax

v1 = a1;
v2 = *(_BYTE *)(gng_bgcolorram + a1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = v2;
v5 = (*(unsigned __int8 *)(gng_bgvideoram + v1) + ((4 * v2) & 0x300u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v5;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 7);
v6 = *(_QWORD *)(v3 + 32);
v7 = 0;
if ( v6 )
v7 = *(_DWORD *)(v6 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = v7;
result = ((unsigned int)v4 >> 1) & 4;
*((_DWORD *)&tile_info + 5) = result | (v4 >> 4) & 3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rax
unsigned __int8 v2; // cl
__int64 v3; // rdi
int v4; // esi
signed int v5; // edx
__int64 v6; // rcx
int v7; // eax
__int64 result; // rax

v1 = a1;
v2 = *(_BYTE *)(gng_bgcolorram + a1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = v2;
v5 = (*(unsigned __int8 *)(gng_bgvideoram + v1) + ((4 * v2) & 0x300u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v5;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 7);
v6 = *(_QWORD *)(v3 + 32);
v7 = 0;
if ( v6 )
v7 = *(_DWORD *)(v6 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = v7;
result = ((unsigned int)v4 >> 1) & 4;
*((_DWORD *)&tile_info + 5) = result | (v4 >> 4) & 3;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = gng_bgcolorram[tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (gng_bgvideoram[tile_index] + ((attr & 0xc0) << 2)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x07)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0x30) >> 4) | (((attr & 0x08) >> 3)<<2);
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = gng_bgcolorram[tile_index];
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (gng_bgvideoram[tile_index] + ((attr & 0xc0) << 2)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x07)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0x30) >> 4) | (((attr & 0x08) >> 3)<<2);
}

user_defined_types: struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; }


decompiled_code:
void *__fastcall draw_sprites(__int64 a1)
{
__int64 v1; // r14
void *result; // rax
int v3; // ebp
__int64 v4; // rbx

v1 = *(_QWORD *)(Machine + 528LL);
result = &spriteram_size;
v3 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = v3 + 1LL;
do
{
result = (void *)drawgfx(
a1,
v1,
*(unsigned __int8 *)(spriteram + v4 - 1)
+ ((4 * *(unsigned __int8 *)(spriteram + v4)) & 0x300u),
(*(_BYTE *)(spriteram + v4) >> 4) & 3);
v4 -= 4LL;
v3 -= 4;
}
while ( v3 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1)
{
__int64 v1; // r14
void *result; // rax
int v3; // ebp
__int64 v4; // rbx

v1 = *(_QWORD *)(Machine + 528LL);
result = &spriteram_size;
v3 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = v3 + 1LL;
do
{
result = (void *)drawgfx(
a1,
v1,
*(unsigned __int8 *)(spriteram + v4 - 1)
+ ((4 * *(unsigned __int8 *)(spriteram + v4)) & 0x300u),
(*(_BYTE *)(spriteram + v4) >> 4) & 3);
v4 -= 4LL;
v3 -= 4;
}
while ( v3 >= 0 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 const struct GfxElement *gfx = Machine->gfx[2];
 const struct rectangle *clip = &Machine->visible_area;
 int offs;
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4){
  unsigned char attributes = spriteram[offs+1];
  int sx = spriteram[offs + 3] - 0x100 * (attributes & 0x01);
  int sy = spriteram[offs + 2];
  int flipx = attributes & 0x04;
  int flipy = attributes & 0x08;
  if (flipscreen){
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,gfx,
    spriteram[offs] + ((attributes<<2) & 0x300),
    (attributes >> 4) & 3,
    flipx,flipy,
    sx,sy,
    clip,TRANSPARENCY_PEN,15);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 struct GfxElement *gfx = Machine->gfx[2];
 struct rectangle *clip = &Machine->visible_area;
 int offs;
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4){
  unsigned char attributes = spriteram[offs+1];
  int sx = spriteram[offs + 3] - 0x100 * (attributes & 0x01);
  int sy = spriteram[offs + 2];
  int flipx = attributes & 0x04;
  int flipy = attributes & 0x08;
  if (flipscreen){
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,gfx,
    spriteram[offs] + ((attributes<<2) & 0x300),
    (attributes >> 4) & 3,
    flipx,flipy,
    sx,sy,
    clip,TRANSPARENCY_PEN,15);
 }
}

variable_types: struct rectangle { int min_x; int min_y; } *

variable_types: offs int

variable_types:
attributes
unsigned char

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int

user_defined_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; }


original_code:
static UINT32 background_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
{
 return (col & 0x0f) + ((row & 0x0f) << 4) + ((col & 0x10) << 4) + ((row & 0x10) << 5);
}

canonical_original_code:
static unsigned int background_scan(unsigned int col, unsigned int row, unsigned int num_cols, unsigned int num_rows)
{
 return (col & 0x0f) + ((row & 0x0f) << 4) + ((col & 0x10) << 4) + ((row & 0x10) << 5);
}

variable_types:
col
unsigned int

variable_types:
row
unsigned int


decompiled_code:
_DWORD *ddragon_init_machine()
{
_DWORD *result; // rax

sprite_irq = 2;
sound_irq = 1;
ym_irq = 1;
result = dd2_video;
dd2_video[0] = 0;
dd_sub_cpu_busy = 16;
dword_EEC = 1;
adpcm_idle = 1;
return result;
}

canonical_decompiled_code:
_DWORD *func3()
{
_DWORD *result; // rax

sprite_irq = 2;
sound_irq = 1;
ym_irq = 1;
result = dd2_video;
dd2_video[0] = 0;
dd_sub_cpu_busy = 16;
dword_EEC = 1;
adpcm_idle = 1;
return result;
}

original_code:
static void ddragon_init_machine( void )
{
 sprite_irq = 2;
 sound_irq = 1;
 ym_irq = 1;
 dd2_video = 0;
 dd_sub_cpu_busy = 0x10;
 adpcm_idle[0] = adpcm_idle[1] = 1;
}

canonical_original_code:
static void ddragon_init_machine()
{
 sprite_irq = 2;
 sound_irq = 1;
 ym_irq = 1;
 dd2_video = 0;
 dd_sub_cpu_busy = 0x10;
 adpcm_idle[0] = adpcm_idle[1] = 1;
}


decompiled_code:
_DWORD *ddragonb_init_machine()
{
_DWORD *result; // rax

sprite_irq = 4;
sound_irq = 1;
ym_irq = 1;
result = dd2_video;
dd2_video[0] = 0;
dd_sub_cpu_busy = 16;
dword_EEC = 1;
adpcm_idle = 1;
return result;
}

canonical_decompiled_code:
_DWORD *func4()
{
_DWORD *result; // rax

sprite_irq = 4;
sound_irq = 1;
ym_irq = 1;
result = dd2_video;
dd2_video[0] = 0;
dd_sub_cpu_busy = 16;
dword_EEC = 1;
adpcm_idle = 1;
return result;
}

original_code:
static void ddragonb_init_machine( void )
{
 sprite_irq = 4;
 sound_irq = 1;
 ym_irq = 1;
 dd2_video = 0;
 dd_sub_cpu_busy = 0x10;
 adpcm_idle[0] = adpcm_idle[1] = 1;
}

canonical_original_code:
static void ddragonb_init_machine()
{
 sprite_irq = 4;
 sound_irq = 1;
 ym_irq = 1;
 dd2_video = 0;
 dd_sub_cpu_busy = 0x10;
 adpcm_idle[0] = adpcm_idle[1] = 1;
}


decompiled_code:
_DWORD *ddragon2_init_machine()
{
_DWORD *result; // rax

sprite_irq = -2;
sound_irq = -2;
ym_irq = 0;
result = dd2_video;
dd2_video[0] = 1;
dd_sub_cpu_busy = 16;
return result;
}

canonical_decompiled_code:
_DWORD *func5()
{
_DWORD *result; // rax

sprite_irq = -2;
sound_irq = -2;
ym_irq = 0;
result = dd2_video;
dd2_video[0] = 1;
dd_sub_cpu_busy = 16;
return result;
}

original_code:
static void ddragon2_init_machine( void )
{
 sprite_irq = -2;
 sound_irq = -2;
 ym_irq = 0;
 dd2_video = 1;
 dd_sub_cpu_busy = 0x10;
}

canonical_original_code:
static void ddragon2_init_machine()
{
 sprite_irq = -2;
 sound_irq = -2;
 ym_irq = 0;
 dd2_video = 1;
 dd_sub_cpu_busy = 0x10;
}


decompiled_code:
__int64 __fastcall ddragon_spriteram_r(unsigned int a1)
{
return *(unsigned __int8 *)(ddragon_spriteram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
return *(unsigned __int8 *)(ddragon_spriteram + a1);
}

original_code:
static data_t ddragon_spriteram_r(offs_t offset)
{
 return ddragon_spriteram[offset];
}

canonical_original_code:
static unsigned int ddragon_spriteram_r(unsigned int offset)
{
 return ddragon_spriteram[offset];
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 dd_adpcm_status_r()
{
return (unsigned int)(adpcm_idle + 2 * dword_EEC);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)(adpcm_idle + 2 * dword_EEC);
}

original_code:
static data_t dd_adpcm_status_r(offs_t offset)
{
 return adpcm_idle[0] + (adpcm_idle[1] << 1);
}

canonical_original_code:
static unsigned int dd_adpcm_status_r(unsigned int offset)
{
 return adpcm_idle[0] + (adpcm_idle[1] << 1);
}


decompiled_code:
__int64 ddragon_vh_start()
{
__int64 v0; // rax
__int64 v2; // [rsp+0h] [rbp-18h]

bg_tilemap = tilemap_create(get_bg_tile_info, background_scan, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v2);
fg_tilemap = v0;
if ( !bg_tilemap || !v0 )
return 1LL;
*(_DWORD *)(v0 + 132) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rax
__int64 v2; // [rsp+0h] [rbp-18h]

bg_tilemap = tilemap_create(get_bg_tile_info, background_scan, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v2);
fg_tilemap = v0;
if ( !bg_tilemap || !v0 )
return 1LL;
*(_DWORD *)(v0 + 132) = 0;
return 0LL;
}

original_code:
int ddragon_vh_start(void)
{
 bg_tilemap = tilemap_create(get_bg_tile_info,background_scan, 0x00, 16,16,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01, 8, 8,32,32);
 if (!bg_tilemap || !fg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 return 0;
}

canonical_original_code:
int ddragon_vh_start()
{
 bg_tilemap = tilemap_create(get_bg_tile_info,background_scan, 0x00, 16,16,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01, 8, 8,32,32);
 if (!bg_tilemap || !fg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 return 0;
}


decompiled_code:
__int64 __fastcall ddragon_vh_screenrefresh(__int64 a1)
{
unsigned int v1; // ebp

v1 = ddragon_scrolly_hi + (unsigned __int8)*ddragon_scrolly_lo;
tilemap_set_scrollx(bg_tilemap, 0LL, ddragon_scrollx_hi + (unsigned int)(unsigned __int8)*ddragon_scrollx_lo);
tilemap_set_scrolly(bg_tilemap, 0LL, v1);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
draw_sprites(a1);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int v1; // ebp

v1 = ddragon_scrolly_hi + (unsigned __int8)*ddragon_scrolly_lo;
tilemap_set_scrollx(bg_tilemap, 0LL, ddragon_scrollx_hi + (unsigned int)(unsigned __int8)*ddragon_scrollx_lo);
tilemap_set_scrolly(bg_tilemap, 0LL, v1);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
func9(a1);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

original_code:
void ddragon_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int scrollx = ddragon_scrollx_hi + *ddragon_scrollx_lo;
 int scrolly = ddragon_scrolly_hi + *ddragon_scrolly_lo;
 tilemap_set_scrollx(bg_tilemap,0,scrollx);
 tilemap_set_scrolly(bg_tilemap,0,scrolly);
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,fg_tilemap,0);
}

canonical_original_code:
void ddragon_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int scrollx = ddragon_scrollx_hi + *ddragon_scrollx_lo;
 int scrolly = ddragon_scrolly_hi + *ddragon_scrolly_lo;
 tilemap_set_scrollx(bg_tilemap,0,scrollx);
 tilemap_set_scrolly(bg_tilemap,0,scrolly);
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,fg_tilemap,0);
}

variable_types: scrollx int

variable_types: scrolly int


decompiled_code:
__int64 ddragon_interrupt()
{
cpu_set_irq_line(0LL, 1LL, 2LL);
cpu_set_nmi_line(0LL, 3LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
cpu_set_irq_line(0LL, 1LL, 2LL);
cpu_set_nmi_line(0LL, 3LL);
return 0LL;
}

original_code:
static int ddragon_interrupt(void)
{
    cpu_set_irq_line(0, 1, 2);
    cpu_set_nmi_line(0, 3);
    return 0;
}

canonical_original_code:
static int ddragon_interrupt()
{
    cpu_set_irq_line(0, 1, 2);
    cpu_set_nmi_line(0, 3);
    return 0;
}


decompiled_code:
__int64 ddragon_forcedIRQ_w()
{
return cpu_cause_interrupt(0LL, 1LL);
}

canonical_decompiled_code:
__int64 func15()
{
return cpu_cause_interrupt(0LL, 1LL);
}

original_code:
static void ddragon_forcedIRQ_w(offs_t offset,data_t data)
{
 cpu_cause_interrupt( 0, 1 );
}

canonical_original_code:
static void ddragon_forcedIRQ_w(unsigned int offset, unsigned int data)
{
 cpu_cause_interrupt( 0, 1 );
}

variable_types:
data
unsigned int


decompiled_code:
void *__fastcall ddragon_bankswitch_w(__int64 a1, __int16 a2)
{
__int64 v2; // rbp
void *result; // rax
unsigned int v4; // eax

v2 = memory_region(129LL);
ddragon_scrolly_hi = (a2 << 7) & 0x100;
ddragon_scrollx_hi = (a2 << 8) & 0x100;
flip_screen_w(0LL, ~(_BYTE)a2 & 4);
if ( (a2 & 0x10) != 0 )
{
dd_sub_cpu_busy = 0;
}
else if ( !dd_sub_cpu_busy )
{
cpu_cause_interrupt(1LL, (unsigned int)sprite_irq);
}
cpu_bankbase[1] = v2 + (((unsigned int)((unsigned __int8)a2 >> 5) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func17(__int64 a1, __int16 a2)
{
__int64 v2; // rbp
void *result; // rax
unsigned int v4; // eax

v2 = memory_region(129LL);
ddragon_scrolly_hi = (a2 << 7) & 0x100;
ddragon_scrollx_hi = (a2 << 8) & 0x100;
flip_screen_w(0LL, ~(_BYTE)a2 & 4);
if ( (a2 & 0x10) != 0 )
{
dd_sub_cpu_busy = 0;
}
else if ( !dd_sub_cpu_busy )
{
cpu_cause_interrupt(1LL, (unsigned int)sprite_irq);
}
cpu_bankbase[1] = v2 + (((unsigned int)((unsigned __int8)a2 >> 5) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

original_code:
static void ddragon_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 ddragon_scrolly_hi = ( ( data & 0x02 ) << 7 );
 ddragon_scrollx_hi = ( ( data & 0x01 ) << 8 );
 flip_screen_w(0,~data & 0x04);
 if (data & 0x10)
  dd_sub_cpu_busy = 0x00;
 else if (dd_sub_cpu_busy == 0x00)
  cpu_cause_interrupt( 1, sprite_irq );
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[ 0x10000 + ( 0x4000 * ( ( data & 0xe0) >> 5 ) ) ]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void ddragon_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 ddragon_scrolly_hi = ( ( data & 0x02 ) << 7 );
 ddragon_scrollx_hi = ( ( data & 0x01 ) << 8 );
 flip_screen_w(0,~data & 0x04);
 if (data & 0x10)
  dd_sub_cpu_busy = 0x00;
 else if (dd_sub_cpu_busy == 0x00)
  cpu_cause_interrupt( 1, sprite_irq );
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[ 0x10000 + ( 0x4000 * ( ( data & 0xe0) >> 5 ) ) ]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 port4_r()
{
return dd_sub_cpu_busy | (unsigned int)readinputport(4LL);
}

canonical_decompiled_code:
__int64 func18()
{
return dd_sub_cpu_busy | (unsigned int)readinputport(4LL);
}

original_code:
static data_t port4_r(offs_t offset)
{
 int port = readinputport( 4 );
 return port | dd_sub_cpu_busy;
}

canonical_original_code:
static unsigned int port4_r(unsigned int offset)
{
 int port = readinputport( 4 );
 return port | dd_sub_cpu_busy;
}

variable_types: port int


decompiled_code:
void *__fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rax
int v6; // esi
void *result; // rax

v1 = 2 * a1;
v2 = *(_BYTE *)(ddragon_bgvideoram + v1);
v3 = *(_QWORD *)(Machine + 528LL);
v4 = (*(unsigned __int8 *)(ddragon_bgvideoram + v1 + 1) + ((v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * ((v2 >> 3) & 7);
v5 = *(_QWORD *)(v3 + 32);
v6 = 0;
if ( v5 )
v6 = *(_DWORD *)(v5 + 4LL * v4);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v6;
*((_DWORD *)&tile_info + 5) = v2 >> 6;
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
__int64 v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rax
int v6; // esi
void *result; // rax

v1 = 2 * a1;
v2 = *(_BYTE *)(ddragon_bgvideoram + v1);
v3 = *(_QWORD *)(Machine + 528LL);
v4 = (*(unsigned __int8 *)(ddragon_bgvideoram + v1 + 1) + ((v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * ((v2 >> 3) & 7);
v5 = *(_QWORD *)(v3 + 32);
v6 = 0;
if ( v5 )
v6 = *(_DWORD *)(v5 + 4LL * v4);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v6;
*((_DWORD *)&tile_info + 5) = v2 >> 6;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = ddragon_bgvideoram[2*tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (ddragon_bgvideoram[2*tile_index+1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 3) & 0x07)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0xc0) >> 6);
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = ddragon_bgvideoram[2*tile_index];
 { struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (ddragon_bgvideoram[2*tile_index+1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 3) & 0x07)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0xc0) >> 6);
}

variable_types:
attr
unsigned char


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
__int64 v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_BYTE *)(ddragon_fgvideoram + v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(ddragon_fgvideoram + v1 + 1) + ((v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 5);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_BYTE *)(ddragon_fgvideoram + v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(ddragon_fgvideoram + v1 + 1) + ((v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 5);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = ddragon_fgvideoram[2*tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (ddragon_fgvideoram[2*tile_index+1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr >> 5)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = ddragon_fgvideoram[2*tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (ddragon_fgvideoram[2*tile_index+1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr >> 5)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

variable_types: struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; } *


original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 const struct rectangle *clip = &Machine->visible_area;
 const struct GfxElement *gfx = Machine->gfx[1];
 unsigned char *src = &( ddragon_spriteram[0x800] );
 int i;
 for( i = 0; i < ( 64 * 5 ); i += 5 ) {
  int attr = src[i+1];
  if ( attr & 0x80 ) {
   int sx = 240 - src[i+4] + ( ( attr & 2 ) << 7 );
   int sy = 240 - src[i+0] + ( ( attr & 1 ) << 8 );
   int size = ( attr & 0x30 ) >> 4;
   int flipx = ( attr & 8 );
   int flipy = ( attr & 4 );
   int dx = -16,dy = -16;
   int which;
   int color;
   if ( dd2_video ) {
    color = ( src[i+2] >> 5 );
    which = src[i+3] + ( ( src[i+2] & 0x1f ) << 8 );
   } else {
    color = ( src[i+2] >> 4 ) & 0x07;
    which = src[i+3] + ( ( src[i+2] & 0x0f ) << 8 );
   }
   if (flip_screen_x)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
    dx = -dx;
    dy = -dy;
   }
   switch ( size ) {
    case 0:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 1:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+1),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 2:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx + dx,sy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+2),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 3:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx + dx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+1),color,flipx,flipy,sx + dx,sy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+2),color,flipx,flipy,sx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+3),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
   }
  }
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 struct rectangle *clip = &Machine->visible_area;
 struct GfxElement *gfx = Machine->gfx[1];
 unsigned char *src = &( ddragon_spriteram[0x800] );
 int i;
 for( i = 0; i < ( 64 * 5 ); i += 5 ) {
  int attr = src[i+1];
  if ( attr & 0x80 ) {
   int sx = 240 - src[i+4] + ( ( attr & 2 ) << 7 );
   int sy = 240 - src[i+0] + ( ( attr & 1 ) << 8 );
   int size = ( attr & 0x30 ) >> 4;
   int flipx = ( attr & 8 );
   int flipy = ( attr & 4 );
   int dx = -16; int dy = -16;
   int which;
   int color;
   if ( dd2_video ) {
    color = ( src[i+2] >> 5 );
    which = src[i+3] + ( ( src[i+2] & 0x1f ) << 8 );
   } else {
    color = ( src[i+2] >> 4 ) & 0x07;
    which = src[i+3] + ( ( src[i+2] & 0x0f ) << 8 );
   }
   if (flip_screen_x)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
    dx = -dx;
    dy = -dy;
   }
   switch ( size ) {
    case 0:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 1:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+1),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 2:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx + dx,sy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+2),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 3:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx + dx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+1),color,flipx,flipy,sx + dx,sy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+2),color,flipx,flipy,sx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+3),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
   }
  }
 }
}

variable_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *

variable_types: struct rectangle { int min_x; int min_y; } *

variable_types:
src
unsigned char *

variable_types: i int

variable_types: attr int

variable_types: size int

variable_types: dx int

variable_types: dy int

variable_types: which int

variable_types: color int


decompiled_code:
__int64 __fastcall irq_handler(int a1)
{
return cpu_set_irq_line(2LL, (unsigned int)ym_irq, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
return cpu_set_irq_line(2LL, (unsigned int)ym_irq, a1 != 0);
}

original_code:
static void irq_handler(int irq)
{
 cpu_set_irq_line( 2, ym_irq , irq ? 1 : 0 );
}

variable_types: irq int


decompiled_code:
__int64 cpu_sound_command_w()
{
soundlatch_w();
return cpu_cause_interrupt(2LL, (unsigned int)sound_irq);
}

canonical_decompiled_code:
__int64 func16()
{
soundlatch_w();
return cpu_cause_interrupt(2LL, (unsigned int)sound_irq);
}

original_code:
static void cpu_sound_command_w(offs_t offset,data_t data)
{
 soundlatch_w( offset, data );
 cpu_cause_interrupt( 2, sound_irq );
}

canonical_original_code:
static void cpu_sound_command_w(unsigned int offset, unsigned int data)
{
 soundlatch_w( offset, data );
 cpu_cause_interrupt( 2, sound_irq );
}

variable_types:
offset
unsigned int


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

v0 = Machine;
*(_QWORD *)(v0 + 848) = readsamples(gorf_sample_names, *(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL));
GorfBaseFrequency = 11025;
GorfBaseVolume = 230;
GorfChannel = 0;
return 0LL;
}

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

v0 = Machine;
*(_QWORD *)(v0 + 848) = readsamples(gorf_sample_names, *(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL));
GorfBaseFrequency = 11025;
GorfBaseVolume = 230;
GorfChannel = 0;
return 0LL;
}

original_code:
int gorf_sh_start(const struct MachineSound *msound)
{
 Machine->samples = readsamples(gorf_sample_names,Machine->gamedrv->name);
    GorfBaseFrequency = 11025;
    GorfBaseVolume = 230;
    GorfChannel = 0;
    return 0;
}

canonical_original_code:
int gorf_sh_start(struct MachineSound *msound)
{
 Machine->samples = readsamples(gorf_sample_names,Machine->gamedrv->name);
    GorfBaseFrequency = 11025;
    GorfBaseVolume = 230;
    GorfChannel = 0;
    return 0;
}

variable_types: struct MachineSound { int sound_type; void *sound_interface; } *


decompiled_code:
__int64 gorf_speech_r()
{
unsigned int v0; // er14
__int64 v1; // rbx
const char *v2; // rdi

totalword_ptr = totalword;
v0 = (unsigned int)cpu_get_reg(4LL) >> 8;
if ( (v0 & 0x3F) == 63 )
{
sample_stop(GorfChannel);
totalword[0] = 0;
}
else
{
if ( totalword[0] )
{
strcat(totalword, PhonemeTable[v0 & 0x3F]);
}
else
{
strcpy(totalword, PhonemeTable[v0 & 0x3F]);
if ( plural )
{
if ( !strcmp("S", totalword) )
{
sample_start(GorfChannel, 117LL, 0LL);
sample_set_freq(GorfChannel, GorfBaseFrequency);
totalword[0] = 0;
oldword[0] = 0;
return v0;
}
plural = 0;
}
}
v1 = 0LL;
v2 = "A2AYY1";
while ( strcmp(v2, totalword) )
{
v2 = GorfWordTable[++v1];
if ( !v2 )
return v0;
}
if ( !strcmp("GDTO1RFYA2N", totalword)
|| !strcmp("RO1U1BAH1T", totalword)
|| !strcmp("KO1UH3I3E1N", totalword)
|| !strcmp("WORAYY1EH3R", totalword)
|| !strcmp("IN", totalword) )
{
plural = v1 + 1;
strcpy(oldword, totalword);
}
else
{
plural = 0;
}
sample_start(GorfChannel, (unsigned int)v1, 0LL);
sample_set_freq(GorfChannel, GorfBaseFrequency);
totalword[0] = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er14
__int64 v1; // rbx
const char *v2; // rdi

totalword_ptr = totalword;
v0 = (unsigned int)cpu_get_reg(4LL) >> 8;
if ( (v0 & 0x3F) == 63 )
{
sample_stop(GorfChannel);
totalword[0] = 0;
}
else
{
if ( totalword[0] )
{
strcat(totalword, PhonemeTable[v0 & 0x3F]);
}
else
{
strcpy(totalword, PhonemeTable[v0 & 0x3F]);
if ( plural )
{
if ( !strcmp("S", totalword) )
{
sample_start(GorfChannel, 117LL, 0LL);
sample_set_freq(GorfChannel, GorfBaseFrequency);
totalword[0] = 0;
oldword[0] = 0;
return v0;
}
plural = 0;
}
}
v1 = 0LL;
v2 = "A2AYY1";
while ( strcmp(v2, totalword) )
{
v2 = GorfWordTable[++v1];
if ( !v2 )
return v0;
}
if ( !strcmp("GDTO1RFYA2N", totalword)
|| !strcmp("RO1U1BAH1T", totalword)
|| !strcmp("KO1UH3I3E1N", totalword)
|| !strcmp("WORAYY1EH3R", totalword)
|| !strcmp("IN", totalword) )
{
plural = v1 + 1;
strcpy(oldword, totalword);
}
else
{
plural = 0;
}
sample_start(GorfChannel, (unsigned int)v1, 0LL);
sample_set_freq(GorfChannel, GorfBaseFrequency);
totalword[0] = 0;
}
return v0;
}

original_code:
data_t gorf_speech_r(offs_t offset)
{
    int Phoneme,Intonation;
    int i = 0;
 int data;
    totalword_ptr = totalword;
 data = cpu_get_reg(Z80_BC) >> 8;
    Phoneme = data & 0x3F;
    Intonation = data >> 6;
  if(Phoneme==63) {
     sample_stop(GorfChannel);
                totalword[0] = 0;
      return data;
    }
  if (strlen(totalword) == 0) {
   strcpy(totalword,PhonemeTable[Phoneme]);
   if (plural != 0) {
    if (!strcmp("S",totalword)) {
     sample_start(GorfChannel, (sizeof(GorfWordTable)/sizeof(char *))-2, 0);
     sample_set_freq(GorfChannel, GorfBaseFrequency);
     totalword[0] = 0;
     oldword[0] = 0;
     return data;
    } else {
     plural=0;
    }
   }
  } else
   strcat(totalword,PhonemeTable[Phoneme]);
  for (i=0; GorfWordTable[i]; i++) {
   if (!strcmp(GorfWordTable[i],totalword)) {
    if ((!strcmp("GDTO1RFYA2N",totalword)) || (!strcmp("RO1U1BAH1T",totalword)) || (!strcmp("KO1UH3I3E1N",totalword)) || (!strcmp("WORAYY1EH3R",totalword)) || (!strcmp("IN",totalword)) ) {
     plural=i+1;
     strcpy(oldword,totalword);
    } else {
             plural=0;
          }
          sample_start(GorfChannel, i, 0);
          sample_set_freq(GorfChannel, GorfBaseFrequency);
          totalword[0] = 0;
          return data;
       }
    }
  return data;
}

canonical_original_code:
unsigned int gorf_speech_r(unsigned int offset)
{
    int Phoneme; int Intonation;
    int i = 0;
 int data;
    totalword_ptr = totalword;
 data = cpu_get_reg(Z80_BC) >> 8;
    Phoneme = data & 0x3F;
    Intonation = data >> 6;
  if(Phoneme==63) {
     sample_stop(GorfChannel);
                totalword[0] = 0;
      return data;
    }
  if (strlen(totalword) == 0) {
   strcpy(totalword,PhonemeTable[Phoneme]);
   if (plural != 0) {
    if (!strcmp("S",totalword)) {
     sample_start(GorfChannel, (sizeof(GorfWordTable)/sizeof(char *))-2, 0);
     sample_set_freq(GorfChannel, GorfBaseFrequency);
     totalword[0] = 0;
     oldword[0] = 0;
     return data;
    } else {
     plural=0;
    }
   }
  } else
   strcat(totalword,PhonemeTable[Phoneme]);
  for (i=0; GorfWordTable[i]; i++) {
   if (!strcmp(GorfWordTable[i],totalword)) {
    if ((!strcmp("GDTO1RFYA2N",totalword)) || (!strcmp("RO1U1BAH1T",totalword)) || (!strcmp("KO1UH3I3E1N",totalword)) || (!strcmp("WORAYY1EH3R",totalword)) || (!strcmp("IN",totalword)) ) {
     plural=i+1;
     strcpy(oldword,totalword);
    } else {
             plural=0;
          }
          sample_start(GorfChannel, i, 0);
          sample_set_freq(GorfChannel, GorfBaseFrequency);
          totalword[0] = 0;
          return data;
       }
    }
  return data;
}

variable_types: Phoneme int

variable_types: Intonation int

variable_types: data int


decompiled_code:
_BOOL8 gorf_status_r()
{
return (unsigned int)sample_playing(GorfChannel) == 0;
}

canonical_decompiled_code:
_BOOL8 func2()
{
return (unsigned int)sample_playing(GorfChannel) == 0;
}

original_code:
int gorf_status_r(void)
{
    return !sample_playing(GorfChannel);
}

canonical_original_code:
int gorf_status_r()
{
    return !sample_playing(GorfChannel);
}


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

v0 = input_port_2_r(0LL) & 0x7F;
if ( gorf_status_r() )
v0 += 128;
return v0;
}

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

v0 = input_port_2_r(0LL) & 0x7F;
if ( func2() )
v0 += 128;
return v0;
}

original_code:
data_t gorf_port_2_r(offs_t offset)
{
    int Ans;
    Ans = (input_port_2_r(0) & 0x7F);
    if (gorf_status_r() != 0) Ans += 128;
    return Ans;
}

canonical_original_code:
unsigned int gorf_port_2_r(unsigned int offset)
{
    int Ans;
    Ans = (input_port_2_r(0) & 0x7F);
    if (gorf_status_r() != 0) Ans += 128;
    return Ans;
}

variable_types: Ans int


decompiled_code:
void gorf_sh_update()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void gorf_sh_update(void)
{
}

canonical_original_code:
void gorf_sh_update()
{
}


original_code:
static void K005289_update(int ch, INT16 *buffer, int length)
{
 k005289_sound_channel *voice=channel_list;
 short *mix;
 int i,v,f;
 memset(mixer_buffer, 0, length * sizeof(INT16));
 v=voice[0].volume;
 f=voice[0].frequency;
 if (v && f)
 {
  const unsigned char *w = voice[0].wave;
  int c = voice[0].counter;
  mix = mixer_buffer;
  for (i = 0; i < length; i++)
  {
   int offs;
   c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
   offs = (c >> 16) & 0x1f;
   *mix++ += ((w[offs] & 0x0f) - 8) * v;
  }
  voice[0].counter = c;
 }
 v=voice[1].volume;
 f=voice[1].frequency;
 if (v && f)
 {
  const unsigned char *w = voice[1].wave;
  int c = voice[1].counter;
  mix = mixer_buffer;
  for (i = 0; i < length; i++)
  {
   int offs;
   c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
   offs = (c >> 16) & 0x1f;
   *mix++ += ((w[offs] & 0x0f) - 8) * v;
  }
  voice[1].counter = c;
 }
 mix = mixer_buffer;
 for (i = 0; i < length; i++)
  *buffer++ = mixer_lookup[*mix++];
}

canonical_original_code:
static void K005289_update(int ch, short *buffer, int length)
{
 struct k005289_sound_channel *voice = channel_list;
 short *mix;
 int i; int v; int f;
 memset(mixer_buffer, 0, length * sizeof(INT16));
 v=voice[0].volume;
 f=voice[0].frequency;
 if (v && f)
 {
  unsigned char *w = voice[0].wave;
  int c = voice[0].counter;
  mix = mixer_buffer;
  for (i = 0; i < length; i++)
  {
   int offs;
   c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
   offs = (c >> 16) & 0x1f;
   *mix++ += ((w[offs] & 0x0f) - 8) * v;
  }
  voice[0].counter = c;
 }
 v=voice[1].volume;
 f=voice[1].frequency;
 if (v && f)
 {
  unsigned char *w = voice[1].wave;
  int c = voice[1].counter;
  mix = mixer_buffer;
  for (i = 0; i < length; i++)
  {
   int offs;
   c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
   offs = (c >> 16) & 0x1f;
   *mix++ += ((w[offs] & 0x0f) - 8) * v;
  }
  voice[1].counter = c;
 }
 mix = mixer_buffer;
 for (i = 0; i < length; i++)
  *buffer++ = mixer_lookup[*mix++];
}

variable_types: ch int

variable_types:
buffer
short *

variable_types: length int

variable_types: struct k005289_sound_channel { int frequency; int counter; int volume; unsigned char *wave; } *

variable_types:
mix
short *

variable_types: v int

variable_types: f int

variable_types:
w
unsigned char *

variable_types: c int

variable_types: offs int


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

if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
channel_list = k005289_A_frequency;
dword_538 = k005289_B_frequency;
dword_528 = k005289_A_volume;
dword_540 = k005289_B_volume;
qword_530 = sound_prom + 32 * k005289_A_waveform;
result = sound_prom + 32 * k005289_B_waveform + 256;
qword_548 = result;
return result;
}

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

if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
channel_list = k005289_A_frequency;
dword_538 = k005289_B_frequency;
dword_528 = k005289_A_volume;
dword_540 = k005289_B_volume;
qword_530 = sound_prom + 32 * k005289_A_waveform;
result = sound_prom + 32 * k005289_B_waveform + 256;
qword_548 = result;
return result;
}

original_code:
static void k005289_recompute(void)
{
 k005289_sound_channel *voice = channel_list;
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 voice[0].frequency = k005289_A_frequency;
 voice[1].frequency = k005289_B_frequency;
 voice[0].volume = k005289_A_volume;
 voice[1].volume = k005289_B_volume;
 voice[0].wave = &sound_prom[32 * k005289_A_waveform];
 voice[1].wave = &sound_prom[32 * k005289_B_waveform + 0x100];
}

canonical_original_code:
static void k005289_recompute()
{
 struct k005289_sound_channel *voice = channel_list;
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 voice[0].frequency = k005289_A_frequency;
 voice[1].frequency = k005289_B_frequency;
 voice[0].volume = k005289_A_volume;
 voice[1].volume = k005289_B_volume;
 voice[0].wave = &sound_prom[32 * k005289_A_waveform];
 voice[1].wave = &sound_prom[32 * k005289_B_waveform + 0x100];
}

user_defined_types: struct k005289_sound_channel { int frequency; int counter; int volume; unsigned char *wave; }


decompiled_code:
__int64 __fastcall K005289_sh_start(__int64 a1)
{
__int64 v1; // rbp
void *v2; // rax
void *v3; // rbx
unsigned int v4; // er12

v1 = *(_QWORD *)(a1 + 8);
stream = stream_init("K005289", *(unsigned int *)(v1 + 4), *(unsigned int *)(Machine + 836LL), 0LL, K005289_update);
mclock = *(_DWORD *)v1;
rate = *(_DWORD *)(Machine + 836LL);
v2 = malloc(4LL * rate);
mixer_buffer = v2;
if ( !v2 )
return 1;
v3 = v2;
v4 = make_mixer_table(2);
if ( v4 )
{
free(v3);
v4 = 1;
}
else
{
sound_prom = memory_region(*(unsigned int *)(v1 + 8));
channel_list = 0;
dword_528 = 0;
qword_530 = sound_prom;
dword_524 = 0;
dword_538 = 0;
dword_540 = 0;
qword_548 = sound_prom + 256;
dword_53C = 0;
}
return v4;
}

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

v1 = *(_QWORD *)(a1 + 8);
stream = stream_init("K005289", *(unsigned int *)(v1 + 4), *(unsigned int *)(Machine + 836LL), 0LL, K005289_update);
mclock = *(_DWORD *)v1;
rate = *(_DWORD *)(Machine + 836LL);
v2 = malloc(4LL * rate);
mixer_buffer = v2;
if ( !v2 )
return 1;
v3 = v2;
v4 = func0(2);
if ( v4 )
{
free(v3);
v4 = 1;
}
else
{
sound_prom = memory_region(*(unsigned int *)(v1 + 8));
channel_list = 0;
dword_528 = 0;
qword_530 = sound_prom;
dword_524 = 0;
dword_538 = 0;
dword_540 = 0;
qword_548 = sound_prom + 256;
dword_53C = 0;
}
return v4;
}

original_code:
int K005289_sh_start(const struct MachineSound *msound)
{
 const char *snd_name = "K005289";
 k005289_sound_channel *voice=channel_list;
 const struct k005289_interface *intf = (const struct k005289_interface *)msound->sound_interface;
 stream = stream_init(snd_name, intf->volume, Machine->sample_rate, 0, K005289_update);
 mclock = intf->master_clock;
 rate = Machine->sample_rate;
 if ((mixer_buffer = (short int*)malloc(2 * sizeof(short) * Machine->sample_rate)) == 0)
  return 1;
 if (make_mixer_table(2))
 {
  free(mixer_buffer);
  return 1;
 }
 sound_prom = memory_region(intf->region);
 voice[0].frequency = 0;
 voice[0].volume = 0;
 voice[0].wave = &sound_prom[0];
 voice[0].counter = 0;
 voice[1].frequency = 0;
 voice[1].volume = 0;
 voice[1].wave = &sound_prom[0x100];
 voice[1].counter = 0;
 return 0;
}

canonical_original_code:
int K005289_sh_start(struct MachineSound *msound)
{
 char *snd_name = "K005289";
 struct k005289_sound_channel *voice = channel_list;
 struct k005289_interface *intf = (const struct k005289_interface *)msound->sound_interface;
 stream = stream_init(snd_name, intf->volume, Machine->sample_rate, 0, K005289_update);
 mclock = intf->master_clock;
 rate = Machine->sample_rate;
 if ((mixer_buffer = (short *)malloc(2 * sizeof(short) * Machine->sample_rate)) == 0)
  return 1;
 if (make_mixer_table(2))
 {
  free(mixer_buffer);
  return 1;
 }
 sound_prom = memory_region(intf->region);
 voice[0].frequency = 0;
 voice[0].volume = 0;
 voice[0].wave = &sound_prom[0];
 voice[0].counter = 0;
 voice[1].frequency = 0;
 voice[1].volume = 0;
 voice[1].wave = &sound_prom[0x100];
 voice[1].counter = 0;
 return 0;
}

variable_types: struct k005289_interface { int master_clock; int volume; int region; } *

user_defined_types: struct MachineSound { int sound_type; void *sound_interface; }


decompiled_code:
void K005289_sh_stop()
{
free(mixer_table);
free(mixer_buffer);
}

canonical_decompiled_code:
void func4()
{
free(mixer_table);
free(mixer_buffer);
}

original_code:
void K005289_sh_stop(void)
{
 free(mixer_table);
 free(mixer_buffer);
}


decompiled_code:
__int64 __fastcall k005289_control_A_w(__int64 a1, unsigned int a2)
{
k005289_A_volume = a2 & 0xF;
k005289_A_waveform = a2 >> 5;
return k005289_recompute();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
k005289_A_volume = a2 & 0xF;
k005289_A_waveform = a2 >> 5;
return func2();
}

original_code:
void k005289_control_A_w(offs_t offset,data_t data)
{
 k005289_A_volume=data&0xf;
 k005289_A_waveform=data>>5;
 k005289_recompute();
}

canonical_original_code:
void k005289_control_A_w(unsigned int offset, unsigned int data)
{
 k005289_A_volume=data&0xf;
 k005289_A_waveform=data>>5;
 k005289_recompute();
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall k005289_control_B_w(__int64 a1, unsigned int a2)
{
k005289_B_volume = a2 & 0xF;
k005289_B_waveform = a2 >> 5;
return k005289_recompute();
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
k005289_B_volume = a2 & 0xF;
k005289_B_waveform = a2 >> 5;
return func2();
}

original_code:
void k005289_control_B_w(offs_t offset,data_t data)
{
 k005289_B_volume=data&0xf;
 k005289_B_waveform=data>>5;
 k005289_recompute();
}

canonical_original_code:
void k005289_control_B_w(unsigned int offset, unsigned int data)
{
 k005289_B_volume=data&0xf;
 k005289_B_waveform=data>>5;
 k005289_recompute();
}


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

result = (unsigned int)(4096 - a1);
k005289_A_latch = 4096 - a1;
return result;
}

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

result = (unsigned int)(4096 - a1);
k005289_A_latch = 4096 - a1;
return result;
}

original_code:
void k005289_pitch_A_w(offs_t offset,data_t data)
{
 k005289_A_latch = 0x1000 - offset;
}

canonical_original_code:
void k005289_pitch_A_w(unsigned int offset, unsigned int data)
{
 k005289_A_latch = 0x1000 - offset;
}


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

result = (unsigned int)(4096 - a1);
k005289_B_latch = 4096 - a1;
return result;
}

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

result = (unsigned int)(4096 - a1);
k005289_B_latch = 4096 - a1;
return result;
}

original_code:
void k005289_pitch_B_w(offs_t offset,data_t data)
{
 k005289_B_latch = 0x1000 - offset;
}

canonical_original_code:
void k005289_pitch_B_w(unsigned int offset, unsigned int data)
{
 k005289_B_latch = 0x1000 - offset;
}


decompiled_code:
__int64 k005289_keylatch_A_w()
{
k005289_A_frequency = k005289_A_latch;
return k005289_recompute();
}

canonical_decompiled_code:
__int64 func9()
{
k005289_A_frequency = k005289_A_latch;
return func2();
}

original_code:
void k005289_keylatch_A_w(offs_t offset,data_t data)
{
 k005289_A_frequency = k005289_A_latch;
 k005289_recompute();
}

canonical_original_code:
void k005289_keylatch_A_w(unsigned int offset, unsigned int data)
{
 k005289_A_frequency = k005289_A_latch;
 k005289_recompute();
}


decompiled_code:
__int64 k005289_keylatch_B_w()
{
k005289_B_frequency = k005289_B_latch;
return k005289_recompute();
}

canonical_decompiled_code:
__int64 func10()
{
k005289_B_frequency = k005289_B_latch;
return func2();
}

original_code:
void k005289_keylatch_B_w(offs_t offset,data_t data)
{
 k005289_B_frequency = k005289_B_latch;
 k005289_recompute();
}

canonical_original_code:
void k005289_keylatch_B_w(unsigned int offset, unsigned int data)
{
 k005289_B_frequency = k005289_B_latch;
 k005289_recompute();
}


decompiled_code:
void __fastcall leprechn_graphics_command_w(__int64 a1, int a2)
{
last_command = a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
last_command = a2;
}

original_code:
void leprechn_graphics_command_w(offs_t offset,data_t data)
{
    last_command = data;
}

canonical_original_code:
void leprechn_graphics_command_w(unsigned int offset, unsigned int data)
{
    last_command = data;
}


decompiled_code:
__int64 leprechn_graphics_data_r()
{
return *(unsigned __int8 *)(videoram + x + screen_width * y);
}

canonical_decompiled_code:
__int64 func1()
{
return *(unsigned __int8 *)(videoram + x + screen_width * y);
}

original_code:
data_t leprechn_graphics_data_r(offs_t offset)
{
    return videoram[y * screen_width + x];
}

canonical_original_code:
unsigned int leprechn_graphics_data_r(unsigned int offset)
{
    return videoram[y * screen_width + x];
}


decompiled_code:
__int64 __fastcall leprechn_vh_screenrefresh(__int64 a1, int a2)
{
int i; // ebp
unsigned int j; // ebx
__int64 v4; // rdx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; screen_width > i; ++i )
{
v4 = Machine;
result = *(_QWORD *)(Machine + 824LL);
for ( j = 0; *(_DWORD *)(result + 668) > (signed int)j; result = *(_QWORD *)(Machine + 824LL) )
{
plot_pixel(
*(_QWORD *)(v4 + 768),
(unsigned int)i,
j,
*(unsigned __int16 *)(*(_QWORD *)(v4 + 792)
+ 2LL * *(unsigned __int8 *)(videoram + (int)(i + screen_width * j))));
++j;
v4 = Machine;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
int i; // ebp
unsigned int j; // ebx
__int64 v4; // rdx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; screen_width > i; ++i )
{
v4 = Machine;
result = *(_QWORD *)(Machine + 824LL);
for ( j = 0; *(_DWORD *)(result + 668) > (signed int)j; result = *(_QWORD *)(Machine + 824LL) )
{
plot_pixel(
*(_QWORD *)(v4 + 768),
(unsigned int)i,
j,
*(unsigned __int16 *)(*(_QWORD *)(v4 + 792)
+ 2LL * *(unsigned __int8 *)(videoram + (int)(i + screen_width * j))));
++j;
v4 = Machine;
}
}
}
return result;
}

original_code:
void leprechn_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 if (full_refresh)
 {
  int sx, sy;
  for (sx = 0; sx < screen_width; sx++)
  {
   for (sy = 0; sy < Machine->drv->screen_height; sy++)
   {
    plot_pixel(Machine->scrbitmap, sx, sy, Machine->pens[videoram[sy * screen_width + sx]]);
   }
  }
 }
}

canonical_original_code:
void leprechn_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 if (full_refresh)
 {
  int sx; int sy;
  for (sx = 0; sx < screen_width; sx++)
  {
   for (sy = 0; sy < Machine->drv->screen_height; sy++)
   {
    plot_pixel(Machine->scrbitmap, sx, sy, Machine->pens[videoram[sy * screen_width + sx]]);
   }
  }
 }
}

variable_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *

variable_types: sx int

variable_types: sy int


decompiled_code:
void __fastcall leprechn_input_port_select_w(__int64 a1, char a2)
{
input_port_select = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, char a2)
{
input_port_select = a2;
}

original_code:
static void leprechn_input_port_select_w(offs_t offset,data_t data)
{
    input_port_select = data;
}

canonical_original_code:
static void leprechn_input_port_select_w(unsigned int offset, unsigned int data)
{
    input_port_select = data;
}


decompiled_code:
__int64 leprechn_200d_r()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 2LL;
}

original_code:
static data_t leprechn_200d_r(offs_t offset)
{
    return 0x02;
}

canonical_original_code:
static unsigned int leprechn_200d_r(unsigned int offset)
{
    return 0x02;
}


decompiled_code:
__int64 leprechn_0805_r()
{
return 192LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 192LL;
}

original_code:
static data_t leprechn_0805_r(offs_t offset)
{
    return 0xc0;
}

canonical_original_code:
static unsigned int leprechn_0805_r(unsigned int offset)
{
    return 0xc0;
}