decompiled_code:
__int64 __fastcall kl_sphere_extend(__int64 a1, float *a2, float *a3)
{
__int64 result; // rax
float v5; // xmm0_4
float v6[3]; // [rsp+0h] [rbp-50h] BYREF
__int64 v7; // [rsp+Ch] [rbp-44h] BYREF
unsigned int v8; // [rsp+14h] [rbp-3Ch]
float v9[3]; // [rsp+18h] [rbp-38h] BYREF
float v10[11]; // [rsp+24h] [rbp-2Ch] BYREF

result = kl_sphere_test(a2, a3);
if ( (_DWORD)result )
{
*(__m128i *)a1 = _mm_loadu_si128((const __m128i *)a2);
}
else
{
kl_vec3f_sub(v10, a2, a3);
kl_vec3f_norm((__int64)v10, v10);
kl_vec3f_scale(v9, v10, a2[3]);
kl_vec3f_add(v9, v9, a2);
kl_vec3f_add((float *)&v7, v9, a3);
kl_vec3f_scale((float *)&v7, (float *)&v7, 0.5);
kl_vec3f_sub(v6, v9, a3);
v5 = kl_vec3f_magnitude(v6);
*(_QWORD *)a1 = v7;
result = v8;
*(_DWORD *)(a1 + 8) = v8;
*(float *)(a1 + 12) = v5 * 0.5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, float *a2, float *a3)
{
__int64 result; // rax
float v5; // xmm0_4
float v6[3]; // [rsp+0h] [rbp-50h] BYREF
__int64 v7; // [rsp+Ch] [rbp-44h] BYREF
unsigned int v8; // [rsp+14h] [rbp-3Ch]
float v9[3]; // [rsp+18h] [rbp-38h] BYREF
float v10[11]; // [rsp+24h] [rbp-2Ch] BYREF

result = func6(a2, a3);
if ( (_DWORD)result )
{
*(__m128i *)a1 = _mm_loadu_si128((const __m128i *)a2);
}
else
{
func1(v10, a2, a3);
func4((__int64)v10, v10);
func2(v9, v10, a2[3]);
func0(v9, v9, a2);
func0((float *)&v7, v9, a3);
func2((float *)&v7, (float *)&v7, 0.5);
func1(v6, v9, a3);
v5 = func3(v6);
*(_QWORD *)a1 = v7;
result = v8;
*(_DWORD *)(a1 + 8) = v8;
*(float *)(a1 + 12) = v5 * 0.5;
}
return result;
}

original_code:
void kl_sphere_extend(kl_sphere_t *dst, kl_sphere_t *s1, kl_vec3f_t *s2) {
  if (kl_sphere_test(s1, s2)) {
    *dst = *s1;
    return;
  }
  kl_vec3f_t dir;
  kl_vec3f_sub(&dir, &s1->center, s2);
  kl_vec3f_norm(&dir, &dir);
  kl_vec3f_t far;
  kl_vec3f_scale(&far, &dir, s1->radius);
  kl_vec3f_add(&far, &far, &s1->center);
  kl_vec3f_t center;
  kl_vec3f_add(&center, &far, s2);
  kl_vec3f_scale(&center, &center, 0.5f);
  kl_vec3f_t temp;
  kl_vec3f_sub(&temp, &far, s2);
  float radius = kl_vec3f_magnitude(&temp) / 2.0f;
  *dst = (kl_sphere_t){
    .center = center,
    .radius = radius
  };
}

canonical_original_code:
void kl_sphere_extend(struct kl_sphere *dst, struct kl_sphere *s1, struct kl_vec3f *s2) {
  if (kl_sphere_test(s1, s2)) {
    *dst = *s1;
    return;
  }
  struct kl_vec3f dir;
  kl_vec3f_sub(&dir, &s1->center, s2);
  kl_vec3f_norm(&dir, &dir);
  struct kl_vec3f far;
  kl_vec3f_scale(&far, &dir, s1->radius);
  kl_vec3f_add(&far, &far, &s1->center);
  struct kl_vec3f center;
  kl_vec3f_add(&center, &far, s2);
  kl_vec3f_scale(&center, &center, 0.5f);
  struct kl_vec3f temp;
  kl_vec3f_sub(&temp, &far, s2);
  float radius = kl_vec3f_magnitude(&temp) / 2.0f;
  *dst = (struct kl_sphere){
    .center = center,
    .radius = radius
  };
}

variable_types:
far
struct kl_vec3f { float x; }


repo: zvxryb/kludge-engine

original_code:
void kl_sphere_bounds(kl_sphere_t *dst, kl_vec3f_t *verts, int n) {
  if (n < 1) return;
  kl_sphere_t bounds = {
    .center = verts[0],
    .radius = 0.0f
  };
  for (int i=0; i < n; i++) {
    kl_vec3f_t *v = verts + i;
    if (kl_sphere_test(&bounds, v)) continue;
    kl_sphere_extend(&bounds, &bounds, v);
  }
  *dst = bounds;
}

canonical_original_code:
void kl_sphere_bounds(struct kl_sphere *dst, struct kl_vec3f *verts, int n) {
  if (n < 1) return;
  struct kl_sphere bounds = {
    .center = verts[0],
    .radius = 0.0f
  };
  for (int i = 0; i < n; i++) {
    struct kl_vec3f *v = verts + i;
    if (kl_sphere_test(&bounds, v)) continue;
    kl_sphere_extend(&bounds, &bounds, v);
  }
  *dst = bounds;
}

variable_types: struct kl_sphere { struct kl_vec3f { float x; } center; float radius; } *

variable_types:
verts
struct kl_vec3f *

variable_types: n int

variable_types: i int

variable_types:
v
struct kl_vec3f { float x; } *

return_type: void

user_defined_types: struct kl_sphere { struct kl_vec3f center; float radius; }


original_code:
_Bool kl_model_isiqm2(uint8_t *data, int size) {
  iqm_header_t *header = (iqm_header_t*)data;
  if (data == ((void *)0)) return 0;
  if (size < sizeof(iqm_header_t)) return 1;
  return header->magic[0] == iqm_magic[0] && header->magic[1] == iqm_magic[1] &&
         header->magic[2] == iqm_magic[2] && header->magic[3] == iqm_magic[3];
}

canonical_original_code:
_Bool kl_model_isiqm2(unsigned char *data, int size) {
  struct iqm_header *header = (iqm_header_t*)data;
  if (data == ((void *)0)) return 0;
  if (size < sizeof(iqm_header_t)) return 1;
  return header->magic[0] == iqm_magic[0] && header->magic[1] == iqm_magic[1] &&
         header->magic[2] == iqm_magic[2] && header->magic[3] == iqm_magic[3];
}

variable_types:
data
unsigned char *

variable_types: size int

variable_types: struct iqm_header { unsigned int magic[4]; unsigned int version; unsigned int filesize; unsigned int flags; unsigned int text_n; unsigned int mesh_n; unsigned int vertarray_n; unsigned int tris_n; unsigned int joints_n; unsigned int poses_n; unsigned int anims_n; unsigned int frames_n; unsigned int comment_n; unsigned int ext_n; } *


repo: zwizwa/shaco

original_code:
int test1(void) {
    struct vars vars = {};
    struct shaco sc = {};
    do {
        parse(&sc, &vars);
        *(int*)sc.buf = 3;
    } while(sc.next);
    return 0;
}

canonical_original_code:
int test1() {
    struct vars vars = {};
    struct shaco sc = {};
    do {
        parse(&sc, &vars);
        *(int *)sc.buf = 3;
    } while(sc.next);
    return 0;
}

variable_types:
vars
struct vars { int i; int j; int a; }

variable_types: struct shaco { void **next; void *buf; int size; }

return_type: int


original_code:
int test2(void) {
    struct vars vars = {};
    struct shaco sc = {};
    int stream[] = {3,
                    3, 101, 102, 103,
                    2, 101, 102,
                    1, 101};
    int i = 0;
    do {
        parse(&sc, &vars);
        *(int*)sc.buf = stream[i++];
    } while (sc.next);
    return 0;
}

canonical_original_code:
int test2() {
    struct vars vars = {};
    struct shaco sc = {};
    int stream[] = {3,
                    3, 101, 102, 103,
                    2, 101, 102,
                    1, 101};
    int i = 0;
    do {
        parse(&sc, &vars);
        *(int *)sc.buf = stream[i++];
    } while (sc.next);
    return 0;
}

variable_types:
stream
int []

user_defined_types: struct shaco { void **next; void *buf; int size; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test1(argc, argv, envp);
test2();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func11(argc, argv, envp);
func12();
return 0;
}

original_code:
int main(void) {
    test1();
    test2();
    return 0;
}

canonical_original_code:
int main() {
    test1();
    test2();
    return 0;
}


repo: zwizwa/sl-apdu

decompiled_code:
int __fastcall apdu_cb(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx

fwrite("APDU:", 1uLL, 5uLL, stderr);
if ( a2 )
{
v2 = a1;
do
fprintf(stderr, " %02x", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func11(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx

fwrite("APDU:", 1uLL, 5uLL, stderr);
if ( a2 )
{
v2 = a1;
do
fprintf(stderr, " %02x", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return fputc(10, stderr);
}

original_code:
static void apdu_cb(u8 *buf, uint len, void *ctx) {
    fprintf(stderr, "APDU:");
    uint i;
    for (i=0; i<len; i++) fprintf(stderr, " %02x", buf[i]);
    fprintf(stderr, "\n");
}

canonical_original_code:
static void apdu_cb(unsigned char *buf, unsigned int len, void *ctx) {
    fprintf(stderr, "APDU:");
    unsigned int i;
    for (i=0; i<len; i++) fprintf(stderr, " %02x", buf[i]);
    fprintf(stderr, "\n");
}

variable_types:
buf
unsigned char *

variable_types:
len
unsigned int

variable_types:
ctx
void *

variable_types:
i
unsigned int


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

if ( !a2 )
{
a1[6] = 0;
result = memset(a1 + 8, 0, 0x20000uLL);
}
if ( a1[4] != a2 )
a1[4] = a2;
return result;
}

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

if ( !a2 )
{
a1[6] = 0;
result = memset(a1 + 8, 0, 0x20000uLL);
}
if ( a1[4] != a2 )
a1[4] = a2;
return result;
}

original_code:
static void set_state(struct apdu_split *as, enum iso7816_apdu_state new_state)
{
 switch (new_state) {
 case APDU_S_CLA:
  as->apdu_len = 0;
  memset(as->apdu_buf, 0, sizeof(as->apdu_buf));
  break;
 }
 if (as->state == new_state)
  return;
 as->state = new_state;
}

variable_types: struct apdu_split { void (*apdu_out_cb)(unsigned char *buf, unsigned int len, void *user_data); void *user_data; enum iso7816_apdu_state { APDU_S_CLA=0, APDU_S_INS=1, APDU_S_P1=2, APDU_S_P2=3, APDU_S_P3=4, APDU_S_DATA=5, APDU_S_DATA_SINGLE=6, APDU_S_SW1=7, APDU_S_SW2=8 } state; unsigned char apdu_ins; unsigned int apdu_len; unsigned int apdu_data_remaining; unsigned char apdu_buf[-1]; } *

user_defined_types: struct apdu_split { void (*apdu_out_cb)(unsigned char *buf, unsigned int len, void *user_data); void *user_data; enum iso7816_apdu_state state; unsigned char apdu_ins; unsigned int apdu_len; unsigned int apdu_data_remaining; unsigned char apdu_buf[-1]; }


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

LODWORD(result) = *(_DWORD *)(a1 + 24);
if ( (unsigned int)result > 0x1FFFF )
__assert_fail("as->apdu_len < sizeof(as->apdu_buf)", "apdu_split.c", 0x45u, "apdu_buf_append");
*(_DWORD *)(a1 + 24) = result + 1;
result = (unsigned int)result;
*(_BYTE *)(a1 + (unsigned int)result + 32) = a2;
return result;
}

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

LODWORD(result) = *(_DWORD *)(a1 + 24);
if ( (unsigned int)result > 0x1FFFF )
__assert_fail("as->apdu_len < sizeof(as->apdu_buf)", "apdu_split.c", 0x45u, "apdu_buf_append");
*(_DWORD *)(a1 + 24) = result + 1;
result = (unsigned int)result;
*(_BYTE *)(a1 + (unsigned int)result + 32) = a2;
return result;
}

original_code:
static void apdu_buf_append(struct apdu_split *as, uint8_t ch)
{
 ((void) sizeof ((as->apdu_len < sizeof(as->apdu_buf)) ? 1 : 0), __extension__ ({ if (as->apdu_len < sizeof(as->apdu_buf)) ; else __assert_fail ("as->apdu_len < sizeof(as->apdu_buf)", "apdu_split.c", 69, __extension__ __PRETTY_FUNCTION__); }));
 as->apdu_buf[as->apdu_len++] = ch;
}

canonical_original_code:
static void apdu_buf_append(struct apdu_split *as, unsigned char ch)
{
 ((void) sizeof ((as->apdu_len < sizeof(as->apdu_buf)) ? 1 : 0), __extension__ ({ if (as->apdu_len < sizeof(as->apdu_buf)) ; else __assert_fail ("as->apdu_len < sizeof(as->apdu_buf)", "apdu_split.c", 69, __extension__ __PRETTY_FUNCTION__); }));
 as->apdu_buf[as->apdu_len++] = ch;
}

variable_types:
ch
unsigned char

user_defined_types: enum iso7816_apdu_state { APDU_S_CLA=0, APDU_S_INS=1, APDU_S_P1=2, APDU_S_P2=3, APDU_S_P3=4, APDU_S_DATA=5, APDU_S_DATA_SINGLE=6, APDU_S_SW1=7, APDU_S_SW2=8 }


decompiled_code:
unsigned __int64 __fastcall apdu_split_inbyte(__int64 a1, unsigned __int8 a2)
{
unsigned __int64 result; // rax
int v3; // eax
unsigned __int8 v4; // al

result = *(unsigned int *)(a1 + 16);
switch ( *(_DWORD *)(a1 + 16) )
{
case 0:
case 2:
case 3:
goto LABEL_3;
case 1:
*(_BYTE *)(a1 + 20) = a2;
LABEL_3:
apdu_buf_append(a1, a2);
result = (unsigned __int64)set_state((_DWORD *)a1, *(_DWORD *)(a1 + 16) + 1);
break;
case 4:
apdu_buf_append(a1, a2);
v3 = a2;
if ( !a2 )
v3 = 256;
*(_DWORD *)(a1 + 28) = v3;
result = (unsigned __int64)set_state((_DWORD *)a1, 7);
break;
case 5:
apdu_buf_append(a1, a2);
result = (unsigned int)(*(_DWORD *)(a1 + 28) - 1);
*(_DWORD *)(a1 + 28) = result;
if ( !(_DWORD)result )
result = (unsigned __int64)set_state((_DWORD *)a1, 7);
break;
case 6:
apdu_buf_append(a1, a2);
--*(_DWORD *)(a1 + 28);
result = (unsigned __int64)set_state((_DWORD *)a1, 7);
break;
case 7:
if ( a2 != 96 )
{
v4 = *(_BYTE *)(a1 + 20);
if ( v4 == a2 || a2 == v4 + 1 )
{
result = (unsigned __int64)set_state((_DWORD *)a1, 5);
}
else
{
apdu_buf_append(a1, a2);
result = (unsigned __int64)set_state((_DWORD *)a1, 8);
}
}
break;
case 8:
apdu_buf_append(a1, a2);
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))a1)(a1 + 32, *(unsigned int *)(a1 + 24), *(_QWORD *)(a1 + 8));
result = (unsigned __int64)set_state((_DWORD *)a1, 0);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func17(__int64 a1, unsigned __int8 a2)
{
unsigned __int64 result; // rax
int v3; // eax
unsigned __int8 v4; // al

result = *(unsigned int *)(a1 + 16);
switch ( *(_DWORD *)(a1 + 16) )
{
case 0:
case 2:
case 3:
goto LABEL_3;
case 1:
*(_BYTE *)(a1 + 20) = a2;
LABEL_3:
func16(a1, a2);
result = (unsigned __int64)func15((_DWORD *)a1, *(_DWORD *)(a1 + 16) + 1);
break;
case 4:
func16(a1, a2);
v3 = a2;
if ( !a2 )
v3 = 256;
*(_DWORD *)(a1 + 28) = v3;
result = (unsigned __int64)func15((_DWORD *)a1, 7);
break;
case 5:
func16(a1, a2);
result = (unsigned int)(*(_DWORD *)(a1 + 28) - 1);
*(_DWORD *)(a1 + 28) = result;
if ( !(_DWORD)result )
result = (unsigned __int64)func15((_DWORD *)a1, 7);
break;
case 6:
func16(a1, a2);
--*(_DWORD *)(a1 + 28);
result = (unsigned __int64)func15((_DWORD *)a1, 7);
break;
case 7:
if ( a2 != 96 )
{
v4 = *(_BYTE *)(a1 + 20);
if ( v4 == a2 || a2 == v4 + 1 )
{
result = (unsigned __int64)func15((_DWORD *)a1, 5);
}
else
{
func16(a1, a2);
result = (unsigned __int64)func15((_DWORD *)a1, 8);
}
}
break;
case 8:
func16(a1, a2);
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))a1)(a1 + 32, *(unsigned int *)(a1 + 24), *(_QWORD *)(a1 + 8));
result = (unsigned __int64)func15((_DWORD *)a1, 0);
break;
default:
return result;
}
return result;
}

