decompiled_code:
__int64 __fastcall rpc_os_heart(__int64 a1, unsigned int *a2, const char *a3)
{
__int64 result; // rax

result = rpccall_os_heart(a1, (__int64)a2, a3);
if ( (int)result >= 0 )
result = *a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2, const char *a3)
{
__int64 result; // rax

result = func1(a1, (__int64)a2, a3);
if ( (int)result >= 0 )
result = *a2;
return result;
}

original_code:
int rpc_os_heart(os_heart_in *arg, os_heart_out *res, char *ipp)
{
 int ret = rpccall_os_heart(arg, res, ipp);
 if(ret < 0)
  return ret;
 return res->err;
}

canonical_original_code:
int rpc_os_heart(struct os_heart_in *arg, struct os_heart_out *res, char *ipp)
{
 int ret = rpccall_os_heart(arg, res, ipp);
 if(ret < 0)
  return ret;
 return res->err;
}

variable_types: ret int

user_defined_types: struct os_heart_in { unsigned int total; unsigned int avail; }


repo: zydcom/dnfs

decompiled_code:
__int64 __fastcall heart_state(void *a1)
{
__int64 result; // rax
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h] BYREF
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( 1 )
{
LODWORD(result) = get_space_info(&v3, v4);
if ( (int)result < 0 )
break;
fprintf(stderr, "[hear report]: total=%uKB, avail = %uKB\n", v3, v4[0]);
rpc_os_heart((__int64)&v3, &v2, meta_server);
sleep(heart_itval);
}
return (int)result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *a1)
{
__int64 result; // rax
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h] BYREF
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( 1 )
{
LODWORD(result) = func0(&v3, v4);
if ( (int)result < 0 )
break;
fprintf(stderr, "[hear report]: total=%uKB, avail = %uKB\n", v3, v4[0]);
func2((__int64)&v3, &v2, meta_server);
sleep(heart_itval);
}
return (int)result;
}

original_code:
void *heart_state()
{
 uint32_t space;
 os_heart_in arg;
 os_heart_out res;
 int ret;
 while(1) {
  ret = get_space_info(&arg.total, &arg.avail);
  do { if((ret) < 0) return (void*)ret; } while(0);
  fprintf(stderr, "[hear report]: total=%uKB, avail = %uKB\n", arg.total, arg.avail);
  rpc_os_heart(&arg, &res, meta_server);
  sleep(heart_itval);
 }
}

canonical_original_code:
void *heart_state()
{
 unsigned int space;
 struct os_heart_in arg;
 struct os_heart_out res;
 int ret;
 while(1) {
  ret = get_space_info(&arg.total, &arg.avail);
  do { if((ret) < 0) return (void *)ret; } while(0);
  fprintf(stderr, "[hear report]: total=%uKB, avail = %uKB\n", arg.total, arg.avail);
  rpc_os_heart(&arg, &res, meta_server);
  sleep(heart_itval);
 }
}

variable_types:
space
unsigned int

variable_types: struct os_heart_in { unsigned int total; unsigned int avail; }

variable_types:
res
struct os_heart_out { int err; }

return_type: void *


decompiled_code:
__int64 __fastcall parse_storage_cmd(char a1, __int64 a2)
{
const char **v2; // rbx
int v3; // er12
__int64 v4; // rbp
_BYTE *v5; // rax
__int64 result; // rax
const char *v7; // rdi

if ( a1 > 1 )
{
v2 = (const char **)(a2 + 16);
v3 = 0;
v4 = a2 + 16LL * ((unsigned int)(a1 - 2) >> 1) + 32;
while ( 1 )
{
v5 = *(v2 - 1);
if ( *v5 != 45 )
goto LABEL_4;
if ( v5[1] == 115 && !v5[2] )
break;
if ( v5[1] != 114 || v5[2] )
{
if ( v5[1] != 105 || v5[2] )
goto LABEL_4;
v7 = *v2;
v2 += 2;
heart_itval = atoi(v7);
if ( v2 == (const char **)v4 )
{
LABEL_11:
if ( !v3 )
goto LABEL_4;
return 0LL;
}
}
else
{
result = check_directory(*v2);
if ( (int)result < 0 )
return result;
strcpy(storage_root, *v2);
LABEL_16:
v2 += 2;
if ( v2 == (const char **)v4 )
goto LABEL_11;
}
}
if ( !(unsigned int)is_ipv4(*v2) )
{
puts("invaild ip address.");
return 0xFFFFFFFFLL;
}
v3 = 1;
strcpy(meta_server, *v2);
goto LABEL_16;
}
LABEL_4:
usage();
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, __int64 a2)
{
const char **v2; // rbx
int v3; // er12
__int64 v4; // rbp
_BYTE *v5; // rax
__int64 result; // rax
const char *v7; // rdi

if ( a1 > 1 )
{
v2 = (const char **)(a2 + 16);
v3 = 0;
v4 = a2 + 16LL * ((unsigned int)(a1 - 2) >> 1) + 32;
while ( 1 )
{
v5 = *(v2 - 1);
if ( *v5 != 45 )
goto LABEL_4;
if ( v5[1] == 115 && !v5[2] )
break;
if ( v5[1] != 114 || v5[2] )
{
if ( v5[1] != 105 || v5[2] )
goto LABEL_4;
v7 = *v2;
v2 += 2;
heart_itval = atoi(v7);
if ( v2 == (const char **)v4 )
{
LABEL_11:
if ( !v3 )
goto LABEL_4;
return 0LL;
}
}
else
{
result = check_directory(*v2);
if ( (int)result < 0 )
return result;
strcpy(storage_root, *v2);
LABEL_16:
v2 += 2;
if ( v2 == (const char **)v4 )
goto LABEL_11;
}
}
if ( !(unsigned int)is_ipv4(*v2) )
{
puts("invaild ip address.");
return 0xFFFFFFFFLL;
}
v3 = 1;
strcpy(meta_server, *v2);
goto LABEL_16;
}
LABEL_4:
func4();
return 0xFFFFFFFFLL;
}

original_code:
int parse_storage_cmd(char argc, char *argv[])
{
 int i;
 int ret;
 int srvflag = 0;
 for(i = 1; i < argc; i += 2) {
  if(!strcmp(argv[i], "-s")) {
   if(!is_ipv4(argv[i+1])) {
    printf("invaild ip address.\n");
    return -1;
   }
   strcpy(meta_server, argv[i+1]);
   srvflag = 1;
  }
  else if(!strcmp(argv[i], "-r")) {
   ret = check_directory(argv[i+1]);
   do {if((ret) < 0) return ret; } while(0);
   strcpy(storage_root, argv[i+1]);
  }
  else if(!strcmp(argv[i], "-i")) {
   heart_itval = atoi(argv[i+1]);
  }
  else {
   usage();
   return -1;
  }
 }
 if(!srvflag) {
  usage();
  return -1;
 }
 return 0;
}

variable_types: argc char

variable_types:
argv
char *[]

variable_types: i int

variable_types: srvflag int

return_type: int


decompiled_code:
__int64 __fastcall storage_init(char a1, __int64 a2)
{
int v2; // er12
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v2 = parse_storage_cmd(a1, a2);
if ( v2 >= 0 )
{
v2 = check_directory(storage_root);
if ( v2 >= 0 )
{
v2 = pthread_create(newthread, 0LL, (void *(*)(void *))heart_state, 0LL);
if ( v2 )
{
v2 = -1;
perror("pthread_create error in [osd_init]");
}
else
{
printf("metadata server: %s\n", meta_server);
printf("storage root dierctory: %s\n", storage_root);
printf("heart interval: %d seconds\n", heart_itval);
puts("Storage node initialized successfully!\n");
}
}
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, __int64 a2)
{
int v2; // er12
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v2 = func5(a1, a2);
if ( v2 >= 0 )
{
v2 = check_directory(storage_root);
if ( v2 >= 0 )
{
v2 = pthread_create(newthread, 0LL, (void *(*)(void *))heart_state, 0LL);
if ( v2 )
{
v2 = -1;
perror("pthread_create error in [osd_init]");
}
else
{
printf("metadata server: %s\n", meta_server);
printf("storage root dierctory: %s\n", storage_root);
printf("heart interval: %d seconds\n", heart_itval);
puts("Storage node initialized successfully!\n");
}
}
}
return (unsigned int)v2;
}

original_code:
int storage_init(int argc, char *argv[])
{
 int ret;
 ret = parse_storage_cmd(argc, argv);
 do {if((ret) < 0) return ret; } while(0);
 ret = check_directory(storage_root);
 do {if((ret) < 0) return ret; } while(0);
 pthread_t tid;
 if((ret = pthread_create(&tid, ((void *)0), heart_state, ((void *)0))) != 0) {
  perror("pthread_create error in [osd_init]");
  return -1;
 }
 printf("metadata server: %s\n", meta_server);
 printf("storage root dierctory: %s\n", storage_root);
 printf("heart interval: %d seconds\n", heart_itval);
 printf("Storage node initialized successfully!\n\n");
 return 0;
}

canonical_original_code:
int storage_init(int argc, char *argv[])
{
 int ret;
 ret = parse_storage_cmd(argc, argv);
 do {if((ret) < 0) return ret; } while(0);
 ret = check_directory(storage_root);
 do {if((ret) < 0) return ret; } while(0);
 unsigned long tid;
 if((ret = pthread_create(&tid, ((void *)0), heart_state, ((void *)0))) != 0) {
  perror("pthread_create error in [osd_init]");
  return -1;
 }
 printf("metadata server: %s\n", meta_server);
 printf("storage root dierctory: %s\n", storage_root);
 printf("heart interval: %d seconds\n", heart_itval);
 printf("Storage node initialized successfully!\n\n");
 return 0;
}

variable_types: argc int

variable_types:
tid
unsigned long


usage

decompiled_code:
int usage()
{
return puts("dnfs-node -s server-ip [-r root-directory] [-i heart-interval]");
}

canonical_decompiled_code:
int func4()
{
return puts("dnfs-node -s server-ip [-r root-directory] [-i heart-interval]");
}

original_code:
void usage()
{
 printf("dnfs-node -s server-ip [-r root-directory] [-i heart-interval]\n");
}

return_type: void


decompiled_code:
__int64 __fastcall co_write_1(__int64 a1, __int64 a2, __int64 a3)
{
return (**(__int64 (__fastcall ***)(__int64, __int64, void *, __int64, void *, __int64, __int64, _QWORD))(a3 + 8))(
a3,
1LL,
&xdr_co_write_in,
a1,
&xdr_co_write_out,
a2,
TIMEOUT,
0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
return (**(__int64 (__fastcall ***)(__int64, __int64, void *, __int64, void *, __int64, __int64, _QWORD))(a3 + 8))(
a3,
1LL,
&xdr_co_write_in,
a1,
&xdr_co_write_out,
a2,
TIMEOUT,
0LL);
}

original_code:
enum clnt_stat
co_write_1(co_write_in *argp, co_write_out *clnt_res, CLIENT *clnt)
{
 return (((*(clnt)->cl_ops->cl_call)(clnt, 1, (xdrproc_t) xdr_co_write_in, (caddr_t) argp, (xdrproc_t) xdr_co_write_out, (caddr_t) clnt_res, TIMEOUT)));
}

canonical_original_code:
enum clnt_stat co_write_1(struct co_write_in *argp, struct co_write_out *clnt_res, struct CLIENT *clnt)
{
 return (((*(clnt)->cl_ops->cl_call)(clnt, 1, (int (*)(struct XDR *, void *, ...)) xdr_co_write_in, (char *) argp, (int (*)(struct XDR *, void *, ...)) xdr_co_write_out, (char *) clnt_res, TIMEOUT)));
}

variable_types: struct co_write_in { char chunkid[20]; struct { unsigned int buf_len; char *buf_val; } buf; unsigned long offset; unsigned int ip; } *

variable_types: struct CLIENT { struct AUTH { struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; } ah_cred; struct opaque_auth ah_verf; union des_block { struct { unsigned int high; unsigned int low; } key; char c[8]; } ah_key; struct auth_ops { void (*ah_nextverf)(struct AUTH *); int (*ah_marshal)(struct AUTH *, struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *); int (*ah_validate)(struct AUTH *, struct opaque_auth *); int (*ah_refresh)(struct AUTH *); void (*ah_destroy)(struct AUTH *); } *ah_ops; char *ah_private; } *cl_auth; struct clnt_ops { enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 } (*cl_call)(struct CLIENT *, unsigned long, int (*)(struct XDR *, void *, ...), char *, int (*)(struct XDR *, void *, ...), char *, struct timeval { long tv_sec; long tv_usec; }); void (*cl_abort)(); void (*cl_geterr)(struct CLIENT *, struct rpc_err { enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 } re_status; union { int RE_errno; enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 } RE_why; struct { unsigned long low; unsigned long high; } RE_vers; struct { long s1; long s2; } RE_lb; } ru; } *); int (*cl_freeres)(struct CLIENT *, int (*)(struct XDR *, void *, ...), char *); void (*cl_destroy)(struct CLIENT *); int (*cl_control)(struct CLIENT *, int, char *); } *cl_ops; char *cl_private; } *

