decompiled_code:
int __fastcall olympus_prop(unsigned __int16 *a1, __int64 a2)
{
char *v2; // rax
__int64 v3; // r12
__int64 v4; // r13
__int64 v5; // r13
__int64 v6; // rbx
int v7; // er12
int v8; // eax

LODWORD(v2) = *a1;
switch ( (_WORD)v2 )
{
case 0x200:
v3 = *(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2);
v4 = ((__int64 (*)(void))childprop)();
*(_DWORD *)(v4 + 8) = exif4byte(v3, *(unsigned int *)(a2 + 56));
*(_QWORD *)(v4 + 16) = "OlympusPicMode";
*(_QWORD *)(v4 + 24) = "Picture Mode";
*(_WORD *)(v4 + 40) = 1;
v5 = childprop(a1);
*(_DWORD *)(v5 + 8) = exif4byte(v3 + 4, *(unsigned int *)(a2 + 56));
*(_QWORD *)(v5 + 16) = "OlympusSeqNum";
*(_QWORD *)(v5 + 24) = "Sequence Number";
*(_WORD *)(v5 + 40) = 1;
v6 = childprop(a1);
LODWORD(v2) = exif4byte(v3 + 8, *(unsigned int *)(a2 + 56));
*(_DWORD *)(v6 + 8) = (_DWORD)v2;
*(_QWORD *)(v6 + 16) = "OlympusPanDir";
*(_QWORD *)(v6 + 24) = "Panoramic Direction";
*(_WORD *)(v6 + 40) = 1;
break;
case 0x204:
v7 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2), *(unsigned int *)(a2 + 56));
v8 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2) + 4LL, *(unsigned int *)(a2 + 56));
if ( v7 == v8 )
{
v2 = (char *)*((_QWORD *)a1 + 4);
strcpy(v2, "None");
}
else
{
LODWORD(v2) = snprintf(*((char **)a1 + 4), 0x1FuLL, "x%.1f", (float)((float)v7 / (float)v8));
}
break;
case 8:
exifstralloc(a1 + 16, 32LL);
LODWORD(v2) = snprintf(
*((char **)a1 + 4),
0x1FuLL,
"%03d-%04d",
*((unsigned int *)a1 + 2) / 0x2710uLL,
*((_DWORD *)a1 + 2) % 0x2710u);
break;
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int16 *a1, __int64 a2)
{
char *v2; // rax
__int64 v3; // r12
__int64 v4; // r13
__int64 v5; // r13
__int64 v6; // rbx
int v7; // er12
int v8; // eax

LODWORD(v2) = *a1;
switch ( (_WORD)v2 )
{
case 0x200:
v3 = *(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2);
v4 = ((__int64 (*)(void))childprop)();
*(_DWORD *)(v4 + 8) = exif4byte(v3, *(unsigned int *)(a2 + 56));
*(_QWORD *)(v4 + 16) = "OlympusPicMode";
*(_QWORD *)(v4 + 24) = "Picture Mode";
*(_WORD *)(v4 + 40) = 1;
v5 = childprop(a1);
*(_DWORD *)(v5 + 8) = exif4byte(v3 + 4, *(unsigned int *)(a2 + 56));
*(_QWORD *)(v5 + 16) = "OlympusSeqNum";
*(_QWORD *)(v5 + 24) = "Sequence Number";
*(_WORD *)(v5 + 40) = 1;
v6 = childprop(a1);
LODWORD(v2) = exif4byte(v3 + 8, *(unsigned int *)(a2 + 56));
*(_DWORD *)(v6 + 8) = (_DWORD)v2;
*(_QWORD *)(v6 + 16) = "OlympusPanDir";
*(_QWORD *)(v6 + 24) = "Panoramic Direction";
*(_WORD *)(v6 + 40) = 1;
break;
case 0x204:
v7 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2), *(unsigned int *)(a2 + 56));
v8 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2) + 4LL, *(unsigned int *)(a2 + 56));
if ( v7 == v8 )
{
v2 = (char *)*((_QWORD *)a1 + 4);
strcpy(v2, "None");
}
else
{
LODWORD(v2) = snprintf(*((char **)a1 + 4), 0x1FuLL, "x%.1f", (float)((float)v7 / (float)v8));
}
break;
case 8:
exifstralloc(a1 + 16, 32LL);
LODWORD(v2) = snprintf(
*((char **)a1 + 4),
0x1FuLL,
"%03d-%04d",
*((unsigned int *)a1 + 2) / 0x2710uLL,
*((_DWORD *)a1 + 2) % 0x2710u);
break;
}
return (int)v2;
}

original_code:
void
olympus_prop(struct exifprop *prop, struct exiftags *t)
{
 u_int32_t a, b;
 unsigned char *offset;
 struct exifprop *aprop;
 switch (prop->tag) {
 case 0x0200:
  offset = t->mkrmd.btiff + prop->value;
  aprop = childprop(prop);
  aprop->value = exif4byte(offset, t->mkrmd.order);
  aprop->name = "OlympusPicMode";
  aprop->descr = "Picture Mode";
  aprop->lvl = 0x01;
  aprop = childprop(prop);
  aprop->value = exif4byte(offset + 4, t->mkrmd.order);
  aprop->name = "OlympusSeqNum";
  aprop->descr = "Sequence Number";
  aprop->lvl = 0x01;
  aprop = childprop(prop);
  aprop->value = exif4byte(offset + 8, t->mkrmd.order);
  aprop->name = "OlympusPanDir";
  aprop->descr = "Panoramic Direction";
  aprop->lvl = 0x01;
  break;
 case 0x0204:
  a = exif4byte(t->mkrmd.btiff + prop->value, t->mkrmd.order);
  b = exif4byte(t->mkrmd.btiff + prop->value + 4, t->mkrmd.order);
  if (a == b)
   snprintf(prop->str, 31, "None");
  else
   snprintf(prop->str, 31, "x%.1f", (float)a / (float)b);
  break;
 case 0x0008:
  exifstralloc(&prop->str, 32);
  snprintf(prop->str, 31, "%03d-%04d", prop->value / 10000,
      prop->value % 10000);
  break;
 }
}

canonical_original_code:
void olympus_prop(struct exifprop *prop, struct exiftags *t)
{
 unsigned int a; unsigned int b;
 unsigned char *offset;
 struct exifprop *aprop;
 switch (prop->tag) {
 case 0x0200:
  offset = t->mkrmd.btiff + prop->value;
  aprop = childprop(prop);
  aprop->value = exif4byte(offset, t->mkrmd.order);
  aprop->name = "OlympusPicMode";
  aprop->descr = "Picture Mode";
  aprop->lvl = 0x01;
  aprop = childprop(prop);
  aprop->value = exif4byte(offset + 4, t->mkrmd.order);
  aprop->name = "OlympusSeqNum";
  aprop->descr = "Sequence Number";
  aprop->lvl = 0x01;
  aprop = childprop(prop);
  aprop->value = exif4byte(offset + 8, t->mkrmd.order);
  aprop->name = "OlympusPanDir";
  aprop->descr = "Panoramic Direction";
  aprop->lvl = 0x01;
  break;
 case 0x0204:
  a = exif4byte(t->mkrmd.btiff + prop->value, t->mkrmd.order);
  b = exif4byte(t->mkrmd.btiff + prop->value + 4, t->mkrmd.order);
  if (a == b)
   snprintf(prop->str, 31, "None");
  else
   snprintf(prop->str, 31, "x%.1f", (float)a / (float)b);
  break;
 case 0x0008:
  exifstralloc(&prop->str, 32);
  snprintf(prop->str, 31, "%03d-%04d", prop->value / 10000,
      prop->value % 10000);
  break;
 }
}

variable_types:
offset
unsigned char *


repo: ejohnst/exiftags

decompiled_code:
__int64 __fastcall olympus_ifd(unsigned int a1, __int64 a2)
{
__int64 v3[2]; // [rsp+8h] [rbp-10h] BYREF

if ( !strcmp((const char *)(*(_QWORD *)(a2 + 8) + a1), "OLYMP") )
readifd(a1 + 8, v3, &olympus_tags, a2);
else
readifd(a1, v3, &olympus_tags, a2);
return v3[0];
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
__int64 v3[2]; // [rsp+8h] [rbp-10h] BYREF

if ( !strcmp((const char *)(*(_QWORD *)(a2 + 8) + a1), "OLYMP") )
readifd(a1 + 8, v3, &olympus_tags, a2);
else
readifd(a1, v3, &olympus_tags, a2);
return v3[0];
}

original_code:
struct ifd *
olympus_ifd(u_int32_t offset, struct tiffmeta *md)
{
 struct ifd *myifd;
 if (!strcmp((const char *)(md->btiff + offset), "OLYMP"))
  readifd(offset + strlen("OLYMP") + 3, &myifd, olympus_tags, md);
 else
  readifd(offset, &myifd, olympus_tags, md);
 return (myifd);
}

canonical_original_code:
struct ifd *olympus_ifd(unsigned int offset, struct tiffmeta *md)
{
 struct ifd *myifd;
 if (!strcmp((char *)(md->btiff + offset), "OLYMP"))
  readifd(offset + strlen("OLYMP") + 3, &myifd, olympus_tags, md);
 else
  readifd(offset, &myifd, olympus_tags, md);
 return (myifd);
}

variable_types:
offset
unsigned int

variable_types:
md
struct tiffmeta *

variable_types: struct ifd { unsigned int num; struct field { unsigned char tag[2]; unsigned char type[2]; unsigned char count[4]; unsigned char value[4]; } *fields; struct exifprop { unsigned int tag; unsigned int type; unsigned int count; unsigned int value; char *name; char *descr; char *str; unsigned short lvl; int ifdseq; unsigned int override; struct exiftag { unsigned int tag; unsigned int type; unsigned int count; unsigned short lvl; char *name; char *descr; struct descrip { int val; char *descr; } *table; } *tagset; struct exifprop *par; struct exifprop *next; } *par; struct exiftag *tagset; struct tiffmeta { enum byteorder { LITTLE=0, BIG=1 } order; unsigned char *btiff; unsigned char *etiff; void *ifdoffs; } md; struct ifd *next; } *

user_defined_types: struct ifd { unsigned int num; struct field *fields; struct exifprop *par; struct exiftag *tagset; struct tiffmeta md; struct ifd *next; }

user_defined_types: struct tiffmeta { enum byteorder order; unsigned char *btiff; unsigned char *etiff; void *ifdoffs; }

user_defined_types: struct exifprop { unsigned int tag; unsigned int type; unsigned int count; unsigned int value; char *name; char *descr; char *str; unsigned short lvl; int ifdseq; unsigned int override; struct exiftag *tagset; struct exifprop *par; struct exifprop *next; }

user_defined_types: struct exiftag { unsigned int tag; unsigned int type; unsigned int count; unsigned short lvl; char *name; char *descr; struct descrip *table; }


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

if ( !*(_WORD *)a1 && *(_DWORD *)(a1 + 4) == 4 )
{
exifstralloc(a1 + 32, 5LL);
result = byte4exif(*(unsigned int *)(a1 + 8), *(_QWORD *)(a1 + 32), 0LL);
}
return result;
}

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

if ( !*(_WORD *)a1 && *(_DWORD *)(a1 + 4) == 4 )
{
exifstralloc(a1 + 32, 5LL);
result = byte4exif(*(unsigned int *)(a1 + 8), *(_QWORD *)(a1 + 32), 0LL);
}
return result;
}

original_code:
void
fuji_prop(struct exifprop *prop, struct exiftags *t)
{
 switch (prop->tag) {
 case 0x0000:
  if (prop->count != 4)
   break;
  exifstralloc(&prop->str, prop->count + 1);
  byte4exif(prop->value, (unsigned char *)prop->str, LITTLE);
  break;
 }
}

variable_types: struct exifprop { unsigned int tag; unsigned int type; unsigned int count; unsigned int value; char *name; char *descr; char *str; unsigned short lvl; int ifdseq; unsigned int override; struct exiftag { unsigned int tag; unsigned int type; unsigned int count; unsigned short lvl; char *name; char *descr; struct descrip { int val; char *descr; } *table; } *tagset; struct exifprop *par; struct exifprop *next; } *

variable_types: struct exiftags { struct exifprop *props; struct tiffmeta { enum byteorder { LITTLE=0, BIG=1 } order; unsigned char *btiff; unsigned char *etiff; void *ifdoffs; } md; char *model; short mkrval; struct tiffmeta mkrmd; short exifmaj; short exifmin; } *

return_type: void

user_defined_types: struct exiftags { struct exifprop *props; struct tiffmeta md; char *model; short mkrval; struct tiffmeta mkrmd; short exifmaj; short exifmin; }


decompiled_code:
__int64 __fastcall fuji_ifd(unsigned int a1, __int64 a2)
{
__int64 v4; // r8
__int64 v5; // rdx
unsigned __int16 v6; // ax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = *(_QWORD *)(a2 + 8);
v5 = a1;
if ( !memcmp((const void *)(v4 + a1), "FUJIFILM", 8uLL) )
{
v6 = exif2byte(v4 + v5 + 8, 0LL);
*(_DWORD *)a2 = 0;
readifd(a1 + v6, v8, &fuji_tags, a2);
}
else
{
readifd(a1, v8, &fuji_tags, a2);
}
return v8[0];
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
__int64 v4; // r8
__int64 v5; // rdx
unsigned __int16 v6; // ax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = *(_QWORD *)(a2 + 8);
v5 = a1;
if ( !memcmp((const void *)(v4 + a1), "FUJIFILM", 8uLL) )
{
v6 = exif2byte(v4 + v5 + 8, 0LL);
*(_DWORD *)a2 = 0;
readifd(a1 + v6, v8, &fuji_tags, a2);
}
else
{
readifd(a1, v8, &fuji_tags, a2);
}
return v8[0];
}

original_code:
struct ifd *
fuji_ifd(u_int32_t offset, struct tiffmeta *md)
{
 struct ifd *myifd;
 int fujilen, fujioff;
 fujilen = strlen("FUJIFILM");
 if (!strncmp((const char *)(md->btiff + offset), "FUJIFILM", fujilen)) {
  fujioff = exif2byte(md->btiff + offset + fujilen, LITTLE);
  md->order = LITTLE;
  readifd(offset + fujioff, &myifd, fuji_tags, md);
 } else
  readifd(offset, &myifd, fuji_tags, md);
 return (myifd);
}

canonical_original_code:
struct ifd *fuji_ifd(unsigned int offset, struct tiffmeta *md)
{
 struct ifd *myifd;
 int fujilen; int fujioff;
 fujilen = strlen("FUJIFILM");
 if (!strncmp((char *)(md->btiff + offset), "FUJIFILM", fujilen)) {
  fujioff = exif2byte(md->btiff + offset + fujilen, LITTLE);
  md->order = LITTLE;
  readifd(offset + fujioff, &myifd, fuji_tags, md);
 } else
  readifd(offset, &myifd, fuji_tags, md);
 return (myifd);
}

variable_types: fujilen int

variable_types: fujioff int