original_code:
static void apdu_split_inbyte(struct apdu_split *as, uint8_t ch)
{
 switch (as->state) {
 case APDU_S_INS:
  as->apdu_ins = ch;
 case APDU_S_CLA:
 case APDU_S_P1:
 case APDU_S_P2:
  apdu_buf_append(as, ch);
  set_state(as, as->state+1);
  break;
 case APDU_S_P3:
  apdu_buf_append(as, ch);
  as->apdu_data_remaining = (ch == 0 ? 256 : ch);
  set_state(as, APDU_S_SW1);
  break;
 case APDU_S_DATA:
  apdu_buf_append(as, ch);
  as->apdu_data_remaining--;
  if (as->apdu_data_remaining == 0)
   set_state(as, APDU_S_SW1);
  break;
 case APDU_S_DATA_SINGLE:
  apdu_buf_append(as, ch);
  as->apdu_data_remaining--;
  set_state(as, APDU_S_SW1);
  break;
 case APDU_S_SW1:
  if (ch == 0x60) {
  } else
  if (ch == as->apdu_ins || ch == as->apdu_ins + 1 ||
      ch == ~(as->apdu_ins+1)) {
   set_state(as, APDU_S_DATA);
  } else
  if (ch == ~(as->apdu_ins)) {
   set_state(as, APDU_S_DATA_SINGLE);
  } else {
   apdu_buf_append(as, ch);
   set_state(as, APDU_S_SW2);
  }
  break;
 case APDU_S_SW2:
  apdu_buf_append(as, ch);
  as->apdu_out_cb(as->apdu_buf, as->apdu_len, as->user_data);
  set_state(as, APDU_S_CLA);
  break;
 }
}

canonical_original_code:
static void apdu_split_inbyte(struct apdu_split *as, unsigned char ch)
{
 switch (as->state) {
 case APDU_S_INS:
  as->apdu_ins = ch;
 case APDU_S_CLA:
 case APDU_S_P1:
 case APDU_S_P2:
  apdu_buf_append(as, ch);
  set_state(as, as->state+1);
  break;
 case APDU_S_P3:
  apdu_buf_append(as, ch);
  as->apdu_data_remaining = (ch == 0 ? 256 : ch);
  set_state(as, APDU_S_SW1);
  break;
 case APDU_S_DATA:
  apdu_buf_append(as, ch);
  as->apdu_data_remaining--;
  if (as->apdu_data_remaining == 0)
   set_state(as, APDU_S_SW1);
  break;
 case APDU_S_DATA_SINGLE:
  apdu_buf_append(as, ch);
  as->apdu_data_remaining--;
  set_state(as, APDU_S_SW1);
  break;
 case APDU_S_SW1:
  if (ch == 0x60) {
  } else
  if (ch == as->apdu_ins || ch == as->apdu_ins + 1 ||
      ch == ~(as->apdu_ins+1)) {
   set_state(as, APDU_S_DATA);
  } else
  if (ch == ~(as->apdu_ins)) {
   set_state(as, APDU_S_DATA_SINGLE);
  } else {
   apdu_buf_append(as, ch);
   set_state(as, APDU_S_SW2);
  }
  break;
 case APDU_S_SW2:
  apdu_buf_append(as, ch);
  as->apdu_out_cb(as->apdu_buf, as->apdu_len, as->user_data);
  set_state(as, APDU_S_CLA);
  break;
 }
}


decompiled_code:
void *__fastcall apdu_split_reset(_DWORD *a1)
{
return set_state(a1, 0);
}