user_defined_types: struct CLIENT { struct AUTH *cl_auth; struct clnt_ops *cl_ops; char *cl_private; }

user_defined_types: struct AUTH { struct opaque_auth ah_cred; struct opaque_auth ah_verf; union des_block ah_key; struct auth_ops *ah_ops; char *ah_private; }

user_defined_types: struct clnt_ops { enum clnt_stat (*cl_call)(struct CLIENT *, unsigned long, int (*)(struct XDR *, void *, ...), char *, int (*)(struct XDR *, void *, ...), char *, struct timeval); void (*cl_abort)(); void (*cl_geterr)(struct CLIENT *, struct rpc_err *); int (*cl_freeres)(struct CLIENT *, int (*)(struct XDR *, void *, ...), char *); void (*cl_destroy)(struct CLIENT *); int (*cl_control)(struct CLIENT *, int, char *); }

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }

user_defined_types: struct auth_ops { void (*ah_nextverf)(struct AUTH *); int (*ah_marshal)(struct AUTH *, struct XDR *); int (*ah_validate)(struct AUTH *, struct opaque_auth *); int (*ah_refresh)(struct AUTH *); void (*ah_destroy)(struct AUTH *); }

user_defined_types: struct rpc_err { enum clnt_stat re_status; union { int RE_errno; enum auth_stat RE_why; struct { unsigned long low; unsigned long high; } RE_vers; struct { long s1; long s2; } RE_lb; } ru; }


decompiled_code:
__int64 __fastcall co_read_1(__int64 a1, __int64 a2, __int64 a3)
{
return (**(__int64 (__fastcall ***)(__int64, __int64, void *, __int64, void *, __int64, __int64, _QWORD))(a3 + 8))(
a3,
2LL,
&xdr_co_read_in,
a1,
&xdr_co_read_out,
a2,
TIMEOUT,
0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
return (**(__int64 (__fastcall ***)(__int64, __int64, void *, __int64, void *, __int64, __int64, _QWORD))(a3 + 8))(
a3,
2LL,
&xdr_co_read_in,
a1,
&xdr_co_read_out,
a2,
TIMEOUT,
0LL);
}

original_code:
enum clnt_stat
co_read_1(co_read_in *argp, co_read_out *clnt_res, CLIENT *clnt)
{
 return (((*(clnt)->cl_ops->cl_call)(clnt, 2, (xdrproc_t) xdr_co_read_in, (caddr_t) argp, (xdrproc_t) xdr_co_read_out, (caddr_t) clnt_res, TIMEOUT)));
}

canonical_original_code:
enum clnt_stat co_read_1(struct co_read_in *argp, struct co_read_out *clnt_res, struct CLIENT *clnt)
{
 return (((*(clnt)->cl_ops->cl_call)(clnt, 2, (int (*)(struct XDR *, void *, ...)) xdr_co_read_in, (char *) argp, (int (*)(struct XDR *, void *, ...)) xdr_co_read_out, (char *) clnt_res, TIMEOUT)));
}

variable_types: struct co_read_in { char chunkid[20]; unsigned int size; unsigned long offset; } *

variable_types: struct co_read_out { struct { unsigned int buf_len; char *buf_val; } buf; int err; } *

return_type: enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 }

user_defined_types: struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; }

user_defined_types: union des_block { struct { unsigned int high; unsigned int low; } key; char c[8]; }

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }

user_defined_types: struct timeval { long tv_sec; long tv_usec; }

user_defined_types: enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 }


decompiled_code:
__int64 __fastcall co_unlink_1(__int64 a1, __int64 a2, __int64 a3)
{
return (**(__int64 (__fastcall ***)(__int64, __int64, void *, __int64, void *, __int64, __int64, _QWORD))(a3 + 8))(
a3,
3LL,
&xdr_co_unlink_in,
a1,
&xdr_co_unlink_out,
a2,
TIMEOUT,
0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
return (**(__int64 (__fastcall ***)(__int64, __int64, void *, __int64, void *, __int64, __int64, _QWORD))(a3 + 8))(
a3,
3LL,
&xdr_co_unlink_in,
a1,
&xdr_co_unlink_out,
a2,
TIMEOUT,
0LL);
}

original_code:
enum clnt_stat
co_unlink_1(co_unlink_in *argp, co_unlink_out *clnt_res, CLIENT *clnt)
{
 return (((*(clnt)->cl_ops->cl_call)(clnt, 3, (xdrproc_t) xdr_co_unlink_in, (caddr_t) argp, (xdrproc_t) xdr_co_unlink_out, (caddr_t) clnt_res, TIMEOUT)));
}

canonical_original_code:
enum clnt_stat co_unlink_1(struct co_unlink_in *argp, struct co_unlink_out *clnt_res, struct CLIENT *clnt)
{
 return (((*(clnt)->cl_ops->cl_call)(clnt, 3, (int (*)(struct XDR *, void *, ...)) xdr_co_unlink_in, (char *) argp, (int (*)(struct XDR *, void *, ...)) xdr_co_unlink_out, (char *) clnt_res, TIMEOUT)));
}

variable_types: struct co_unlink_in { char chunkid[20]; } *

user_defined_types: enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 }


original_code:
void set_dnfs_attr(struct stat stbuf, dnfs_stat *st)
{
   st->s_ino = stbuf.st_ino;
   st->s_mode = stbuf.st_mode;
   st->s_nlink = stbuf.st_nlink;
   st->s_uid = stbuf.st_uid;
   st->s_gid = stbuf.st_gid;
   st->s_rdev = stbuf.st_rdev;
   st->s_size = stbuf.st_size;
   st->s_blocks = stbuf.st_blocks;
   st->s_atime = stbuf.st_atim.tv_sec;
   st->s_mtime = stbuf.st_mtim.tv_sec;
   st->s_ctime = stbuf.st_ctim.tv_sec;
}

canonical_original_code:
void set_dnfs_attr(struct stat stbuf, struct dnfs_stat *st)
{
   st->s_ino = stbuf.st_ino;
   st->s_mode = stbuf.st_mode;
   st->s_nlink = stbuf.st_nlink;
   st->s_uid = stbuf.st_uid;
   st->s_gid = stbuf.st_gid;
   st->s_rdev = stbuf.st_rdev;
   st->s_size = stbuf.st_size;
   st->s_blocks = stbuf.st_blocks;
   st->s_atime = stbuf.st_atim.tv_sec;
   st->s_mtime = stbuf.st_mtim.tv_sec;
   st->s_ctime = stbuf.st_ctim.tv_sec;
}

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

variable_types: struct dnfs_stat { unsigned long s_ino; unsigned int s_mode; unsigned short s_chunks; unsigned short s_copies; unsigned long s_nlink; unsigned int s_uid; unsigned int s_gid; unsigned long s_rdev; unsigned long s_size; unsigned long s_blocks; unsigned long s_atime; unsigned long s_mtime; unsigned long s_ctime; } *

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


original_code:
void get_dnfs_attr(struct stat *stbuf, dnfs_stat st)
{
   stbuf->st_ino = st.s_ino;
   stbuf->st_mode = st.s_mode;
   stbuf->st_nlink = st.s_nlink;
   stbuf->st_uid = st.s_uid;
   stbuf->st_gid = st.s_gid;
   stbuf->st_rdev = st.s_rdev;
   stbuf->st_size = st.s_size;
   stbuf->st_blocks = st.s_blocks;
   stbuf->st_atim.tv_sec = st.s_atime;
   stbuf->st_mtim.tv_sec = st.s_mtime;
   stbuf->st_ctim.tv_sec = st.s_ctime;
   stbuf->st_dev = 0;
   stbuf->st_blksize = 0;
}

canonical_original_code:
void get_dnfs_attr(struct stat *stbuf, struct dnfs_stat st)
{
   stbuf->st_ino = st.s_ino;
   stbuf->st_mode = st.s_mode;
   stbuf->st_nlink = st.s_nlink;
   stbuf->st_uid = st.s_uid;
   stbuf->st_gid = st.s_gid;
   stbuf->st_rdev = st.s_rdev;
   stbuf->st_size = st.s_size;
   stbuf->st_blocks = st.s_blocks;
   stbuf->st_atim.tv_sec = st.s_atime;
   stbuf->st_mtim.tv_sec = st.s_mtime;
   stbuf->st_ctim.tv_sec = st.s_ctime;
   stbuf->st_dev = 0;
   stbuf->st_blksize = 0;
}

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

variable_types: struct dnfs_stat { unsigned long s_ino; unsigned int s_mode; unsigned short s_chunks; unsigned short s_copies; unsigned long s_nlink; unsigned int s_uid; unsigned int s_gid; unsigned long s_rdev; unsigned long s_size; unsigned long s_blocks; unsigned long s_atime; unsigned long s_mtime; unsigned long s_ctime; }


decompiled_code:
__int64 __fastcall is_ipv4(__int64 a1)
{
int v1; // er8
__int64 result; // rax
int v3; // [rsp+0h] [rbp-18h] BYREF
unsigned int v4; // [rsp+4h] [rbp-14h] BYREF
unsigned int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-Ch] BYREF

v1 = _isoc99_sscanf(a1, "%u.%u.%u.%u", &v3, &v4, &v5, &v6);
result = 0LL;
if ( v1 == 4 && v4 <= 0xFF && v5 <= 0xFF )
result = ((unsigned int)(v3 - 1) <= 0xFE) & (unsigned __int8)(v6 <= 0xFF);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // er8
__int64 result; // rax
int v3; // [rsp+0h] [rbp-18h] BYREF
unsigned int v4; // [rsp+4h] [rbp-14h] BYREF
unsigned int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-Ch] BYREF

v1 = _isoc99_sscanf(a1, "%u.%u.%u.%u", &v3, &v4, &v5, &v6);
result = 0LL;
if ( v1 == 4 && v4 <= 0xFF && v5 <= 0xFF )
result = ((unsigned int)(v3 - 1) <= 0xFE) & (unsigned __int8)(v6 <= 0xFF);
return result;
}

variable_types:
ip
char *


decompiled_code:
int __fastcall get_addr(char *a1, unsigned int a2)
{
return sprintf(a1, "%u.%u.%u.%u", HIBYTE(a2), BYTE2(a2), BYTE1(a2), (unsigned __int8)a2);
}

canonical_decompiled_code:
int __fastcall func4(char *a1, unsigned int a2)
{
return sprintf(a1, "%u.%u.%u.%u", HIBYTE(a2), BYTE2(a2), BYTE1(a2), (unsigned __int8)a2);
}

canonical_original_code:
void get_addr(char *ipp, unsigned int ip)
{
    unsigned int p1; unsigned int p2; unsigned int p3; unsigned int p4;
    p1 = ip / 0x1000000;
    p2 = ip % 0x1000000 / 0x10000;
    p3 = ip % 0x10000 / 0x100;
    p4 = ip % 0x100;
    sprintf(ipp, "%u.%u.%u.%u", p1, p2, p3, p4);
}

variable_types:
ipp
char *

variable_types:
ip
unsigned int


