decompiled_code:
_QWORD *sdelay_create()
{
_QWORD *v0; // rbx

v0 = malloc(0x30uLL);
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
v0[3] = 0LL;
v0[4] = 0LL;
v0[5] = 0LL;
*v0 = sdelay_allpass_create(0x515u, (__m128i)(unsigned int)LC0);
v0[1] = sdelay_allpass_create(0x2AFu, (__m128i)(unsigned int)LC0);
v0[2] = sdelay_allpass_create(0x14Fu, (__m128i)(unsigned int)LC0);
*((_DWORD *)v0 + 7) = 0;
*((_DWORD *)v0 + 8) = 1065353216;
return v0;
}

canonical_decompiled_code:
_QWORD *func5()
{
_QWORD *v0; // rbx

v0 = malloc(0x30uLL);
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
v0[3] = 0LL;
v0[4] = 0LL;
v0[5] = 0LL;
*v0 = sdelay_allpass_create(0x515u, (__m128i)(unsigned int)LC0);
v0[1] = sdelay_allpass_create(0x2AFu, (__m128i)(unsigned int)LC0);
v0[2] = sdelay_allpass_create(0x14Fu, (__m128i)(unsigned int)LC0);
*((_DWORD *)v0 + 7) = 0;
*((_DWORD *)v0 + 8) = 1065353216;
return v0;
}

original_code:
sdelay_t *sdelay_create(){
  sdelay_t *s;
  int i;
  s = (sdelay_t *)malloc(sizeof(sdelay_t));
  memset(s, 0, sizeof(sdelay_t));
  for(i = 0 ; i < 3; i ++){
    s->apfilter[i] = sdelay_allpass_create(tapdefs[i], gaindefs[i]);
  }
  s->dry = 0.0;
  s->wet = 1.0;
  return s;
}

canonical_original_code:
struct sdelay_t *sdelay_create(){
  struct sdelay_t *s;
  int i;
  s = (struct sdelay_t *)malloc(sizeof(sdelay_t));
  memset(s, 0, sizeof(sdelay_t));
  for(i = 0 ; i < 3; i ++){
    s->apfilter[i] = sdelay_allpass_create(tapdefs[i], gaindefs[i]);
  }
  s->dry = 0.0;
  s->wet = 1.0;
  return s;
}

return_type: struct sdelay_t { struct sdelay_allpass_t { struct audiobuf_t { int n_channels; int sampling_rate; int qbit; float **data; int *index; int size; } *tap; float gain; float current_output_l; float current_output_r; } *apfilter[3]; float gain; float dry; float wet; float current_output_l; float current_output_r; } *


