decompiled_code:
void __fastcall frame_free_resources(__int64 a1)
{
void *v1; // rdi

if ( *(_DWORD *)a1 == 1 )
{
if ( *(_QWORD *)(a1 + 112) )
kl_material_decref();
}
else if ( *(_DWORD *)a1 == 2 )
{
v1 = *(void **)(a1 + 120);
if ( v1 )
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
void *v1; // rdi

if ( *(_DWORD *)a1 == 1 )
{
if ( *(_QWORD *)(a1 + 112) )
kl_material_decref();
}
else if ( *(_DWORD *)a1 == 2 )
{
v1 = *(void **)(a1 + 120);
if ( v1 )
free(v1);
}
}

original_code:
void frame_free_resources(kl_frame_t *frame) {
  switch (frame->header.type) {
    case 0x01:
      if (frame->graphic.material != ((void *)0)) {
        kl_material_decref(frame->graphic.material);
      }
      break;
    case 0x02:
      if (frame->text.str != ((void *)0)) {
        free(frame->text.str);
      }
      break;
  }
}

canonical_original_code:
void frame_free_resources(union kl_frame *frame) {
  switch (frame->header.type) {
    case 0x01:
      if (frame->graphic.material != ((void *)0)) {
        kl_material_decref(frame->graphic.material);
      }
      break;
    case 0x02:
      if (frame->text.str != ((void *)0)) {
        free(frame->text.str);
      }
      break;
  }
}

user_defined_types: struct kl_frame_text { struct kl_frame_header header; int n; char *str; }

user_defined_types: struct kl_frame_coord { int type; float x; }

user_defined_types: struct kl_frame_anchor { int point; unsigned int target_id; int target_point; struct kl_frame_coord offset; }


repo: zvxryb/kludge-engine

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

frame_free_resources(a1);
*(_DWORD *)a1 = 1;
result = kl_material_incref(a2);
*(_QWORD *)(a1 + 112) = result;
return result;
}

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

func9(a1);
*(_DWORD *)a1 = 1;
result = kl_material_incref(a2);
*(_QWORD *)(a1 + 112) = result;
return result;
}

original_code:
void kl_frame_graphic(kl_frame_t *frame, char *path) {
  frame_free_resources(frame);
  frame->header.type = 0x01;
  frame->graphic.material = kl_material_incref(path);
}

canonical_original_code:
void kl_frame_graphic(union kl_frame *frame, char *path) {
  frame_free_resources(frame);
  frame->header.type = 0x01;
  frame->graphic.material = kl_material_incref(path);
}

variable_types: union kl_frame { struct kl_frame_header { int type; int hidden; unsigned int id; struct kl_frame_coord { int type; float x; } preferred_size; struct kl_frame_anchor { int point; unsigned int target_id; int target_point; struct kl_frame_coord offset; } anchor_primary; struct kl_frame_anchor anchor_secondary; struct kl_vec2f { float x; } effective_position; struct kl_vec2f effective_size; struct kl_array { unsigned char *data; int size; int item_size; int num_items; } children; } header; struct kl_frame_graphic { struct kl_frame_header header; struct kl_material { char path[256]; struct kl_texture_t { char path[256]; unsigned int w; unsigned int id; } *diffuse; struct kl_texture_t *normal; struct kl_texture_t *specular; struct kl_texture_t *emissive; } *material; } graphic; struct kl_frame_text { struct kl_frame_header header; int n; char *str; } text; } *

variable_types:
path
char *

return_type: void

user_defined_types: union kl_frame { struct kl_frame_header header; struct kl_frame_graphic graphic; struct kl_frame_text text; }

user_defined_types: struct kl_frame_header { int type; int hidden; unsigned int id; struct kl_frame_coord preferred_size; struct kl_frame_anchor anchor_primary; struct kl_frame_anchor anchor_secondary; struct kl_vec2f effective_position; struct kl_vec2f effective_size; struct kl_array children; }

user_defined_types: struct kl_frame_graphic { struct kl_frame_header header; struct kl_material *material; }

user_defined_types: struct kl_material { char path[256]; struct kl_texture_t *diffuse; struct kl_texture_t *normal; struct kl_texture_t *specular; struct kl_texture_t *emissive; }


decompiled_code:
void __fastcall kl_frame_delete(__int64 a1)
{
int i; // ebx
unsigned int v2; // er13
int v3; // ecx
void *ptr; // [rsp+8h] [rbp-28h] BYREF

for ( i = 0; ; ++i )
{
v2 = *(_DWORD *)(a1 + 104);
if ( (int)kl_array_size_isra_0(v2) <= i )
break;
v3 = i;
kl_array_get_isra_0(*(_QWORD *)(a1 + 88), *(_DWORD *)(a1 + 100), v2, v3, &ptr);
kl_frame_delete(ptr);
}
kl_array_free(a1 + 88);
frame_free_resources(a1);
free((void *)a1);
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
int i; // ebx
unsigned int v2; // er13
int v3; // ecx
void *ptr; // [rsp+8h] [rbp-28h] BYREF

for ( i = 0; ; ++i )
{
v2 = *(_DWORD *)(a1 + 104);
if ( (int)func6(v2) <= i )
break;
v3 = i;
func7(*(_QWORD *)(a1 + 88), *(_DWORD *)(a1 + 100), v2, v3, &ptr);
func11(ptr);
}
kl_array_free(a1 + 88);
func9(a1);
free((void *)a1);
}