decompiled_code:
__int64 __fastcall check_directory(const char *a1)
{
int v1; // er8
__int64 result; // rax
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

v1 = access(a1, 0);
result = 0LL;
if ( v1 < 0 )
{
sprintf(v3, "mkdir -p %s", a1);
result = (unsigned int)(system(v3) >> 31);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
int v1; // er8
__int64 result; // rax
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

v1 = access(a1, 0);
result = 0LL;
if ( v1 < 0 )
{
sprintf(v3, "mkdir -p %s", a1);
result = (unsigned int)(system(v3) >> 31);
}
return result;
}

original_code:
int check_directory(char *path)
{
 int res = 0;
 res = access(path, 0);
 if(res < 0) {
  char root_dir[1024];
  sprintf(root_dir, "mkdir -p %s", path);
  if(system(root_dir) < 0)
   return -1;
 }
 return 0;
}

variable_types:
path
char *

variable_types: res int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("c99int:\t%u, %u, %u, %lu\n", 255LL, 0xFFFFLL, 0xFFFFFFFFLL, -1LL);
return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 unsigned char i8 = (uint8_t)-1;
 unsigned short i16 = (uint16_t)-1;
 unsigned int i32 = (uint32_t)-1;
 unsigned long i64 = (uint64_t)-1L;
 printf("c99int:\t%" "u" ", %" "u" ", %" "u" ", %" "l" "u" "\n", i8, i16, i32, i64);
 return 0;
}

variable_types:
argv
char *[]


repo: zyoung/passgen

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
const char **v5; // rbp
const char *v6; // rdi
char v7; // al

if ( argc > 1 )
{
v4 = argv + 1;
v5 = &argv[(unsigned int)(argc - 2) + 2];
while ( 1 )
{
v6 = *v4;
if ( **v4 == 45 )
{
v7 = v6[1];
if ( v7 == 110 || v7 == 115 || v7 == 108 )
parameter(v6, argv, envp);
}
if ( ++v4 == v5 )
{
puts("There was an error processing your parameters");
puts("Valid input is:");
puts("\t-n=<number of passwords>");
puts("\t-l=<length of password>");
puts("\t-s=<strength 1 being weakest and 4 being strongest>");
exit(1);
}
}
}
intro(argc, argv, envp);
printf("NUM: %d", 20LL);
printf(" LENGTH: %d", 12LL);
printf(" STRENGTH %d\n", 4LL);
passgen(20LL, 12LL, 4LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
const char **v5; // rbp
const char *v6; // rdi
char v7; // al

if ( argc > 1 )
{
v4 = argv + 1;
v5 = &argv[(unsigned int)(argc - 2) + 2];
while ( 1 )
{
v6 = *v4;
if ( **v4 == 45 )
{
v7 = v6[1];
if ( v7 == 110 || v7 == 115 || v7 == 108 )
func7(v6, argv, envp);
}
if ( ++v4 == v5 )
{
puts("There was an error processing your parameters");
puts("Valid input is:");
puts("\t-n=<number of passwords>");
puts("\t-l=<length of password>");
puts("\t-s=<strength 1 being weakest and 4 being strongest>");
exit(1);
}
}
}
func8(argc, argv, envp);
printf("NUM: %d", 20LL);
printf(" LENGTH: %d", 12LL);
printf(" STRENGTH %d\n", 4LL);
func11(20LL, 12LL, 4LL);
return 0;
}

original_code:
int main(int argv, char *argc[]) {
    int num = 20;
    int length = 12;
    int strength = 4;
    int idx;
    int error;
    if (argv > 1) {
 for (idx = 1; idx < argv; idx++) {
     if (argc[idx][0] == '-') {
  switch (argc[idx][1]) {
  case 's':
      strength = parameter(argc[idx]);
      break;
  case 'n':
      num = parameter(argc[idx]);
      break;
  case 'l':
      length = parameter(argc[idx]);
      break;
  default:
      strength = -1;
      break;
  }
     } else {
  error = 1;
     }
 }
 if (error == 1 || strength == -1 || num == -1 || length == -1) {
     printf("There was an error processing your parameters\n");
     printf("Valid input is:\n");
     printf("\t-n=<number of passwords>\n");
     printf("\t-l=<length of password>\n");
     printf
  ("\t-s=<strength 1 being weakest and 4 being strongest>\n");
     exit(1);
 }
    }
    intro();
    printf("NUM: %d", num);
    printf(" LENGTH: %d", length);
    printf(" STRENGTH %d\n", strength);
    passgen(num, length, strength);
    return 0;
}

variable_types: argv int

variable_types:
argc
char *[]

variable_types: num int

variable_types: length int

variable_types: strength int

variable_types: idx int

variable_types: error int


parameter

decompiled_code:
__int64 __fastcall parameter(const char *a1)
{
size_t v2; // rax
int v3; // edx
int v4; // esi
size_t v5; // rdi
size_t i; // rax
char v7; // cl
__int64 v8; // r9
__int64 result; // rax
char v10[72]; // [rsp+0h] [rbp-48h] BYREF

if ( *a1 )
{
v2 = strlen(a1);
v3 = 0;
v4 = 0;
v5 = v2;
for ( i = 0LL; i < v5; ++i )
{
v7 = a1[i];
if ( v3 )
{
v8 = v4++;
v10[v8] = v7;
}
if ( v7 == 61 )
v3 = 1;
}
v10[v4] = 0;
result = strtol(v10, 0LL, 10);
}
else
{
puts("Error resolving parameters.");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
size_t v2; // rax
int v3; // edx
int v4; // esi
size_t v5; // rdi
size_t i; // rax
char v7; // cl
__int64 v8; // r9
__int64 result; // rax
char v10[72]; // [rsp+0h] [rbp-48h] BYREF

if ( *a1 )
{
v2 = strlen(a1);
v3 = 0;
v4 = 0;
v5 = v2;
for ( i = 0LL; i < v5; ++i )
{
v7 = a1[i];
if ( v3 )
{
v8 = v4++;
v10[v8] = v7;
}
if ( v7 == 61 )
v3 = 1;
}
v10[v4] = 0;
result = strtol(v10, 0LL, 10);
}
else
{
puts("Error resolving parameters.");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int parameter(char *arg) {
    int value = 1;
    int lcv;
    int index = 0;
    int record = 0;
    char temp[50];
    if (strlen(arg)) {
        for (lcv = 0; lcv < strlen(arg); lcv++) {
            if (record) {
                temp[index] = arg[lcv];
                index++;
            }
            if (arg[lcv] == '=') {
                record = 1;
            }
        }
        temp[index] = '\0';
        value = strtol(temp, ((void *)0), 10);
    } else {
        printf("Error resolving parameters.\n");
        value = -1;
    }
    return value;
}

variable_types:
arg
char *

variable_types: value int

variable_types: lcv int

variable_types: index int

variable_types: record int

variable_types:
temp
char [50]


intro

decompiled_code:
int intro()
{
puts("Passgen 2.0");
puts("Written by Zach Young");
puts("Copyright 2004, 2005, 2006 Zach Young");
puts("This is free software; see the source for copying conditions. There is NO");
return puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
}

canonical_decompiled_code:
int func8()
{
puts("Passgen 2.0");
puts("Written by Zach Young");
puts("Copyright 2004, 2005, 2006 Zach Young");
puts("This is free software; see the source for copying conditions. There is NO");
return puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
}

original_code:
void intro()
{
    printf("Passgen 2.0\n");
    printf("Written by Zach Young\n");
    printf("Copyright 2004, 2005, 2006 Zach Young\n");
    printf("This is free software; see the source for copying conditions.  There is NO\n");
    printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
    return;
}


getValue

decompiled_code:
__int64 __fastcall getValue(int a1)
{
unsigned int v1; // edx
int v2; // ebp
int v3; // ebx

v1 = rand() % a1;
if ( v1 > 3 )
{
v3 = 97;
v2 = 26;
}
else
{
v2 = CSWTCH_2[v1];
v3 = (unsigned __int8)CSWTCH_3[4 * v1];
}
return (unsigned int)(v3 + rand() % v2);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
unsigned int v1; // edx
int v2; // ebp
int v3; // ebx

v1 = rand() % a1;
if ( v1 > 3 )
{
v3 = 97;
v2 = 26;
}
else
{
v2 = CSWTCH_2[v1];
v3 = (unsigned __int8)CSWTCH_3[4 * v1];
}
return (unsigned int)(v3 + rand() % v2);
}

original_code:
char getValue(int s)
{
    char c;
    int idx;
    int l;
    int o;
    int type = rand() % s;
    switch (type) {
        case 0:
            l = 10;
            o = 48;
            break;
        case 1:
            l = 26;
            o = 97;
            break;
        case 2:
            l = 26;
            o = 65;
            break;
        case 3:
            l = 15;
            o = 33;
            break;
        default:
            l = 26;
            o = 97;
    }
 return rand() % l + o;
}

variable_types: s int

variable_types: c char

variable_types: l int

variable_types: o int

variable_types: type int

return_type: char


generate

decompiled_code:
int __fastcall generate(int a1, int a2)
{
int i; // ebx
char v3; // al

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v3 = getValue(a2);
putchar(v3);
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(int a1, int a2)
{
int i; // ebx
char v3; // al

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v3 = func9(a2);
putchar(v3);
}
}
return putchar(10);
}

original_code:
void generate(int l, int s)
{
    int idx;
    for (idx = 0; idx < l; idx++) {
        printf("%c", getValue(s));
    }
    printf("\n");
    return;
}


passgen

decompiled_code:
void __fastcall passgen(int a1, int a2, int a3)
{
unsigned int v4; // eax
int i; // ebx

v4 = time(0LL);
srand(v4);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
generate(a2, a3);
}
}

canonical_decompiled_code:
void __fastcall func11(int a1, int a2, int a3)
{
unsigned int v4; // eax
int i; // ebx

v4 = time(0LL);
srand(v4);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
func10(a2, a3);
}
}

original_code:
void passgen(int num, int length, int strength)
{
    int idx;
    srand(time(((void *)0)));
    for (idx = 0; idx < num; idx++) {
        generate(length, strength);
    }
    return;
}


backtrace

repo: zzmfish/tracegraph

decompiled_code:
int *__fastcall backtrace()
{
__int64 *v0; // rbp
int *result; // rax
int v2; // er12
unsigned __int64 v3; // rsi
__int64 *i; // rbx
unsigned __int64 v5; // rbp
__int64 *v6; // r13
__int64 v7; // [rsp+0h] [rbp-38h] BYREF

result = *(int **)&addr_start;
if ( addr_end > *(_QWORD *)&addr_start )
{
v2 = 0;
v3 = 0LL;
for ( i = v0; i >= &v7; i = v6 )
{
v5 = i[1];
v6 = (__int64 *)*i;
if ( v5 >= *(_QWORD *)&addr_start && v5 < addr_end && v3 >= *(_QWORD *)&addr_start && v3 < addr_end )
call_table_set((unsigned int)(v5 - addr_start), (unsigned int)(v3 - addr_start), v2 == 1);
result = &max_frame_size;
if ( (int)abs32((_DWORD)i - (_DWORD)v6) > max_frame_size )
break;
result = &max_frame_depth;
if ( max_frame_depth < ++v2 )
break;
v3 = v5;
}
}
return result;
}

canonical_decompiled_code:
int *__fastcall func7()
{
__int64 *v0; // rbp
int *result; // rax
int v2; // er12
unsigned __int64 v3; // rsi
__int64 *i; // rbx
unsigned __int64 v5; // rbp
__int64 *v6; // r13
__int64 v7; // [rsp+0h] [rbp-38h] BYREF

result = *(int **)&addr_start;
if ( addr_end > *(_QWORD *)&addr_start )
{
v2 = 0;
v3 = 0LL;
for ( i = v0; i >= &v7; i = v6 )
{
v5 = i[1];
v6 = (__int64 *)*i;
if ( v5 >= *(_QWORD *)&addr_start && v5 < addr_end && v3 >= *(_QWORD *)&addr_start && v3 < addr_end )
call_table_set((unsigned int)(v5 - addr_start), (unsigned int)(v3 - addr_start), v2 == 1);
result = &max_frame_size;
if ( (int)abs32((_DWORD)i - (_DWORD)v6) > max_frame_size )
break;
result = &max_frame_depth;
if ( max_frame_depth < ++v2 )
break;
v3 = v5;
}
}
return result;
}