decompiled_code:
void __fastcall sdelay_destroy(void *ptr)
{
sdelay_allpass_destroy(*(void **)ptr);
sdelay_allpass_destroy(*((void **)ptr + 1));
sdelay_allpass_destroy(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
func4(*(void **)ptr);
func4(*((void **)ptr + 1));
func4(*((void **)ptr + 2));
free(ptr);
}

original_code:
void sdelay_destroy(sdelay_t *s){
  int i;
  for(i = 0 ; i < 3; i ++){
    sdelay_allpass_destroy(s->apfilter[i]);
  }
  free(s);
}

canonical_original_code:
void sdelay_destroy(struct sdelay_t *s){
  int i;
  for(i = 0 ; i < 3; i ++){
    sdelay_allpass_destroy(s->apfilter[i]);
  }
  free(s);
}

variable_types: struct sdelay_t { struct sdelay_allpass_t { struct audiobuf_t { int n_channels; int sampling_rate; int qbit; float **data; int *index; int size; } *tap; float gain; float current_output_l; float current_output_r; } *apfilter[3]; float gain; float dry; float wet; float current_output_l; float current_output_r; } *

variable_types: i int

return_type: void

user_defined_types: struct sdelay_t { struct sdelay_allpass_t *apfilter[3]; float gain; float dry; float wet; float current_output_l; float current_output_r; }

user_defined_types: struct sdelay_allpass_t { struct audiobuf_t *tap; float gain; float current_output_l; float current_output_r; }


decompiled_code:
void __fastcall sdelay_set_drywet(__int64 a1, float a2, float a3)
{
*(float *)(a1 + 28) = a2;
*(float *)(a1 + 32) = a3;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, float a2, float a3)
{
*(float *)(a1 + 28) = a2;
*(float *)(a1 + 32) = a3;
}

original_code:
void sdelay_set_drywet(sdelay_t *s, float dry, float wet){
  s->dry = dry;
  s->wet = wet;
}

canonical_original_code:
void sdelay_set_drywet(struct sdelay_t *s, float dry, float wet){
  s->dry = dry;
  s->wet = wet;
}

variable_types: dry float

variable_types: wet float

user_defined_types: struct audiobuf_t { int n_channels; int sampling_rate; int qbit; float **data; int *index; int size; }


decompiled_code:
__int64 __fastcall sdelay_render(__int64 a1, __int64 a2, unsigned int a3, int a4)
{
__int64 result; // rax
int v6; // er12
double v7; // xmm0_8
float v8; // [rsp+0h] [rbp-38h]
float v9; // [rsp+4h] [rbp-34h]
float v10; // [rsp+8h] [rbp-30h]
float v11; // [rsp+Ch] [rbp-2Ch]

result = audiobuf_seek(a2, a3);
if ( a4 > 0 )
{
v6 = 0;
do
{
v8 = audiobuf_get(a2, 0LL);
v9 = audiobuf_get(a2, 1LL);
sdelay_process((float **)a1, v8, v9);
v10 = sdelay_current_output_l(a1);
v11 = sdelay_current_output_r(a1);
audiobuf_write(
a2,
0LL,
COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT((float)(v10 * *(float *)(a1 + 32)) + (float)(v8 * *(float *)(a1 + 28)))));
*(_QWORD *)&v7 = LODWORD(v11);
*(float *)&v7 = (float)(v11 * *(float *)(a1 + 32)) + (float)(v9 * *(float *)(a1 + 28));
result = audiobuf_write(a2, 1LL, v7);
++v6;
}
while ( a4 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned int a3, int a4)
{
__int64 result; // rax
int v6; // er12
double v7; // xmm0_8
float v8; // [rsp+0h] [rbp-38h]
float v9; // [rsp+4h] [rbp-34h]
float v10; // [rsp+8h] [rbp-30h]
float v11; // [rsp+Ch] [rbp-2Ch]

result = audiobuf_seek(a2, a3);
if ( a4 > 0 )
{
v6 = 0;
do
{
v8 = audiobuf_get(a2, 0LL);
v9 = audiobuf_get(a2, 1LL);
func3((float **)a1, v8, v9);
v10 = func0(a1);
v11 = func1(a1);
audiobuf_write(
a2,
0LL,
COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT((float)(v10 * *(float *)(a1 + 32)) + (float)(v8 * *(float *)(a1 + 28)))));
*(_QWORD *)&v7 = LODWORD(v11);
*(float *)&v7 = (float)(v11 * *(float *)(a1 + 32)) + (float)(v9 * *(float *)(a1 + 28));
result = audiobuf_write(a2, 1LL, v7);
++v6;
}
while ( a4 != v6 );
}
return result;
}

original_code:
void sdelay_render(sdelay_t *s, audiobuf_t *a, int start, int size){
  int i;
  float il, ir;
  float ol, or;
  audiobuf_seek(a, start);
  for(i = 0; i < size; i ++){
    il = audiobuf_get(a, 0);
    ir = audiobuf_get(a, 1);
    sdelay_process(s, il, ir);
    ol = sdelay_current_output_l(s);
    or = sdelay_current_output_r(s);
    audiobuf_write(a, 0, ol*s->wet + il*s->dry);
    audiobuf_write(a, 1, or*s->wet + ir*s->dry);
  }
}

canonical_original_code:
void sdelay_render(struct sdelay_t *s, struct audiobuf_t *a, int start, int size){
  int i;
  float il; float ir;
  float ol; float or;
  audiobuf_seek(a, start);
  for(i = 0; i < size; i ++){
    il = audiobuf_get(a, 0);
    ir = audiobuf_get(a, 1);
    sdelay_process(s, il, ir);
    ol = sdelay_current_output_l(s);
    or = sdelay_current_output_r(s);
    audiobuf_write(a, 0, ol*s->wet + il*s->dry);
    audiobuf_write(a, 1, or*s->wet + ir*s->dry);
  }
}

variable_types:
a
struct audiobuf_t *

variable_types: start int

variable_types: size int

variable_types: il float

variable_types: ir float

variable_types: ol float

variable_types: or float


decompiled_code:
void __fastcall soundmodule_chamber_init(__int64 a1, int a2)
{
*(_DWORD *)a1 = a2;
if ( a2 )
{
if ( a2 == 1 )
*(_QWORD *)(a1 + 8) = nrsynth_create();
}
else
{
*(_QWORD *)(a1 + 8) = wtssynth_create();
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
*(_DWORD *)a1 = a2;
if ( a2 )
{
if ( a2 == 1 )
*(_QWORD *)(a1 + 8) = nrsynth_create();
}
else
{
*(_QWORD *)(a1 + 8) = wtssynth_create();
}
}

original_code:
void soundmodule_chamber_init(soundmodule_chamber_t *c, int type){
  c->type = type;
  switch(type){
  case SOUNDMODULE_CHAMBER_TYPE_WTS:
    c->synth = wtssynth_create();
    break;
  case SOUNDMODULE_CHAMBER_TYPE_NR:
    c->synth = nrsynth_create();
    break;
  default:
    ;
  }
}

canonical_original_code:
void soundmodule_chamber_init(struct soundmodule_chamber_t *c, int type){
  c->type = type;
  switch(type){
  case SOUNDMODULE_CHAMBER_TYPE_WTS:
    c->synth = wtssynth_create();
    break;
  case SOUNDMODULE_CHAMBER_TYPE_NR:
    c->synth = nrsynth_create();
    break;
  default:
    ;
  }
}

variable_types: struct soundmodule_chamber_t { int type; void *synth; int is_muted; } *

variable_types: type int


decompiled_code:
void *soundmodule_create()
{
void *v0; // r12
__int64 v1; // rbp
int i; // ebx

v0 = malloc(0x180uLL);
memset(v0, 0, 0x180uLL);
v1 = (__int64)v0;
for ( i = 0; i != 16; ++i )
{
soundmodule_chamber_init(v1, i == 9);
v1 += 24LL;
}
return v0;
}

original_code:
soundmodule_t *soundmodule_create(){
  soundmodule_t *s;
  int i;
  s = (soundmodule_t *)malloc(sizeof(soundmodule_t));
  memset(s, 0, sizeof(soundmodule_t));
  for(i = 0; i < 16; i ++){
    soundmodule_chamber_init(&s->chambers[i],
        i != 9 ? SOUNDMODULE_CHAMBER_TYPE_WTS : SOUNDMODULE_CHAMBER_TYPE_NR);
  }
  return s;
}

canonical_original_code:
struct soundmodule_t *soundmodule_create(){
  struct soundmodule_t *s;
  int i;
  s = (struct soundmodule_t *)malloc(sizeof(soundmodule_t));
  memset(s, 0, sizeof(soundmodule_t));
  for(i = 0; i < 16; i ++){
    soundmodule_chamber_init(&s->chambers[i],
        i != 9 ? SOUNDMODULE_CHAMBER_TYPE_WTS : SOUNDMODULE_CHAMBER_TYPE_NR);
  }
  return s;
}

variable_types: struct soundmodule_t { struct soundmodule_chamber_t { int type; void *synth; int is_muted; } chambers[16]; } *

user_defined_types: struct soundmodule_t { struct soundmodule_chamber_t chambers[16]; }


decompiled_code:
void __fastcall soundmodule_destroy(void *ptr)
{
_QWORD *v1; // rbp
int i; // ebx

if ( ptr )
{
v1 = (char *)ptr + 8;
for ( i = 1; ; ++i )
{
if ( *v1 )
{
if ( i == 10 )
{
nrsynth_destroy();
goto LABEL_5;
}
wtssynth_destroy();
}
if ( i > 15 )
{
free(ptr);
return;
}
LABEL_5:
v1 += 3;
}
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
_QWORD *v1; // rbp
int i; // ebx

if ( ptr )
{
v1 = (char *)ptr + 8;
for ( i = 1; ; ++i )
{
if ( *v1 )
{
if ( i == 10 )
{
nrsynth_destroy();
goto LABEL_5;
}
wtssynth_destroy();
}
if ( i > 15 )
{
free(ptr);
return;
}
LABEL_5:
v1 += 3;
}
}
}

original_code:
void soundmodule_destroy(soundmodule_t *s){
  int i;
  if(s == ((void *)0)) return;
  for(i = 0; i < 16; i ++){
    if(s->chambers[i].synth == ((void *)0)) continue;
    if(i != 9){
      wtssynth_destroy(s->chambers[i].synth);
    }else{
      nrsynth_destroy(s->chambers[i].synth);
    }
  }
  free(s);
}

canonical_original_code:
void soundmodule_destroy(struct soundmodule_t *s){
  int i;
  if(s == ((void *)0)) return;
  for(i = 0; i < 16; i ++){
    if(s->chambers[i].synth == ((void *)0)) continue;
    if(i != 9){
      wtssynth_destroy(s->chambers[i].synth);
    }else{
      nrsynth_destroy(s->chambers[i].synth);
    }
  }
  free(s);
}

user_defined_types: struct soundmodule_chamber_t { int type; void *synth; int is_muted; }


decompiled_code:
__int64 __fastcall soundmodule_dispatch_midi(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rsi
unsigned int *v4; // rax
__int64 v5; // rdi

result = midifile_current_event(a2);
if ( !*(_DWORD *)(result + 8) )
{
v3 = result;
v4 = (unsigned int *)(a1 + 24LL * *(int *)(result + 12));
v5 = *((_QWORD *)v4 + 1);
result = *v4;
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
result = nrsynth_midi(v5, v3);
}
else
{
result = wtssynth_midi(v5, v3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rsi
unsigned int *v4; // rax
__int64 v5; // rdi

result = midifile_current_event(a2);
if ( !*(_DWORD *)(result + 8) )
{
v3 = result;
v4 = (unsigned int *)(a1 + 24LL * *(int *)(result + 12));
v5 = *((_QWORD *)v4 + 1);
result = *v4;
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
result = nrsynth_midi(v5, v3);
}
else
{
result = wtssynth_midi(v5, v3);
}
}
return result;
}

original_code:
void soundmodule_dispatch_midi(soundmodule_t *s, midifile_t *mf){
  void *synth;
  midievent_t *e = midifile_current_event(mf);
  if(e->is_meta){
    ;
  }else{
    synth = s->chambers[e->channel].synth;
    switch(s->chambers[e->channel].type){
    case SOUNDMODULE_CHAMBER_TYPE_WTS:
      wtssynth_midi(synth, e);
      break;
    case SOUNDMODULE_CHAMBER_TYPE_NR:
      nrsynth_midi(synth, e);
      break;
    default:
      ;
    }
  }
}

canonical_original_code:
void soundmodule_dispatch_midi(struct soundmodule_t *s, struct midifile_t *mf){
  void *synth;
  struct midievent_t *e = midifile_current_event(mf);
  if(e->is_meta){
    ;
  }else{
    synth = s->chambers[e->channel].synth;
    switch(s->chambers[e->channel].type){
    case SOUNDMODULE_CHAMBER_TYPE_WTS:
      wtssynth_midi(synth, e);
      break;
    case SOUNDMODULE_CHAMBER_TYPE_NR:
      nrsynth_midi(synth, e);
      break;
    default:
      ;
    }
  }
}

variable_types: struct midifile_t { int size; struct midievent_t { unsigned int absolute_time; unsigned int ticks; int is_meta; int channel; int type; int shortparam[4]; int longparam_size; char *longparam_char; int longparam_int; } **events; int current_index; int record_index; struct midiparam_t { unsigned int header_length; unsigned short format; unsigned short num_tracks; unsigned short deltatime; unsigned int track_length; unsigned int current_time; unsigned char command; unsigned char last_command; unsigned char channel; unsigned char last_channel; char author[129]; char title[129]; } midiparam; int tempo; int current_ticks; int verbose; } *

variable_types:
synth
void *

user_defined_types: struct midifile_t { int size; struct midievent_t **events; int current_index; int record_index; struct midiparam_t midiparam; int tempo; int current_ticks; int verbose; }


decompiled_code:
void __fastcall soundmodule_dispatch_wave(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rbx

v6 = a1;
do
{
if ( !*(_DWORD *)(v6 + 16) )
{
if ( *(_DWORD *)v6 )
{
if ( *(_DWORD *)v6 == 1 )
nrsynth_render(*(_QWORD *)(v6 + 8), a2, a3, a4);
}
else
{
wtssynth_render(*(_QWORD *)(v6 + 8), a2, a3, a4);
}
}
v6 += 24LL;
}
while ( v6 != a1 + 384 );
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rbx

v6 = a1;
do
{
if ( !*(_DWORD *)(v6 + 16) )
{
if ( *(_DWORD *)v6 )
{
if ( *(_DWORD *)v6 == 1 )
nrsynth_render(*(_QWORD *)(v6 + 8), a2, a3, a4);
}
else
{
wtssynth_render(*(_QWORD *)(v6 + 8), a2, a3, a4);
}
}
v6 += 24LL;
}
while ( v6 != a1 + 384 );
}

original_code:
void soundmodule_dispatch_wave(soundmodule_t *s, audiobuf_t *a, int current_bufpos, int length){
  int i;
  for(i = 0; i < 16; i ++){
    if(s->chambers[i].is_muted) continue;
    switch(s->chambers[i].type){
    case SOUNDMODULE_CHAMBER_TYPE_WTS:
      wtssynth_render(s->chambers[i].synth, a, current_bufpos, length);
      break;
    case SOUNDMODULE_CHAMBER_TYPE_NR:
      nrsynth_render(s->chambers[i].synth, a, current_bufpos, length);
      break;
    default:
      ;
    }
  }
}

canonical_original_code:
void soundmodule_dispatch_wave(struct soundmodule_t *s, struct audiobuf_t *a, int current_bufpos, int length){
  int i;
  for(i = 0; i < 16; i ++){
    if(s->chambers[i].is_muted) continue;
    switch(s->chambers[i].type){
    case SOUNDMODULE_CHAMBER_TYPE_WTS:
      wtssynth_render(s->chambers[i].synth, a, current_bufpos, length);
      break;
    case SOUNDMODULE_CHAMBER_TYPE_NR:
      nrsynth_render(s->chambers[i].synth, a, current_bufpos, length);
      break;
    default:
      ;
    }
  }
}

variable_types: struct audiobuf_t { int n_channels; int sampling_rate; int qbit; float **data; int *index; int size; } *

variable_types: length int


decompiled_code:
void __fastcall soundmodule_render(__int64 a1, __int64 a2, __int64 a3)
{
signed int i; // er13
signed int v5; // ebp

for ( i = 0; *(_DWORD *)(a2 + 32) > i; i += v5 )
{
while ( (unsigned int)midifile_has_waiting_event(a3) )
{
soundmodule_dispatch_midi(a1, a3);
midifile_next_event(a3);
}
v5 = midifile_get_nextevent_time(a3);
if ( v5 <= 0 || *(_DWORD *)(a2 + 32) - i < v5 )
v5 = *(_DWORD *)(a2 + 32) - i;
soundmodule_dispatch_wave(a1, a2, i, v5);
midifile_ticks_proceed(a3, (unsigned int)v5);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
signed int i; // er13
signed int v5; // ebp

for ( i = 0; *(_DWORD *)(a2 + 32) > i; i += v5 )
{
while ( (unsigned int)midifile_has_waiting_event(a3) )
{
func3(a1, a3);
midifile_next_event(a3);
}
v5 = midifile_get_nextevent_time(a3);
if ( v5 <= 0 || *(_DWORD *)(a2 + 32) - i < v5 )
v5 = *(_DWORD *)(a2 + 32) - i;
func4(a1, a2, i, v5);
midifile_ticks_proceed(a3, (unsigned int)v5);
}
}

original_code:
void soundmodule_render(soundmodule_t *s, audiobuf_t *a, midifile_t *mf){
  int samples_to_render;
  int current_bufpos = 0;
  while(current_bufpos < a->size){
    while(midifile_has_waiting_event(mf)){
      soundmodule_dispatch_midi(s, mf);
      midifile_next_event(mf);
    }
    samples_to_render = midifile_get_nextevent_time(mf);
    if(samples_to_render <= 0 ||
       a->size - current_bufpos < samples_to_render){
      samples_to_render = a->size - current_bufpos;
    }
    soundmodule_dispatch_wave(s, a, current_bufpos, samples_to_render);
    midifile_ticks_proceed(mf, samples_to_render);
    current_bufpos += samples_to_render;
  }
}

canonical_original_code:
void soundmodule_render(struct soundmodule_t *s, struct audiobuf_t *a, struct midifile_t *mf){
  int samples_to_render;
  int current_bufpos = 0;
  while(current_bufpos < a->size){
    while(midifile_has_waiting_event(mf)){
      soundmodule_dispatch_midi(s, mf);
      midifile_next_event(mf);
    }
    samples_to_render = midifile_get_nextevent_time(mf);
    if(samples_to_render <= 0 ||
       a->size - current_bufpos < samples_to_render){
      samples_to_render = a->size - current_bufpos;
    }
    soundmodule_dispatch_wave(s, a, current_bufpos, samples_to_render);
    midifile_ticks_proceed(mf, samples_to_render);
    current_bufpos += samples_to_render;
  }
}

user_defined_types: struct midiparam_t { unsigned int header_length; unsigned short format; unsigned short num_tracks; unsigned short deltatime; unsigned int track_length; unsigned int current_time; unsigned char command; unsigned char last_command; unsigned char channel; unsigned char last_channel; char author[129]; char title[129]; }

user_defined_types: struct midievent_t { unsigned int absolute_time; unsigned int ticks; int is_meta; int channel; int type; int shortparam[4]; int longparam_size; char *longparam_char; int longparam_int; }


decompiled_code:
_BOOL8 __fastcall soundmodule_is_muted(__int64 a1, int a2)
{
return *(_DWORD *)(a1 + 24LL * a2 + 16) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, int a2)
{
return *(_DWORD *)(a1 + 24LL * a2 + 16) == 1;
}

original_code:
int soundmodule_is_muted(soundmodule_t *s, int channel){
  return s->chambers[channel].is_muted == 1;
}

canonical_original_code:
int soundmodule_is_muted(struct soundmodule_t *s, int channel){
  return s->chambers[channel].is_muted == 1;
}

variable_types: channel int

return_type: int


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

*(_DWORD *)(a1 + 24LL * a2 + 16) = 0;
result = a1 + 24LL * a2;
if ( !*(_DWORD *)result )
result = wtssynth_all_note_off(*(_QWORD *)(result + 8));
return result;
}

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

*(_DWORD *)(a1 + 24LL * a2 + 16) = 0;
result = a1 + 24LL * a2;
if ( !*(_DWORD *)result )
result = wtssynth_all_note_off(*(_QWORD *)(result + 8));
return result;
}

original_code:
void soundmodule_unmute(soundmodule_t *s, int channel){
  void *synth;
  s->chambers[channel].is_muted = 0;
  synth = s->chambers[channel].synth;
  switch(s->chambers[channel].type){
  case SOUNDMODULE_CHAMBER_TYPE_WTS:
    return wtssynth_all_note_off(synth);
  case SOUNDMODULE_CHAMBER_TYPE_NR:
    return ;
  default:
    return ;
  }
}

canonical_original_code:
void soundmodule_unmute(struct soundmodule_t *s, int channel){
  void *synth;
  s->chambers[channel].is_muted = 0;
  synth = s->chambers[channel].synth;
  switch(s->chambers[channel].type){
  case SOUNDMODULE_CHAMBER_TYPE_WTS:
    return wtssynth_all_note_off(synth);
  case SOUNDMODULE_CHAMBER_TYPE_NR:
    return ;
  default:
    return ;
  }
}


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

v2 = a1;
do
{
if ( !*(_DWORD *)v2 )
result = wtssynth_midi_key(*(_QWORD *)(v2 + 8), a2);
v2 += 24LL;
}
while ( v2 != a1 + 384 );
return result;
}

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

v2 = a1;
do
{
if ( !*(_DWORD *)v2 )
result = wtssynth_midi_key(*(_QWORD *)(v2 + 8), a2);
v2 += 24LL;
}
while ( v2 != a1 + 384 );
return result;
}

original_code:
void soundmodule_midi_key(soundmodule_t *s, int midi_key){
  int i;
  void *synth;
  for(i = 0; i < 16; i ++){
    synth = s->chambers[i].synth;
    switch(s->chambers[i].type){
    case SOUNDMODULE_CHAMBER_TYPE_WTS:
      wtssynth_midi_key(synth, midi_key);
      break;
    case SOUNDMODULE_CHAMBER_TYPE_NR:
      break;
    default:
      ;
    }
  }
}

canonical_original_code:
void soundmodule_midi_key(struct soundmodule_t *s, int midi_key){
  int i;
  void *synth;
  for(i = 0; i < 16; i ++){
    synth = s->chambers[i].synth;
    switch(s->chambers[i].type){
    case SOUNDMODULE_CHAMBER_TYPE_WTS:
      wtssynth_midi_key(synth, midi_key);
      break;
    case SOUNDMODULE_CHAMBER_TYPE_NR:
      break;
    default:
      ;
    }
  }
}

variable_types: i int


decompiled_code:
__int64 __fastcall soundmodule_get_current_key(__int64 a1, int a2, unsigned int a3)
{
int *v3; // rax
__int64 v4; // rdi
int v5; // eax

v3 = (int *)(a1 + 24LL * a2);
v4 = *((_QWORD *)v3 + 1);
v5 = *v3;
if ( !v5 )
return wtssynth_get_current_key(v4, a3);
if ( v5 == 1 )
return nrsynth_get_current_key(v4, a3);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, unsigned int a3)
{
int *v3; // rax
__int64 v4; // rdi
int v5; // eax

v3 = (int *)(a1 + 24LL * a2);
v4 = *((_QWORD *)v3 + 1);
v5 = *v3;
if ( !v5 )
return wtssynth_get_current_key(v4, a3);
if ( v5 == 1 )
return nrsynth_get_current_key(v4, a3);
return 0xFFFFFFFFLL;
}

original_code:
int soundmodule_get_current_key(soundmodule_t *s, int channel, int voice_index){
  void *synth;
  synth = s->chambers[channel].synth;
  switch(s->chambers[channel].type){
  case SOUNDMODULE_CHAMBER_TYPE_WTS:
    return wtssynth_get_current_key(synth, voice_index);
  case SOUNDMODULE_CHAMBER_TYPE_NR:
    return nrsynth_get_current_key(synth, voice_index);
  default:
    return -1;
  }
}

canonical_original_code:
int soundmodule_get_current_key(struct soundmodule_t *s, int channel, int voice_index){
  void *synth;
  synth = s->chambers[channel].synth;
  switch(s->chambers[channel].type){
  case SOUNDMODULE_CHAMBER_TYPE_WTS:
    return wtssynth_get_current_key(synth, voice_index);
  case SOUNDMODULE_CHAMBER_TYPE_NR:
    return nrsynth_get_current_key(synth, voice_index);
  default:
    return -1;
  }
}


decompiled_code:
__int64 __fastcall soundmodule_is_key_offing(__int64 a1, int a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = a1 + 24LL * a2;
result = 0LL;
if ( !*(_DWORD *)v3 )
result = wtssynth_is_key_offing(*(_QWORD *)(v3 + 8), a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = a1 + 24LL * a2;
result = 0LL;
if ( !*(_DWORD *)v3 )
result = wtssynth_is_key_offing(*(_QWORD *)(v3 + 8), a3);
return result;
}

original_code:
int soundmodule_is_key_offing(soundmodule_t *s, int channel, int voice_index){
  void *synth;
  synth = s->chambers[channel].synth;
  switch(s->chambers[channel].type){
  case SOUNDMODULE_CHAMBER_TYPE_WTS:
    return wtssynth_is_key_offing(synth, voice_index);
  case SOUNDMODULE_CHAMBER_TYPE_NR:
    return 0;
  default:
    return 0;
    ;
  }
}

canonical_original_code:
int soundmodule_is_key_offing(struct soundmodule_t *s, int channel, int voice_index){
  void *synth;
  synth = s->chambers[channel].synth;
  switch(s->chambers[channel].type){
  case SOUNDMODULE_CHAMBER_TYPE_WTS:
    return wtssynth_is_key_offing(synth, voice_index);
  case SOUNDMODULE_CHAMBER_TYPE_NR:
    return 0;
  default:
    return 0;
    ;
  }
}


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

v2 = a1 + 24LL * a2;
result = 0LL;
if ( !*(_DWORD *)v2 )
result = wtssynth_get_program(*(_QWORD *)(v2 + 8));
return result;
}

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

v2 = a1 + 24LL * a2;
result = 0LL;
if ( !*(_DWORD *)v2 )
result = wtssynth_get_program(*(_QWORD *)(v2 + 8));
return result;
}

original_code:
int soundmodule_get_program(soundmodule_t *s, int channel){
  void *synth;
  synth = s->chambers[channel].synth;
  switch(s->chambers[channel].type){
  case SOUNDMODULE_CHAMBER_TYPE_WTS:
    return wtssynth_get_program(synth);
  case SOUNDMODULE_CHAMBER_TYPE_NR:
    return 0;
  default:
    return 0;
  }
}

canonical_original_code:
int soundmodule_get_program(struct soundmodule_t *s, int channel){
  void *synth;
  synth = s->chambers[channel].synth;
  switch(s->chambers[channel].type){
  case SOUNDMODULE_CHAMBER_TYPE_WTS:
    return wtssynth_get_program(synth);
  case SOUNDMODULE_CHAMBER_TYPE_NR:
    return 0;
  default:
    return 0;
  }
}


decompiled_code:
void __fastcall xor128_init(__int64 a1)
{
v = a1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
v = a1;
}

original_code: void xor128_init(unsigned long s){v[0] = s;}

variable_types:
s
unsigned long


decompiled_code:
unsigned __int64 xor128()
{
unsigned __int64 v0; // rdx
unsigned __int64 result; // rax

v0 = v ^ (v << 11);
v = qword_128;
qword_128 = qword_130;
qword_130 = qword_138;
result = (v0 >> 8) ^ v0 ^ qword_138 ^ ((unsigned __int64)qword_138 >> 19);
qword_138 = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 func1()
{
unsigned __int64 v0; // rdx
unsigned __int64 result; // rax

v0 = v ^ (v << 11);
v = qword_128;
qword_128 = qword_130;
qword_130 = qword_138;
result = (v0 >> 8) ^ v0 ^ qword_138 ^ ((unsigned __int64)qword_138 >> 19);
qword_138 = result;
return result;
}

variable_types:
t
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall midievent_destroy(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 5);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 5);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void midievent_destroy(midievent_t *e){
  if(e->longparam_char != ((void *)0)){
    free(e->longparam_char);
  }
  free(e);
}