original_code:
void kl_frame_delete(kl_frame_t *frame) {
  kl_frame_header_t *header = &frame->header;
  kl_frame_t *child;
  for (int i=0; i < kl_array_size(&header->children); i++) {
    kl_array_get(&header->children, i, &child);
    kl_frame_delete(child);
  }
  kl_array_free(&header->children);
  frame_free_resources(frame);
  free(frame);
}

canonical_original_code:
void kl_frame_delete(union kl_frame *frame) {
  struct kl_frame_header *header = &frame->header;
  union kl_frame *child;
  for (int i = 0; i < kl_array_size(&header->children); i++) {
    kl_array_get(&header->children, i, &child);
    kl_frame_delete(child);
  }
  kl_array_free(&header->children);
  frame_free_resources(frame);
  free(frame);
}

variable_types: struct kl_frame_header { int type; int hidden; unsigned int id; struct kl_frame_coord { int type; float x; } preferred_size; struct kl_frame_anchor { int point; unsigned int target_id; int target_point; struct kl_frame_coord offset; } anchor_primary; struct kl_frame_anchor anchor_secondary; struct kl_vec2f { float x; } effective_position; struct kl_vec2f effective_size; struct kl_array { unsigned char *data; int size; int item_size; int num_items; } children; } *

variable_types: i int

user_defined_types: struct kl_texture_t { char path[256]; unsigned int w; unsigned int id; }


decompiled_code:
__int64 __fastcall kl_frame_add(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-8h] BYREF

v3 = a2;
return kl_array_push(a1 + 88, &v3);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-8h] BYREF

v3 = a2;
return kl_array_push(a1 + 88, &v3);
}

original_code:
void kl_frame_add(kl_frame_t *frame, kl_frame_t *child) {
  kl_array_push(&frame->header.children, &child);
}

canonical_original_code:
void kl_frame_add(union kl_frame *frame, union kl_frame *child) {
  kl_array_push(&frame->header.children, &child);
}

variable_types:
child
union kl_frame *

user_defined_types: struct kl_array { unsigned char *data; int size; int item_size; int num_items; }


original_code:
void kl_frame_update(kl_frame_t *frame, kl_frame_t *parent, int screen_w, int screen_h) {
  kl_frame_header_t *header = &frame->header;
  if (header->anchor_primary.point == 0xFF) return;
  if (header->hidden) return;
  kl_frame_anchor_t *anchor_primary = &header->anchor_primary;
  kl_frame_anchor_t *anchor_secondary = &header->anchor_secondary;
  kl_vec2f_t preferred_size;
  coord_normalize(&header->preferred_size, &preferred_size, screen_w, screen_h);
  kl_frame_t *primary_target = frame_lookup(parent, anchor_primary->target_id);
  kl_vec2f_t primary_target_point;
  anchor_point(anchor_primary->target_point, &primary_target_point);
  kl_vec2f_mul(&primary_target_point, &primary_target_point, &primary_target->header.effective_size);
  kl_vec2f_add(&primary_target_point, &primary_target_point, &primary_target->header.effective_position);
  kl_vec2f_t primary_offset;
  coord_normalize(&anchor_primary->offset, &primary_offset, screen_w, screen_h);
  kl_vec2f_add(&primary_target_point, &primary_target_point, &primary_offset);
  kl_vec2f_t primary_local_point;
  anchor_point(anchor_primary->point, &primary_local_point);
  kl_vec2f_t size, position;
  if (anchor_secondary->point == 0xFF) {
    size = preferred_size;
  } else {
    kl_frame_t *secondary_target = frame_lookup(parent, anchor_secondary->target_id);
    kl_vec2f_t secondary_target_point;
    anchor_point(anchor_secondary->target_point, &secondary_target_point);
    kl_vec2f_mul(&secondary_target_point, &secondary_target_point, &secondary_target->header.effective_size);
    kl_vec2f_add(&secondary_target_point, &secondary_target_point, &secondary_target->header.effective_position);
    kl_vec2f_t secondary_offset;
    coord_normalize(&anchor_secondary->offset, &secondary_offset, screen_w, screen_h);
    kl_vec2f_add(&secondary_target_point, &secondary_target_point, &secondary_offset);
    kl_vec2f_t secondary_local_point;
    anchor_point(anchor_secondary->point, &secondary_local_point);
    kl_vec2f_t target_dist;
    kl_vec2f_sub(&target_dist, &primary_target_point, &secondary_target_point);
    kl_vec2f_t local_dist;
    kl_vec2f_sub(&local_dist, &primary_local_point, &secondary_local_point);
    if ((anchor_primary->target_point & 0x0F) ==
        (anchor_secondary->target_point & 0x0F))
    {
      size.x = preferred_size.x;
    } else {
      size.x = target_dist.x / local_dist.x;
    }
    if ((anchor_primary->target_point & 0xF0) ==
        (anchor_secondary->target_point & 0xF0))
    {
      size.y = preferred_size.y;
    } else {
      size.y = target_dist.y / local_dist.y;
    }
  }
  kl_vec2f_mul(&position, &size, &primary_local_point);
  kl_vec2f_sub(&position, &primary_target_point, &position);
  kl_frame_t *child;
  for (int i=0; i < kl_array_size(&header->children); i++) {
    kl_array_get(&header->children, i, &child);
    kl_frame_update(child, frame, screen_w, screen_h);
  }
}

