decompiled_code:
void __fastcall nikon_prop1(__int16 *a1, __int64 a2)
{
__int16 v3; // ax
char *v4; // rdi
const char *v5; // rdx
size_t v6; // rsi
double v7; // xmm0_8
unsigned int v8; // eax
unsigned int v9; // er12
int v10; // eax
__int64 v11; // rax
__int64 v12; // rdi
__int64 v13; // r12
double v14; // xmm4_8
double v15; // xmm0_8
double v16; // xmm1_8
int v17; // er12
int v18; // eax
int v19; // er12
int v20; // eax
unsigned int v21; // eax
int v22; // er12
int v23; // eax
int v24; // eax
unsigned int v25; // ebp
unsigned int v26; // er12
__int16 v27; // ax
unsigned int v28; // esi
char *v29; // rbp
int v30; // eax
const char *v31; // r12
int v32; // er13
int v33; // eax
char *v34; // r12
const char *v35; // rbp
char v36; // al
size_t v37; // rax
char *v38; // r12
int v39; // er13
int v40; // eax
size_t v41; // rax
int v42; // eax
char *v43; // r13
int v44; // er15
int v45; // eax
int v46; // [rsp+8h] [rbp-60h]
char nptr[4]; // [rsp+10h] [rbp-58h] BYREF
int v48; // [rsp+14h] [rbp-54h]
int v49; // [rsp+18h] [rbp-50h]
int v50; // [rsp+1Ch] [rbp-4Ch]
int v51; // [rsp+20h] [rbp-48h]
int v52; // [rsp+24h] [rbp-44h]
int v53; // [rsp+28h] [rbp-40h]
int v54; // [rsp+2Ch] [rbp-3Ch]

v3 = *a1;
if ( (unsigned __int16)*a1 <= 0x19u )
{
if ( v3 )
{
switch ( v3 )
{
case 1:
byte4exif(*((unsigned int *)a1 + 2), nptr, *(unsigned int *)(a2 + 56));
LOBYTE(v48) = 0;
v24 = atoi(&nptr[2]);
nptr[2] = 0;
v25 = v24;
v26 = atoi(nptr);
exifstralloc(a1 + 16, 8LL);
snprintf(*((char **)a1 + 4), 7uLL, "%d.%d", v26, v25);
return;
case 2:
case 19:
v8 = *((_DWORD *)a1 + 2);
v9 = (unsigned __int16)v8;
if ( !*(_DWORD *)(a2 + 56) )
v9 = HIWORD(v8);
exifstralloc(a1 + 16, 32LL);
snprintf(*((char **)a1 + 4), 0x1FuLL, "%d", v9);
if ( !v9 )
goto LABEL_11;
return;
case 5:
a1[24] = -23549;
return;
case 18:
case 24:
exifstralloc(a1 + 16, 10LL);
v4 = (char *)*((_QWORD *)a1 + 4);
v5 = "%.1f EV";
v6 = 9LL;
v7 = (double)*((unsigned __int8 *)a1 + 11) / 6.0;
goto LABEL_7;
case 25:
v22 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2), *(unsigned int *)(a2 + 56));
v23 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2) + 4LL, *(unsigned int *)(a2 + 56));
if ( v22 && !v23 )
{
LABEL_73:
**((_DWORD **)a1 + 4) = 6369134;
goto LABEL_11;
}
v4 = (char *)*((_QWORD *)a1 + 4);
v5 = "%.1f EV";
v7 = (float)((float)v22 / (float)v23);
LABEL_35:
v6 = 31LL;
LABEL_7:
snprintf(v4, v6, v5, v7);
break;
default:
return;
}
}
}
else
{
switch ( v3 )
{
case 131:
*((_QWORD *)a1 + 4) = finddescr(&nikon_lenstype, *((unsigned __int8 *)a1 + 11));
return;
case 132:
v11 = *((unsigned int *)a1 + 2);
v12 = *(_QWORD *)(a2 + 64);
if ( (int)v11 + 8 * *((_DWORD *)a1 + 1) > (unsigned int)(*(_DWORD *)(a2 + 72) - v12) )
return;
v13 = 0LL;
while ( 1 )
{
*(_DWORD *)&nptr[v13] = exif4byte(v13 + v11 + v12, *(unsigned int *)(a2 + 56));
v13 += 4LL;
if ( v13 == 32 )
break;
v12 = *(_QWORD *)(a2 + 64);
v11 = *((unsigned int *)a1 + 2);
}
if ( *(_DWORD *)nptr && !v48 || v49 && !v50 || v51 && !v52 || v53 && !v54 )
goto LABEL_73;
v14 = (float)((float)v51 / (float)v52);
v15 = (float)((float)*(int *)nptr / (float)v48);
if ( *(_DWORD *)nptr == v49 && v48 == v50 )
{
if ( v51 == v53 && v52 == v54 )
snprintf(*((char **)a1 + 4), 0x1FuLL, "%.1f mm; f/%.1f", v15, v14);
else
snprintf(
*((char **)a1 + 4),
0x1FuLL,
"%.1f mm; f/%.1f - f/%.1f",
v15,
v14,
(float)((float)v53 / (float)v54));
}
else
{
v16 = (float)((float)v49 / (float)v50);
if ( v51 == v53 && v52 == v54 )
snprintf(*((char **)a1 + 4), 0x1FuLL, "%.1f - %.1f mm; f/%.1f", v15, v16, v14);
else
snprintf(
*((char **)a1 + 4),
0x1FuLL,
"%.1f - %.1f mm; f/%.1f - f/%.1f",
v15,
v16,
v14,
(float)((float)v53 / (float)v54));
}
return;
case 133:
v17 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2), *(unsigned int *)(a2 + 56));
v18 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2) + 4LL, *(unsigned int *)(a2 + 56));
if ( v17 == v18 || v17 && !v18 )
goto LABEL_73;
v4 = (char *)*((_QWORD *)a1 + 4);
v5 = "x%.1f m";
v7 = (float)((float)v17 / (float)v18);
goto LABEL_35;
case 134:
v19 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2), *(unsigned int *)(a2 + 56));
v20 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2) + 4LL, *(unsigned int *)(a2 + 56));
if ( v19 != v20 && v19 != 0 && v20 )
{
v4 = (char *)*((_QWORD *)a1 + 4);
v5 = "x%.1f";
v7 = (float)((float)v19 / (float)v20);
goto LABEL_35;
}
strcpy(*((char **)a1 + 4), "None");
a1[20] = 8;
return;
case 136:
v21 = *((_DWORD *)a1 + 2);
if ( (v21 & 0xFFFF00FF) != 0 )
{
v38 = (char *)finddescr(&nikon_afmode, HIBYTE(v21));
v29 = (char *)finddescr(&nikon_afpos, *((unsigned __int8 *)a1 + 8));
if ( (unsigned __int8)BYTE2(*((_DWORD *)a1 + 2)) != *((_BYTE *)a1 + 8) )
{
v43 = (char *)finddescr(&nikon_afpos, (unsigned __int8)BYTE2(*((_DWORD *)a1 + 2)));
v46 = strlen(v38);
v44 = strlen(v29);
v45 = strlen(v43);
exifstralloc(a1 + 16, (unsigned int)(v46 + v44 + 24 + v45));
sprintf(*((char **)a1 + 4), "%s, %s Selected, %s Focused", v38, v43, v29);
free(v43);
}
else
{
v39 = strlen(v38);
v40 = strlen(v29);
exifstralloc(a1 + 16, (unsigned int)(v39 + v40 + 3));
sprintf(*((char **)a1 + 4), "%s, %s", v38, v29);
}
free(v38);
LABEL_56:
free(v29);
}
else
{
if ( *((_QWORD *)a1 + 4) )
{
puts("err, hello? overwriting?");
v21 = *((_DWORD *)a1 + 2);
}
*((_QWORD *)a1 + 4) = finddescr(&nikon_afpos, BYTE1(v21));
}
return;
case 137:
v27 = a1[1];
v28 = *((_DWORD *)a1 + 2);
if ( v27 == 1 )
{
v28 >>= 24;
*((_DWORD *)a1 + 2) = v28;
}
else if ( v27 == 3 )
{
v28 = BYTE1(v28);
*((_DWORD *)a1 + 2) = v28;
}
v29 = (char *)finddescr(&nikon_shoot, v28 & 3);
if ( (*((_DWORD *)a1 + 2) & 0x40) != 0 )
{
v30 = *((_DWORD *)a1 + 2) & 0x10;
v31 = "On, White Balance";
v32 = (v30 == 0) + 17;
if ( !v30 )
v31 = "Off, White Balance";
}
else
{
v42 = *((_DWORD *)a1 + 2) & 0x10;
v31 = "On";
v32 = (v42 == 0) + 2;
if ( !v42 )
v31 = "Off";
}
v33 = strlen(v29);
exifstralloc(a1 + 16, (unsigned int)(v32 + v33 + 2));
sprintf(*((char **)a1 + 4), "%s/%s", v29, v31);
goto LABEL_56;
case 141:
if ( *((_QWORD *)a1 + 4) )
{
if ( !memcmp(*((const void **)a1 + 4), "MODE1a", 6uLL) )
{
free(*((void **)a1 + 4));
*((_QWORD *)a1 + 4) = 0LL;
exifstralloc(a1 + 16, 14LL);
strcpy(*((char **)a1 + 4), "Portrait sRGB");
}
else if ( !memcmp(*((const void **)a1 + 4), "MODE2", 5uLL) )
{
free(*((void **)a1 + 4));
*((_QWORD *)a1 + 4) = 0LL;
exifstralloc(a1 + 16, 10LL);
strcpy(*((char **)a1 + 4), "Adobe RGB");
}
else if ( !memcmp(*((const void **)a1 + 4), "MODE3a", 6uLL) )
{
free(*((void **)a1 + 4));
*((_QWORD *)a1 + 4) = 0LL;
exifstralloc(a1 + 16, 15LL);
strcpy(*((char **)a1 + 4), "Landscape sRGB");
}
}
return;
case 148:
v10 = *((_DWORD *)a1 + 2);
if ( !v10 )
{
exifstralloc(a1 + 16, 7LL);
strcpy(*((char **)a1 + 4), "Normal");
LABEL_14:
a1[24] = -23543;
return;
}
if ( v10 == -3 )
{
exifstralloc(a1 + 16, 14LL);
strcpy(*((char **)a1 + 4), "Black & White");
goto LABEL_14;
}
LABEL_11:
a1[20] = 8;
break;
case 160:
v34 = (char *)*((_QWORD *)a1 + 4);
if ( !memcmp(v34, "NO= ", 4uLL) )
{
v41 = strlen(v34 + 4);
memmove(v34, v34 + 4, v41 + 1);
v34 = (char *)*((_QWORD *)a1 + 4);
}
if ( *v34 == 32 )
{
v35 = v34;
do
v36 = *++v35;
while ( v36 == 32 );
if ( v35 > v34 && v36 )
{
v37 = strlen(v35);
memmove(v34, v35, v37 + 1);
}
}
return;
case 170:
goto LABEL_14;
default:
return;
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int16 *a1, __int64 a2)
{
__int16 v3; // ax
char *v4; // rdi
const char *v5; // rdx
size_t v6; // rsi
double v7; // xmm0_8
unsigned int v8; // eax
unsigned int v9; // er12
int v10; // eax
__int64 v11; // rax
__int64 v12; // rdi
__int64 v13; // r12
double v14; // xmm4_8
double v15; // xmm0_8
double v16; // xmm1_8
int v17; // er12
int v18; // eax
int v19; // er12
int v20; // eax
unsigned int v21; // eax
int v22; // er12
int v23; // eax
int v24; // eax
unsigned int v25; // ebp
unsigned int v26; // er12
__int16 v27; // ax
unsigned int v28; // esi
char *v29; // rbp
int v30; // eax
const char *v31; // r12
int v32; // er13
int v33; // eax
char *v34; // r12
const char *v35; // rbp
char v36; // al
size_t v37; // rax
char *v38; // r12
int v39; // er13
int v40; // eax
size_t v41; // rax
int v42; // eax
char *v43; // r13
int v44; // er15
int v45; // eax
int v46; // [rsp+8h] [rbp-60h]
char nptr[4]; // [rsp+10h] [rbp-58h] BYREF
int v48; // [rsp+14h] [rbp-54h]
int v49; // [rsp+18h] [rbp-50h]
int v50; // [rsp+1Ch] [rbp-4Ch]
int v51; // [rsp+20h] [rbp-48h]
int v52; // [rsp+24h] [rbp-44h]
int v53; // [rsp+28h] [rbp-40h]
int v54; // [rsp+2Ch] [rbp-3Ch]

v3 = *a1;
if ( (unsigned __int16)*a1 <= 0x19u )
{
if ( v3 )
{
switch ( v3 )
{
case 1:
byte4exif(*((unsigned int *)a1 + 2), nptr, *(unsigned int *)(a2 + 56));
LOBYTE(v48) = 0;
v24 = atoi(&nptr[2]);
nptr[2] = 0;
v25 = v24;
v26 = atoi(nptr);
exifstralloc(a1 + 16, 8LL);
snprintf(*((char **)a1 + 4), 7uLL, "%d.%d", v26, v25);
return;
case 2:
case 19:
v8 = *((_DWORD *)a1 + 2);
v9 = (unsigned __int16)v8;
if ( !*(_DWORD *)(a2 + 56) )
v9 = HIWORD(v8);
exifstralloc(a1 + 16, 32LL);
snprintf(*((char **)a1 + 4), 0x1FuLL, "%d", v9);
if ( !v9 )
goto LABEL_11;
return;
case 5:
a1[24] = -23549;
return;
case 18:
case 24:
exifstralloc(a1 + 16, 10LL);
v4 = (char *)*((_QWORD *)a1 + 4);
v5 = "%.1f EV";
v6 = 9LL;
v7 = (double)*((unsigned __int8 *)a1 + 11) / 6.0;
goto LABEL_7;
case 25:
v22 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2), *(unsigned int *)(a2 + 56));
v23 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2) + 4LL, *(unsigned int *)(a2 + 56));
if ( v22 && !v23 )
{
LABEL_73:
**((_DWORD **)a1 + 4) = 6369134;
goto LABEL_11;
}
v4 = (char *)*((_QWORD *)a1 + 4);
v5 = "%.1f EV";
v7 = (float)((float)v22 / (float)v23);
LABEL_35:
v6 = 31LL;
LABEL_7:
snprintf(v4, v6, v5, v7);
break;
default:
return;
}
}
}
else
{
switch ( v3 )
{
case 131:
*((_QWORD *)a1 + 4) = finddescr(&nikon_lenstype, *((unsigned __int8 *)a1 + 11));
return;
case 132:
v11 = *((unsigned int *)a1 + 2);
v12 = *(_QWORD *)(a2 + 64);
if ( (int)v11 + 8 * *((_DWORD *)a1 + 1) > (unsigned int)(*(_DWORD *)(a2 + 72) - v12) )
return;
v13 = 0LL;
while ( 1 )
{
*(_DWORD *)&nptr[v13] = exif4byte(v13 + v11 + v12, *(unsigned int *)(a2 + 56));
v13 += 4LL;
if ( v13 == 32 )
break;
v12 = *(_QWORD *)(a2 + 64);
v11 = *((unsigned int *)a1 + 2);
}
if ( *(_DWORD *)nptr && !v48 || v49 && !v50 || v51 && !v52 || v53 && !v54 )
goto LABEL_73;
v14 = (float)((float)v51 / (float)v52);
v15 = (float)((float)*(int *)nptr / (float)v48);
if ( *(_DWORD *)nptr == v49 && v48 == v50 )
{
if ( v51 == v53 && v52 == v54 )
snprintf(*((char **)a1 + 4), 0x1FuLL, "%.1f mm; f/%.1f", v15, v14);
else
snprintf(
*((char **)a1 + 4),
0x1FuLL,
"%.1f mm; f/%.1f - f/%.1f",
v15,
v14,
(float)((float)v53 / (float)v54));
}
else
{
v16 = (float)((float)v49 / (float)v50);
if ( v51 == v53 && v52 == v54 )
snprintf(*((char **)a1 + 4), 0x1FuLL, "%.1f - %.1f mm; f/%.1f", v15, v16, v14);
else
snprintf(
*((char **)a1 + 4),
0x1FuLL,
"%.1f - %.1f mm; f/%.1f - f/%.1f",
v15,
v16,
v14,
(float)((float)v53 / (float)v54));
}
return;
case 133:
v17 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2), *(unsigned int *)(a2 + 56));
v18 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2) + 4LL, *(unsigned int *)(a2 + 56));
if ( v17 == v18 || v17 && !v18 )
goto LABEL_73;
v4 = (char *)*((_QWORD *)a1 + 4);
v5 = "x%.1f m";
v7 = (float)((float)v17 / (float)v18);
goto LABEL_35;
case 134:
v19 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2), *(unsigned int *)(a2 + 56));
v20 = exif4byte(*(_QWORD *)(a2 + 64) + *((unsigned int *)a1 + 2) + 4LL, *(unsigned int *)(a2 + 56));
if ( v19 != v20 && v19 != 0 && v20 )
{
v4 = (char *)*((_QWORD *)a1 + 4);
v5 = "x%.1f";
v7 = (float)((float)v19 / (float)v20);
goto LABEL_35;
}
strcpy(*((char **)a1 + 4), "None");
a1[20] = 8;
return;
case 136:
v21 = *((_DWORD *)a1 + 2);
if ( (v21 & 0xFFFF00FF) != 0 )
{
v38 = (char *)finddescr(&nikon_afmode, HIBYTE(v21));
v29 = (char *)finddescr(&nikon_afpos, *((unsigned __int8 *)a1 + 8));
if ( (unsigned __int8)BYTE2(*((_DWORD *)a1 + 2)) != *((_BYTE *)a1 + 8) )
{
v43 = (char *)finddescr(&nikon_afpos, (unsigned __int8)BYTE2(*((_DWORD *)a1 + 2)));
v46 = strlen(v38);
v44 = strlen(v29);
v45 = strlen(v43);
exifstralloc(a1 + 16, (unsigned int)(v46 + v44 + 24 + v45));
sprintf(*((char **)a1 + 4), "%s, %s Selected, %s Focused", v38, v43, v29);
free(v43);
}
else
{
v39 = strlen(v38);
v40 = strlen(v29);
exifstralloc(a1 + 16, (unsigned int)(v39 + v40 + 3));
sprintf(*((char **)a1 + 4), "%s, %s", v38, v29);
}
free(v38);
LABEL_56:
free(v29);
}
else
{
if ( *((_QWORD *)a1 + 4) )
{
puts("err, hello? overwriting?");
v21 = *((_DWORD *)a1 + 2);
}
*((_QWORD *)a1 + 4) = finddescr(&nikon_afpos, BYTE1(v21));
}
return;
case 137:
v27 = a1[1];
v28 = *((_DWORD *)a1 + 2);
if ( v27 == 1 )
{
v28 >>= 24;
*((_DWORD *)a1 + 2) = v28;
}
else if ( v27 == 3 )
{
v28 = BYTE1(v28);
*((_DWORD *)a1 + 2) = v28;
}
v29 = (char *)finddescr(&nikon_shoot, v28 & 3);
if ( (*((_DWORD *)a1 + 2) & 0x40) != 0 )
{
v30 = *((_DWORD *)a1 + 2) & 0x10;
v31 = "On, White Balance";
v32 = (v30 == 0) + 17;
if ( !v30 )
v31 = "Off, White Balance";
}
else
{
v42 = *((_DWORD *)a1 + 2) & 0x10;
v31 = "On";
v32 = (v42 == 0) + 2;
if ( !v42 )
v31 = "Off";
}
v33 = strlen(v29);
exifstralloc(a1 + 16, (unsigned int)(v32 + v33 + 2));
sprintf(*((char **)a1 + 4), "%s/%s", v29, v31);
goto LABEL_56;
case 141:
if ( *((_QWORD *)a1 + 4) )
{
if ( !memcmp(*((const void **)a1 + 4), "MODE1a", 6uLL) )
{
free(*((void **)a1 + 4));
*((_QWORD *)a1 + 4) = 0LL;
exifstralloc(a1 + 16, 14LL);
strcpy(*((char **)a1 + 4), "Portrait sRGB");
}
else if ( !memcmp(*((const void **)a1 + 4), "MODE2", 5uLL) )
{
free(*((void **)a1 + 4));
*((_QWORD *)a1 + 4) = 0LL;
exifstralloc(a1 + 16, 10LL);
strcpy(*((char **)a1 + 4), "Adobe RGB");
}
else if ( !memcmp(*((const void **)a1 + 4), "MODE3a", 6uLL) )
{
free(*((void **)a1 + 4));
*((_QWORD *)a1 + 4) = 0LL;
exifstralloc(a1 + 16, 15LL);
strcpy(*((char **)a1 + 4), "Landscape sRGB");
}
}
return;
case 148:
v10 = *((_DWORD *)a1 + 2);
if ( !v10 )
{
exifstralloc(a1 + 16, 7LL);
strcpy(*((char **)a1 + 4), "Normal");
LABEL_14:
a1[24] = -23543;
return;
}
if ( v10 == -3 )
{
exifstralloc(a1 + 16, 14LL);
strcpy(*((char **)a1 + 4), "Black & White");
goto LABEL_14;
}
LABEL_11:
a1[20] = 8;
break;
case 160:
v34 = (char *)*((_QWORD *)a1 + 4);
if ( !memcmp(v34, "NO= ", 4uLL) )
{
v41 = strlen(v34 + 4);
memmove(v34, v34 + 4, v41 + 1);
v34 = (char *)*((_QWORD *)a1 + 4);
}
if ( *v34 == 32 )
{
v35 = v34;
do
v36 = *++v35;
while ( v36 == 32 );
if ( v35 > v34 && v36 )
{
v37 = strlen(v35);
memmove(v34, v35, v37 + 1);
}
}
return;
case 170:
goto LABEL_14;
default:
return;
}
}
}