canonical_decompiled_code:
void *__fastcall func18(_DWORD *a1)
{
return func15(a1, 0);
}

original_code:
int apdu_split_reset(struct apdu_split *as)
{
 set_state(as, APDU_S_CLA);
}


decompiled_code:
void *__fastcall apdu_split_boundary(__int64 a1)
{
puts("BOUNDARY");
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))a1)(a1 + 32, *(unsigned int *)(a1 + 24), *(_QWORD *)(a1 + 8));
return set_state((_DWORD *)a1, 0);
}

canonical_decompiled_code:
void *__fastcall func19(__int64 a1)
{
puts("BOUNDARY");
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))a1)(a1 + 32, *(unsigned int *)(a1 + 24), *(_QWORD *)(a1 + 8));
return func15((_DWORD *)a1, 0);
}

original_code:
void apdu_split_boundary(struct apdu_split *as)
{
 printf("BOUNDARY\n");
 as->apdu_out_cb(as->apdu_buf, as->apdu_len, as->user_data);
 set_state(as, APDU_S_CLA);
}


decompiled_code:
unsigned __int64 __fastcall apdu_split_in(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // rbp
unsigned __int64 result; // rax

if ( a3 )
{
v3 = a2;
v4 = &a2[a3];
do
result = apdu_split_inbyte(a1, *v3++);
while ( v3 != v4 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func20(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // rbp
unsigned __int64 result; // rax

if ( a3 )
{
v3 = a2;
v4 = &a2[a3];
do
result = func17(a1, *v3++);
while ( v3 != v4 );
}
return result;
}

original_code:
void apdu_split_in(struct apdu_split *as, uint8_t *buf, int len)
{
 while (len--)
  apdu_split_inbyte(as, *buf++);
}

canonical_original_code:
void apdu_split_in(struct apdu_split *as, unsigned char *buf, int len)
{
 while (len--)
  apdu_split_inbyte(as, *buf++);
}

variable_types: len int


repo: zxhhs/Button-Wizard

decompiled_code:
__int64 __fastcall cmd_sleep(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
unsigned int v4; // ebp
double v6; // xmm0_8
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
v4 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
{
v6 = atof(**(const char ***)(a1 + 8));
zdo_sleep(v6);
v4 = 1;
}
else
{
zdo_alert(114LL, "No argument for seconds.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <seconds>\x1B[0m \n"
"\x1B[32mSleep for seconds.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <seconds>\x1B[0m \n"
"\x1B[32mSleep for seconds.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
v4 = 0;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <seconds>\x1B[0m \n"
"\x1B[32mSleep for seconds.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
unsigned int v4; // ebp
double v6; // xmm0_8
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
v4 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
{
v6 = atof(**(const char ***)(a1 + 8));
zdo_sleep(v6);
v4 = 1;
}
else
{
zdo_alert(114LL, "No argument for seconds.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <seconds>\x1B[0m \n"
"\x1B[32mSleep for seconds.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <seconds>\x1B[0m \n"
"\x1B[32mSleep for seconds.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
v4 = 0;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <seconds>\x1B[0m \n"
"\x1B[32mSleep for seconds.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
v4 = -1;
}
return v4;
}

original_code:
int cmd_sleep(context_t *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <seconds>\x1b[0m \n"
    "\x1b[32mSleep for seconds.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc == 0) {
  zdo_alert('r', "No argument for seconds.\n");
  fprintf(stderr, usage, cmd);
  return 0;
 }
 else {
  zdo_sleep(atof(context->argv[0]));
 }
 return 1;
}

canonical_original_code:
int cmd_sleep(struct context *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <seconds>\x1b[0m \n"
    "\x1b[32mSleep for seconds.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc == 0) {
  zdo_alert('r', "No argument for seconds.\n");
  fprintf(stderr, usage, cmd);
  return 0;
 }
 else {
  zdo_sleep(atof(context->argv[0]));
 }
 return 1;
}

variable_types: struct context { int argc; char **argv; } *

variable_types: ret int

variable_types:
cmd
char *

variable_types: c char

variable_types:
usage
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


decompiled_code:
__int64 __fastcall cmd_mouseup(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // rbp
char v3; // al
__int64 result; // rax
unsigned int v5; // eax
int v6; // edx
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
v5 = atoi(**(const char ***)(a1 + 8));
v6 = zdo_mouseup(v5);
}
else
{
v6 = zdo_mouseup(1LL);
}
result = 1LL;
if ( v6 == -1 )
{
zdo_alert(114LL, "zdo_mouseup reported an error.\n");
result = 1LL;
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <button>\x1B[0m \n"
"\x1B[32mRelease a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <button>\x1B[0m \n"
"\x1B[32mRelease a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // rbp
char v3; // al
__int64 result; // rax
unsigned int v5; // eax
int v6; // edx
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
v5 = atoi(**(const char ***)(a1 + 8));
v6 = zdo_mouseup(v5);
}
else
{
v6 = zdo_mouseup(1LL);
}
result = 1LL;
if ( v6 == -1 )
{
zdo_alert(114LL, "zdo_mouseup reported an error.\n");
result = 1LL;
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <button>\x1B[0m \n"
"\x1B[32mRelease a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <button>\x1B[0m \n"
"\x1B[32mRelease a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cmd_mouseup(context_t *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <button>\x1b[0m \n"
    "\x1b[32mRelease a mouse button.\x1b[0m\n"
    "\x1b[32m1     for     left(default).\x1b[0m\n"
    "\x1b[32m2     for     middle.\x1b[0m\n"
    "\x1b[32m3     for     right.\x1b[0m\n"
    "\x1b[32m4     for     wheel up.\x1b[0m\n"
    "\x1b[32m5     for     wheel down.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0)
  ret = zdo_mouseup(atoi(context->argv[0]));
 else
  ret = zdo_mouseup(1);
 if (ret == -1) {
  zdo_alert('r', "zdo_mouseup reported an error.\n");
 }
 return 1;
}

canonical_original_code:
int cmd_mouseup(struct context *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <button>\x1b[0m \n"
    "\x1b[32mRelease a mouse button.\x1b[0m\n"
    "\x1b[32m1     for     left(default).\x1b[0m\n"
    "\x1b[32m2     for     middle.\x1b[0m\n"
    "\x1b[32m3     for     right.\x1b[0m\n"
    "\x1b[32m4     for     wheel up.\x1b[0m\n"
    "\x1b[32m5     for     wheel down.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0)
  ret = zdo_mouseup(atoi(context->argv[0]));
 else
  ret = zdo_mouseup(1);
 if (ret == -1) {
  zdo_alert('r', "zdo_mouseup reported an error.\n");
 }
 return 1;
}

user_defined_types: struct context { int argc; char **argv; }

user_defined_types: struct option { char *name; int has_arg; int *flag; int val; }


decompiled_code:
__int64 cmd_help()
{
const char *v0; // rdx
__int64 v1; // rbx

zdo_alert(103LL, "Available commands:\n");
v0 = dispatch;
if ( dispatch )
{
v1 = (unsigned int)((_DWORD)&dispatch + 16);
do
{
zdo_alert(98LL, "--%s\n", v0);
v1 += 16LL;
v0 = *(const char **)(v1 - 16);
}
while ( v0 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
const char *v0; // rdx
__int64 v1; // rbx

zdo_alert(103LL, "Available commands:\n");
v0 = dispatch;
if ( dispatch )
{
v1 = (unsigned int)((_DWORD)&dispatch + 16);
do
{
zdo_alert(98LL, "--%s\n", v0);
v1 += 16LL;
v0 = *(const char **)(v1 - 16);
}
while ( v0 );
}
return 0LL;
}

original_code:
int cmd_help() {
 int i;
 zdo_alert('g', "Available commands:\n");
 for (i = 0; dispatch[i].name != ((void *)0); i++)
  zdo_alert('b', "--%s\n", dispatch[i].name);
 return 0;
}

variable_types: i int


decompiled_code:
__int64 __fastcall is_command(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx

v2 = dispatch;
if ( !dispatch )
return 0LL;
v3 = (unsigned int)((_DWORD)&dispatch + 16);
while ( strcasecmp(v2, s2) )
{
v3 += 16LL;
v2 = *(const char **)(v3 - 16);
if ( !v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx

v2 = dispatch;
if ( !dispatch )
return 0LL;
v3 = (unsigned int)((_DWORD)&dispatch + 16);
while ( strcasecmp(v2, s2) )
{
v3 += 16LL;
v2 = *(const char **)(v3 - 16);
if ( !v2 )
return 0LL;
}
return 1LL;
}

original_code:
Bool is_command(char *cmd) {
 int i;
 for (i=0; dispatch[i].name != ((void *)0); i++) {
  if (!strcasecmp(dispatch[i].name, cmd)) {
         return 1;
       }
 }
 return 0;
}

canonical_original_code:
int is_command(char *cmd) {
 int i;
 for (i=0; dispatch[i].name != ((void *)0); i++) {
  if (!strcasecmp(dispatch[i].name, cmd)) {
         return 1;
       }
 }
 return 0;
}


decompiled_code:
__int64 __fastcall cmd_exec(int a1, __int64 a2)
{
const char *v2; // rdi
const char *v3; // r12
__int64 v4; // rbx
int v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h]

v6 = a1 - 1;
v7 = a2 + 8;
v2 = dispatch;
if ( !dispatch )
return 0LL;
v3 = *(const char **)(a2 + 8);
v4 = 0LL;
while ( strcasecmp(v2, v3) )
{
++v4;
v2 = (&dispatch)[2 * v4];
if ( !v2 )
return 0LL;
}
return ((__int64 (__fastcall *)(int *))(&dispatch)[2 * (int)v4 + 1])(&v6);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
const char *v2; // rdi
const char *v3; // r12
__int64 v4; // rbx
int v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h]

v6 = a1 - 1;
v7 = a2 + 8;
v2 = dispatch;
if ( !dispatch )
return 0LL;
v3 = *(const char **)(a2 + 8);
v4 = 0LL;
while ( strcasecmp(v2, v3) )
{
++v4;
v2 = (&dispatch)[2 * v4];
if ( !v2 )
return 0LL;
}
return ((__int64 (__fastcall *)(int *))(&dispatch)[2 * (int)v4 + 1])(&v6);
}

original_code:
int cmd_exec(int argc, char *argv[]) {
 context_t context;
 context.argc = --argc;
 context.argv = ++argv;
 int i;
 for (i=0; dispatch[i].name != ((void *)0); i++) {
  if (!strcasecmp(dispatch[i].name, argv[0])) {
         return dispatch[i].func(&context);
       }
 }
 return 0;
}

canonical_original_code:
int cmd_exec(int argc, char *argv[]) {
 struct context context;
 context.argc = --argc;
 context.argv = ++argv;
 int i;
 for (i=0; dispatch[i].name != ((void *)0); i++) {
  if (!strcasecmp(dispatch[i].name, argv[0])) {
         return dispatch[i].func(&context);
       }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct context { int argc; char **argv; }


decompiled_code:
__int64 __fastcall ZMagic_main(int a1, __int64 a2)
{
char *v2; // r12
__int64 result; // rax

if ( a1 <= 1 )
{
cmd_help();
result = 0LL;
}
else
{
v2 = *(char **)(a2 + 8);
if ( (unsigned int)is_command(v2) )
{
result = cmd_exec(a1, a2);
}
else
{
zdo_alert(114LL, "Command '%s' is not found.\n", v2);
cmd_help();
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
char *v2; // r12
__int64 result; // rax

if ( a1 <= 1 )
{
func0();
result = 0LL;
}
else
{
v2 = *(char **)(a2 + 8);
if ( (unsigned int)func1(v2) )
{
result = func2(a1, a2);
}
else
{
zdo_alert(114LL, "Command '%s' is not found.\n", v2);
func0();
result = 1LL;
}
}
return result;
}

original_code:
int ZMagic_main(int argc, char *argv[]) {
 if (argc >= 2) {
  if (is_command(argv[1])) {
   return cmd_exec(argc, argv);
  }
  else {
   zdo_alert('r', "Command '%s' is not found.\n", argv[1]);
   cmd_help();
   return 1;
  }
 }
 else {
  cmd_help();
 }
 return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return ZMagic_main(argc, (__int64)argv);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return func3(argc, (__int64)argv);
}

original_code:
int main(int argc, char *argv[]) {
 return ZMagic_main(argc, argv);
}


decompiled_code:
__int64 __fastcall consume_args(unsigned int *a1, int a2)
{
__int64 v2; // rcx
__int64 result; // rax

v2 = *a1;
if ( (int)v2 < a2 )
{
zdo_alert(114LL, "Can't consume %d args; are only %d available. This is a bug.\n", (unsigned int)a2, v2);
result = 8LL * (int)*a1;
*((_QWORD *)a1 + 1) += result;
*a1 = 0;
}
else
{
result = 8LL * a2;
*((_QWORD *)a1 + 1) += result;
*a1 = v2 - a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, int a2)
{
__int64 v2; // rcx
__int64 result; // rax

v2 = *a1;
if ( (int)v2 < a2 )
{
zdo_alert(114LL, "Can't consume %d args; are only %d available. This is a bug.\n", (unsigned int)a2, v2);
result = 8LL * (int)*a1;
*((_QWORD *)a1 + 1) += result;
*a1 = 0;
}
else
{
result = 8LL * a2;
*((_QWORD *)a1 + 1) += result;
*a1 = v2 - a2;
}
return result;
}

original_code:
void consume_args(context_t *context, int count) {
 if (count > context->argc) {
  zdo_alert('r', "Can't consume %d args; are only %d available. This is a bug.\n",
     count, context->argc);
  context->argv += context->argc;
  context->argc = 0;
  return;
 }
 context->argv += count;
 context->argc -= count;
}

canonical_original_code:
void consume_args(struct context *context, int count) {
 if (count > context->argc) {
  zdo_alert('r', "Can't consume %d args; are only %d available. This is a bug.\n",
     count, context->argc);
  context->argv += context->argc;
  context->argc = 0;
  return;
 }
 context->argv += count;
 context->argc -= count;
}

variable_types: count int


decompiled_code:
__int64 __fastcall cmd_mousedown(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // rbp
char v3; // al
__int64 result; // rax
unsigned int v5; // eax
int v6; // edx
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
v5 = atoi(**(const char ***)(a1 + 8));
v6 = zdo_mousedown(v5);
}
else
{
v6 = zdo_mousedown(1LL);
}
result = 1LL;
if ( v6 == -1 )
{
zdo_alert(114LL, "zdo_mousedown reported an error.\n");
result = 1LL;
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <button>\x1B[0m \n"
"\x1B[32mPress down a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <button>\x1B[0m \n"
"\x1B[32mPress down a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // rbp
char v3; // al
__int64 result; // rax
unsigned int v5; // eax
int v6; // edx
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
v5 = atoi(**(const char ***)(a1 + 8));
v6 = zdo_mousedown(v5);
}
else
{
v6 = zdo_mousedown(1LL);
}
result = 1LL;
if ( v6 == -1 )
{
zdo_alert(114LL, "zdo_mousedown reported an error.\n");
result = 1LL;
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <button>\x1B[0m \n"
"\x1B[32mPress down a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <button>\x1B[0m \n"
"\x1B[32mPress down a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cmd_mousedown(context_t *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <button>\x1b[0m \n"
    "\x1b[32mPress down a mouse button.\x1b[0m\n"
    "\x1b[32m1     for     left(default).\x1b[0m\n"
    "\x1b[32m2     for     middle.\x1b[0m\n"
    "\x1b[32m3     for     right.\x1b[0m\n"
    "\x1b[32m4     for     wheel up.\x1b[0m\n"
    "\x1b[32m5     for     wheel down.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0)
  ret = zdo_mousedown(atoi(context->argv[0]));
 else
  ret = zdo_mousedown(1);
 if (ret == -1) {
  zdo_alert('r', "zdo_mousedown reported an error.\n");
 }
 return 1;
}

canonical_original_code:
int cmd_mousedown(struct context *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <button>\x1b[0m \n"
    "\x1b[32mPress down a mouse button.\x1b[0m\n"
    "\x1b[32m1     for     left(default).\x1b[0m\n"
    "\x1b[32m2     for     middle.\x1b[0m\n"
    "\x1b[32m3     for     right.\x1b[0m\n"
    "\x1b[32m4     for     wheel up.\x1b[0m\n"
    "\x1b[32m5     for     wheel down.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0)
  ret = zdo_mousedown(atoi(context->argv[0]));
 else
  ret = zdo_mousedown(1);
 if (ret == -1) {
  zdo_alert('r', "zdo_mousedown reported an error.\n");
 }
 return 1;
}


decompiled_code:
__int64 __fastcall cmd_mousemove_relative(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // rbp
char v3; // al
__int64 result; // rax
const char **v5; // rbp
unsigned int v6; // ebx
unsigned int v7; // eax
int v8; // edx
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "rh", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
if ( *(int *)a1 <= 1 )
{
zdo_alert(114LL, "You specified the wrong number of args (expected 2 coordinates).\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
v5 = *(const char ***)(a1 + 8);
v6 = atoi(*v5);
v7 = atoi(v5[1]);
v8 = zdo_mousemove_relative(v6, v7);
result = 0LL;
if ( v8 == -1 )
{
zdo_alert(114LL, "zdo_mousemove_relative reported an error.\n");
result = 0LL;
}
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // rbp
char v3; // al
__int64 result; // rax
const char **v5; // rbp
unsigned int v6; // ebx
unsigned int v7; // eax
int v8; // edx
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "rh", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
if ( *(int *)a1 <= 1 )
{
zdo_alert(114LL, "You specified the wrong number of args (expected 2 coordinates).\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
v5 = *(const char ***)(a1 + 8);
v6 = atoi(*v5);
v7 = atoi(v5[1]);
v8 = zdo_mousemove_relative(v6, v7);
result = 0LL;
if ( v8 == -1 )
{
zdo_alert(114LL, "zdo_mousemove_relative reported an error.\n");
result = 0LL;
}
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cmd_mousemove_relative(context_t *context) {
 int dx, dy;
 int ret;
 char c;
 int option_index;
 char *cmd = *context->argv;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <x> <y>\x1b[0m \n"
    "\x1b[32mMove the pointer relative to the current position.\x1b[0m\n"
    "\x1b[1;34m--help       -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "rh",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc < 2) {
  zdo_alert('r', "You specified the wrong number of args (expected 2 coordinates).\n");
  fprintf(stderr, usage, cmd);
 }
 else {
  dx = atoi(context->argv[0]);
     dy = atoi(context->argv[1]);
     ret = zdo_mousemove_relative(dx, dy);
     if (ret == -1) {
      zdo_alert('r', "zdo_mousemove_relative reported an error.\n");
  }
 }
 return 0;
}

canonical_original_code:
int cmd_mousemove_relative(struct context *context) {
 int dx; int dy;
 int ret;
 char c;
 int option_index;
 char *cmd = *context->argv;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <x> <y>\x1b[0m \n"
    "\x1b[32mMove the pointer relative to the current position.\x1b[0m\n"
    "\x1b[1;34m--help       -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "rh",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc < 2) {
  zdo_alert('r', "You specified the wrong number of args (expected 2 coordinates).\n");
  fprintf(stderr, usage, cmd);
 }
 else {
  dx = atoi(context->argv[0]);
     dy = atoi(context->argv[1]);
     ret = zdo_mousemove_relative(dx, dy);
     if (ret == -1) {
      zdo_alert('r', "zdo_mousemove_relative reported an error.\n");
  }
 }
 return 0;
}

variable_types: dx int

variable_types: dy int


decompiled_code:
__int64 __fastcall cmd_mousemove(__int64 a1)
{
const char *v1; // r12
unsigned int i; // ebp
char v3; // al
__int64 result; // rax
const char **v5; // r12
unsigned int v6; // ebx
unsigned int v7; // eax
int v8; // edx
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = **(const char ***)(a1 + 8);
for ( i = 0; ; i = 1 )
{
v3 = getopt_long_only(*(_DWORD *)a1, *(char *const **)(a1 + 8), "rh", &longopts_0, longind);
if ( v3 == -1 )
break;
if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--relative] [--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the mouse to the specific X and Y coordinates on the screen.\x1B[0m\n"
"\x1B[1;34m--relative -r\x1B[0m \x1B[32m- move the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0LL;
}
if ( v3 != 114 )
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--relative] [--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the mouse to the specific X and Y coordinates on the screen.\x1B[0m\n"
"\x1B[1;34m--relative -r\x1B[0m \x1B[32m- move the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0xFFFFFFFFLL;
}
}
consume_args(a1, (unsigned int)optind);
if ( *(int *)a1 <= 1 )
{
zdo_alert(114LL, "You specified the wrong number of args (expected 2 coordinates).\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--relative] [--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the mouse to the specific X and Y coordinates on the screen.\x1B[0m\n"
"\x1B[1;34m--relative -r\x1B[0m \x1B[32m- move the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
result = 1LL;
}
else
{
v5 = *(const char ***)(a1 + 8);
v6 = atoi(*v5);
v7 = atoi(v5[1]);
v8 = zdo_mousemove(v6, v7, i);
result = 1LL;
if ( v8 == -1 )
{
zdo_alert(114LL, "zdo_mousemove reported an error.\n");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
const char *v1; // r12
unsigned int i; // ebp
char v3; // al
__int64 result; // rax
const char **v5; // r12
unsigned int v6; // ebx
unsigned int v7; // eax
int v8; // edx
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = **(const char ***)(a1 + 8);
for ( i = 0; ; i = 1 )
{
v3 = getopt_long_only(*(_DWORD *)a1, *(char *const **)(a1 + 8), "rh", &longopts_0, longind);
if ( v3 == -1 )
break;
if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--relative] [--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the mouse to the specific X and Y coordinates on the screen.\x1B[0m\n"
"\x1B[1;34m--relative -r\x1B[0m \x1B[32m- move the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0LL;
}
if ( v3 != 114 )
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--relative] [--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the mouse to the specific X and Y coordinates on the screen.\x1B[0m\n"
"\x1B[1;34m--relative -r\x1B[0m \x1B[32m- move the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0xFFFFFFFFLL;
}
}
consume_args(a1, (unsigned int)optind);
if ( *(int *)a1 <= 1 )
{
zdo_alert(114LL, "You specified the wrong number of args (expected 2 coordinates).\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--relative] [--help] <x> <y>\x1B[0m \n"
"\x1B[32mMove the mouse to the specific X and Y coordinates on the screen.\x1B[0m\n"
"\x1B[1;34m--relative -r\x1B[0m \x1B[32m- move the pointer relative to the current position.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
result = 1LL;
}
else
{
v5 = *(const char ***)(a1 + 8);
v6 = atoi(*v5);
v7 = atoi(v5[1]);
v8 = zdo_mousemove(v6, v7, i);
result = 1LL;
if ( v8 == -1 )
{
zdo_alert(114LL, "zdo_mousemove reported an error.\n");
result = 1LL;
}
}
return result;
}

original_code:
int cmd_mousemove(context_t *context) {
 int x, y;
 int ret;
 char c;
 int is_rel = 0;
 int option_index;
 char *cmd = *context->argv;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--relative] [--help] <x> <y>\x1b[0m \n"
    "\x1b[32mMove the mouse to the specific X and Y coordinates on the screen.\x1b[0m\n"
    "\x1b[1;34m--relative   -r\x1b[0m           \x1b[32m- move the pointer relative to the current position.\x1b[0m\n"
    "\x1b[1;34m--help       -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "relative", 0, ((void *)0), 'r' },
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "rh",
                               longopts, &option_index)) != -1) {
  switch (c) {
   case 'r':
    is_rel = 1;
    break;
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc < 2) {
  zdo_alert('r', "You specified the wrong number of args (expected 2 coordinates).\n");
  fprintf(stderr, usage, cmd);
 }
 else {
  x = atoi(context->argv[0]);
     y = atoi(context->argv[1]);
     ret = zdo_mousemove(x, y, is_rel);
     if (ret == -1) {
      zdo_alert('r', "zdo_mousemove reported an error.\n");
  }
 }
 return 1;
}

canonical_original_code:
int cmd_mousemove(struct context *context) {
 int x; int y;
 int ret;
 char c;
 int is_rel = 0;
 int option_index;
 char *cmd = *context->argv;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--relative] [--help] <x> <y>\x1b[0m \n"
    "\x1b[32mMove the mouse to the specific X and Y coordinates on the screen.\x1b[0m\n"
    "\x1b[1;34m--relative   -r\x1b[0m           \x1b[32m- move the pointer relative to the current position.\x1b[0m\n"
    "\x1b[1;34m--help       -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "relative", 0, ((void *)0), 'r' },
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "rh",
                               longopts, &option_index)) != -1) {
  switch (c) {
   case 'r':
    is_rel = 1;
    break;
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc < 2) {
  zdo_alert('r', "You specified the wrong number of args (expected 2 coordinates).\n");
  fprintf(stderr, usage, cmd);
 }
 else {
  x = atoi(context->argv[0]);
     y = atoi(context->argv[1]);
     ret = zdo_mousemove(x, y, is_rel);
     if (ret == -1) {
      zdo_alert('r', "zdo_mousemove reported an error.\n");
  }
 }
 return 1;
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall cmd_record(__int64 a1)
{
const char *v1; // r14
unsigned int v2; // ebp
unsigned int v3; // er12
unsigned int v4; // er13
unsigned int v5; // eax
unsigned int v6; // er15
const char **v8; // rax
const char *v9; // rbx
char v10; // [rsp+Bh] [rbp-3Dh] BYREF
int longind[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v1 = **(const char ***)(a1 + 8);
v2 = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt_long_only(*(_DWORD *)a1, *(char *const **)(a1 + 8), "mkhc", &longopts_0, longind);
v10 = v5;
if ( (_BYTE)v5 == 0xFF )
break;
if ( (_BYTE)v5 == 107 )
{
v2 = 1;
v3 = 0;
}
else if ( (char)v5 > 107 )
{
if ( (_BYTE)v5 != 109 )
goto LABEL_11;
v2 = 0;
v3 = 1;
}
else
{
if ( (_BYTE)v5 != 99 )
{
if ( (_BYTE)v5 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--mouse_only] [--key_only] [--continue] [--help] <file>"
"\x1B[0m \n"
"\x1B[32mRecord the motions of mouse and keyboard into the file(should be *.sh).\x1B[0m\n"
"\x1B[1;34m--mouse_only -m\x1B[0m \x1B[32m- record mouse movements only.\x1B[0m\n"
"\x1B[1;34m--key_only -k\x1B[0m \x1B[32m- record keyboard movements only.\x1B[0m\n"
"\x1B[1;34m--continue -c\x1B[0m \x1B[32m- write records from the end of the file(must exists).\x1B[0"
"m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0;
}
LABEL_11:
zdo_alert(114LL, "unknown option.\n", v5);
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--mouse_only] [--key_only] [--continue] [--help] <file>\x1B"
"[0m \n"
"\x1B[32mRecord the motions of mouse and keyboard into the file(should be *.sh).\x1B[0m\n"
"\x1B[1;34m--mouse_only -m\x1B[0m \x1B[32m- record mouse movements only.\x1B[0m\n"
"\x1B[1;34m--key_only -k\x1B[0m \x1B[32m- record keyboard movements only.\x1B[0m\n"
"\x1B[1;34m--continue -c\x1B[0m \x1B[32m- write records from the end of the file(must exists).\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return (unsigned int)-1;
}
v4 = 1;
}
}
consume_args(a1, (unsigned int)optind, v5);
v6 = *(_DWORD *)a1;
if ( !*(_DWORD *)a1 )
{
zdo_alert(114LL, "Need a file for record.\n");
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--mouse_only] [--key_only] [--continue] [--help] <file>\x1B[0"
"m \n"
"\x1B[32mRecord the motions of mouse and keyboard into the file(should be *.sh).\x1B[0m\n"
"\x1B[1;34m--mouse_only -m\x1B[0m \x1B[32m- record mouse movements only.\x1B[0m\n"
"\x1B[1;34m--key_only -k\x1B[0m \x1B[32m- record keyboard movements only.\x1B[0m\n"
"\x1B[1;34m--continue -c\x1B[0m \x1B[32m- write records from the end of the file(must exists).\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return v6;
}
v8 = *(const char ***)(a1 + 8);
v9 = *v8;
if ( v4 )
{
v6 = access(*v8, 0);
if ( v6 == -1 )
{
zdo_alert(114LL, "No such file(%s).\n", v9);
return v6;
}
}
else if ( access(*v8, 0) != -1 )
{
zdo_alert(114LL, "The %s exists. Do you want to overwrite it? (y/c/n)\n", v9);
zdo_alert(103LL, "--select 'y' to overwrite.\n");
zdo_alert(103LL, "--select 'c' to continue.\n");
zdo_alert(103LL, "--select 'n' to quit.\n");
_isoc99_scanf("%c", &v10);
if ( v10 != 121 )
{
v6 = 0;
if ( v10 != 99 )
return v6;
v4 = 1;
}
}
zdo_record(v9, v4, v2, v3);
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
const char *v1; // r14
unsigned int v2; // ebp
unsigned int v3; // er12
unsigned int v4; // er13
unsigned int v5; // eax
unsigned int v6; // er15
const char **v8; // rax
const char *v9; // rbx
char v10; // [rsp+Bh] [rbp-3Dh] BYREF
int longind[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v1 = **(const char ***)(a1 + 8);
v2 = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt_long_only(*(_DWORD *)a1, *(char *const **)(a1 + 8), "mkhc", &longopts_0, longind);
v10 = v5;
if ( (_BYTE)v5 == 0xFF )
break;
if ( (_BYTE)v5 == 107 )
{
v2 = 1;
v3 = 0;
}
else if ( (char)v5 > 107 )
{
if ( (_BYTE)v5 != 109 )
goto LABEL_11;
v2 = 0;
v3 = 1;
}
else
{
if ( (_BYTE)v5 != 99 )
{
if ( (_BYTE)v5 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--mouse_only] [--key_only] [--continue] [--help] <file>"
"\x1B[0m \n"
"\x1B[32mRecord the motions of mouse and keyboard into the file(should be *.sh).\x1B[0m\n"
"\x1B[1;34m--mouse_only -m\x1B[0m \x1B[32m- record mouse movements only.\x1B[0m\n"
"\x1B[1;34m--key_only -k\x1B[0m \x1B[32m- record keyboard movements only.\x1B[0m\n"
"\x1B[1;34m--continue -c\x1B[0m \x1B[32m- write records from the end of the file(must exists).\x1B[0"
"m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0;
}
LABEL_11:
zdo_alert(114LL, "unknown option.\n", v5);
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--mouse_only] [--key_only] [--continue] [--help] <file>\x1B"
"[0m \n"
"\x1B[32mRecord the motions of mouse and keyboard into the file(should be *.sh).\x1B[0m\n"
"\x1B[1;34m--mouse_only -m\x1B[0m \x1B[32m- record mouse movements only.\x1B[0m\n"
"\x1B[1;34m--key_only -k\x1B[0m \x1B[32m- record keyboard movements only.\x1B[0m\n"
"\x1B[1;34m--continue -c\x1B[0m \x1B[32m- write records from the end of the file(must exists).\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return (unsigned int)-1;
}
v4 = 1;
}
}
consume_args(a1, (unsigned int)optind, v5);
v6 = *(_DWORD *)a1;
if ( !*(_DWORD *)a1 )
{
zdo_alert(114LL, "Need a file for record.\n");
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--mouse_only] [--key_only] [--continue] [--help] <file>\x1B[0"
"m \n"
"\x1B[32mRecord the motions of mouse and keyboard into the file(should be *.sh).\x1B[0m\n"
"\x1B[1;34m--mouse_only -m\x1B[0m \x1B[32m- record mouse movements only.\x1B[0m\n"
"\x1B[1;34m--key_only -k\x1B[0m \x1B[32m- record keyboard movements only.\x1B[0m\n"
"\x1B[1;34m--continue -c\x1B[0m \x1B[32m- write records from the end of the file(must exists).\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return v6;
}
v8 = *(const char ***)(a1 + 8);
v9 = *v8;
if ( v4 )
{
v6 = access(*v8, 0);
if ( v6 == -1 )
{
zdo_alert(114LL, "No such file(%s).\n", v9);
return v6;
}
}
else if ( access(*v8, 0) != -1 )
{
zdo_alert(114LL, "The %s exists. Do you want to overwrite it? (y/c/n)\n", v9);
zdo_alert(103LL, "--select 'y' to overwrite.\n");
zdo_alert(103LL, "--select 'c' to continue.\n");
zdo_alert(103LL, "--select 'n' to quit.\n");
_isoc99_scanf("%c", &v10);
if ( v10 != 121 )
{
v6 = 0;
if ( v10 != 99 )
return v6;
v4 = 1;
}
}
zdo_record(v9, v4, v2, v3);
return 0;
}

original_code:
int cmd_record(context_t *context) {
 int option_index;
 char *cmd = *context->argv;
 char c;
 int is_continue = 0;
 int key_mask = 0;
 int mouse_mask = 0;
 char *file;
 static const char *usage =
    "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--mouse_only] [--key_only] [--continue] [--help] <file>\x1b[0m \n"
    "\x1b[32mRecord the motions of mouse and keyboard into the file(should be *.sh).\x1b[0m\n"
    "\x1b[1;34m--mouse_only -m\x1b[0m        \x1b[32m- record mouse movements only.\x1b[0m\n"
    "\x1b[1;34m--key_only   -k\x1b[0m        \x1b[32m- record keyboard movements only.\x1b[0m\n"
    "\x1b[1;34m--continue   -c\x1b[0m        \x1b[32m- write records from the end of the file(must exists).\x1b[0m\n"
    "\x1b[1;34m--help       -h\x1b[0m        \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "mouse_only", 0, ((void *)0), 'm'},
  { "key_only", 0, ((void *)0), 'k'},
  { "continue", 0, ((void *)0), 'c'},
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "mkhc",
                               longopts, &option_index)) != -1) {
  switch (c) {
   case 'm':
    key_mask = 1;
    mouse_mask = 0;
    break;
   case 'k':
    key_mask = 0;
    mouse_mask = 1;
    break;
   case 'c':
    is_continue = 1;
    break;
   case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0) {
  file = context->argv[0];
  if (!is_continue && access(file, 0) != -1) {
   zdo_alert('r', "The %s exists. Do you want to overwrite it? (y/c/n)\n", file);
   zdo_alert('g', "--select 'y' to overwrite.\n");
   zdo_alert('g', "--select 'c' to continue.\n");
   zdo_alert('g', "--select 'n' to quit.\n");
   scanf("%c", &c);
   if (c == 'y') {
    is_continue = 0;
   }
   else if (c == 'c') {
    is_continue = 1;
   }
   else {
    return 0;
   }
  }
  else if (is_continue && access(file, 0) == -1) {
   zdo_alert('r', "No such file(%s).\n", file);
   return -1;
  }
  zdo_record(file, is_continue, mouse_mask, key_mask);
 }
 else {
  zdo_alert('r', "Need a file for record.\n");
  printf(usage, cmd);
 }
 return 0;
}

canonical_original_code:
int cmd_record(struct context *context) {
 int option_index;
 char *cmd = *context->argv;
 char c;
 int is_continue = 0;
 int key_mask = 0;
 int mouse_mask = 0;
 char *file;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--mouse_only] [--key_only] [--continue] [--help] <file>\x1b[0m \n"
    "\x1b[32mRecord the motions of mouse and keyboard into the file(should be *.sh).\x1b[0m\n"
    "\x1b[1;34m--mouse_only -m\x1b[0m        \x1b[32m- record mouse movements only.\x1b[0m\n"
    "\x1b[1;34m--key_only   -k\x1b[0m        \x1b[32m- record keyboard movements only.\x1b[0m\n"
    "\x1b[1;34m--continue   -c\x1b[0m        \x1b[32m- write records from the end of the file(must exists).\x1b[0m\n"
    "\x1b[1;34m--help       -h\x1b[0m        \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "mouse_only", 0, ((void *)0), 'm'},
  { "key_only", 0, ((void *)0), 'k'},
  { "continue", 0, ((void *)0), 'c'},
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "mkhc",
                               longopts, &option_index)) != -1) {
  switch (c) {
   case 'm':
    key_mask = 1;
    mouse_mask = 0;
    break;
   case 'k':
    key_mask = 0;
    mouse_mask = 1;
    break;
   case 'c':
    is_continue = 1;
    break;
   case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0) {
  file = context->argv[0];
  if (!is_continue && access(file, 0) != -1) {
   zdo_alert('r', "The %s exists. Do you want to overwrite it? (y/c/n)\n", file);
   zdo_alert('g', "--select 'y' to overwrite.\n");
   zdo_alert('g', "--select 'c' to continue.\n");
   zdo_alert('g', "--select 'n' to quit.\n");
   scanf("%c", &c);
   if (c == 'y') {
    is_continue = 0;
   }
   else if (c == 'c') {
    is_continue = 1;
   }
   else {
    return 0;
   }
  }
  else if (is_continue && access(file, 0) == -1) {
   zdo_alert('r', "No such file(%s).\n", file);
   return -1;
  }
  zdo_record(file, is_continue, mouse_mask, key_mask);
 }
 else {
  zdo_alert('r', "Need a file for record.\n");
  printf(usage, cmd);
 }
 return 0;
}

variable_types:
file
char *


decompiled_code:
__int64 __fastcall cmd_alert(__int64 a1)
{
const char *v1; // r13
char i; // bp
char v3; // al
__int64 v4; // rdx
unsigned int v5; // er12
__int64 v7; // [rsp+0h] [rbp-48h] BYREF
int longind[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v1 = **(const char ***)(a1 + 8);
for ( i = 114; ; i = v3 )
{
v3 = getopt_long_only(*(_DWORD *)a1, *(char *const **)(a1 + 8), "rgbh", &longopts_0, longind);
if ( v3 == -1 )
break;
if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--red] [--green] [--blue] [--help] <text>\x1B[0m \n"
"\x1B[32mPrint the text in the console.\x1B[0m\n"
"\x1B[1;34m--red -m\x1B[0m \x1B[32m- print red text(default).\x1B[0m\n"
"\x1B[1;34m--green -k\x1B[0m \x1B[32m- print green text.\x1B[0m\n"
"\x1B[1;34m--blue -c\x1B[0m \x1B[32m- print blue text.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0;
}
if ( v3 <= 104 )
{
if ( v3 != 98 && v3 != 103 )
{
LABEL_9:
zdo_alert(114LL, "unknown option.\n", v4);
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--red] [--green] [--blue] [--help] <text>\x1B[0m \n"
"\x1B[32mPrint the text in the console.\x1B[0m\n"
"\x1B[1;34m--red -m\x1B[0m \x1B[32m- print red text(default).\x1B[0m\n"
"\x1B[1;34m--green -k\x1B[0m \x1B[32m- print green text.\x1B[0m\n"
"\x1B[1;34m--blue -c\x1B[0m \x1B[32m- print blue text.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return (unsigned int)-1;
}
}
else if ( v3 != 114 )
{
goto LABEL_9;
}
}
consume_args(a1, (unsigned int)optind);
v5 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
{
zdo_alert((unsigned int)i, **(_QWORD **)(a1 + 8), &v7);
v5 = 0;
}
else
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--red] [--green] [--blue] [--help] <text>\x1B[0m \n"
"\x1B[32mPrint the text in the console.\x1B[0m\n"
"\x1B[1;34m--red -m\x1B[0m \x1B[32m- print red text(default).\x1B[0m\n"
"\x1B[1;34m--green -k\x1B[0m \x1B[32m- print green text.\x1B[0m\n"
"\x1B[1;34m--blue -c\x1B[0m \x1B[32m- print blue text.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
const char *v1; // r13
char i; // bp
char v3; // al
__int64 v4; // rdx
unsigned int v5; // er12
__int64 v7; // [rsp+0h] [rbp-48h] BYREF
int longind[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v1 = **(const char ***)(a1 + 8);
for ( i = 114; ; i = v3 )
{
v3 = getopt_long_only(*(_DWORD *)a1, *(char *const **)(a1 + 8), "rgbh", &longopts_0, longind);
if ( v3 == -1 )
break;
if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--red] [--green] [--blue] [--help] <text>\x1B[0m \n"
"\x1B[32mPrint the text in the console.\x1B[0m\n"
"\x1B[1;34m--red -m\x1B[0m \x1B[32m- print red text(default).\x1B[0m\n"
"\x1B[1;34m--green -k\x1B[0m \x1B[32m- print green text.\x1B[0m\n"
"\x1B[1;34m--blue -c\x1B[0m \x1B[32m- print blue text.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0;
}
if ( v3 <= 104 )
{
if ( v3 != 98 && v3 != 103 )
{
LABEL_9:
zdo_alert(114LL, "unknown option.\n", v4);
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--red] [--green] [--blue] [--help] <text>\x1B[0m \n"
"\x1B[32mPrint the text in the console.\x1B[0m\n"
"\x1B[1;34m--red -m\x1B[0m \x1B[32m- print red text(default).\x1B[0m\n"
"\x1B[1;34m--green -k\x1B[0m \x1B[32m- print green text.\x1B[0m\n"
"\x1B[1;34m--blue -c\x1B[0m \x1B[32m- print blue text.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return (unsigned int)-1;
}
}
else if ( v3 != 114 )
{
goto LABEL_9;
}
}
consume_args(a1, (unsigned int)optind);
v5 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
{
zdo_alert((unsigned int)i, **(_QWORD **)(a1 + 8), &v7);
v5 = 0;
}
else
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--red] [--green] [--blue] [--help] <text>\x1B[0m \n"
"\x1B[32mPrint the text in the console.\x1B[0m\n"
"\x1B[1;34m--red -m\x1B[0m \x1B[32m- print red text(default).\x1B[0m\n"
"\x1B[1;34m--green -k\x1B[0m \x1B[32m- print green text.\x1B[0m\n"
"\x1B[1;34m--blue -c\x1B[0m \x1B[32m- print blue text.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
}
return v5;
}

original_code:
int cmd_alert(context_t *context) {
 int option_index;
 char *cmd = *context->argv;
 char c;
 char color = 'r';
 char *s;
 static const char *usage =
    "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--red] [--green] [--blue] [--help] <text>\x1b[0m \n"
    "\x1b[32mPrint the text in the console.\x1b[0m\n"
    "\x1b[1;34m--red      -m\x1b[0m        \x1b[32m- print red text(default).\x1b[0m\n"
    "\x1b[1;34m--green    -k\x1b[0m        \x1b[32m- print green text.\x1b[0m\n"
    "\x1b[1;34m--blue     -c\x1b[0m        \x1b[32m- print blue text.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m        \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "red", 0, ((void *)0), 'r'},
  { "green", 0, ((void *)0), 'g'},
  { "blue", 0, ((void *)0), 'b'},
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "rgbh",
                               longopts, &option_index)) != -1) {
  switch (c) {
   case 'r':
   case 'g':
   case 'b':
    color = c;
    break;
   case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
      zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0) {
  char *format = context->argv[0];
va_list args;
  zdo_alert(color, format, args);
 }
 else {
  printf(usage, cmd);
 }
 return 0;
}

canonical_original_code:
int cmd_alert(struct context *context) {
 int option_index;
 char *cmd = *context->argv;
 char c;
 char color = 'r';
 char *s;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--red] [--green] [--blue] [--help] <text>\x1b[0m \n"
    "\x1b[32mPrint the text in the console.\x1b[0m\n"
    "\x1b[1;34m--red      -m\x1b[0m        \x1b[32m- print red text(default).\x1b[0m\n"
    "\x1b[1;34m--green    -k\x1b[0m        \x1b[32m- print green text.\x1b[0m\n"
    "\x1b[1;34m--blue     -c\x1b[0m        \x1b[32m- print blue text.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m        \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "red", 0, ((void *)0), 'r'},
  { "green", 0, ((void *)0), 'g'},
  { "blue", 0, ((void *)0), 'b'},
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "rgbh",
                               longopts, &option_index)) != -1) {
  switch (c) {
   case 'r':
   case 'g':
   case 'b':
    color = c;
    break;
   case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
      zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0) {
  char *format = context->argv[0];
__builtin_va_list args;
  zdo_alert(color, format, args);
 }
 else {
  printf(usage, cmd);
 }
 return 0;
}

variable_types: color char

variable_types:
s
char *

variable_types:
format
char *


decompiled_code:
__int64 __fastcall cmd_key(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
char **v4; // rbx
const char *v5; // rdx
int v6; // ebp
__int64 v8; // rbp
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
v6 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
{
if ( v6 <= 0 )
{
v6 = 0;
}
else
{
v8 = 0LL;
do
{
if ( (unsigned int)zdo_key(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v8), v2) == -1 )
zdo_alert(
114LL,
"zdo_key reported an error for string '%s'.\n",
*(const char **)(*(_QWORD *)(a1 + 8) + 8 * v8));
++v8;
}
while ( *(_DWORD *)a1 > (int)v8 );
v6 = 0;
}
}
else
{
zdo_alert(114LL, "No keys.\n");
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
zdo_alert(103LL, "\nAvailable keys:\n");
zdo_alert(103LL, "Meaning\t\tkey_name\n");
v4 = &keysym_charmap;
v5 = (const char *)&unk_1C1;
do
{
zdo_alert(98LL, "%-15s%-10s\n", v5, *v4);
v4 += 3;
v5 = v4[1];
}
while ( v5 );
v6 = 0;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
v6 = -1;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
char **v4; // rbx
const char *v5; // rdx
int v6; // ebp
__int64 v8; // rbp
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
v6 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
{
if ( v6 <= 0 )
{
v6 = 0;
}
else
{
v8 = 0LL;
do
{
if ( (unsigned int)zdo_key(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v8), v2) == -1 )
zdo_alert(
114LL,
"zdo_key reported an error for string '%s'.\n",
*(const char **)(*(_QWORD *)(a1 + 8) + 8 * v8));
++v8;
}
while ( *(_DWORD *)a1 > (int)v8 );
v6 = 0;
}
}
else
{
zdo_alert(114LL, "No keys.\n");
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
zdo_alert(103LL, "\nAvailable keys:\n");
zdo_alert(103LL, "Meaning\t\tkey_name\n");
v4 = &keysym_charmap;
v5 = (const char *)&unk_1C1;
do
{
zdo_alert(98LL, "%-15s%-10s\n", v5, *v4);
v4 += 3;
v5 = v4[1];
}
while ( v5 );
v6 = 0;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
v6 = -1;
}
return (unsigned int)v6;
}

original_code:
int cmd_key(context_t *context) {
 int i;
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <key>\x1b[0m \n"
    "\x1b[32mPress a key or a list of key(devided by '+').\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
    static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    int i;
    zdo_alert('g', "\nAvailable keys:\n");
    zdo_alert('g', "Meaning\t\tkey_name\n");
    for (i = 0; keysym_charmap[i].meaning != ((void *)0); i++) {
     zdo_alert('b', "%-15s%-10s\n", keysym_charmap[i].meaning,
       keysym_charmap[i].keysym);
    }
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
    if (context->argc != 0) {
  for (i=0; i<context->argc; i++) {
   ret = zdo_key(context->argv[i], cmd);
   if (ret == -1) {
    zdo_alert('r', "zdo_key reported an error for string '%s'.\n",
     context->argv[i]);
   }
  }
 }
 else {
  zdo_alert('r', "No keys.\n");
  printf(usage, cmd);
 }
 return 0;
}

canonical_original_code:
int cmd_key(struct context *context) {
 int i;
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <key>\x1b[0m \n"
    "\x1b[32mPress a key or a list of key(devided by '+').\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
    static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    int i;
    zdo_alert('g', "\nAvailable keys:\n");
    zdo_alert('g', "Meaning\t\tkey_name\n");
    for (i = 0; keysym_charmap[i].meaning != ((void *)0); i++) {
     zdo_alert('b', "%-15s%-10s\n", keysym_charmap[i].meaning,
       keysym_charmap[i].keysym);
    }
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
    if (context->argc != 0) {
  for (i=0; i<context->argc; i++) {
   ret = zdo_key(context->argv[i], cmd);
   if (ret == -1) {
    zdo_alert('r', "zdo_key reported an error for string '%s'.\n",
     context->argv[i]);
   }
  }
 }
 else {
  zdo_alert('r', "No keys.\n");
  printf(usage, cmd);
 }
 return 0;
}

variable_types: struct context { int argc; char **argv; } *

variable_types: ret int

variable_types:
cmd
char *


decompiled_code:
__int64 cmd_version()
{
zdo_alert(103LL, "About Us :\n");
zdo_alert(98LL, "Program Name : ZMagic\n");
zdo_alert(98LL, "Version : 1.0.0\n");
zdo_alert(114LL, "Created By : Zhang Xiang & Zhong Guang Pei\n");
zdo_alert(98LL, "Copyright : 2012-2020\n");
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
zdo_alert(103LL, "About Us :\n");
zdo_alert(98LL, "Program Name : ZMagic\n");
zdo_alert(98LL, "Version : 1.0.0\n");
zdo_alert(114LL, "Created By : Zhang Xiang & Zhong Guang Pei\n");
zdo_alert(98LL, "Copyright : 2012-2020\n");
return 1LL;
}

original_code:
int cmd_version(context_t *context) {
 zdo_alert('g', "About Us     :\n");
 zdo_alert('b', "Program Name : ZMagic\n");
 zdo_alert('b', "Version      : 1.0.0\n");
 zdo_alert('r', "Created By   : Zhang Xiang & Zhong Guang Pei\n");
 zdo_alert('b', "Copyright    : 2012-2020\n");
 return 1;
}

canonical_original_code:
int cmd_version(struct context *context) {
 zdo_alert('g', "About Us     :\n");
 zdo_alert('b', "Program Name : ZMagic\n");
 zdo_alert('b', "Version      : 1.0.0\n");
 zdo_alert('r', "Created By   : Zhang Xiang & Zhong Guang Pei\n");
 zdo_alert('b', "Copyright    : 2012-2020\n");
 return 1;
}


decompiled_code:
__int64 __fastcall cmd_click(__int64 a1)
{
const char *v1; // r13
unsigned __int64 v2; // r12
int v3; // ebp
char v4; // al
__int64 result; // rax
char *v6; // r14
unsigned int v7; // eax
int v8; // edx
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = **(const char ***)(a1 + 8);
v2 = 100LL;
v3 = 1;
while ( 1 )
{
v4 = getopt_long_only(*(_DWORD *)a1, *(char *const **)(a1 + 8), "r:d:h", &longopts_0, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'h':
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N] [--delay MS] [--help] <button>\x1B[0m \n"
"\x1B[32mClick a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--repeat -r N\x1B[0m \x1B[32m- repeat N times to click. Default is 1.\x1B[0m\n"
"\x1B[1;34m--delay -d MS\x1B[0m \x1B[32m- delay in MS between clicks. Default is 100ms.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0LL;
case 'r':
v6 = optarg;
v3 = atoi(optarg);
if ( v3 <= 0 )
{
zdo_alert(114LL, "Invalid repeat value '%s' (must be >= 1).\n", v6);
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N] [--delay MS] [--help] <button>\x1B[0m \n"
"\x1B[32mClick a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--repeat -r N\x1B[0m \x1B[32m- repeat N times to click. Default is 1.\x1B[0m\n"
"\x1B[1;34m--delay -d MS\x1B[0m \x1B[32m- delay in MS between clicks. Default is 100ms.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0xFFFFFFFFLL;
}
break;
case 'd':
v2 = strtoul(optarg, 0LL, 10);
break;
default:
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N] [--delay MS] [--help] <button>\x1B[0m \n"
"\x1B[32mClick a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--repeat -r N\x1B[0m \x1B[32m- repeat N times to click. Default is 1.\x1B[0m\n"
"\x1B[1;34m--delay -d MS\x1B[0m \x1B[32m- delay in MS between clicks. Default is 100ms.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0xFFFFFFFFLL;
}
}
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
v7 = atoi(**(const char ***)(a1 + 8));
v8 = zdo_click(v7, (unsigned int)v3, 1000 * v2);
}
else
{
v8 = zdo_click(1LL, (unsigned int)v3, 1000 * v2);
}
result = 1LL;
if ( v8 == -1 )
{
zdo_alert(114LL, "zdo_click reported an error.\n");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
const char *v1; // r13
unsigned __int64 v2; // r12
int v3; // ebp
char v4; // al
__int64 result; // rax
char *v6; // r14
unsigned int v7; // eax
int v8; // edx
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = **(const char ***)(a1 + 8);
v2 = 100LL;
v3 = 1;
while ( 1 )
{
v4 = getopt_long_only(*(_DWORD *)a1, *(char *const **)(a1 + 8), "r:d:h", &longopts_0, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'h':
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N] [--delay MS] [--help] <button>\x1B[0m \n"
"\x1B[32mClick a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--repeat -r N\x1B[0m \x1B[32m- repeat N times to click. Default is 1.\x1B[0m\n"
"\x1B[1;34m--delay -d MS\x1B[0m \x1B[32m- delay in MS between clicks. Default is 100ms.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0LL;
case 'r':
v6 = optarg;
v3 = atoi(optarg);
if ( v3 <= 0 )
{
zdo_alert(114LL, "Invalid repeat value '%s' (must be >= 1).\n", v6);
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N] [--delay MS] [--help] <button>\x1B[0m \n"
"\x1B[32mClick a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--repeat -r N\x1B[0m \x1B[32m- repeat N times to click. Default is 1.\x1B[0m\n"
"\x1B[1;34m--delay -d MS\x1B[0m \x1B[32m- delay in MS between clicks. Default is 100ms.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0xFFFFFFFFLL;
}
break;
case 'd':
v2 = strtoul(optarg, 0LL, 10);
break;
default:
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N] [--delay MS] [--help] <button>\x1B[0m \n"
"\x1B[32mClick a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--repeat -r N\x1B[0m \x1B[32m- repeat N times to click. Default is 1.\x1B[0m\n"
"\x1B[1;34m--delay -d MS\x1B[0m \x1B[32m- delay in MS between clicks. Default is 100ms.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v1);
return 0xFFFFFFFFLL;
}
}
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
v7 = atoi(**(const char ***)(a1 + 8));
v8 = zdo_click(v7, (unsigned int)v3, 1000 * v2);
}
else
{
v8 = zdo_click(1LL, (unsigned int)v3, 1000 * v2);
}
result = 1LL;
if ( v8 == -1 )
{
zdo_alert(114LL, "zdo_click reported an error.\n");
result = 1LL;
}
return result;
}

original_code:
int cmd_click(context_t *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 int repeat = 1;
 unsigned long delay = 100;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--repeat N] [--delay MS] [--help] <button>\x1b[0m \n"
    "\x1b[32mClick a mouse button.\x1b[0m\n"
    "\x1b[32m1     for     left(default).\x1b[0m\n"
    "\x1b[32m2     for     middle.\x1b[0m\n"
    "\x1b[32m3     for     right.\x1b[0m\n"
    "\x1b[32m4     for     wheel up.\x1b[0m\n"
    "\x1b[32m5     for     wheel down.\x1b[0m\n"
    "\x1b[1;34m--repeat   -r N\x1b[0m         \x1b[32m- repeat N times to click. Default is 1.\x1b[0m\n"
    "\x1b[1;34m--delay    -d MS\x1b[0m        \x1b[32m- delay in MS between clicks. Default is 100ms.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "repeat", 1, ((void *)0), 'r'},
  { "delay", 1, ((void *)0), 'd' },
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "r:d:h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'r':
    repeat = atoi(optarg);
    if (repeat <= 0) {
     zdo_alert('r', "Invalid repeat value '%s' (must be >= 1).\n", optarg);
     fprintf(stderr, usage, cmd);
     return -1;
    }
    break;
      case 'd':
    delay = strtoul(optarg, ((void *)0), 10);
    break;
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0)
  ret = zdo_click(atoi(context->argv[0]), repeat, delay * 1000);
 else
  ret = zdo_click(1, repeat, delay * 1000);
 if (ret == -1) {
  zdo_alert('r', "zdo_click reported an error.\n");
 }
 return 1;
}

canonical_original_code:
int cmd_click(struct context *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 int repeat = 1;
 unsigned long delay = 100;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--repeat N] [--delay MS] [--help] <button>\x1b[0m \n"
    "\x1b[32mClick a mouse button.\x1b[0m\n"
    "\x1b[32m1     for     left(default).\x1b[0m\n"
    "\x1b[32m2     for     middle.\x1b[0m\n"
    "\x1b[32m3     for     right.\x1b[0m\n"
    "\x1b[32m4     for     wheel up.\x1b[0m\n"
    "\x1b[32m5     for     wheel down.\x1b[0m\n"
    "\x1b[1;34m--repeat   -r N\x1b[0m         \x1b[32m- repeat N times to click. Default is 1.\x1b[0m\n"
    "\x1b[1;34m--delay    -d MS\x1b[0m        \x1b[32m- delay in MS between clicks. Default is 100ms.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "repeat", 1, ((void *)0), 'r'},
  { "delay", 1, ((void *)0), 'd' },
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "r:d:h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'r':
    repeat = atoi(optarg);
    if (repeat <= 0) {
     zdo_alert('r', "Invalid repeat value '%s' (must be >= 1).\n", optarg);
     fprintf(stderr, usage, cmd);
     return -1;
    }
    break;
      case 'd':
    delay = strtoul(optarg, ((void *)0), 10);
    break;
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0)
  ret = zdo_click(atoi(context->argv[0]), repeat, delay * 1000);
 else
  ret = zdo_click(1, repeat, delay * 1000);
 if (ret == -1) {
  zdo_alert('r', "zdo_click reported an error.\n");
 }
 return 1;
}

variable_types: c char

variable_types: repeat int

variable_types:
delay
unsigned long

variable_types:
usage
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


decompiled_code:
__int64 __fastcall cmd_type(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // rbp
char v3; // al
__int64 result; // rax
__int64 v5; // rbp
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
if ( *(int *)a1 <= 0 )
{
result = 1LL;
}
else
{
v5 = 0LL;
do
{
if ( (unsigned int)zdo_type(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v5)) == -1 )
zdo_alert(
114LL,
"zdo_key reported an error for string '%s'.\n",
*(const char **)(*(_QWORD *)(a1 + 8) + 8 * v5));
++v5;
}
while ( *(_DWORD *)a1 > (int)v5 );
result = 1LL;
}
}
else
{
zdo_alert(114LL, "No keys.\n");
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 1LL;
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // rbp
char v3; // al
__int64 result; // rax
__int64 v5; // rbp
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
if ( *(int *)a1 <= 0 )
{
result = 1LL;
}
else
{
v5 = 0LL;
do
{
if ( (unsigned int)zdo_type(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v5)) == -1 )
zdo_alert(
114LL,
"zdo_key reported an error for string '%s'.\n",
*(const char **)(*(_QWORD *)(a1 + 8) + 8 * v5));
++v5;
}
while ( *(_DWORD *)a1 > (int)v5 );
result = 1LL;
}
}
else
{
zdo_alert(114LL, "No keys.\n");
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 1LL;
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cmd_type(context_t *context) {
 int i;
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--repeat N][--help] <button>\x1b[0m \n"
    "\x1b[32mSend keystrokes.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0) {
  for (i=0; i<context->argc; i++) {
   ret = zdo_type(context->argv[i]);
   if (ret == -1) {
    zdo_alert('r', "zdo_key reported an error for string '%s'.\n",
     context->argv[i]);
   }
  }
 }
 else {
  zdo_alert('r', "No keys.\n");
  printf(usage, cmd);
 }
 return 1;
}

canonical_original_code:
int cmd_type(struct context *context) {
 int i;
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--repeat N][--help] <button>\x1b[0m \n"
    "\x1b[32mSend keystrokes.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0) {
  for (i=0; i<context->argc; i++) {
   ret = zdo_type(context->argv[i]);
   if (ret == -1) {
    zdo_alert('r', "zdo_key reported an error for string '%s'.\n",
     context->argv[i]);
   }
  }
 }
 else {
  zdo_alert('r', "No keys.\n");
  printf(usage, cmd);
 }
 return 1;
}

variable_types: i int


decompiled_code:
__int64 __fastcall cmd_getmouselocation(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // rbp
char v3; // al
unsigned int v4; // ebx
unsigned int v6; // [rsp+4h] [rbp-24h] BYREF
unsigned int v7; // [rsp+8h] [rbp-20h] BYREF
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
v4 = zdo_getmouselocation(&v7, &v6);
if ( v4 )
{
zdo_alert(114LL, "X=%d\n", v7);
zdo_alert(114LL, "Y=%d\n", v6);
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help]\x1B[0m \n"
"\x1B[32mGet locations of the mouse.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
v4 = 0;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help]\x1B[0m \n"
"\x1B[32mGet locations of the mouse.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // rbp
char v3; // al
unsigned int v4; // ebx
unsigned int v6; // [rsp+4h] [rbp-24h] BYREF
unsigned int v7; // [rsp+8h] [rbp-20h] BYREF
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
v4 = zdo_getmouselocation(&v7, &v6);
if ( v4 )
{
zdo_alert(114LL, "X=%d\n", v7);
zdo_alert(114LL, "Y=%d\n", v6);
}
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help]\x1B[0m \n"
"\x1B[32mGet locations of the mouse.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
v4 = 0;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help]\x1B[0m \n"
"\x1B[32mGet locations of the mouse.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
v4 = -1;
}
return v4;
}

original_code:
int cmd_getmouselocation(context_t *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 int x, y;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help]\x1b[0m \n"
    "\x1b[32mGet locations of the mouse.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m        \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
   case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 ret = zdo_getmouselocation(&x, &y);
 if (ret) {
  zdo_alert('r', "X=%d\n", x);
  zdo_alert('r', "Y=%d\n", y);
 }
 return ret;
}

canonical_original_code:
int cmd_getmouselocation(struct context *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 int x; int y;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help]\x1b[0m \n"
    "\x1b[32mGet locations of the mouse.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m        \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
   case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 ret = zdo_getmouselocation(&x, &y);
 if (ret) {
  zdo_alert('r', "X=%d\n", x);
  zdo_alert('r', "Y=%d\n", y);
 }
 return ret;
}