canonical_original_code:
void midievent_destroy(struct midievent_t *e){
  if(e->longparam_char != ((void *)0)){
    free(e->longparam_char);
  }
  free(e);
}

variable_types: struct midievent_t { unsigned int absolute_time; unsigned int ticks; int is_meta; int channel; int type; int shortparam[4]; int longparam_size; char *longparam_char; int longparam_int; } *


decompiled_code:
int __fastcall midievent_dump(unsigned int *a1)
{
int result; // eax

if ( a1[2] )
result = printf(" %010d %010d [%02d]: Long %02x %d\n", *a1, a1[1], a1[3], a1[4], a1[12]);
else
result = printf(
" Ticks[%010d] Ch[%02d]: Type[%02x] Param[%d %d %d %d]\n",
*a1,
a1[3],
a1[4],
a1[5],
a1[6],
a1[7],
a1[8]);
return result;
}

original_code:
void midievent_dump(midievent_t *e){
  if(e->is_meta == 0){
    printf("    Ticks[%010d] Ch[%02d]: Type[%02x] Param[%d %d %d %d]\n",
    e->absolute_time, e->channel, e->type,
    e->shortparam[0], e->shortparam[1], e->shortparam[2], e->shortparam[3]);
  }else{
    printf(" %010d %010d [%02d]: Long  %02x %d\n",
    e->absolute_time, e->ticks, e->channel, e->type, e->longparam_int);
  }
}

canonical_original_code:
void midievent_dump(struct midievent_t *e){
  if(e->is_meta == 0){
    printf("    Ticks[%010d] Ch[%02d]: Type[%02x] Param[%d %d %d %d]\n",
    e->absolute_time, e->channel, e->type,
    e->shortparam[0], e->shortparam[1], e->shortparam[2], e->shortparam[3]);
  }else{
    printf(" %010d %010d [%02d]: Long  %02x %d\n",
    e->absolute_time, e->ticks, e->channel, e->type, e->longparam_int);
  }
}