original_code:
static void
nikon_prop1(struct exifprop *prop, struct exiftags *t)
{
 int i;
 u_int32_t v[8];
 char *c1, *c2, *c3;
 int32_t sn, sd;
 char buf[5];
 switch (prop->tag) {
 case 0x0001:
  byte4exif(prop->value, (unsigned char *)buf, t->mkrmd.order);
  buf[4] = '\0';
  v[1] = atoi(buf + 2);
  buf[2] = '\0';
  v[0] = atoi(buf);
  exifstralloc(&prop->str, 8);
  snprintf(prop->str, 7, "%d.%d", v[0], v[1]);
  break;
 case 0x0002:
 case 0x0013:
  if (t->mkrmd.order == LITTLE)
   v[0] = (prop->value >> 16) & 0xffff;
  else
   v[0] = prop->value & 0xffff;
  exifstralloc(&prop->str, 32);
  snprintf(prop->str, 31, "%d", (u_int16_t)v[0]);
  if (!v[0]) prop->lvl = 0x08;
  break;
 case 0x0005:
  prop->override = 0xa403;
  break;
 case 0x0012:
 case 0x0018:
  exifstralloc(&prop->str, 10);
  snprintf(prop->str, 9, "%.1f EV",
      (int16_t)(prop->value >> 24) / 6.0);
  break;
 case 0x0019:
  sn = exif4byte(t->mkrmd.btiff + prop->value, t->mkrmd.order);
  sd = exif4byte(t->mkrmd.btiff + prop->value + 4,
      t->mkrmd.order);
  if (sn && !sd) {
   snprintf(prop->str, 31, "n/a");
   prop->lvl = 0x08;
  } else
   snprintf(prop->str, 31, "%.1f EV", (float)sn /
       (float)sd);
  break;
 case 0x0083:
  prop->str = finddescr(nikon_lenstype,
      (u_int16_t)((prop->value >> 24) & 0xff));
  break;
 case 0x0084:
  if (prop->value + prop->count * 8 >
      (u_int32_t)(t->mkrmd.etiff - t->mkrmd.btiff))
   break;
  for (i = 0; i < 8; i++)
   v[i] = exif4byte(t->mkrmd.btiff + prop->value + (i * 4),
       t->mkrmd.order);
  if ((v[0] && !v[1]) || (v[2] && !v[3]) ||
      (v[4] && !v[5]) || (v[6] && !v[7])) {
   snprintf(prop->str, 31, "n/a");
   prop->lvl = 0x08;
   break;
  }
  if (v[0] == v[2] && v[1] == v[3]) {
   if (v[4] == v[6] && v[5] == v[7]) {
    snprintf(prop->str, 31, "%.1f mm; f/%.1f",
        (float)v[0] / (float)v[1],
        (float)v[4] / (float)v[5]);
    break;
   }
   snprintf(prop->str, 31, "%.1f mm; f/%.1f - f/%.1f",
       (float)v[0] / (float)v[1], (float)v[4] /
       (float)v[5], (float)v[6] / (float)v[7]);
   break;
  }
  if (v[4] == v[6] && v[5] == v[7]) {
   snprintf(prop->str, 31, "%.1f - %.1f mm; f/%.1f",
       (float)v[0] / (float)v[1], (float)v[2] /
       (float)v[3], (float)v[4] / (float)v[5]);
   break;
  }
  snprintf(prop->str, 31, "%.1f - %.1f mm; f/%.1f - f/%.1f",
      (float)v[0] / (float)v[1], (float)v[2] / (float)v[3],
      (float)v[4] / (float)v[5], (float)v[6] / (float)v[7]);
  break;
 case 0x0085:
  v[0] = exif4byte(t->mkrmd.btiff + prop->value, t->mkrmd.order);
  v[1] = exif4byte(t->mkrmd.btiff + prop->value + 4,
      t->mkrmd.order);
  if (v[0] == v[1] || (v[0] && !v[1])) {
   snprintf(prop->str, 31, "n/a");
   prop->lvl = 0x08;
  } else
   snprintf(prop->str, 31, "x%.1f m", (float)v[0] /
       (float)v[1]);
  break;
 case 0x0086:
  v[0] = exif4byte(t->mkrmd.btiff + prop->value, t->mkrmd.order);
  v[1] = exif4byte(t->mkrmd.btiff + prop->value + 4,
      t->mkrmd.order);
  if (v[0] == v[1] || !v[0] || (v[0] && !v[1])) {
   snprintf(prop->str, 31, "None");
   prop->lvl = 0x08;
  } else
   snprintf(prop->str, 31, "x%.1f", (float)v[0] /
       (float)v[1]);
  break;
 case 0x0088:
  if (!(prop->value & 0xffff00ff)) {
   if (prop->str) printf("err, hello?  overwriting?\n");
   prop->str = finddescr(nikon_afpos,
       (u_int16_t)((prop->value >> 8) & 0xff));
   break;
  }
  c1 = finddescr(nikon_afmode,
      (u_int16_t)((prop->value >> 24) & 0xff));
  c2 = finddescr(nikon_afpos, (u_int16_t)(prop->value & 0xff));
  if ((prop->value & 0xff) == ((prop->value >> 16) & 0xff)) {
   exifstralloc(&prop->str, strlen(c1) + strlen(c2) + 3);
   sprintf(prop->str, "%s, %s", c1, c2);
  } else {
   c3 = finddescr(nikon_afpos,
       (u_int16_t)((prop->value >> 16) & 0xff));
   exifstralloc(&prop->str, strlen(c1) + strlen(c2) +
       strlen(c3) + 24);
   sprintf(prop->str, "%s, %s Selected, %s Focused",
       c1, c3, c2);
   free(c3);
  }
  free(c1);
  free(c2);
  break;
 case 0x0089:
  if (prop->type == 1)
   prop->value = (prop->value >> 24) & 0xff;
  else if (prop->type == 3)
   prop->value = (prop->value >> 8) & 0xff;
  c1 = finddescr(nikon_shoot, (u_int16_t)(prop->value & 0x03));
  if (prop->value & 0x40) {
   if (prop->value & 0x10)
    c2 = "On, White Balance";
   else
    c2 = "Off, White Balance";
  } else {
   if (prop->value & 0x10)
    c2 = "On";
   else
    c2 = "Off";
  }
  exifstralloc(&prop->str, strlen(c1) + strlen(c2) + 2);
  sprintf(prop->str, "%s/%s", c1, c2);
  free(c1);
  break;
 case 0x008d:
  if (!(c1 = prop->str)) break;
  if (!strncmp(c1, "MODE1a", 6)) {
   free(c1);
   prop->str = ((void *)0);
   c1 = "Portrait sRGB";
   exifstralloc(&prop->str, strlen(c1) + 1);
   strcpy(prop->str, c1);
   break;
  }
  if (!strncmp(c1, "MODE2", 5)) {
   free(c1);
   prop->str = ((void *)0);
   c1 = "Adobe RGB";
   exifstralloc(&prop->str, strlen(c1) + 1);
   strcpy(prop->str, c1);
   break;
  }
  if (!strncmp(c1, "MODE3a", 6)) {
   free(c1);
   prop->str = ((void *)0);
   c1 = "Landscape sRGB";
   exifstralloc(&prop->str, strlen(c1) + 1);
   strcpy(prop->str, c1);
   break;
  }
  break;
 case 0x0094:
  c1 = ((void *)0);
  switch (prop->value) {
  case -3:
   c1 = "Black & White";
   exifstralloc(&prop->str, strlen(c1) + 1);
   strcpy(prop->str, c1);
   break;
  case 0:
   c1 = "Normal";
   exifstralloc(&prop->str, strlen(c1) + 1);
   strcpy(prop->str, c1);
   break;
  }
  if (!c1) {
   prop->lvl = 0x08;
   break;
  }
 case 0x00aa:
  prop->override = 0xa409;
  break;
 case 0x00a0:
  if (!strncmp(prop->str, "NO= ", 4))
   memmove(prop->str, prop->str + 4,
       strlen(prop->str + 4) + 1);
  for (c1 = prop->str; *c1 && *c1 == (unsigned char)' '; c1++);
  if (*c1 && c1 > prop->str)
   memmove(prop->str, c1, strlen(c1) + 1);
  break;
 }
}