return_type: struct ifd { unsigned int num; struct field { unsigned char tag[2]; unsigned char type[2]; unsigned char count[4]; unsigned char value[4]; } *fields; struct exifprop { unsigned int tag; unsigned int type; unsigned int count; unsigned int value; char *name; char *descr; char *str; unsigned short lvl; int ifdseq; unsigned int override; struct exiftag { unsigned int tag; unsigned int type; unsigned int count; unsigned short lvl; char *name; char *descr; struct descrip { int val; char *descr; } *table; } *tagset; struct exifprop *par; struct exifprop *next; } *par; struct exiftag *tagset; struct tiffmeta { enum byteorder { LITTLE=0, BIG=1 } order; unsigned char *btiff; unsigned char *etiff; void *ifdoffs; } md; struct ifd *next; } *


decompiled_code:
int __fastcall sigma_deprefix(void *dest, char *s2)
{
size_t v2; // rbx
int result; // eax
const char *v4; // rbx
size_t v5; // rax

v2 = (int)strlen(s2);
result = strncmp((const char *)dest, s2, v2);
if ( !result )
{
v4 = (char *)dest + v2;
v5 = strlen(v4);
result = (unsigned int)memmove(dest, v4, v5 + 1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(void *dest, char *s2)
{
size_t v2; // rbx
int result; // eax
const char *v4; // rbx
size_t v5; // rax

v2 = (int)strlen(s2);
result = strncmp((const char *)dest, s2, v2);
if ( !result )
{
v4 = (char *)dest + v2;
v5 = strlen(v4);
result = (unsigned int)memmove(dest, v4, v5 + 1);
}
return result;
}

original_code:
static void
sigma_deprefix(char *str, const char *prefix)
{
 int l;
 l = strlen(prefix);
 if (!strncmp(str, prefix, l))
  memmove(str, str + l, strlen(str + l) + 1);
}

canonical_original_code:
static void sigma_deprefix(char *str, char *prefix)
{
 int l;
 l = strlen(prefix);
 if (!strncmp(str, prefix, l))
  memmove(str, str + l, strlen(str + l) + 1);
}

variable_types:
str
char *

variable_types:
prefix
char *

variable_types: l int


decompiled_code:
int __fastcall sigma_prop(__int64 a1)
{
int result; // eax

if ( *(_WORD *)(a1 + 2) != 2 || *(_QWORD *)(a1 + 32) )
{
result = (unsigned __int16)(*(_WORD *)a1 - 12);
switch ( *(_WORD *)a1 )
{
case 0xC:
result = sigma_deprefix(*(void **)(a1 + 32), "Expo:");
break;
case 0xD:
result = sigma_deprefix(*(void **)(a1 + 32), "Cont:");
break;
case 0xE:
result = sigma_deprefix(*(void **)(a1 + 32), "Shad:");
break;
case 0xF:
result = sigma_deprefix(*(void **)(a1 + 32), "High:");
break;
case 0x10:
result = sigma_deprefix(*(void **)(a1 + 32), "Satu:");
break;
case 0x11:
result = sigma_deprefix(*(void **)(a1 + 32), "Shar:");
break;
case 0x12:
result = sigma_deprefix(*(void **)(a1 + 32), "Fill:");
break;
case 0x14:
result = sigma_deprefix(*(void **)(a1 + 32), "CC:");
break;
case 0x16:
result = sigma_deprefix(*(void **)(a1 + 32), "Qual:");
break;
default:
return result;
}
}
return result;
}

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

if ( *(_WORD *)(a1 + 2) != 2 || *(_QWORD *)(a1 + 32) )
{
result = (unsigned __int16)(*(_WORD *)a1 - 12);
switch ( *(_WORD *)a1 )
{
case 0xC:
result = func0(*(void **)(a1 + 32), "Expo:");
break;
case 0xD:
result = func0(*(void **)(a1 + 32), "Cont:");
break;
case 0xE:
result = func0(*(void **)(a1 + 32), "Shad:");
break;
case 0xF:
result = func0(*(void **)(a1 + 32), "High:");
break;
case 0x10:
result = func0(*(void **)(a1 + 32), "Satu:");
break;
case 0x11:
result = func0(*(void **)(a1 + 32), "Shar:");
break;
case 0x12:
result = func0(*(void **)(a1 + 32), "Fill:");
break;
case 0x14:
result = func0(*(void **)(a1 + 32), "CC:");
break;
case 0x16:
result = func0(*(void **)(a1 + 32), "Qual:");
break;
default:
return result;
}
}
return result;
}

original_code:
void
sigma_prop(struct exifprop *prop, struct exiftags *t)
{
 if (prop->type == 2 && !prop->str)
  return;
 switch (prop->tag) {
 case 0x000c:
  sigma_deprefix(prop->str, "Expo:");
  break;
 case 0x000d:
  sigma_deprefix(prop->str, "Cont:");
  break;
 case 0x000e:
  sigma_deprefix(prop->str, "Shad:");
  break;
 case 0x000f:
  sigma_deprefix(prop->str, "High:");
  break;
 case 0x0010:
  sigma_deprefix(prop->str, "Satu:");
  break;
 case 0x0011:
  sigma_deprefix(prop->str, "Shar:");
  break;
 case 0x0012:
  sigma_deprefix(prop->str, "Fill:");
  break;
 case 0x0014:
  sigma_deprefix(prop->str, "CC:");
  break;
 case 0x0016:
  sigma_deprefix(prop->str, "Qual:");
  break;
 }
}

user_defined_types: struct descrip { int val; char *descr; }


decompiled_code:
__int64 __fastcall sigma_ifd(unsigned int a1, __int64 a2)
{
const void *v2; // rbp

v2 = (const void *)(*(_QWORD *)(a2 + 8) + a1);
if ( memcmp("SIGMA", v2, 8uLL) || memcmp("FOVEON", v2, 8uLL) )
return readifds(a1 + 10, &sigma_tags, a2);
exifwarn("Sigma maker note version not supported");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
const void *v2; // rbp

v2 = (const void *)(*(_QWORD *)(a2 + 8) + a1);
if ( memcmp("SIGMA", v2, 8uLL) || memcmp("FOVEON", v2, 8uLL) )
return readifds(a1 + 10, &sigma_tags, a2);
exifwarn("Sigma maker note version not supported");
return 0LL;
}

original_code:
struct ifd *
sigma_ifd(u_int32_t offset, struct tiffmeta *md)
{
 if (memcmp("SIGMA\0\0\0", md->btiff + offset, 8) ||
     memcmp("FOVEON\0\0", md->btiff + offset, 8))
  return (readifds(offset + 10, sigma_tags, md));
 exifwarn("Sigma maker note version not supported");
 return (((void *)0));
}

canonical_original_code:
struct ifd *sigma_ifd(unsigned int offset, struct tiffmeta *md)
{
 if (memcmp("SIGMA\0\0\0", md->btiff + offset, 8) ||
     memcmp("FOVEON\0\0", md->btiff + offset, 8))
  return (readifds(offset + 10, sigma_tags, md));
 exifwarn("Sigma maker note version not supported");
 return (((void *)0));
}

user_defined_types: struct field { unsigned char tag[2]; unsigned char type[2]; unsigned char count[4]; unsigned char value[4]; }


original_code:
void
sanyo_prop(struct exifprop *prop, struct exiftags *t)
{
 int i, j;
 u_int32_t a, b;
 char *c1, *c2;
 struct exifprop *aprop;
 switch (prop->tag) {
 case 0x0200:
  if (debug)
   printf("Processing %s (0x%04X) directory, %d entries\n",
       prop->name, prop->tag, prop->count);
  for (i = 0; i < (int)prop->count; i++) {
   a = exif4byte(t->mkrmd.btiff + prop->value + i * 2,
       t->mkrmd.order);
   aprop = childprop(prop);
   aprop->value = a;
   aprop->tag = i;
   aprop->tagset = sanyo_shoottags;
   aprop->type = prop->type;
   aprop->count = 1;
   for (j = 0; sanyo_shoottags[j].tag < 0xffff &&
       sanyo_shoottags[j].tag != i; j++);
   aprop->name = sanyo_shoottags[j].name;
   aprop->descr = sanyo_shoottags[j].descr;
   aprop->lvl = sanyo_shoottags[j].lvl;
   if (sanyo_shoottags[j].table)
    aprop->str =
        finddescr(sanyo_shoottags[j].table,
        (u_int16_t)a);
   switch (aprop->tag) {
   case 0x0001:
    if (!aprop->value)
     aprop->lvl = 0x08;
    aprop->value += 1;
    break;
   }
   dumpprop(aprop, ((void *)0));
  }
  break;
 case 0x0201:
  c1 = finddescr(sanyo_quality,
      (u_int16_t)((prop->value >> 8) & 0xff));
  c2 = finddescr(sanyo_res, (u_int16_t)(prop->value & 0xff));
  exifstralloc(&prop->str, strlen(c1) + strlen(c2) + 3);
  sprintf(prop->str, "%s, %s", c1, c2);
  free(c1);
  free(c2);
  break;
 case 0x0204:
  a = exif4byte(t->mkrmd.btiff + prop->value, t->mkrmd.order);
  b = exif4byte(t->mkrmd.btiff + prop->value + 4, t->mkrmd.order);
  if (!a || !b || a == b)
   snprintf(prop->str, 31, "None");
  else
   snprintf(prop->str, 31, "x%.1f", (float)a / (float)b);
  break;
 case 0x0210:
  prop->str = finddescr(sanyo_offon, (u_int16_t)(!!prop->value));
  break;
 }
}

canonical_original_code:
void sanyo_prop(struct exifprop *prop, struct exiftags *t)
{
 int i; int j;
 unsigned int a; unsigned int b;
 char *c1; char *c2;
 struct exifprop *aprop;
 switch (prop->tag) {
 case 0x0200:
  if (debug)
   printf("Processing %s (0x%04X) directory, %d entries\n",
       prop->name, prop->tag, prop->count);
  for (i = 0; i < (int)prop->count; i++) {
   a = exif4byte(t->mkrmd.btiff + prop->value + i * 2,
       t->mkrmd.order);
   aprop = childprop(prop);
   aprop->value = a;
   aprop->tag = i;
   aprop->tagset = sanyo_shoottags;
   aprop->type = prop->type;
   aprop->count = 1;
   for (j = 0; sanyo_shoottags[j].tag < 0xffff &&
       sanyo_shoottags[j].tag != i; j++);
   aprop->name = sanyo_shoottags[j].name;
   aprop->descr = sanyo_shoottags[j].descr;
   aprop->lvl = sanyo_shoottags[j].lvl;
   if (sanyo_shoottags[j].table)
    aprop->str =
        finddescr(sanyo_shoottags[j].table,
        (unsigned int)a);
   switch (aprop->tag) {
   case 0x0001:
    if (!aprop->value)
     aprop->lvl = 0x08;
    aprop->value += 1;
    break;
   }
   dumpprop(aprop, ((void *)0));
  }
  break;
 case 0x0201:
  c1 = finddescr(sanyo_quality,
      (u_int16_t)((prop->value >> 8) & 0xff));
  c2 = finddescr(sanyo_res, (u_int16_t)(prop->value & 0xff));
  exifstralloc(&prop->str, strlen(c1) + strlen(c2) + 3);
  sprintf(prop->str, "%s, %s", c1, c2);
  free(c1);
  free(c2);
  break;
 case 0x0204:
  a = exif4byte(t->mkrmd.btiff + prop->value, t->mkrmd.order);
  b = exif4byte(t->mkrmd.btiff + prop->value + 4, t->mkrmd.order);
  if (!a || !b || a == b)
   snprintf(prop->str, 31, "None");
  else
   snprintf(prop->str, 31, "x%.1f", (float)a / (float)b);
  break;
 case 0x0210:
  prop->str = finddescr(sanyo_offon, (u_int16_t)(!!prop->value));
  break;
 }
}

variable_types: i int

variable_types: j int

variable_types:
a
unsigned int

variable_types:
b
unsigned int


decompiled_code:
__int64 __fastcall sanyo_ifd(unsigned int a1, __int64 a2)
{
__int64 v3[2]; // [rsp+8h] [rbp-10h] BYREF

if ( !strcmp((const char *)(*(_QWORD *)(a2 + 8) + a1), "SANYO") )
readifd(a1 + 8, v3, &sanyo_tags, a2);
else
readifd(a1, v3, &sanyo_tags, a2);
return v3[0];
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
__int64 v3[2]; // [rsp+8h] [rbp-10h] BYREF

if ( !strcmp((const char *)(*(_QWORD *)(a2 + 8) + a1), "SANYO") )
readifd(a1 + 8, v3, &sanyo_tags, a2);
else
readifd(a1, v3, &sanyo_tags, a2);
return v3[0];
}

original_code:
struct ifd *
sanyo_ifd(u_int32_t offset, struct tiffmeta *md)
{
 struct ifd *myifd;
 if (!strcmp((const char *)(md->btiff + offset), "SANYO"))
  readifd(offset + strlen("SANYO") + 3, &myifd, sanyo_tags, md);
 else
  readifd(offset, &myifd, sanyo_tags, md);
 return (myifd);
}

canonical_original_code:
struct ifd *sanyo_ifd(unsigned int offset, struct tiffmeta *md)
{
 struct ifd *myifd;
 if (!strcmp((char *)(md->btiff + offset), "SANYO"))
  readifd(offset + strlen("SANYO") + 3, &myifd, sanyo_tags, md);
 else
  readifd(offset, &myifd, sanyo_tags, md);
 return (myifd);
}


decompiled_code:
__int64 __fastcall leica_prop(unsigned __int16 *a1)
{
__int64 result; // rax

if ( *((_UNKNOWN **)a1 + 7) != &leica_tags )
return fuji_prop();
result = *a1;
if ( (_WORD)result == 3 )
{
a1[24] = -23549;
}
else if ( (_WORD)result == 44 )
{
a1[24] = -23544;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 *a1)
{
__int64 result; // rax

if ( *((_UNKNOWN **)a1 + 7) != &leica_tags )
return fuji_prop();
result = *a1;
if ( (_WORD)result == 3 )
{
a1[24] = -23549;
}
else if ( (_WORD)result == 44 )
{
a1[24] = -23544;
}
return result;
}

original_code:
void
leica_prop(struct exifprop *prop, struct exiftags *t)
{
 if (prop->tagset != leica_tags) {
  fuji_prop(prop, t);
  return;
 }
 switch (prop->tag) {
 case 0x0003:
  prop->override = 0xa403;
  break;
 case 0x002c:
  prop->override = 0xa408;
  break;
 }
}


decompiled_code:
__int64 __fastcall leica_ifd(unsigned int a1, __int64 a2)
{
const void *v4; // rax

v4 = (const void *)(*(_QWORD *)(a2 + 8) + a1);
if ( !memcmp(v4, "FUJIFILM", 8uLL) )
return fuji_ifd(a1, a2);
if ( !memcmp(v4, "LEICA", 5uLL) )
return readifds(a1 + 8, &leica_tags, a2);
return readifds(a1, &leica_tags, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
const void *v4; // rax

v4 = (const void *)(*(_QWORD *)(a2 + 8) + a1);
if ( !memcmp(v4, "FUJIFILM", 8uLL) )
return fuji_ifd(a1, a2);
if ( !memcmp(v4, "LEICA", 5uLL) )
return readifds(a1 + 8, &leica_tags, a2);
return readifds(a1, &leica_tags, a2);
}

original_code:
struct ifd *
leica_ifd(u_int32_t offset, struct tiffmeta *md)
{
 if (!strncmp((const char *)(md->btiff + offset), "FUJIFILM", 8))
  return (fuji_ifd(offset, md));
 if (!strncmp((const char *)(md->btiff + offset), "LEICA", 5))
  return (readifds(offset + 8, leica_tags, md));
 return (readifds(offset, leica_tags, md));
}

canonical_original_code:
struct ifd *leica_ifd(unsigned int offset, struct tiffmeta *md)
{
 if (!strncmp((char *)(md->btiff + offset), "FUJIFILM", 8))
  return (fuji_ifd(offset, md));
 if (!strncmp((char *)(md->btiff + offset), "LEICA", 5))
  return (readifds(offset + 8, leica_tags, md));
 return (readifds(offset, leica_tags, md));
}


decompiled_code:
__int64 __fastcall casio_ifd(unsigned int a1, __int64 a2)
{
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !memcmp(&unk_5C1, (const void *)(*(_QWORD *)(a2 + 8) + a1), 6uLL) )
{
readifd(a1 + 6, v3, &casio_tags1, a2);
exifwarn("Casio maker note version not supported");
}
else
{
readifd(a1, v3, &casio_tags0, a2);
}
return v3[0];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !memcmp(&unk_5C1, (const void *)(*(_QWORD *)(a2 + 8) + a1), 6uLL) )
{
readifd(a1 + 6, v3, &casio_tags1, a2);
exifwarn("Casio maker note version not supported");
}
else
{
readifd(a1, v3, &casio_tags0, a2);
}
return v3[0];
}

original_code:
struct ifd *
casio_ifd(u_int32_t offset, struct tiffmeta *md)
{
 struct ifd *myifd;
 if (!memcmp("QVC\0\0\0", md->btiff + offset, 6)) {
  readifd(offset + strlen("QVC") + 3, &myifd, casio_tags1, md);
  exifwarn("Casio maker note version not supported");
 } else
  readifd(offset, &myifd, casio_tags0, md);
 return (myifd);
}

canonical_original_code:
struct ifd *casio_ifd(unsigned int offset, struct tiffmeta *md)
{
 struct ifd *myifd;
 if (!memcmp("QVC\0\0\0", md->btiff + offset, 6)) {
  readifd(offset + strlen("QVC") + 3, &myifd, casio_tags1, md);
  exifwarn("Casio maker note version not supported");
 } else
  readifd(offset, &myifd, casio_tags0, md);
 return (myifd);
}


decompiled_code:
__int64 __fastcall minolta_naval(__int64 a1, __int64 a2, unsigned __int16 a3)
{
__int64 result; // rax
__int64 v4; // rbx

result = findprop(a1, a2, a3);
if ( result )
{
v4 = result;
free(*(void **)(result + 32));
*(_QWORD *)(v4 + 32) = 0LL;
exifstralloc(v4 + 32, 4LL);
result = *(_QWORD *)(v4 + 32);
*(_DWORD *)result = 6369134;
if ( (*(_BYTE *)(v4 + 40) & 1) == 0 )
*(_WORD *)(v4 + 40) = 8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned __int16 a3)
{
__int64 result; // rax
__int64 v4; // rbx

result = findprop(a1, a2, a3);
if ( result )
{
v4 = result;
free(*(void **)(result + 32));
*(_QWORD *)(v4 + 32) = 0LL;
exifstralloc(v4 + 32, 4LL);
result = *(_QWORD *)(v4 + 32);
*(_DWORD *)result = 6369134;
if ( (*(_BYTE *)(v4 + 40) & 1) == 0 )
*(_WORD *)(v4 + 40) = 8;
}
return result;
}

original_code:
static void
minolta_naval(struct exifprop *props, struct exiftag *tags, int16_t tag)
{
 struct exifprop *prop;
 const char *na = "n/a";
 if (!(prop = findprop(props, tags, tag)))
  return;
 free(prop->str);
 prop->str = ((void *)0);
 exifstralloc(&prop->str, strlen(na) + 1);
 strcpy(prop->str, na);
 if (!(prop->lvl & 0x01))
  prop->lvl = 0x08;
}

canonical_original_code:
static void minolta_naval(struct exifprop *props, struct exiftag *tags, short tag)
{
 struct exifprop *prop;
 char *na = "n/a";
 if (!(prop = findprop(props, tags, tag)))
  return;
 free(prop->str);
 prop->str = ((void *)0);
 exifstralloc(&prop->str, strlen(na) + 1);
 strcpy(prop->str, na);
 if (!(prop->lvl & 0x01))
  prop->lvl = 0x08;
}

variable_types:
tags
struct exiftag *

variable_types: tag short


original_code:
void
minolta_cprop(struct exifprop *prop, unsigned char *off, struct exiftags *t,
    struct exiftag *thetags)
{
 unsigned int i, j, k;
 u_int32_t v;
 int32_t model;
 double d;
 char *valbuf;
 unsigned char buf[8];
 struct exifprop *aprop;
 valbuf = ((void *)0);
 model = -1;
 for (i = 0; i * 4 < prop->count; i++) {
  if (thetags == minolta_MLT0 && i >= 51 && model == 5) {
   if (i == 51) continue;
   k = i - 1;
  } else
   k = i;
  aprop = childprop(prop);
  aprop->tag = i;
  aprop->tagset = thetags;
  aprop->value = exif4byte(off + (4 * i), BIG);
  for (j = 0; thetags[j].tag < 0xffff &&
   thetags[j].tag != k; j++);
  aprop->name = thetags[j].name;
  aprop->descr = thetags[j].descr;
  aprop->lvl = thetags[j].lvl;
  if (thetags[j].table)
   aprop->str = finddescr(thetags[j].table,
       (u_int16_t)aprop->value);
  dumpprop(aprop, ((void *)0));
  if (thetags != minolta_MLT0)
   continue;
  if (!valbuf)
   exifstralloc(&valbuf, 16);
  switch (k) {
  case 16:
  case 27:
   aprop->value += 1;
   break;
  case 13:
  case 35:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   if (aprop->value != 6)
    snprintf(aprop->str, 15, "%+0.1f EV",
        ((double)aprop->value - 6) / 3);
   else
    snprintf(aprop->str, 15, "Normal");
   break;
  case 37:
   model = aprop->value;
   break;
  case 18:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   snprintf(aprop->str, 15, "%02f",
       (double)aprop->value / 256);
   break;
  case 28:
  case 29:
  case 30:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   snprintf(aprop->str, 15, "%0.6f",
       (double)aprop->value / 256);
   break;
  case 8:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   v = (u_int16_t)(pow(2, ((double)aprop->value / 8) -
       1) * (double)3.125);
   snprintf(aprop->str, 15, "%d", v);
   break;
  case 10:
  case 23:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   d = pow(2, ((double)aprop->value / 16) - 0.5);
   snprintf(aprop->str, 15, "%0.1f", d);
   break;
  case 9:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   d = (double)pow(2,
       ((double)abs(48 - aprop->value)) / 8);
   if (aprop->value < 56)
    snprintf(aprop->str, 15, "%0.1f", d);
   else
    snprintf(aprop->str, 15, "1/%d",
        (unsigned int)d);
   break;
  case 19:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   if (!aprop->value)
    strcpy(aprop->str, "Infinite");
   else
    snprintf(aprop->str, 15, "%.1f",
        (float)(aprop->value / (float)1000));
   aprop->value /= 100;
   break;
  case 1:
   aprop->override = 0x8822;
   break;
  case 21:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   byte4exif(aprop->value, buf, LITTLE);
   snprintf(aprop->str, 15, "%02d/%02d/%04d",
       buf[0], buf[1], buf[3] << 8 | buf[2]);
   break;
  case 22:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   byte4exif(aprop->value, buf, LITTLE);
   snprintf(aprop->str, 9, "%02d:%02d:%02d",
       buf[2], buf[1], buf[0]);
   break;
  case 3:
   aprop->override = 0xa403;
   break;
  case 33:
   aprop->override = 0xa40a;
   break;
  case 7:
   aprop->override = 0x9207;
   break;
  case 31:
  case 32:
   aprop->override = (i == 31 ? 0xa409 :
       0xa408);
  case 41:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   aprop->value -= 3;
   if (aprop->value)
    snprintf(aprop->str, 15, "%+d", aprop->value);
   else
    strcpy(aprop->str, "Normal");
   break;
  case 34:
   aprop->override = 0xa406;
   break;
  }
 }
 if (valbuf)
  free(valbuf);
}

canonical_original_code:
void minolta_cprop(struct exifprop *prop, unsigned char *off, struct exiftags *t, struct exiftag *thetags)
{
 unsigned int i; unsigned int j; unsigned int k;
 unsigned int v;
 int model;
 double d;
 char *valbuf;
 unsigned char buf[8];
 struct exifprop *aprop;
 valbuf = ((void *)0);
 model = -1;
 for (i = 0; i * 4 < prop->count; i++) {
  if (thetags == minolta_MLT0 && i >= 51 && model == 5) {
   if (i == 51) continue;
   k = i - 1;
  } else
   k = i;
  aprop = childprop(prop);
  aprop->tag = i;
  aprop->tagset = thetags;
  aprop->value = exif4byte(off + (4 * i), BIG);
  for (j = 0; thetags[j].tag < 0xffff &&
   thetags[j].tag != k; j++);
  aprop->name = thetags[j].name;
  aprop->descr = thetags[j].descr;
  aprop->lvl = thetags[j].lvl;
  if (thetags[j].table)
   aprop->str = finddescr(thetags[j].table,
       (unsigned int)aprop->value);
  dumpprop(aprop, ((void *)0));
  if (thetags != minolta_MLT0)
   continue;
  if (!valbuf)
   exifstralloc(&valbuf, 16);
  switch (k) {
  case 16:
  case 27:
   aprop->value += 1;
   break;
  case 13:
  case 35:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   if (aprop->value != 6)
    snprintf(aprop->str, 15, "%+0.1f EV",
        ((double)aprop->value - 6) / 3);
   else
    snprintf(aprop->str, 15, "Normal");
   break;
  case 37:
   model = aprop->value;
   break;
  case 18:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   snprintf(aprop->str, 15, "%02f",
       (double)aprop->value / 256);
   break;
  case 28:
  case 29:
  case 30:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   snprintf(aprop->str, 15, "%0.6f",
       (double)aprop->value / 256);
   break;
  case 8:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   v = (u_int16_t)(pow(2, ((double)aprop->value / 8) -
       1) * (double)3.125);
   snprintf(aprop->str, 15, "%d", v);
   break;
  case 10:
  case 23:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   d = pow(2, ((double)aprop->value / 16) - 0.5);
   snprintf(aprop->str, 15, "%0.1f", d);
   break;
  case 9:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   d = (double)pow(2,
       ((double)abs(48 - aprop->value)) / 8);
   if (aprop->value < 56)
    snprintf(aprop->str, 15, "%0.1f", d);
   else
    snprintf(aprop->str, 15, "1/%d",
        (unsigned int)d);
   break;
  case 19:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   if (!aprop->value)
    strcpy(aprop->str, "Infinite");
   else
    snprintf(aprop->str, 15, "%.1f",
        (float)(aprop->value / (float)1000));
   aprop->value /= 100;
   break;
  case 1:
   aprop->override = 0x8822;
   break;
  case 21:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   byte4exif(aprop->value, buf, LITTLE);
   snprintf(aprop->str, 15, "%02d/%02d/%04d",
       buf[0], buf[1], buf[3] << 8 | buf[2]);
   break;
  case 22:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   byte4exif(aprop->value, buf, LITTLE);
   snprintf(aprop->str, 9, "%02d:%02d:%02d",
       buf[2], buf[1], buf[0]);
   break;
  case 3:
   aprop->override = 0xa403;
   break;
  case 33:
   aprop->override = 0xa40a;
   break;
  case 7:
   aprop->override = 0x9207;
   break;
  case 31:
  case 32:
   aprop->override = (i == 31 ? 0xa409 :
       0xa408);
  case 41:
   aprop->str = valbuf;
   valbuf = ((void *)0);
   aprop->value -= 3;
   if (aprop->value)
    snprintf(aprop->str, 15, "%+d", aprop->value);
   else
    strcpy(aprop->str, "Normal");
   break;
  case 34:
   aprop->override = 0xa406;
   break;
  }
 }
 if (valbuf)
  free(valbuf);
}

variable_types:
off
unsigned char *

variable_types:
thetags
struct exiftag *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
k
unsigned int

variable_types:
v
unsigned int

variable_types: model int

variable_types: d double

variable_types:
valbuf
char *

variable_types:
buf
unsigned char [8]


decompiled_code:
char __fastcall minolta_prop(__int64 a1, __int64 *a2, __int64 a3, __int64 a4)
{
__int64 v5; // rax
unsigned int v6; // esi
bool v7; // zf
char *v8; // r12
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax

if ( debug )
{
if ( !once_0 )
{
puts("Processing Minolta Maker Note");
once_0 = 1;
}
dumpprop(a1, 0LL, a3, a4);
}
LOWORD(v5) = *(_WORD *)a1;
if ( *(_WORD *)a1 == 1 )
{
v8 = (char *)&minolta_MLT0;
if ( *(_DWORD *)(a1 + 4) != 156 )
{
exifwarn("Minolta maker note not fully supported");
v8 = (char *)&minolta_unkn;
}
}
else
{
if ( (_WORD)v5 != 3 )
{
if ( !(_WORD)v5 )
{
v6 = *(_DWORD *)(a1 + 4);
if ( v6 > 3 )
{
exifstralloc(a1 + 32, v6 + 1);
byte4exif(*(unsigned int *)(a1 + 8), *(_QWORD *)(a1 + 32), *((unsigned int *)a2 + 14));
v7 = strcmp(*(const char **)(a1 + 32), "MLT0") == 0;
LOBYTE(v5) = !v7;
if ( !v7 )
{
v7 = strcmp(*(const char **)(a1 + 32), "mlt0") == 0;
LOBYTE(v5) = !v7;
if ( !v7 )
LOBYTE(v5) = exifwarn2("Minolta maker note version not supported", *(_QWORD *)(a1 + 32));
}
}
}
return v5;
}
v8 = (char *)&minolta_MLT0;
if ( (*(_DWORD *)(a1 + 4) & 0xFFFFFFFB) != 224 )
{
exifwarn("Minolta maker note not fully supported");
v8 = (char *)&minolta_unkn;
}
}
minolta_cprop(a1, a2[8] + *(unsigned int *)(a1 + 8), (__int64)a2, v8);
v9 = findprop(*a2, v8, 6LL);
if ( v9 && *(_DWORD *)(v9 + 8) != 4 )
{
minolta_naval(*a2, (__int64)v8, 0xEu);
minolta_naval(*a2, (__int64)v8, 0x32u);
}
v10 = findprop(*a2, v8, 48LL);
if ( v10 && *(_DWORD *)(v10 + 8) == 1 )
{
minolta_naval(*a2, (__int64)v8, 0x2Du);
minolta_naval(*a2, (__int64)v8, 0x2Eu);
minolta_naval(*a2, (__int64)v8, 0x2Fu);
minolta_naval(*a2, (__int64)v8, 0x31u);
}
v11 = findprop(*a2, v8, 20LL);
if ( v11 && *(_DWORD *)(v11 + 8) != 1 )
{
minolta_naval(*a2, (__int64)v8, 2u);
minolta_naval(*a2, (__int64)v8, 0x23u);
minolta_naval(*a2, (__int64)v8, 0x2Bu);
}
v12 = findprop(*a2, &tags, 41986LL);
if ( v12 && *(_DWORD *)(v12 + 8) == 1 )
{
minolta_naval(*a2, (__int64)v8, 7u);
minolta_naval(*a2, (__int64)v8, 0xDu);
}
v13 = findprop(*a2, v8, 1LL);
if ( v13 && *(_DWORD *)(v13 + 8) )
minolta_naval(*a2, (__int64)v8, 0x22u);
v5 = findprop(*a2, v8, 38LL);
if ( v5 && *(_DWORD *)(v5 + 8) != 1 )
{
minolta_naval(*a2, (__int64)v8, 0x10u);
LOBYTE(v5) = minolta_naval(*a2, (__int64)v8, 0x11u);
}
return v5;
}

canonical_decompiled_code:
char __fastcall func2(__int64 a1, __int64 *a2, __int64 a3, __int64 a4)
{
__int64 v5; // rax
unsigned int v6; // esi
bool v7; // zf
char *v8; // r12
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax

if ( debug )
{
if ( !once_0 )
{
puts("Processing Minolta Maker Note");
once_0 = 1;
}
dumpprop(a1, 0LL, a3, a4);
}
LOWORD(v5) = *(_WORD *)a1;
if ( *(_WORD *)a1 == 1 )
{
v8 = (char *)&minolta_MLT0;
if ( *(_DWORD *)(a1 + 4) != 156 )
{
exifwarn("Minolta maker note not fully supported");
v8 = (char *)&minolta_unkn;
}
}
else
{
if ( (_WORD)v5 != 3 )
{
if ( !(_WORD)v5 )
{
v6 = *(_DWORD *)(a1 + 4);
if ( v6 > 3 )
{
exifstralloc(a1 + 32, v6 + 1);
byte4exif(*(unsigned int *)(a1 + 8), *(_QWORD *)(a1 + 32), *((unsigned int *)a2 + 14));
v7 = strcmp(*(const char **)(a1 + 32), "MLT0") == 0;
LOBYTE(v5) = !v7;
if ( !v7 )
{
v7 = strcmp(*(const char **)(a1 + 32), "mlt0") == 0;
LOBYTE(v5) = !v7;
if ( !v7 )
LOBYTE(v5) = exifwarn2("Minolta maker note version not supported", *(_QWORD *)(a1 + 32));
}
}
}
return v5;
}
v8 = (char *)&minolta_MLT0;
if ( (*(_DWORD *)(a1 + 4) & 0xFFFFFFFB) != 224 )
{
exifwarn("Minolta maker note not fully supported");
v8 = (char *)&minolta_unkn;
}
}
func1(a1, a2[8] + *(unsigned int *)(a1 + 8), (__int64)a2, v8);
v9 = findprop(*a2, v8, 6LL);
if ( v9 && *(_DWORD *)(v9 + 8) != 4 )
{
func0(*a2, (__int64)v8, 0xEu);
func0(*a2, (__int64)v8, 0x32u);
}
v10 = findprop(*a2, v8, 48LL);
if ( v10 && *(_DWORD *)(v10 + 8) == 1 )
{
func0(*a2, (__int64)v8, 0x2Du);
func0(*a2, (__int64)v8, 0x2Eu);
func0(*a2, (__int64)v8, 0x2Fu);
func0(*a2, (__int64)v8, 0x31u);
}
v11 = findprop(*a2, v8, 20LL);
if ( v11 && *(_DWORD *)(v11 + 8) != 1 )
{
func0(*a2, (__int64)v8, 2u);
func0(*a2, (__int64)v8, 0x23u);
func0(*a2, (__int64)v8, 0x2Bu);
}
v12 = findprop(*a2, &tags, 41986LL);
if ( v12 && *(_DWORD *)(v12 + 8) == 1 )
{
func0(*a2, (__int64)v8, 7u);
func0(*a2, (__int64)v8, 0xDu);
}
v13 = findprop(*a2, v8, 1LL);
if ( v13 && *(_DWORD *)(v13 + 8) )
func0(*a2, (__int64)v8, 0x22u);
v5 = findprop(*a2, v8, 38LL);
if ( v5 && *(_DWORD *)(v5 + 8) != 1 )
{
func0(*a2, (__int64)v8, 0x10u);
LOBYTE(v5) = func0(*a2, (__int64)v8, 0x11u);
}
return v5;
}

original_code:
void
minolta_prop(struct exifprop *prop, struct exiftags *t)
{
 struct exiftag *fielddefs = ((void *)0);
 struct exifprop *tmpprop;
 if (debug) {
  static int once = 0;
  if (!once) {
   printf("Processing Minolta Maker Note\n");
   once = 1;
  }
  dumpprop(prop, ((void *)0));
 }
 switch (prop->tag) {
 case 0x0000:
  if (prop->count < 4)
   break;
  exifstralloc(&prop->str, prop->count + 1);
  byte4exif(prop->value, (unsigned char *)prop->str,
      t->mkrmd.order);
  if (strcmp(prop->str, "MLT0") && strcmp(prop->str, "mlt0"))
   exifwarn2("Minolta maker note version not supported",
       prop->str);
  break;
 case 0x0001:
  if (prop->count != 39 * 4) {
   exifwarn("Minolta maker note not fully supported");
   fielddefs = minolta_unkn;
  } else
   fielddefs = minolta_MLT0;
  minolta_cprop(prop, t->mkrmd.btiff + prop->value, t, fielddefs);
  break;
 case 0x0003:
  if (prop->count != 56 * 4 && prop->count != 57 * 4) {
   exifwarn("Minolta maker note not fully supported");
   fielddefs = minolta_unkn;
  } else
   fielddefs = minolta_MLT0;
  minolta_cprop(prop, t->mkrmd.btiff + prop->value, t, fielddefs);
  break;
 }
 if (fielddefs) {
  if ((tmpprop = findprop(t->props, fielddefs, 6)))
   if (tmpprop->value != 4) {
    minolta_naval(t->props, fielddefs, 14);
    minolta_naval(t->props, fielddefs, 50);
   }
  if ((tmpprop = findprop(t->props, fielddefs, 48)))
   if (tmpprop->value == 1) {
    minolta_naval(t->props, fielddefs, 45);
    minolta_naval(t->props, fielddefs, 46);
    minolta_naval(t->props, fielddefs, 47);
    minolta_naval(t->props, fielddefs, 49);
   }
  if ((tmpprop = findprop(t->props, fielddefs, 20)))
   if (tmpprop->value != 1) {
    minolta_naval(t->props, fielddefs, 2);
    minolta_naval(t->props, fielddefs, 35);
    minolta_naval(t->props, fielddefs, 43);
   }
  if ((tmpprop = findprop(t->props, tags, 0xa402)))
   if (tmpprop->value == 1) {
    minolta_naval(t->props, fielddefs, 7);
    minolta_naval(t->props, fielddefs, 13);
   }
  if ((tmpprop = findprop(t->props, fielddefs, 1)))
   if (tmpprop->value != 0)
    minolta_naval(t->props, fielddefs, 34);
  if ((tmpprop = findprop(t->props, fielddefs, 38)))
   if (tmpprop->value != 1) {
    minolta_naval(t->props, fielddefs, 16);
    minolta_naval(t->props, fielddefs, 17);
   }
 }
}

variable_types: struct exifprop { unsigned int tag; unsigned int type; unsigned int count; unsigned int value; char *name; char *descr; char *str; unsigned short lvl; int ifdseq; unsigned int override; struct exiftag { unsigned int tag; unsigned int type; unsigned int count; unsigned short lvl; char *name; char *descr; struct descrip { int val; char *descr; } *table; } *tagset; struct exifprop *par; struct exifprop *next; } *

variable_types: struct exiftags { struct exifprop *props; struct tiffmeta { enum byteorder { LITTLE=0, BIG=1 } order; unsigned char *btiff; unsigned char *etiff; void *ifdoffs; } md; char *model; short mkrval; struct tiffmeta mkrmd; short exifmaj; short exifmin; } *

variable_types: once int


decompiled_code:
__int64 __fastcall minolta_ifd(unsigned int a1, unsigned int *a2)
{
const char *v2; // rdx

v2 = (const char *)(*((_QWORD *)a2 + 1) + a1);
if ( strcmp(v2, "+M")
&& (unsigned __int16)exif2byte(v2, *a2) <= 0xFFu
&& (unsigned __int16)exif2byte(*((_QWORD *)a2 + 1) + a1, *a2) > 1u )
{
return readifds(a1, &minolta_tags, a2);
}
exifwarn("Minolta maker note version not supported");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int *a2)
{
const char *v2; // rdx

v2 = (const char *)(*((_QWORD *)a2 + 1) + a1);
if ( strcmp(v2, "+M")
&& (unsigned __int16)exif2byte(v2, *a2) <= 0xFFu
&& (unsigned __int16)exif2byte(*((_QWORD *)a2 + 1) + a1, *a2) > 1u )
{
return readifds(a1, &minolta_tags, a2);
}
exifwarn("Minolta maker note version not supported");
return 0LL;
}

original_code:
struct ifd *
minolta_ifd(u_int32_t offset, struct tiffmeta *md)
{
 if (!strcmp((const char *)(md->btiff + offset), "+M")) {
  exifwarn("Minolta maker note version not supported");
  return (((void *)0));
 }
 if (exif2byte(md->btiff + offset, md->order) > 0xff ||
     exif2byte(md->btiff + offset, md->order) < 0x02) {
  exifwarn("Minolta maker note version not supported");
  return (((void *)0));
 }
 return (readifds(offset, minolta_tags, md));
}

canonical_original_code:
struct ifd *minolta_ifd(unsigned int offset, struct tiffmeta *md)
{
 if (!strcmp((char *)(md->btiff + offset), "+M")) {
  exifwarn("Minolta maker note version not supported");
  return (((void *)0));
 }
 if (exif2byte(md->btiff + offset, md->order) > 0xff ||
     exif2byte(md->btiff + offset, md->order) < 0x02) {
  exifwarn("Minolta maker note version not supported");
  return (((void *)0));
 }
 return (readifds(offset, minolta_tags, md));
}

variable_types:
offset
unsigned int

variable_types:
md
struct tiffmeta *


printprops

decompiled_code:
void __fastcall printprops(__int64 a1, unsigned __int16 a2, int a3)
{
__int64 v3; // rbx
__int16 v6; // ax
const char *v7; // rsi
const char *v8; // rcx

v3 = a1;
if ( !quiet )
{
if ( prevf_0 == fnum )
putchar(10);
else
prevf_0 = fnum;
if ( a2 == 4 )
{
puts("Image-Specific Properties:\n");
}
else if ( a2 > 4u )
{
if ( a2 == 8 )
{
puts("Other Properties:\n");
}
else if ( a2 == 64 )
{
puts("Invalid Properties:\n");
}
}
else if ( a2 == 1 )
{
puts("Unsupported Properties:\n");
}
else if ( a2 == 2 )
{
puts("Camera-Specific Properties:\n");
}
}
if ( a1 )
{
do
{
v6 = *(_WORD *)(v3 + 40);
if ( v6 == 16 )
{
*(_WORD *)(v3 + 40) = a3 == 0 ? 4 : 2;
}
else if ( v6 == 32 )
{
*(_WORD *)(v3 + 40) = 8;
}
if ( *(_WORD *)(v3 + 40) == a2 )
{
v7 = *(const char **)(v3 + 24);
if ( !v7 )
v7 = *(const char **)(v3 + 16);
v8 = *(const char **)(v3 + 32);
if ( v8 )
printf("%s%s%s\n", v7, delim, v8);
else
printf("%s%s%d\n", v7, delim, *(unsigned int *)(v3 + 8));
}
v3 = *(_QWORD *)(v3 + 72);
}
while ( v3 );
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned __int16 a2, int a3)
{
__int64 v3; // rbx
__int16 v6; // ax
const char *v7; // rsi
const char *v8; // rcx

v3 = a1;
if ( !quiet )
{
if ( prevf_0 == fnum )
putchar(10);
else
prevf_0 = fnum;
if ( a2 == 4 )
{
puts("Image-Specific Properties:\n");
}
else if ( a2 > 4u )
{
if ( a2 == 8 )
{
puts("Other Properties:\n");
}
else if ( a2 == 64 )
{
puts("Invalid Properties:\n");
}
}
else if ( a2 == 1 )
{
puts("Unsupported Properties:\n");
}
else if ( a2 == 2 )
{
puts("Camera-Specific Properties:\n");
}
}
if ( a1 )
{
do
{
v6 = *(_WORD *)(v3 + 40);
if ( v6 == 16 )
{
*(_WORD *)(v3 + 40) = a3 == 0 ? 4 : 2;
}
else if ( v6 == 32 )
{
*(_WORD *)(v3 + 40) = 8;
}
if ( *(_WORD *)(v3 + 40) == a2 )
{
v7 = *(const char **)(v3 + 24);
if ( !v7 )
v7 = *(const char **)(v3 + 16);
v8 = *(const char **)(v3 + 32);
if ( v8 )
printf("%s%s%s\n", v7, delim, v8);
else
printf("%s%s%d\n", v7, delim, *(unsigned int *)(v3 + 8));
}
v3 = *(_QWORD *)(v3 + 72);
}
while ( v3 );
}
}

original_code:
static void
printprops(struct exifprop *list, unsigned short lvl, int pas)
{
 static int prevf = -1;
 const char *n;
 if (!quiet) {
  if (prevf == fnum)
   printf("\n");
  else
   prevf = fnum;
  switch (lvl) {
  case 0x01:
   printf("Unsupported Properties:\n\n");
   break;
  case 0x02:
   printf("Camera-Specific Properties:\n\n");
   break;
  case 0x04:
   printf("Image-Specific Properties:\n\n");
   break;
  case 0x08:
   printf("Other Properties:\n\n");
   break;
  case 0x40:
   printf("Invalid Properties:\n\n");
   break;
  }
 }
 while (list) {
  if (list->lvl == 0x10)
   list->lvl = pas ? 0x02 : 0x04;
  if (list->lvl == 0x20)
   list->lvl = 0x08;
  if (list->lvl == lvl) {
   n = list->descr ? list->descr : list->name;
   if (list->str)
    printf("%s%s%s\n", n, delim, list->str);
   else
    printf("%s%s%d\n", n, delim, list->value);
  }
  list = list->next;
 }
}

canonical_original_code:
static void printprops(struct exifprop *list, unsigned short lvl, int pas)
{
 static int prevf = -1;
 char *n;
 if (!quiet) {
  if (prevf == fnum)
   printf("\n");
  else
   prevf = fnum;
  switch (lvl) {
  case 0x01:
   printf("Unsupported Properties:\n\n");
   break;
  case 0x02:
   printf("Camera-Specific Properties:\n\n");
   break;
  case 0x04:
   printf("Image-Specific Properties:\n\n");
   break;
  case 0x08:
   printf("Other Properties:\n\n");
   break;
  case 0x40:
   printf("Invalid Properties:\n\n");
   break;
  }
 }
 while (list) {
  if (list->lvl == 0x10)
   list->lvl = pas ? 0x02 : 0x04;
  if (list->lvl == 0x20)
   list->lvl = 0x08;
  if (list->lvl == lvl) {
   n = list->descr ? list->descr : list->name;
   if (list->str)
    printf("%s%s%s\n", n, delim, list->str);
   else
    printf("%s%s%d\n", n, delim, list->value);
  }
  list = list->next;
 }
}

variable_types:
lvl
unsigned short

variable_types: pas int

variable_types: prevf int

variable_types:
n
char *


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"Usage: %s [options] [files]\nDisplays Exif data from the specified files or standard input.\n",
progname);
fprintf(stderr, "Version: %s\n\n", "1.01");
fwrite("Available options:\n", 1uLL, 0x13uLL, stderr);
fwrite(" -a\tDisplay camera-specific, image-specific, and verbose properties.\n", 1uLL, 0x46uLL, stderr);
fwrite(" -c\tDisplay camera-specific properties.\n", 1uLL, 0x29uLL, stderr);
fwrite(" -i\tDisplay image-specific properties.\n", 1uLL, 0x28uLL, stderr);
fwrite(" -v\tDisplay verbose properties.\n", 1uLL, 0x21uLL, stderr);
fwrite(" -u\tDisplay unknown/unsupported properties (also invalid props w/debug).\n", 1uLL, 0x4AuLL, stderr);
fwrite(" -l\tCamera has a removable lens.\n", 1uLL, 0x22uLL, stderr);
fwrite(" -d\tDisplay parse debug information.\n", 1uLL, 0x26uLL, stderr);
fwrite(" -q\tSuppress section headers.\n", 1uLL, 0x1FuLL, stderr);
fwrite(" -s\tSet delimiter to provided string (default: \": \").\n", 1uLL, 0x37uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fprintf(
stderr,
"Usage: %s [options] [files]\nDisplays Exif data from the specified files or standard input.\n",
progname);
fprintf(stderr, "Version: %s\n\n", "1.01");
fwrite("Available options:\n", 1uLL, 0x13uLL, stderr);
fwrite(" -a\tDisplay camera-specific, image-specific, and verbose properties.\n", 1uLL, 0x46uLL, stderr);
fwrite(" -c\tDisplay camera-specific properties.\n", 1uLL, 0x29uLL, stderr);
fwrite(" -i\tDisplay image-specific properties.\n", 1uLL, 0x28uLL, stderr);
fwrite(" -v\tDisplay verbose properties.\n", 1uLL, 0x21uLL, stderr);
fwrite(" -u\tDisplay unknown/unsupported properties (also invalid props w/debug).\n", 1uLL, 0x4AuLL, stderr);
fwrite(" -l\tCamera has a removable lens.\n", 1uLL, 0x22uLL, stderr);
fwrite(" -d\tDisplay parse debug information.\n", 1uLL, 0x26uLL, stderr);
fwrite(" -q\tSuppress section headers.\n", 1uLL, 0x1FuLL, stderr);
fwrite(" -s\tSet delimiter to provided string (default: \": \").\n", 1uLL, 0x37uLL, stderr);
exit(1);
}

original_code:
static
void usage()
{
 fprintf(stderr, "Usage: %s [options] [files]\nDisplays Exif data "
     "from the specified files or standard input.\n", progname);
 fprintf(stderr, "Version: %s\n\n", version);
 fprintf(stderr, "Available options:\n");
 fprintf(stderr, "  -a\tDisplay camera-specific, image-specific, "
     "and verbose properties.\n");
 fprintf(stderr, "  -c\tDisplay camera-specific properties.\n");
 fprintf(stderr, "  -i\tDisplay image-specific properties.\n");
 fprintf(stderr, "  -v\tDisplay verbose properties.\n");
 fprintf(stderr, "  -u\tDisplay unknown/unsupported properties (also "
     "invalid props w/debug).\n");
 fprintf(stderr, "  -l\tCamera has a removable lens.\n");
 fprintf(stderr, "  -d\tDisplay parse debug information.\n");
 fprintf(stderr, "  -q\tSuppress section headers.\n");
 fprintf(stderr, "  -s\tSet delimiter to provided string "
     "(default: \": \").\n");
 exit(1);
}


main

canonical_name: main

repo: ekg/filevercmp

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
unsigned int v4; // eax

if ( argc == 3 )
{
v4 = filevercmp((char *)argv[1], (char *)argv[2]);
printf("%s < %s = %i\n", argv[1], argv[2], v4);
result = 0;
}
else
{
printf("usage: %s [a] [b]\n", *argv);
puts("shows version-string comparison of strings a and b");
puts("for instance, chr1 < chr10, 1 < 10, abca < bcac");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
unsigned int v4; // eax

if ( argc == 3 )
{
v4 = func10((char *)argv[1], (char *)argv[2]);
printf("%s < %s = %i\n", argv[1], argv[2], v4);
result = 0;
}
else
{
printf("usage: %s [a] [b]\n", *argv);
puts("shows version-string comparison of strings a and b");
puts("for instance, chr1 < chr10, 1 < 10, abca < bcac");
result = 1;
}
return result;
}

original_code:
int main(int argc, char** argv) {
    if (argc != 3) {
        printf("usage: %s [a] [b]\n", argv[0]);
        printf("shows version-string comparison of strings a and b\n");
        printf("for instance, chr1 < chr10, 1 < 10, abca < bcac\n");
        return 1;
    }
    int c = filevercmp(argv[1], argv[2]);
    printf("%s < %s = %i\n", argv[1], argv[2], c);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    if (argc != 3) {
        printf("usage: %s [a] [b]\n", argv[0]);
        printf("shows version-string comparison of strings a and b\n");
        printf("for instance, chr1 < chr10, 1 < 10, abca < bcac\n");
        return 1;
    }
    int c = filevercmp(argv[1], argv[2]);
    printf("%s < %s = %i\n", argv[1], argv[2], c);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

return_type: int


order

decompiled_code:
__int64 __fastcall order(unsigned __int8 a1)
{
unsigned __int16 v1; // dx
__int64 result; // rax

v1 = (*__ctype_b_loc())[a1];
result = 0LL;
if ( (v1 & 0x800) == 0 )
{
result = a1;
if ( (v1 & 0x400) == 0 )
{
if ( a1 == 126 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)a1 + 256;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 a1)
{
unsigned __int16 v1; // dx
__int64 result; // rax

v1 = (*__ctype_b_loc())[a1];
result = 0LL;
if ( (v1 & 0x800) == 0 )
{
result = a1;
if ( (v1 & 0x400) == 0 )
{
if ( a1 == 126 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)a1 + 256;
}
}
return result;
}

original_code:
static inline int
order (unsigned char c)
{
  if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
    return 0;
  else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha))
    return c;
  else if (c == '~')
    return -1;
  else
    return (int) c + (0x7f * 2 + 1) + 1;
}

canonical_original_code:
static inline int order(unsigned char c)
{
  if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
    return 0;
  else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha))
    return c;
  else if (c == '~')
    return -1;
  else
    return (int) c + (0x7f * 2 + 1) + 1;
}

variable_types:
c
unsigned char


verrevcmp

original_code:
static int
verrevcmp (const char *s1, size_t s1_len, const char *s2, size_t s2_len)
{
  size_t s1_pos = 0;
  size_t s2_pos = 0;
  while (s1_pos < s1_len || s2_pos < s2_len)
    {
      int first_diff = 0;
      while ((s1_pos < s1_len && !((*__ctype_b_loc ())[(int) ((s1[s1_pos]))] & (unsigned short int) _ISdigit))
      || (s2_pos < s2_len && !((*__ctype_b_loc ())[(int) ((s2[s2_pos]))] & (unsigned short int) _ISdigit)))
 {
   int s1_c = (s1_pos == s1_len) ? 0 : order (s1[s1_pos]);
   int s2_c = (s2_pos == s2_len) ? 0 : order (s2[s2_pos]);
   if (s1_c != s2_c)
     return s1_c - s2_c;
   s1_pos++;
   s2_pos++;
 }
      while (s1[s1_pos] == '0')
 s1_pos++;
      while (s2[s2_pos] == '0')
 s2_pos++;
      while (((*__ctype_b_loc ())[(int) ((s1[s1_pos]))] & (unsigned short int) _ISdigit) && ((*__ctype_b_loc ())[(int) ((s2[s2_pos]))] & (unsigned short int) _ISdigit))
 {
   if (!first_diff)
     first_diff = s1[s1_pos] - s2[s2_pos];
   s1_pos++;
   s2_pos++;
 }
      if (((*__ctype_b_loc ())[(int) ((s1[s1_pos]))] & (unsigned short int) _ISdigit))
 return 1;
      if (((*__ctype_b_loc ())[(int) ((s2[s2_pos]))] & (unsigned short int) _ISdigit))
 return -1;
      if (first_diff)
 return first_diff;
    }
  return 0;
}

canonical_original_code:
static int verrevcmp(char *s1, unsigned long s1_len, char *s2, unsigned long s2_len)
{
  unsigned long s1_pos = 0;
  unsigned long s2_pos = 0;
  while (s1_pos < s1_len || s2_pos < s2_len)
    {
      int first_diff = 0;
      while ((s1_pos < s1_len && !((*__ctype_b_loc ())[(int) ((s1[s1_pos]))] & (unsigned short) _ISdigit))
      || (s2_pos < s2_len && !((*__ctype_b_loc ())[(int) ((s2[s2_pos]))] & (unsigned short) _ISdigit)))
 {
   int s1_c = (s1_pos == s1_len) ? 0 : order (s1[s1_pos]);
   int s2_c = (s2_pos == s2_len) ? 0 : order (s2[s2_pos]);
   if (s1_c != s2_c)
     return s1_c - s2_c;
   s1_pos++;
   s2_pos++;
 }
      while (s1[s1_pos] == '0')
 s1_pos++;
      while (s2[s2_pos] == '0')
 s2_pos++;
      while (((*__ctype_b_loc ())[(int) ((s1[s1_pos]))] & (unsigned short) _ISdigit) && ((*__ctype_b_loc ())[(int) ((s2[s2_pos]))] & (unsigned short) _ISdigit))
 {
   if (!first_diff)
     first_diff = s1[s1_pos] - s2[s2_pos];
   s1_pos++;
   s2_pos++;
 }
      if (((*__ctype_b_loc ())[(int) ((s1[s1_pos]))] & (unsigned short) _ISdigit))
 return 1;
      if (((*__ctype_b_loc ())[(int) ((s2[s2_pos]))] & (unsigned short) _ISdigit))
 return -1;
      if (first_diff)
 return first_diff;
    }
  return 0;
}


filevercmp

original_code:
int
filevercmp (const char *s1, const char *s2)
{
  const char *s1_pos;
  const char *s2_pos;
  const char *s1_suffix, *s2_suffix;
  size_t s1_len, s2_len;
  int result;
  int simple_cmp = strcmp (s1, s2);
  if (simple_cmp == 0)
    return 0;
  if (!*s1)
    return -1;
  if (!*s2)
    return 1;
  if (0 == strcmp (".", s1))
    return -1;
  if (0 == strcmp (".", s2))
    return 1;
  if (0 == strcmp ("..", s1))
    return -1;
  if (0 == strcmp ("..", s2))
    return 1;
  if (*s1 == '.' && *s2 != '.')
    return -1;
  if (*s1 != '.' && *s2 == '.')
    return 1;
  if (*s1 == '.' && *s2 == '.')
    {
      s1++;
      s2++;
    }
  s1_pos = s1;
  s2_pos = s2;
  s1_suffix = match_suffix (&s1_pos);
  s2_suffix = match_suffix (&s2_pos);
  s1_len = (s1_suffix ? s1_suffix : s1_pos) - s1;
  s2_len = (s2_suffix ? s2_suffix : s2_pos) - s2;
  if ((s1_suffix || s2_suffix) && (s1_len == s2_len)
      && 0 == strncmp (s1, s2, s1_len))
    {
      s1_len = s1_pos - s1;
      s2_len = s2_pos - s2;
    }
  result = verrevcmp (s1, s1_len, s2, s2_len);
  return result == 0 ? simple_cmp : result;
}

canonical_original_code:
int filevercmp(char *s1, char *s2)
{
  char *s1_pos;
  char *s2_pos;
  char *s1_suffix; char *s2_suffix;
  unsigned long s1_len; unsigned long s2_len;
  int result;
  int simple_cmp = strcmp (s1, s2);
  if (simple_cmp == 0)
    return 0;
  if (!*s1)
    return -1;
  if (!*s2)
    return 1;
  if (0 == strcmp (".", s1))
    return -1;
  if (0 == strcmp (".", s2))
    return 1;
  if (0 == strcmp ("..", s1))
    return -1;
  if (0 == strcmp ("..", s2))
    return 1;
  if (*s1 == '.' && *s2 != '.')
    return -1;
  if (*s1 != '.' && *s2 == '.')
    return 1;
  if (*s1 == '.' && *s2 == '.')
    {
      s1++;
      s2++;
    }
  s1_pos = s1;
  s2_pos = s2;
  s1_suffix = match_suffix (&s1_pos);
  s2_suffix = match_suffix (&s2_pos);
  s1_len = (s1_suffix ? s1_suffix : s1_pos) - s1;
  s2_len = (s2_suffix ? s2_suffix : s2_pos) - s2;
  if ((s1_suffix || s2_suffix) && (s1_len == s2_len)
      && 0 == strncmp (s1, s2, s1_len))
    {
      s1_len = s1_pos - s1;
      s2_len = s2_pos - s2;
    }
  result = verrevcmp (s1, s1_len, s2, s2_len);
  return result == 0 ? simple_cmp : result;
}

variable_types: result int


sout

repo: ekimekim/sic

decompiled_code:
int sout(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(bufout, 0x1000uLL, format, arg);
if ( debug )
fprintf(stderr, "SEND: %s\n", bufout);
return fprintf(srv, "%s\r\n", bufout);
}

canonical_decompiled_code:
int func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(bufout, 0x1000uLL, format, arg);
if ( debug )
fprintf(stderr, "SEND: %s\n", bufout);
return fprintf(srv, "%s\r\n", bufout);
}

original_code:
static void
sout(char *fmt, ...) {
 va_list ap;
 __builtin_va_start(ap,fmt);
 vsnprintf(bufout, sizeof bufout, fmt, ap);
 __builtin_va_end(ap);
 if (debug) fprintf(stderr, "SEND: %s\n", bufout);
 fprintf(srv, "%s\r\n", bufout);
}

canonical_original_code:
static void sout(char *fmt, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vsnprintf(bufout, sizeof bufout, fmt, ap);
 __builtin_va_end(ap);
 if (debug) fprintf(stderr, "SEND: %s\n", bufout);
 fprintf(srv, "%s\r\n", bufout);
}

variable_types:
fmt
char *


trim

decompiled_code:
__int64 __fastcall trim(const char *a1)
{
const char *v1; // rbx
const unsigned __int16 *v2; // rdx
__int64 result; // rax

v1 = &a1[strlen(a1) - 1];
v2 = *_ctype_b_loc();
while ( 1 )
{
result = *v1;
if ( (v2[result] & 0x2000) == 0 || v1 <= a1 )
break;
--v1;
}
*((_BYTE *)v1 + 1) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
const char *v1; // rbx
const unsigned __int16 *v2; // rdx
__int64 result; // rax

v1 = &a1[strlen(a1) - 1];
v2 = *_ctype_b_loc();
while ( 1 )
{
result = *v1;
if ( (v2[result] & 0x2000) == 0 || v1 <= a1 )
break;
--v1;
}
*((_BYTE *)v1 + 1) = 0;
return result;
}

original_code:
static void
trim(char *s) {
 char *e;
 e = s + strlen(s) - 1;
 while(((*__ctype_b_loc ())[(int) ((*e))] & (unsigned short int) _ISspace) && e > s)
  e--;
 *(e + 1) = '\0';
}

canonical_original_code:
static void trim(char *s) {
 char *e;
 e = s + strlen(s) - 1;
 while(((*__ctype_b_loc ())[(int) ((*e))] & (unsigned short) _ISspace) && e > s)
  e--;
 *(e + 1) = '\0';
}

variable_types:
s
char *

variable_types:
e
char *


pout

decompiled_code:
int pout(const char *a1, const char *a2, ...)
{
struct tm *v2; // rax
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
time_t timer; // [rsp+18h] [rbp-C0h] BYREF

va_start(va, a2);
vsnprintf(bufout, 0x1000uLL, a2, va);
timer = time(0LL);
v2 = localtime(&timer);
strftime(timestr_0, 0x12uLL, "%D %R", v2);
return fprintf(stdout, "%-12s: %s %s\n", a1, timestr_0, bufout);
}

canonical_decompiled_code:
int func3(const char *a1, const char *a2, ...)
{
struct tm *v2; // rax
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
time_t timer; // [rsp+18h] [rbp-C0h] BYREF

va_start(va, a2);
vsnprintf(bufout, 0x1000uLL, a2, va);
timer = time(0LL);
v2 = localtime(&timer);
strftime(timestr_0, 0x12uLL, "%D %R", v2);
return fprintf(stdout, "%-12s: %s %s\n", a1, timestr_0, bufout);
}

original_code:
static void
pout(char *channel, char *fmt, ...) {
 static char timestr[18];
 time_t t;
 va_list ap;
 __builtin_va_start(ap,fmt);
 vsnprintf(bufout, sizeof bufout, fmt, ap);
 __builtin_va_end(ap);
 t = time(((void *)0));
 strftime(timestr, sizeof timestr, "%D %R", localtime(&t));
 fprintf(stdout, "%-12s: %s %s\n", channel, timestr, bufout);
}

canonical_original_code:
static void pout(char *channel, char *fmt, ...) {
 static char timestr[18];
 long t;
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vsnprintf(bufout, sizeof bufout, fmt, ap);
 __builtin_va_end(ap);
 t = time(((void *)0));
 strftime(timestr, sizeof timestr, "%D %R", localtime(&t));
 fprintf(stdout, "%-12s: %s %s\n", channel, timestr, bufout);
}

variable_types:
channel
char *

variable_types:
timestr
char [18]

variable_types: t long


privmsg

decompiled_code:
int __fastcall privmsg(const char *a1, const char *a2)
{
if ( !*a1 )
return pout((const char *)&unk_2F08, "No channel to send to");
pout(a1, "<%s> %s", nick, a2);
return sout("PRIVMSG %s :%s", a1, a2);
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, const char *a2)
{
if ( !*a1 )
return func3((const char *)&unk_2F08, "No channel to send to");
func3(a1, "<%s> %s", nick, a2);
return func1("PRIVMSG %s :%s", a1, a2);
}

original_code:
static void
privmsg(char *channel, char *msg) {
 if(channel[0] == '\0') {
  pout("", "No channel to send to");
  return;
 }
 pout(channel, "<%s> %s", nick, msg);
 sout("PRIVMSG %s :%s", channel, msg);
}

variable_types:
msg
char *


eprint

decompiled_code:
void __noreturn eprint(char *s, ...)
{
int *v1; // rax
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, s);
vsnprintf(bufout, 0x1000uLL, s, arg);
fputs(bufout, stderr);
if ( *s )
{
if ( s[strlen(s) - 1] == 58 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, " %s\n", v2);
}
}
exit(1);
}