canonical_original_code:
void kl_frame_update(union kl_frame *frame, union kl_frame *parent, int screen_w, int screen_h) {
  struct kl_frame_header *header = &frame->header;
  if (header->anchor_primary.point == 0xFF) return;
  if (header->hidden) return;
  struct kl_frame_anchor *anchor_primary = &header->anchor_primary;
  struct kl_frame_anchor *anchor_secondary = &header->anchor_secondary;
  struct kl_vec2f preferred_size;
  coord_normalize(&header->preferred_size, &preferred_size, screen_w, screen_h);
  union kl_frame *primary_target = frame_lookup(parent, anchor_primary->target_id);
  struct kl_vec2f primary_target_point;
  anchor_point(anchor_primary->target_point, &primary_target_point);
  kl_vec2f_mul(&primary_target_point, &primary_target_point, &primary_target->header.effective_size);
  kl_vec2f_add(&primary_target_point, &primary_target_point, &primary_target->header.effective_position);
  struct kl_vec2f primary_offset;
  coord_normalize(&anchor_primary->offset, &primary_offset, screen_w, screen_h);
  kl_vec2f_add(&primary_target_point, &primary_target_point, &primary_offset);
  struct kl_vec2f primary_local_point;
  anchor_point(anchor_primary->point, &primary_local_point);
  struct kl_vec2f size; struct kl_vec2f position;
  if (anchor_secondary->point == 0xFF) {
    size = preferred_size;
  } else {
    union kl_frame *secondary_target = frame_lookup(parent, anchor_secondary->target_id);
    struct kl_vec2f secondary_target_point;
    anchor_point(anchor_secondary->target_point, &secondary_target_point);
    kl_vec2f_mul(&secondary_target_point, &secondary_target_point, &secondary_target->header.effective_size);
    kl_vec2f_add(&secondary_target_point, &secondary_target_point, &secondary_target->header.effective_position);
    struct kl_vec2f secondary_offset;
    coord_normalize(&anchor_secondary->offset, &secondary_offset, screen_w, screen_h);
    kl_vec2f_add(&secondary_target_point, &secondary_target_point, &secondary_offset);
    struct kl_vec2f secondary_local_point;
    anchor_point(anchor_secondary->point, &secondary_local_point);
    struct kl_vec2f target_dist;
    kl_vec2f_sub(&target_dist, &primary_target_point, &secondary_target_point);
    struct kl_vec2f local_dist;
    kl_vec2f_sub(&local_dist, &primary_local_point, &secondary_local_point);
    if ((anchor_primary->target_point & 0x0F) ==
        (anchor_secondary->target_point & 0x0F))
    {
      size.x = preferred_size.x;
    } else {
      size.x = target_dist.x / local_dist.x;
    }
    if ((anchor_primary->target_point & 0xF0) ==
        (anchor_secondary->target_point & 0xF0))
    {
      size.y = preferred_size.y;
    } else {
      size.y = target_dist.y / local_dist.y;
    }
  }
  kl_vec2f_mul(&position, &size, &primary_local_point);
  kl_vec2f_sub(&position, &primary_target_point, &position);
  union kl_frame *child;
  for (int i = 0; i < kl_array_size(&header->children); i++) {
    kl_array_get(&header->children, i, &child);
    kl_frame_update(child, frame, screen_w, screen_h);
  }
}

variable_types:
parent
union kl_frame *

variable_types: struct kl_frame_anchor { int point; unsigned int target_id; int target_point; struct kl_frame_coord { int type; float x; } offset; } *

variable_types:
size
struct kl_vec2f { float x; }

variable_types:
position
struct kl_vec2f { float x; }


decompiled_code:
void __fastcall mtl_free(void *ptr)
{
kl_array_free();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
kl_array_free();
free(ptr);
}

original_code:
static void mtl_free(void *item) {
  kl_array_t *entries = item;
  kl_array_free(entries);
  free(item);
}

canonical_original_code:
static void mtl_free(void *item) {
  struct kl_array *entries = item;
  kl_array_free(entries);
  free(item);
}

variable_types:
item
void *

variable_types: struct kl_array { unsigned char *data; int size; int item_size; int num_items; } *


decompiled_code:
__int64 __fastcall kl_material_mtl_incref(__int64 a1)
{
__int64 v1; // rax

if ( !loader )
loader = kl_resource_loader_new(mtl_load, mtl_free);
v1 = kl_resource_getid(a1);
return kl_resource_incref(loader, v1);
}

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

if ( !loader )
loader = kl_resource_loader_new(mtl_load, mtl_free);
v1 = kl_resource_getid(a1);
return kl_resource_incref(loader, v1);
}

original_code:
kl_array_t *kl_material_mtl_incref(char *path) {
  if (loader == ((void *)0)) {
    loader = kl_resource_loader_new((kl_resources_load_cb)&mtl_load, (kl_resources_free_cb)&mtl_free);
  }
  kl_resource_id_t resid = kl_resource_getid(path);
  kl_array_t *entries = kl_resource_incref(loader, resid);
  return entries;
}

canonical_original_code:
struct kl_array *kl_material_mtl_incref(char *path) {
  if (loader == ((void *)0)) {
    loader = kl_resource_loader_new((kl_resources_load_cb)&mtl_load, (kl_resources_free_cb)&mtl_free);
  }
  unsigned long resid = kl_resource_getid(path);
  struct kl_array *entries = kl_resource_incref(loader, resid);
  return entries;
}

variable_types:
resid
unsigned long

return_type: struct kl_array { unsigned char *data; int size; int item_size; int num_items; } *