canonical_original_code:
static void nikon_prop1(struct exifprop *prop, struct exiftags *t)
{
 int i;
 unsigned int v[8];
 char *c1; char *c2; char *c3;
 int sn; int sd;
 char buf[5];
 switch (prop->tag) {
 case 0x0001:
  byte4exif(prop->value, (unsigned char *)buf, t->mkrmd.order);
  buf[4] = '\0';
  v[1] = atoi(buf + 2);
  buf[2] = '\0';
  v[0] = atoi(buf);
  exifstralloc(&prop->str, 8);
  snprintf(prop->str, 7, "%d.%d", v[0], v[1]);
  break;
 case 0x0002:
 case 0x0013:
  if (t->mkrmd.order == LITTLE)
   v[0] = (prop->value >> 16) & 0xffff;
  else
   v[0] = prop->value & 0xffff;
  exifstralloc(&prop->str, 32);
  snprintf(prop->str, 31, "%d", (unsigned int)v[0]);
  if (!v[0]) prop->lvl = 0x08;
  break;
 case 0x0005:
  prop->override = 0xa403;
  break;
 case 0x0012:
 case 0x0018:
  exifstralloc(&prop->str, 10);
  snprintf(prop->str, 9, "%.1f EV",
      (short)(prop->value >> 24) / 6.0);
  break;
 case 0x0019:
  sn = exif4byte(t->mkrmd.btiff + prop->value, t->mkrmd.order);
  sd = exif4byte(t->mkrmd.btiff + prop->value + 4,
      t->mkrmd.order);
  if (sn && !sd) {
   snprintf(prop->str, 31, "n/a");
   prop->lvl = 0x08;
  } else
   snprintf(prop->str, 31, "%.1f EV", (float)sn /
       (float)sd);
  break;
 case 0x0083:
  prop->str = finddescr(nikon_lenstype,
      (u_int16_t)((prop->value >> 24) & 0xff));
  break;
 case 0x0084:
  if (prop->value + prop->count * 8 >
      (u_int32_t)(t->mkrmd.etiff - t->mkrmd.btiff))
   break;
  for (i = 0; i < 8; i++)
   v[i] = exif4byte(t->mkrmd.btiff + prop->value + (i * 4),
       t->mkrmd.order);
  if ((v[0] && !v[1]) || (v[2] && !v[3]) ||
      (v[4] && !v[5]) || (v[6] && !v[7])) {
   snprintf(prop->str, 31, "n/a");
   prop->lvl = 0x08;
   break;
  }
  if (v[0] == v[2] && v[1] == v[3]) {
   if (v[4] == v[6] && v[5] == v[7]) {
    snprintf(prop->str, 31, "%.1f mm; f/%.1f",
        (float)v[0] / (float)v[1],
        (float)v[4] / (float)v[5]);
    break;
   }
   snprintf(prop->str, 31, "%.1f mm; f/%.1f - f/%.1f",
       (float)v[0] / (float)v[1], (float)v[4] /
       (float)v[5], (float)v[6] / (float)v[7]);
   break;
  }
  if (v[4] == v[6] && v[5] == v[7]) {
   snprintf(prop->str, 31, "%.1f - %.1f mm; f/%.1f",
       (float)v[0] / (float)v[1], (float)v[2] /
       (float)v[3], (float)v[4] / (float)v[5]);
   break;
  }
  snprintf(prop->str, 31, "%.1f - %.1f mm; f/%.1f - f/%.1f",
      (float)v[0] / (float)v[1], (float)v[2] / (float)v[3],
      (float)v[4] / (float)v[5], (float)v[6] / (float)v[7]);
  break;
 case 0x0085:
  v[0] = exif4byte(t->mkrmd.btiff + prop->value, t->mkrmd.order);
  v[1] = exif4byte(t->mkrmd.btiff + prop->value + 4,
      t->mkrmd.order);
  if (v[0] == v[1] || (v[0] && !v[1])) {
   snprintf(prop->str, 31, "n/a");
   prop->lvl = 0x08;
  } else
   snprintf(prop->str, 31, "x%.1f m", (float)v[0] /
       (float)v[1]);
  break;
 case 0x0086:
  v[0] = exif4byte(t->mkrmd.btiff + prop->value, t->mkrmd.order);
  v[1] = exif4byte(t->mkrmd.btiff + prop->value + 4,
      t->mkrmd.order);
  if (v[0] == v[1] || !v[0] || (v[0] && !v[1])) {
   snprintf(prop->str, 31, "None");
   prop->lvl = 0x08;
  } else
   snprintf(prop->str, 31, "x%.1f", (float)v[0] /
       (float)v[1]);
  break;
 case 0x0088:
  if (!(prop->value & 0xffff00ff)) {
   if (prop->str) printf("err, hello?  overwriting?\n");
   prop->str = finddescr(nikon_afpos,
       (u_int16_t)((prop->value >> 8) & 0xff));
   break;
  }
  c1 = finddescr(nikon_afmode,
      (u_int16_t)((prop->value >> 24) & 0xff));
  c2 = finddescr(nikon_afpos, (u_int16_t)(prop->value & 0xff));
  if ((prop->value & 0xff) == ((prop->value >> 16) & 0xff)) {
   exifstralloc(&prop->str, strlen(c1) + strlen(c2) + 3);
   sprintf(prop->str, "%s, %s", c1, c2);
  } else {
   c3 = finddescr(nikon_afpos,
       (u_int16_t)((prop->value >> 16) & 0xff));
   exifstralloc(&prop->str, strlen(c1) + strlen(c2) +
       strlen(c3) + 24);
   sprintf(prop->str, "%s, %s Selected, %s Focused",
       c1, c3, c2);
   free(c3);
  }
  free(c1);
  free(c2);
  break;
 case 0x0089:
  if (prop->type == 1)
   prop->value = (prop->value >> 24) & 0xff;
  else if (prop->type == 3)
   prop->value = (prop->value >> 8) & 0xff;
  c1 = finddescr(nikon_shoot, (u_int16_t)(prop->value & 0x03));
  if (prop->value & 0x40) {
   if (prop->value & 0x10)
    c2 = "On, White Balance";
   else
    c2 = "Off, White Balance";
  } else {
   if (prop->value & 0x10)
    c2 = "On";
   else
    c2 = "Off";
  }
  exifstralloc(&prop->str, strlen(c1) + strlen(c2) + 2);
  sprintf(prop->str, "%s/%s", c1, c2);
  free(c1);
  break;
 case 0x008d:
  if (!(c1 = prop->str)) break;
  if (!strncmp(c1, "MODE1a", 6)) {
   free(c1);
   prop->str = ((void *)0);
   c1 = "Portrait sRGB";
   exifstralloc(&prop->str, strlen(c1) + 1);
   strcpy(prop->str, c1);
   break;
  }
  if (!strncmp(c1, "MODE2", 5)) {
   free(c1);
   prop->str = ((void *)0);
   c1 = "Adobe RGB";
   exifstralloc(&prop->str, strlen(c1) + 1);
   strcpy(prop->str, c1);
   break;
  }
  if (!strncmp(c1, "MODE3a", 6)) {
   free(c1);
   prop->str = ((void *)0);
   c1 = "Landscape sRGB";
   exifstralloc(&prop->str, strlen(c1) + 1);
   strcpy(prop->str, c1);
   break;
  }
  break;
 case 0x0094:
  c1 = ((void *)0);
  switch (prop->value) {
  case -3:
   c1 = "Black & White";
   exifstralloc(&prop->str, strlen(c1) + 1);
   strcpy(prop->str, c1);
   break;
  case 0:
   c1 = "Normal";
   exifstralloc(&prop->str, strlen(c1) + 1);
   strcpy(prop->str, c1);
   break;
  }
  if (!c1) {
   prop->lvl = 0x08;
   break;
  }
 case 0x00aa:
  prop->override = 0xa409;
  break;
 case 0x00a0:
  if (!strncmp(prop->str, "NO= ", 4))
   memmove(prop->str, prop->str + 4,
       strlen(prop->str + 4) + 1);
  for (c1 = prop->str; *c1 && *c1 == (unsigned char)' '; c1++);
  if (*c1 && c1 > prop->str)
   memmove(prop->str, c1, strlen(c1) + 1);
  break;
 }
}

variable_types: i int

variable_types:
v
unsigned int [8]

variable_types: sn int

variable_types: sd int

variable_types:
buf
char [5]

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


repo: ejohnst/exiftags