original_code:
void backtrace()
{
  if (addr_end <= addr_start)
    return;
  void *bp = 0, *ip = 0, *sp = 0, *prev_bp = 0, *prev_ip = 0;
  __asm__("movq %%rbp, %0;" : "=r"(bp));
  __asm__("movq %%rsp, %0;" : "=r"(sp));
  int i = 0;
  while (bp >= sp) {
    prev_bp = *((void**)bp);
    prev_ip = *((void**)bp + 1);
    if ((unsigned long)prev_ip >= addr_start && (unsigned long)prev_ip < addr_end
        && (unsigned long)ip >= addr_start && (unsigned long)ip < addr_end) {
      call_table_set((unsigned long)prev_ip - addr_start, (unsigned long)ip - addr_start, i == 1);
    }
    if (abs(bp - prev_bp) > max_frame_size)
      break;
    i ++;
    if (i > max_frame_depth)
      break;
    bp = prev_bp;
    ip = prev_ip;
  }
}

canonical_original_code:
void backtrace()
{
  if (addr_end <= addr_start)
    return;
  void *bp = 0; void *ip = 0; void *sp = 0; void *prev_bp = 0; void *prev_ip = 0;
  __asm__("movq %%rbp, %0;" : "=r"(bp));
  __asm__("movq %%rsp, %0;" : "=r"(sp));
  int i = 0;
  while (bp >= sp) {
    prev_bp = *((void **)bp);
    prev_ip = *((void **)bp + 1);
    if ((unsigned long)prev_ip >= addr_start && (unsigned long)prev_ip < addr_end
        && (unsigned long)ip >= addr_start && (unsigned long)ip < addr_end) {
      call_table_set((unsigned long)prev_ip - addr_start, (unsigned long)ip - addr_start, i == 1);
    }
    if (abs(bp - prev_bp) > max_frame_size)
      break;
    i ++;
    if (i > max_frame_depth)
      break;
    bp = prev_bp;
    ip = prev_ip;
  }
}

variable_types:
bp
void *

variable_types:
ip
void *

variable_types:
sp
void *

variable_types: i int


decompiled_code:
__int64 __fastcall mcu_sort_list(unsigned __int8 *a1, __int64 a2)
{
char *v2; // rdx
__int64 result; // rax
int v4; // eax

v2 = (char *)&unk_3501;
do
{
result = *a1;
if ( *a1 <= 0x1Fu )
{
v4 = 2 * result;
*(_BYTE *)(a2 + v4) = *(v2 - 1);
result = v4 + 1;
*(_BYTE *)(a2 + result) = *v2;
}
v2 += 2;
++a1;
}
while ( v2 != (char *)&unk_3501 + 64 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, __int64 a2)
{
char *v2; // rdx
__int64 result; // rax
int v4; // eax

v2 = (char *)&unk_3501;
do
{
result = *a1;
if ( *a1 <= 0x1Fu )
{
v4 = 2 * result;
*(_BYTE *)(a2 + v4) = *(v2 - 1);
result = v4 + 1;
*(_BYTE *)(a2 + result) = *v2;
}
v2 += 2;
++a1;
}
while ( v2 != (char *)&unk_3501 + 64 );
return result;
}

original_code:
static void mcu_sort_list( unsigned char *src, unsigned char *dst ) {
 int i;
 for ( i = 0; i < 0x20; i++ ) {
  int where = src[i];
  if ( where < 0x20 ) {
   int offs = ( i << 1 );
   where <<= 1;
   dst[where] = mcu_table3[offs];
   dst[where+1] = mcu_table3[offs+1];
  }
 }
}

canonical_original_code:
static void mcu_sort_list(unsigned char *src, unsigned char *dst) {
 int i;
 for ( i = 0; i < 0x20; i++ ) {
  int where = src[i];
  if ( where < 0x20 ) {
   int offs = ( i << 1 );
   where <<= 1;
   dst[where] = mcu_table3[offs];
   dst[where+1] = mcu_table3[offs+1];
  }
 }
}

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

variable_types: where int

variable_types: offs int


original_code:
void exctsccr_mcu_control_w(offs_t offset,data_t data) {
 if ( data == 0xff ) {
  exctsccr_mcu_ram[0x0003] = 0x01;
  exctsccr_mcu_ram[0x0005] = 0x08;
  exctsccr_mcu_ram[0x0380] = 0xf1;
  exctsccr_mcu_ram[0x0381] = 0x01;
  exctsccr_mcu_ram[0x02f8] = 0x1f;
  exctsccr_mcu_ram[0x0009] = 0x08;
  memcpy( &exctsccr_mcu_ram[0x0170], mcu_table1, 16 );
  if ( exctsccr_mcu_ram[0x000d] == 0x01 ) {
   exctsccr_mcu_ram[0x000d] = 0x08;
   memcpy( &exctsccr_mcu_ram[0x01f0], mcu_table2, 16 );
  }
  mcu_sort_list( &exctsccr_mcu_ram[0x03e0], &exctsccr_mcu_ram[0x0300] );
  exctsccr_mcu_ram[0x02fb] = 0x7e;
  exctsccr_mcu_ram[0x02fd] = 0x7e;
  if ( mcu_code_latch ) {
   exctsccr_mcu_ram[0x02f9] = 0x7f;
   exctsccr_mcu_ram[0x02fa] = 0x0d;
   exctsccr_mcu_ram[0x02fc] = 0x05;
   exctsccr_mcu_ram[0x02fe] = 0x01;
  } else {
   exctsccr_mcu_ram[0x02f9] = 0x81;
   exctsccr_mcu_ram[0x02fa] = 0x2d;
   exctsccr_mcu_ram[0x02fc] = 0x25;
   exctsccr_mcu_ram[0x02fe] = 0x09;
  }
  if ( exctsccr_mcu_ram[0x000f] == 0x02 ) {
   exctsccr_mcu_ram[0x000f] = 0x08;
   exctsccr_mcu_ram[0x02f6] = 0xd6;
   exctsccr_mcu_ram[0x02f7] = 0x39;
  }
  if ( exctsccr_mcu_ram[0x0007] == 0x02 ) {
   exctsccr_mcu_ram[0x0007] = 0x08;
   if ( exctsccr_mcu_ram[0x0204] > 3 )
    exctsccr_mcu_ram[0x0204] = 0;
   switch( exctsccr_mcu_ram[0x0204] ) {
    case 0x00:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table4, 16 );
    break;
    case 0x01:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table5, 16 );
    break;
    case 0x02:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table6, 16 );
    break;
    case 0x03:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table7, 16 );
    break;
   }
   if ( exctsccr_mcu_ram[0x0204] != 3 )
    exctsccr_mcu_ram[0x0204]++;
  }
  exctsccr_mcu_ram[0x0011] = 0x08;
  memcpy( &exctsccr_mcu_ram[0x007f], mcu_table8, 16*2 );
 }
}

canonical_original_code:
void exctsccr_mcu_control_w(unsigned int offset, unsigned int data) {
 if ( data == 0xff ) {
  exctsccr_mcu_ram[0x0003] = 0x01;
  exctsccr_mcu_ram[0x0005] = 0x08;
  exctsccr_mcu_ram[0x0380] = 0xf1;
  exctsccr_mcu_ram[0x0381] = 0x01;
  exctsccr_mcu_ram[0x02f8] = 0x1f;
  exctsccr_mcu_ram[0x0009] = 0x08;
  memcpy( &exctsccr_mcu_ram[0x0170], mcu_table1, 16 );
  if ( exctsccr_mcu_ram[0x000d] == 0x01 ) {
   exctsccr_mcu_ram[0x000d] = 0x08;
   memcpy( &exctsccr_mcu_ram[0x01f0], mcu_table2, 16 );
  }
  mcu_sort_list( &exctsccr_mcu_ram[0x03e0], &exctsccr_mcu_ram[0x0300] );
  exctsccr_mcu_ram[0x02fb] = 0x7e;
  exctsccr_mcu_ram[0x02fd] = 0x7e;
  if ( mcu_code_latch ) {
   exctsccr_mcu_ram[0x02f9] = 0x7f;
   exctsccr_mcu_ram[0x02fa] = 0x0d;
   exctsccr_mcu_ram[0x02fc] = 0x05;
   exctsccr_mcu_ram[0x02fe] = 0x01;
  } else {
   exctsccr_mcu_ram[0x02f9] = 0x81;
   exctsccr_mcu_ram[0x02fa] = 0x2d;
   exctsccr_mcu_ram[0x02fc] = 0x25;
   exctsccr_mcu_ram[0x02fe] = 0x09;
  }
  if ( exctsccr_mcu_ram[0x000f] == 0x02 ) {
   exctsccr_mcu_ram[0x000f] = 0x08;
   exctsccr_mcu_ram[0x02f6] = 0xd6;
   exctsccr_mcu_ram[0x02f7] = 0x39;
  }
  if ( exctsccr_mcu_ram[0x0007] == 0x02 ) {
   exctsccr_mcu_ram[0x0007] = 0x08;
   if ( exctsccr_mcu_ram[0x0204] > 3 )
    exctsccr_mcu_ram[0x0204] = 0;
   switch( exctsccr_mcu_ram[0x0204] ) {
    case 0x00:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table4, 16 );
    break;
    case 0x01:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table5, 16 );
    break;
    case 0x02:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table6, 16 );
    break;
    case 0x03:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table7, 16 );
    break;
   }
   if ( exctsccr_mcu_ram[0x0204] != 3 )
    exctsccr_mcu_ram[0x0204]++;
  }
  exctsccr_mcu_ram[0x0011] = 0x08;
  memcpy( &exctsccr_mcu_ram[0x007f], mcu_table8, 16*2 );
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
void __fastcall exctsccr_gfx_bank_w(__int64 a1, char a2)
{
gfx_bank = a2 & 1;
}

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

original_code:
void exctsccr_gfx_bank_w(offs_t offset,data_t data) {
 gfx_bank = data & 1;
}

canonical_original_code:
void exctsccr_gfx_bank_w(unsigned int offset, unsigned int data) {
 gfx_bank = data & 1;
}


decompiled_code:
__int64 exctsccr_vh_start()
{
exctsccr_fm_timer = timer_pulse(14316557LL, 0LL, exctsccr_fm_callback);
return generic_vh_start();
}

canonical_decompiled_code:
__int64 func5()
{
exctsccr_fm_timer = timer_pulse(14316557LL, 0LL, exctsccr_fm_callback);
return generic_vh_start();
}

original_code:
int exctsccr_vh_start( void ) {
 exctsccr_fm_timer = timer_pulse( ((1<<30) / ((timer_tm)(75.0))), 0, exctsccr_fm_callback );
 return generic_vh_start();
}

canonical_original_code:
int exctsccr_vh_start() {
 exctsccr_fm_timer = timer_pulse( ((1<<30) / ((timer_tm)(75.0))), 0, exctsccr_fm_callback );
 return generic_vh_start();
}


decompiled_code:
__int64 exctsccr_fm_callback()
{
return cpu_cause_interrupt(1LL, 255LL);
}

canonical_decompiled_code:
__int64 func6()
{
return cpu_cause_interrupt(1LL, 255LL);
}

original_code:
static void exctsccr_fm_callback( int param ) {
 cpu_cause_interrupt( 1, 0xff );
}

canonical_original_code:
static void exctsccr_fm_callback(int param) {
 cpu_cause_interrupt( 1, 0xff );
}

variable_types: param int