decompiled_code:
__int64 __fastcall kl_material_mtl_decref(__int64 a1)
{
__int64 v1; // rax

v1 = kl_resource_getid(a1);
return kl_resource_decref(v1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rax

v1 = kl_resource_getid(a1);
return kl_resource_decref(v1);
}

original_code:
void kl_material_mtl_decref(char *path) {
  kl_resource_id_t resid = kl_resource_getid(path);
  kl_resource_decref(resid);
}

canonical_original_code:
void kl_material_mtl_decref(char *path) {
  unsigned long resid = kl_resource_getid(path);
  kl_resource_decref(resid);
}


decompiled_code:
__int64 __fastcall kl_material_loadfrommtl(__int64 a1, const char *a2, const char *a3, __int64 a4)
{
int i; // ebx
unsigned int v7; // er15
__int64 result; // rax
__int64 v9; // r15
__int64 v10; // r13
__int64 v11; // r12
__int64 v12; // rbx
char s1[256]; // [rsp+10h] [rbp-530h] BYREF
char v14[256]; // [rsp+110h] [rbp-430h] BYREF
char v15[256]; // [rsp+210h] [rbp-330h] BYREF
char v16[256]; // [rsp+310h] [rbp-230h] BYREF
char v17[304]; // [rsp+410h] [rbp-130h] BYREF

for ( i = 0; ; ++i )
{
v7 = *(_DWORD *)(a1 + 16);
if ( (int)kl_array_size_isra_0(v7) <= i )
return 0LL;
kl_array_get_isra_0(*(_QWORD *)a1, *(_DWORD *)(a1 + 12), v7, i, s1);
if ( !strcmp(s1, a3) )
break;
}
strncpy((char *)a4, a2, 0x100uLL);
v9 = kl_texture_incref(v14);
v10 = kl_texture_incref(v16);
v11 = kl_texture_incref(v15);
v12 = kl_texture_incref(v17);
if ( !v9 )
v9 = kl_texture_incref("DEFAULT_DIFFUSE");
if ( !v10 )
v10 = kl_texture_incref("DEFAULT_NORMAL");
if ( !v11 )
v11 = kl_texture_incref("DEFAULT_SPECULAR");
if ( !v12 )
v12 = kl_texture_incref("DEFAULT_EMISSIVE");
*(_QWORD *)(a4 + 256) = v9;
result = 1LL;
*(_QWORD *)(a4 + 264) = v10;
*(_QWORD *)(a4 + 272) = v11;
*(_QWORD *)(a4 + 280) = v12;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, const char *a3, __int64 a4)
{
int i; // ebx
unsigned int v7; // er15
__int64 result; // rax
__int64 v9; // r15
__int64 v10; // r13
__int64 v11; // r12
__int64 v12; // rbx
char s1[256]; // [rsp+10h] [rbp-530h] BYREF
char v14[256]; // [rsp+110h] [rbp-430h] BYREF
char v15[256]; // [rsp+210h] [rbp-330h] BYREF
char v16[256]; // [rsp+310h] [rbp-230h] BYREF
char v17[304]; // [rsp+410h] [rbp-130h] BYREF

for ( i = 0; ; ++i )
{
v7 = *(_DWORD *)(a1 + 16);
if ( (int)func2(v7) <= i )
return 0LL;
func3(*(_QWORD *)a1, *(_DWORD *)(a1 + 12), v7, i, s1);
if ( !strcmp(s1, a3) )
break;
}
strncpy((char *)a4, a2, 0x100uLL);
v9 = kl_texture_incref(v14);
v10 = kl_texture_incref(v16);
v11 = kl_texture_incref(v15);
v12 = kl_texture_incref(v17);
if ( !v9 )
v9 = kl_texture_incref("DEFAULT_DIFFUSE");
if ( !v10 )
v10 = kl_texture_incref("DEFAULT_NORMAL");
if ( !v11 )
v11 = kl_texture_incref("DEFAULT_SPECULAR");
if ( !v12 )
v12 = kl_texture_incref("DEFAULT_EMISSIVE");
*(_QWORD *)(a4 + 256) = v9;
result = 1LL;
*(_QWORD *)(a4 + 264) = v10;
*(_QWORD *)(a4 + 272) = v11;
*(_QWORD *)(a4 + 280) = v12;
return result;
}

original_code:
_Bool kl_material_loadfrommtl(kl_array_t *entries, char *vpath, char *entvpath, kl_material_t *material) {
  mtl_entry_t entry;
  for (int i=0; i < kl_array_size(entries); i++) {
    kl_array_get(entries, i, &entry);
    if (strcmp(entry.path, entvpath) == 0) {
      strncpy(material->path, vpath, 0x100);
      kl_texture_t *diffuse = kl_texture_incref(entry.map_diffuse);
      kl_texture_t *normal = kl_texture_incref(entry.map_normal);
      kl_texture_t *specular = kl_texture_incref(entry.map_specular);
      kl_texture_t *emissive = kl_texture_incref(entry.map_emissive);
      if (diffuse == ((void *)0)) diffuse = kl_texture_incref("DEFAULT_DIFFUSE");
      if (normal == ((void *)0)) normal = kl_texture_incref("DEFAULT_NORMAL");
      if (specular == ((void *)0)) specular = kl_texture_incref("DEFAULT_SPECULAR");
      if (emissive == ((void *)0)) emissive = kl_texture_incref("DEFAULT_EMISSIVE");
      material->diffuse = diffuse;
      material->normal = normal;
      material->specular = specular;
      material->emissive = emissive;
      return 1;
    }
  }
  return 0;
}

canonical_original_code:
_Bool kl_material_loadfrommtl(struct kl_array *entries, char *vpath, char *entvpath, struct kl_material *material) {
  struct mtl_entry entry;
  for (int i = 0; i < kl_array_size(entries); i++) {
    kl_array_get(entries, i, &entry);
    if (strcmp(entry.path, entvpath) == 0) {
      strncpy(material->path, vpath, 0x100);
      struct kl_texture_t *diffuse = kl_texture_incref(entry.map_diffuse);
      struct kl_texture_t *normal = kl_texture_incref(entry.map_normal);
      struct kl_texture_t *specular = kl_texture_incref(entry.map_specular);
      struct kl_texture_t *emissive = kl_texture_incref(entry.map_emissive);
      if (diffuse == ((void *)0)) diffuse = kl_texture_incref("DEFAULT_DIFFUSE");
      if (normal == ((void *)0)) normal = kl_texture_incref("DEFAULT_NORMAL");
      if (specular == ((void *)0)) specular = kl_texture_incref("DEFAULT_SPECULAR");
      if (emissive == ((void *)0)) emissive = kl_texture_incref("DEFAULT_EMISSIVE");
      material->diffuse = diffuse;
      material->normal = normal;
      material->specular = specular;
      material->emissive = emissive;
      return 1;
    }
  }
  return 0;
}

variable_types:
vpath
char *

variable_types:
entvpath
char *

variable_types: struct kl_material { char path[256]; struct kl_texture_t { char path[256]; unsigned int w; unsigned int id; } *diffuse; struct kl_texture_t *normal; struct kl_texture_t *specular; struct kl_texture_t *emissive; } *

variable_types: struct mtl_entry { char path[256]; char map_diffuse[256]; char map_specular[256]; char map_normal[256]; char map_emissive[256]; }


original_code:
static inline void kl_vec3f_norm(kl_vec3f_t *dst, kl_vec3f_t *src) {
  float m = kl_vec3f_magnitude(src);
  if (m == 0.0f) {
    *dst = (kl_vec3f_t){ .x = 0.0f, .y = 0.0f, .z = 0.0f };
    return;
  }
  float s = 1.0f/m;
  kl_vec3f_scale(dst, src, s);
}

canonical_original_code:
static inline void kl_vec3f_norm(struct kl_vec3f *dst, struct kl_vec3f *src) {
  float m = kl_vec3f_magnitude(src);
  if (m == 0.0f) {
    *dst = (struct kl_vec3f){ .x = 0.0f, .y = 0.0f, .z = 0.0f };
    return;
  }
  float s = 1.0f/m;
  kl_vec3f_scale(dst, src, s);
}

variable_types:
dst
struct kl_vec3f { float x; } *

variable_types:
src
struct kl_vec3f *

variable_types: m float

variable_types: s float


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

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

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

variable_types:
temp
struct kl_vec3f { float x; }

variable_types:
dir
struct kl_vec3f { float x; }

variable_types:
center
struct kl_vec3f { float x; }

variable_types: radius float

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


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; }


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:
verts
struct kl_vec3f *