original_code:
void
nikon_prop(struct exifprop *prop, struct exiftags *t)
{
 int i;
 for (i = 0; prop->tagset[i].tag < 0xffff &&
     prop->tagset[i].tag != prop->tag; i++);
 if (prop->tagset[i].type && prop->tagset[i].type != prop->type)
  exifwarn2("field type mismatch", prop->name);
 if (prop->tagset[i].count && prop->tagset[i].count != prop->count)
  exifwarn2("field count mismatch", prop->name);
 if (prop->tagset == nikon_tags0) {
  nikon_prop0(prop, t);
  return;
 }
 if (prop->tagset == nikon_tags1) {
  nikon_prop1(prop, t);
  return;
 }
}

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 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 exiftags { struct exifprop *props; struct tiffmeta md; char *model; short mkrval; struct tiffmeta mkrmd; short exifmaj; short exifmin; }

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

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 nikon_ifd(unsigned int a1, unsigned int *a2)
{
__int64 v3; // rbx
__int16 v4; // ax
__int64 result; // rax
__int64 v6; // rsi
unsigned int v7; // eax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = *((_QWORD *)a2 + 1) + a1;
if ( strcmp((const char *)v3, "Nikon") )
{
readifd(a1, v8, &nikon_tags1, a2);
return v8[0];
}
v4 = exif2byte(v3 + 6, 1LL);
if ( (v4 & 0xFFEF) == 512 )
{
if ( *(_WORD *)(v3 + 10) == 19789 )
{
*a2 = 1;
v6 = 1LL;
}
else
{
if ( *(_WORD *)(v3 + 10) != 18761 )
{
LABEL_13:
exifwarn("invalid Nikon TIFF header");
return 0LL;
}
*a2 = 0;
v6 = 0LL;
}
*((_QWORD *)a2 + 1) = v3 + 10;
if ( (unsigned __int16)exif2byte(v3 + 12, v6) == 42 )
{
v7 = exif4byte(v3 + 14, *a2);
readifd(v7, v8, &nikon_tags1, a2);
return v8[0];
}
goto LABEL_13;
}
if ( v4 == 256 )
{
readifd(a1 + 8, v8, &nikon_tags0, a2);
result = v8[0];
}
else
{
exifwarn("Nikon maker note version not supported");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int *a2)
{
__int64 v3; // rbx
__int16 v4; // ax
__int64 result; // rax
__int64 v6; // rsi
unsigned int v7; // eax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = *((_QWORD *)a2 + 1) + a1;
if ( strcmp((const char *)v3, "Nikon") )
{
readifd(a1, v8, &nikon_tags1, a2);
return v8[0];
}
v4 = exif2byte(v3 + 6, 1LL);
if ( (v4 & 0xFFEF) == 512 )
{
if ( *(_WORD *)(v3 + 10) == 19789 )
{
*a2 = 1;
v6 = 1LL;
}
else
{
if ( *(_WORD *)(v3 + 10) != 18761 )
{
LABEL_13:
exifwarn("invalid Nikon TIFF header");
return 0LL;
}
*a2 = 0;
v6 = 0LL;
}
*((_QWORD *)a2 + 1) = v3 + 10;
if ( (unsigned __int16)exif2byte(v3 + 12, v6) == 42 )
{
v7 = exif4byte(v3 + 14, *a2);
readifd(v7, v8, &nikon_tags1, a2);
return v8[0];
}
goto LABEL_13;
}
if ( v4 == 256 )
{
readifd(a1 + 8, v8, &nikon_tags0, a2);
result = v8[0];
}
else
{
exifwarn("Nikon maker note version not supported");
result = 0LL;
}
return result;
}

original_code:
struct ifd *
nikon_ifd(u_int32_t offset, struct tiffmeta *md)
{
 struct ifd *myifd;
 unsigned char *b;
 b = md->btiff + offset;
 if (!strcmp((const char *)b, "Nikon")) {
  b += 6;
  switch (exif2byte(b, BIG)) {
  case 0x0100:
   readifd(offset + 8, &myifd, nikon_tags0, md);
   return (myifd);
  case 0x0200:
  case 0x0210:
   b += 4;
   if (!memcmp(b, "MM", 2))
    md->order = BIG;
   else if (!memcmp(b, "II", 2))
    md->order = LITTLE;
   else {
    exifwarn("invalid Nikon TIFF header");
    return (((void *)0));
   }
   md->btiff = b;
   b += 2;
   if (exif2byte(b, md->order) != 42) {
    exifwarn("invalid Nikon TIFF header");
    return (((void *)0));
   }
   b += 2;
   readifd(exif4byte(b, md->order), &myifd,
       nikon_tags1, md);
   return (myifd);
  default:
   exifwarn("Nikon maker note version not supported");
   return (((void *)0));
  }
 }
 readifd(offset, &myifd, nikon_tags1, md);
 return (myifd);
}

canonical_original_code:
struct ifd *nikon_ifd(unsigned int offset, struct tiffmeta *md)
{
 struct ifd *myifd;
 unsigned char *b;
 b = md->btiff + offset;
 if (!strcmp((char *)b, "Nikon")) {
  b += 6;
  switch (exif2byte(b, BIG)) {
  case 0x0100:
   readifd(offset + 8, &myifd, nikon_tags0, md);
   return (myifd);
  case 0x0200:
  case 0x0210:
   b += 4;
   if (!memcmp(b, "MM", 2))
    md->order = BIG;
   else if (!memcmp(b, "II", 2))
    md->order = LITTLE;
   else {
    exifwarn("invalid Nikon TIFF header");
    return (((void *)0));
   }
   md->btiff = b;
   b += 2;
   if (exif2byte(b, md->order) != 42) {
    exifwarn("invalid Nikon TIFF header");
    return (((void *)0));
   }
   b += 2;
   readifd(exif4byte(b, md->order), &myifd,
       nikon_tags1, md);
   return (myifd);
  default:
   exifwarn("Nikon maker note version not supported");
   return (((void *)0));
  }
 }
 readifd(offset, &myifd, nikon_tags1, 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; } *

variable_types:
b
unsigned char *

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


trans

decompiled_code:
__int64 __fastcall trans(unsigned int *a1, __int64 a2)
{
__int64 i; // rbx
__int64 v3; // rbp
unsigned int v4; // er12
_DWORD *j; // r13
size_t v6; // rax
const char *v7; // rbp
char v9[56]; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0LL; i != 16; ++i )
{
v3 = *(char *)(a2 + i);
if ( !(_BYTE)v3 )
break;
v9[i] = (*_ctype_tolower_loc())[v3];
}
v4 = *a1;
v9[15] = 0;
for ( j = a1 + 4; v4 != -1; j += 4 )
{
v7 = (const char *)*((_QWORD *)j - 1);
if ( !strncmp(v7, v9, 3uLL) )
break;
v6 = strlen(v7);
if ( !strncmp(v7, v9, v6) )
break;
v4 = *j;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, __int64 a2)
{
__int64 i; // rbx
__int64 v3; // rbp
unsigned int v4; // er12
_DWORD *j; // r13
size_t v6; // rax
const char *v7; // rbp
char v9[56]; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0LL; i != 16; ++i )
{
v3 = *(char *)(a2 + i);
if ( !(_BYTE)v3 )
break;
v9[i] = (*_ctype_tolower_loc())[v3];
}
v4 = *a1;
v9[15] = 0;
for ( j = a1 + 4; v4 != -1; j += 4 )
{
v7 = (const char *)*((_QWORD *)j - 1);
if ( !strncmp(v7, v9, 3uLL) )
break;
v6 = strlen(v7);
if ( !strncmp(v7, v9, v6) )
break;
v4 = *j;
}
return v4;
}

original_code:
static int
trans(const struct trans t[], const char *arg)
{
  int f;
  char tmp[16];
  for (f = 0; f < sizeof(tmp) && arg[f]; f++)
    tmp[f] = tolower(arg[f]);
  tmp[15] = '\0';
  for (f = 0; t[f].val != -1; f++)
    if (!strncmp(t[f].str, tmp, 3) ||
        !strncmp(t[f].str, tmp, strlen(t[f].str)))
      return t[f].val;
  return -1;
}

canonical_original_code:
static int trans(struct trans t[], char *arg)
{
  int f;
  char tmp[16];
  for (f = 0; f < sizeof(tmp) && arg[f]; f++)
    tmp[f] = tolower(arg[f]);
  tmp[15] = '\0';
  for (f = 0; t[f].val != -1; f++)
    if (!strncmp(t[f].str, tmp, 3) ||
        !strncmp(t[f].str, tmp, strlen(t[f].str)))
      return t[f].val;
  return -1;
}

variable_types:
t
struct trans { int val; char *str; } []

variable_types:
arg
char *

variable_types: f int

variable_types:
tmp
char [16]

return_type: int


adjday

decompiled_code:
__int64 __fastcall adjday(struct tm *tp, char a2, int a3, int a4)
{
int v5; // ebx
__int64 result; // rax
int v7; // eax
int v8; // edx
int v9; // eax
int v10; // eax

v5 = a3;
if ( a2 == 43 )
{
while ( v5 )
{
v7 = daysinmonth_isra_0(tp->tm_mon, tp->tm_year);
v8 = tp->tm_mday;
v9 = v7 - v8;
if ( v9 >= v5 )
{
result = 1LL;
tp->tm_mday = v5 + v8;
if ( !a4 )
return result;
return (unsigned int)domktime(tp) != -1;
}
tp->tm_mday = 1;
v5 -= v9 + 1;
if ( !(unsigned int)adjmon(tp, 43LL, 1LL, 0LL, 0LL) )
return 0LL;
}
goto LABEL_6;
}
if ( a2 != 45 )
{
if ( a3 <= 0 || (int)daysinmonth_isra_0(tp->tm_mon, tp->tm_year) < a3 )
return 0LL;
tp->tm_mday = v5;
LABEL_6:
result = 1LL;
if ( !a4 )
return result;
return (unsigned int)domktime(tp) != -1;
}
if ( !a3 )
goto LABEL_6;
v10 = tp->tm_mday;
while ( v10 <= v5 )
{
tp->tm_mday = 1;
v5 -= v10;
if ( !(unsigned int)adjmon(tp, 45LL, 1LL, 0LL, 0LL) )
return 0LL;
v10 = daysinmonth_isra_0(tp->tm_mon, tp->tm_year);
tp->tm_mday = v10;
if ( !v5 )
goto LABEL_6;
}
tp->tm_mday = v10 - v5;
result = 1LL;
if ( a4 )
return (unsigned int)domktime(tp) != -1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(struct tm *tp, char a2, int a3, int a4)
{
int v5; // ebx
__int64 result; // rax
int v7; // eax
int v8; // edx
int v9; // eax
int v10; // eax

v5 = a3;
if ( a2 == 43 )
{
while ( v5 )
{
v7 = func1(tp->tm_mon, tp->tm_year);
v8 = tp->tm_mday;
v9 = v7 - v8;
if ( v9 >= v5 )
{
result = 1LL;
tp->tm_mday = v5 + v8;
if ( !a4 )
return result;
return (unsigned int)func4(tp) != -1;
}
tp->tm_mday = 1;
v5 -= v9 + 1;
if ( !(unsigned int)func6(tp, 43LL, 1LL, 0LL, 0LL) )
return 0LL;
}
goto LABEL_6;
}
if ( a2 != 45 )
{
if ( a3 <= 0 || (int)func1(tp->tm_mon, tp->tm_year) < a3 )
return 0LL;
tp->tm_mday = v5;
LABEL_6:
result = 1LL;
if ( !a4 )
return result;
return (unsigned int)func4(tp) != -1;
}
if ( !a3 )
goto LABEL_6;
v10 = tp->tm_mday;
while ( v10 <= v5 )
{
tp->tm_mday = 1;
v5 -= v10;
if ( !(unsigned int)func6(tp, 45LL, 1LL, 0LL, 0LL) )
return 0LL;
v10 = func1(tp->tm_mon, tp->tm_year);
tp->tm_mday = v10;
if ( !v5 )
goto LABEL_6;
}
tp->tm_mday = v10 - v5;
result = 1LL;
if ( a4 )
return (unsigned int)func4(tp) != -1;
return result;
}

original_code:
static int
adjday(struct tm *t, char type, int val, int mk)
{
  int lmdays;
  switch (type) {
    case '+':
      while (val) {
        lmdays = daysinmonth(t);
        if (val > lmdays - t->tm_mday) {
          val -= lmdays - t->tm_mday + 1;
          t->tm_mday = 1;
          if (!adjmon(t, '+', 1, 0, 0))
            return 0;
        } else {
          t->tm_mday += val;
          val = 0;
        }
      }
      break;
    case '-':
      while (val)
        if (val >= t->tm_mday) {
          val -= t->tm_mday;
          t->tm_mday = 1;
          if (!adjmon(t, '-', 1, 0, 0))
            return 0;
          t->tm_mday = daysinmonth(t);
        } else {
          t->tm_mday -= val;
          val = 0;
        }
      break;
    default:
      if (val > 0 && val <= daysinmonth(t))
        t->tm_mday = val;
      else
        return 0;
      break;
  }
  return !mk || domktime(t, type) != -1;
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: type char

variable_types: val int

variable_types: mk int

variable_types: lmdays int


adjhour

decompiled_code:
_BOOL8 __fastcall adjhour(struct tm *a1, char a2, int a3, int a4)
{
_BOOL8 result; // rax
int v6; // er8
int v7; // edx
int v8; // eax
int v9; // eax
int v10; // edx
char v11; // si
int v12; // ecx

if ( a3 < 0 )
return 0LL;
if ( a2 == 43 )
{
if ( !a3 )
goto LABEL_6;
v12 = a1->tm_hour;
a1->tm_hour = (v12 + a3 % 24) % 24;
v11 = 43;
v10 = (v12 + a3) / 24;
goto LABEL_12;
}
if ( a2 != 45 )
{
if ( a3 <= 23 )
{
a1->tm_hour = a3;
goto LABEL_6;
}
return 0LL;
}
if ( a3 )
{
v6 = a3 / 24;
v7 = a3 % 24;
v8 = a1->tm_hour;
if ( v8 < v7 )
{
++v6;
v7 -= 24;
}
v9 = v8 - v7;
v10 = v6;
v11 = 45;
a1->tm_hour = v9;
LABEL_12:
if ( !(unsigned int)adjday(a1, v11, v10, 0) )
return 0LL;
}
LABEL_6:
result = 1LL;
if ( a4 )
result = (unsigned int)domktime(a1) != -1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(struct tm *a1, char a2, int a3, int a4)
{
_BOOL8 result; // rax
int v6; // er8
int v7; // edx
int v8; // eax
int v9; // eax
int v10; // edx
char v11; // si
int v12; // ecx

if ( a3 < 0 )
return 0LL;
if ( a2 == 43 )
{
if ( !a3 )
goto LABEL_6;
v12 = a1->tm_hour;
a1->tm_hour = (v12 + a3 % 24) % 24;
v11 = 43;
v10 = (v12 + a3) / 24;
goto LABEL_12;
}
if ( a2 != 45 )
{
if ( a3 <= 23 )
{
a1->tm_hour = a3;
goto LABEL_6;
}
return 0LL;
}
if ( a3 )
{
v6 = a3 / 24;
v7 = a3 % 24;
v8 = a1->tm_hour;
if ( v8 < v7 )
{
++v6;
v7 -= 24;
}
v9 = v8 - v7;
v10 = v6;
v11 = 45;
a1->tm_hour = v9;
LABEL_12:
if ( !(unsigned int)func2(a1, v11, v10, 0) )
return 0LL;
}
LABEL_6:
result = 1LL;
if ( a4 )
result = (unsigned int)func4(a1) != -1;
return result;
}

original_code:
static int
adjhour(struct tm *t, char type, int val, int mk)
{
  if (val < 0)
    return 0;
  switch (type) {
    case '+':
      if (val) {
        int days;
        days = (t->tm_hour + val) / 24;
        val %= 24;
        t->tm_hour += val;
        t->tm_hour %= 24;
        if (!adjday(t, '+', days, 0))
          return 0;
      }
      break;
    case '-':
      if (val) {
        int days;
        days = val / 24;
        val %= 24;
        if (val > t->tm_hour) {
          days++;
          val -= 24;
        }
        t->tm_hour -= val;
        if (!adjday(t, '-', days, 0))
          return 0;
      }
      break;
    default:
      if (val > 23)
        return 0;
      t->tm_hour = val;
  }
  return !mk || domktime(t, type) != -1;
}

variable_types: days int

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


domktime

decompiled_code:
time_t __fastcall domktime(struct tm *tp, char a2)
{
time_t result; // rax

while ( 1 )
{
result = mktime(tp);
if ( result != -1 )
break;
if ( (unsigned int)(tp->tm_year - 69) > 0x44 )
return 0xFFFFFFFFLL;
adjhour(tp, 2 * (a2 == 45) + 43, 1, 0);
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func4(struct tm *tp, char a2)
{
time_t result; // rax

while ( 1 )
{
result = mktime(tp);
if ( result != -1 )
break;
if ( (unsigned int)(tp->tm_year - 69) > 0x44 )
return 0xFFFFFFFFLL;
func3(tp, 2 * (a2 == 45) + 43, 1, 0);
}
return result;
}

original_code:
static int
domktime(struct tm *t, char type)
{
  time_t ret;
  while ((ret = mktime(t)) == -1 && t->tm_year > 68 && t->tm_year < 138)
    adjhour(t, (char)(type == '-' ? type : '+'), 1, 0);
  return ret;
}

canonical_original_code:
static int domktime(struct tm *t, char type)
{
  long ret;
  while ((ret = mktime(t)) == -1 && t->tm_year > 68 && t->tm_year < 138)
    adjhour(t, (char)(type == '-' ? type : '+'), 1, 0);
  return ret;
}

variable_types: ret long


adjyear

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

if ( a2 == 43 )
{
a1->tm_year += a3;
goto LABEL_7;
}
if ( a2 == 45 )
{
a1->tm_year -= a3;
goto LABEL_7;
}
if ( a3 > 68 )
{
if ( a3 >= 1901 )
a3 -= 1900;
a1->tm_year = a3;
LABEL_7:
result = 1LL;
if ( a4 )
return (unsigned int)domktime(a1, a2) != -1;
return result;
}
result = 1LL;
a1->tm_year = a3 + 100;
if ( a4 )
return (unsigned int)domktime(a1, a2) != -1;
return result;
}

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

if ( a2 == 43 )
{
a1->tm_year += a3;
goto LABEL_7;
}
if ( a2 == 45 )
{
a1->tm_year -= a3;
goto LABEL_7;
}
if ( a3 > 68 )
{
if ( a3 >= 1901 )
a3 -= 1900;
a1->tm_year = a3;
LABEL_7:
result = 1LL;
if ( a4 )
return (unsigned int)func4(a1, a2) != -1;
return result;
}
result = 1LL;
a1->tm_year = a3 + 100;
if ( a4 )
return (unsigned int)func4(a1, a2) != -1;
return result;
}

original_code:
static int
adjyear(struct tm *t, char type, int val, int mk)
{
  switch (type) {
    case '+':
      t->tm_year += val;
      break;
    case '-':
      t->tm_year -= val;
      break;
    default:
      t->tm_year = val;
      if (t->tm_year < 69)
       t->tm_year += 100;
      else if (t->tm_year > 1900)
        t->tm_year -= 1900;
      break;
  }
  return !mk || domktime(t, type) != -1;
}


adjmon

decompiled_code:
_BOOL8 __fastcall adjmon(struct tm *a1, char a2, int a3, int a4, int a5)
{
int v6; // ebx
_BOOL8 result; // rax
int v8; // eax
int v9; // ebx
int v10; // eax
int v11; // eax
int v12; // ebx

if ( a3 < 0 )
return 0LL;
v6 = a3;
if ( a2 == 43 )
{
if ( a4 )
{
v11 = a1->tm_mon;
if ( v11 < a3 )
v6 = a3 - (v11 + 1);
else
v6 = a3 - v11 + 11;
}
if ( !v6 )
goto LABEL_6;
if ( (unsigned int)adjyear(a1, 43, (v6 + a1->tm_mon) / 12, 0) )
{
v12 = a1->tm_mon + v6 % 12;
if ( v12 >= 12 )
v12 -= 12;
a1->tm_mon = v12;
goto LABEL_6;
}
return 0LL;
}
if ( a2 != 45 )
{
if ( (unsigned int)(a3 - 1) <= 0xB )
{
a1->tm_mon = a3 - 1;
goto LABEL_6;
}
return 0LL;
}
if ( a4 )
{
v8 = a1->tm_mon;
if ( a3 - 1 <= v8 )
v6 = v8 - a3 + 1;
else
v6 = v8 - a3 + 13;
}
if ( !v6 )
goto LABEL_6;
if ( !(unsigned int)adjyear(a1, 45, v6 / 12, 0) )
return 0LL;
v9 = v6 % 12;
v10 = a1->tm_mon;
if ( v10 < v9 )
{
if ( !(unsigned int)adjyear(a1, 45, 1, 0) )
return 0LL;
v9 -= 12;
v10 = a1->tm_mon;
}
a1->tm_mon = v10 - v9;
LABEL_6:
result = 1LL;
if ( a5 )
result = (unsigned int)domktime(a1, a2) != -1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(struct tm *a1, char a2, int a3, int a4, int a5)
{
int v6; // ebx
_BOOL8 result; // rax
int v8; // eax
int v9; // ebx
int v10; // eax
int v11; // eax
int v12; // ebx

if ( a3 < 0 )
return 0LL;
v6 = a3;
if ( a2 == 43 )
{
if ( a4 )
{
v11 = a1->tm_mon;
if ( v11 < a3 )
v6 = a3 - (v11 + 1);
else
v6 = a3 - v11 + 11;
}
if ( !v6 )
goto LABEL_6;
if ( (unsigned int)func5(a1, 43, (v6 + a1->tm_mon) / 12, 0) )
{
v12 = a1->tm_mon + v6 % 12;
if ( v12 >= 12 )
v12 -= 12;
a1->tm_mon = v12;
goto LABEL_6;
}
return 0LL;
}
if ( a2 != 45 )
{
if ( (unsigned int)(a3 - 1) <= 0xB )
{
a1->tm_mon = a3 - 1;
goto LABEL_6;
}
return 0LL;
}
if ( a4 )
{
v8 = a1->tm_mon;
if ( a3 - 1 <= v8 )
v6 = v8 - a3 + 1;
else
v6 = v8 - a3 + 13;
}
if ( !v6 )
goto LABEL_6;
if ( !(unsigned int)func5(a1, 45, v6 / 12, 0) )
return 0LL;
v9 = v6 % 12;
v10 = a1->tm_mon;
if ( v10 < v9 )
{
if ( !(unsigned int)func5(a1, 45, 1, 0) )
return 0LL;
v9 -= 12;
v10 = a1->tm_mon;
}
a1->tm_mon = v10 - v9;
LABEL_6:
result = 1LL;
if ( a5 )
result = (unsigned int)func4(a1, a2) != -1;
return result;
}

original_code:
static int
adjmon(struct tm *t, char type, int val, int istext, int mk)
{
  if (val < 0)
    return 0;
  switch (type) {
    case '+':
      if (istext) {
        if (val <= t->tm_mon)
          val += 11 - t->tm_mon;
        else
          val -= t->tm_mon + 1;
      }
      if (val) {
        if (!adjyear(t, '+', (t->tm_mon + val) / 12, 0))
          return 0;
        val %= 12;
        t->tm_mon += val;
        if (t->tm_mon > 11)
          t->tm_mon -= 12;
      }
      break;
    case '-':
      if (istext) {
        if (val-1 > t->tm_mon)
          val = 13 - val + t->tm_mon;
        else
          val = t->tm_mon - val + 1;
      }
      if (val) {
        if (!adjyear(t, '-', val / 12, 0))
          return 0;
        val %= 12;
        if (val > t->tm_mon) {
          if (!adjyear(t, '-', 1, 0))
            return 0;
          val -= 12;
        }
        t->tm_mon -= val;
      }
      break;
    default:
      if (val > 12 || val < 1)
        return 0;
      t->tm_mon = --val;
  }
  return !mk || domktime(t, type) != -1;
}

variable_types: istext int


adjmin

decompiled_code:
_BOOL8 __fastcall adjmin(struct tm *a1, char a2, int a3, int a4)
{
_BOOL8 result; // rax
int v7; // er13
int v8; // eax
int v9; // ebx
int v10; // ebx

if ( a3 < 0 )
return 0LL;
if ( a2 == 43 )
{
if ( a3 )
{
if ( adjhour(a1, 43, (a3 + a1->tm_min) / 60, 0) )
{
v10 = a1->tm_min + a3 % 60;
if ( v10 >= 60 )
v10 -= 60;
a1->tm_min = v10;
goto LABEL_6;
}
return 0LL;
}
}
else
{
if ( a2 != 45 )
{
if ( a3 <= 59 )
{
a1->tm_min = a3;
goto LABEL_6;
}
return 0LL;
}
if ( a3 )
{
v7 = a3 / 60;
if ( !adjhour(a1, 45, a3 / 60, 0) )
return 0LL;
v8 = a1->tm_min;
v9 = a3 - 60 * v7;
if ( v8 < v9 )
{
if ( !adjhour(a1, 45, 1, 0) )
return 0LL;
v9 -= 60;
v8 = a1->tm_min;
}
a1->tm_min = v8 - v9;
}
}
LABEL_6:
result = 1LL;
if ( a4 )
result = (unsigned int)domktime(a1, a2) != -1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(struct tm *a1, char a2, int a3, int a4)
{
_BOOL8 result; // rax
int v7; // er13
int v8; // eax
int v9; // ebx
int v10; // ebx

if ( a3 < 0 )
return 0LL;
if ( a2 == 43 )
{
if ( a3 )
{
if ( func3(a1, 43, (a3 + a1->tm_min) / 60, 0) )
{
v10 = a1->tm_min + a3 % 60;
if ( v10 >= 60 )
v10 -= 60;
a1->tm_min = v10;
goto LABEL_6;
}
return 0LL;
}
}
else
{
if ( a2 != 45 )
{
if ( a3 <= 59 )
{
a1->tm_min = a3;
goto LABEL_6;
}
return 0LL;
}
if ( a3 )
{
v7 = a3 / 60;
if ( !func3(a1, 45, a3 / 60, 0) )
return 0LL;
v8 = a1->tm_min;
v9 = a3 - 60 * v7;
if ( v8 < v9 )
{
if ( !func3(a1, 45, 1, 0) )
return 0LL;
v9 -= 60;
v8 = a1->tm_min;
}
a1->tm_min = v8 - v9;
}
}
LABEL_6:
result = 1LL;
if ( a4 )
result = (unsigned int)func4(a1, a2) != -1;
return result;
}

original_code:
static int
adjmin(struct tm *t, char type, int val, int mk)
{
  if (val < 0)
    return 0;
  switch (type) {
    case '+':
      if (val) {
        if (!adjhour(t, '+', (t->tm_min + val) / 60, 0))
          return 0;
        val %= 60;
        t->tm_min += val;
        if (t->tm_min > 59)
          t->tm_min -= 60;
      }
      break;
    case '-':
      if (val) {
        if (!adjhour(t, '-', val / 60, 0))
          return 0;
        val %= 60;
        if (val > t->tm_min) {
          if (!adjhour(t, '-', 1, 0))
            return 0;
          val -= 60;
        }
        t->tm_min -= val;
      }
      break;
    default:
      if (val > 59)
        return 0;
      t->tm_min = val;
  }
  return !mk || domktime(t, type) != -1;
}


original_code:
struct vary *
vary_append(struct vary *v, char *arg)
{
  struct vary *result, **nextp;
  if (v) {
    result = v;
    while (v->next)
      v = v->next;
    nextp = &v->next;
  } else
    nextp = &result;
  if ((*nextp = (struct vary *)malloc(sizeof(struct vary))) == ((void *)0))
    exifdie((const char *)strerror((*__errno_location ())));
  (*nextp)->arg = arg;
  (*nextp)->next = ((void *)0);
  return result;
}

canonical_original_code:
struct vary *vary_append(struct vary *v, char *arg)
{
  struct vary *result; struct vary **nextp;
  if (v) {
    result = v;
    while (v->next)
      v = v->next;
    nextp = &v->next;
  } else
    nextp = &result;
  if ((*nextp = (struct vary *)malloc(sizeof(struct vary))) == ((void *)0))
    exifdie((char *)strerror((*__errno_location ())));
  (*nextp)->arg = arg;
  (*nextp)->next = ((void *)0);
  return result;
}

variable_types:
v
struct vary *

variable_types: struct vary { char *arg; struct vary *next; } **


decompiled_code:
__int64 __fastcall vary_apply(__int64 a1, struct tm *a2)
{
__int64 v2; // r12
const char *v3; // r14
size_t v4; // rax
size_t v5; // rbx
size_t v6; // r15
int v7; // edx
char v8; // bp
int v9; // edx
int v10; // edx

v2 = a1;
for ( a2->tm_isdst = -1; v2; v2 = *(_QWORD *)(v2 + 8) )
{
v3 = *(const char **)v2;
v8 = **(_BYTE **)v2;
if ( ((v8 - 43) & 0xFD) != 0 )
v8 = 0;
else
++v3;
v4 = strlen(v3);
if ( v4 <= 1 )
break;
v5 = v4 - 1;
v6 = strspn(v3, digits);
if ( v6 == v5 )
{
v9 = atoi(v3);
switch ( v3[v6] )
{
case 'H':
if ( adjhour(a2, v8, v9, 1) )
continue;
break;
case 'M':
if ( adjmin(a2, v8, v9, 1) )
continue;
break;
case 'S':
if ( adjsec_constprop_0(a2, v8, v9) )
continue;
break;
case 'd':
if ( (unsigned int)adjday(a2, v8, v9, 1) )
continue;
break;
case 'm':
if ( adjmon(a2, v8, v9, 0, 1) )
continue;
break;
case 'w':
if ( (unsigned int)adjwday_constprop_0(a2, v8, v9, 0) )
continue;
break;
case 'y':
if ( (unsigned int)adjyear(a2, v8, v9, 1) )
continue;
break;
default:
return v2;
}
return v2;
}
v7 = trans((unsigned int *)&trans_wday, (__int64)v3);
if ( v7 == -1 )
{
v10 = trans((unsigned int *)&trans_mon, (__int64)v3);
if ( v10 == -1 || !adjmon(a2, v8, v10, 1, 1) )
return v2;
}
else if ( !(unsigned int)adjwday_constprop_0(a2, v8, v7, 1) )
{
return v2;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, struct tm *a2)
{
__int64 v2; // r12
const char *v3; // r14
size_t v4; // rax
size_t v5; // rbx
size_t v6; // r15
int v7; // edx
char v8; // bp
int v9; // edx
int v10; // edx

v2 = a1;
for ( a2->tm_isdst = -1; v2; v2 = *(_QWORD *)(v2 + 8) )
{
v3 = *(const char **)v2;
v8 = **(_BYTE **)v2;
if ( ((v8 - 43) & 0xFD) != 0 )
v8 = 0;
else
++v3;
v4 = strlen(v3);
if ( v4 <= 1 )
break;
v5 = v4 - 1;
v6 = strspn(v3, digits);
if ( v6 == v5 )
{
v9 = atoi(v3);
switch ( v3[v6] )
{
case 'H':
if ( func3(a2, v8, v9, 1) )
continue;
break;
case 'M':
if ( func7(a2, v8, v9, 1) )
continue;
break;
case 'S':
if ( func8(a2, v8, v9) )
continue;
break;
case 'd':
if ( (unsigned int)func2(a2, v8, v9, 1) )
continue;
break;
case 'm':
if ( func6(a2, v8, v9, 0, 1) )
continue;
break;
case 'w':
if ( (unsigned int)func9(a2, v8, v9, 0) )
continue;
break;
case 'y':
if ( (unsigned int)func5(a2, v8, v9, 1) )
continue;
break;
default:
return v2;
}
return v2;
}
v7 = func0((unsigned int *)&trans_wday, (__int64)v3);
if ( v7 == -1 )
{
v10 = func0((unsigned int *)&trans_mon, (__int64)v3);
if ( v10 == -1 || !func6(a2, v8, v10, 1, 1) )
return v2;
}
else if ( !(unsigned int)func9(a2, v8, v7, 1) )
{
return v2;
}
}
return v2;
}

original_code:
const struct vary *
vary_apply(const struct vary *v, struct tm *t)
{
  char type;
  char which;
  char *arg;
  size_t len;
  int val;
  t->tm_isdst = -1;
  for (; v; v = v->next) {
    type = *v->arg;
    arg = v->arg;
    if (type == '+' || type == '-')
      arg++;
    else
      type = '\0';
    len = strlen(arg);
    if (len < 2)
      return v;
    if (strspn(arg, digits) != len-1) {
      val = trans(trans_wday, arg);
      if (val != -1) {
          if (!adjwday(t, type, val, 1, 1))
            return v;
      } else {
        val = trans(trans_mon, arg);
        if (val != -1) {
          if (!adjmon(t, type, val, 1, 1))
            return v;
        } else
          return v;
      }
    } else {
      val = atoi(arg);
      which = arg[len-1];
      switch (which) {
        case 'S':
          if (!adjsec(t, type, val, 1))
            return v;
          break;
        case 'M':
          if (!adjmin(t, type, val, 1))
            return v;
          break;
        case 'H':
          if (!adjhour(t, type, val, 1))
            return v;
          break;
        case 'd':
          if (!adjday(t, type, val, 1))
            return v;
          break;
        case 'w':
          if (!adjwday(t, type, val, 0, 1))
            return v;
          break;
        case 'm':
          if (!adjmon(t, type, val, 0, 1))
            return v;
          break;
        case 'y':
          if (!adjyear(t, type, val, 1))
            return v;
          break;
        default:
          return v;
      }
    }
  }
  return 0;
}

canonical_original_code:
struct vary *vary_apply(struct vary *v, struct tm *t)
{
  char type;
  char which;
  char *arg;
  unsigned long len;
  int val;
  t->tm_isdst = -1;
  for (; v; v = v->next) {
    type = *v->arg;
    arg = v->arg;
    if (type == '+' || type == '-')
      arg++;
    else
      type = '\0';
    len = strlen(arg);
    if (len < 2)
      return v;
    if (strspn(arg, digits) != len-1) {
      val = trans(trans_wday, arg);
      if (val != -1) {
          if (!adjwday(t, type, val, 1, 1))
            return v;
      } else {
        val = trans(trans_mon, arg);
        if (val != -1) {
          if (!adjmon(t, type, val, 1, 1))
            return v;
        } else
          return v;
      }
    } else {
      val = atoi(arg);
      which = arg[len-1];
      switch (which) {
        case 'S':
          if (!adjsec(t, type, val, 1))
            return v;
          break;
        case 'M':
          if (!adjmin(t, type, val, 1))
            return v;
          break;
        case 'H':
          if (!adjhour(t, type, val, 1))
            return v;
          break;
        case 'd':
          if (!adjday(t, type, val, 1))
            return v;
          break;
        case 'w':
          if (!adjwday(t, type, val, 0, 1))
            return v;
          break;
        case 'm':
          if (!adjmon(t, type, val, 0, 1))
            return v;
          break;
        case 'y':
          if (!adjyear(t, type, val, 1))
            return v;
          break;
        default:
          return v;
      }
    }
  }
  return 0;
}

variable_types: which char

variable_types:
len
unsigned long

return_type: struct vary { char *arg; struct vary *next; } *


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

result = *(unsigned __int16 *)a1;
if ( (_WORD)result == 36 )
{
exifstralloc(a1 + 4, 10LL);
result = snprintf(a1[4], 9uLL, "%.2f EV", (double)*((__int16 *)a1 + 4) / 3.0);
}
else if ( (unsigned __int16)result > 0x24u )
{
if ( (_WORD)result == 44 )
{
result = -23544;
*((_WORD *)a1 + 24) = -23544;
}
}
else if ( (_WORD)result == 3 )
{
*((_WORD *)a1 + 24) = -23549;
}
else if ( (_WORD)result == 35 )
{
exifstralloc(a1 + 4, 10LL);
result = snprintf(a1[4], 9uLL, "%d", (unsigned int)*((__int16 *)a1 + 4));
}
return result;
}

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

result = *(unsigned __int16 *)a1;
if ( (_WORD)result == 36 )
{
exifstralloc(a1 + 4, 10LL);
result = snprintf(a1[4], 9uLL, "%.2f EV", (double)*((__int16 *)a1 + 4) / 3.0);
}
else if ( (unsigned __int16)result > 0x24u )
{
if ( (_WORD)result == 44 )
{
result = -23544;
*((_WORD *)a1 + 24) = -23544;
}
}
else if ( (_WORD)result == 3 )
{
*((_WORD *)a1 + 24) = -23549;
}
else if ( (_WORD)result == 35 )
{
exifstralloc(a1 + 4, 10LL);
result = snprintf(a1[4], 9uLL, "%d", (unsigned int)*((__int16 *)a1 + 4));
}
return result;
}

original_code:
void
panasonic_prop(struct exifprop *prop, struct exiftags *t)
{
 switch (prop->tag) {
 case 0x0003:
  prop->override = 0xa403;
  break;
 case 0x0023:
  exifstralloc(&prop->str, 10);
  snprintf(prop->str, 9, "%d", (int16_t)prop->value);
  break;
 case 0x0024:
  exifstralloc(&prop->str, 10);
  snprintf(prop->str, 9, "%.2f EV", (int16_t)prop->value / 3.0);
  break;
 case 0x002c:
  prop->override = 0xa408;
  break;
 }
}

canonical_original_code:
void panasonic_prop(struct exifprop *prop, struct exiftags *t)
{
 switch (prop->tag) {
 case 0x0003:
  prop->override = 0xa403;
  break;
 case 0x0023:
  exifstralloc(&prop->str, 10);
  snprintf(prop->str, 9, "%d", (short)prop->value);
  break;
 case 0x0024:
  exifstralloc(&prop->str, 10);
  snprintf(prop->str, 9, "%.2f EV", (short)prop->value / 3.0);
  break;
 case 0x002c:
  prop->override = 0xa408;
  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; } *


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

v2 = *(_QWORD *)(a2 + 8) + a1;
if ( *(_QWORD *)v2 == 0x696E6F73616E6150LL && *(_DWORD *)(v2 + 8) == 99 )
return readifds(a1 + 12, &panasonic_tags0, a2);
exifwarn("Maker note format not supported");
return 0LL;
}

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

v2 = *(_QWORD *)(a2 + 8) + a1;
if ( *(_QWORD *)v2 == 0x696E6F73616E6150LL && *(_DWORD *)(v2 + 8) == 99 )
return readifds(a1 + 12, &panasonic_tags0, a2);
exifwarn("Maker note format not supported");
return 0LL;
}

original_code:
struct ifd *
panasonic_ifd(u_int32_t offset, struct tiffmeta *md)
{
 if (memcmp("Panasonic\0\0\0", md->btiff + offset, 12)) {
  exifwarn("Maker note format not supported");
  return (((void *)0));
 }
 return (readifds(offset + 12, panasonic_tags0, md));
}

canonical_original_code:
struct ifd *panasonic_ifd(unsigned int offset, struct tiffmeta *md)
{
 if (memcmp("Panasonic\0\0\0", md->btiff + offset, 12)) {
  exifwarn("Maker note format not supported");
  return (((void *)0));
 }
 return (readifds(offset + 12, panasonic_tags0, md));
}

variable_types:
offset
unsigned int

variable_types:
md
struct tiffmeta *

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


printcom

decompiled_code:
__int64 __fastcall printcom(const char *a1, __int64 a2, __int64 a3)
{
_QWORD *v5; // rsi
const char *v6; // rsi
unsigned int v7; // er12
__int64 v9; // rdx
unsigned int v10; // er12
const char *v11; // rdx
size_t v12; // rax

if ( !a2 )
{
v7 = 1;
fprintf(stderr, "%s: comment not available\n", a1);
return v7;
}
if ( !vflag )
{
v5 = (_QWORD *)(a3 + *(unsigned int *)(a2 + 8));
if ( *(_BYTE *)v5 )
{
if ( *v5 == 0x4949435341LL )
{
LABEL_5:
v6 = *(const char **)(a2 + 32);
if ( v6 )
{
v7 = 0;
if ( *v6 )
goto LABEL_8;
}
goto LABEL_7;
}
goto LABEL_16;
}
LABEL_7:
v7 = 2;
v6 = (const char *)&unk_C67;
LABEL_8:
printf("%s", v6);
return v7;
}
printf("Supported Length%s%d\n", delim, (unsigned int)(*(_DWORD *)(a2 + 4) - 8));
v9 = *(unsigned int *)(a2 + 8);
if ( !*(_BYTE *)(a3 + v9) )
{
if ( !vflag )
goto LABEL_7;
goto LABEL_12;
}
if ( *(_QWORD *)(a3 + v9) == 0x4949435341LL )
{
if ( !vflag )
goto LABEL_5;
printf("Type%s%s\n", delim, (const char *)(a3 + v9));
v6 = *(const char **)(a2 + 32);
v7 = vflag;
if ( v6 && *v6 )
{
if ( !vflag )
goto LABEL_8;
v10 = 0;
v12 = strlen(*(const char **)(a2 + 32));
printf("Length%s%d\n", delim, v12);
v11 = *(const char **)(a2 + 32);
goto LABEL_13;
}
if ( !vflag )
goto LABEL_7;
LABEL_12:
v10 = 2;
printf("Length%s%d\n", delim, 0LL);
v11 = (const char *)&unk_C67;
LABEL_13:
printf("Comment%s%s\n", delim, v11);
return v10;
}
if ( !vflag )
{
LABEL_16:
exifwarn2("comment type not supported");
if ( !vflag )
{
LABEL_17:
v7 = 3;
v6 = (const char *)&unk_C67;
goto LABEL_8;
}
v9 = *(unsigned int *)(a2 + 8);
}
printf("Type%s%s\n", delim, (const char *)(a3 + v9));
if ( !vflag )
goto LABEL_17;
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int64 a2, __int64 a3)
{
_QWORD *v5; // rsi
const char *v6; // rsi
unsigned int v7; // er12
__int64 v9; // rdx
unsigned int v10; // er12
const char *v11; // rdx
size_t v12; // rax

if ( !a2 )
{
v7 = 1;
fprintf(stderr, "%s: comment not available\n", a1);
return v7;
}
if ( !vflag )
{
v5 = (_QWORD *)(a3 + *(unsigned int *)(a2 + 8));
if ( *(_BYTE *)v5 )
{
if ( *v5 == 0x4949435341LL )
{
LABEL_5:
v6 = *(const char **)(a2 + 32);
if ( v6 )
{
v7 = 0;
if ( *v6 )
goto LABEL_8;
}
goto LABEL_7;
}
goto LABEL_16;
}
LABEL_7:
v7 = 2;
v6 = (const char *)&unk_C67;
LABEL_8:
printf("%s", v6);
return v7;
}
printf("Supported Length%s%d\n", delim, (unsigned int)(*(_DWORD *)(a2 + 4) - 8));
v9 = *(unsigned int *)(a2 + 8);
if ( !*(_BYTE *)(a3 + v9) )
{
if ( !vflag )
goto LABEL_7;
goto LABEL_12;
}
if ( *(_QWORD *)(a3 + v9) == 0x4949435341LL )
{
if ( !vflag )
goto LABEL_5;
printf("Type%s%s\n", delim, (const char *)(a3 + v9));
v6 = *(const char **)(a2 + 32);
v7 = vflag;
if ( v6 && *v6 )
{
if ( !vflag )
goto LABEL_8;
v10 = 0;
v12 = strlen(*(const char **)(a2 + 32));
printf("Length%s%d\n", delim, v12);
v11 = *(const char **)(a2 + 32);
goto LABEL_13;
}
if ( !vflag )
goto LABEL_7;
LABEL_12:
v10 = 2;
printf("Length%s%d\n", delim, 0LL);
v11 = (const char *)&unk_C67;
LABEL_13:
printf("Comment%s%s\n", delim, v11);
return v10;
}
if ( !vflag )
{
LABEL_16:
exifwarn2("comment type not supported");
if ( !vflag )
{
LABEL_17:
v7 = 3;
v6 = (const char *)&unk_C67;
goto LABEL_8;
}
v9 = *(unsigned int *)(a2 + 8);
}
printf("Type%s%s\n", delim, (const char *)(a3 + v9));
if ( !vflag )
goto LABEL_17;
return 3LL;
}

original_code:
static int
printcom(const char *fname, struct exifprop *p, const unsigned char *btiff)
{
 int rc = 0;
 if (!p) {
  fprintf(stderr, "%s: comment not available\n", fname);
  return (1);
 }
 if (vflag)
  printf("Supported Length%s%d\n", delim, p->count - 8);
 if (!*(btiff + p->value))
  rc = 2;
 else {
  if (memcmp("ASCII\0\0\0", btiff + p->value, 8)) {
   if (!vflag)
    exifwarn2("comment type not supported",
        (const char *)(btiff + p->value));
   rc = 3;
  }
  if (vflag)
   printf("Type%s%s\n", delim, btiff + p->value);
 }
 if (!rc && (!p->str || !*(p->str)))
  rc = 2;
 if (!vflag) {
  printf("%s", rc ? "" : p->str);
  return (rc);
 }
 if (rc != 1 && rc != 3) {
  printf("Length%s%d\n", delim, rc ? 0 : (int)strlen(p->str));
  printf("Comment%s%s\n", delim, rc ? "" : p->str);
 }
 return (rc);
}

canonical_original_code:
static int printcom(char *fname, struct exifprop *p, unsigned char *btiff)
{
 int rc = 0;
 if (!p) {
  fprintf(stderr, "%s: comment not available\n", fname);
  return (1);
 }
 if (vflag)
  printf("Supported Length%s%d\n", delim, p->count - 8);
 if (!*(btiff + p->value))
  rc = 2;
 else {
  if (memcmp("ASCII\0\0\0", btiff + p->value, 8)) {
   if (!vflag)
    exifwarn2("comment type not supported",
        (char *)(btiff + p->value));
   rc = 3;
  }
  if (vflag)
   printf("Type%s%s\n", delim, btiff + p->value);
 }
 if (!rc && (!p->str || !*(p->str)))
  rc = 2;
 if (!vflag) {
  printf("%s", rc ? "" : p->str);
  return (rc);
 }
 if (rc != 1 && rc != 3) {
  printf("Length%s%d\n", delim, rc ? 0 : (int)strlen(p->str));
  printf("Comment%s%s\n", delim, rc ? "" : p->str);
 }
 return (rc);
}

variable_types:
fname
char *

variable_types:
btiff
unsigned char *

variable_types: rc int


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "Usage: %s [options] [-w string] file ...\n", progname);
fwrite("Displays or sets Exif comment in the specified files.\n", 1uLL, 0x36uLL, stderr);
fprintf(stderr, "Version: %s\n\n", "1.01");
fwrite("Available options:\n", 1uLL, 0x13uLL, stderr);
fwrite(" -b\tOverwrite the comment tag with zeros.\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -f\tAnswer 'yes' to any confirmation prompts.\n", 1uLL, 0x2FuLL, stderr);
fwrite(" -i\tConfirm overwrites (default).\n", 1uLL, 0x23uLL, stderr);
fwrite(" -n\tAnswer 'no' to any confirmation prompts.\n", 1uLL, 0x2EuLL, stderr);
fwrite(" -v\tBe verbose about comment information.\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -w\tSet comment to provided string.\n", 1uLL, 0x25uLL, 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] [-w string] file ...\n", progname);
fwrite("Displays or sets Exif comment in the specified files.\n", 1uLL, 0x36uLL, stderr);
fprintf(stderr, "Version: %s\n\n", "1.01");
fwrite("Available options:\n", 1uLL, 0x13uLL, stderr);
fwrite(" -b\tOverwrite the comment tag with zeros.\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -f\tAnswer 'yes' to any confirmation prompts.\n", 1uLL, 0x2FuLL, stderr);
fwrite(" -i\tConfirm overwrites (default).\n", 1uLL, 0x23uLL, stderr);
fwrite(" -n\tAnswer 'no' to any confirmation prompts.\n", 1uLL, 0x2EuLL, stderr);
fwrite(" -v\tBe verbose about comment information.\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -w\tSet comment to provided string.\n", 1uLL, 0x25uLL, 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] [-w string] file ...\n", progname);
 fprintf(stderr, "Displays or sets Exif comment in the specified "
     "files.\n");
 fprintf(stderr, "Version: %s\n\n", version);
 fprintf(stderr, "Available options:\n");
 fprintf(stderr, "  -b\tOverwrite the comment tag with zeros.\n");
 fprintf(stderr, "  -f\tAnswer 'yes' to any confirmation prompts.\n");
 fprintf(stderr, "  -i\tConfirm overwrites (default).\n");
 fprintf(stderr, "  -n\tAnswer 'no' to any confirmation prompts.\n");
 fprintf(stderr, "  -v\tBe verbose about comment information.\n");
 fprintf(stderr, "  -w\tSet comment to provided string.\n");
 fprintf(stderr, "  -s\tSet delimiter to provided string "
     "(default: \": \").\n");
 exit(1);
}


exifdie

decompiled_code:
void __fastcall __noreturn exifdie(const char *a1)
{
fprintf(stderr, "%s: %s\n", (const char *)progname, a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "%s: %s\n", (const char *)progname, a1);
exit(1);
}

original_code:
void
exifdie(const char *msg)
{
 fprintf(stderr, "%s: %s\n", progname, msg);
 exit(1);
}

canonical_original_code:
void exifdie(char *msg)
{
 fprintf(stderr, "%s: %s\n", progname, msg);
 exit(1);
}

variable_types:
msg
char *


exifwarn

decompiled_code:
int __fastcall exifwarn(const char *a1)
{
return fprintf(stderr, "%s: %s\n", (const char *)progname, a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "%s: %s\n", (const char *)progname, a1);
}

original_code:
void
exifwarn(const char *msg)
{
 fprintf(stderr, "%s: %s\n", progname, msg);
}

canonical_original_code:
void exifwarn(char *msg)
{
 fprintf(stderr, "%s: %s\n", progname, msg);
}


decompiled_code:
int __fastcall exifwarn2(const char *a1, const char *a2)
{
return fprintf(stderr, "%s: %s (%s)\n", (const char *)progname, a1, a2);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, const char *a2)
{
return fprintf(stderr, "%s: %s (%s)\n", (const char *)progname, a1, a2);
}

original_code:
void
exifwarn2(const char *msg1, const char *msg2)
{
 fprintf(stderr, "%s: %s (%s)\n", progname, msg1, msg2);
}

canonical_original_code:
void exifwarn2(char *msg1, char *msg2)
{
 fprintf(stderr, "%s: %s (%s)\n", progname, msg1, msg2);
}


offsanity

decompiled_code:
__int64 __fastcall offsanity(__int64 a1, unsigned __int16 a2, __int64 a3)
{
const char *v3; // r8
__int64 v4; // rax
unsigned int v5; // edx
unsigned int v6; // ecx
__int64 result; // rax
unsigned int v8; // eax
unsigned int v9; // esi

v3 = *(const char **)(a1 + 16);
v4 = *(_QWORD *)(a3 + 48) - *(_QWORD *)(a3 + 40);
v5 = *(_DWORD *)(a1 + 4);
v6 = v4;
if ( !v3 )
v3 = "Unknown";
if ( !v5 )
{
result = 0LL;
if ( *(_DWORD *)(a1 + 8) <= v6 )
return result;
LABEL_9:
exifwarn2("invalid field offset", v3);
*(_WORD *)(a1 + 40) = 64;
return 1LL;
}
v8 = v5 * a2;
if ( !is_mul_ok(v5, a2) )
{
exifwarn2("invalid field count", v3);
*(_WORD *)(a1 + 40) = 64;
return 1LL;
}
if ( ~*(_DWORD *)(a1 + 8) < v8 )
goto LABEL_9;
v9 = v8 + *(_DWORD *)(a1 + 8);
result = 0LL;
if ( v9 > v6 )
goto LABEL_9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int16 a2, __int64 a3)
{
const char *v3; // r8
__int64 v4; // rax
unsigned int v5; // edx
unsigned int v6; // ecx
__int64 result; // rax
unsigned int v8; // eax
unsigned int v9; // esi

v3 = *(const char **)(a1 + 16);
v4 = *(_QWORD *)(a3 + 48) - *(_QWORD *)(a3 + 40);
v5 = *(_DWORD *)(a1 + 4);
v6 = v4;
if ( !v3 )
v3 = "Unknown";
if ( !v5 )
{
result = 0LL;
if ( *(_DWORD *)(a1 + 8) <= v6 )
return result;
LABEL_9:
func2("invalid field offset", v3);
*(_WORD *)(a1 + 40) = 64;
return 1LL;
}
v8 = v5 * a2;
if ( !is_mul_ok(v5, a2) )
{
func2("invalid field count", v3);
*(_WORD *)(a1 + 40) = 64;
return 1LL;
}
if ( ~*(_DWORD *)(a1 + 8) < v8 )
goto LABEL_9;
v9 = v8 + *(_DWORD *)(a1 + 8);
result = 0LL;
if ( v9 > v6 )
goto LABEL_9;
return result;
}

original_code:
int
offsanity(struct exifprop *prop, u_int16_t size, struct ifd *dir)
{
 u_int32_t tifflen;
 const char *name;
 tifflen = dir->md.etiff - dir->md.btiff;
 if (prop->name)
  name = prop->name;
 else
  name = "Unknown";
 if (!prop->count) {
  if (prop->value > tifflen) {
   exifwarn2("invalid field offset", name);
   prop->lvl = 0x40;
   return (1);
  }
  return (0);
 }
 if (size > (u_int32_t)(-1) / prop->count) {
  exifwarn2("invalid field count", name);
  prop->lvl = 0x40;
  return (1);
 }
 if ((u_int32_t)(-1) - prop->value < prop->count * size) {
  exifwarn2("invalid field offset", name);
  prop->lvl = 0x40;
  return (1);
 }
 if (prop->value + prop->count * size > tifflen) {
  exifwarn2("invalid field offset", name);
  prop->lvl = 0x40;
  return (1);
 }
 return (0);
}

canonical_original_code:
int offsanity(struct exifprop *prop, unsigned int size, struct ifd *dir)
{
 unsigned int tifflen;
 char *name;
 tifflen = dir->md.etiff - dir->md.btiff;
 if (prop->name)
  name = prop->name;
 else
  name = "Unknown";
 if (!prop->count) {
  if (prop->value > tifflen) {
   exifwarn2("invalid field offset", name);
   prop->lvl = 0x40;
   return (1);
  }
  return (0);
 }
 if (size > (u_int32_t)(-1) / prop->count) {
  exifwarn2("invalid field count", name);
  prop->lvl = 0x40;
  return (1);
 }
 if ((u_int32_t)(-1) - prop->value < prop->count * size) {
  exifwarn2("invalid field offset", name);
  prop->lvl = 0x40;
  return (1);
 }
 if (prop->value + prop->count * size > tifflen) {
  exifwarn2("invalid field offset", name);
  prop->lvl = 0x40;
  return (1);
 }
 return (0);
}

variable_types:
size
unsigned int

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

variable_types:
tifflen
unsigned int

variable_types:
name
char *


decompiled_code:
__int64 __fastcall exif2byte(unsigned __int16 *a1, int a2)
{
__int64 result; // rax
unsigned int v3; // edx

result = *a1;
v3 = *a1;
LOWORD(v3) = __ROL2__(v3, 8);
if ( a2 == 1 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 *a1, int a2)
{
__int64 result; // rax
unsigned int v3; // edx

result = *a1;
v3 = *a1;
LOWORD(v3) = __ROL2__(v3, 8);
if ( a2 == 1 )
result = v3;
return result;
}

original_code:
u_int16_t
exif2byte(unsigned char *b, enum byteorder o)
{
 if (o == BIG)
  return ((b[0] << 8) | b[1]);
 else
  return ((b[1] << 8) | b[0]);
}

canonical_original_code:
unsigned int exif2byte(unsigned char *b, enum byteorder o)
{
 if (o == BIG)
  return ((b[0] << 8) | b[1]);
 else
  return ((b[1] << 8) | b[0]);
}

variable_types:
b
unsigned char *

variable_types:
o
enum byteorder { LITTLE=0, BIG=1 }

return_type: unsigned int


decompiled_code:
__int16 __fastcall exif2sbyte(_WORD *a1, int a2)
{
__int16 result; // ax

result = __ROL2__(*a1, 8);
if ( a2 != 1 )
result = *a1;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func5(_WORD *a1, int a2)
{
__int16 result; // ax

result = __ROL2__(*a1, 8);
if ( a2 != 1 )
result = *a1;
return result;
}

original_code:
int16_t
exif2sbyte(unsigned char *b, enum byteorder o)
{
 if (o == BIG)
  return ((b[0] << 8) | b[1]);
 else
  return ((b[1] << 8) | b[0]);
}

canonical_original_code:
short exif2sbyte(unsigned char *b, enum byteorder o)
{
 if (o == BIG)
  return ((b[0] << 8) | b[1]);
 else
  return ((b[1] << 8) | b[0]);
}

return_type: short


decompiled_code:
__int64 __fastcall exif4byte(unsigned int *a1, int a2)
{
__int64 result; // rax
unsigned __int32 v3; // edx

result = *a1;
v3 = _byteswap_ulong(*a1);
if ( a2 == 1 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, int a2)
{
__int64 result; // rax
unsigned __int32 v3; // edx

result = *a1;
v3 = _byteswap_ulong(*a1);
if ( a2 == 1 )
result = v3;
return result;
}


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

result = _byteswap_ulong(*a1);
if ( a2 != 1 )
result = *a1;
return result;
}

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

result = _byteswap_ulong(*a1);
if ( a2 != 1 )
result = *a1;
return result;
}


finddescr

decompiled_code:
void *__fastcall finddescr(int *a1, unsigned __int16 a2)
{
int i; // eax
const char *v3; // rbp
size_t v4; // r12
void *v5; // rax
int *v7; // rax
char *v8; // rax

for ( i = *a1; i != -1; a1 += 4 )
{
if ( i == a2 )
break;
i = a1[4];
}
v3 = (const char *)*((_QWORD *)a1 + 1);
v4 = strlen(v3) + 1;
v5 = malloc(v4);
if ( !v5 )
{
v7 = _errno_location();
v8 = strerror(*v7);
exifdie(v8);
}
return memcpy(v5, v3, v4);
}

canonical_decompiled_code:
void *__fastcall func9(int *a1, unsigned __int16 a2)
{
int i; // eax
const char *v3; // rbp
size_t v4; // r12
void *v5; // rax
int *v7; // rax
char *v8; // rax

for ( i = *a1; i != -1; a1 += 4 )
{
if ( i == a2 )
break;
i = a1[4];
}
v3 = (const char *)*((_QWORD *)a1 + 1);
v4 = strlen(v3) + 1;
v5 = malloc(v4);
if ( !v5 )
{
v7 = _errno_location();
v8 = strerror(*v7);
func0(v8);
}
return memcpy(v5, v3, v4);
}

original_code:
char *
finddescr(struct descrip *table, u_int16_t val)
{
 int i;
 char *c;
 for (i = 0; table[i].val != -1 && table[i].val != val; i++);
 if (!(c = (char *)malloc(strlen(table[i].descr) + 1)))
  exifdie((const char *)strerror((*__errno_location ())));
 strcpy(c, table[i].descr);
 return (c);
}

canonical_original_code:
char *finddescr(struct descrip *table, unsigned int val)
{
 int i;
 char *c;
 for (i = 0; table[i].val != -1 && table[i].val != val; i++);
 if (!(c = (char *)malloc(strlen(table[i].descr) + 1)))
  exifdie((char *)strerror((*__errno_location ())));
 strcpy(c, table[i].descr);
 return (c);
}

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

variable_types:
val
unsigned int

variable_types: i int

variable_types:
c
char *

return_type: char *


catdescr

decompiled_code:
__int64 __fastcall catdescr(char *dest, const char **a2, unsigned __int16 a3, int a4)
{
__int64 v4; // rbp
int v5; // eax
const char **v6; // rbx
int v7; // er13
size_t v8; // rax
size_t v10; // rax

v4 = a4 - 1;
dest[v4] = 0;
v5 = *(_DWORD *)a2;
if ( *(_DWORD *)a2 == -1 )
return 0LL;
v6 = a2;
while ( v5 != a3 )
{
v5 = *((_DWORD *)v6 + 4);
v6 += 2;
if ( v5 == -1 )
return 0LL;
}
v7 = 0;
if ( *dest )
{
v7 = 2;
v10 = strlen(dest);
strncat(dest, ", ", v4 - v10);
}
v8 = strlen(dest);
strncat(dest, v6[1], v4 - v8);
return v7 + (unsigned int)strlen(v6[1]);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *dest, const char **a2, unsigned __int16 a3, int a4)
{
__int64 v4; // rbp
int v5; // eax
const char **v6; // rbx
int v7; // er13
size_t v8; // rax
size_t v10; // rax

v4 = a4 - 1;
dest[v4] = 0;
v5 = *(_DWORD *)a2;
if ( *(_DWORD *)a2 == -1 )
return 0LL;
v6 = a2;
while ( v5 != a3 )
{
v5 = *((_DWORD *)v6 + 4);
v6 += 2;
if ( v5 == -1 )
return 0LL;
}
v7 = 0;
if ( *dest )
{
v7 = 2;
v10 = strlen(dest);
strncat(dest, ", ", v4 - v10);
}
v8 = strlen(dest);
strncat(dest, v6[1], v4 - v8);
return v7 + (unsigned int)strlen(v6[1]);
}

original_code:
int
catdescr(char *c, struct descrip *table, u_int16_t val, int len)
{
 int i, l;
 l = 0;
 len -= 1;
 c[len] = '\0';
 for (i = 0; table[i].val != -1 && table[i].val != val; i++);
 if (table[i].val == -1)
  return (0);
 if (strlen(c)) {
  strncat(c, ", ", len - strlen(c));
  l += 2;
 }
 strncat(c, table[i].descr, len - strlen(c));
 l += strlen(table[i].descr);
 return (l);
}

canonical_original_code:
int catdescr(char *c, struct descrip *table, unsigned int val, int len)
{
 int i; int l;
 l = 0;
 len -= 1;
 c[len] = '\0';
 for (i = 0; table[i].val != -1 && table[i].val != val; i++);
 if (table[i].val == -1)
  return (0);
 if (strlen(c)) {
  strncat(c, ", ", len - strlen(c));
  l += 2;
 }
 strncat(c, table[i].descr, len - strlen(c));
 l += strlen(table[i].descr);
 return (l);
}

variable_types: len int

variable_types: l int


findprop

decompiled_code:
__int64 __fastcall findprop(__int64 a1, __int64 a2, __int16 a3)
{
__int64 result; // rax

for ( result = a1; result; result = *(_QWORD *)(result + 72) )
{
if ( *(_QWORD *)(result + 56) == a2 && *(_WORD *)result == a3 && *(_WORD *)(result + 40) != 64 )
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int16 a3)
{
__int64 result; // rax

for ( result = a1; result; result = *(_QWORD *)(result + 72) )
{
if ( *(_QWORD *)(result + 56) == a2 && *(_WORD *)result == a3 && *(_WORD *)(result + 40) != 64 )
break;
}
return result;
}

original_code:
struct exifprop *
findprop(struct exifprop *prop, struct exiftag *tagset, u_int16_t tag)
{
 for (; prop && (prop->tagset != tagset || prop->tag != tag ||
     prop->lvl == 0x40); prop = prop->next);
 return (prop);
}

canonical_original_code:
struct exifprop *findprop(struct exifprop *prop, struct exiftag *tagset, unsigned int tag)
{
 for (; prop && (prop->tagset != tagset || prop->tag != tag ||
     prop->lvl == 0x40); prop = prop->next);
 return (prop);
}

variable_types:
prop
struct exifprop *

variable_types:
tagset
struct exiftag *

variable_types:
tag
unsigned int

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


newprop

decompiled_code:
void *newprop()
{
void *result; // rax
int *v1; // rax
char *v2; // rax

result = calloc(0x50uLL, 1uLL);
if ( !result )
{
v1 = _errno_location();
v2 = strerror(*v1);
exifdie(v2);
}
return result;
}

canonical_decompiled_code:
void *func12()
{
void *result; // rax
int *v1; // rax
char *v2; // rax

result = calloc(0x50uLL, 1uLL);
if ( !result )
{
v1 = _errno_location();
v2 = strerror(*v1);
func0(v2);
}
return result;
}

original_code:
struct exifprop *
newprop(void)
{
 struct exifprop *prop;
 prop = (struct exifprop *)malloc(sizeof(struct exifprop));
 if (!prop)
  exifdie((const char *)strerror((*__errno_location ())));
 memset(prop, 0, sizeof(struct exifprop));
 return (prop);
}

canonical_original_code:
struct exifprop *newprop()
{
 struct exifprop *prop;
 prop = (struct exifprop *)malloc(sizeof(struct exifprop));
 if (!prop)
  exifdie((char *)strerror((*__errno_location ())));
 memset(prop, 0, sizeof(struct exifprop));
 return (prop);
}

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


exifstralloc

decompiled_code:
void *__fastcall exifstralloc(_QWORD *a1, int a2)
{
void *result; // rax
int *v3; // rax
char *v4; // rax

if ( *a1 )
{
exifwarn("tried to alloc over non-null string");
abort();
}
result = calloc(1uLL, a2);
*a1 = result;
if ( !result )
{
v3 = _errno_location();
v4 = strerror(*v3);
exifdie(v4);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func13(_QWORD *a1, int a2)
{
void *result; // rax
int *v3; // rax
char *v4; // rax

if ( *a1 )
{
func1("tried to alloc over non-null string");
abort();
}
result = calloc(1uLL, a2);
*a1 = result;
if ( !result )
{
v3 = _errno_location();
v4 = strerror(*v3);
func0(v4);
}
return result;
}

original_code:
void
exifstralloc(char **str, int len)
{
 if (*str) {
  exifwarn("tried to alloc over non-null string");
  abort();
 }
 if (!(*str = (char *)calloc(1, len)))
  exifdie((const char *)strerror((*__errno_location ())));
}

canonical_original_code:
void exifstralloc(char **str, int len)
{
 if (*str) {
  exifwarn("tried to alloc over non-null string");
  abort();
 }
 if (!(*str = (char *)calloc(1, len)))
  exifdie((char *)strerror((*__errno_location ())));
}

variable_types:
str
char **


hexprint

decompiled_code:
int __fastcall hexprint(unsigned __int8 *a1, int a2)
{
__int64 v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
result = printf(" %02X", v4);
}
while ( v3 != (unsigned __int8 *)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(unsigned __int8 *a1, int a2)
{
__int64 v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
result = printf(" %02X", v4);
}
while ( v3 != (unsigned __int8 *)v2 );
}
return result;
}

original_code:
void
hexprint(unsigned char *b, int len)
{
 int i;
 for (i = 0; i < len; i++)
  printf(" %02X", b[i]);
}


dumpprop

decompiled_code:
void __fastcall dumpprop(unsigned __int16 *a1, unsigned __int8 *a2)
{
__int16 v2; // ax
unsigned __int64 v4; // rdx
int v5; // ecx
__int64 v6; // r9
__int64 v7; // r8
__int64 v8; // rdx
const char *v9; // rsi
const char *v10; // rcx

if ( debug )
{
v2 = ftypes;
if ( ftypes )
{
v4 = (unsigned int)((_DWORD)&ftypes + 24);
v5 = 0;
do
{
if ( a1[1] == v2 )
break;
v2 = *(_WORD *)v4;
v4 += 24LL;
++v5;
}
while ( v2 );
}
else
{
v5 = 0;
}
v6 = *((unsigned int *)a1 + 2);
v7 = *((unsigned int *)a1 + 1);
v8 = *a1;
v9 = (const char *)*((_QWORD *)a1 + 2);
v10 = (const char *)*((_QWORD *)&ftypes + 3 * v5 + 1);
if ( a2 )
{
printf(" %s (0x%04X): %s, %u; %u\n", v9, v8, v10, v7, v6);
printf(" ");
hexprint(a2, 2);
printf(" |");
hexprint(a2 + 2, 2);
printf(" |");
hexprint(a2 + 4, 4);
printf(" |");
hexprint(a2 + 8, 4);
putchar(10);
}
else
{
printf(" %s (0x%04X): %s, %d; %d, 0x%04X\n", v9, v8, v10, v7, v6, v6);
}
}
}

original_code:
void
dumpprop(struct exifprop *prop, struct field *afield)
{
 int i;
 if (!debug) return;
 for (i = 0; ftypes[i].type && ftypes[i].type != prop->type; i++);
 if (afield) {
  printf("   %s (0x%04X): %s, %u; %u\n", prop->name,
      prop->tag, ftypes[i].name, prop->count,
      prop->value);
  printf("      ");
  hexprint(afield->tag, 2);
  printf(" |");
  hexprint(afield->type, 2);
  printf(" |");
  hexprint(afield->count, 4);
  printf(" |");
  hexprint(afield->value, 4);
  printf("\n");
 } else
  printf("   %s (0x%04X): %s, %d; %d, 0x%04X\n",
      prop->name, prop->tag, ftypes[i].name,
      prop->count, prop->value, prop->value);
}

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


readifd

original_code:
u_int32_t
readifd(u_int32_t offset, struct ifd **dir, struct exiftag *tagset,
    struct tiffmeta *md)
{
 u_int32_t ifdsize, tifflen;
 unsigned char *b;
 struct ifdoff *ifdoffs, *lastoff;
 tifflen = md->etiff - md->btiff;
 b = md->btiff;
 ifdoffs = (struct ifdoff *)(md->ifdoffs);
 lastoff = ((void *)0);
 *dir = ((void *)0);
 while (ifdoffs && ifdoffs->offset != b + offset) {
  lastoff = ifdoffs;
  ifdoffs = ifdoffs->next;
 }
 if (ifdoffs) {
  if (debug) exifwarn("loop in IFD reference");
  return (0);
 }
 ifdoffs = (struct ifdoff *)malloc(sizeof(struct ifdoff));
 if (!ifdoffs) {
  exifwarn2("can't allocate IFD offset record",
      (const char *)strerror((*__errno_location ())));
  return (0);
 }
 ifdoffs->offset = offset + b;
 ifdoffs->next = ((void *)0);
 if (lastoff)
  lastoff->next = ifdoffs;
 else
  md->ifdoffs = (void *)ifdoffs;
 if ((u_int32_t)(-1) - offset < 2 || offset + 2 > tifflen)
  return (0);
 *dir = (struct ifd *)malloc(sizeof(struct ifd));
 if (!*dir) {
  exifwarn2("can't allocate IFD record",
      (const char *)strerror((*__errno_location ())));
  return (0);
 }
 (*dir)->num = exif2byte(b + offset, md->order);
 (*dir)->par = ((void *)0);
 (*dir)->tagset = tagset;
 (*dir)->md = *md;
 (*dir)->next = ((void *)0);
 if ((*dir)->num &&
     sizeof(struct field) > (u_int32_t)(-1) / (*dir)->num) {
  free(*dir);
  *dir = ((void *)0);
  return (0);
 }
 ifdsize = (*dir)->num * sizeof(struct field);
 b += offset + 2;
 if ((u_int32_t)(-1) - (offset + 2) < ifdsize ||
     offset + 2 + ifdsize > tifflen) {
  free(*dir);
  *dir = ((void *)0);
  return (0);
 }
 (*dir)->fields = (struct field *)b;
 return ((b + ifdsize + 4 > md->etiff) ? 0 :
     exif4byte(b + ifdsize, md->order));
}

canonical_original_code:
unsigned int readifd(unsigned int offset, struct ifd **dir, struct exiftag *tagset, struct tiffmeta *md)
{
 unsigned int ifdsize; unsigned int tifflen;
 unsigned char *b;
 struct ifdoff *ifdoffs; struct ifdoff *lastoff;
 tifflen = md->etiff - md->btiff;
 b = md->btiff;
 ifdoffs = (struct ifdoff *)(md->ifdoffs);
 lastoff = ((void *)0);
 *dir = ((void *)0);
 while (ifdoffs && ifdoffs->offset != b + offset) {
  lastoff = ifdoffs;
  ifdoffs = ifdoffs->next;
 }
 if (ifdoffs) {
  if (debug) exifwarn("loop in IFD reference");
  return (0);
 }
 ifdoffs = (struct ifdoff *)malloc(sizeof(struct ifdoff));
 if (!ifdoffs) {
  exifwarn2("can't allocate IFD offset record",
      (char *)strerror((*__errno_location ())));
  return (0);
 }
 ifdoffs->offset = offset + b;
 ifdoffs->next = ((void *)0);
 if (lastoff)
  lastoff->next = ifdoffs;
 else
  md->ifdoffs = (void *)ifdoffs;
 if ((u_int32_t)(-1) - offset < 2 || offset + 2 > tifflen)
  return (0);
 *dir = (struct ifd *)malloc(sizeof(struct ifd));
 if (!*dir) {
  exifwarn2("can't allocate IFD record",
      (char *)strerror((*__errno_location ())));
  return (0);
 }
 (*dir)->num = exif2byte(b + offset, md->order);
 (*dir)->par = ((void *)0);
 (*dir)->tagset = tagset;
 (*dir)->md = *md;
 (*dir)->next = ((void *)0);
 if ((*dir)->num &&
     sizeof(struct field) > (u_int32_t)(-1) / (*dir)->num) {
  free(*dir);
  *dir = ((void *)0);
  return (0);
 }
 ifdsize = (*dir)->num * sizeof(struct field);
 b += offset + 2;
 if ((u_int32_t)(-1) - (offset + 2) < ifdsize ||
     offset + 2 + ifdsize > tifflen) {
  free(*dir);
  *dir = ((void *)0);
  return (0);
 }
 (*dir)->fields = (struct field *)b;
 return ((b + ifdsize + 4 > md->etiff) ? 0 :
     exif4byte(b + ifdsize, md->order));
}

variable_types:
offset
unsigned int

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

variable_types:
md
struct tiffmeta *

variable_types:
ifdsize
unsigned int

variable_types: struct ifdoff { unsigned char *offset; struct ifdoff *next; } *


gcd

decompiled_code:
__int64 __fastcall gcd(unsigned int a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // er8
int v4; // edx

v2 = a1;
v3 = a2;
if ( !a2 )
return a1;
while ( 1 )
{
v4 = v2 % v3;
v2 = v3;
if ( !v4 )
break;
v3 = v4;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // er8
int v4; // edx

v2 = a1;
v3 = a2;
if ( !a2 )
return a1;
while ( 1 )
{
v4 = v2 % v3;
v2 = v3;
if ( !v4 )
break;
v3 = v4;
}
return v3;
}

original_code:
u_int32_t
gcd(u_int32_t a, u_int32_t b)
{
 if (!b) return (a);
 return (gcd(b, a % b));
}

canonical_original_code:
unsigned int gcd(unsigned int a, unsigned int b)
{
 if (!b) return (a);
 return (gcd(b, a % b));
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int


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

result = *a1;
if ( (_WORD)result == 32 )
{
a1[24] = -23544;
}
else if ( (unsigned __int16)result > 0x20u )
{
if ( (_WORD)result == 33 )
{
result = 4294943754LL;
a1[24] = -23542;
}
}
else if ( (_WORD)result == 25 )
{
a1[24] = -23549;
}
else if ( (_WORD)result == 31 )
{
a1[24] = -23543;
}
return result;
}

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

result = *a1;
if ( (_WORD)result == 32 )
{
a1[24] = -23544;
}
else if ( (unsigned __int16)result > 0x20u )
{
if ( (_WORD)result == 33 )
{
result = 4294943754LL;
a1[24] = -23542;
}
}
else if ( (_WORD)result == 25 )
{
a1[24] = -23549;
}
else if ( (_WORD)result == 31 )
{
a1[24] = -23543;
}
return result;
}

original_code:
void
asahi_prop(struct exifprop *prop, struct exiftags *t)
{
 switch (prop->tag) {
 case 0x0019:
  prop->override = 0xa403;
  break;
 case 0x001f:
  prop->override = 0xa409;
  break;
 case 0x0020:
  prop->override = 0xa408;
  break;
 case 0x0021:
  prop->override = 0xa40a;
  break;
 }
}

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


decompiled_code:
__int64 __fastcall asahi_ifd(unsigned int a1, unsigned int *a2)
{
__int64 v2; // rax
__int64 v4; // rdx
_DWORD *v5; // rdi
_WORD *v6; // rax
__int64 result; // rax

v2 = a1;
v4 = *((_QWORD *)a2 + 1);
v5 = (_DWORD *)(v4 + a1);
if ( *v5 == 4411201 )
{
v6 = (_WORD *)(v4 + v2 + 4);
if ( *v6 == 8224 )
{
*a2 = 1;
}
else if ( *v6 )
{
LABEL_4:
exifwarn("Asahi maker note version not supported");
return 0LL;
}
result = readifds(a1 + 6, &asahi_tags, a2);
}
else
{
if ( (unsigned __int16)exif2byte(v5, *a2) <= 9u )
goto LABEL_4;
*a2 = 1;
result = readifds(a1, &asahi_tags, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int *a2)
{
__int64 v2; // rax
__int64 v4; // rdx
_DWORD *v5; // rdi
_WORD *v6; // rax
__int64 result; // rax

v2 = a1;
v4 = *((_QWORD *)a2 + 1);
v5 = (_DWORD *)(v4 + a1);
if ( *v5 == 4411201 )
{
v6 = (_WORD *)(v4 + v2 + 4);
if ( *v6 == 8224 )
{
*a2 = 1;
}
else if ( *v6 )
{
LABEL_4:
exifwarn("Asahi maker note version not supported");
return 0LL;
}
result = readifds(a1 + 6, &asahi_tags, a2);
}
else
{
if ( (unsigned __int16)exif2byte(v5, *a2) <= 9u )
goto LABEL_4;
*a2 = 1;
result = readifds(a1, &asahi_tags, a2);
}
return result;
}

original_code:
struct ifd *
asahi_ifd(u_int32_t offset, struct tiffmeta *md)
{
 if (!memcmp("AOC\0", md->btiff + offset, 4)) {
  if (!memcmp("  ", md->btiff + offset + 4, 2)) {
   md->order = BIG;
   return (readifds(offset + 6, asahi_tags, md));
  }
  if (!memcmp("\0\0", md->btiff + offset + 4, 2))
   return (readifds(offset + 6, asahi_tags, md));
  if (!memcmp("MM", md->btiff + offset + 4, 2)) {
   exifwarn("Asahi maker note version not supported");
   return (((void *)0));
  }
  exifwarn("Asahi maker note version not supported");
  return (((void *)0));
 }
 if (exif2byte(md->btiff + offset, md->order) < 10) {
  exifwarn("Asahi maker note version not supported");
  return (((void *)0));
 }
 md->order = BIG;
 return (readifds(offset, asahi_tags, md));
}

canonical_original_code:
struct ifd *asahi_ifd(unsigned int offset, struct tiffmeta *md)
{
 if (!memcmp("AOC\0", md->btiff + offset, 4)) {
  if (!memcmp("  ", md->btiff + offset + 4, 2)) {
   md->order = BIG;
   return (readifds(offset + 6, asahi_tags, md));
  }
  if (!memcmp("\0\0", md->btiff + offset + 4, 2))
   return (readifds(offset + 6, asahi_tags, md));
  if (!memcmp("MM", md->btiff + offset + 4, 2)) {
   exifwarn("Asahi maker note version not supported");
   return (((void *)0));
  }
  exifwarn("Asahi maker note version not supported");
  return (((void *)0));
 }
 if (exif2byte(md->btiff + offset, md->order) < 10) {
  exifwarn("Asahi maker note version not supported");
  return (((void *)0));
 }
 md->order = BIG;
 return (readifds(offset, asahi_tags, md));
}

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