canonical_decompiled_code:
void __noreturn func7(char *s, ...)
{
int *v1; // rax
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, s);
vsnprintf(bufout, 0x1000uLL, s, arg);
fputs(bufout, stderr);
if ( *s )
{
if ( s[strlen(s) - 1] == 58 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, " %s\n", v2);
}
}
exit(1);
}

original_code:
static void
eprint(const char *fmt, ...) {
 va_list ap;
 __builtin_va_start(ap,fmt);
 vsnprintf(bufout, sizeof bufout, fmt, ap);
 __builtin_va_end(ap);
 fprintf(stderr, "%s", bufout);
 if(fmt[0] && fmt[strlen(fmt) - 1] == ':')
  fprintf(stderr, " %s\n", strerror((*__errno_location ())));
 exit(1);
}

canonical_original_code:
static void eprint(char *fmt, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vsnprintf(bufout, sizeof bufout, fmt, ap);
 __builtin_va_end(ap);
 fprintf(stderr, "%s", bufout);
 if(fmt[0] && fmt[strlen(fmt) - 1] == ':')
  fprintf(stderr, " %s\n", strerror((*__errno_location ())));
 exit(1);
}


dial

decompiled_code:
__int64 __fastcall dial(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // ebp
struct addrinfo *pai; // [rsp+8h] [rbp-20h] BYREF

*(_QWORD *)&hints_1.ai_flags = 0LL;
*(_QWORD *)&hints_1.ai_socktype = 1LL;
*(_QWORD *)&hints_1.ai_addrlen = 0LL;
hints_1.ai_addr = 0LL;
hints_1.ai_canonname = 0LL;
hints_1.ai_next = 0LL;
if ( getaddrinfo(a1, a2, &hints_1, &pai) )
eprint("error: cannot resolve hostname '%s':", a1);
v2 = pai;
if ( !pai )
{
LABEL_3:
freeaddrinfo(pai);
eprint("error: cannot connect to host '%s'\n", a1);
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 )
break;
LABEL_5:
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_3;
}
if ( connect(v3, v2->ai_addr, v2->ai_addrlen) )
{
close(v4);
goto LABEL_5;
}
freeaddrinfo(pai);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // ebp
struct addrinfo *pai; // [rsp+8h] [rbp-20h] BYREF