variable_types: n int

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

variable_types: i int

variable_types:
v
struct kl_vec3f { float x; } *


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; } *


main

canonical_name: main

repo: zwizwa/shaco

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)
{
func8(argc, argv, envp);
func9();
return 0;
}

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

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

return_type: int


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; }


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; }


repo: zwizwa/sl-apdu

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

v2 = a1;
fwrite("APDU:", 1uLL, 5uLL, stderr);
if ( a2 )
{
do
{
v3 = *v2++;
fprintf(stderr, " %02x", v3);
}
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
__int64 v3; // rdx

v2 = a1;
fwrite("APDU:", 1uLL, 5uLL, stderr);
if ( a2 )
{
do
{
v3 = *v2++;
fprintf(stderr, " %02x", v3);
}
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 func16(_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

result = *(unsigned int *)(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;
*(_BYTE *)(a1 + result + 32) = a2;
return result;
}

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

result = *(unsigned int *)(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;
*(_BYTE *)(a1 + 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:
__int64 __fastcall apdu_split_inbyte(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3; // esi
int v4; // er12
int v6; // eax

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);
v3 = *(_DWORD *)(a1 + 16) + 1;
goto LABEL_4;
case 4:
v4 = a2;
apdu_buf_append(a1, a2);
if ( !a2 )
v4 = 256;
*(_DWORD *)(a1 + 28) = v4;
return (__int64)set_state((_DWORD *)a1, 7);
case 5:
result = apdu_buf_append(a1, a2);
if ( (*(_DWORD *)(a1 + 28))-- != 1 )
return result;
goto LABEL_12;
case 6:
apdu_buf_append(a1, a2);
--*(_DWORD *)(a1 + 28);
LABEL_12:
result = (__int64)set_state((_DWORD *)a1, 7);
break;
case 7:
if ( a2 != 96 )
{
v6 = *(unsigned __int8 *)(a1 + 20);
if ( (_BYTE)v6 == a2 || a2 == v6 + 1 )
{
v3 = 5;
}
else
{
apdu_buf_append(a1, a2);
v3 = 8;
}
LABEL_4:
result = (__int64)set_state((_DWORD *)a1, v3);
}
break;
case 8:
apdu_buf_append(a1, a2);
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))a1)(a1 + 32, *(unsigned int *)(a1 + 24), *(_QWORD *)(a1 + 8));
result = (__int64)set_state((_DWORD *)a1, 0);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3; // esi
int v4; // er12
int v6; // eax

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:
func17(a1, a2);
v3 = *(_DWORD *)(a1 + 16) + 1;
goto LABEL_4;
case 4:
v4 = a2;
func17(a1, a2);
if ( !a2 )
v4 = 256;
*(_DWORD *)(a1 + 28) = v4;
return (__int64)func16((_DWORD *)a1, 7);
case 5:
result = func17(a1, a2);
if ( (*(_DWORD *)(a1 + 28))-- != 1 )
return result;
goto LABEL_12;
case 6:
func17(a1, a2);
--*(_DWORD *)(a1 + 28);
LABEL_12:
result = (__int64)func16((_DWORD *)a1, 7);
break;
case 7:
if ( a2 != 96 )
{
v6 = *(unsigned __int8 *)(a1 + 20);
if ( (_BYTE)v6 == a2 || a2 == v6 + 1 )
{
v3 = 5;
}
else
{
func17(a1, a2);
v3 = 8;
}
LABEL_4:
result = (__int64)func16((_DWORD *)a1, v3);
}
break;
case 8:
func17(a1, a2);
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))a1)(a1 + 32, *(unsigned int *)(a1 + 24), *(_QWORD *)(a1 + 8));
result = (__int64)func16((_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 func19(_DWORD *a1)
{
return func16(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 func20(__int64 a1)
{
puts("BOUNDARY");
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))a1)(a1 + 32, *(unsigned int *)(a1 + 24), *(_QWORD *)(a1 + 8));
return func16((_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:
__int64 __fastcall apdu_split_in(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int8 *v3; // rbp
unsigned __int8 *v4; // rbx
unsigned __int8 v5; // si
__int64 result; // rax

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

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

if ( a3 )
{
v3 = &a2[a3];
v4 = a2;
do
{
v5 = *v4++;
result = func18(a1, v5);
}
while ( v4 != v3 );
}
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; // r13
char v3; // al
unsigned int v4; // er12
__int64 result; // rax
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 )
{
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);
return v4;
}
v6 = atof(**(const char ***)(a1 + 8));
zdo_sleep(v6);
result = 1LL;
}
else
{
if ( v3 != 104 )
{
v4 = -1;
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);
return v4;
}
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);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r13
char v3; // al
unsigned int v4; // er12
__int64 result; // rax
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 )
{
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);
return v4;
}
v6 = atof(**(const char ***)(a1 + 8));
zdo_sleep(v6);
result = 1LL;
}
else
{
if ( v3 != 104 )
{
v4 = -1;
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);
return v4;
}
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);
result = 0LL;
}
return result;
}

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; // r12
char v3; // al
const char *v4; // rdx
unsigned int v5; // er12
int v7; // eax
unsigned int v8; // eax
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 )
{
v8 = atoi(**(const char ***)(a1 + 8));
v7 = zdo_mouseup(v8);
}
else
{
v7 = zdo_mouseup(1LL);
}
v5 = 1;
if ( v7 == -1 )
zdo_alert(114LL, "zdo_mouseup reported an error.\n");
return v5;
}
if ( v3 != 104 )
{
zdo_alert(114LL, "unknown option.\n");
v4 = v2;
v5 = -1;
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",
v4);
return v5;
}
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);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
const char *v4; // rdx
unsigned int v5; // er12
int v7; // eax
unsigned int v8; // eax
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 )
{
v8 = atoi(**(const char ***)(a1 + 8));
v7 = zdo_mouseup(v8);
}
else
{
v7 = zdo_mouseup(1LL);
}
v5 = 1;
if ( v7 == -1 )
zdo_alert(114LL, "zdo_mouseup reported an error.\n");
return v5;
}
if ( v3 != 104 )
{
zdo_alert(114LL, "unknown option.\n");
v4 = v2;
v5 = -1;
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",
v4);
return v5;
}
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);
return 0LL;
}

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
{
v1 += 16LL;
zdo_alert(98LL, "--%s\n", v0);
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
{
v1 += 16LL;
zdo_alert(98LL, "--%s\n", v0);
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
const char **v3; // rbx

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

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

v2 = dispatch;
if ( !dispatch )
return 0LL;
v3 = (const char **)(unsigned int)((_DWORD)&dispatch + 16);
while ( strcasecmp(v2, s2) )
{
v2 = *v3;
v3 += 2;
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;
v2 = dispatch;
v7 = a2 + 8;
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;
v2 = dispatch;
v7 = a2 + 8;
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; // r13
__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; // r13
__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:
__int64 __fastcall consume_args(unsigned int *a1, int a2)
{
__int64 v2; // rcx
__int64 result; // rax
__int64 v4; // 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);
v4 = (int)*a1;
*a1 = 0;
result = 8 * v4;
}
else
{
*a1 = v2 - a2;
result = 8LL * a2;
}
*((_QWORD *)a1 + 1) += result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, int a2)
{
__int64 v2; // rcx
__int64 result; // rax
__int64 v4; // 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);
v4 = (int)*a1;
*a1 = 0;
result = 8 * v4;
}
else
{
*a1 = v2 - a2;
result = 8LL * a2;
}
*((_QWORD *)a1 + 1) += result;
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:
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 cmd_mousedown(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
const char *v4; // rdx
unsigned int v5; // er12
int v7; // eax
unsigned int v8; // eax
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 )
{
v8 = atoi(**(const char ***)(a1 + 8));
v7 = zdo_mousedown(v8);
}
else
{
v7 = zdo_mousedown(1LL);
}
v5 = 1;
if ( v7 == -1 )
zdo_alert(114LL, "zdo_mousedown reported an error.\n");
return v5;
}
if ( v3 != 104 )
{
zdo_alert(114LL, "unknown option.\n");
v4 = v2;
v5 = -1;
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",
v4);
return v5;
}
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);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
const char *v4; // rdx
unsigned int v5; // er12
int v7; // eax
unsigned int v8; // eax
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 )
{
v8 = atoi(**(const char ***)(a1 + 8));
v7 = zdo_mousedown(v8);
}
else
{
v7 = zdo_mousedown(1LL);
}
v5 = 1;
if ( v7 == -1 )
zdo_alert(114LL, "zdo_mousedown reported an error.\n");
return v5;
}
if ( v3 != 104 )
{
zdo_alert(114LL, "unknown option.\n");
v4 = v2;
v5 = -1;
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",
v4);
return v5;
}
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);
return 0LL;
}

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
char *v2; // r12
char v3; // al
const char *v4; // rsi
unsigned int v5; // er12
const char **v7; // rbx
unsigned int v8; // er12
unsigned int v9; // eax
__int64 v10; // rdi
const char *v11; // rdx
const char *v12; // rdx
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");
v11 = v2;
v5 = 0;
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",
v11);
}
else
{
v7 = *(const char ***)(a1 + 8);
v8 = atoi(*v7);
v9 = atoi(v7[1]);
v10 = v8;
v5 = 0;
if ( (unsigned int)zdo_mousemove_relative(v10, v9) == -1 )
zdo_alert(114LL, "zdo_mousemove_relative reported an error.\n");
}
}
else if ( v3 == 104 )
{
v4 = v2;
v5 = 0;
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",
v4);
}
else
{
zdo_alert(114LL, "unknown option.\n");
v12 = v2;
v5 = -1;
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",
v12);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
char *v2; // r12
char v3; // al
const char *v4; // rsi
unsigned int v5; // er12
const char **v7; // rbx
unsigned int v8; // er12
unsigned int v9; // eax
__int64 v10; // rdi
const char *v11; // rdx
const char *v12; // rdx
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");
v11 = v2;
v5 = 0;
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",
v11);
}
else
{
v7 = *(const char ***)(a1 + 8);
v8 = atoi(*v7);
v9 = atoi(v7[1]);
v10 = v8;
v5 = 0;
if ( (unsigned int)zdo_mousemove_relative(v10, v9) == -1 )
zdo_alert(114LL, "zdo_mousemove_relative reported an error.\n");
}
}
else if ( v3 == 104 )
{
v4 = v2;
v5 = 0;
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",
v4);
}
else
{
zdo_alert(114LL, "unknown option.\n");
v12 = v2;
v5 = -1;
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",
v12);
}
return v5;
}

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)
{
unsigned int v1; // er13
char *const *v2; // rsi
const char *v3; // r12
char v4; // al
const char *v5; // rdx
unsigned int v6; // er12
const char **v8; // rbx
unsigned int v9; // er12
unsigned int v10; // eax
__int64 v11; // rdi
const char *v12; // rdx
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = 0;
v2 = *(char *const **)(a1 + 8);
v3 = *v2;
while ( 1 )
{
v4 = getopt_long_only(*(_DWORD *)a1, v2, "rh", &longopts_0, longind);
if ( v4 == -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");
v12 = v3;
v6 = 1;
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",
v12);
}
else
{
v8 = *(const char ***)(a1 + 8);
v9 = atoi(*v8);
v10 = atoi(v8[1]);
v11 = v9;
v6 = 1;
if ( (unsigned int)zdo_mousemove(v11, v10, v1) == -1 )
zdo_alert(114LL, "zdo_mousemove reported an error.\n");
}
return v6;
}
if ( v4 == 104 )
break;
if ( v4 != 114 )
{
zdo_alert(114LL, "unknown option.\n");
v5 = v3;
v6 = -1;
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",
v5);
return v6;
}
v2 = *(char *const **)(a1 + 8);
v1 = 1;
}
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",
v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // er13
char *const *v2; // rsi
const char *v3; // r12
char v4; // al
const char *v5; // rdx
unsigned int v6; // er12
const char **v8; // rbx
unsigned int v9; // er12
unsigned int v10; // eax
__int64 v11; // rdi
const char *v12; // rdx
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = 0;
v2 = *(char *const **)(a1 + 8);
v3 = *v2;
while ( 1 )
{
v4 = getopt_long_only(*(_DWORD *)a1, v2, "rh", &longopts_0, longind);
if ( v4 == -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");
v12 = v3;
v6 = 1;
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",
v12);
}
else
{
v8 = *(const char ***)(a1 + 8);
v9 = atoi(*v8);
v10 = atoi(v8[1]);
v11 = v9;
v6 = 1;
if ( (unsigned int)zdo_mousemove(v11, v10, v1) == -1 )
zdo_alert(114LL, "zdo_mousemove reported an error.\n");
}
return v6;
}
if ( v4 == 104 )
break;
if ( v4 != 114 )
{
zdo_alert(114LL, "unknown option.\n");
v5 = v3;
v6 = -1;
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",
v5);
return v6;
}
v2 = *(char *const **)(a1 + 8);
v1 = 1;
}
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",
v3);
return 0LL;
}

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)
{
unsigned int v1; // er13
unsigned int v2; // er12
unsigned int v3; // ebp
char *const *v4; // rsi
const char *v5; // r14
unsigned int v6; // eax
unsigned int v7; // er15
const char *v9; // r14
char v10; // [rsp+Bh] [rbp-3Dh] BYREF
int longind[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v1 = 0;
v2 = 0;
v3 = 0;
v4 = *(char *const **)(a1 + 8);
v5 = *v4;
while ( 1 )
{
v6 = getopt_long_only(*(_DWORD *)a1, v4, "mkhc", &longopts_0, longind);
v10 = v6;
if ( (_BYTE)v6 == 0xFF )
break;
if ( (_BYTE)v6 == 107 )
{
v1 = 1;
v2 = 0;
}
else if ( (char)v6 > 107 )
{
if ( (_BYTE)v6 != 109 )
goto LABEL_14;
v1 = 0;
v2 = 1;
}
else
{
if ( (_BYTE)v6 != 99 )
{
if ( (_BYTE)v6 == 104 )
{
v7 = 0;
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",
v5);
return v7;
}
LABEL_14:
v7 = -1;
zdo_alert(114LL, "unknown option.\n");
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",
v5);
return v7;
}
v3 = 1;
}
v4 = *(char *const **)(a1 + 8);
}
consume_args(a1, (unsigned int)optind, v6);
v7 = *(_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",
v5);
return v7;
}
v9 = **(const char ***)(a1 + 8);
if ( v3 )
{
v7 = access(v9, 0);
if ( v7 == -1 )
{
zdo_alert(114LL, "No such file(%s).\n", v9);
return v7;
}
}
else
{
if ( access(v9, 0) == -1 )
goto LABEL_19;
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 )
goto LABEL_19;
v7 = 0;
if ( v10 != 99 )
return v7;
}
v3 = 1;
LABEL_19:
zdo_record(v9, v3, v1, v2);
return 0;
}

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