decompiled_code:
__int64 exctsccr_vh_stop()
{
if ( exctsccr_fm_timer )
{
timer_remove();
exctsccr_fm_timer = 0LL;
}
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func7()
{
if ( exctsccr_fm_timer )
{
timer_remove();
exctsccr_fm_timer = 0LL;
}
return generic_vh_stop();
}

original_code:
void exctsccr_vh_stop( void ) {
 if ( exctsccr_fm_timer ) {
  timer_remove( exctsccr_fm_timer );
  exctsccr_fm_timer = 0;
 }
 generic_vh_stop();
}

canonical_original_code:
void exctsccr_vh_stop() {
 if ( exctsccr_fm_timer ) {
  timer_remove( exctsccr_fm_timer );
  exctsccr_fm_timer = 0;
 }
 generic_vh_stop();
}


original_code:
static void exctsccr_drawsprites( struct osd_bitmap *bitmap ) {
 int offs;
 unsigned char *OBJ1, *OBJ2;
 OBJ1 = videoram;
 OBJ2 = &(spriteram[0x20]);
 for ( offs = 0x0e; offs >= 0; offs -= 2 ) {
  int sx,sy,code,bank,flipx,flipy,color;
  sx = 256 - OBJ2[offs+1];
  sy = OBJ2[offs] - 16;
  code = ( OBJ1[offs] >> 2 ) & 0x3f;
  flipx = ( OBJ1[offs] ) & 0x01;
  flipy = ( OBJ1[offs] ) & 0x02;
  color = ( OBJ1[offs+1] ) & 0x1f;
  bank = 2;
  bank += ( ( OBJ1[offs+1] >> 4 ) & 1 );
  drawgfx(bitmap,Machine->gfx[bank],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
 }
 OBJ1 = &(memory_region(REGION_CPU1)[0x8800]);
 OBJ2 = spriteram;
 for ( offs = 0x0e; offs >= 0; offs -= 2 ) {
  int sx,sy,code,bank,flipx,flipy,color;
  sx = 256 - OBJ2[offs+1];
  sy = OBJ2[offs] - 16;
  code = ( OBJ1[offs] >> 2 ) & 0x3f;
  flipx = ( OBJ1[offs] ) & 0x01;
  flipy = ( OBJ1[offs] ) & 0x02;
  color = ( OBJ1[offs+1] ) & 0x1f;
  bank = 3;
  if ( color == 0 )
   continue;
  if ( color < 0x10 )
   bank++;
  if ( color > 0x10 && color < 0x17 )
  {
   drawgfx(bitmap,Machine->gfx[4],
    code,
    0x0e,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
   color += 6;
  }
  if ( color==0x1d && gfx_bank==1 )
  {
   drawgfx(bitmap,Machine->gfx[3],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
   drawgfx(bitmap,Machine->gfx[4],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_COLOR, 16);
  } else
  {
  drawgfx(bitmap,Machine->gfx[bank],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
  }
 }
}

canonical_original_code:
static void exctsccr_drawsprites(struct osd_bitmap *bitmap) {
 int offs;
 unsigned char *OBJ1; unsigned char *OBJ2;
 OBJ1 = videoram;
 OBJ2 = &(spriteram[0x20]);
 for ( offs = 0x0e; offs >= 0; offs -= 2 ) {
  int sx; int sy; int code; int bank; int flipx; int flipy; int color;
  sx = 256 - OBJ2[offs+1];
  sy = OBJ2[offs] - 16;
  code = ( OBJ1[offs] >> 2 ) & 0x3f;
  flipx = ( OBJ1[offs] ) & 0x01;
  flipy = ( OBJ1[offs] ) & 0x02;
  color = ( OBJ1[offs+1] ) & 0x1f;
  bank = 2;
  bank += ( ( OBJ1[offs+1] >> 4 ) & 1 );
  drawgfx(bitmap,Machine->gfx[bank],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
 }
 OBJ1 = &(memory_region(REGION_CPU1)[0x8800]);
 OBJ2 = spriteram;
 for ( offs = 0x0e; offs >= 0; offs -= 2 ) {
  int sx; int sy; int code; int bank; int flipx; int flipy; int color;
  sx = 256 - OBJ2[offs+1];
  sy = OBJ2[offs] - 16;
  code = ( OBJ1[offs] >> 2 ) & 0x3f;
  flipx = ( OBJ1[offs] ) & 0x01;
  flipy = ( OBJ1[offs] ) & 0x02;
  color = ( OBJ1[offs+1] ) & 0x1f;
  bank = 3;
  if ( color == 0 )
   continue;
  if ( color < 0x10 )
   bank++;
  if ( color > 0x10 && color < 0x17 )
  {
   drawgfx(bitmap,Machine->gfx[4],
    code,
    0x0e,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
   color += 6;
  }
  if ( color==0x1d && gfx_bank==1 )
  {
   drawgfx(bitmap,Machine->gfx[3],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
   drawgfx(bitmap,Machine->gfx[4],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_COLOR, 16);
  } else
  {
  drawgfx(bitmap,Machine->gfx[bank],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
  }
 }
}

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

variable_types: sx int

variable_types: sy int

variable_types: code int

variable_types: bank int

variable_types: flipx int

variable_types: flipy int

variable_types: color int


decompiled_code:
__int64 __fastcall exctsccr_vh_screenrefresh(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // rcx
__int64 v3; // rdx
char v4; // al
__int64 v6; // [rsp-28h] [rbp-60h]

if ( videoram_size != 16LL )
{
v1 = 0LL;
do
{
while ( !*(_BYTE *)(v1 + dirtybuffer) )
{
if ( videoram_size - 16LL <= ++v1 )
goto LABEL_6;
}
*(_BYTE *)(v1 + dirtybuffer) = 0;
v2 = *(_BYTE *)(colorram + v1) & 0x1F;
v3 = *(unsigned __int8 *)(videoram + v1);
v6 = (unsigned int)(8 * ((int)v1 >> 5));
v4 = v1++;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
v3,
v2,
0LL,
0LL,
8 * (v4 & 0x1Fu),
v6,
Machine + 776LL,
0LL,
0LL);
}
while ( videoram_size - 16LL > v1 );
}
LABEL_6:
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return exctsccr_drawsprites(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // rcx
__int64 v3; // rdx
char v4; // al
__int64 v6; // [rsp-28h] [rbp-60h]

if ( videoram_size != 16LL )
{
v1 = 0LL;
do
{
while ( !*(_BYTE *)(v1 + dirtybuffer) )
{
if ( videoram_size - 16LL <= ++v1 )
goto LABEL_6;
}
*(_BYTE *)(v1 + dirtybuffer) = 0;
v2 = *(_BYTE *)(colorram + v1) & 0x1F;
v3 = *(unsigned __int8 *)(videoram + v1);
v6 = (unsigned int)(8 * ((int)v1 >> 5));
v4 = v1++;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
v3,
v2,
0LL,
0LL,
8 * (v4 & 0x1Fu),
v6,
Machine + 776LL,
0LL,
0LL);
}
while ( videoram_size - 16LL > v1 );
}
LABEL_6:
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return func8(a1);
}

original_code:
void exctsccr_vh_screenrefresh( struct osd_bitmap *bitmap, int full_refresh ) {
 int offs;
 for (offs = 0;offs < ( videoram_size - 0x10 );offs++) {
  if ( dirtybuffer[offs] ) {
   int sx,sy,code;
   dirtybuffer[offs] = 0;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   code = videoram[offs];
   drawgfx(tmpbitmap,Machine->gfx[gfx_bank],
     code,
     ( colorram[offs] ) & 0x1f,
     0, 0,
     sx,sy,
     &Machine->visible_area,
     TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 exctsccr_drawsprites( bitmap );
}

canonical_original_code:
void exctsccr_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh) {
 int offs;
 for (offs = 0;offs < ( videoram_size - 0x10 );offs++) {
  if ( dirtybuffer[offs] ) {
   int sx; int sy; int code;
   dirtybuffer[offs] = 0;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   code = videoram[offs];
   drawgfx(tmpbitmap,Machine->gfx[gfx_bank],
     code,
     ( colorram[offs] ) & 0x1f,
     0, 0,
     sx,sy,
     &Machine->visible_area,
     TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 exctsccr_drawsprites( bitmap );
}

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


decompiled_code:
__int64 __fastcall exctsccr_DAC_data_w(__int64 a1, int a2)
{
return DAC_signed_data_w(a1, (unsigned int)(4 * a2));
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
return DAC_signed_data_w(a1, (unsigned int)(4 * a2));
}

original_code:
void exctsccr_DAC_data_w(offs_t offset,data_t data)
{
 DAC_signed_data_w(offset,data << 2);
}

canonical_original_code:
void exctsccr_DAC_data_w(unsigned int offset, unsigned int data)
{
 DAC_signed_data_w(offset,data << 2);
}


original_code:
void goindol_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
 for (i = 0;i < 256;i++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = i;
}

canonical_original_code:
void goindol_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
 for (i = 0;i < 256;i++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = i;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
__int64 goindol_vh_stop()
{
free(fg_dirtybuffer);
free(bg_dirtybuffer);
bitmap_free(bitmap_fg);
return bitmap_free(bitmap_bg);
}

canonical_decompiled_code:
__int64 func3()
{
free(fg_dirtybuffer);
free(bg_dirtybuffer);
bitmap_free(bitmap_fg);
return bitmap_free(bitmap_bg);
}

original_code:
void goindol_vh_stop(void)
{
 free(fg_dirtybuffer);
 free(bg_dirtybuffer);
 bitmap_free(bitmap_fg);
 bitmap_free(bitmap_bg);
}

canonical_original_code:
void goindol_vh_stop()
{
 free(fg_dirtybuffer);
 free(bg_dirtybuffer);
 bitmap_free(bitmap_fg);
 bitmap_free(bitmap_bg);
}


decompiled_code:
__int64 goindol_vh_start()
{
_QWORD *v0; // rcx
unsigned __int64 v1; // rdi
_QWORD *v2; // rcx
unsigned __int64 v3; // rdi

fg_dirtybuffer = malloc(0x400uLL);
if ( fg_dirtybuffer )
{
bg_dirtybuffer = malloc(0x400uLL);
if ( bg_dirtybuffer )
{
bitmap_fg = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_fg )
{
bitmap_bg = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_bg )
{
v0 = fg_dirtybuffer;
v1 = (unsigned __int64)fg_dirtybuffer + 8;
*(_QWORD *)fg_dirtybuffer = 0x101010101010101LL;
v0[127] = 0x101010101010101LL;
memset((void *)(v1 & 0xFFFFFFFFFFFFFFF8LL), 1u, 8 * (((unsigned int)v0 - (v1 & 0xFFFFFFF8) + 1024) >> 3));
v2 = bg_dirtybuffer;
v3 = (unsigned __int64)bg_dirtybuffer + 8;
*(_QWORD *)bg_dirtybuffer = 0x101010101010101LL;
v2[127] = 0x101010101010101LL;
memset((void *)(v3 & 0xFFFFFFFFFFFFFFF8LL), 1u, 8 * (((unsigned int)v2 - (v3 & 0xFFFFFFF8) + 1024) >> 3));
return 0LL;
}
bitmap_free(bitmap_fg);
}
free(fg_dirtybuffer);
free(bg_dirtybuffer);
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 func4()
{
_QWORD *v0; // rcx
unsigned __int64 v1; // rdi
_QWORD *v2; // rcx
unsigned __int64 v3; // rdi

fg_dirtybuffer = malloc(0x400uLL);
if ( fg_dirtybuffer )
{
bg_dirtybuffer = malloc(0x400uLL);
if ( bg_dirtybuffer )
{
bitmap_fg = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_fg )
{
bitmap_bg = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_bg )
{
v0 = fg_dirtybuffer;
v1 = (unsigned __int64)fg_dirtybuffer + 8;
*(_QWORD *)fg_dirtybuffer = 0x101010101010101LL;
v0[127] = 0x101010101010101LL;
memset((void *)(v1 & 0xFFFFFFFFFFFFFFF8LL), 1u, 8 * (((unsigned int)v0 - (v1 & 0xFFFFFFF8) + 1024) >> 3));
v2 = bg_dirtybuffer;
v3 = (unsigned __int64)bg_dirtybuffer + 8;
*(_QWORD *)bg_dirtybuffer = 0x101010101010101LL;
v2[127] = 0x101010101010101LL;
memset((void *)(v3 & 0xFFFFFFFFFFFFFFF8LL), 1u, 8 * (((unsigned int)v2 - (v3 & 0xFFFFFFF8) + 1024) >> 3));
return 0LL;
}
bitmap_free(bitmap_fg);
}
free(fg_dirtybuffer);
free(bg_dirtybuffer);
}
}
return 1LL;
}

original_code:
int goindol_vh_start(void)
{
        if ((fg_dirtybuffer = (unsigned char*)malloc(32*32)) == 0)
 {
         return 1;
 }
        if ((bg_dirtybuffer = (unsigned char*)malloc(32*32)) == 0)
 {
  free(bg_dirtybuffer);
         return 1;
 }
 if ((bitmap_fg = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(fg_dirtybuffer);
  free(bg_dirtybuffer);
  return 1;
 }
 if ((bitmap_bg = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(bitmap_fg);
  free(fg_dirtybuffer);
  free(bg_dirtybuffer);
  return 1;
 }
        memset(fg_dirtybuffer,1,32*32);
        memset(bg_dirtybuffer,1,32*32);
        return 0;
}

canonical_original_code:
int goindol_vh_start()
{
        if ((fg_dirtybuffer = (unsigned char *)malloc(32*32)) == 0)
 {
         return 1;
 }
        if ((bg_dirtybuffer = (unsigned char *)malloc(32*32)) == 0)
 {
  free(bg_dirtybuffer);
         return 1;
 }
 if ((bitmap_fg = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(fg_dirtybuffer);
  free(bg_dirtybuffer);
  return 1;
 }
 if ((bitmap_bg = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(bitmap_fg);
  free(fg_dirtybuffer);
  free(bg_dirtybuffer);
  return 1;
 }
        memset(fg_dirtybuffer,1,32*32);
        memset(bg_dirtybuffer,1,32*32);
        return 0;
}


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

result = memory_region(129LL);
*(_WORD *)(result + 8588) = 0;
*(_BYTE *)(result + 8590) = 0;
return result;
}

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

result = memory_region(129LL);
*(_WORD *)(result + 8588) = 0;
*(_BYTE *)(result + 8590) = 0;
return result;
}

original_code:
void init_homo(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 rom[0x218c] = 0x00;
 rom[0x218d] = 0x00;
 rom[0x218e] = 0x00;
}

canonical_original_code:
void init_homo()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 rom[0x218c] = 0x00;
 rom[0x218d] = 0x00;
 rom[0x218e] = 0x00;
}

variable_types:
rom
unsigned char *


decompiled_code:
__int64 __fastcall meadows_char_dirty(int a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edx

for ( result = 0LL; result != 16; result += 4LL )
{
v3 = *(_DWORD *)((char *)&sprite_horz + result);
if ( v3 > a1 + 7 || v3 + 15 < a1 )
{
v4 = *(_DWORD *)((char *)&sprite_vert + result);
if ( a2 + 7 < v4 || v4 + 15 < a2 )
continue;
}
*(_DWORD *)((char *)&sprite_dirty + result) = 1;
}
return result;
}

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

for ( result = 0LL; result != 16; result += 4LL )
{
v3 = *(_DWORD *)((char *)&sprite_horz + result);
if ( v3 > a1 + 7 || v3 + 15 < a1 )
{
v4 = *(_DWORD *)((char *)&sprite_vert + result);
if ( a2 + 7 < v4 || v4 + 15 < a2 )
continue;
}
*(_DWORD *)((char *)&sprite_dirty + result) = 1;
}
return result;
}

original_code:
static void meadows_char_dirty(int x, int y)
{
int i;
 for (i = 0; i < 4; i++)
 {
  if ((x + 7 >= sprite_horz[i] && x <= sprite_horz[i] + 15) ||
   (y + 7 >= sprite_vert[i] && y <= sprite_vert[i] + 15))
    sprite_dirty[i] = 1;
 }
}

variable_types: x int

variable_types: y int

variable_types: i int


decompiled_code:
__int64 __fastcall dirty_sprite(int a1)
{
int v1; // eax
int v2; // edx
int v3; // eax
int v4; // er9
__int64 result; // rax
int v6; // eax
int v7; // edx
int v8; // eax
int v9; // ecx
int v10; // eax
int v11; // edx
int v12; // eax
int v13; // eax
int v14; // edx
int v15; // eax

sprite_dirty[a1] = 1;
v1 = sprite_vert[a1];
v2 = v1 + 7;
v3 = v1 + 14;
v4 = sprite_vert[a1] / 8;
if ( v2 >= 0 )
v3 = v2;
result = (unsigned int)((v3 >> 3) + 1);
if ( v4 <= (int)result )
{
while ( 1 )
{
v6 = sprite_horz[a1];
v7 = v6 + 7;
v8 = v6 + 14;
v9 = sprite_horz[a1] / 8;
if ( v7 >= 0 )
v8 = v7;
if ( v9 <= (v8 >> 3) + 1 )
{
while ( 1 )
{
if ( (unsigned int)v9 <= 0x1F && (unsigned int)v4 <= 0x1D )
*(_BYTE *)(dirtybuffer + v9 + 32 * v4) = 1;
v10 = sprite_horz[a1];
v11 = v10 + 14;
v12 = v10 + 7;
if ( v12 < 0 )
v12 = v11;
if ( v12 >> 3 < v9 )
break;
++v9;
}
}
v13 = sprite_vert[a1];
v14 = v13 + 14;
v15 = v13 + 7;
if ( v15 < 0 )
v15 = v14;
result = (unsigned int)(v15 >> 3);
if ( (int)result < v4 )
break;
++v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
int v2; // edx
int v3; // eax
int v4; // er9
__int64 result; // rax
int v6; // eax
int v7; // edx
int v8; // eax
int v9; // ecx
int v10; // eax
int v11; // edx
int v12; // eax
int v13; // eax
int v14; // edx
int v15; // eax

sprite_dirty[a1] = 1;
v1 = sprite_vert[a1];
v2 = v1 + 7;
v3 = v1 + 14;
v4 = sprite_vert[a1] / 8;
if ( v2 >= 0 )
v3 = v2;
result = (unsigned int)((v3 >> 3) + 1);
if ( v4 <= (int)result )
{
while ( 1 )
{
v6 = sprite_horz[a1];
v7 = v6 + 7;
v8 = v6 + 14;
v9 = sprite_horz[a1] / 8;
if ( v7 >= 0 )
v8 = v7;
if ( v9 <= (v8 >> 3) + 1 )
{
while ( 1 )
{
if ( (unsigned int)v9 <= 0x1F && (unsigned int)v4 <= 0x1D )
*(_BYTE *)(dirtybuffer + v9 + 32 * v4) = 1;
v10 = sprite_horz[a1];
v11 = v10 + 14;
v12 = v10 + 7;
if ( v12 < 0 )
v12 = v11;
if ( v12 >> 3 < v9 )
break;
++v9;
}
}
v13 = sprite_vert[a1];
v14 = v13 + 14;
v15 = v13 + 7;
if ( v15 < 0 )
v15 = v14;
result = (unsigned int)(v15 >> 3);
if ( (int)result < v4 )
break;
++v4;
}
}
return result;
}

original_code:
static void dirty_sprite(int n)
{
int x, y;
 sprite_dirty[n] = 1;
 for (y = sprite_vert[n] / 8;
   y < (sprite_vert[n] + 8 - 1) / 8 + 16 / 8 ;
   y++)
 {
  for (x = sprite_horz[n] / 8;
    x < (sprite_horz[n] + 8 - 1) / 8 + 16 / 8;
    x++)
  {
   if (y >= 0 && y < 30 && x >= 0 && x < 32)
    dirtybuffer[y * 32 + x] = 1;
  }
 }
}

canonical_original_code:
static void dirty_sprite(int n)
{
int x; int y;
 sprite_dirty[n] = 1;
 for (y = sprite_vert[n] / 8;
   y < (sprite_vert[n] + 8 - 1) / 8 + 16 / 8 ;
   y++)
 {
  for (x = sprite_horz[n] / 8;
    x < (sprite_horz[n] + 8 - 1) / 8 + 16 / 8;
    x++)
  {
   if (y >= 0 && y < 30 && x >= 0 && x < 32)
    dirtybuffer[y * 32 + x] = 1;
  }
 }
}

variable_types: n int


decompiled_code:
void *__fastcall meadows_hardware_w(int a1, int a2)
{
void *result; // rax

if ( !a1 )
{
result = &meadows_0c00;
if ( meadows_0c00 != a2 )
meadows_0c00 = a2;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(int a1, int a2)
{
void *result; // rax

if ( !a1 )
{
result = &meadows_0c00;
if ( meadows_0c00 != a2 )
meadows_0c00 = a2;
}
return result;
}

original_code:
void meadows_hardware_w(offs_t offset,data_t data)
{
 switch( offset ) {
  case 0:
   if (meadows_0c00 == data)
    break;
   meadows_0c00 = data;
            break;
  case 1:
            break;
        case 2:
            break;
  case 3:
   break;
 }
}

canonical_original_code:
void meadows_hardware_w(unsigned int offset, unsigned int data)
{
 switch( offset ) {
  case 0:
   if (meadows_0c00 == data)
    break;
   meadows_0c00 = data;
            break;
  case 1:
            break;
        case 2:
            break;
  case 3:
   break;
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

result = 0LL;
if ( !a1 )
result = meadows_0c00;
return result;
}

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

result = 0LL;
if ( !a1 )
result = meadows_0c00;
return result;
}

original_code:
static data_t sound_hardware_r(offs_t offset)
{
 int data = 0;
 switch( offset ) {
  case 0:
   data = meadows_0c00;
            break;
  case 1: break;
  case 2: break;
  case 3: break;
 }
    return data;
}

canonical_original_code:
static unsigned int sound_hardware_r(unsigned int offset)
{
 int data = 0;
 switch( offset ) {
  case 0:
   data = meadows_0c00;
            break;
  case 1: break;
  case 2: break;
  case 3: break;
 }
    return data;
}

variable_types: data int

return_type: unsigned int


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

v1 = 0xFF000000FFLL;
channel = mixer_allocate_channels(2LL, &v1);
mixer_set_volume((unsigned int)channel, 0LL);
mixer_play_sample((unsigned int)channel, &waveform, 2LL, (unsigned int)freq1, 1LL);
mixer_set_volume((unsigned int)(channel + 1), 0LL);
mixer_play_sample((unsigned int)(channel + 1), &waveform, 2LL, (unsigned int)freq2, 1LL);
return 0LL;
}

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

v1 = 0xFF000000FFLL;
channel = mixer_allocate_channels(2LL, &v1);
mixer_set_volume((unsigned int)channel, 0LL);
mixer_play_sample((unsigned int)channel, &waveform, 2LL, (unsigned int)freq1, 1LL);
mixer_set_volume((unsigned int)(channel + 1), 0LL);
mixer_play_sample((unsigned int)(channel + 1), &waveform, 2LL, (unsigned int)freq2, 1LL);
return 0LL;
}

original_code:
int meadows_sh_start(const struct MachineSound *msound)
{
 int vol[2];
 vol[0]=vol[1]=255;
 channel = mixer_allocate_channels(2,vol);
 mixer_set_volume(channel,0);
 mixer_play_sample(channel,waveform,sizeof(waveform),freq1,1);
 mixer_set_volume(channel+1,0);
 mixer_play_sample(channel+1,waveform,sizeof(waveform),freq2,1);
    return 0;
}

canonical_original_code:
int meadows_sh_start(struct MachineSound *msound)
{
 int vol[2];
 vol[0]=vol[1]=255;
 channel = mixer_allocate_channels(2,vol);
 mixer_set_volume(channel,0);
 mixer_play_sample(channel,waveform,sizeof(waveform),freq1,1);
 mixer_set_volume(channel+1,0);
 mixer_play_sample(channel+1,waveform,sizeof(waveform),freq2,1);
    return 0;
}

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

variable_types:
vol
int [2]


decompiled_code:
__int64 meadows_sh_stop()
{
mixer_stop_sample((unsigned int)channel);
return mixer_stop_sample((unsigned int)(channel + 1));
}

canonical_decompiled_code:
__int64 func5()
{
mixer_stop_sample((unsigned int)channel);
return mixer_stop_sample((unsigned int)(channel + 1));
}

original_code:
void meadows_sh_stop(void)
{
 mixer_stop_sample(channel);
    mixer_stop_sample(channel+1);
}

canonical_original_code:
void meadows_sh_stop()
{
 mixer_stop_sample(channel);
    mixer_stop_sample(channel+1);
}


decompiled_code:
__int64 deadeye_vh_start()
{
unsigned int v0; // er12

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&deadeye_artwork, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // er12

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&deadeye_artwork, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

original_code:
int deadeye_vh_start(void)
{
 if( generic_vh_start() ) return 1;
 overlay_create(deadeye_artwork, 2, Machine->drv->total_colors - 2);
    return 0;
}

canonical_original_code:
int deadeye_vh_start()
{
 if( generic_vh_start() ) return 1;
 overlay_create(deadeye_artwork, 2, Machine->drv->total_colors - 2);
    return 0;
}


decompiled_code:
__int64 gypsyjug_vh_start()
{
unsigned int v0; // er12

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&gypsyjug_artwork, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // er12

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&gypsyjug_artwork, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

original_code:
int gypsyjug_vh_start(void)
{
 if( generic_vh_start() ) return 1;
 overlay_create(gypsyjug_artwork, 2, Machine->drv->total_colors - 2);
    return 0;
}

canonical_original_code:
int gypsyjug_vh_start()
{
 if( generic_vh_start() ) return 1;
 overlay_create(gypsyjug_artwork, 2, Machine->drv->total_colors - 2);
    return 0;
}


decompiled_code:
__int64 __fastcall meadows_draw_sprites(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax
int v3; // er8

for ( i = 1LL; i != 5; ++i )
{
result = dword_1110C[i];
if ( (_DWORD)result )
{
v3 = dword_110DC[i];
dword_1110C[i] = 0;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (int)i + 512),
v3 & 0xF,
1LL,
(unsigned int)(v3 >> 5),
0LL,
dword_110FC[i],
dword_110EC[i],
Machine + 776LL,
2LL,
0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax
int v3; // er8

for ( i = 1LL; i != 5; ++i )
{
result = dword_1110C[i];
if ( (_DWORD)result )
{
v3 = dword_110DC[i];
dword_1110C[i] = 0;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (int)i + 512),
v3 & 0xF,
1LL,
(unsigned int)(v3 >> 5),
0LL,
dword_110FC[i],
dword_110EC[i],
Machine + 776LL,
2LL,
0LL);
}
}
return result;
}

original_code:
static void meadows_draw_sprites(struct osd_bitmap *bitmap)
{
 int i;
 for( i = 0; i < 4; i++ ) {
  int x, y, n, p, f;
  if (!sprite_dirty[i])
   continue;
  sprite_dirty[i] = 0;
  x = sprite_horz[i];
  y = sprite_vert[i];
  n = sprite_index[i] & 0x0f;
  p = i;
  f = sprite_index[i] >> 5;
  drawgfx(bitmap, Machine->gfx[p + 1],
   n, 1, f, 0, x, y,
   &Machine->visible_area,
   TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void meadows_draw_sprites(struct osd_bitmap *bitmap)
{
 int i;
 for( i = 0; i < 4; i++ ) {
  int x; int y; int n; int p; int f;
  if (!sprite_dirty[i])
   continue;
  sprite_dirty[i] = 0;
  x = sprite_horz[i];
  y = sprite_vert[i];
  n = sprite_index[i] & 0x0f;
  p = i;
  f = sprite_index[i] >> 5;
  drawgfx(bitmap, Machine->gfx[p + 1],
   n, 1, f, 0, x, y,
   &Machine->visible_area,
   TRANSPARENCY_PEN,0);
 }
}

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

variable_types: p int

variable_types: f int


decompiled_code:
__int64 __fastcall meadows_vh_screenrefresh(__int64 a1, int a2)
{
_QWORD *v3; // rdx
__int64 v4; // rdi
__int64 i; // rbx
__int64 v6; // rbp
__int64 v7; // r12
char v8; // dl

if ( palette_recalc() || a2 )
{
v3 = dirtybuffer;
v4 = (__int64)(dirtybuffer + 1);
*dirtybuffer = 0x101010101010101LL;
v3[119] = 0x101010101010101LL;
memset(
(void *)(v4 & 0xFFFFFFFFFFFFFFF8LL),
1u,
8 * ((unsigned __int64)((unsigned int)v3 - (v4 & 0xFFFFFFF8) + 960) >> 3));
}
for ( i = 0LL; i != 960; ++i )
{
while ( !*((_BYTE *)dirtybuffer + i) )
{
if ( ++i == 960 )
return meadows_draw_sprites(a1);
}
*((_BYTE *)dirtybuffer + i) = 0;
v6 = 8 * (unsigned int)(i & 0x1F);
v7 = (unsigned int)(8 * ((int)i >> 5));
v8 = *(_BYTE *)(videoram + i);
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v8 & 0x7F, 1LL, 0LL, 0LL, v6, v7, Machine + 776LL, 0LL, 0LL);
meadows_char_dirty(v6, v7);
}
return meadows_draw_sprites(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
_QWORD *v3; // rdx
__int64 v4; // rdi
__int64 i; // rbx
__int64 v6; // rbp
__int64 v7; // r12
char v8; // dl

if ( palette_recalc() || a2 )
{
v3 = dirtybuffer;
v4 = (__int64)(dirtybuffer + 1);
*dirtybuffer = 0x101010101010101LL;
v3[119] = 0x101010101010101LL;
memset(
(void *)(v4 & 0xFFFFFFFFFFFFFFF8LL),
1u,
8 * ((unsigned __int64)((unsigned int)v3 - (v4 & 0xFFFFFFF8) + 960) >> 3));
}
for ( i = 0LL; i != 960; ++i )
{
while ( !*((_BYTE *)dirtybuffer + i) )
{
if ( ++i == 960 )
return func8(a1);
}
*((_BYTE *)dirtybuffer + i) = 0;
v6 = 8 * (unsigned int)(i & 0x1F);
v7 = (unsigned int)(8 * ((int)i >> 5));
v8 = *(_BYTE *)(videoram + i);
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v8 & 0x7F, 1LL, 0LL, 0LL, v6, v7, Machine + 776LL, 0LL, 0LL);
func0(v6, v7);
}
return func8(a1);
}

original_code:
void meadows_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i;
 if (palette_recalc() || full_refresh)
 {
  memset(dirtybuffer,1,30 * 32);
 }
 for (i = 0; i < 30 * 32; i++)
 {
  if (dirtybuffer[i])
  {
   int x, y;
            dirtybuffer[i] = 0;
   x = (i % 32) * 8;
   y = (i / 32) * 8;
   drawgfx(bitmap, Machine->gfx[0],
    videoram[i] & 0x7f, 1, 0,0, x, y,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0);
   meadows_char_dirty(x,y);
  }
 }
 meadows_draw_sprites(bitmap);
}

canonical_original_code:
void meadows_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i;
 if (palette_recalc() || full_refresh)
 {
  memset(dirtybuffer,1,30 * 32);
 }
 for (i = 0; i < 30 * 32; i++)
 {
  if (dirtybuffer[i])
  {
   int x; int y;
            dirtybuffer[i] = 0;
   x = (i % 32) * 8;
   y = (i / 32) * 8;
   drawgfx(bitmap, Machine->gfx[0],
    videoram[i] & 0x7f, 1, 0,0, x, y,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0);
   meadows_char_dirty(x,y);
  }
 }
 meadows_draw_sprites(bitmap);
}


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

if ( a1 == 2 )
return flip_bits[(unsigned __int8)(cycles_currently_ran() - cycles_at_vsync)];
if ( a1 > 2 )
{
if ( a1 == 3 )
result = input_port_2_r(0LL);
else
result = 0LL;
}
else if ( a1 )
{
result = input_port_1_r(0LL);
}
else
{
result = input_port_0_r(0LL);
}
return result;
}

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

if ( a1 == 2 )
return flip_bits[(unsigned __int8)(cycles_currently_ran() - cycles_at_vsync)];
if ( a1 > 2 )
{
if ( a1 == 3 )
result = input_port_2_r(0LL);
else
result = 0LL;
}
else if ( a1 )
{
result = input_port_1_r(0LL);
}
else
{
result = input_port_0_r(0LL);
}
return result;
}

original_code:
data_t meadows_hardware_r(offs_t offset)
{
 switch( offset ) {
        case 0:
            return input_port_0_r(0);
        case 1:
            return input_port_1_r(0);
        case 2:
   return flip_bits[(cycles_currently_ran() - cycles_at_vsync) & 0xff];
        case 3:
            return input_port_2_r(0);
    }
    return 0;
}

canonical_original_code:
unsigned int meadows_hardware_r(unsigned int offset)
{
 switch( offset ) {
        case 0:
            return input_port_0_r(0);
        case 1:
            return input_port_1_r(0);
        case 2:
   return flip_bits[(cycles_currently_ran() - cycles_at_vsync) & 0xff];
        case 3:
            return input_port_2_r(0);
    }
    return 0;
}


decompiled_code:
__int64 meadows_interrupt()
{
int v0; // eax
bool v1; // zf

v0 = cycles_currently_ran();
v1 = sense_state_3 == 1;
sense_state_3 ^= 1u;
cycles_at_vsync = v0;
cpu_set_irq_line(0LL, 1LL, !v1);
if ( (input_port_3_r(0LL) & 1) != 0 && !coin1_state_2 )
{
coin1_state_2 = 1;
cpu_irq_line_vector_w(0LL, 0LL, 130LL);
cpu_set_irq_line(0LL, 0LL, 3LL);
}
coin1_state_2 = 0;
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax
bool v1; // zf

v0 = cycles_currently_ran();
v1 = sense_state_3 == 1;
sense_state_3 ^= 1u;
cycles_at_vsync = v0;
cpu_set_irq_line(0LL, 1LL, !v1);
if ( (input_port_3_r(0LL) & 1) != 0 && !coin1_state_2 )
{
coin1_state_2 = 1;
cpu_irq_line_vector_w(0LL, 0LL, 130LL);
cpu_set_irq_line(0LL, 0LL, 3LL);
}
coin1_state_2 = 0;
return ignore_interrupt();
}

original_code:
int meadows_interrupt(void)
{
static int sense_state = 0;
static int coin1_state = 0;
    cycles_at_vsync = cycles_currently_ran();
 sense_state ^= 1;
 cpu_set_irq_line( 0, 1, (sense_state) ? 1 : 0);
 if( input_port_3_r(0) & 0x01 ) {
  if( !coin1_state ) {
   coin1_state = 1;
   cpu_irq_line_vector_w(0,0,0x82);
   cpu_set_irq_line(0,0,3);
  }
 }
 coin1_state = 0;
 return ignore_interrupt();
}

canonical_original_code:
int meadows_interrupt()
{
static int sense_state = 0;
static int coin1_state = 0;
    cycles_at_vsync = cycles_currently_ran();
 sense_state ^= 1;
 cpu_set_irq_line( 0, 1, (sense_state) ? 1 : 0);
 if( input_port_3_r(0) & 0x01 ) {
  if( !coin1_state ) {
   coin1_state = 1;
   cpu_irq_line_vector_w(0,0,0x82);
   cpu_set_irq_line(0,0,3);
  }
 }
 coin1_state = 0;
 return ignore_interrupt();
}


decompiled_code:
__int64 init_gypsyjug()
{
int v0; // ebx
const void *v1; // rbp
void *v2; // rax
size_t v3; // rdx
__int64 v4; // rbx
__int64 v5; // rax
__m128i v6; // xmm0
__int64 v7; // rax
__m128i v8; // xmm0
__int64 result; // rax

v0 = memory_region_length(139LL);
v1 = (const void *)memory_region(138LL);
v2 = (void *)memory_region(139LL);
v3 = v0;
v4 = 0LL;
memcpy(v2, v1, v3);
while ( 1 )
{
result = memory_region_length(140LL);
if ( (int)result <= (int)v4 )
break;
v5 = memory_region(140LL);
v6 = _mm_load_si128((const __m128i *)&LC0);
*(_OWORD *)(v5 + v4) = 0LL;
*(__m128i *)(v5 + v4 + 16) = v6;
v7 = memory_region(141LL);
v8 = _mm_load_si128((const __m128i *)&LC0);
*(_OWORD *)(v7 + v4) = 0LL;
*(__m128i *)(v7 + v4 + 16) = v8;
v4 += 32LL;
}
return result;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // ebx
const void *v1; // rbp
void *v2; // rax
size_t v3; // rdx
__int64 v4; // rbx
__int64 v5; // rax
__m128i v6; // xmm0
__int64 v7; // rax
__m128i v8; // xmm0
__int64 result; // rax

v0 = memory_region_length(139LL);
v1 = (const void *)memory_region(138LL);
v2 = (void *)memory_region(139LL);
v3 = v0;
v4 = 0LL;
memcpy(v2, v1, v3);
while ( 1 )
{
result = memory_region_length(140LL);
if ( (int)result <= (int)v4 )
break;
v5 = memory_region(140LL);
v6 = _mm_load_si128((const __m128i *)&LC0);
*(_OWORD *)(v5 + v4) = 0LL;
*(__m128i *)(v5 + v4 + 16) = v6;
v7 = memory_region(141LL);
v8 = _mm_load_si128((const __m128i *)&LC0);
*(_OWORD *)(v7 + v4) = 0LL;
*(__m128i *)(v7 + v4 + 16) = v8;
v4 += 32LL;
}
return result;
}

original_code:
static void init_gypsyjug(void)
{
int i;
static unsigned char ball[16*2] = {
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x01,0x80, 0x03,0xc0, 0x03,0xc0, 0x01,0x80};
 memcpy(memory_region(REGION_GFX3),memory_region(REGION_GFX2),memory_region_length(REGION_GFX3));
 for (i = 0; i < memory_region_length(REGION_GFX4); i += 16*2)
 {
  memcpy(memory_region(REGION_GFX4) + i, ball, sizeof(ball));
  memcpy(memory_region(REGION_GFX5) + i, ball, sizeof(ball));
 }
}

canonical_original_code:
static void init_gypsyjug()
{
int i;
static unsigned char ball[-1] = {
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x01,0x80, 0x03,0xc0, 0x03,0xc0, 0x01,0x80};
 memcpy(memory_region(REGION_GFX3),memory_region(REGION_GFX2),memory_region_length(REGION_GFX3));
 for (i = 0; i < memory_region_length(REGION_GFX4); i += 16*2)
 {
  memcpy(memory_region(REGION_GFX4) + i, ball, sizeof(ball));
  memcpy(memory_region(REGION_GFX5) + i, ball, sizeof(ball));
 }
}

variable_types:
ball
unsigned char [-1]


decompiled_code:
__int64 meadows_sh_update()
{
int v0; // ecx
int v1; // er13
unsigned int v2; // ebp
int v3; // eax
__int64 result; // rax
unsigned int v5; // ebp
int v6; // eax
int v7; // eax

v0 = meadows_0c03;
if ( latched_0c01_6 == meadows_0c01 && latched_0c03_5 == meadows_0c03 )
{
result = meadows_0c02;
if ( meadows_0c02 == latched_0c02_4 )
goto LABEL_14;
goto LABEL_9;
}
v1 = 0;
if ( (meadows_0c03 & 8) != 0 )
v1 = (meadows_0c01 >> 1) & 0x78;
if ( (unsigned int)s2650_get_flag() )
v1 += 128;
v2 = ~meadows_0c01 & 0xF;
v3 = freq1;
if ( (~meadows_0c01 & 0xF) != 0 )
{
v3 = 19531 / (int)(v2 + 1);
v2 = 100 * v1 / 0xFFu;
freq1 = v3;
}
mixer_set_sample_frequency((unsigned int)channel, (unsigned int)(2 * v3));
mixer_set_volume((unsigned int)channel, v2);
v0 = meadows_0c03;
result = meadows_0c02;
if ( latched_0c02_4 != meadows_0c02 || latched_0c03_5 != meadows_0c03 )
{
LABEL_9:
v5 = (unsigned __int8)~(_BYTE)result;
v6 = freq2;
if ( v5 )
{
v7 = 156250 / (int)(v5 + 1);
v5 = 100 * ((v0 << 30 >> 31) & 0xA0u) / 0xFF;
if ( (v0 & 1) != 0 )
v6 = v7 >> 1;
else
v6 = v7 >> 2;
freq2 = v6;
}
mixer_set_sample_frequency((unsigned int)(channel + 1), (unsigned int)(2 * v6));
mixer_set_volume((unsigned int)(channel + 1), v5);
LOBYTE(v0) = meadows_0c03;
if ( latched_0c03_5 == meadows_0c03 )
{
result = meadows_0c02;
}
else
{
dac_enable = meadows_0c03 & 4;
if ( (meadows_0c03 & 4) != 0 )
DAC_data_w(0LL, (unsigned __int8)meadows_dac);
else
DAC_data_w(0LL, 0LL);
result = meadows_0c02;
LOBYTE(v0) = meadows_0c03;
}
}
LABEL_14:
latched_0c02_4 = result;
latched_0c03_5 = v0;
latched_0c01_6 = meadows_0c01;
return result;
}

canonical_decompiled_code:
__int64 func15()
{
int v0; // ecx
int v1; // er13
unsigned int v2; // ebp
int v3; // eax
__int64 result; // rax
unsigned int v5; // ebp
int v6; // eax
int v7; // eax

v0 = meadows_0c03;
if ( latched_0c01_6 == meadows_0c01 && latched_0c03_5 == meadows_0c03 )
{
result = meadows_0c02;
if ( meadows_0c02 == latched_0c02_4 )
goto LABEL_14;
goto LABEL_9;
}
v1 = 0;
if ( (meadows_0c03 & 8) != 0 )
v1 = (meadows_0c01 >> 1) & 0x78;
if ( (unsigned int)s2650_get_flag() )
v1 += 128;
v2 = ~meadows_0c01 & 0xF;
v3 = freq1;
if ( (~meadows_0c01 & 0xF) != 0 )
{
v3 = 19531 / (int)(v2 + 1);
v2 = 100 * v1 / 0xFFu;
freq1 = v3;
}
mixer_set_sample_frequency((unsigned int)channel, (unsigned int)(2 * v3));
mixer_set_volume((unsigned int)channel, v2);
v0 = meadows_0c03;
result = meadows_0c02;
if ( latched_0c02_4 != meadows_0c02 || latched_0c03_5 != meadows_0c03 )
{
LABEL_9:
v5 = (unsigned __int8)~(_BYTE)result;
v6 = freq2;
if ( v5 )
{
v7 = 156250 / (int)(v5 + 1);
v5 = 100 * ((v0 << 30 >> 31) & 0xA0u) / 0xFF;
if ( (v0 & 1) != 0 )
v6 = v7 >> 1;
else
v6 = v7 >> 2;
freq2 = v6;
}
mixer_set_sample_frequency((unsigned int)(channel + 1), (unsigned int)(2 * v6));
mixer_set_volume((unsigned int)(channel + 1), v5);
LOBYTE(v0) = meadows_0c03;
if ( latched_0c03_5 == meadows_0c03 )
{
result = meadows_0c02;
}
else
{
dac_enable = meadows_0c03 & 4;
if ( (meadows_0c03 & 4) != 0 )
DAC_data_w(0LL, (unsigned __int8)meadows_dac);
else
DAC_data_w(0LL, 0LL);
result = meadows_0c02;
LOBYTE(v0) = meadows_0c03;
}
}
LABEL_14:
latched_0c02_4 = result;
latched_0c03_5 = v0;
latched_0c01_6 = meadows_0c01;
return result;
}

original_code:
void meadows_sh_update(void)
{
static unsigned char latched_0c01 = 0;
static unsigned char latched_0c02 = 0;
static unsigned char latched_0c03 = 0;
int preset, amp;
    if (latched_0c01 != meadows_0c01 || latched_0c03 != meadows_0c03)
 {
  amp = ((meadows_0c03 & 0x08) == 0) ? 0 : (meadows_0c01 & 0xf0) >> 1;
  if( s2650_get_flag() )
   amp += 0x80;
  preset = (meadows_0c01 & 15) ^ 15;
  if (preset)
   freq1 = (5000000 / 256) / (preset + 1);
  else amp = 0;
  mixer_set_sample_frequency(channel, freq1 * sizeof(waveform));
  mixer_set_volume(channel,amp*100/255);
    }
 if (latched_0c02 != meadows_0c02 || latched_0c03 != meadows_0c03)
 {
  amp = ((meadows_0c03 & 0x02) != 0) ? 0xa0 : 0;
  preset = meadows_0c02 ^ 0xff;
  if (preset)
  {
   freq2 = (5000000 / 32) / (preset + 1) / 2;
   if ((meadows_0c03 & 0x01) == 0)
    freq2 >>= 1;
  }
  else amp = 0;
  mixer_set_sample_frequency(channel+1, freq2 * sizeof(waveform));
  mixer_set_volume(channel+1,amp*100/255);
    }
 if (latched_0c03 != meadows_0c03)
 {
  dac_enable = meadows_0c03 & 0x04;
  if (dac_enable)
   DAC_data_w(0, meadows_dac);
  else
   DAC_data_w(0, 0);
    }
    latched_0c01 = meadows_0c01;
 latched_0c02 = meadows_0c02;
 latched_0c03 = meadows_0c03;
}

canonical_original_code:
void meadows_sh_update()
{
static unsigned char latched_0c01 = 0;
static unsigned char latched_0c02 = 0;
static unsigned char latched_0c03 = 0;
int preset; int amp;
    if (latched_0c01 != meadows_0c01 || latched_0c03 != meadows_0c03)
 {
  amp = ((meadows_0c03 & 0x08) == 0) ? 0 : (meadows_0c01 & 0xf0) >> 1;
  if( s2650_get_flag() )
   amp += 0x80;
  preset = (meadows_0c01 & 15) ^ 15;
  if (preset)
   freq1 = (5000000 / 256) / (preset + 1);
  else amp = 0;
  mixer_set_sample_frequency(channel, freq1 * sizeof(waveform));
  mixer_set_volume(channel,amp*100/255);
    }
 if (latched_0c02 != meadows_0c02 || latched_0c03 != meadows_0c03)
 {
  amp = ((meadows_0c03 & 0x02) != 0) ? 0xa0 : 0;
  preset = meadows_0c02 ^ 0xff;
  if (preset)
  {
   freq2 = (5000000 / 32) / (preset + 1) / 2;
   if ((meadows_0c03 & 0x01) == 0)
    freq2 >>= 1;
  }
  else amp = 0;
  mixer_set_sample_frequency(channel+1, freq2 * sizeof(waveform));
  mixer_set_volume(channel+1,amp*100/255);
    }
 if (latched_0c03 != meadows_0c03)
 {
  dac_enable = meadows_0c03 & 0x04;
  if (dac_enable)
   DAC_data_w(0, meadows_dac);
  else
   DAC_data_w(0, 0);
    }
    latched_0c01 = meadows_0c01;
 latched_0c02 = meadows_0c02;
 latched_0c03 = meadows_0c03;
}

variable_types: preset int

variable_types: amp int


decompiled_code:
__int64 __fastcall meadows_sh_dac_w(unsigned __int8 a1)
{
__int64 result; // rax

meadows_dac = a1;
if ( dac_enable )
result = DAC_data_w(0LL, a1);
else
result = DAC_data_w(0LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned __int8 a1)
{
__int64 result; // rax

meadows_dac = a1;
if ( dac_enable )
result = DAC_data_w(0LL, a1);
else
result = DAC_data_w(0LL, 0LL);
return result;
}

original_code:
void meadows_sh_dac_w(int data)
{
 meadows_dac = data;
 if (dac_enable)
  DAC_data_w(0, meadows_dac);
 else
  DAC_data_w(0, 0);
}


decompiled_code:
__int64 sound_interrupt()
{
bool v0; // zf

v0 = sense_state_1 == 1;
sense_state_1 ^= 1u;
cpu_set_irq_line(1LL, 1LL, !v0);
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func12()
{
bool v0; // zf

v0 = sense_state_1 == 1;
sense_state_1 ^= 1u;
cpu_set_irq_line(1LL, 1LL, !v0);
return ignore_interrupt();
}

original_code:
static int sound_interrupt(void)
{
 static int sense_state = 0;
 sense_state ^= 1;
 cpu_set_irq_line( 1, 1, (sense_state) ? 1 : 0 );
 return ignore_interrupt();
}

canonical_original_code:
static int sound_interrupt()
{
 static int sense_state = 0;
 sense_state ^= 1;
 cpu_set_irq_line( 1, 1, (sense_state) ? 1 : 0 );
 return ignore_interrupt();
}


decompiled_code:
void *__fastcall init_palette(__int64 a1, void *a2)
{
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return memcpy(a2, &colortable, (size_t)&unk_10004);
}

canonical_decompiled_code:
void *__fastcall func13(__int64 a1, void *a2)
{
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return memcpy(a2, &colortable, (size_t)&unk_10004);
}

original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}

canonical_original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable, unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}