decompiled_code:
__int64 __fastcall midievent_compare(_DWORD **a1, _DWORD **a2)
{
return (unsigned int)(**a1 - **a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD **a1, _DWORD **a2)
{
return (unsigned int)(**a1 - **a2);
}

original_code:
int midievent_compare(const void *p, const void *q){
  midievent_t **_p = (midievent_t **)p;
  midievent_t **_q = (midievent_t **)q;
  return (*_p)->absolute_time - (*_q)->absolute_time;
}

canonical_original_code:
int midievent_compare(void *p, void *q){
  struct midievent_t **_p = (midievent_t **)p;
  struct midievent_t **_q = (midievent_t **)q;
  return (*_p)->absolute_time - (*_q)->absolute_time;
}

variable_types:
p
void *

variable_types:
q
void *

variable_types: struct midievent_t { unsigned int absolute_time; unsigned int ticks; int is_meta; int channel; int type; int shortparam[4]; int longparam_size; char *longparam_char; int longparam_int; } **


GCMFileEntryStructToRaw

repo: sadistech/gcmtool

original_code:
void GCMFileEntryStructToRaw(GCMFileEntryStruct *e, char *buf) {
 if (!e || !buf) return;
 bzero(buf, 0x000c);
 char *start = buf;
 if (e->isDir) {
  buf[0] = 1;
 }
 *buf++;
 u32 *tempFilenameOffset = (u32*)malloc(sizeof(u32));
 *tempFilenameOffset = (e->filenameOffset << 8);
 memcpy(buf, tempFilenameOffset, 3);
 buf += 3;
 u32 *offset = (u32*)malloc(sizeof(u32));
 *offset = htonl(e->offset);
 memcpy(buf, offset, sizeof(u32));
 buf += sizeof(u32);
 u32 *length = (u32*)malloc(sizeof(u32));
 *length = htonl(e->length);
 memcpy(buf, length, sizeof(u32));
 buf += sizeof(u32);
 buf = start;
}

canonical_original_code:
void GCMFileEntryStructToRaw(struct gcm_file_entry_struct *e, char *buf) {
 if (!e || !buf) return;
 bzero(buf, 0x000c);
 char *start = buf;
 if (e->isDir) {
  buf[0] = 1;
 }
 *buf++;
 unsigned long *tempFilenameOffset = (u32*)malloc(sizeof(u32));
 *tempFilenameOffset = (e->filenameOffset << 8);
 memcpy(buf, tempFilenameOffset, 3);
 buf += 3;
 unsigned long *offset = (u32*)malloc(sizeof(u32));
 *offset = htonl(e->offset);
 memcpy(buf, offset, sizeof(u32));
 buf += sizeof(u32);
 unsigned long *length = (u32*)malloc(sizeof(u32));
 *length = htonl(e->length);
 memcpy(buf, length, sizeof(u32));
 buf += sizeof(u32);
 buf = start;
}

variable_types: struct gcm_file_entry_struct { int index; char isDir; unsigned long filenameOffset; unsigned long offset; unsigned long length; char *data; char *filename; } *

variable_types:
buf
char *

variable_types:
start
char *

variable_types:
tempFilenameOffset
unsigned long *

variable_types:
offset
unsigned long *

variable_types:
length
unsigned long *


GCMFreeFileEntryStruct

decompiled_code:
void __fastcall GCMFreeFileEntryStruct(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
void GCMFreeFileEntryStruct(GCMFileEntryStruct *fe) {
 if (!fe) return;
 if (fe->data != ((void *)0))
  free(fe->data);
 if (fe->filename != ((void *)0))
  free(fe->filename);
 free(fe);
}

canonical_original_code:
void GCMFreeFileEntryStruct(struct gcm_file_entry_struct *fe) {
 if (!fe) return;
 if (fe->data != ((void *)0))
  free(fe->data);
 if (fe->filename != ((void *)0))
  free(fe->filename);
 free(fe);
}

user_defined_types: struct gcm_file_entry_struct { int index; char isDir; unsigned long filenameOffset; unsigned long offset; unsigned long length; char *data; char *filename; }


printBnrInfo

decompiled_code:
int __fastcall printBnrInfo(const char *a1)
{
printf("Name: %s\n", a1);
printf("Developer: %s\n", a1 + 32);
printf("Full Name: %s\n", a1 + 64);
printf("Full Developer: %s\n", a1 + 128);
return printf("Description: %s\n", a1 + 192);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
printf("Name: %s\n", a1);
printf("Developer: %s\n", a1 + 32);
printf("Full Name: %s\n", a1 + 64);
printf("Full Developer: %s\n", a1 + 128);
return printf("Description: %s\n", a1 + 192);
}

original_code:
void printBnrInfo(GCMBnrInfoStruct *r) {
 printf("Name:           %s\n", r->name);
 printf("Developer:      %s\n", r->developer);
 printf("Full Name:      %s\n", r->fullName);
 printf("Full Developer: %s\n", r->fullDeveloper);
 printf("Description:    %s\n", r->description);
}

canonical_original_code:
void printBnrInfo(struct gcm_bnr_info_record_struct *r) {
 printf("Name:           %s\n", r->name);
 printf("Developer:      %s\n", r->developer);
 printf("Full Name:      %s\n", r->fullName);
 printf("Full Developer: %s\n", r->fullDeveloper);
 printf("Description:    %s\n", r->description);
}

variable_types: struct gcm_bnr_info_record_struct { char name[32]; char developer[32]; char fullName[64]; char fullDeveloper[64]; char description[128]; struct gcm_bnr_info_record_struct *next; } *


printBnr

decompiled_code:
int __fastcall printBnr(char *a1)
{
__int64 v1; // rbx
int result; // eax
unsigned int v3; // eax

printf("Version: %c\n", (unsigned int)*a1);
if ( (int)GCMBnrInfoCount(*((_QWORD *)a1 + 769)) > 1 )
{
v3 = GCMBnrInfoCount(*((_QWORD *)a1 + 769));
printf(" Count: %d\n", v3);
putchar(10);
}
v1 = *((_QWORD *)a1 + 769);
do
{
printBnrInfo((const char *)v1);
result = putchar(10);
v1 = *(_QWORD *)(v1 + 320);
}
while ( v1 );
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *a1)
{
__int64 v1; // rbx
int result; // eax
unsigned int v3; // eax

printf("Version: %c\n", (unsigned int)*a1);
if ( (int)GCMBnrInfoCount(*((_QWORD *)a1 + 769)) > 1 )
{
v3 = GCMBnrInfoCount(*((_QWORD *)a1 + 769));
printf(" Count: %d\n", v3);
putchar(10);
}
v1 = *((_QWORD *)a1 + 769);
do
{
func0((const char *)v1);
result = putchar(10);
v1 = *(_QWORD *)(v1 + 320);
}
while ( v1 );
return result;
}

original_code:
void printBnr(GCMBnrStruct *b) {
 printf("Version:        %c\n", b->version);
 if (GCMBnrInfoCount(b->info) > 1) {
  printf(" Count:   %d\n", GCMBnrInfoCount(b->info));
  printf("\n");
 }
 GCMBnrInfoStruct *info = b->info;
 do {
  printBnrInfo(info);
  printf("\n");
 } while (info = info->next);
}

canonical_original_code:
void printBnr(struct gcm_bnr_struct *b) {
 printf("Version:        %c\n", b->version);
 if (GCMBnrInfoCount(b->info) > 1) {
  printf(" Count:   %d\n", GCMBnrInfoCount(b->info));
  printf("\n");
 }
 struct gcm_bnr_info_record_struct *info = b->info;
 do {
  printBnrInfo(info);
  printf("\n");
 } while (info = info->next);
}

variable_types: struct gcm_bnr_struct { char version; char graphic[6144]; struct gcm_bnr_info_record_struct { char name[32]; char developer[32]; char fullName[64]; char fullDeveloper[64]; char description[128]; struct gcm_bnr_info_record_struct *next; } *info; } *

user_defined_types: struct gcm_bnr_struct { char version; char graphic[6144]; struct gcm_bnr_info_record_struct *info; }


openBnr

decompiled_code:
FILE *openBnr()
{
FILE *result; // rax

result = fopen(filename, "r+");
bnrFile = result;
if ( !result )
{
printf("Error opening %s\n", filename);
exit(1);
}
return result;
}

canonical_decompiled_code:
FILE *func2()
{
FILE *result; // rax

result = fopen(filename, "r+");
bnrFile = result;
if ( !result )
{
printf("Error opening %s\n", filename);
exit(1);
}
return result;
}

original_code:
void openBnr() {
 if (!(bnrFile = fopen(filename, "r+"))) {
  printf("Error opening %s\n", filename);
  exit(1);
 }
}


closeBnr

decompiled_code:
int closeBnr()
{
return fclose(bnrFile);
}

canonical_decompiled_code:
int func3()
{
return fclose(bnrFile);
}

original_code:
void closeBnr() {
 fclose(bnrFile);
}

canonical_original_code:
void closeBnr() {
 fclose(bnrFile);
}


printUsage

decompiled_code:
int printUsage()
{
printf("gcmbnrtool %s- Utility for working with .bnr files from GameCube DVD Images (GCMs)\n", "0.3.3d");
puts("http://gcmtool.sourceforge.net\n");
printf("Usage:\t");
puts("gcmbnrtool [options] <bnr_file>\n");
return puts("Use -? to view extended usage.\n");
}

canonical_decompiled_code:
int func4()
{
printf("gcmbnrtool %s- Utility for working with .bnr files from GameCube DVD Images (GCMs)\n", "0.3.3d");
puts("http://gcmtool.sourceforge.net\n");
printf("Usage:\t");
puts("gcmbnrtool [options] <bnr_file>\n");
return puts("Use -? to view extended usage.\n");
}

original_code:
void printUsage() {
 printf("gcmbnrtool %s- Utility for working with .bnr files from GameCube DVD Images (GCMs)\n", "0.3.3d");
 printf("http://gcmtool.sourceforge.net\n\n");
 printf("Usage:\t");
 printf("gcmbnrtool [options] <bnr_file>\n\n");
 printf("Use -? to view extended usage.\n\n");
}


printExtendedUsage

decompiled_code:
int printExtendedUsage()
{
printUsage();
printf("\t\x1B[1m-?%s--help \x1B[m\n\t\tDisplays this help.\n\n", ", ");
printf(
"\t\x1B[1m-i%s--icon [ -raw | -ppm ] <pathname>\x1B[m\n"
"\t\tSets the icon from <pathname> and injects it into the bnr. -raw is the default\n"
"\n",
", ");
printf(
"\t\x1B[1m-e%s--extract-icon [ -raw | -ppm ] <pathname>\x1B[m\n"
"\t\tExtracts the icon from the bnr in the desired format. -raw is the default\n"
"\n",
", ");
printf("\t\x1B[1m-m%s--modify-nth <index>\x1B[m\n\t\tModify the nth record (only for multi-lingual BNRs)\n\n", ", ");
printf("When editing BNR2s, you must use %s to declare which field you'd like to edit.\n", "-m");
printf("\t\x1B[1m-n%s--name <name>\x1B[m\n\t\tSets the name field to <name>\n\n", ", ");
printf("\t\x1B[1m-d%s--developer <developer>\x1B[m\n\t\tSets the developer field to <developer>\n\n", ", ");
printf("\t\x1B[1m-N%s--full-name <full_name>\x1B[m\n\t\tSets the full name field to <full_name>\n\n", ", ");
printf(
"\t\x1B[1m-D%s--full-developer <full_developer>\x1B[m\n\t\tSets the full developer field to <full_developer>\n\n",
", ");
return printf(
"\t\x1B[1m-s%s--description <full_description>\x1B[m\n"
"\t\tSets the description field to <full_description>\n"
"\n",
", ");
}

canonical_decompiled_code:
int func5()
{
func4();
printf("\t\x1B[1m-?%s--help \x1B[m\n\t\tDisplays this help.\n\n", ", ");
printf(
"\t\x1B[1m-i%s--icon [ -raw | -ppm ] <pathname>\x1B[m\n"
"\t\tSets the icon from <pathname> and injects it into the bnr. -raw is the default\n"
"\n",
", ");
printf(
"\t\x1B[1m-e%s--extract-icon [ -raw | -ppm ] <pathname>\x1B[m\n"
"\t\tExtracts the icon from the bnr in the desired format. -raw is the default\n"
"\n",
", ");
printf("\t\x1B[1m-m%s--modify-nth <index>\x1B[m\n\t\tModify the nth record (only for multi-lingual BNRs)\n\n", ", ");
printf("When editing BNR2s, you must use %s to declare which field you'd like to edit.\n", "-m");
printf("\t\x1B[1m-n%s--name <name>\x1B[m\n\t\tSets the name field to <name>\n\n", ", ");
printf("\t\x1B[1m-d%s--developer <developer>\x1B[m\n\t\tSets the developer field to <developer>\n\n", ", ");
printf("\t\x1B[1m-N%s--full-name <full_name>\x1B[m\n\t\tSets the full name field to <full_name>\n\n", ", ");
printf(
"\t\x1B[1m-D%s--full-developer <full_developer>\x1B[m\n\t\tSets the full developer field to <full_developer>\n\n",
", ");
return printf(
"\t\x1B[1m-s%s--description <full_description>\x1B[m\n"
"\t\tSets the description field to <full_description>\n"
"\n",
", ");
}

original_code:
void printExtendedUsage() {
 printUsage();
 printf("\t\033[1m" "-?" "%s" "--help" " " "" "\033[m\n\t\t" "Displays this help." "\n\n", strcmp("", "--help") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-i" "%s" "--icon" " " "[ " "-raw" " | " "-ppm" " ] <pathname>" "\033[m\n\t\t" "Sets the icon from <pathname> and injects it into the bnr. " "-raw" " is the default" "\n\n", strcmp("", "--icon") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-e" "%s" "--extract-icon" " " "[ " "-raw" " | " "-ppm" " ] <pathname>" "\033[m\n\t\t" "Extracts the icon from the bnr in the desired format. " "-raw" " is the default" "\n\n", strcmp("", "--extract-icon") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-m" "%s" "--modify-nth" " " "<index>" "\033[m\n\t\t" "Modify the nth record (only for multi-lingual BNRs)" "\n\n", strcmp("", "--modify-nth") == 0 ? "" : ", ");;
 printf("When editing BNR2s, you must use %s to declare which field you'd like to edit.\n", "-m");
 printf("\t\033[1m" "-n" "%s" "--name" " " "<name>" "\033[m\n\t\t" "Sets the name field to <name>" "\n\n", strcmp("", "--name") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-d" "%s" "--developer" " " "<developer>" "\033[m\n\t\t" "Sets the developer field to <developer>" "\n\n", strcmp("", "--developer") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-N" "%s" "--full-name" " " "<full_name>" "\033[m\n\t\t" "Sets the full name field to <full_name>" "\n\n", strcmp("", "--full-name") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-D" "%s" "--full-developer" " " "<full_developer>" "\033[m\n\t\t" "Sets the full developer field to <full_developer>" "\n\n", strcmp("", "--full-developer") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-s" "%s" "--description" " " "<full_description>" "\033[m\n\t\t" "Sets the description field to <full_description>" "\n\n", strcmp("", "--description") == 0 ? "" : ", ");;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // er12
const char *v5; // r15
const char *v6; // r14
int v7; // eax
const char *v8; // rbx
bool v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rsi
__int64 v13; // rcx
const char *v14; // rdi
char v15; // al
bool v16; // cf
bool v17; // zf
__int64 v18; // rcx
const char *v19; // rdi
char v20; // al
bool v21; // cf
bool v22; // zf
const char **v23; // r13
__int64 v24; // rcx
const char *v25; // rdi
char v26; // al
bool v27; // cf
bool v28; // zf
__int64 v29; // rcx
const char *v30; // rdi
char v31; // al
bool v32; // cf
bool v33; // zf
const char *v34; // rax
__int64 v35; // rcx
const char *v36; // rdi
char v37; // al
bool v38; // cf
bool v39; // zf
__int64 v40; // rcx
const char *v41; // rdi
char v42; // al
bool v43; // cf
bool v44; // zf
const char *v45; // rax
__int64 v46; // rcx
const char *v47; // rdi
const char *v48; // rax
const char *v49; // rax
const char *v50; // rax
const char *v51; // rbx
const char *v52; // rbx
size_t v53; // rbx
void *v54; // rbp
char *v55; // rax
char *v56; // rbx
char *v57; // rbp
int v58; // er12
__int64 v59; // rcx
char *v60; // rdi
__int64 v61; // rcx
_DWORD *v62; // rdi
__int64 v63; // rcx
_DWORD *v64; // rdi
__int64 v65; // rcx
_DWORD *v66; // rdi
char *v67; // rbp
__int64 v68; // rcx
char *v69; // rdi
void *v70; // rbp
__int64 v71; // rsi
size_t v72; // rbp
void *v73; // rax
void *v74; // r12
char *v75; // rbp
size_t v76; // rbp
void *v77; // r12
char *src; // [rsp+0h] [rbp-68h]
const char *v80; // [rsp+8h] [rbp-60h]
char *v81; // [rsp+10h] [rbp-58h]
char *v82; // [rsp+18h] [rbp-50h]
char *v83; // [rsp+20h] [rbp-48h]
int v84; // [rsp+28h] [rbp-40h]
int v85; // [rsp+2Ch] [rbp-3Ch]

v85 = 0;
v84 = 0;
v4 = 0;
v5 = 0LL;
v80 = 0LL;
v83 = 0LL;
v82 = 0LL;
v81 = 0LL;
src = 0LL;
v6 = 0LL;
while ( 1 )
{
v8 = argv[1];
if ( !v8 )
{
printUsage();
exit(1);
}
if ( !strcmp("-?", argv[1]) || (v9 = strcmp("--help", argv[1]) != 0, v10 = 0, v11 = !v9) )
{
printExtendedUsage();
exit(1);
}
v12 = "-m";
v13 = 3LL;
v14 = argv[1];
do
{
if ( !v13 )
break;
v10 = *v12 < (unsigned int)*v14;
v11 = *v12++ == *v14++;
--v13;
}
while ( v11 );
v15 = (!v10 && !v11) - v10;
v16 = 0;
v17 = v15 == 0;
if ( !v15 )
goto LABEL_4;
v12 = "--modify-nth";
v18 = 13LL;
v19 = argv[1];
do
{
if ( !v18 )
break;
v16 = *v12 < (unsigned int)*v19;
v17 = *v12++ == *v19++;
--v18;
}
while ( v17 );
v20 = (!v16 && !v17) - v16;
v21 = 0;
v22 = v20 == 0;
if ( !v20 )
{
LABEL_4:
v7 = atoi(argv[2]);
v4 = v7;
if ( v7 <= 0 )
{
printf(" index is out of bounds! (%d)\n", (unsigned int)v7);
exit(1);
}
argv += 2;
goto LABEL_6;
}
v23 = argv + 1;
v12 = "-n";
v24 = 3LL;
v25 = argv[1];
do
{
if ( !v24 )
break;
v21 = *v12 < (unsigned int)*v25;
v22 = *v12++ == *v25++;
--v24;
}
while ( v22 );
v26 = (!v21 && !v22) - v21;
v27 = 0;
v28 = v26 == 0;
if ( v26 )
{
v12 = "--name";
v29 = 7LL;
v30 = argv[1];
do
{
if ( !v29 )
break;
v27 = *v12 < (unsigned int)*v30;
v28 = *v12++ == *v30++;
--v29;
}
while ( v28 );
v31 = (!v27 && !v28) - v27;
v32 = 0;
v33 = v31 == 0;
if ( v31 )
break;
}
v34 = argv[2];
if ( v34 )
{
argv += 2;
v6 = v34;
}
else
{
++argv;
}
LABEL_6:
if ( !*argv )
goto LABEL_73;
}
v12 = "-d";
v35 = 3LL;
v36 = argv[1];
do
{
if ( !v35 )
break;
v32 = *v12 < (unsigned int)*v36;
v33 = *v12++ == *v36++;
--v35;
}
while ( v33 );
v37 = (!v32 && !v33) - v32;
v38 = 0;
v39 = v37 == 0;
if ( !v37 )
goto LABEL_37;
v12 = "--developer";
v40 = 12LL;
v41 = argv[1];
do
{
if ( !v40 )
break;
v38 = *v12 < (unsigned int)*v41;
v39 = *v12++ == *v41++;
--v40;
}
while ( v39 );
v42 = (!v38 && !v39) - v38;
v43 = 0;
v44 = v42 == 0;
if ( !v42 )
{
LABEL_37:
v45 = argv[2];
if ( v45 )
{
argv += 2;
src = (char *)v45;
}
else
{
++argv;
}
goto LABEL_6;
}
v12 = "-N";
v46 = 3LL;
v47 = argv[1];
do
{
if ( !v46 )
break;
v43 = *v12 < (unsigned int)*v47;
v44 = *v12++ == *v47++;
--v46;
}
while ( v44 );
if ( (!v43 && !v44) == v43 || (v12 = argv[1], !strcmp("--full-name", v12)) )
{
v48 = argv[2];
if ( v48 )
{
argv += 2;
v81 = (char *)v48;
}
else
{
++argv;
}
goto LABEL_6;
}
v12 = v8;
if ( !strcmp("-D", v8) || (v12 = v8, !strcmp("--full-developer", v8)) )
{
v49 = argv[2];
if ( v49 )
{
argv += 2;
v82 = (char *)v49;
}
else
{
++argv;
}
goto LABEL_6;
}
v12 = v8;
if ( !strcmp("-s", v8) || (v12 = v8, !strcmp("--description", v8)) )
{
v50 = argv[2];
if ( v50 )
{
argv += 2;
v83 = (char *)v50;
}
else
{
++argv;
}
goto LABEL_6;
}
v12 = v8;
if ( !strcmp("-e", v8) || (v12 = v8, !strcmp("--extract-icon", v8)) )
{
v51 = argv[2];
if ( v51 )
{
v12 = "-raw";
if ( !strcmp(argv[2], "-raw") )
{
v23 = argv + 2;
v84 = 0;
}
else
{
v12 = "-ppm";
if ( !strcmp(v51, "-ppm") )
{
v23 = argv + 2;
v84 = 1;
}
}
if ( v23[1] )
{
argv = v23 + 1;
v80 = v23[1];
}
else
{
argv = v23;
}
}
else
{
++argv;
}
goto LABEL_6;
}
v12 = v8;
if ( !strcmp("-i", v8) || (v12 = v8, !strcmp("--icon", v8)) )
{
v52 = argv[2];
if ( v52 )
{
v12 = "-raw";
if ( !strcmp(argv[2], "-raw") )
{
v23 = argv + 2;
v85 = 0;
}
else
{
v12 = "-ppm";
if ( !strcmp(v52, "-ppm") )
{
v23 = argv + 2;
v85 = 1;
}
}
if ( v23[1] )
{
argv = v23 + 1;
v5 = v23[1];
}
else
{
argv = v23;
}
}
else
{
++argv;
}
goto LABEL_6;
}
filename = (char *)v8;
LABEL_73:
openBnr();
v53 = GetFilesizeFromStream(bnrFile, v12);
v54 = malloc(v53);
if ( ReadDataFromFile(v54, filename) != v53 )
{
perror(filename);
exit(1);
}
v55 = (char *)GCMRawBnrToStruct(v54, (unsigned int)v53);
v56 = v55;
if ( !v55 )
{
puts("error opening banner!");
exit(1);
}
printBnr(v55);
if ( *v56 == 49 )
v57 = (char *)*((_QWORD *)v56 + 769);
else
v57 = (char *)GCMBnrGetNthInfo(*((_QWORD *)v56 + 769), (unsigned int)(v4 - 1));
if ( !v57 )
{
puts("ERROR! mod == NULL (this shouldn't happen!)");
exit(1);
}
v58 = 0;
if ( v6 )
{
v59 = 8LL;
v60 = v57;
while ( v59 )
{
*(_DWORD *)v60 = 0;
v60 += 4;
--v59;
}
strcpy(v57, v6);
v58 = 1;
}
if ( src )
{
v61 = 8LL;
v62 = v57 + 32;
while ( v61 )
{
*v62++ = 0;
--v61;
}
strcpy(v57 + 32, src);
v58 = 1;
}
if ( v81 )
{
v63 = 16LL;
v64 = v57 + 64;
while ( v63 )
{
*v64++ = 0;
--v63;
}
strcpy(v57 + 64, v81);
v58 = 1;
}
if ( v82 )
{
v65 = 16LL;
v66 = v57 + 128;
while ( v65 )
{
*v66++ = 0;
--v65;
}
strcpy(v57 + 128, v82);
v58 = 1;
}
if ( v83 )
{
v67 = v57 + 192;
v68 = 32LL;
v69 = v67;
while ( v68 )
{
*(_DWORD *)v69 = 0;
v69 += 4;
--v68;
}
strcpy(v67, v83);
v58 = 1;
}
if ( v80 )
{
if ( v84 )
{
v70 = malloc(0x240DuLL);
GCMBnrGetImagePPM(v56, v70);
v71 = 9229LL;
}
else
{
v70 = malloc(0x2400uLL);
GCMBnrGetImageRaw(v56, v70);
v71 = 9216LL;
}
WriteDataToFile(v70, v71, v80);
}
if ( v5 )
{
v72 = GetFilesizeFromPath(v5);
v73 = malloc(v72);
v74 = v73;
if ( v85 )
{
puts("PPM IMPORT IS NOT IMPLEMENTED! (file not affected)\n");
exit(1);
}
if ( ReadDataFromFile(v73, v5) != v72 )
{
perror(v5);
exit(1);
}
v75 = (char *)malloc(0x1800uLL);
GCMBnrRawImageToGraphic(v74, v75);
*(_QWORD *)(v56 + 1) = *(_QWORD *)v75;
*(_QWORD *)(v56 + 6137) = *((_QWORD *)v75 + 767);
qmemcpy(
(void *)((unsigned __int64)(v56 + 9) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v75 - &v56[-((unsigned __int64)(v56 + 9) & 0xFFFFFFFFFFFFFFF8LL) + 1]),
8LL * (((_DWORD)v56 + 1 - (((_DWORD)v56 + 9) & 0xFFFFFFF8) + 6144) >> 3));
free(v75);
LABEL_111:
rewind(bnrFile);
v76 = GCMBnrRawSize(v56);
v77 = malloc(v76);
GCMBnrStructToRaw(v56, v77);
if ( fwrite(v77, 1uLL, v76, bnrFile) != v76 )
{
perror(filename);
exit(1);
}
}
else if ( v58 )
{
goto LABEL_111;
}
GCMFreeBnrInfoStruct(*((_QWORD *)v56 + 769));
closeBnr();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // er12
const char *v5; // r15
const char *v6; // r14
int v7; // eax
const char *v8; // rbx
bool v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rsi
__int64 v13; // rcx
const char *v14; // rdi
char v15; // al
bool v16; // cf
bool v17; // zf
__int64 v18; // rcx
const char *v19; // rdi
char v20; // al
bool v21; // cf
bool v22; // zf
const char **v23; // r13
__int64 v24; // rcx
const char *v25; // rdi
char v26; // al
bool v27; // cf
bool v28; // zf
__int64 v29; // rcx
const char *v30; // rdi
char v31; // al
bool v32; // cf
bool v33; // zf
const char *v34; // rax
__int64 v35; // rcx
const char *v36; // rdi
char v37; // al
bool v38; // cf
bool v39; // zf
__int64 v40; // rcx
const char *v41; // rdi
char v42; // al
bool v43; // cf
bool v44; // zf
const char *v45; // rax
__int64 v46; // rcx
const char *v47; // rdi
const char *v48; // rax
const char *v49; // rax
const char *v50; // rax
const char *v51; // rbx
const char *v52; // rbx
size_t v53; // rbx
void *v54; // rbp
char *v55; // rax
char *v56; // rbx
char *v57; // rbp
int v58; // er12
__int64 v59; // rcx
char *v60; // rdi
__int64 v61; // rcx
_DWORD *v62; // rdi
__int64 v63; // rcx
_DWORD *v64; // rdi
__int64 v65; // rcx
_DWORD *v66; // rdi
char *v67; // rbp
__int64 v68; // rcx
char *v69; // rdi
void *v70; // rbp
__int64 v71; // rsi
size_t v72; // rbp
void *v73; // rax
void *v74; // r12
char *v75; // rbp
size_t v76; // rbp
void *v77; // r12
char *src; // [rsp+0h] [rbp-68h]
const char *v80; // [rsp+8h] [rbp-60h]
char *v81; // [rsp+10h] [rbp-58h]
char *v82; // [rsp+18h] [rbp-50h]
char *v83; // [rsp+20h] [rbp-48h]
int v84; // [rsp+28h] [rbp-40h]
int v85; // [rsp+2Ch] [rbp-3Ch]

v85 = 0;
v84 = 0;
v4 = 0;
v5 = 0LL;
v80 = 0LL;
v83 = 0LL;
v82 = 0LL;
v81 = 0LL;
src = 0LL;
v6 = 0LL;
while ( 1 )
{
v8 = argv[1];
if ( !v8 )
{
func4();
exit(1);
}
if ( !strcmp("-?", argv[1]) || (v9 = strcmp("--help", argv[1]) != 0, v10 = 0, v11 = !v9) )
{
func5();
exit(1);
}
v12 = "-m";
v13 = 3LL;
v14 = argv[1];
do
{
if ( !v13 )
break;
v10 = *v12 < (unsigned int)*v14;
v11 = *v12++ == *v14++;
--v13;
}
while ( v11 );
v15 = (!v10 && !v11) - v10;
v16 = 0;
v17 = v15 == 0;
if ( !v15 )
goto LABEL_4;
v12 = "--modify-nth";
v18 = 13LL;
v19 = argv[1];
do
{
if ( !v18 )
break;
v16 = *v12 < (unsigned int)*v19;
v17 = *v12++ == *v19++;
--v18;
}
while ( v17 );
v20 = (!v16 && !v17) - v16;
v21 = 0;
v22 = v20 == 0;
if ( !v20 )
{
LABEL_4:
v7 = atoi(argv[2]);
v4 = v7;
if ( v7 <= 0 )
{
printf(" index is out of bounds! (%d)\n", (unsigned int)v7);
exit(1);
}
argv += 2;
goto LABEL_6;
}
v23 = argv + 1;
v12 = "-n";
v24 = 3LL;
v25 = argv[1];
do
{
if ( !v24 )
break;
v21 = *v12 < (unsigned int)*v25;
v22 = *v12++ == *v25++;
--v24;
}
while ( v22 );
v26 = (!v21 && !v22) - v21;
v27 = 0;
v28 = v26 == 0;
if ( v26 )
{
v12 = "--name";
v29 = 7LL;
v30 = argv[1];
do
{
if ( !v29 )
break;
v27 = *v12 < (unsigned int)*v30;
v28 = *v12++ == *v30++;
--v29;
}
while ( v28 );
v31 = (!v27 && !v28) - v27;
v32 = 0;
v33 = v31 == 0;
if ( v31 )
break;
}
v34 = argv[2];
if ( v34 )
{
argv += 2;
v6 = v34;
}
else
{
++argv;
}
LABEL_6:
if ( !*argv )
goto LABEL_73;
}
v12 = "-d";
v35 = 3LL;
v36 = argv[1];
do
{
if ( !v35 )
break;
v32 = *v12 < (unsigned int)*v36;
v33 = *v12++ == *v36++;
--v35;
}
while ( v33 );
v37 = (!v32 && !v33) - v32;
v38 = 0;
v39 = v37 == 0;
if ( !v37 )
goto LABEL_37;
v12 = "--developer";
v40 = 12LL;
v41 = argv[1];
do
{
if ( !v40 )
break;
v38 = *v12 < (unsigned int)*v41;
v39 = *v12++ == *v41++;
--v40;
}
while ( v39 );
v42 = (!v38 && !v39) - v38;
v43 = 0;
v44 = v42 == 0;
if ( !v42 )
{
LABEL_37:
v45 = argv[2];
if ( v45 )
{
argv += 2;
src = (char *)v45;
}
else
{
++argv;
}
goto LABEL_6;
}
v12 = "-N";
v46 = 3LL;
v47 = argv[1];
do
{
if ( !v46 )
break;
v43 = *v12 < (unsigned int)*v47;
v44 = *v12++ == *v47++;
--v46;
}
while ( v44 );
if ( (!v43 && !v44) == v43 || (v12 = argv[1], !strcmp("--full-name", v12)) )
{
v48 = argv[2];
if ( v48 )
{
argv += 2;
v81 = (char *)v48;
}
else
{
++argv;
}
goto LABEL_6;
}
v12 = v8;
if ( !strcmp("-D", v8) || (v12 = v8, !strcmp("--full-developer", v8)) )
{
v49 = argv[2];
if ( v49 )
{
argv += 2;
v82 = (char *)v49;
}
else
{
++argv;
}
goto LABEL_6;
}
v12 = v8;
if ( !strcmp("-s", v8) || (v12 = v8, !strcmp("--description", v8)) )
{
v50 = argv[2];
if ( v50 )
{
argv += 2;
v83 = (char *)v50;
}
else
{
++argv;
}
goto LABEL_6;
}
v12 = v8;
if ( !strcmp("-e", v8) || (v12 = v8, !strcmp("--extract-icon", v8)) )
{
v51 = argv[2];
if ( v51 )
{
v12 = "-raw";
if ( !strcmp(argv[2], "-raw") )
{
v23 = argv + 2;
v84 = 0;
}
else
{
v12 = "-ppm";
if ( !strcmp(v51, "-ppm") )
{
v23 = argv + 2;
v84 = 1;
}
}
if ( v23[1] )
{
argv = v23 + 1;
v80 = v23[1];
}
else
{
argv = v23;
}
}
else
{
++argv;
}
goto LABEL_6;
}
v12 = v8;
if ( !strcmp("-i", v8) || (v12 = v8, !strcmp("--icon", v8)) )
{
v52 = argv[2];
if ( v52 )
{
v12 = "-raw";
if ( !strcmp(argv[2], "-raw") )
{
v23 = argv + 2;
v85 = 0;
}
else
{
v12 = "-ppm";
if ( !strcmp(v52, "-ppm") )
{
v23 = argv + 2;
v85 = 1;
}
}
if ( v23[1] )
{
argv = v23 + 1;
v5 = v23[1];
}
else
{
argv = v23;
}
}
else
{
++argv;
}
goto LABEL_6;
}
filename = (char *)v8;
LABEL_73:
func2();
v53 = GetFilesizeFromStream(bnrFile, v12);
v54 = malloc(v53);
if ( ReadDataFromFile(v54, filename) != v53 )
{
perror(filename);
exit(1);
}
v55 = (char *)GCMRawBnrToStruct(v54, (unsigned int)v53);
v56 = v55;
if ( !v55 )
{
puts("error opening banner!");
exit(1);
}
func1(v55);
if ( *v56 == 49 )
v57 = (char *)*((_QWORD *)v56 + 769);
else
v57 = (char *)GCMBnrGetNthInfo(*((_QWORD *)v56 + 769), (unsigned int)(v4 - 1));
if ( !v57 )
{
puts("ERROR! mod == NULL (this shouldn't happen!)");
exit(1);
}
v58 = 0;
if ( v6 )
{
v59 = 8LL;
v60 = v57;
while ( v59 )
{
*(_DWORD *)v60 = 0;
v60 += 4;
--v59;
}
strcpy(v57, v6);
v58 = 1;
}
if ( src )
{
v61 = 8LL;
v62 = v57 + 32;
while ( v61 )
{
*v62++ = 0;
--v61;
}
strcpy(v57 + 32, src);
v58 = 1;
}
if ( v81 )
{
v63 = 16LL;
v64 = v57 + 64;
while ( v63 )
{
*v64++ = 0;
--v63;
}
strcpy(v57 + 64, v81);
v58 = 1;
}
if ( v82 )
{
v65 = 16LL;
v66 = v57 + 128;
while ( v65 )
{
*v66++ = 0;
--v65;
}
strcpy(v57 + 128, v82);
v58 = 1;
}
if ( v83 )
{
v67 = v57 + 192;
v68 = 32LL;
v69 = v67;
while ( v68 )
{
*(_DWORD *)v69 = 0;
v69 += 4;
--v68;
}
strcpy(v67, v83);
v58 = 1;
}
if ( v80 )
{
if ( v84 )
{
v70 = malloc(0x240DuLL);
GCMBnrGetImagePPM(v56, v70);
v71 = 9229LL;
}
else
{
v70 = malloc(0x2400uLL);
GCMBnrGetImageRaw(v56, v70);
v71 = 9216LL;
}
WriteDataToFile(v70, v71, v80);
}
if ( v5 )
{
v72 = GetFilesizeFromPath(v5);
v73 = malloc(v72);
v74 = v73;
if ( v85 )
{
puts("PPM IMPORT IS NOT IMPLEMENTED! (file not affected)\n");
exit(1);
}
if ( ReadDataFromFile(v73, v5) != v72 )
{
perror(v5);
exit(1);
}
v75 = (char *)malloc(0x1800uLL);
GCMBnrRawImageToGraphic(v74, v75);
*(_QWORD *)(v56 + 1) = *(_QWORD *)v75;
*(_QWORD *)(v56 + 6137) = *((_QWORD *)v75 + 767);
qmemcpy(
(void *)((unsigned __int64)(v56 + 9) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v75 - &v56[-((unsigned __int64)(v56 + 9) & 0xFFFFFFFFFFFFFFF8LL) + 1]),
8LL * (((_DWORD)v56 + 1 - (((_DWORD)v56 + 9) & 0xFFFFFFF8) + 6144) >> 3));
free(v75);
LABEL_111:
rewind(bnrFile);
v76 = GCMBnrRawSize(v56);
v77 = malloc(v76);
GCMBnrStructToRaw(v56, v77);
if ( fwrite(v77, 1uLL, v76, bnrFile) != v76 )
{
perror(filename);
exit(1);
}
}
else if ( v58 )
{
goto LABEL_111;
}
GCMFreeBnrInfoStruct(*((_QWORD *)v56 + 769));
func3();
return 0;
}

original_code:
int main(int argc, char **argv) {
 char *newName = ((void *)0);
 char *newDeveloper = ((void *)0);
 char *newFullName = ((void *)0);
 char *newFullDeveloper = ((void *)0);
 char *newDescription = ((void *)0);
 char *extractIconPath = ((void *)0);
 char *injectIconPath = ((void *)0);
 int modIndex = 0;
 int extractFormat = 0;
 int injectFormat = 0;
 char *currentArg = ((void *)0);
 do {
  currentArg = *(++argv);
  if (!currentArg) {
   printUsage();
   exit(1);
  } else if (strcmp("-?", currentArg) == 0 || strcmp("--help", currentArg) == 0) {
   printExtendedUsage();
   exit(1);
  } else if (strcmp("-m", currentArg) == 0 || strcmp("--modify-nth", currentArg) == 0) {
   modIndex = atoi(*(++argv));
   if (modIndex < 1) {
    printf(" index is out of bounds! (%d)\n", modIndex);
    exit(1);
   }
  } else if (strcmp("-n", currentArg) == 0 || strcmp("--name", currentArg) == 0) {
   if (*(argv + 1)) {
    newName = *(++argv);
   }
  } else if (strcmp("-d", currentArg) == 0 || strcmp("--developer", currentArg) == 0) {
   if (*(argv + 1)) {
    newDeveloper = *(++argv);
   }
  } else if (strcmp("-N", currentArg) == 0 || strcmp("--full-name", currentArg) == 0) {
   if (*(argv + 1)) {
    newFullName = *(++argv);
   }
  } else if (strcmp("-D", currentArg) == 0 || strcmp("--full-developer", currentArg) == 0) {
   if (*(argv + 1)) {
    newFullDeveloper = *(++argv);
   }
  } else if (strcmp("-s", currentArg) == 0 || strcmp("--description", currentArg) == 0) {
   if (*(argv + 1)) {
    newDescription = *(++argv);
   }
  } else if (strcmp("-e", currentArg) == 0 || strcmp("--extract-icon", currentArg) == 0) {
   if (*(argv + 1)) {
    if (strcmp(*(argv + 1), "-raw") == 0) {
     extractFormat = 0;
     *(argv += 1);
    } else if (strcmp(*(argv + 1), "-ppm") == 0) {
     extractFormat = 1;
     *(argv += 1);
    }
    if (*(argv + 1)) {
     extractIconPath = *(++argv);
    }
   }
  } else if (strcmp("-i", currentArg) == 0 || strcmp("--icon", currentArg) == 0) {
   if (*(argv + 1)) {
    if (strcmp(*(argv + 1), "-raw") == 0) {
     injectFormat = 0;
     *(argv += 1);
    } else if (strcmp(*(argv + 1), "-ppm") == 0) {
     injectFormat = 1;
     *(argv += 1);
    }
    if (*(argv + 1)) {
     injectIconPath = *(++argv);
    }
   }
  } else {
   filename = currentArg;
   break;
  }
 }while (*argv);
 openBnr();
 unsigned long len = GetFilesizeFromStream(bnrFile);
 char *data = (char*)malloc(len);
 if (ReadDataFromFile(data, filename) != len) {
  perror(filename);
  exit(1);
 }
 GCMBnrStruct *b = GCMRawBnrToStruct(data, len);
 if (!b) {
  printf("error opening banner!\n");
  exit(1);
 }
 printBnr(b);
 int fileChanged = 0;
 GCMBnrInfoStruct *mod = ((void *)0);
 if (b->version != '1') {
  mod = GCMBnrGetNthInfo(b->info, modIndex - 1);
 } else {
  mod = b->info;
 }
 if (!mod) {
  printf("ERROR! mod == NULL (this shouldn't happen!)\n");
  exit(1);
 }
 if (newName != ((void *)0)) {
  bzero(mod->name, 0x0020);
  strcpy(mod->name, newName);
  fileChanged = 1;
 }
 if (newDeveloper != ((void *)0)) {
  bzero(mod->developer, 0x0020);
  strcpy(mod->developer, newDeveloper);
  fileChanged = 1;
 }
 if (newFullName != ((void *)0)) {
  bzero(mod->fullName, 0x0040);
  strcpy(mod->fullName, newFullName);
  fileChanged = 1;
 }
 if (newFullDeveloper != ((void *)0)) {
  bzero(mod->fullDeveloper, 0x0040);
  strcpy(mod->fullDeveloper, newFullDeveloper);
  fileChanged = 1;
 }
 if (newDescription != ((void *)0)) {
  bzero(mod->description, 0x0080);
  strcpy(mod->description, newDescription);
  fileChanged = 1;
 }
 if (extractIconPath != ((void *)0)) {
  char *imageData = ((void *)0);
  u32 len;
  if (extractFormat == 0) {
   len = 3 * 96 * 32;
   imageData = (char*)malloc(len);
   GCMBnrGetImageRaw(b, imageData);
  } else {
   len = 3 * 96 * 32 + 13;
   imageData = (char*)malloc(len);
   GCMBnrGetImagePPM(b, imageData);
  }
  WriteDataToFile(imageData, len, extractIconPath);
 }
 if (injectIconPath != ((void *)0)) {
  u32 len = GetFilesizeFromPath(injectIconPath);
  char *imageData = (char*)malloc(len);
  if (injectFormat == 0) {
   if (ReadDataFromFile(imageData, injectIconPath) != len) {
    perror(injectIconPath);
    exit(1);
   }
  } else {
   printf("PPM IMPORT IS NOT IMPLEMENTED! (file not affected)\n\n");
   exit(1);
  }
  char *iconData = (char*)malloc(0x1800);
  GCMBnrRawImageToGraphic(imageData, iconData);
  memcpy(b->graphic, iconData, 0x1800);
  free(iconData);
  fileChanged = 1;
 }
 if (fileChanged) {
  rewind(bnrFile);
  u32 bnrSize = GCMBnrRawSize(b);
  char *buf = (char*)malloc(bnrSize);
  GCMBnrStructToRaw(b, buf);
  if (fwrite(buf, 1, bnrSize, bnrFile) != bnrSize) {
   perror(filename);
   exit(1);
  }
 }
 GCMFreeBnrInfoStruct(b->info);
 closeBnr();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 char *newName = ((void *)0);
 char *newDeveloper = ((void *)0);
 char *newFullName = ((void *)0);
 char *newFullDeveloper = ((void *)0);
 char *newDescription = ((void *)0);
 char *extractIconPath = ((void *)0);
 char *injectIconPath = ((void *)0);
 int modIndex = 0;
 int extractFormat = 0;
 int injectFormat = 0;
 char *currentArg = ((void *)0);
 do {
  currentArg = *(++argv);
  if (!currentArg) {
   printUsage();
   exit(1);
  } else if (strcmp("-?", currentArg) == 0 || strcmp("--help", currentArg) == 0) {
   printExtendedUsage();
   exit(1);
  } else if (strcmp("-m", currentArg) == 0 || strcmp("--modify-nth", currentArg) == 0) {
   modIndex = atoi(*(++argv));
   if (modIndex < 1) {
    printf(" index is out of bounds! (%d)\n", modIndex);
    exit(1);
   }
  } else if (strcmp("-n", currentArg) == 0 || strcmp("--name", currentArg) == 0) {
   if (*(argv + 1)) {
    newName = *(++argv);
   }
  } else if (strcmp("-d", currentArg) == 0 || strcmp("--developer", currentArg) == 0) {
   if (*(argv + 1)) {
    newDeveloper = *(++argv);
   }
  } else if (strcmp("-N", currentArg) == 0 || strcmp("--full-name", currentArg) == 0) {
   if (*(argv + 1)) {
    newFullName = *(++argv);
   }
  } else if (strcmp("-D", currentArg) == 0 || strcmp("--full-developer", currentArg) == 0) {
   if (*(argv + 1)) {
    newFullDeveloper = *(++argv);
   }
  } else if (strcmp("-s", currentArg) == 0 || strcmp("--description", currentArg) == 0) {
   if (*(argv + 1)) {
    newDescription = *(++argv);
   }
  } else if (strcmp("-e", currentArg) == 0 || strcmp("--extract-icon", currentArg) == 0) {
   if (*(argv + 1)) {
    if (strcmp(*(argv + 1), "-raw") == 0) {
     extractFormat = 0;
     *(argv += 1);
    } else if (strcmp(*(argv + 1), "-ppm") == 0) {
     extractFormat = 1;
     *(argv += 1);
    }
    if (*(argv + 1)) {
     extractIconPath = *(++argv);
    }
   }
  } else if (strcmp("-i", currentArg) == 0 || strcmp("--icon", currentArg) == 0) {
   if (*(argv + 1)) {
    if (strcmp(*(argv + 1), "-raw") == 0) {
     injectFormat = 0;
     *(argv += 1);
    } else if (strcmp(*(argv + 1), "-ppm") == 0) {
     injectFormat = 1;
     *(argv += 1);
    }
    if (*(argv + 1)) {
     injectIconPath = *(++argv);
    }
   }
  } else {
   filename = currentArg;
   break;
  }
 }while (*argv);
 openBnr();
 unsigned long len = GetFilesizeFromStream(bnrFile);
 char *data = (char*)malloc(len);
 if (ReadDataFromFile(data, filename) != len) {
  perror(filename);
  exit(1);
 }
 struct gcm_bnr_struct *b = GCMRawBnrToStruct(data, len);
 if (!b) {
  printf("error opening banner!\n");
  exit(1);
 }
 printBnr(b);
 int fileChanged = 0;
 struct gcm_bnr_info_record_struct *mod = ((void *)0);
 if (b->version != '1') {
  mod = GCMBnrGetNthInfo(b->info, modIndex - 1);
 } else {
  mod = b->info;
 }
 if (!mod) {
  printf("ERROR! mod == NULL (this shouldn't happen!)\n");
  exit(1);
 }
 if (newName != ((void *)0)) {
  bzero(mod->name, 0x0020);
  strcpy(mod->name, newName);
  fileChanged = 1;
 }
 if (newDeveloper != ((void *)0)) {
  bzero(mod->developer, 0x0020);
  strcpy(mod->developer, newDeveloper);
  fileChanged = 1;
 }
 if (newFullName != ((void *)0)) {
  bzero(mod->fullName, 0x0040);
  strcpy(mod->fullName, newFullName);
  fileChanged = 1;
 }
 if (newFullDeveloper != ((void *)0)) {
  bzero(mod->fullDeveloper, 0x0040);
  strcpy(mod->fullDeveloper, newFullDeveloper);
  fileChanged = 1;
 }
 if (newDescription != ((void *)0)) {
  bzero(mod->description, 0x0080);
  strcpy(mod->description, newDescription);
  fileChanged = 1;
 }
 if (extractIconPath != ((void *)0)) {
  char *imageData = ((void *)0);
  unsigned long len;
  if (extractFormat == 0) {
   len = 3 * 96 * 32;
   imageData = (char *)malloc(len);
   GCMBnrGetImageRaw(b, imageData);
  } else {
   len = 3 * 96 * 32 + 13;
   imageData = (char *)malloc(len);
   GCMBnrGetImagePPM(b, imageData);
  }
  WriteDataToFile(imageData, len, extractIconPath);
 }
 if (injectIconPath != ((void *)0)) {
  unsigned long len = GetFilesizeFromPath(injectIconPath);
  char *imageData = (char*)malloc(len);
  if (injectFormat == 0) {
   if (ReadDataFromFile(imageData, injectIconPath) != len) {
    perror(injectIconPath);
    exit(1);
   }
  } else {
   printf("PPM IMPORT IS NOT IMPLEMENTED! (file not affected)\n\n");
   exit(1);
  }
  char *iconData = (char*)malloc(0x1800);
  GCMBnrRawImageToGraphic(imageData, iconData);
  memcpy(b->graphic, iconData, 0x1800);
  free(iconData);
  fileChanged = 1;
 }
 if (fileChanged) {
  rewind(bnrFile);
  unsigned long bnrSize = GCMBnrRawSize(b);
  char *buf = (char*)malloc(bnrSize);
  GCMBnrStructToRaw(b, buf);
  if (fwrite(buf, 1, bnrSize, bnrFile) != bnrSize) {
   perror(filename);
   exit(1);
  }
 }
 GCMFreeBnrInfoStruct(b->info);
 closeBnr();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
newName
char *

variable_types:
newDeveloper
char *

variable_types:
newFullName
char *

variable_types:
newFullDeveloper
char *

variable_types:
newDescription
char *

variable_types:
extractIconPath
char *

variable_types:
injectIconPath
char *

variable_types: modIndex int

variable_types: extractFormat int

variable_types: injectFormat int

variable_types:
currentArg
char *

variable_types:
len
unsigned long

variable_types:
data
char *

variable_types: fileChanged int

variable_types:
imageData
char *

variable_types:
iconData
char *

variable_types:
bnrSize
unsigned long

user_defined_types: struct gcm_bnr_info_record_struct { char name[32]; char developer[32]; char fullName[64]; char fullDeveloper[64]; char description[128]; struct gcm_bnr_info_record_struct *next; }


GCMNewApploaderStruct

decompiled_code:
_QWORD *GCMNewApploaderStruct()
{
_QWORD *result; // rax

result = malloc(0x30uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x30uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
return result;
}

original_code:
GCMApploaderStruct *GCMNewApploaderStruct() {
 GCMApploaderStruct *a = (GCMApploaderStruct*)malloc(sizeof(GCMApploaderStruct));
 bzero(a->date, 0x0010);
 a->entrypoint = 0;
 a->size = 0;
 a->unknown = 0;
 a->code = ((void *)0);
 return a;
}

canonical_original_code:
struct gcm_apploader_struct *GCMNewApploaderStruct() {
 struct gcm_apploader_struct *a = (GCMApploaderStruct*)malloc(sizeof(GCMApploaderStruct));
 bzero(a->date, 0x0010);
 a->entrypoint = 0;
 a->size = 0;
 a->unknown = 0;
 a->code = ((void *)0);
 return a;
}

variable_types: struct gcm_apploader_struct { char date[16]; unsigned long entrypoint; unsigned long size; unsigned long unknown; char *code; } *


GCMApploaderStructToRaw

original_code:
void GCMApploaderStructToRaw(GCMApploaderStruct *a, char *buf) {
 if (!a) return;
 char *start = buf;
 memcpy(buf, a->date, 0x0010);
 buf += 0x0010;
 u32 *entrypoint = (u32*)malloc(sizeof(u32));
 *entrypoint = htonl(a->entrypoint);
 memcpy(buf, entrypoint, 0x0004);
 free(entrypoint);
 buf += 0x0004;
 u32 *size = (u32*)malloc(sizeof(u32));
 *size = htonl(a->size);
 memcpy(buf, size, 0x0004);
 free(size);
 buf += 0x0004;
 u32 *unknown = (u32*)malloc(sizeof(u32));
 *unknown = htonl(a->unknown);
 memcpy(buf, unknown, 0x0004);
 free(unknown);
 buf += 0x0004;
 buf += 4;
 memcpy(buf, a->code, (a->size));
 buf = start;
}

canonical_original_code:
void GCMApploaderStructToRaw(struct gcm_apploader_struct *a, char *buf) {
 if (!a) return;
 char *start = buf;
 memcpy(buf, a->date, 0x0010);
 buf += 0x0010;
 unsigned long *entrypoint = (u32*)malloc(sizeof(u32));
 *entrypoint = htonl(a->entrypoint);
 memcpy(buf, entrypoint, 0x0004);
 free(entrypoint);
 buf += 0x0004;
 unsigned long *size = (u32*)malloc(sizeof(u32));
 *size = htonl(a->size);
 memcpy(buf, size, 0x0004);
 free(size);
 buf += 0x0004;
 unsigned long *unknown = (u32*)malloc(sizeof(u32));
 *unknown = htonl(a->unknown);
 memcpy(buf, unknown, 0x0004);
 free(unknown);
 buf += 0x0004;
 buf += 4;
 memcpy(buf, a->code, (a->size));
 buf = start;
}

variable_types:
buf
char *

variable_types:
start
char *

variable_types:
entrypoint
unsigned long *

variable_types:
size
unsigned long *

variable_types:
unknown
unsigned long *

user_defined_types: struct gcm_apploader_struct { char date[16]; unsigned long entrypoint; unsigned long size; unsigned long unknown; char *code; }


GCMFreeApploaderStruct

decompiled_code:
void __fastcall GCMFreeApploaderStruct(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 5);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 5);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void GCMFreeApploaderStruct(GCMApploaderStruct *a) {
 if (!a) return;
 if (a->code != ((void *)0))
  free(a->code);
 free(a);
}

canonical_original_code:
void GCMFreeApploaderStruct(struct gcm_apploader_struct *a) {
 if (!a) return;
 if (a->code != ((void *)0))
  free(a->code);
 free(a);
}


GCMFreeBnrInfoStruct

decompiled_code:
void __fastcall GCMFreeBnrInfoStruct(_QWORD *a1)
{
if ( a1[40] )
GCMFreeBnrInfoStruct();
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1)
{
if ( a1[40] )
func0();
free(a1);
}

original_code:
void GCMFreeBnrInfoStruct(GCMBnrInfoStruct *r) {
 if (r->next) {
  GCMFreeBnrInfoStruct(r->next);
 }
 free(r);
}

canonical_original_code:
void GCMFreeBnrInfoStruct(struct gcm_bnr_info_record_struct *r) {
 if (r->next) {
  GCMFreeBnrInfoStruct(r->next);
 }
 free(r);
}

variable_types: struct gcm_bnr_info_record_struct { char name[32]; char developer[32]; char fullName[64]; char fullDeveloper[64]; char description[128]; struct gcm_bnr_info_record_struct *next; } *


GCMBnrInfoCount

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

result = 1LL;
if ( *(_QWORD *)(a1 + 320) )
result = (unsigned int)GCMBnrInfoCount() + 1;
return result;
}

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

result = 1LL;
if ( *(_QWORD *)(a1 + 320) )
result = (unsigned int)func1() + 1;
return result;
}

original_code:
int GCMBnrInfoCount(GCMBnrInfoStruct *r) {
 if (r->next) {
  return 1 + GCMBnrInfoCount(r->next);
 } else {
  return 1;
 }
}

canonical_original_code:
int GCMBnrInfoCount(struct gcm_bnr_info_record_struct *r) {
 if (r->next) {
  return 1 + GCMBnrInfoCount(r->next);
 } else {
  return 1;
 }
}


GCMBnrGetNthInfo

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

result = a1;
if ( a2 )
{
result = *(_QWORD *)(a1 + 320);
if ( result )
result = GCMBnrGetNthInfo(*(_QWORD *)(a1 + 320), (unsigned int)(a2 - 1));
}
return result;
}

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

result = a1;
if ( a2 )
{
result = *(_QWORD *)(a1 + 320);
if ( result )
result = func2(*(_QWORD *)(a1 + 320), (unsigned int)(a2 - 1));
}
return result;
}

original_code:
GCMBnrInfoStruct *GCMBnrGetNthInfo(GCMBnrInfoStruct *r, int n) {
 if (n == 0) {
  return r;
 } else if (r->next) {
  return GCMBnrGetNthInfo(r->next, n - 1);
 } else {
  return ((void *)0);
 }
}

canonical_original_code:
struct gcm_bnr_info_record_struct *GCMBnrGetNthInfo(struct gcm_bnr_info_record_struct *r, int n) {
 if (n == 0) {
  return r;
 } else if (r->next) {
  return GCMBnrGetNthInfo(r->next, n - 1);
 } else {
  return ((void *)0);
 }
}

variable_types:
r
struct gcm_bnr_info_record_struct *

variable_types: n int

return_type: struct gcm_bnr_info_record_struct { char name[32]; char developer[32]; char fullName[64]; char fullDeveloper[64]; char description[128]; struct gcm_bnr_info_record_struct *next; } *


initRecursion

decompiled_code:
FILE *initRecursion()
{
int v0; // eax
int v1; // edi
FILE *result; // rax

strcpy(fstTempFilename, "fstData.tmp.XXXXXX");
v0 = mkstemp(fstTempFilename);
if ( v0 == -1 || (fstTempFile = fdopen(v0, "w+")) == 0LL )
{
perror("ERROR OPENING TEMP FILE");
exit(1);
}
strcpy(stringTableTempFilename, "stringtable.tmp.XXXXXX");
v1 = mkstemp(stringTableTempFilename);
if ( v1 == -1 || (result = fdopen(v1, "w+"), (stringTableTempFile = result) == 0LL) )
{
perror("ERROR OPENING TEMP FILE!");
exit(1);
}
return result;
}

canonical_decompiled_code:
FILE *func1()
{
int v0; // eax
int v1; // edi
FILE *result; // rax

strcpy(fstTempFilename, "fstData.tmp.XXXXXX");
v0 = mkstemp(fstTempFilename);
if ( v0 == -1 || (fstTempFile = fdopen(v0, "w+")) == 0LL )
{
perror("ERROR OPENING TEMP FILE");
exit(1);
}
strcpy(stringTableTempFilename, "stringtable.tmp.XXXXXX");
v1 = mkstemp(stringTableTempFilename);
if ( v1 == -1 || (result = fdopen(v1, "w+"), (stringTableTempFile = result) == 0LL) )
{
perror("ERROR OPENING TEMP FILE!");
exit(1);
}
return result;
}

original_code:
static void initRecursion() {
 int fst_fd = -1;
 int stringTable_fd = -1;
 strcpy(fstTempFilename, "fstData.tmp.XXXXXX");
 if (((fst_fd = mkstemp(fstTempFilename)) == -1) || !(fstTempFile = fdopen(fst_fd, "w+"))) {
  perror("ERROR OPENING TEMP FILE");
  exit(1);
 }
 strcpy(stringTableTempFilename, "stringtable.tmp.XXXXXX");
 if (((stringTable_fd = mkstemp(stringTableTempFilename)) == -1) || !(stringTableTempFile = fdopen(stringTable_fd, "w+"))) {
  perror("ERROR OPENING TEMP FILE!");
  exit(1);
 }
}


writeStringToTempFile

decompiled_code:
__int64 __fastcall writeStringToTempFile(void *ptr)
{
int v1; // ebx

v1 = strlen((const char *)ptr) + 1;
if ( v1 != fwrite(ptr, 1uLL, v1, stringTableTempFile) )
{
perror("Error writing to string table!\n");
exit(1);
}
return ftell(stringTableTempFile) - v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
int v1; // ebx

v1 = strlen((const char *)ptr) + 1;
if ( v1 != fwrite(ptr, 1uLL, v1, stringTableTempFile) )
{
perror("Error writing to string table!\n");
exit(1);
}
return ftell(stringTableTempFile) - v1;
}

original_code:
static u32 writeStringToTempFile(char *string) {
 int len = strlen(string) + 1;
 if (fwrite(string, 1, len, stringTableTempFile) != len) {
  perror("Error writing to string table!\n");
  exit(1);
 }
 return ftell(stringTableTempFile) - len;
}

canonical_original_code:
static unsigned long writeStringToTempFile(char *string) {
 int len = strlen(string) + 1;
 if (fwrite(string, 1, len, stringTableTempFile) != len) {
  perror("Error writing to string table!\n");
  exit(1);
 }
 return ftell(stringTableTempFile) - len;
}

variable_types:
string
char *

variable_types: len int


lastPathComponent

decompiled_code:
const char *__fastcall lastPathComponent(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

v2 = rindex(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

v2 = rindex(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

original_code:
char *lastPathComponent(char *source) {
 char *last = rindex(source, '/');
 if (last && last != '\0') {
  *last++;
  return last;
 } else {
  return source;
 }
}

variable_types:
source
char *

variable_types:
last
char *

return_type: char *


nthPathComponent

decompiled_code:
char *__fastcall nthPathComponent(char *s, int a2, char *a3)
{
char *v3; // rbx
size_t v5; // rax
char *v6; // r14
int v7; // ebp
char *v8; // rax
char *v9; // rbx
char *v10; // rdx
char v11; // al

if ( !s )
return 0LL;
v3 = s;
if ( !a3 )
return 0LL;
v5 = strlen(s);
v6 = (char *)malloc(v5 + 1);
v7 = 0;
if ( a2 <= 0 )
{
LABEL_6:
v10 = v6;
do
{
v11 = *v3;
if ( *v3 == 47 )
break;
++v3;
*v10++ = v11;
}
while ( v11 );
*v10 = 0;
strcpy(a3, v6);
free(v6);
v9 = a3;
}
else
{
while ( 1 )
{
v8 = index(v3, 47);
v9 = v8;
if ( !v8 )
break;
++v7;
v3 = v8 + 1;
if ( a2 == v7 )
goto LABEL_6;
}
puts("not enough path components!!!!!");
free(v6);
}
return v9;
}

canonical_decompiled_code:
char *__fastcall func1(char *s, int a2, char *a3)
{
char *v3; // rbx
size_t v5; // rax
char *v6; // r14
int v7; // ebp
char *v8; // rax
char *v9; // rbx
char *v10; // rdx
char v11; // al

if ( !s )
return 0LL;
v3 = s;
if ( !a3 )
return 0LL;
v5 = strlen(s);
v6 = (char *)malloc(v5 + 1);
v7 = 0;
if ( a2 <= 0 )
{
LABEL_6:
v10 = v6;
do
{
v11 = *v3;
if ( *v3 == 47 )
break;
++v3;
*v10++ = v11;
}
while ( v11 );
*v10 = 0;
strcpy(a3, v6);
free(v6);
v9 = a3;
}
else
{
while ( 1 )
{
v8 = index(v3, 47);
v9 = v8;
if ( !v8 )
break;
++v7;
v3 = v8 + 1;
if ( a2 == v7 )
goto LABEL_6;
}
puts("not enough path components!!!!!");
free(v6);
}
return v9;
}

original_code:
char *nthPathComponent(char *source, int n, char *buf) {
 if (!source || !buf) return ((void *)0);
 int i = 0;
 char *pathItem = (char*)malloc(strlen(source) + 1);
 char *os1 = pathItem;
 char *s = source;
 for (i = 0; (i < n) && (s = index(s, '/')); i++, *s++);
 if (!s) {
  printf("not enough path components!!!!!\n");
  free(pathItem);
  return ((void *)0);
 }
 while (*s != '/' && (*os1++ = *s++));
 *os1++ = 0;
 strcpy(buf, pathItem);
 free(pathItem);
 return buf;
}

variable_types: i int

variable_types:
pathItem
char *

variable_types:
s
char *


pathComponentCount

decompiled_code:
__int64 __fastcall pathComponentCount(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++a1;
v2 += v1 == 47;
v1 = *a1;
}
while ( *a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++a1;
v2 += v1 == 47;
v1 = *a1;
}
while ( *a1 );
return v2;
}

original_code:
int pathComponentCount(char *source) {
 int count = 0;
 while(*source) {
  if (*source++ == '/') {
   count++;
  }
 }
 return count;
}

variable_types: count int


GCMSystemIDToStr

decompiled_code:
const char *__fastcall GCMSystemIDToStr(char a1)
{
const char *result; // rax

result = "Gamecube";
if ( a1 != 71 )
{
result = "Other";
if ( a1 == 85 )
result = "GBA Player";
}
return result;
}

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

result = "Gamecube";
if ( a1 != 71 )
{
result = "Other";
if ( a1 == 85 )
result = "GBA Player";
}
return result;
}

original_code:
char *GCMSystemIDToStr(char sysID) {
 switch (sysID) {
 case 'G':
  return "Gamecube";
 case 'U':
  return "GBA Player";
 default:
  return "Other";
 }
}

variable_types: sysID char


GCMMakerCodeToStr

decompiled_code:
const char *__fastcall GCMMakerCodeToStr(const char *a1)
{
const char *v1; // rcx

v1 = "Nintendo";
if ( strcmp(a1, "01") )
{
v1 = "Capcom";
if ( strcmp(a1, "08") )
{
v1 = "Eidos";
if ( strcmp(a1, "4F") )
{
v1 = "Acclaim";
if ( strcmp(a1, "51") )
{
v1 = "Midway";
if ( strcmp(a1, "5D") )
{
v1 = "Hudson";
if ( strcmp(a1, "5G") )
{
v1 = "Lucas Arts";
if ( strcmp(a1, "64") )
{
v1 = "Electronic Arts";
if ( strcmp(a1, "69") )
{
v1 = "TDK Mediactive";
if ( strcmp(a1, "6S") )
{
v1 = "Sega";
if ( strcmp(a1, "8P") )
{
v1 = "Namco";
if ( strcmp(a1, "AF") )
{
v1 = "Tomy";
if ( strcmp(a1, "DA") )
{
v1 = "Konami";
if ( strcmp(a1, "EM") )
{
v1 = "Activision";
if ( strcmp(a1, "52") )
{
v1 = "Bandai";
if ( strcmp(a1, "B2") )
{
v1 = "Ubisoft";
if ( strcmp(a1, "41") )
{
v1 = "Mirage Studios";
if ( strcmp(a1, "A4") )
v1 = "Other";
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
const char *v1; // rcx

v1 = "Nintendo";
if ( strcmp(a1, "01") )
{
v1 = "Capcom";
if ( strcmp(a1, "08") )
{
v1 = "Eidos";
if ( strcmp(a1, "4F") )
{
v1 = "Acclaim";
if ( strcmp(a1, "51") )
{
v1 = "Midway";
if ( strcmp(a1, "5D") )
{
v1 = "Hudson";
if ( strcmp(a1, "5G") )
{
v1 = "Lucas Arts";
if ( strcmp(a1, "64") )
{
v1 = "Electronic Arts";
if ( strcmp(a1, "69") )
{
v1 = "TDK Mediactive";
if ( strcmp(a1, "6S") )
{
v1 = "Sega";
if ( strcmp(a1, "8P") )
{
v1 = "Namco";
if ( strcmp(a1, "AF") )
{
v1 = "Tomy";
if ( strcmp(a1, "DA") )
{
v1 = "Konami";
if ( strcmp(a1, "EM") )
{
v1 = "Activision";
if ( strcmp(a1, "52") )
{
v1 = "Bandai";
if ( strcmp(a1, "B2") )
{
v1 = "Ubisoft";
if ( strcmp(a1, "41") )
{
v1 = "Mirage Studios";
if ( strcmp(a1, "A4") )
v1 = "Other";
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return v1;
}

original_code:
char *GCMMakerCodeToStr(char *code) {
 if (strcmp(code, "01") == 0) {
  return "Nintendo";
 } else if (strcmp(code, "08") == 0) {
  return "Capcom";
 } else if (strcmp(code, "4F") == 0) {
  return "Eidos";
 } else if (strcmp(code, "51") == 0) {
  return "Acclaim";
 } else if (strcmp(code, "5D") == 0) {
  return "Midway";
 } else if (strcmp(code, "5G") == 0) {
  return "Hudson";
 } else if (strcmp(code, "64") == 0) {
  return "Lucas Arts";
 } else if (strcmp(code, "69") == 0) {
  return "Electronic Arts";
 } else if (strcmp(code, "6S") == 0) {
  return "TDK Mediactive";
 } else if (strcmp(code, "8P") == 0) {
  return "Sega";
 } else if (strcmp(code, "AF") == 0) {
  return "Namco";
 } else if (strcmp(code, "DA") == 0) {
  return "Tomy";
 } else if (strcmp(code, "EM") == 0) {
  return "Konami";
 } else if (strcmp(code, "52") == 0) {
  return "Activision";
 } else if (strcmp(code, "B2") == 0) {
  return "Bandai";
 } else if (strcmp(code, "41") == 0) {
  return "Ubisoft";
 } else if (strcmp(code, "A4") == 0) {
  return "Mirage Studios";
 } else {
  return "Other";
 }
}

variable_types:
code
char *


GCMRegionCodeToStr

decompiled_code:
const char *__fastcall GCMRegionCodeToStr(char a1)
{
const char *result; // rax

result = "Japan/NTSC";
if ( a1 != 74 )
{
result = "Europe/PAL";
if ( a1 != 80 )
{
result = "Other";
if ( a1 == 69 )
result = "USA/NTSC";
}
}
return result;
}

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

result = "Japan/NTSC";
if ( a1 != 74 )
{
result = "Europe/PAL";
if ( a1 != 80 )
{
result = "Other";
if ( a1 == 69 )
result = "USA/NTSC";
}
}
return result;
}

original_code:
char *GCMRegionCodeToStr(char code) {
 switch (code) {
 case 'E':
  return "USA/NTSC";
 case 'P':
  return "Europe/PAL";
 case 'J':
  return "Japan/NTSC";
 default:
  return "Other";
 }
}

variable_types: code char


GCMBnrStructToRaw

original_code:
void GCMBnrStructToRaw(GCMBnrStruct *b, char *buf) {
 if (!b || !buf) return;
 char *start = buf;
 bzero(buf, 0x1960);
 memcpy(buf, "BNR", 0x0003);
 buf += 0x0003;
 char versionStr[2] = "";
 sprintf(versionStr, "%c", b->version);
 memcpy(buf, versionStr, 0x0001);
 buf += 0x0001;
 buf += 0x001c;
 memcpy(buf, b->graphic, 0x1800);
 buf += 0x1800;
 GCMBnrInfoStruct *head = b->info;
 GCMBnrInfoStruct *n = head;
 do {
  printf("writing: %s\n", n->name);
  memcpy(buf, n->name, 0x0020);
  buf += 0x0020;
  memcpy(buf, n->developer, 0x0020);
  buf += 0x0020;
  memcpy(buf, n->fullName, 0x0040);
  buf += 0x0040;
  memcpy(buf, n->fullDeveloper, 0x0040);
  buf += 0x0040;
  memcpy(buf, n->description, 0x0080);
  buf += 0x0080;
 } while (n = n->next);
 buf = start;
}

canonical_original_code:
void GCMBnrStructToRaw(struct gcm_bnr_struct *b, char *buf) {
 if (!b || !buf) return;
 char *start = buf;
 bzero(buf, 0x1960);
 memcpy(buf, "BNR", 0x0003);
 buf += 0x0003;
 char versionStr[2] = "";
 sprintf(versionStr, "%c", b->version);
 memcpy(buf, versionStr, 0x0001);
 buf += 0x0001;
 buf += 0x001c;
 memcpy(buf, b->graphic, 0x1800);
 buf += 0x1800;
 struct gcm_bnr_info_record_struct *head = b->info;
 struct gcm_bnr_info_record_struct *n = head;
 do {
  printf("writing: %s\n", n->name);
  memcpy(buf, n->name, 0x0020);
  buf += 0x0020;
  memcpy(buf, n->developer, 0x0020);
  buf += 0x0020;
  memcpy(buf, n->fullName, 0x0040);
  buf += 0x0040;
  memcpy(buf, n->fullDeveloper, 0x0040);
  buf += 0x0040;
  memcpy(buf, n->description, 0x0080);
  buf += 0x0080;
 } while (n = n->next);
 buf = start;
}

variable_types: struct gcm_bnr_struct { char version; char graphic[6144]; struct gcm_bnr_info_record_struct { char name[32]; char developer[32]; char fullName[64]; char fullDeveloper[64]; char description[128]; struct gcm_bnr_info_record_struct *next; } *info; } *

variable_types:
buf
char *

variable_types:
start
char *

variable_types:
versionStr
char [2]


GCMBnrRawSize

decompiled_code:
__int64 __fastcall GCMBnrRawSize(__int64 a1)
{
return (int)(320 * GCMBnrInfoCount(*(_QWORD *)(a1 + 6152)) + 6176);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return (int)(320 * GCMBnrInfoCount(*(_QWORD *)(a1 + 6152)) + 6176);
}

original_code:
u32 GCMBnrRawSize(GCMBnrStruct *b) {
 return (0x0004 + 0x001c + 0x1800 + (GCMBnrInfoCount(b->info) * 0x0140));
}

canonical_original_code:
unsigned long GCMBnrRawSize(struct gcm_bnr_struct *b) {
 return (0x0004 + 0x001c + 0x1800 + (GCMBnrInfoCount(b->info) * 0x0140));
}


decompiled_code:
__int16 __fastcall GCMColorToRGB5A1(_BYTE *a1)
{
unsigned __int8 v1; // bp
unsigned __int8 v2; // bl
unsigned __int8 v3; // dl
__int16 v4; // ax
int v5; // ecx
int v6; // ecx
int i; // ecx
__int16 result; // ax

v1 = GCMBnrReverseBits((int)((double)(unsigned __int8)a1[1] * 0.125), 5);
v2 = GCMBnrReverseBits((int)((double)(unsigned __int8)a1[2] * 0.125), 5);
v3 = GCMBnrReverseBits((int)((double)(unsigned __int8)a1[3] * 0.125), 5);
v4 = 2 * (*a1 != 0);
v5 = 5;
do
{
v4 = 2 * (v4 - (((v1 & 1) == 0) - 1));
v1 >>= 1;
--v5;
}
while ( v5 );
v6 = 5;
do
{
v4 = 2 * (v4 - (((v2 & 1) == 0) - 1));
v2 >>= 1;
--v6;
}
while ( v6 );
for ( i = 5; ; --i )
{
result = v4 - (((v3 & 1) == 0) - 1);
if ( i == 1 )
break;
v4 = 2 * result;
v3 >>= 1;
}
return result;
}

canonical_original_code:
unsigned short GCMColorToRGB5A1(struct gcm_rgb_color *c) {
 unsigned char r = GCMBnrReverseBits((uchar)(c->red / (256.0 / 32.0)), 5);
 unsigned char g = GCMBnrReverseBits((uchar)(c->green / (256.0 / 32.0)), 5);
 unsigned char b = GCMBnrReverseBits((uchar)(c->blue / (256.0 / 32.0)), 5);
 unsigned short s = 0;
 if (c->alpha) {
  s++;
  s <<= 1;
 }
 int i = 0;
 for (i = 0; i < 5; i++) {
  if (r % 2) {
   s++;
  }
  s <<= 1;
  r >>= 1;
 }
 for (i = 0; i < 5; i++) {
  if (g % 2) {
   s++;
  }
  s <<= 1;
  g >>= 1;
 }
 for (i = 0; i < 5; i++) {
  if (b % 2) {
   s++;
  }
  if (i != 4)
   s <<= 1;
  b >>= 1;
 }
 return s;
}

variable_types: struct gcm_rgb_color { unsigned char alpha; unsigned char red; unsigned char green; unsigned char blue; } *

variable_types:
r
unsigned char

variable_types:
g
unsigned char

variable_types:
b
unsigned char

variable_types:
s
unsigned short

return_type: unsigned short


GCMBnrGetImageRaw

original_code:
void GCMBnrGetImageRaw(GCMBnrStruct *b, char *buf) {
 if (!b || !buf) return;
 u16 *curPixel = (u16*)(b->graphic);
 int i = 0;
 for (i = 0; i < (96 * 32); i++) {
  int j = ((i / 4) * (4 * 4) + (i % 4)) % (96 * 4);
  j = j + (i / 96 % 4 * 4) + (i / 384 % 8 * 384);
  GCMRgbColor *c = GCMRGB5A1toColor(curPixel[j]);
  buf[i * 3] = c->red;
  buf[i * 3 + 1] = c->green;
  buf[i * 3 + 2] = c->blue;
  free(c);
 }
}

canonical_original_code:
void GCMBnrGetImageRaw(struct gcm_bnr_struct *b, char *buf) {
 if (!b || !buf) return;
 unsigned short *curPixel = (u16*)(b->graphic);
 int i = 0;
 for (i = 0; i < (96 * 32); i++) {
  int j = ((i / 4) * (4 * 4) + (i % 4)) % (96 * 4);
  j = j + (i / 96 % 4 * 4) + (i / 384 % 8 * 384);
  struct gcm_rgb_color *c = GCMRGB5A1toColor(curPixel[j]);
  buf[i * 3] = c->red;
  buf[i * 3 + 1] = c->green;
  buf[i * 3 + 2] = c->blue;
  free(c);
 }
}

variable_types:
curPixel
unsigned short *

variable_types: j int

user_defined_types: struct gcm_rgb_color { unsigned char alpha; unsigned char red; unsigned char green; unsigned char blue; }


GCMBnrGetImagePPM

decompiled_code:
void __fastcall GCMBnrGetImagePPM(__int64 a1, char *a2)
{
size_t v2; // rax
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v3, "%s\n%d %d\n255\n", "P6", 96LL, 32LL);
strcpy(a2, v3);
v2 = strlen(v3);
GCMBnrGetImageRaw(a1, &a2[v2]);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, char *a2)
{
size_t v2; // rax
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v3, "%s\n%d %d\n255\n", "P6", 96LL, 32LL);
strcpy(a2, v3);
v2 = strlen(v3);
func5(a1, &a2[v2]);
}

original_code:
void GCMBnrGetImagePPM(GCMBnrStruct *b, char *buf) {
 char header[256];
 sprintf(header, "%s\n%d %d\n255\n", "P6", 96, 32);
 strcpy(buf, header);
 buf += strlen(header);
 GCMBnrGetImageRaw(b, buf);
}

canonical_original_code:
void GCMBnrGetImagePPM(struct gcm_bnr_struct *b, char *buf) {
 char header[256];
 sprintf(header, "%s\n%d %d\n255\n", "P6", 96, 32);
 strcpy(buf, header);
 buf += strlen(header);
 GCMBnrGetImageRaw(b, buf);
}

variable_types:
header
char [256]


GCMBnrRawImageToGraphic

original_code:
void GCMBnrRawImageToGraphic(char *raw, char *buf) {
 if (!raw || !buf) {
  return;
 }
 int i = 0;
 for (i = 0; i < (96 * 32); i++) {
  int j = (i % 4) + (i / 16 % 24 * 4);
  j += (i / 4 % 4 * 96) + (i / 384 % 8 * 384);
  GCMRgbColor *c = (GCMRgbColor*)malloc(sizeof(GCMRgbColor));
  c->red = raw[j * 3];
  c->green = raw[j * 3 + 1];
  c->blue = raw[j * 3 + 2];
  u16 *p = (u16*)malloc(sizeof(u16));
  *p = GCMColorToRGB5A1(c);
  *p = htons(*p);
  memcpy(buf, (char*)p, sizeof(u16));
  buf += sizeof(u16);
  free(c);
  free(p);
 }
}

canonical_original_code:
void GCMBnrRawImageToGraphic(char *raw, char *buf) {
 if (!raw || !buf) {
  return;
 }
 int i = 0;
 for (i = 0; i < (96 * 32); i++) {
  int j = (i % 4) + (i / 16 % 24 * 4);
  j += (i / 4 % 4 * 96) + (i / 384 % 8 * 384);
  struct gcm_rgb_color *c = (GCMRgbColor*)malloc(sizeof(GCMRgbColor));
  c->red = raw[j * 3];
  c->green = raw[j * 3 + 1];
  c->blue = raw[j * 3 + 2];
  unsigned short *p = (u16*)malloc(sizeof(u16));
  *p = GCMColorToRGB5A1(c);
  *p = htons(*p);
  memcpy(buf, (char *)p, sizeof(u16));
  buf += sizeof(u16);
  free(c);
  free(p);
 }
}

variable_types:
raw
char *

variable_types: i int

variable_types:
p
unsigned short *


printApploader

decompiled_code:
int __fastcall printApploader(__int64 a1)
{
const char *v1; // rdx
const char *v2; // rdx
const char *v3; // rdx
__int64 v5[2]; // [rsp+0h] [rbp-108h] BYREF
char v6[232]; // [rsp+10h] [rbp-F8h] BYREF
int v7; // [rsp+F8h] [rbp-10h]
__int16 v8; // [rsp+FCh] [rbp-Ch]
char v9; // [rsp+FEh] [rbp-Ah]

printf("Date: %s\n", (const char *)a1);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
v9 = 0;
v1 = "0x%08X";
if ( !hexFlag )
v1 = "%lu";
sprintf((char *)v5, "Entrypoint: %s\n", v1);
printf((const char *)v5, *(_QWORD *)(a1 + 16));
v2 = "0x%08X";
if ( !hexFlag )
v2 = "%lu";
sprintf((char *)v5, "Size: %s\n", v2);
printf((const char *)v5, *(_QWORD *)(a1 + 24));
v3 = "0x%08X";
if ( !hexFlag )
v3 = "%lu";
sprintf((char *)v5, "Unknown: %s\n", v3);
return printf((const char *)v5, *(_QWORD *)(a1 + 32));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
const char *v1; // rdx
const char *v2; // rdx
const char *v3; // rdx
__int64 v5[2]; // [rsp+0h] [rbp-108h] BYREF
char v6[232]; // [rsp+10h] [rbp-F8h] BYREF
int v7; // [rsp+F8h] [rbp-10h]
__int16 v8; // [rsp+FCh] [rbp-Ch]
char v9; // [rsp+FEh] [rbp-Ah]

printf("Date: %s\n", (const char *)a1);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
v9 = 0;
v1 = "0x%08X";
if ( !hexFlag )
v1 = "%lu";
sprintf((char *)v5, "Entrypoint: %s\n", v1);
printf((const char *)v5, *(_QWORD *)(a1 + 16));
v2 = "0x%08X";
if ( !hexFlag )
v2 = "%lu";
sprintf((char *)v5, "Size: %s\n", v2);
printf((const char *)v5, *(_QWORD *)(a1 + 24));
v3 = "0x%08X";
if ( !hexFlag )
v3 = "%lu";
sprintf((char *)v5, "Unknown: %s\n", v3);
return printf((const char *)v5, *(_QWORD *)(a1 + 32));
}

original_code:
void printApploader(GCMApploaderStruct *a) {
 printf("Date:       %s\n", a->date);
 char format[255] = "";
 sprintf(format, "Entrypoint: %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, a->entrypoint);
 sprintf(format,"Size:       %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, a->size);
 sprintf(format, "Unknown:    %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, a->unknown);
}

canonical_original_code:
void printApploader(struct gcm_apploader_struct *a) {
 printf("Date:       %s\n", a->date);
 char format[255] = "";
 sprintf(format, "Entrypoint: %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, a->entrypoint);
 sprintf(format,"Size:       %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, a->size);
 sprintf(format, "Unknown:    %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, a->unknown);
}

variable_types: struct gcm_apploader_struct { char date[16]; unsigned long entrypoint; unsigned long size; unsigned long unknown; char *code; } *

variable_types:
format
char [255]


closeFile

decompiled_code:
int closeFile()
{
return fclose(appldrFile);
}

canonical_decompiled_code:
int func1()
{
return fclose(appldrFile);
}

original_code:
void closeFile() {
 fclose(appldrFile);
}


printUsage

decompiled_code:
int printUsage()
{
printf("gcmapploadertool %s- Utility for working with GameCube DVD Image apploaders.\n", "0.3.3d");
puts("http://gcmtool.sourceforge.net\n");
printf("Usage:\t");
puts("gcmapploadertool <apploader_file>\n");
return printf("Use %s to view extended usage.\n\n", "-?");
}

canonical_decompiled_code:
int func2()
{
printf("gcmapploadertool %s- Utility for working with GameCube DVD Image apploaders.\n", "0.3.3d");
puts("http://gcmtool.sourceforge.net\n");
printf("Usage:\t");
puts("gcmapploadertool <apploader_file>\n");
return printf("Use %s to view extended usage.\n\n", "-?");
}

original_code:
void printUsage() {
 printf("gcmapploadertool %s- Utility for working with GameCube DVD Image apploaders.\n", "0.3.3d");
 printf("http://gcmtool.sourceforge.net\n\n");
 printf("Usage:\t");
 printf("gcmapploadertool <apploader_file>\n\n");
 printf("Use %s to view extended usage.\n\n", "-?");
}


printExtendedUsage

decompiled_code:
int printExtendedUsage()
{
printUsage();
return printf("\t\x1B[1m-?%s--help \x1B[m\n\t\tDisplays this help.\n\n", ", ");
}

canonical_decompiled_code:
int func3()
{
func2();
return printf("\t\x1B[1m-?%s--help \x1B[m\n\t\tDisplays this help.\n\n", ", ");
}

original_code:
void printExtendedUsage() {
 printUsage();
 printf("\t\033[1m" "-?" "%s" "--help" " " "" "\033[m\n\t\t" "Displays this help." "\n\n", strcmp("", "--help") == 0 ? "" : ", ");;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r8
const char *v4; // rax
bool v5; // dl
bool v6; // cf
bool v7; // zf
const char *v8; // rsi
__int64 v9; // rcx
const char *v10; // rdi
size_t v11; // rbx
void *v12; // rbp
__int64 v13; // rax

hexFlag = 0;
v3 = argv + 1;
v4 = argv[1];
if ( !v4 )
{
LABEL_2:
printUsage();
exit(1);
}
while ( 1 )
{
if ( !strcmp("-?", v4) || !strcmp("--help", v4) )
{
printExtendedUsage();
exit(0);
}
v5 = strcmp("-h", v4) != 0;
v6 = 0;
v7 = !v5;
if ( v5 )
{
v8 = "--hex";
v9 = 6LL;
v10 = v4;
do
{
if ( !v9 )
break;
v6 = *v8 < (unsigned int)*v10;
v7 = *v8++ == *v10++;
--v9;
}
while ( v7 );
if ( (!v6 && !v7) != v6 )
break;
}
hexFlag = 1;
v4 = *++v3;
if ( !*v3 )
goto LABEL_2;
}
filename = (char *)v4;
openFile("r");
v11 = GetFilesizeFromStream(appldrFile, v8);
v12 = malloc(v11);
if ( fread(v12, 1uLL, v11, appldrFile) != v11 )
{
perror(filename);
exit(1);
}
v13 = GCMRawApploaderToStruct(v12);
printApploader(v13);
closeFile();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r8
const char *v4; // rax
bool v5; // dl
bool v6; // cf
bool v7; // zf
const char *v8; // rsi
__int64 v9; // rcx
const char *v10; // rdi
size_t v11; // rbx
void *v12; // rbp
__int64 v13; // rax

hexFlag = 0;
v3 = argv + 1;
v4 = argv[1];
if ( !v4 )
{
LABEL_2:
func2();
exit(1);
}
while ( 1 )
{
if ( !strcmp("-?", v4) || !strcmp("--help", v4) )
{
func3();
exit(0);
}
v5 = strcmp("-h", v4) != 0;
v6 = 0;
v7 = !v5;
if ( v5 )
{
v8 = "--hex";
v9 = 6LL;
v10 = v4;
do
{
if ( !v9 )
break;
v6 = *v8 < (unsigned int)*v10;
v7 = *v8++ == *v10++;
--v9;
}
while ( v7 );
if ( (!v6 && !v7) != v6 )
break;
}
hexFlag = 1;
v4 = *++v3;
if ( !*v3 )
goto LABEL_2;
}
filename = (char *)v4;
openFile("r");
v11 = GetFilesizeFromStream(appldrFile, v8);
v12 = malloc(v11);
if ( fread(v12, 1uLL, v11, appldrFile) != v11 )
{
perror(filename);
exit(1);
}
v13 = GCMRawApploaderToStruct(v12);
func0(v13);
func1();
return 0;
}

original_code:
int main(int argc, char **argv) {
 hexFlag = 0;
 char *currentArg = ((void *)0);
 do {
  currentArg = *(++argv);
  if (!currentArg) {
   printUsage();
   exit(1);
  } else if (strcmp("-?", currentArg) == 0 || strcmp("--help", currentArg) == 0) {
   printExtendedUsage();
   exit(0);
  } else if (strcmp("-h", currentArg) == 0 || strcmp("--hex", currentArg) == 0) {
   hexFlag = 1;
  } else {
   filename = currentArg;
   break;
  }
 } while(*argv);
 openFile("r");
 u32 len = GetFilesizeFromStream(appldrFile);
 char *data = (char*)malloc(len);
 if (fread(data, 1, len, appldrFile) != len) {
  perror(filename);
  exit(1);
 }
 GCMApploaderStruct *a = GCMRawApploaderToStruct(data);
 printApploader(a);
 closeFile();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 hexFlag = 0;
 char *currentArg = ((void *)0);
 do {
  currentArg = *(++argv);
  if (!currentArg) {
   printUsage();
   exit(1);
  } else if (strcmp("-?", currentArg) == 0 || strcmp("--help", currentArg) == 0) {
   printExtendedUsage();
   exit(0);
  } else if (strcmp("-h", currentArg) == 0 || strcmp("--hex", currentArg) == 0) {
   hexFlag = 1;
  } else {
   filename = currentArg;
   break;
  }
 } while(*argv);
 openFile("r");
 unsigned long len = GetFilesizeFromStream(appldrFile);
 char *data = (char*)malloc(len);
 if (fread(data, 1, len, appldrFile) != len) {
  perror(filename);
  exit(1);
 }
 struct gcm_apploader_struct *a = GCMRawApploaderToStruct(data);
 printApploader(a);
 closeFile();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
currentArg
char *

variable_types:
len
unsigned long

variable_types:
data
char *