v1 = 0;
v2 = 0;
v3 = 0;
v4 = *(char *const **)(a1 + 8);
v5 = *v4;
while ( 1 )
{
v6 = getopt_long_only(*(_DWORD *)a1, v4, "mkhc", &longopts_0, longind);
v10 = v6;
if ( (_BYTE)v6 == 0xFF )
break;
if ( (_BYTE)v6 == 107 )
{
v1 = 1;
v2 = 0;
}
else if ( (char)v6 > 107 )
{
if ( (_BYTE)v6 != 109 )
goto LABEL_14;
v1 = 0;
v2 = 1;
}
else
{
if ( (_BYTE)v6 != 99 )
{
if ( (_BYTE)v6 == 104 )
{
v7 = 0;
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",
v5);
return v7;
}
LABEL_14:
v7 = -1;
zdo_alert(114LL, "unknown option.\n");
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",
v5);
return v7;
}
v3 = 1;
}
v4 = *(char *const **)(a1 + 8);
}
consume_args(a1, (unsigned int)optind, v6);
v7 = *(_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",
v5);
return v7;
}
v9 = **(const char ***)(a1 + 8);
if ( v3 )
{
v7 = access(v9, 0);
if ( v7 == -1 )
{
zdo_alert(114LL, "No such file(%s).\n", v9);
return v7;
}
}
else
{
if ( access(v9, 0) == -1 )
goto LABEL_19;
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 )
goto LABEL_19;
v7 = 0;
if ( v10 != 99 )
return v7;
}
v3 = 1;
LABEL_19:
zdo_record(v9, v3, v1, v2);
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)
{
char v1; // r12
char *const *v2; // rsi
const char *v3; // rbp
char v4; // al
__int64 v5; // rdx
unsigned int v6; // er13
int longind; // [rsp+4h] [rbp-44h] BYREF
char v9[64]; // [rsp+8h] [rbp-40h] BYREF

v1 = 114;
v2 = *(char *const **)(a1 + 8);
v3 = *v2;
while ( 1 )
{
v4 = getopt_long_only(*(_DWORD *)a1, v2, "rgbh", &longopts_0, &longind);
if ( v4 == -1 )
{
consume_args(a1, (unsigned int)optind);
v6 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
{
v6 = 0;
zdo_alert((unsigned int)v1, **(_QWORD **)(a1 + 8), v9);
}
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",
v3);
}
return v6;
}
if ( v4 == 104 )
break;
if ( v4 > 104 )
{
if ( v4 != 114 )
goto LABEL_9;
}
else if ( v4 != 98 && v4 != 103 )
{
LABEL_9:
v6 = -1;
zdo_alert(114LL, "unknown option.\n", v5);
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",
v3);
return v6;
}
v2 = *(char *const **)(a1 + 8);
v1 = v4;
}
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",
v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char v1; // r12
char *const *v2; // rsi
const char *v3; // rbp
char v4; // al
__int64 v5; // rdx
unsigned int v6; // er13
int longind; // [rsp+4h] [rbp-44h] BYREF
char v9[64]; // [rsp+8h] [rbp-40h] BYREF

v1 = 114;
v2 = *(char *const **)(a1 + 8);
v3 = *v2;
while ( 1 )
{
v4 = getopt_long_only(*(_DWORD *)a1, v2, "rgbh", &longopts_0, &longind);
if ( v4 == -1 )
{
consume_args(a1, (unsigned int)optind);
v6 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
{
v6 = 0;
zdo_alert((unsigned int)v1, **(_QWORD **)(a1 + 8), v9);
}
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",
v3);
}
return v6;
}
if ( v4 == 104 )
break;
if ( v4 > 104 )
{
if ( v4 != 114 )
goto LABEL_9;
}
else if ( v4 != 98 && v4 != 103 )
{
LABEL_9:
v6 = -1;
zdo_alert(114LL, "unknown option.\n", v5);
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",
v3);
return v6;
}
v2 = *(char *const **)(a1 + 8);
v1 = v4;
}
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",
v3);
return 0LL;
}

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 *