*(_QWORD *)&hints_1.ai_flags = 0LL;
*(_QWORD *)&hints_1.ai_socktype = 1LL;
*(_QWORD *)&hints_1.ai_addrlen = 0LL;
hints_1.ai_addr = 0LL;
hints_1.ai_canonname = 0LL;
hints_1.ai_next = 0LL;
if ( getaddrinfo(a1, a2, &hints_1, &pai) )
func7("error: cannot resolve hostname '%s':", a1);
v2 = pai;
if ( !pai )
{
LABEL_3:
freeaddrinfo(pai);
func7("error: cannot connect to host '%s'\n", a1);
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 )
break;
LABEL_5:
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_3;
}
if ( connect(v3, v2->ai_addr, v2->ai_addrlen) )
{
close(v4);
goto LABEL_5;
}
freeaddrinfo(pai);
return v4;
}

original_code:
static int
dial(char *host, char *port) {
 static struct addrinfo hints;
 int srv;
 struct addrinfo *res, *r;
 memset(&hints, 0, sizeof hints);
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 if(getaddrinfo(host, port, &hints, &res) != 0)
  eprint("error: cannot resolve hostname '%s':", host);
 for(r = res; r; r = r->ai_next) {
  if((srv = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
   continue;
  if(connect(srv, r->ai_addr, r->ai_addrlen) == 0)
   break;
  close(srv);
 }
 freeaddrinfo(res);
 if(!r)
  eprint("error: cannot connect to host '%s'\n", host);
 return srv;
}

canonical_original_code:
static int dial(char *host, char *port) {
 static struct addrinfo hints;
 int srv;
 struct addrinfo *res; struct addrinfo *r;
 memset(&hints, 0, sizeof hints);
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 if(getaddrinfo(host, port, &hints, &res) != 0)
  eprint("error: cannot resolve hostname '%s':", host);
 for(r = res; r; r = r->ai_next) {
  if((srv = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
   continue;
  if(connect(srv, r->ai_addr, r->ai_addrlen) == 0)
   break;
  close(srv);
 }
 freeaddrinfo(res);
 if(!r)
  eprint("error: cannot connect to host '%s'\n", host);
 return srv;
}

variable_types:
host
char *

variable_types:
port
char *

variable_types: srv int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rsi
int v5; // ebx
__int64 v6; // rcx
const char *v7; // rdx
int v8; // eax
FILE *v9; // r12
int v10; // ebx
int v11; // eax
int v12; // eax
int v13; // eax
FILE *v14; // rbp
__fd_mask v15; // r12
fd_set v17; // [rsp+0h] [rbp-B8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-38h] BYREF

v4 = getenv("IRC_NICK");
if ( !v4 )
{
v4 = getenv("USER");
if ( !v4 )
v4 = "unknown";
}
strlcpy(nick, v4, 32);
if ( argc > 1 )
{
v5 = 1;
while ( 2 )
{
v6 = v5;
v7 = argv[v6];
if ( *v7 == 45 && !v7[2] )
{
switch ( v7[1] )
{
case 'c':
if ( argc > ++v5 )
strlcpy(&channel, argv[v6 + 1], 256);
goto LABEL_15;
case 'd':
debug = 1;
goto LABEL_15;
case 'h':
if ( argc > ++v5 )
host = (char *)argv[v6 + 1];
goto LABEL_15;
case 'k':
if ( argc > ++v5 )
password = (char *)argv[v6 + 1];
goto LABEL_15;
case 'n':
if ( argc > ++v5 )
strlcpy(nick, argv[v6 + 1], 32);
goto LABEL_15;
case 'p':
if ( argc > ++v5 )
port = (char *)argv[v6 + 1];
LABEL_15:
if ( argc > ++v5 )
continue;
goto LABEL_23;
case 'v':
eprint("sic-1.3, © 2005-2012 Kris Maglione, Anselm R. Garbe, Nico Golde\n");
default:
goto LABEL_22;
}
}
break;
}
LABEL_22:
eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-c channel] [-d] [-v]\n");
}
LABEL_23:
if ( password )
{
if ( !strcmp(password, "-") )
{
password = getpass("Password: ");
if ( !password )
perror("getpass() failed");
}
}
v8 = dial(host, port);
srv = fdopen(v8, "r+");
if ( password )
sout("PASS %s", password);
sout("USER %s localhost %s :%s", nick, host, nick);
sout("NICK %s", nick);
sout("JOIN %s", "#desertbus");
strlcpy(&channel, "#desertbus", 256);
if ( channel )
sout("JOIN %s", &channel);
fflush(srv);
setbuf(stdout, 0LL);
setbuf(srv, 0LL);
while ( 1 )
{
while ( 1 )
{
memset(&v17, 0, sizeof(v17));
v17.fds_bits[0] |= 1uLL;
v9 = srv;
v10 = fileno(srv);
v11 = fileno(v9);
v17.fds_bits[v11 / 64] |= 1LL << (v10 % 64);
timeout.tv_sec = 120LL;
timeout.tv_usec = 0LL;
v12 = fileno(v9);
v13 = select(v12 + 1, &v17, 0LL, 0LL, &timeout);
if ( v13 < 0 )
break;
if ( v13 )
{
v14 = srv;
v15 = v17.fds_bits[fileno(srv) / 64];
if ( (v15 & (1LL << (fileno(v14) % 64))) != 0 )
{
if ( !fgets(bufin, 4096, v14) )
eprint("sic: remote host closed connection\n");
parsesrv(bufin);
trespond = time(0LL);
}
if ( (v17.fds_bits[0] & 1) != 0 )
{
if ( !fgets(bufin, 4096, stdin) )
eprint("sic: end of input\n");
parsein(bufin);
}
}
else
{
if ( time(0LL) - trespond > 299 )
eprint("sic shutting down: parse timeout\n");
sout("PING %s", host);
}
}
if ( *_errno_location() != 4 )
eprint("sic: error on select():");
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rsi
int v5; // ebx
__int64 v6; // rcx
const char *v7; // rdx
int v8; // eax
FILE *v9; // r12
int v10; // ebx
int v11; // eax
int v12; // eax
int v13; // eax
FILE *v14; // rbp
__fd_mask v15; // r12
fd_set v17; // [rsp+0h] [rbp-B8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-38h] BYREF

v4 = getenv("IRC_NICK");
if ( !v4 )
{
v4 = getenv("USER");
if ( !v4 )
v4 = "unknown";
}
func0(nick, v4, 32);
if ( argc > 1 )
{
v5 = 1;
while ( 2 )
{
v6 = v5;
v7 = argv[v6];
if ( *v7 == 45 && !v7[2] )
{
switch ( v7[1] )
{
case 'c':
if ( argc > ++v5 )
func0(&channel, argv[v6 + 1], 256);
goto LABEL_15;
case 'd':
debug = 1;
goto LABEL_15;
case 'h':
if ( argc > ++v5 )
host = (char *)argv[v6 + 1];
goto LABEL_15;
case 'k':
if ( argc > ++v5 )
password = (char *)argv[v6 + 1];
goto LABEL_15;
case 'n':
if ( argc > ++v5 )
func0(nick, argv[v6 + 1], 32);
goto LABEL_15;
case 'p':
if ( argc > ++v5 )
port = (char *)argv[v6 + 1];
LABEL_15:
if ( argc > ++v5 )
continue;
goto LABEL_23;
case 'v':
func7("sic-1.3, © 2005-2012 Kris Maglione, Anselm R. Garbe, Nico Golde\n");
default:
goto LABEL_22;
}
}
break;
}
LABEL_22:
func7("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-c channel] [-d] [-v]\n");
}
LABEL_23:
if ( password )
{
if ( !strcmp(password, "-") )
{
password = getpass("Password: ");
if ( !password )
perror("getpass() failed");
}
}
v8 = func8(host, port);
srv = fdopen(v8, "r+");
if ( password )
func1("PASS %s", password);
func1("USER %s localhost %s :%s", nick, host, nick);
func1("NICK %s", nick);
func1("JOIN %s", "#desertbus");
func0(&channel, "#desertbus", 256);
if ( channel )
func1("JOIN %s", &channel);
fflush(srv);
setbuf(stdout, 0LL);
setbuf(srv, 0LL);
while ( 1 )
{
while ( 1 )
{
memset(&v17, 0, sizeof(v17));
v17.fds_bits[0] |= 1uLL;
v9 = srv;
v10 = fileno(srv);
v11 = fileno(v9);
v17.fds_bits[v11 / 64] |= 1LL << (v10 % 64);
timeout.tv_sec = 120LL;
timeout.tv_usec = 0LL;
v12 = fileno(v9);
v13 = select(v12 + 1, &v17, 0LL, 0LL, &timeout);
if ( v13 < 0 )
break;
if ( v13 )
{
v14 = srv;
v15 = v17.fds_bits[fileno(srv) / 64];
if ( (v15 & (1LL << (fileno(v14) % 64))) != 0 )
{
if ( !fgets(bufin, 4096, v14) )
func7("sic: remote host closed connection\n");
func4(bufin);
trespond = time(0LL);
}
if ( (v17.fds_bits[0] & 1) != 0 )
{
if ( !fgets(bufin, 4096, stdin) )
func7("sic: end of input\n");
func6(bufin);
}
}
else
{
if ( time(0LL) - trespond > 299 )
func7("sic shutting down: parse timeout\n");
func1("PING %s", host);
}
}
if ( *_errno_location() != 4 )
func7("sic: error on select():");
}
}

original_code:
int
main(int argc, char *argv[]) {
 int i, c;
 struct timeval tv;
 const char *user;
 (user = getenv("IRC_NICK")) || (user = getenv("USER")) || (user = "unknown");
 fd_set rd;
 _strlcpy(nick, user, sizeof nick);
 for(i = 1; i < argc; i++) {
  c = argv[i][1];
  if(argv[i][0] != '-' || argv[i][2])
   c = -1;
  switch(c) {
  case 'h':
   if(++i < argc) host = argv[i];
   break;
  case 'p':
   if(++i < argc) port = argv[i];
   break;
  case 'n':
   if(++i < argc) _strlcpy(nick, argv[i], sizeof nick);
   break;
  case 'k':
   if(++i < argc) password = argv[i];
   break;
  case 'd':
   debug = 1;
   break;
  case 'c':
   if(++i < argc)
    _strlcpy(channel, argv[i], sizeof channel);
   break;
  case 'v':
   eprint("sic-""1.3"", © 2005-2012 Kris Maglione, Anselm R. Garbe, Nico Golde\n");
  default:
   eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-c channel] [-d] [-v]\n");
  }
 }
 if(password && strcmp(password, "-") == 0) {
  password = getpass("Password: ");
  if(!password) perror("getpass() failed");
 }
 i = dial(host, port);
 srv = fdopen(i, "r+");
 if(password) {
  sout("PASS %s", password);
 }
 sout("USER %s localhost %s :%s", nick, host, nick);
 sout("NICK %s", nick);
 if (start_chan) {
  sout("JOIN %s", start_chan);
  _strlcpy(channel, start_chan, sizeof channel);
 }
 if(channel[0] != '\0')
  sout("JOIN %s", channel);
 fflush(srv);
 setbuf(stdout, ((void *)0));
 setbuf(srv, ((void *)0));
 for(;;) {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd)->fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rd)->fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&rd)->fds_bits)[((fileno(srv)) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fileno(srv)) % (8 * (int) sizeof (__fd_mask)))))));
  tv.tv_sec = 120;
  tv.tv_usec = 0;
  i = select(fileno(srv) + 1, &rd, 0, 0, &tv);
  if(i < 0) {
   if((*__errno_location ()) == 4)
    continue;
   eprint("sic: error on select():");
  }
  else if(i == 0) {
   if(time(((void *)0)) - trespond >= 300)
    eprint("sic shutting down: parse timeout\n");
   sout("PING %s", host);
   continue;
  }
  if(((((&rd)->fds_bits)[((fileno(srv)) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fileno(srv)) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if(fgets(bufin, sizeof bufin, srv) == ((void *)0))
    eprint("sic: remote host closed connection\n");
   parsesrv(bufin);
   trespond = time(((void *)0));
  }
  if(((((&rd)->fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if(fgets(bufin, sizeof bufin, stdin) == ((void *)0))
    eprint("sic: end of input\n");
   parsein(bufin);
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int i; int c;
 struct timeval tv;
 char *user;
 (user = getenv("IRC_NICK")) || (user = getenv("USER")) || (user = "unknown");
 struct fd_set rd;
 _strlcpy(nick, user, sizeof nick);
 for(i = 1; i < argc; i++) {
  c = argv[i][1];
  if(argv[i][0] != '-' || argv[i][2])
   c = -1;
  switch(c) {
  case 'h':
   if(++i < argc) host = argv[i];
   break;
  case 'p':
   if(++i < argc) port = argv[i];
   break;
  case 'n':
   if(++i < argc) _strlcpy(nick, argv[i], sizeof nick);
   break;
  case 'k':
   if(++i < argc) password = argv[i];
   break;
  case 'd':
   debug = 1;
   break;
  case 'c':
   if(++i < argc)
    _strlcpy(channel, argv[i], sizeof channel);
   break;
  case 'v':
   eprint("sic-""1.3"", © 2005-2012 Kris Maglione, Anselm R. Garbe, Nico Golde\n");
  default:
   eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-c channel] [-d] [-v]\n");
  }
 }
 if(password && strcmp(password, "-") == 0) {
  password = getpass("Password: ");
  if(!password) perror("getpass() failed");
 }
 i = dial(host, port);
 srv = fdopen(i, "r+");
 if(password) {
  sout("PASS %s", password);
 }
 sout("USER %s localhost %s :%s", nick, host, nick);
 sout("NICK %s", nick);
 if (start_chan) {
  sout("JOIN %s", start_chan);
  _strlcpy(channel, start_chan, sizeof channel);
 }
 if(channel[0] != '\0')
  sout("JOIN %s", channel);
 fflush(srv);
 setbuf(stdout, ((void *)0));
 setbuf(srv, ((void *)0));
 for(;;) {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd)->fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rd)->fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&rd)->fds_bits)[((fileno(srv)) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fileno(srv)) % (8 * (int) sizeof (__fd_mask)))))));
  tv.tv_sec = 120;
  tv.tv_usec = 0;
  i = select(fileno(srv) + 1, &rd, 0, 0, &tv);
  if(i < 0) {
   if((*__errno_location ()) == 4)
    continue;
   eprint("sic: error on select():");
  }
  else if(i == 0) {
   if(time(((void *)0)) - trespond >= 300)
    eprint("sic shutting down: parse timeout\n");
   sout("PING %s", host);
   continue;
  }
  if(((((&rd)->fds_bits)[((fileno(srv)) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fileno(srv)) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if(fgets(bufin, sizeof bufin, srv) == ((void *)0))
    eprint("sic: remote host closed connection\n");
   parsesrv(bufin);
   trespond = time(((void *)0));
  }
  if(((((&rd)->fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if(fgets(bufin, sizeof bufin, stdin) == ((void *)0))
    eprint("sic: end of input\n");
   parsein(bufin);
  }
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types: i int

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

variable_types:
user
char *

variable_types:
rd
struct fd_set { long fds_bits[-1]; }


repo: eklitzke/scribl

decompiled_code:
char *__fastcall scribl_logfunc(__int64 a1, int a2, __int64 a3, __int64 a4)
{
char *result; // rax

result = getenv("SCRIBL_LOG");
if ( result )
{
if ( !strcmp(result, "5") || (result = (char *)(strcmp(result, "4") != 0), a2 <= 127) && !(_DWORD)result )
result = (char *)g_log_default_handler(a1, (unsigned int)a2, a3, a4);
}
if ( a2 <= 63 )
result = (char *)g_log_default_handler(a1, (unsigned int)a2, a3, a4);
return result;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, int a2, __int64 a3, __int64 a4)
{
char *result; // rax

result = getenv("SCRIBL_LOG");
if ( result )
{
if ( !strcmp(result, "5") || (result = (char *)(strcmp(result, "4") != 0), a2 <= 127) && !(_DWORD)result )
result = (char *)g_log_default_handler(a1, (unsigned int)a2, a3, a4);
}
if ( a2 <= 63 )
result = (char *)g_log_default_handler(a1, (unsigned int)a2, a3, a4);
return result;
}

original_code:
void scribl_logfunc(const char *log_domain,
     GLogLevelFlags log_level,
     const char *message,
     gpointer user_data)
{
 char *base_level;
 base_level = getenv("SCRIBL_LOG");
 if(!base_level)
  goto default_handler;
 if (strcmp(base_level, "5") == 0) {
  g_log_default_handler(log_domain, log_level, message, user_data);
 } else if (strcmp(base_level, "4") == 0) {
  if (log_level < G_LOG_LEVEL_DEBUG) {
   g_log_default_handler(log_domain, log_level, message, user_data);
  }
 } else {
  goto default_handler;
 }
default_handler:
 if (log_level < G_LOG_LEVEL_INFO)
  g_log_default_handler(log_domain, log_level, message, user_data);
}

canonical_original_code:
void scribl_logfunc(char *log_domain, enum GLogLevelFlags log_level, char *message, void *user_data)
{
 char *base_level;
 base_level = getenv("SCRIBL_LOG");
 if(!base_level)
  goto default_handler;
 if (strcmp(base_level, "5") == 0) {
  g_log_default_handler(log_domain, log_level, message, user_data);
 } else if (strcmp(base_level, "4") == 0) {
  if (log_level < G_LOG_LEVEL_DEBUG) {
   g_log_default_handler(log_domain, log_level, message, user_data);
  }
 } else {
  goto default_handler;
 }
default_handler:
 if (log_level < G_LOG_LEVEL_INFO)
  g_log_default_handler(log_domain, log_level, message, user_data);
}

variable_types: enum GLogLevelFlags { G_LOG_FLAG_RECURSION=expr, G_LOG_FLAG_FATAL=expr, G_LOG_LEVEL_ERROR=expr, G_LOG_LEVEL_CRITICAL=expr, G_LOG_LEVEL_WARNING=expr, G_LOG_LEVEL_MESSAGE=expr, G_LOG_LEVEL_INFO=expr, G_LOG_LEVEL_DEBUG=expr, G_LOG_LEVEL_MASK=expr }

variable_types:
message
char *


decompiled_code:
__int64 __fastcall ht_val_free(__int64 a1)
{
return g_slice_free1(8LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return g_slice_free1(8LL, a1);
}

original_code:
static void ht_val_free(gpointer data)
{
 do { if (1) g_slice_free1 (sizeof (double), (data)); else (void) ((double*) 0 == (data)); } while (0);
}

canonical_original_code:
static void ht_val_free(void *data)
{
 do { if (1) g_slice_free1 (sizeof (double), (data)); else (void) ((double *) 0 == (data)); } while (0);
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall scribl_init(double a1)
{
__int64 v1; // rax
__int64 result; // rax
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
g_log_set_default_handler(&scribl_logfunc, 0LL);
scribl_exit_semaphore = g_reverse_semaphore_create();
if ( scribl_exit_semaphore )
{
counter_list_access = g_mutex_new();
counter_list = g_slist_alloc();
event_worker_cond = g_cond_new();
event_worker_access = g_mutex_new();
v1 = g_slice_copy(8LL, v3);
result = g_thread_create(event_loop_worker, v1, 1LL, 0LL);
event_worker_thd = result;
}
else
{
g_assertion_message_expr("scribl", "scribl.c", 35LL, "scribl_init", "scribl_exit_semaphore != NULL");
result = scribl_new_counter();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(double a1)
{
__int64 v1; // rax
__int64 result; // rax
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
g_log_set_default_handler(&scribl_logfunc, 0LL);
scribl_exit_semaphore = g_reverse_semaphore_create();
if ( scribl_exit_semaphore )
{
counter_list_access = g_mutex_new();
counter_list = g_slist_alloc();
event_worker_cond = g_cond_new();
event_worker_access = g_mutex_new();
v1 = g_slice_copy(8LL, v3);
result = g_thread_create(event_loop_worker, v1, 1LL, 0LL);
event_worker_thd = result;
}
else
{
g_assertion_message_expr("scribl", "scribl.c", 35LL, "scribl_init", "scribl_exit_semaphore != NULL");
result = scribl_new_counter();
}
return result;
}

original_code:
void scribl_init(double wakeup_interval)
{
 double *wake_interval_ptr;
 if (!(1))
  g_thread_init (((void *)0));
 g_log_set_default_handler(scribl_logfunc, ((void *)0));
 scribl_exit_semaphore = g_reverse_semaphore_create();
 do { if (scribl_exit_semaphore != ((void *)0)) ; else g_assertion_message_expr ("scribl", "scribl.c", 35, ((const char*) (__func__)), "scribl_exit_semaphore != NULL"); } while (0);
 counter_list_access = g_mutex_new();
 counter_list = g_slist_alloc();
 event_worker_cond = g_cond_new();
 event_worker_access = g_mutex_new();
 wake_interval_ptr = g_slice_copy(sizeof(double), &wakeup_interval);
 event_worker_thd = g_thread_create(event_loop_worker, wake_interval_ptr, (!(0)), ((void *)0));
}

canonical_original_code:
void scribl_init(double wakeup_interval)
{
 double *wake_interval_ptr;
 if (!(1))
  g_thread_init (((void *)0));
 g_log_set_default_handler(scribl_logfunc, ((void *)0));
 scribl_exit_semaphore = g_reverse_semaphore_create();
 do { if (scribl_exit_semaphore != ((void *)0)) ; else g_assertion_message_expr ("scribl", "scribl.c", 35, ((char *) (__func__)), "scribl_exit_semaphore != NULL"); } while (0);
 counter_list_access = g_mutex_new();
 counter_list = g_slist_alloc();
 event_worker_cond = g_cond_new();
 event_worker_access = g_mutex_new();
 wake_interval_ptr = g_slice_copy(sizeof(double), &wakeup_interval);
 event_worker_thd = g_thread_create(event_loop_worker, wake_interval_ptr, (!(0)), ((void *)0));
}


decompiled_code:
__int64 scribl_exit()
{
_QWORD **v0; // rax

g_reverse_semaphore_destroy(scribl_exit_semaphore);
scribl_exit_semaphore = 0LL;
g_cond_signal(event_worker_cond);
g_thread_join(event_worker_thd);
g_mutex_lock(counter_list_access);
v0 = (_QWORD **)counter_list;
if ( counter_list )
{
do
{
if ( !*v0 )
break;
scribl_free_counter(*v0);
v0 = *(_QWORD ***)(counter_list + 8);
}
while ( v0 );
}
g_mutex_unlock(counter_list_access);
g_mutex_free(counter_list_access);
return g_slist_free(counter_list);
}

canonical_decompiled_code:
__int64 func7()
{
_QWORD **v0; // rax

g_reverse_semaphore_destroy(scribl_exit_semaphore);
scribl_exit_semaphore = 0LL;
g_cond_signal(event_worker_cond);
g_thread_join(event_worker_thd);
g_mutex_lock(counter_list_access);
v0 = (_QWORD **)counter_list;
if ( counter_list )
{
do
{
if ( !*v0 )
break;
func6(*v0);
v0 = *(_QWORD ***)(counter_list + 8);
}
while ( v0 );
}
g_mutex_unlock(counter_list_access);
g_mutex_free(counter_list_access);
return g_slist_free(counter_list);
}

original_code:
void scribl_exit()
{
 GSList *element;
 g_reverse_semaphore_destroy(scribl_exit_semaphore);
 scribl_exit_semaphore = ((void *)0);
 g_cond_signal(event_worker_cond);
 g_thread_join(event_worker_thd);
 g_mutex_lock(counter_list_access);
 for (element = counter_list; ((element != ((void *)0)) && (element->data != ((void *)0))); element = counter_list->next)
  scribl_free_counter(element->data);
 g_mutex_unlock(counter_list_access);
 g_mutex_free(counter_list_access);
 g_slist_free(counter_list);
}

canonical_original_code:
void scribl_exit()
{
 struct _GSList *element;
 g_reverse_semaphore_destroy(scribl_exit_semaphore);
 scribl_exit_semaphore = ((void *)0);
 g_cond_signal(event_worker_cond);
 g_thread_join(event_worker_thd);
 g_mutex_lock(counter_list_access);
 for (element = counter_list; ((element != ((void *)0)) && (element->data != ((void *)0))); element = counter_list->next)
  scribl_free_counter(element->data);
 g_mutex_unlock(counter_list_access);
 g_mutex_free(counter_list_access);
 g_slist_free(counter_list);
}

variable_types: struct _GSList { void *data; struct _GSList *next; } *


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

v0 = g_slice_alloc(24LL);
*(_DWORD *)v0 = 0;
*(_QWORD *)(v0 + 8) = g_mutex_new();
*(_QWORD *)(v0 + 16) = g_cond_new();
return v0;
}

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

v0 = g_slice_alloc(24LL);
*(_DWORD *)v0 = 0;
*(_QWORD *)(v0 + 8) = g_mutex_new();
*(_QWORD *)(v0 + 16) = g_cond_new();
return v0;
}

original_code:
GReverseSemaphore* g_reverse_semaphore_create()
{
 GReverseSemaphore *sem;
 sem = g_slice_alloc(sizeof(GReverseSemaphore));
 sem->value = 0;
 sem->access = g_mutex_new();
 sem->cond = g_cond_new();
 return sem;
}

canonical_original_code:
struct _GReverseSemaphore *g_reverse_semaphore_create()
{
 struct _GReverseSemaphore *sem;
 sem = g_slice_alloc(sizeof(GReverseSemaphore));
 sem->value = 0;
 sem->access = g_mutex_new();
 sem->cond = g_cond_new();
 return sem;
}

variable_types: struct _GReverseSemaphore { unsigned int value; union _GMutex { void *p; unsigned int i[2]; } *access; struct _GCond { void *p; unsigned int i[2]; } *cond; } *

user_defined_types: struct _GReverseSemaphore { unsigned int value; union _GMutex *access; struct _GCond *cond; }


decompiled_code:
__int64 __fastcall g_reverse_semaphore_up(__int64 a1)
{
g_mutex_lock(*(_QWORD *)(a1 + 8));
++*(_DWORD *)a1;
return g_mutex_unlock(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
g_mutex_lock(*(_QWORD *)(a1 + 8));
++*(_DWORD *)a1;
return g_mutex_unlock(*(_QWORD *)(a1 + 8));
}

original_code:
void g_reverse_semaphore_up(GReverseSemaphore *sem)
{
 g_mutex_lock(sem->access);
 sem->value = sem->value + 1;
 g_mutex_unlock(sem->access);
}

canonical_original_code:
void g_reverse_semaphore_up(struct _GReverseSemaphore *sem)
{
 g_mutex_lock(sem->access);
 sem->value = sem->value + 1;
 g_mutex_unlock(sem->access);
}

user_defined_types: union _GMutex { void *p; unsigned int i[2]; }

user_defined_types: struct _GCond { void *p; unsigned int i[2]; }


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

g_mutex_lock(*(_QWORD *)(a1 + 8));
if ( *(_DWORD *)a1 )
{
--*(_DWORD *)a1;
g_mutex_unlock(*(_QWORD *)(a1 + 8));
result = g_cond_signal(*(_QWORD *)(a1 + 16));
}
else
{
g_assertion_message_expr(0LL, "reverse_sem.c", 24LL, "g_reverse_semaphore_down", "sem->value > 0");
result = g_reverse_semaphore_destroy();
}
return result;
}

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

g_mutex_lock(*(_QWORD *)(a1 + 8));
if ( *(_DWORD *)a1 )
{
--*(_DWORD *)a1;
g_mutex_unlock(*(_QWORD *)(a1 + 8));
result = g_cond_signal(*(_QWORD *)(a1 + 16));
}
else
{
g_assertion_message_expr(0LL, "reverse_sem.c", 24LL, "g_reverse_semaphore_down", "sem->value > 0");
result = func3();
}
return result;
}

original_code:
void g_reverse_semaphore_down(GReverseSemaphore *sem)
{
 g_mutex_lock(sem->access);
 do { if (sem->value > 0) ; else g_assertion_message_expr (((gchar*) 0), "reverse_sem.c", 24, ((const char*) (__func__)), "sem->value > 0"); } while (0);
 sem->value = sem->value - 1;
 g_mutex_unlock(sem->access);
 g_cond_signal(sem->cond);
}

canonical_original_code:
void g_reverse_semaphore_down(struct _GReverseSemaphore *sem)
{
 g_mutex_lock(sem->access);
 do { if (sem->value > 0) ; else g_assertion_message_expr (((char *) 0), "reverse_sem.c", 24, ((char *) (__func__)), "sem->value > 0"); } while (0);
 sem->value = sem->value - 1;
 g_mutex_unlock(sem->access);
 g_cond_signal(sem->cond);
}


decompiled_code:
__int64 __fastcall g_reverse_semaphore_destroy(__int64 a1)
{
g_mutex_lock(*(_QWORD *)(a1 + 8));
while ( *(_DWORD *)a1 )
g_cond_wait(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 8));
g_mutex_unlock(*(_QWORD *)(a1 + 8));
g_mutex_free(*(_QWORD *)(a1 + 8));
g_cond_free(*(_QWORD *)(a1 + 16));
return g_slice_free1(24LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
g_mutex_lock(*(_QWORD *)(a1 + 8));
while ( *(_DWORD *)a1 )
g_cond_wait(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 8));
g_mutex_unlock(*(_QWORD *)(a1 + 8));
g_mutex_free(*(_QWORD *)(a1 + 8));
g_cond_free(*(_QWORD *)(a1 + 16));
return g_slice_free1(24LL, a1);
}

original_code:
void g_reverse_semaphore_destroy(GReverseSemaphore *sem)
{
 g_mutex_lock(sem->access);
 while (sem->value > 0)
  g_cond_wait(sem->cond, sem->access);
 g_mutex_unlock(sem->access);
 g_mutex_free(sem->access);
 g_cond_free(sem->cond);
 do { if (1) g_slice_free1 (sizeof (GReverseSemaphore), (sem)); else (void) ((GReverseSemaphore*) 0 == (sem)); } while (0);
}

canonical_original_code:
void g_reverse_semaphore_destroy(struct _GReverseSemaphore *sem)
{
 g_mutex_lock(sem->access);
 while (sem->value > 0)
  g_cond_wait(sem->cond, sem->access);
 g_mutex_unlock(sem->access);
 g_mutex_free(sem->access);
 g_cond_free(sem->cond);
 do { if (1) g_slice_free1 (sizeof (GReverseSemaphore), (sem)); else (void) ((struct _GReverseSemaphore *) 0 == (sem)); } while (0);
}


execute

repo: elboza/dwarf-ng

decompiled_code:
__int64 __fastcall execute(const char *a1)
{
if ( !a1 )
a1 = "quit";
yy_scan_string(a1);
yyparse();
return yylex_destroy();
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
if ( !a1 )
a1 = "quit";
yy_scan_string(a1);
yyparse();
return yylex_destroy();
}

original_code:
void execute(char *s)
{
 if(!s) s="quit";
 yy_scan_string(s);
 yyparse();
 yylex_destroy();
}

variable_types:
s
char *


decompiled_code:
int funny_shell_disclaimer()
{
puts(" ________________________________________ ");
puts(" / dwarf-ng Copyright (C) 2007-2013-2017 \\ ");
puts(" | Fernando Iazeolla. This program comes | ");
puts(" | with ABSOLUTELY NO WARRANTY. This is | ");
puts(" | free software (GNU GPLv2), and you are | ");
puts(" | welcome to redistribute it under GNU | ");
puts(" | GPL version 2 (see | ");
puts(" \\ <http://www.gnu.org/licenses/>). / ");
puts(" ---------------------------------------- ");
puts(" \\ ^__^ ");
puts(" \\ (oo)\\_______ ");
puts(" (__)\\ )\\/\\ ");
puts(" ||----w | ");
return puts(" || || ");
}

original_code:
void funny_shell_disclaimer()
{
printf("   ________________________________________  \n");
printf("  / dwarf-ng Copyright (C) 2007-2013-2017  \\ \n");
printf("  | Fernando Iazeolla. This program comes  | \n");
printf("  | with ABSOLUTELY NO WARRANTY. This is   | \n");
printf("  | free software (GNU GPLv2), and you are | \n");
printf("  | welcome to redistribute it under GNU   | \n");
printf("  | GPL version 2 (see                     | \n");
printf("  \\ <http://www.gnu.org/licenses/>).       / \n");
printf("   ----------------------------------------  \n");
printf("          \\   ^__^                           \n");
printf("           \\  (oo)\\_______                   \n");
printf("              (__)\\       )\\/\\               \n");
printf("                  ||----w |                  \n");
printf("                  ||     ||                  \n");
}


decompiled_code:
int normal_shell_disclaimer()
{
puts("dwarf-ng Copyright (C) 2007-2013-2017 Fernando Iazeolla.");
puts("This program comes with ABSOLUTELY NO WARRANTY.");
puts("This is free software (GNU GPLv2), and you are welcome to redistribute it");
return puts("under GNU GPL version 2 (see <http://www.gnu.org/licenses/>).");
}

canonical_decompiled_code:
int func4()
{
puts("dwarf-ng Copyright (C) 2007-2013-2017 Fernando Iazeolla.");
puts("This program comes with ABSOLUTELY NO WARRANTY.");
puts("This is free software (GNU GPLv2), and you are welcome to redistribute it");
return puts("under GNU GPL version 2 (see <http://www.gnu.org/licenses/>).");
}

original_code:
void normal_shell_disclaimer()
{
 printf("dwarf-ng Copyright (C) 2007-2013-2017 Fernando Iazeolla.\n");
 printf("This program comes with ABSOLUTELY NO WARRANTY.\n");
 printf("This is free software (GNU GPLv2), and you are welcome to redistribute it\n");
 printf("under GNU GPL version 2 (see <http://www.gnu.org/licenses/>).\n");
}


decompiled_code:
_BOOL8 check_funny()
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
return div(timer, 10).rem == 7;
}

canonical_decompiled_code:
_BOOL8 func5()
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
return div(timer, 10).rem == 7;
}

original_code:
int check_funny()
{
 time_t now;
 div_t d;
 time(&now);
 d=div(now,10);
 if(d.rem==7) return 1; else return 0;
}

canonical_original_code:
int check_funny()
{
 long now;
 struct div_t d;
 time(&now);
 d=div(now,10);
 if(d.rem==7) return 1; else return 0;
}

variable_types: now long

variable_types:
d
struct div_t { int quot; int rem; }


decompiled_code:
int __fastcall make_prompt(char *a1)
{
int result; // eax

if ( fc_ptr )
result = sprintf(
a1,
"%s[0x%.10llx]>%s ",
*(const char **)(ptr_colors + 64),
*(_QWORD *)(fc_ptr + 3144),
*(const char **)ptr_colors);
else
result = sprintf(a1, "%sdwarf>%s ", *(const char **)(ptr_colors + 64), *(const char **)ptr_colors);
return result;
}

canonical_decompiled_code:
int __fastcall func6(char *a1)
{
int result; // eax

if ( fc_ptr )
result = sprintf(
a1,
"%s[0x%.10llx]>%s ",
*(const char **)(ptr_colors + 64),
*(_QWORD *)(fc_ptr + 3144),
*(const char **)ptr_colors);
else
result = sprintf(a1, "%sdwarf>%s ", *(const char **)(ptr_colors + 64), *(const char **)ptr_colors);
return result;
}

original_code:
void make_prompt(char *s){
 if(!fc_ptr) {sprintf(s,"%sdwarf>%s ",ptr_colors[C_YELLOW],ptr_colors[C_RESET]);return;}
 sprintf(s,"%s[0x%.10llx]>%s ",ptr_colors[C_YELLOW],(long long unsigned)fc_ptr->seek,ptr_colors[C_RESET]);
}

canonical_original_code:
void make_prompt(char *s){
 if(!fc_ptr) {sprintf(s,"%sdwarf>%s ",ptr_colors[C_YELLOW],ptr_colors[C_RESET]);return;}
 sprintf(s,"%s[0x%.10llx]>%s ",ptr_colors[C_YELLOW],(unsigned long long)fc_ptr->seek,ptr_colors[C_RESET]);
}


shell

decompiled_code:
void shell()
{
char *v0; // rbx
const char *v1; // rax

reset_stdin();
quit_shell = 0;
v0 = (char *)malloc(0x80uLL);
if ( check_funny() )
funny_shell_disclaimer();
else
normal_shell_disclaimer();
puts("entering shell-interactive mode...");
puts("type '?' for help.");
while ( !quit_shell )
{
make_prompt(v0);
v1 = (const char *)rl_gets((__int64)v0);
execute(v1);
}
free(v0);
}

canonical_decompiled_code:
void func7()
{
char *v0; // rbx
const char *v1; // rax

reset_stdin();
quit_shell = 0;
v0 = (char *)malloc(0x80uLL);
if ( func5() )
func3();
else
func4();
puts("entering shell-interactive mode...");
puts("type '?' for help.");
while ( !quit_shell )
{
func6(v0);
v1 = (const char *)func0((__int64)v0);
func1(v1);
}
free(v0);
}

original_code:
void shell(void)
{
 char *cmd,*prompt;
 reset_stdin();
 quit_shell=false;
 prompt=(char*)malloc(128*sizeof(char));
 if(check_funny()) funny_shell_disclaimer(); else normal_shell_disclaimer();
 printf("entering shell-interactive mode...\n");
 printf("type '?' for help.\n");
 while(!quit_shell)
 {
  make_prompt(prompt);
  cmd=rl_gets(prompt);
  execute(cmd);
 }
 free(prompt);
}

canonical_original_code:
void shell()
{
 char *cmd; char *prompt;
 reset_stdin();
 quit_shell=false;
 prompt=(char *)malloc(128*sizeof(char));
 if(check_funny()) funny_shell_disclaimer(); else normal_shell_disclaimer();
 printf("entering shell-interactive mode...\n");
 printf("type '?' for help.\n");
 while(!quit_shell)
 {
  make_prompt(prompt);
  cmd=rl_gets(prompt);
  execute(cmd);
 }
 free(prompt);
}

variable_types:
cmd
char *

variable_types:
prompt
char *


die

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
fwrite("** dwarf-ng critical error !!!\n", 1uLL, 0x1FuLL, stderr);
fwrite("------------------------------\n", 1uLL, 0x1FuLL, stderr);
fprintf(stderr, "%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fwrite("** dwarf-ng critical error !!!\n", 1uLL, 0x1FuLL, stderr);
fwrite("------------------------------\n", 1uLL, 0x1FuLL, stderr);
fprintf(stderr, "%s\n", a1);
exit(1);
}

original_code:
void die(char *s)
{
 fprintf(stderr,"** dwarf-ng critical error !!!\n");
 fprintf(stderr,"------------------------------\n");
 fprintf(stderr,"%s\n",s);
 exit(1);
}