repo: defuse/passgen

decompiled_code:
void __fastcall ct_string_init(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

original_code:
void ct_string_init(ct_string *str)
{
    str->allocated_length = 0;
    str->actual_length = 0;
    str->string = ((void *)0);
}

canonical_original_code:
void ct_string_init(struct ConstantTimeString *str)
{
    str->allocated_length = 0;
    str->actual_length = 0;
    str->string = ((void *)0);
}

variable_types: struct ConstantTimeString { unsigned int allocated_length; unsigned int actual_length; unsigned char *string; } *


decompiled_code:
__int64 __fastcall ct_string_concat(unsigned int *a1, __int64 a2, unsigned int a3, unsigned int a4)
{
void *v7; // rdi
char *v8; // rax
unsigned int v9; // eax
unsigned int v10; // ebx
__int64 v11; // r15
unsigned int v12; // eax
char v13; // r12
unsigned int v14; // eax
char v15; // al
_BYTE *v16; // rcx
void *v18; // rax
unsigned int v19; // [rsp+Ch] [rbp-3Ch]

if ( a3 >= a4 && a3 != 0 && a4 )
{
v7 = (void *)*((_QWORD *)a1 + 1);
if ( v7 )
{
v8 = (char *)realloc(v7, *a1 + a3);
*((_QWORD *)a1 + 1) = v8;
if ( v8 )
{
memset(&v8[*a1], 0, a3);
v19 = a3 - 1;
v9 = a3 + *a1;
*a1 = v9;
if ( v9 <= a3 - 1 )
{
LABEL_10:
a1[1] += a4;
return 1LL;
}
LABEL_6:
v10 = 0;
do
{
v11 = 0LL;
v12 = ct_eq_u32(v10, a1[1]);
v13 = ct_mask_u32(v12);
do
{
v14 = ct_lt_u32((unsigned int)v11, a4);
v15 = *(_BYTE *)(a2 + v11) & ct_mask_u32(v14);
v16 = (_BYTE *)(*((_QWORD *)a1 + 1) + v10 + (unsigned int)v11++);
*v16 |= v13 & v15;
}
while ( v19 + 1 != v11 );
++v10;
}
while ( *a1 > v10 + v19 );
goto LABEL_10;
}
}
else
{
v18 = calloc(a3, 1uLL);
*((_QWORD *)a1 + 1) = v18;
if ( v18 )
{
*a1 = a3;
v19 = a3 - 1;
goto LABEL_6;
}
}
}
return 0LL;
}

original_code:
int ct_string_concat(ct_string *str, const unsigned char *to_append, uint32_t max_length, uint32_t actual_length)
{
    if (max_length == 0 || actual_length == 0 || actual_length > max_length) {
        return 0;
    }
    if (str->string == ((void *)0)) {
        str->string = malloc(max_length);
        if (str->string == ((void *)0)) {
            return 0;
        }
        memset(str->string, 0, max_length);
        str->allocated_length = max_length;
    } else {
        str->string = realloc(str->string, str->allocated_length + max_length);
        if (str->string == ((void *)0)) {
            return 0;
        }
        memset(str->string + str->allocated_length, 0, max_length);
        str->allocated_length += max_length;
    }
    for (uint32_t i = 0; i + max_length - 1 < str->allocated_length; i++) {
        uint32_t outer_mask = ct_mask_u32(ct_eq_u32(i, str->actual_length));
        for (uint32_t j = 0; j < max_length; j++) {
            uint32_t inner_mask = ct_mask_u32(ct_lt_u32(j, actual_length));
            str->string[i+j] |= (uint32_t)to_append[j] & outer_mask & inner_mask;
        }
    }
    str->actual_length += actual_length;
    return 1;
}

canonical_original_code:
int ct_string_concat(struct ConstantTimeString *str, unsigned char *to_append, unsigned int max_length, unsigned int actual_length)
{
    if (max_length == 0 || actual_length == 0 || actual_length > max_length) {
        return 0;
    }
    if (str->string == ((void *)0)) {
        str->string = malloc(max_length);
        if (str->string == ((void *)0)) {
            return 0;
        }
        memset(str->string, 0, max_length);
        str->allocated_length = max_length;
    } else {
        str->string = realloc(str->string, str->allocated_length + max_length);
        if (str->string == ((void *)0)) {
            return 0;
        }
        memset(str->string + str->allocated_length, 0, max_length);
        str->allocated_length += max_length;
    }
    for (unsigned int i = 0; i + max_length - 1 < str->allocated_length; i++) {
        unsigned int outer_mask = ct_mask_u32(ct_eq_u32(i, str->actual_length));
        for (unsigned int j = 0; j < max_length; j++) {
            unsigned int inner_mask = ct_mask_u32(ct_lt_u32(j, actual_length));
            str->string[i+j] |= (unsigned int)to_append[j] & outer_mask & inner_mask;
        }
    }
    str->actual_length += actual_length;
    return 1;
}

variable_types:
i
unsigned int

variable_types:
j
unsigned int

return_type: int

user_defined_types: struct ConstantTimeString { unsigned int allocated_length; unsigned int actual_length; unsigned char *string; }


decompiled_code:
__int64 __fastcall ct_string_finalize(unsigned int *a1, __int64 a2, unsigned __int8 a3)
{
__int64 result; // rax
unsigned int v4; // er12
unsigned int v6; // ebx
__int64 v7; // rdi
__int64 v8; // r14
unsigned int v9; // eax

result = *a1;
if ( (_DWORD)result )
{
v4 = a3;
v6 = 0;
do
{
v7 = v6;
v8 = v6++;
v9 = ct_lt_u32(v7, a1[1]);
result = ct_select_u32(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v8), v4, v9);
*(_BYTE *)(a2 + v8) = result;
}
while ( *a1 > v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, __int64 a2, unsigned __int8 a3)
{
__int64 result; // rax
unsigned int v4; // er12
unsigned int v6; // ebx
__int64 v7; // rdi
__int64 v8; // r14
unsigned int v9; // eax

result = *a1;
if ( (_DWORD)result )
{
v4 = a3;
v6 = 0;
do
{
v7 = v6;
v8 = v6++;
v9 = ct_lt_u32(v7, a1[1]);
result = ct_select_u32(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v8), v4, v9);
*(_BYTE *)(a2 + v8) = result;
}
while ( *a1 > v6 );
}
return result;
}

original_code:
void ct_string_finalize(ct_string *str, unsigned char *buf, unsigned char filler)
{
    for (uint32_t i = 0; i < str->allocated_length; i++) {
        buf[i] = ct_select_u32(str->string[i], filler, ct_lt_u32(i, str->actual_length));
    }
}

canonical_original_code:
void ct_string_finalize(struct ConstantTimeString *str, unsigned char *buf, unsigned char filler)
{
    for (unsigned int i = 0; i < str->allocated_length; i++) {
        buf[i] = ct_select_u32(str->string[i], filler, ct_lt_u32(i, str->actual_length));
    }
}

variable_types:
buf
unsigned char *

variable_types:
filler
unsigned char

return_type: void


decompiled_code:
__int64 __fastcall ct_string_allocated_length(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
return *a1;
}

original_code:
uint32_t ct_string_allocated_length(ct_string *str)
{
    return str->allocated_length;
}

canonical_original_code:
unsigned int ct_string_allocated_length(struct ConstantTimeString *str)
{
    return str->allocated_length;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall ct_string_deinit(unsigned int *a1)
{
__int64 v2; // rdi

v2 = *((_QWORD *)a1 + 1);
if ( v2 )
{
memset_s(v2, 0LL, *a1);
free(*((void **)a1 + 1));
}
memset_s(a1, 0LL, 4LL);
return memset_s(a1 + 1, 0LL, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
__int64 v2; // rdi

v2 = *((_QWORD *)a1 + 1);
if ( v2 )
{
memset_s(v2, 0LL, *a1);
free(*((void **)a1 + 1));
}
memset_s(a1, 0LL, 4LL);
return memset_s(a1 + 1, 0LL, 4LL);
}

original_code:
void ct_string_deinit(ct_string *str)
{
    if (str->string != ((void *)0)) {
        memset_s(str->string, 0, str->allocated_length);
        free(str->string);
    }
    memset_s(&(str->allocated_length), 0, sizeof(str->allocated_length));
    memset_s(&(str->actual_length), 0, sizeof(str->actual_length));
}

canonical_original_code:
void ct_string_deinit(struct ConstantTimeString *str)
{
    if (str->string != ((void *)0)) {
        memset_s(str->string, 0, str->allocated_length);
        free(str->string);
    }
    memset_s(&(str->allocated_length), 0, sizeof(str->allocated_length));
    memset_s(&(str->actual_length), 0, sizeof(str->actual_length));
}


showHelp

decompiled_code:
int showHelp()
{
puts("Usage: passgen <type> <optional arguments>");
puts("Where <type> is one of:");
puts(" -x, --hex\t\t\t\t64 hexadecimal characters");
puts(" -a, --ascii\t\t\t\t64 ASCII characters");
puts(" -n, --alpha\t\t\t\t64 alpha-numeric characters");
puts(" -d, --digit\t\t\t\t64 digit characters (for PINs)");
puts(" -l, --lower\t\t\t\t64 lower-alpha characters (for phones)");
printf(" -w, --words\t\t\t\t%d random words from a list of %d\n", 10LL, 7236LL);
puts(" -h, --help\t\t\t\tShow this help menu");
puts("Where <optional arguments> can be:");
puts(" -p, --password-count N\t\tSpecify number of passwords to generate");
return puts("WARNING: If automated, you MUST check that the exit status is 0.");
}

canonical_decompiled_code:
int func0()
{
puts("Usage: passgen <type> <optional arguments>");
puts("Where <type> is one of:");
puts(" -x, --hex\t\t\t\t64 hexadecimal characters");
puts(" -a, --ascii\t\t\t\t64 ASCII characters");
puts(" -n, --alpha\t\t\t\t64 alpha-numeric characters");
puts(" -d, --digit\t\t\t\t64 digit characters (for PINs)");
puts(" -l, --lower\t\t\t\t64 lower-alpha characters (for phones)");
printf(" -w, --words\t\t\t\t%d random words from a list of %d\n", 10LL, 7236LL);
puts(" -h, --help\t\t\t\tShow this help menu");
puts("Where <optional arguments> can be:");
puts(" -p, --password-count N\t\tSpecify number of passwords to generate");
return puts("WARNING: If automated, you MUST check that the exit status is 0.");
}

original_code:
void showHelp(void)
{
    puts("Usage: passgen <type> <optional arguments>");
    puts("Where <type> is one of:");
    puts("  -x, --hex\t\t\t\t64 hexadecimal characters");
    puts("  -a, --ascii\t\t\t\t64 ASCII characters");
    puts("  -n, --alpha\t\t\t\t64 alpha-numeric characters");
    puts("  -d, --digit\t\t\t\t64 digit characters (for PINs)");
    puts("  -l, --lower\t\t\t\t64 lower-alpha characters (for phones)");
    printf("  -w, --words\t\t\t\t%d random words from a list of %d\n", 10, 7236);
    puts("  -h, --help\t\t\t\tShow this help menu");
    puts("Where <optional arguments> can be:");
    puts("  -p, --password-count N\t\tSpecify number of passwords to generate");
    puts("WARNING: If automated, you MUST check that the exit status is 0.");
}

canonical_original_code:
void showHelp()
{
    puts("Usage: passgen <type> <optional arguments>");
    puts("Where <type> is one of:");
    puts("  -x, --hex\t\t\t\t64 hexadecimal characters");
    puts("  -a, --ascii\t\t\t\t64 ASCII characters");
    puts("  -n, --alpha\t\t\t\t64 alpha-numeric characters");
    puts("  -d, --digit\t\t\t\t64 digit characters (for PINs)");
    puts("  -l, --lower\t\t\t\t64 lower-alpha characters (for phones)");
    printf("  -w, --words\t\t\t\t%d random words from a list of %d\n", 10, 7236);
    puts("  -h, --help\t\t\t\tShow this help menu");
    puts("Where <optional arguments> can be:");
    puts("  -p, --password-count N\t\tSpecify number of passwords to generate");
    puts("WARNING: If automated, you MUST check that the exit status is 0.");
}


decompiled_code:
__int64 __fastcall lookup_word(__int64 a1, unsigned int a2)
{
__int64 v2; // r15
unsigned int v3; // er13
unsigned int v4; // er12
int v5; // ebp
char v6; // bl
unsigned int v7; // eax
int v8; // ecx
__int64 i; // rax

v2 = 0LL;
v3 = 0;
v4 = 0;
v5 = 6;
v6 = 97;
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
*(_WORD *)(a1 + 12) = 0;
*(_BYTE *)(a1 + 14) = 0;
while ( 1 )
{
v7 = ct_eq_u32(v3, a2);
v8 = ct_mask_u32(v7);
for ( i = 0LL; ; v6 = words[v2 + 1 + i] )
{
*(_BYTE *)(a1 + i++) |= (unsigned __int8)v8 & v6;
if ( i == 15 )
break;
}
++v3;
v2 += 16LL;
v4 |= v5 & v8;
if ( v3 == 7236 )
break;
v5 = (unsigned __int8)words[v2];
v6 = words[v2 + 1];
}
return v4;
}

original_code:
uint32_t lookup_word(unsigned char *buf, uint32_t index)
{
    uint32_t length = 0;
    for (uint32_t i = 0; i < 15; i++) {
        buf[i] = 0;
    }
    for (uint32_t i = 0; i < 7236; i++) {
        uint32_t mask = ct_mask_u32(ct_eq_u32(i, index));
        for (uint32_t j = 0; j < 15; j++) {
            buf[j] |= words[i][j+1] & mask;
        }
        length |= words[i][0] & mask;
    }
    return length;
}

canonical_original_code:
unsigned int lookup_word(unsigned char *buf, unsigned int index)
{
    unsigned int length = 0;
    for (unsigned int i = 0; i < 15; i++) {
        buf[i] = 0;
    }
    for (unsigned int i = 0; i < 7236; i++) {
        unsigned int mask = ct_mask_u32(ct_eq_u32(i, index));
        for (unsigned int j = 0; j < 15; j++) {
            buf[j] |= words[i][j+1] & mask;
        }
        length |= words[i][0] & mask;
    }
    return length;
}

variable_types:
index
unsigned int

variable_types:
length
unsigned int

variable_types:
mask
unsigned int


getLeastCoveringMask

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

for ( result = 0LL; a1 > result; result = 2 * result + 1 )
;
return result;
}

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

for ( result = 0LL; a1 > result; result = 2 * result + 1 )
;
return result;
}

original_code:
unsigned long getLeastCoveringMask(unsigned long toRepresent)
{
    unsigned long mask = 0;
    while (mask < toRepresent) {
        mask = (mask << 1) | 1;
    }
    return mask;
}

variable_types:
toRepresent
unsigned long

variable_types:
mask
unsigned long

return_type: unsigned long


getPassword

decompiled_code:
_BOOL8 __fastcall getPassword(__int64 a1, unsigned __int64 a2, __int64 a3, size_t a4)
{
void *v5; // rax
void *v6; // r15
char v7; // r13
_BOOL4 v8; // ebx
size_t v9; // r14
size_t v10; // rax
size_t v12; // rbx
_BYTE *v13; // r9

v5 = malloc(a4);
if ( !v5 )
return 0;
v6 = v5;
if ( a2 - 1 > 0xFF )
{
v8 = 0;
free(v5);
}
else
{
v7 = getLeastCoveringMask(a2 - 1);
v8 = getRandom(v6, a4);
if ( v8 )
{
v9 = 0LL;
v10 = 0LL;
if ( a4 )
{
while ( 1 )
{
v12 = v10 + 1;
if ( (unsigned __int8)(v7 & *((_BYTE *)v6 + v10)) < a2 )
{
v13 = (_BYTE *)(a3 + v9++);
*v13 = invariant_time_lookup(a1, (unsigned int)a2, (unsigned __int8)(v7 & *((_BYTE *)v6 + v10)));
}
if ( v9 >= a4 )
break;
if ( a4 <= v12 )
{
v8 = getRandom(v6, a4);
if ( !v8 )
goto LABEL_16;
v12 = 0LL;
}
v10 = v12;
}
}
v8 = 1;
memset_s(v6, 0LL, a4);
free(v6);
}
else
{
LABEL_16:
memset_s(v6, 0LL, a4);
free(v6);
}
}
return v8;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, unsigned __int64 a2, __int64 a3, size_t a4)
{
void *v5; // rax
void *v6; // r15
char v7; // r13
_BOOL4 v8; // ebx
size_t v9; // r14
size_t v10; // rax
size_t v12; // rbx
_BYTE *v13; // r9

v5 = malloc(a4);
if ( !v5 )
return 0;
v6 = v5;
if ( a2 - 1 > 0xFF )
{
v8 = 0;
free(v5);
}
else
{
v7 = func2(a2 - 1);
v8 = func3(v6, a4);
if ( v8 )
{
v9 = 0LL;
v10 = 0LL;
if ( a4 )
{
while ( 1 )
{
v12 = v10 + 1;
if ( (unsigned __int8)(v7 & *((_BYTE *)v6 + v10)) < a2 )
{
v13 = (_BYTE *)(a3 + v9++);
*v13 = invariant_time_lookup(a1, (unsigned int)a2, (unsigned __int8)(v7 & *((_BYTE *)v6 + v10)));
}
if ( v9 >= a4 )
break;
if ( a4 <= v12 )
{
v8 = func3(v6, a4);
if ( !v8 )
goto LABEL_16;
v12 = 0LL;
}
v10 = v12;
}
}
v8 = 1;
memset_s(v6, 0LL, a4);
free(v6);
}
else
{
LABEL_16:
memset_s(v6, 0LL, a4);
free(v6);
}
}
return v8;
}

original_code:
int getPassword(const char *set, unsigned long setLength, unsigned char *password, unsigned long passwordLength)
{
    unsigned long bufLen = passwordLength;
    unsigned long bufIdx = 0;
    unsigned char *rndBuf = (unsigned char*)malloc(bufLen);
    if (rndBuf == ((void *)0)) {
        return 0;
    }
    if (setLength < 1 || setLength > 256) {
        free(rndBuf);
        return 0;
    }
    unsigned char bitMask = getLeastCoveringMask(setLength - 1ul) & 0xFF;
    if(!getRandom(rndBuf, bufLen)) {
        memset_s(rndBuf, 0, bufLen);
        free(rndBuf);
        return 0;
    }
    unsigned long i = 0;
    while(i < passwordLength) {
        if(bufIdx >= bufLen) {
            if(!getRandom(rndBuf, bufLen)) {
                memset_s(rndBuf, 0, bufLen);
                free(rndBuf);
                return 0;
            }
            bufIdx = 0;
        }
        unsigned char c = rndBuf[bufIdx++];
        c = c & bitMask;
        if(c < setLength) {
            password[i] = invariant_time_lookup((const unsigned char*)set, setLength, c);
            i++;
        }
    }
    memset_s(rndBuf, 0, bufLen);
    free(rndBuf);
    return 1;
}

canonical_original_code:
int getPassword(char *set, unsigned long setLength, unsigned char *password, unsigned long passwordLength)
{
    unsigned long bufLen = passwordLength;
    unsigned long bufIdx = 0;
    unsigned char *rndBuf = (unsigned char*)malloc(bufLen);
    if (rndBuf == ((void *)0)) {
        return 0;
    }
    if (setLength < 1 || setLength > 256) {
        free(rndBuf);
        return 0;
    }
    unsigned char bitMask = getLeastCoveringMask(setLength - 1ul) & 0xFF;
    if(!getRandom(rndBuf, bufLen)) {
        memset_s(rndBuf, 0, bufLen);
        free(rndBuf);
        return 0;
    }
    unsigned long i = 0;
    while(i < passwordLength) {
        if(bufIdx >= bufLen) {
            if(!getRandom(rndBuf, bufLen)) {
                memset_s(rndBuf, 0, bufLen);
                free(rndBuf);
                return 0;
            }
            bufIdx = 0;
        }
        unsigned char c = rndBuf[bufIdx++];
        c = c & bitMask;
        if(c < setLength) {
            password[i] = invariant_time_lookup((unsigned char *)set, setLength, c);
            i++;
        }
    }
    memset_s(rndBuf, 0, bufLen);
    free(rndBuf);
    return 1;
}

variable_types:
set
char *

variable_types:
setLength
unsigned long

variable_types:
password
unsigned char *

variable_types:
passwordLength
unsigned long

variable_types:
bufLen
unsigned long

variable_types:
bufIdx
unsigned long

variable_types:
rndBuf
unsigned char *

variable_types:
bitMask
unsigned char

variable_types:
i
unsigned long

variable_types:
c
unsigned char


getRandomUnsignedLong

decompiled_code:
_BOOL8 __fastcall getRandomUnsignedLong(void *a1)
{
return getRandom(a1, 8uLL);
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(void *a1)
{
return func3(a1, 8uLL);
}

original_code:
int getRandomUnsignedLong(unsigned long *random)
{
    return getRandom(random, sizeof(unsigned long));
}

variable_types:
random
unsigned long *


showRandomWords

decompiled_code:
__int64 showRandomWords()
{
int v0; // ebx
unsigned __int64 v1; // rax
unsigned __int64 v2; // rax
size_t v3; // r12
void *v4; // rax
void *v5; // rbp
unsigned int v7; // er12
unsigned __int64 v8; // [rsp+8h] [rbp-40h] BYREF
char v9[15]; // [rsp+11h] [rbp-37h] BYREF
char v10[40]; // [rsp+20h] [rbp-28h] BYREF

v0 = 0;
v8 = 0LL;
ct_string_init(v10);
while ( v0 != 10 )
{
if ( !getRandomUnsignedLong(&v8) )
return 0LL;
v1 = getLeastCoveringMask(0x1C43uLL);
v2 = v8 & v1;
v8 = v2;
if ( v2 <= 0x1C43 )
{
v7 = lookup_word((__int64)v9, v2);
if ( v0 && !(unsigned int)ct_string_concat(v10, ".", 1LL, 1LL)
|| !(unsigned int)ct_string_concat(v10, v9, 15LL, v7) )
{
return 0LL;
}
++v0;
}
}
v3 = (unsigned int)ct_string_allocated_length(v10);
v4 = malloc(v3);
v5 = v4;
if ( v4 )
{
ct_string_finalize(v10, v4, 46LL);
fwrite(v5, 1uLL, v3, stdout);
putchar(10);
memset_s(&v8, 0LL, 8LL);
memset_s(v9, 0LL, 15LL);
memset_s(v5, 0LL, v3);
ct_string_deinit(v10);
free(v5);
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // ebx
unsigned __int64 v1; // rax
unsigned __int64 v2; // rax
size_t v3; // r12
void *v4; // rax
void *v5; // rbp
unsigned int v7; // er12
unsigned __int64 v8; // [rsp+8h] [rbp-40h] BYREF
char v9[15]; // [rsp+11h] [rbp-37h] BYREF
char v10[40]; // [rsp+20h] [rbp-28h] BYREF

v0 = 0;
v8 = 0LL;
ct_string_init(v10);
while ( v0 != 10 )
{
if ( !func5(&v8) )
return 0LL;
v1 = func2(0x1C43uLL);
v2 = v8 & v1;
v8 = v2;
if ( v2 <= 0x1C43 )
{
v7 = func1((__int64)v9, v2);
if ( v0 && !(unsigned int)ct_string_concat(v10, ".", 1LL, 1LL)
|| !(unsigned int)ct_string_concat(v10, v9, 15LL, v7) )
{
return 0LL;
}
++v0;
}
}
v3 = (unsigned int)ct_string_allocated_length(v10);
v4 = malloc(v3);
v5 = v4;
if ( v4 )
{
ct_string_finalize(v10, v4, 46LL);
fwrite(v5, 1uLL, v3, stdout);
putchar(10);
memset_s(&v8, 0LL, 8LL);
memset_s(v9, 0LL, 15LL);
memset_s(v5, 0LL, v3);
ct_string_deinit(v10);
free(v5);
return 1LL;
}
return 0LL;
}

original_code:
int showRandomWords(void)
{
    unsigned int words_added = 0;
    unsigned long random = 0;
    unsigned char word[15];
    uint32_t word_length = 0;
    ct_string str;
    ct_string_init(&str);
    while (words_added < 10) {
        if (!getRandomUnsignedLong(&random)) {
            return 0;
        }
        random = random & getLeastCoveringMask(7236 - 1);
        if (random < 7236) {
            word_length = lookup_word(word, random);
            if (words_added > 0) {
                if (!ct_string_concat(&str, (const unsigned char *)".", 1, 1)) {
                    return 0;
                }
            }
            if (!ct_string_concat(&str, word, 15, word_length)) {
                return 0;
            }
            words_added++;
        }
    }
    uint32_t total_length = ct_string_allocated_length(&str);
    unsigned char *final = malloc(total_length);
    if (final == ((void *)0)) {
        return 0;
    }
    ct_string_finalize(&str, final, '.');
    fwrite(final, sizeof(unsigned char), total_length, stdout);
    printf("\n");
    memset_s(&random, 0, sizeof(random));
    memset_s(word, 0, 15);
    memset_s(final, 0, total_length);
    ct_string_deinit(&str);
    free(final);
    return 1;
}

canonical_original_code:
int showRandomWords()
{
    unsigned int words_added = 0;
    unsigned long random = 0;
    unsigned char word[15];
    unsigned int word_length = 0;
    struct ConstantTimeString str;
    ct_string_init(&str);
    while (words_added < 10) {
        if (!getRandomUnsignedLong(&random)) {
            return 0;
        }
        random = random & getLeastCoveringMask(7236 - 1);
        if (random < 7236) {
            word_length = lookup_word(word, random);
            if (words_added > 0) {
                if (!ct_string_concat(&str, (unsigned char *)".", 1, 1)) {
                    return 0;
                }
            }
            if (!ct_string_concat(&str, word, 15, word_length)) {
                return 0;
            }
            words_added++;
        }
    }
    unsigned int total_length = ct_string_allocated_length(&str);
    unsigned char *final = malloc(total_length);
    if (final == ((void *)0)) {
        return 0;
    }
    ct_string_finalize(&str, final, '.');
    fwrite(final, sizeof(unsigned char), total_length, stdout);
    printf("\n");
    memset_s(&random, 0, sizeof(random));
    memset_s(word, 0, 15);
    memset_s(final, 0, total_length);
    ct_string_deinit(&str);
    free(final);
    return 1;
}

variable_types:
random
unsigned long

variable_types:
word
unsigned char [15]

variable_types: struct ConstantTimeString { unsigned int allocated_length; unsigned int actual_length; unsigned char *string; }

variable_types:
final
unsigned char *


runtimeTests

decompiled_code:
__int64 runtimeTests()
{
_BOOL4 v0; // er8
char *v1; // rax
unsigned int v2; // er12
unsigned __int64 v4; // rbx
__int64 v5; // rax
int v6; // edx
int v7; // ecx
char v8; // si
unsigned int v9; // eax
unsigned int v10; // eax
int v11; // er13
__int64 v12; // [rsp+8h] [rbp-F0h] BYREF
char ptr[16]; // [rsp+10h] [rbp-E8h] BYREF
char v14[16]; // [rsp+20h] [rbp-D8h] BYREF
char s1[32]; // [rsp+30h] [rbp-C8h] BYREF
char v16[3]; // [rsp+50h] [rbp-A8h] BYREF
char v17; // [rsp+53h] [rbp-A5h]
unsigned __int8 v18; // [rsp+CFh] [rbp-29h]

memset_s(ptr, 0LL, 16LL);
v0 = getRandom(ptr, 0x10uLL);
v1 = ptr;
if ( v0 )
{
while ( !*v1 )
{
if ( v14 == ++v1 )
return 0;
}
v12 = 0LL;
if ( getRandomUnsignedLong(&v12) )
{
if ( v12 )
{
v4 = getLeastCoveringMask(0LL);
if ( !v4
&& getLeastCoveringMask(1uLL) == 1
&& getLeastCoveringMask(2uLL) == 3
&& getLeastCoveringMask(3uLL) == 3
&& getLeastCoveringMask(4uLL) == 7
&& getLeastCoveringMask(5uLL) == 7
&& getLeastCoveringMask(6uLL) == 7
&& getLeastCoveringMask(7uLL) == 7
&& getLeastCoveringMask(8uLL) == 15
&& getLeastCoveringMask(0xFFuLL) == 255
&& getLeastCoveringMask(0xFFFFFFFFFFFFFFFFLL) == -1LL
&& getLeastCoveringMask(0xFFFFFFFFFFFFFFFELL) == -1LL )
{
getPassword((__int64)"AB", 2uLL, (__int64)v16, 0x80uLL);
v5 = 0LL;
v6 = 0;
v7 = 0;
do
{
v8 = v16[v5];
if ( v8 == 65 )
{
++v7;
}
else
{
if ( v8 != 66 )
return 0;
++v6;
}
++v5;
}
while ( v5 != 128 );
if ( v7 )
{
if ( v6 )
{
v16[0] = -1;
v17 = -1;
v18 = -1;
memset_s(v16, 0LL, 128LL);
if ( !(v18 | (unsigned __int8)(v17 | v16[0]))
&& (unsigned int)ct_eq_u32(0LL, 0LL) == 1
&& (unsigned int)ct_eq_u32(5LL, 5LL) == 1 )
{
v2 = ct_eq_u32(0x80000000LL, 0x80000000LL);
if ( v2 == 1
&& !(unsigned int)ct_eq_u32(0LL, 1LL)
&& !(unsigned int)ct_eq_u32(1LL, 0LL)
&& !(unsigned int)ct_eq_u32(2LL, 0LL)
&& !(unsigned int)ct_eq_u32(3LL, 0LL)
&& !(unsigned int)ct_eq_u32(1LL, 2LL)
&& !(unsigned int)ct_eq_u32(0x80000000LL, 0LL) )
{
v9 = ct_eq_u32(1LL, 1LL);
if ( (unsigned int)ct_mask_u32(v9) == -1 )
{
v10 = ct_eq_u32(1LL, 0LL);
if ( !(unsigned int)ct_mask_u32(v10) )
{
while ( 1 )
{
v11 = a0123456789Abcd[v4];
if ( v11 != (unsigned __int8)invariant_time_lookup(
"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
"`abcdefghijklmnopqrstuvwxyz{|}~",
94LL,
(unsigned int)v4) )
break;
if ( ++v4 == 94 )
{
ct_string_init(v14);
ct_string_concat(v14, "ABCDEF", 6LL, 3LL);
ct_string_concat(v14, "GHIJKL", 6LL, 3LL);
ct_string_concat(v14, "12345", 5LL, 5LL);
if ( (unsigned int)ct_string_allocated_length(v14) == 17 )
{
ct_string_finalize(v14, s1, 90LL);
if ( !memcmp(s1, "ABCGHI12345ZZZZZZ", 0x11uLL) )
{
ct_string_deinit(v14);
return v2;
}
}
return 0;
}
}
}
}
}
}
}
}
}
}
}
}
return 0;
}

canonical_decompiled_code:
__int64 func7()
{
_BOOL4 v0; // er8
char *v1; // rax
unsigned int v2; // er12
unsigned __int64 v4; // rbx
__int64 v5; // rax
int v6; // edx
int v7; // ecx
char v8; // si
unsigned int v9; // eax
unsigned int v10; // eax
int v11; // er13
__int64 v12; // [rsp+8h] [rbp-F0h] BYREF
char ptr[16]; // [rsp+10h] [rbp-E8h] BYREF
char v14[16]; // [rsp+20h] [rbp-D8h] BYREF
char s1[32]; // [rsp+30h] [rbp-C8h] BYREF
char v16[3]; // [rsp+50h] [rbp-A8h] BYREF
char v17; // [rsp+53h] [rbp-A5h]
unsigned __int8 v18; // [rsp+CFh] [rbp-29h]

memset_s(ptr, 0LL, 16LL);
v0 = func3(ptr, 0x10uLL);
v1 = ptr;
if ( v0 )
{
while ( !*v1 )
{
if ( v14 == ++v1 )
return 0;
}
v12 = 0LL;
if ( func5(&v12) )
{
if ( v12 )
{
v4 = func2(0LL);
if ( !v4
&& func2(1uLL) == 1
&& func2(2uLL) == 3
&& func2(3uLL) == 3
&& func2(4uLL) == 7
&& func2(5uLL) == 7
&& func2(6uLL) == 7
&& func2(7uLL) == 7
&& func2(8uLL) == 15
&& func2(0xFFuLL) == 255
&& func2(0xFFFFFFFFFFFFFFFFLL) == -1LL
&& func2(0xFFFFFFFFFFFFFFFELL) == -1LL )
{
func4((__int64)"AB", 2uLL, (__int64)v16, 0x80uLL);
v5 = 0LL;
v6 = 0;
v7 = 0;
do
{
v8 = v16[v5];
if ( v8 == 65 )
{
++v7;
}
else
{
if ( v8 != 66 )
return 0;
++v6;
}
++v5;
}
while ( v5 != 128 );
if ( v7 )
{
if ( v6 )
{
v16[0] = -1;
v17 = -1;
v18 = -1;
memset_s(v16, 0LL, 128LL);
if ( !(v18 | (unsigned __int8)(v17 | v16[0]))
&& (unsigned int)ct_eq_u32(0LL, 0LL) == 1
&& (unsigned int)ct_eq_u32(5LL, 5LL) == 1 )
{
v2 = ct_eq_u32(0x80000000LL, 0x80000000LL);
if ( v2 == 1
&& !(unsigned int)ct_eq_u32(0LL, 1LL)
&& !(unsigned int)ct_eq_u32(1LL, 0LL)
&& !(unsigned int)ct_eq_u32(2LL, 0LL)
&& !(unsigned int)ct_eq_u32(3LL, 0LL)
&& !(unsigned int)ct_eq_u32(1LL, 2LL)
&& !(unsigned int)ct_eq_u32(0x80000000LL, 0LL) )
{
v9 = ct_eq_u32(1LL, 1LL);
if ( (unsigned int)ct_mask_u32(v9) == -1 )
{
v10 = ct_eq_u32(1LL, 0LL);
if ( !(unsigned int)ct_mask_u32(v10) )
{
while ( 1 )
{
v11 = a0123456789Abcd[v4];
if ( v11 != (unsigned __int8)invariant_time_lookup(
"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
"`abcdefghijklmnopqrstuvwxyz{|}~",
94LL,
(unsigned int)v4) )
break;
if ( ++v4 == 94 )
{
ct_string_init(v14);
ct_string_concat(v14, "ABCDEF", 6LL, 3LL);
ct_string_concat(v14, "GHIJKL", 6LL, 3LL);
ct_string_concat(v14, "12345", 5LL, 5LL);
if ( (unsigned int)ct_string_allocated_length(v14) == 17 )
{
ct_string_finalize(v14, s1, 90LL);
if ( !memcmp(s1, "ABCGHI12345ZZZZZZ", 0x11uLL) )
{
ct_string_deinit(v14);
return v2;
}
}
return 0;
}
}
}
}
}
}
}
}
}
}
}
}
return 0;
}

original_code:
int runtimeTests(void)
{
    unsigned char buffer[16];
    memset_s(buffer, 0, sizeof(buffer));
    if (!getRandom(buffer, sizeof(buffer))) {
        return 0;
    }
    int all_zero = 1;
    for (size_t i = 0; i < sizeof(buffer); i++) {
        if (buffer[i] != 0) {
            all_zero = 0;
            break;
        }
    }
    if (all_zero) {
        return 0;
    }
    unsigned long test = 0;
    if (!getRandomUnsignedLong(&test)) {
        return 0;
    }
    if (test == 0) {
        return 0;
    }
    if (getLeastCoveringMask(0) != 0) { return 0; }
    if (getLeastCoveringMask(1) != 1) { return 0; }
    if (getLeastCoveringMask(2) != 3) { return 0; }
    if (getLeastCoveringMask(3) != 3) { return 0; }
    if (getLeastCoveringMask(4) != 7) { return 0; }
    if (getLeastCoveringMask(5) != 7) { return 0; }
    if (getLeastCoveringMask(6) != 7) { return 0; }
    if (getLeastCoveringMask(7) != 7) { return 0; }
    if (getLeastCoveringMask(8) != 15) { return 0; }
    if (getLeastCoveringMask(255) != 255) { return 0; }
    if (getLeastCoveringMask((0x7fffffffffffffffL * 2UL + 1UL)) != (0x7fffffffffffffffL * 2UL + 1UL)) { return 0; }
    if (getLeastCoveringMask((0x7fffffffffffffffL * 2UL + 1UL) - 1) != (0x7fffffffffffffffL * 2UL + 1UL)) { return 0; }
    unsigned char buffer2[128];
    getPassword("AB", 2, buffer2, sizeof(buffer2));
    unsigned int a_count = 0, b_count = 0;
    for (size_t i = 0; i < sizeof(buffer2); i++) {
        if (buffer2[i] == 'A') { a_count++; }
        else if (buffer2[i] == 'B') { b_count++; }
        else { return 0; }
    }
    if (a_count == 0 || b_count == 0) {
        return 0;
    }
    buffer2[0] = -1;
    buffer2[3] = -1;
    buffer2[127] = -1;
    memset_s(buffer2, 0, sizeof(buffer2));
    if (buffer2[0] != 0 || buffer2[3] != 0 || buffer2[127] != 0) {
        return 0;
    }
    if (ct_eq_u32(0, 0) != 1) { return 0; }
    if (ct_eq_u32(5, 5) != 1) { return 0; }
    if (ct_eq_u32(0x80000000u, 0x80000000u) != 1) { return 0; }
    if (ct_eq_u32(0, 1) != 0) { return 0; }
    if (ct_eq_u32(1, 0) != 0) { return 0; }
    if (ct_eq_u32(2, 0) != 0) { return 0; }
    if (ct_eq_u32(3, 0) != 0) { return 0; }
    if (ct_eq_u32(1, 2) != 0) { return 0; }
    if (ct_eq_u32(0x80000000u, 0) != 0) { return 0; }
    if (ct_mask_u32(ct_eq_u32(1, 1)) != (4294967295U)) { return 0; }
    if (ct_mask_u32(ct_eq_u32(1, 0)) != 0) { return 0; }
    const char *set = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
    for (size_t i = 0; i < strlen(set); i++) {
        if (set[i] != invariant_time_lookup((const unsigned char*)set, strlen(set), i)) {
            return 0;
        }
    }
    ct_string str;
    ct_string_init(&str);
    ct_string_concat(&str, (const unsigned char *)"ABCDEF", 6, 3);
    ct_string_concat(&str, (const unsigned char *)"GHIJKL", 6, 3);
    ct_string_concat(&str, (const unsigned char *)"12345", 5, 5);
    if (ct_string_allocated_length(&str) != 17) { return 0; }
    unsigned char str_result[17];
    ct_string_finalize(&str, str_result, 'Z');
    if (memcmp(str_result, "ABCGHI12345ZZZZZZ", 17) != 0) {
        return 0;
    }
    ct_string_deinit(&str);
    return 1;
}

canonical_original_code:
int runtimeTests()
{
    unsigned char buffer[16];
    memset_s(buffer, 0, sizeof(buffer));
    if (!getRandom(buffer, sizeof(buffer))) {
        return 0;
    }
    int all_zero = 1;
    for (unsigned long i = 0; i < sizeof(buffer); i++) {
        if (buffer[i] != 0) {
            all_zero = 0;
            break;
        }
    }
    if (all_zero) {
        return 0;
    }
    unsigned long test = 0;
    if (!getRandomUnsignedLong(&test)) {
        return 0;
    }
    if (test == 0) {
        return 0;
    }
    if (getLeastCoveringMask(0) != 0) { return 0; }
    if (getLeastCoveringMask(1) != 1) { return 0; }
    if (getLeastCoveringMask(2) != 3) { return 0; }
    if (getLeastCoveringMask(3) != 3) { return 0; }
    if (getLeastCoveringMask(4) != 7) { return 0; }
    if (getLeastCoveringMask(5) != 7) { return 0; }
    if (getLeastCoveringMask(6) != 7) { return 0; }
    if (getLeastCoveringMask(7) != 7) { return 0; }
    if (getLeastCoveringMask(8) != 15) { return 0; }
    if (getLeastCoveringMask(255) != 255) { return 0; }
    if (getLeastCoveringMask((0x7fffffffffffffffL * 2UL + 1UL)) != (0x7fffffffffffffffL * 2UL + 1UL)) { return 0; }
    if (getLeastCoveringMask((0x7fffffffffffffffL * 2UL + 1UL) - 1) != (0x7fffffffffffffffL * 2UL + 1UL)) { return 0; }
    unsigned char buffer2[128];
    getPassword("AB", 2, buffer2, sizeof(buffer2));
    unsigned int a_count = 0; unsigned int b_count = 0;
    for (unsigned long i = 0; i < sizeof(buffer2); i++) {
        if (buffer2[i] == 'A') { a_count++; }
        else if (buffer2[i] == 'B') { b_count++; }
        else { return 0; }
    }
    if (a_count == 0 || b_count == 0) {
        return 0;
    }
    buffer2[0] = -1;
    buffer2[3] = -1;
    buffer2[127] = -1;
    memset_s(buffer2, 0, sizeof(buffer2));
    if (buffer2[0] != 0 || buffer2[3] != 0 || buffer2[127] != 0) {
        return 0;
    }
    if (ct_eq_u32(0, 0) != 1) { return 0; }
    if (ct_eq_u32(5, 5) != 1) { return 0; }
    if (ct_eq_u32(0x80000000u, 0x80000000u) != 1) { return 0; }
    if (ct_eq_u32(0, 1) != 0) { return 0; }
    if (ct_eq_u32(1, 0) != 0) { return 0; }
    if (ct_eq_u32(2, 0) != 0) { return 0; }
    if (ct_eq_u32(3, 0) != 0) { return 0; }
    if (ct_eq_u32(1, 2) != 0) { return 0; }
    if (ct_eq_u32(0x80000000u, 0) != 0) { return 0; }
    if (ct_mask_u32(ct_eq_u32(1, 1)) != (4294967295U)) { return 0; }
    if (ct_mask_u32(ct_eq_u32(1, 0)) != 0) { return 0; }
    char *set = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
    for (unsigned long i = 0; i < strlen(set); i++) {
        if (set[i] != invariant_time_lookup((unsigned char *)set, strlen(set), i)) {
            return 0;
        }
    }
    struct ConstantTimeString str;
    ct_string_init(&str);
    ct_string_concat(&str, (unsigned char *)"ABCDEF", 6, 3);
    ct_string_concat(&str, (unsigned char *)"GHIJKL", 6, 3);
    ct_string_concat(&str, (unsigned char *)"12345", 5, 5);
    if (ct_string_allocated_length(&str) != 17) { return 0; }
    unsigned char str_result[17];
    ct_string_finalize(&str, str_result, 'Z');
    if (memcmp(str_result, "ABCGHI12345ZZZZZZ", 17) != 0) {
        return 0;
    }
    ct_string_deinit(&str);
    return 1;
}

variable_types:
buffer
unsigned char [16]

variable_types:
test
unsigned long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r15
int v4; // er14
int v5; // er13
int v6; // er12
int v7; // eax
int v9; // ebx
unsigned __int64 v10; // rax
int v11; // [rsp+Ch] [rbp-8Ch]
int v12; // [rsp+1Ch] [rbp-7Ch] BYREF
char ptr[120]; // [rsp+20h] [rbp-78h] BYREF

v4 = 0;
v5 = 0;
v6 = 0;
v12 = 1;
v11 = 0;
while ( 2 )
{
v7 = getopt_long(argc, (char *const *)argv, "hzxndlwap:", &long_options, 0LL);
if ( v7 != -1 )
{
switch ( v7 )
{
case 'a':
if ( v6 )
goto LABEL_7;
v6 = 1;
v3 = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
continue;
case 'd':
if ( v6 )
goto LABEL_7;
v6 = 1;
v3 = "0123456789";
continue;
case 'h':
showHelp();
return 0;
case 'l':
if ( v6 )
goto LABEL_7;
v6 = 1;
v3 = "abcdefghijklmnopqrstuvwxyz";
continue;
case 'n':
if ( v6 )
goto LABEL_7;
v6 = 1;
v3 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
continue;
case 'p':
if ( v4 )
goto LABEL_7;
v4 = _isoc99_sscanf(optarg, "%10d", &v12);
if ( v4 != 1 || v12 <= 0 )
goto LABEL_7;
continue;
case 'w':
if ( v6 )
goto LABEL_7;
v6 = 1;
v5 = 1;
continue;
case 'x':
if ( v6 )
goto LABEL_7;
v6 = 1;
v3 = "0123456789ABCDEF";
continue;
case 'z':
v11 = 1;
continue;
default:
goto LABEL_7;
}
}
break;
}
if ( v6 )
{
if ( v11 || (unsigned int)runtimeTests() )
{
v9 = 0;
if ( v5 )
{
while ( 1 )
{
if ( v12 <= v9 )
return 0;
if ( !(unsigned int)showRandomWords() )
break;
++v9;
}
fwrite("Error getting random data.\n", 1uLL, 0x1BuLL, stderr);
}
else
{
while ( v12 > v9 )
{
v10 = strlen(v3);
if ( !getPassword((__int64)v3, v10, (__int64)ptr, 0x40uLL) )
{
v5 = v6;
memset_s(ptr, 0LL, 64LL);
fwrite("Error getting random data or allocating memory.\n", 1uLL, 0x30uLL, stderr);
return v5;
}
++v9;
fwrite(ptr, 1uLL, 0x40uLL, stdout);
putchar(10);
memset_s(ptr, 0LL, 64LL);
}
}
}
else
{
v5 = v6;
fwrite("ERROR: Runtime self-tests failed. SOMETHING IS WRONG\n", 1uLL, 0x35uLL, stderr);
}
}
else
{
LABEL_7:
showHelp();
v5 = 1;
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r15
int v4; // er14
int v5; // er13
int v6; // er12
int v7; // eax
int v9; // ebx
unsigned __int64 v10; // rax
int v11; // [rsp+Ch] [rbp-8Ch]
int v12; // [rsp+1Ch] [rbp-7Ch] BYREF
char ptr[120]; // [rsp+20h] [rbp-78h] BYREF

v4 = 0;
v5 = 0;
v6 = 0;
v12 = 1;
v11 = 0;
while ( 2 )
{
v7 = getopt_long(argc, (char *const *)argv, "hzxndlwap:", &long_options, 0LL);
if ( v7 != -1 )
{
switch ( v7 )
{
case 'a':
if ( v6 )
goto LABEL_7;
v6 = 1;
v3 = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
continue;
case 'd':
if ( v6 )
goto LABEL_7;
v6 = 1;
v3 = "0123456789";
continue;
case 'h':
func0();
return 0;
case 'l':
if ( v6 )
goto LABEL_7;
v6 = 1;
v3 = "abcdefghijklmnopqrstuvwxyz";
continue;
case 'n':
if ( v6 )
goto LABEL_7;
v6 = 1;
v3 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
continue;
case 'p':
if ( v4 )
goto LABEL_7;
v4 = _isoc99_sscanf(optarg, "%10d", &v12);
if ( v4 != 1 || v12 <= 0 )
goto LABEL_7;
continue;
case 'w':
if ( v6 )
goto LABEL_7;
v6 = 1;
v5 = 1;
continue;
case 'x':
if ( v6 )
goto LABEL_7;
v6 = 1;
v3 = "0123456789ABCDEF";
continue;
case 'z':
v11 = 1;
continue;
default:
goto LABEL_7;
}
}
break;
}
if ( v6 )
{
if ( v11 || (unsigned int)func7() )
{
v9 = 0;
if ( v5 )
{
while ( 1 )
{
if ( v12 <= v9 )
return 0;
if ( !(unsigned int)func6() )
break;
++v9;
}
fwrite("Error getting random data.\n", 1uLL, 0x1BuLL, stderr);
}
else
{
while ( v12 > v9 )
{
v10 = strlen(v3);
if ( !func4((__int64)v3, v10, (__int64)ptr, 0x40uLL) )
{
v5 = v6;
memset_s(ptr, 0LL, 64LL);
fwrite("Error getting random data or allocating memory.\n", 1uLL, 0x30uLL, stderr);
return v5;
}
++v9;
fwrite(ptr, 1uLL, 0x40uLL, stdout);
putchar(10);
memset_s(ptr, 0LL, 64LL);
}
}
}
else
{
v5 = v6;
fwrite("ERROR: Runtime self-tests failed. SOMETHING IS WRONG\n", 1uLL, 0x35uLL, stderr);
}
}
else
{
LABEL_7:
func0();
v5 = 1;
}
return v5;
}

original_code:
int main(int argc, char* argv[])
{
    const char *set;
    int numberOfPasswords = 1;
    int generateWordPassword = 0;
    int skipSelfTest = 0;
    int optionCharacter = 0;
    int isPasswordTypeSet = 0;
    int isPasswordCountSet = 0;
    while((optionCharacter = getopt_long(argc, argv, "hzxndlwap:", long_options, ((void *)0))) != -1) {
            switch(optionCharacter)
            {
                case 'h':
                    showHelp();
                    return 0;
                case 'x':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    set = "0123456789ABCDEF";
                    isPasswordTypeSet = 1;
                    break;
                case 'n':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                    isPasswordTypeSet = 1;
                    break;
                case 'a':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    set = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
                    isPasswordTypeSet = 1;
                    break;
                case 'd':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    set = "0123456789";
                    isPasswordTypeSet = 1;
                    break;
                case 'l':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    set = "abcdefghijklmnopqrstuvwxyz";
                    isPasswordTypeSet = 1;
                    break;
                case 'w':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    generateWordPassword = 1;
                    isPasswordTypeSet = 1;
                    break;
                case 'p':
                    if (isPasswordCountSet) {
                        showHelp();
                        return 1;
                    }
                    if(sscanf(optarg, "%10d", &numberOfPasswords) == 1) {
                        if (numberOfPasswords <= 0) {
                            showHelp();
                            return 1;
                        }
                        isPasswordCountSet = 1;
                    } else {
                        showHelp();
                        return 1;
                    }
                    break;
                case 'z':
                    skipSelfTest = 1;
                    break;
                default:
                    showHelp();
                    return 1;
            }
    }
    if(!isPasswordTypeSet) {
        showHelp();
        return 1;
    }
    if (!skipSelfTest && !runtimeTests()) {
        fprintf(stderr, "ERROR: Runtime self-tests failed. SOMETHING IS WRONG\n");
        return 1;
    }
    if (generateWordPassword) {
        for (int i = 0; i < numberOfPasswords; i++) {
            if (!showRandomWords()) {
                fprintf(stderr, "Error getting random data.\n");
                return 1;
            }
        }
    } else {
        unsigned char result[64];
        for(int i = 0; i < numberOfPasswords; i++) {
            if(getPassword(set, strlen(set), result, 64)) {
                fwrite(result, sizeof(unsigned char), 64, stdout);
                printf("\n");
            } else {
                memset_s(result, 0, 64);
                fprintf(stderr, "Error getting random data or allocating memory.\n");
                return 1;
            }
            memset_s(result, 0, 64);
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *set;
    int numberOfPasswords = 1;
    int generateWordPassword = 0;
    int skipSelfTest = 0;
    int optionCharacter = 0;
    int isPasswordTypeSet = 0;
    int isPasswordCountSet = 0;
    while((optionCharacter = getopt_long(argc, argv, "hzxndlwap:", long_options, ((void *)0))) != -1) {
            switch(optionCharacter)
            {
                case 'h':
                    showHelp();
                    return 0;
                case 'x':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    set = "0123456789ABCDEF";
                    isPasswordTypeSet = 1;
                    break;
                case 'n':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                    isPasswordTypeSet = 1;
                    break;
                case 'a':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    set = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
                    isPasswordTypeSet = 1;
                    break;
                case 'd':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    set = "0123456789";
                    isPasswordTypeSet = 1;
                    break;
                case 'l':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    set = "abcdefghijklmnopqrstuvwxyz";
                    isPasswordTypeSet = 1;
                    break;
                case 'w':
                    if (isPasswordTypeSet) {
                        showHelp();
                        return 1;
                    }
                    generateWordPassword = 1;
                    isPasswordTypeSet = 1;
                    break;
                case 'p':
                    if (isPasswordCountSet) {
                        showHelp();
                        return 1;
                    }
                    if(sscanf(optarg, "%10d", &numberOfPasswords) == 1) {
                        if (numberOfPasswords <= 0) {
                            showHelp();
                            return 1;
                        }
                        isPasswordCountSet = 1;
                    } else {
                        showHelp();
                        return 1;
                    }
                    break;
                case 'z':
                    skipSelfTest = 1;
                    break;
                default:
                    showHelp();
                    return 1;
            }
    }
    if(!isPasswordTypeSet) {
        showHelp();
        return 1;
    }
    if (!skipSelfTest && !runtimeTests()) {
        fprintf(stderr, "ERROR: Runtime self-tests failed. SOMETHING IS WRONG\n");
        return 1;
    }
    if (generateWordPassword) {
        for (int i = 0; i < numberOfPasswords; i++) {
            if (!showRandomWords()) {
                fprintf(stderr, "Error getting random data.\n");
                return 1;
            }
        }
    } else {
        unsigned char result[64];
        for(int i = 0; i < numberOfPasswords; i++) {
            if(getPassword(set, strlen(set), result, 64)) {
                fwrite(result, sizeof(unsigned char), 64, stdout);
                printf("\n");
            } else {
                memset_s(result, 0, 64);
                fprintf(stderr, "Error getting random data or allocating memory.\n");
                return 1;
            }
            memset_s(result, 0, 64);
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
set
char *

variable_types: numberOfPasswords int

variable_types: generateWordPassword int

variable_types: skipSelfTest int

variable_types: optionCharacter int

variable_types: isPasswordTypeSet int

variable_types: isPasswordCountSet int

variable_types: i int

variable_types:
result
unsigned char [64]


repo: delan/guardbuffer

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
fputc(10, stderr);
while ( !feof(stdin) )
{
used += fread((void *)(used + 4210912), 1uLL, 0x10000 - used, stdin);
if ( used == 0x10000 )
{
fwrite(&buffer, 0x10000uLL, 1uLL, stdout);
++blocks;
bytes += used;
used = 0LL;
}
progress();
}
if ( used )
{
fwrite(&buffer, 1uLL, used, stdout);
bytes += used;
progress();
}
fflush(stdout);
fprintf(stderr, "\n%jd = %jd x %zu + %zu", bytes, blocks, 0x10000uLL, used);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
fputc(10, stderr);
while ( !feof(stdin) )
{
used += fread((void *)(used + 4210912), 1uLL, 0x10000 - used, stdin);
if ( used == 0x10000 )
{
fwrite(&buffer, 0x10000uLL, 1uLL, stdout);
++blocks;
bytes += used;
used = 0LL;
}
func8();
}
if ( used )
{
fwrite(&buffer, 1uLL, used, stdout);
bytes += used;
func8();
}
fflush(stdout);
fprintf(stderr, "\n%jd = %jd x %zu + %zu", bytes, blocks, 0x10000uLL, used);
return 0;
}

original_code:
int main(void) {
 fprintf(stderr, "\n");
 while (!feof(stdin)) {
  used += fread(buffer + used, 1, ((size_t) 65536) - used, stdin);
  if (used == ((size_t) 65536)) {
   fwrite(buffer, ((size_t) 65536), 1, stdout);
   bytes += used;
   used = 0;
   blocks++;
  }
  progress();
 }
 if (used) {
  fwrite(buffer, 1, used, stdout);
  bytes += used;
  progress();
 }
 fflush(stdout);
 fprintf(stderr, "\n%jd = %jd x %zu + %zu",
  bytes, blocks, ((size_t) 65536), used);
 return 0;
}

canonical_original_code:
int main() {
 fprintf(stderr, "\n");
 while (!feof(stdin)) {
  used += fread(buffer + used, 1, ((unsigned long) 65536) - used, stdin);
  if (used == ((unsigned long) 65536)) {
   fwrite(buffer, ((unsigned long) 65536), 1, stdout);
   bytes += used;
   used = 0;
   blocks++;
  }
  progress();
 }
 if (used) {
  fwrite(buffer, 1, used, stdout);
  bytes += used;
  progress();
 }
 fflush(stdout);
 fprintf(stderr, "\n%jd = %jd x %zu + %zu",
  bytes, blocks, ((unsigned long) 65536), used);
 return 0;
}


human

decompiled_code:
char *__fastcall human(unsigned __int64 a1)
{
unsigned __int64 v1; // rdx
int v2; // esi
unsigned __int64 v3; // rcx
__int64 v4; // r8

v1 = a1;
if ( a1 <= 0x3E7 )
{
v4 = 32LL;
}
else
{
v2 = 0;
do
{
v3 = v1;
++v2;
v1 /= 0x3E8uLL;
}
while ( v3 > 0xF423F );
v4 = (unsigned int)byte_402004[v2];
}
snprintf(out_3, 7uLL, "%llu %cB", v1, v4);
return out_3;
}

canonical_decompiled_code:
char *__fastcall func7(unsigned __int64 a1)
{
unsigned __int64 v1; // rdx
int v2; // esi
unsigned __int64 v3; // rcx
__int64 v4; // r8

v1 = a1;
if ( a1 <= 0x3E7 )
{
v4 = 32LL;
}
else
{
v2 = 0;
do
{
v3 = v1;
++v2;
v1 /= 0x3E8uLL;
}
while ( v3 > 0xF423F );
v4 = (unsigned int)byte_402004[v2];
}
snprintf(out_3, 7uLL, "%llu %cB", v1, v4);
return out_3;
}

original_code:
char *human(uint64_t bytes) {
 static const char *prefix = " kMGTPEZY";
 static char out[] = "999 YB";
 int i = 0;
 while (bytes >= 1000) {
  bytes /= 1000;
  i++;
 }
 snprintf(out, sizeof(out), "%" "ll" "u %cB",
  bytes, prefix[i]);
 return out;
}

canonical_original_code:
char *human(unsigned long bytes) {
 static char *prefix = " kMGTPEZY";
 static char out[] = "999 YB";
 int i = 0;
 while (bytes >= 1000) {
  bytes /= 1000;
  i++;
 }
 snprintf(out, sizeof(out), "%" "ll" "u %cB",
  bytes, prefix[i]);
 return out;
}

variable_types:
bytes
unsigned long

variable_types:
prefix
char *

variable_types:
out
char []

return_type: char *


progress

decompiled_code:
time_t progress()
{
time_t result; // rax
__int64 v1; // rbx
char *v2; // rax
char *v3; // rax

result = time(0LL);
v1 = result;
if ( (int)last_time_2 < (int)result )
{
v2 = human(bytes);
fprintf(stderr, "\r%jd s: %s @ ", ++elapsed_1, v2);
v3 = human(bytes - last_bytes_0);
fprintf(stderr, "%s/s ", v3);
result = bytes;
last_time_2 = v1;
last_bytes_0 = bytes;
}
else
{
last_time_2 = result;
}
return result;
}

canonical_decompiled_code:
time_t func8()
{
time_t result; // rax
__int64 v1; // rbx
char *v2; // rax
char *v3; // rax

result = time(0LL);
v1 = result;
if ( (int)last_time_2 < (int)result )
{
v2 = func7(bytes);
fprintf(stderr, "\r%jd s: %s @ ", ++elapsed_1, v2);
v3 = func7(bytes - last_bytes_0);
fprintf(stderr, "%s/s ", v3);
result = bytes;
last_time_2 = v1;
last_bytes_0 = bytes;
}
else
{
last_time_2 = result;
}
return result;
}

original_code:
void progress(void) {
 static time_t last_time;
 static intmax_t last_bytes;
 static intmax_t elapsed;
 time_t now = time(((void *)0));
 if ((int) now > (int) last_time) {
  fprintf(stderr, "\r%jd s: %s @ ", ++elapsed, human(bytes));
  fprintf(stderr, "%s/s    ", human(bytes - last_bytes));
  last_bytes = bytes;
 }
 last_time = now;
}

canonical_original_code:
void progress() {
 static long last_time;
 static long last_bytes;
 static long elapsed;
 long now = time(((void *)0));
 if ((int) now > (int) last_time) {
  fprintf(stderr, "\r%jd s: %s @ ", ++elapsed, human(bytes));
  fprintf(stderr, "%s/s    ", human(bytes - last_bytes));
  last_bytes = bytes;
 }
 last_time = now;
}

variable_types: elapsed long

variable_types: now long


repo: delan/hdid

decompiled_code:
int __fastcall hdid_print(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, __int64 a10, __int64 a11, unsigned int a12)
{
printf("Manufacturer: %s\n", *((const char **)&hdid_man_list + (unsigned int)a7));
printf("Product family: %s\n", *((const char **)&hdid_family_list + a12));
printf("Spindle speed: %d rpm\n", HIDWORD(a7));
printf("Nominal capacity: %f GB\n", (float)((float)(int)a8 / 1000.0));
printf("Interface: %s\n", *((const char **)&hdid_interface_list + (unsigned int)a9));
printf("Form factor: %s\n", *((const char **)&hdid_form_list + HIDWORD(a9)));
printf("Sector size: %d B\n", (unsigned int)a10);
printf("Cache size: %ld MiB\n", a11 >> 20);
return printf("Platters: %d\n", HIDWORD(a10));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, __int64 a10, __int64 a11, unsigned int a12)
{
printf("Manufacturer: %s\n", *((const char **)&hdid_man_list + (unsigned int)a7));
printf("Product family: %s\n", *((const char **)&hdid_family_list + a12));
printf("Spindle speed: %d rpm\n", HIDWORD(a7));
printf("Nominal capacity: %f GB\n", (float)((float)(int)a8 / 1000.0));
printf("Interface: %s\n", *((const char **)&hdid_interface_list + (unsigned int)a9));
printf("Form factor: %s\n", *((const char **)&hdid_form_list + HIDWORD(a9)));
printf("Sector size: %d B\n", (unsigned int)a10);
printf("Cache size: %ld MiB\n", a11 >> 20);
return printf("Platters: %d\n", HIDWORD(a10));
}

original_code:
void hdid_print(struct hdid_info info) {
 printf(
  "Manufacturer:           %s\n",
  hdid_man_list[info.manufacturer]
 );
 printf(
  "Product family:         %s\n",
  hdid_family_list[info.family]
 );
 printf(
  "Spindle speed:          %d rpm\n",
  info.spindle_rpm
 );
 printf(
  "Nominal capacity:       %f GB\n",
  (float) info.nominal_megabytes / 1000
 );
 printf(
  "Interface:              %s\n",
  hdid_interface_list[info.interface]
 );
 printf(
  "Form factor:            %s\n",
  hdid_form_list[info.form]
 );
 printf(
  "Sector size:            %d B\n",
  info.sector_bytes
 );
 printf(
  "Cache size:             %ld MiB\n",
  info.cache_bytes >> 20
 );
 printf(
  "Platters:               %d\n",
  info.platters
 );
}

variable_types: struct hdid_info { enum hdid_man_t { HDID_MAN_UNKNOWN=0, HDID_MAN_WD=1, HDID_MAN_SEAGATE=2, HDID_MAN_MAXTOR=3, HDID_MAN_SAMSUNG=4, HDID_MAN_HITACHI=5, HDID_MAN_TOSHIBA=6, HDID_MAN_CONNER=7, HDID_MAN_QUANTUM=8, HDID_MAN_IBM=9 } manufacturer; int spindle_rpm; long nominal_megabytes; enum hdid_interface_t { HDID_INTERFACE_UNKNOWN=0, HDID_INTERFACE_ATA33=1, HDID_INTERFACE_ATA66=2, HDID_INTERFACE_ATA100=3, HDID_INTERFACE_ATA133=4, HDID_INTERFACE_SATA1=5, HDID_INTERFACE_SATA2=6, HDID_INTERFACE_SATA3=7, HDID_INTERFACE_FIREWIRE=8, HDID_INTERFACE_CFPLUS2=9, HDID_INTERFACE_SAS10=10, HDID_INTERFACE_SAS11=11, HDID_INTERFACE_SAS20=12, HDID_INTERFACE_SAS30=13, HDID_INTERFACE_ZIF33=14 } interface; enum hdid_form_t { HDID_FORM_UNKNOWN=0, HDID_FORM_100=1, HDID_FORM_180=2, HDID_FORM_180_50=3, HDID_FORM_180_80=4, HDID_FORM_250=5, HDID_FORM_250_50=6, HDID_FORM_250_70=7, HDID_FORM_250_95=8, HDID_FORM_250_125=9, HDID_FORM_250_150=10, HDID_FORM_350=11, HDID_FORM_350_190=12, HDID_FORM_350_254=13, HDID_FORM_525=14, HDID_FORM_525_414=15, HDID_FORM_525_826=16, HDID_FORM_800=17, HDID_FORM_800_1175=18, HDID_FORM_CF_33=19, HDID_FORM_CF_50=20, HDID_FORM_250_350_INCORRECT=21, HDID_FORM_250_350_CORRECT=22 } form; int sector_bytes; int platters; long cache_bytes; enum hdid_family_t { HDID_FAMILY_UNKNOWN=0, HDID_FAMILY_WD_DESKTOP=1, HDID_FAMILY_WD_RE=2, HDID_FAMILY_WD_RAPTOR=3, HDID_FAMILY_WD_RAPTORX=4, HDID_FAMILY_WD_MOBILE=5, HDID_FAMILY_WD_NAS=6, HDID_FAMILY_WD_VR=7, HDID_FAMILY_WD_XE=8, HDID_FAMILY_WD_S25=9, HDID_FAMILY_WD_BRAND=10, HDID_FAMILY_WD_AV=11, HDID_FAMILY_WD_SERVER=12, HDID_FAMILY_WD_PROTEGE=13 } family; }

user_defined_types: struct hdid_info { enum hdid_man_t manufacturer; int spindle_rpm; long nominal_megabytes; enum hdid_interface_t interface; enum hdid_form_t form; int sector_bytes; int platters; long cache_bytes; enum hdid_family_t family; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int64 v4; // rcx
_DWORD *v5; // rsi
__int64 *v6; // rdi
__int64 v7; // [rsp-30h] [rbp-68h] BYREF
_BYTE v8[56]; // [rsp+0h] [rbp-38h] BYREF

if ( argc == 2 )
{
hdid_identify(v8, argv[1], envp);
v4 = 12LL;
v5 = v8;
v6 = &v7;
while ( v4 )
{
*(_DWORD *)v6 = *v5++;
v6 = (__int64 *)((char *)v6 + 4);
--v4;
}
hdid_print(v6, v5);
result = 0;
}
else
{
fprintf(stderr, "Usage: %s [HDD model]\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv) {
 if (argc != 2) {
  fprintf(stderr, "Usage: %s [HDD model]\n", argv[0]);
  return 1;
 }
 hdid_print(hdid_identify(argv[1]));
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


original_code:
void hdid_wd_2005_oem_internal(struct hdid_info *info, const char *model) {
 const char *suffix = hdid_wd_suffix(model);
 info->nominal_megabytes = atoi(model + 2) * 100;
 info->sector_bytes = 512;
 switch (suffix[0]) {
 case 'A':
  info->spindle_rpm = 5400;
  break;
 case 'B':
  info->spindle_rpm = 7200;
  info->cache_bytes = 2097152;
  break;
 case 'C':
  info->spindle_rpm = 10000;
  break;
 case 'D':
  info->spindle_rpm = 4500;
  break;
 case 'E':
  info->spindle_rpm = 5400;
  info->platters = 1;
  break;
 case 'F':
  info->spindle_rpm = 10000;
  info->cache_bytes = 2097152;
  break;
 case 'G':
  info->spindle_rpm = 10000;
  info->cache_bytes = 8388608;
  break;
 case 'H':
  info->spindle_rpm = 10000;
  info->cache_bytes = 4194304;
  break;
 case 'J':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  break;
 case 'K':
  info->spindle_rpm = 7200;
  info->cache_bytes = 16777216;
  info->family = HDID_FAMILY_WD_DESKTOP;
  break;
 case 'L':
  info->spindle_rpm = 7200;
  break;
 case 'M':
  info->spindle_rpm = 5400;
  break;
 case 'N':
  info->spindle_rpm = 5400;
  info->family = HDID_FAMILY_WD_PROTEGE;
  break;
 case 'P':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  break;
 case 'R':
  info->spindle_rpm = 10000;
  info->cache_bytes = 8388608;
  break;
 case 'S':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  info->family = HDID_FAMILY_WD_SERVER;
  break;
 case 'T':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  info->family = HDID_FAMILY_WD_SERVER;
  break;
 case 'U':
  info->spindle_rpm = 5400;
  info->cache_bytes = 2097152;
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'V':
  info->spindle_rpm = 5400;
  info->cache_bytes = 8388608;
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'W':
  info->spindle_rpm = 3600;
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'X':
  info->spindle_rpm = 4200;
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'Y':
  info->spindle_rpm = 7200;
  info->cache_bytes = 16777216;
  info->family = HDID_FAMILY_WD_SERVER;
  break;
 case 'Z':
  info->spindle_rpm = 7200;
  info->cache_bytes = 2097152;
  break;
 }
 switch (suffix[1]) {
 case 'A':
  info->interface = HDID_INTERFACE_ATA66;
  info->form = HDID_FORM_350_254;
  break;
 case 'B':
  info->interface = HDID_INTERFACE_ATA100;
  info->form = HDID_FORM_350_254;
  break;
 case 'C':
  info->interface = HDID_INTERFACE_FIREWIRE;
  info->form = HDID_FORM_350_254;
  break;
 case 'D':
  info->interface = HDID_INTERFACE_SATA1;
  info->form = HDID_FORM_350_254;
  break;
 case 'E':
  info->interface = HDID_INTERFACE_ATA133;
  info->form = HDID_FORM_350_254;
  break;
 case 'P':
  info->interface = HDID_INTERFACE_CFPLUS2;
  info->form = HDID_FORM_CF_50;
  break;
 case 'R':
 case 'S':
  info->interface = HDID_INTERFACE_SATA2;
  info->form = HDID_FORM_350_254;
  break;
 case 'W':
  info->form = HDID_FORM_350_254;
  break;
 }
}

canonical_original_code:
void hdid_wd_2005_oem_internal(struct hdid_info *info, char *model) {
 char *suffix = hdid_wd_suffix(model);
 info->nominal_megabytes = atoi(model + 2) * 100;
 info->sector_bytes = 512;
 switch (suffix[0]) {
 case 'A':
  info->spindle_rpm = 5400;
  break;
 case 'B':
  info->spindle_rpm = 7200;
  info->cache_bytes = 2097152;
  break;
 case 'C':
  info->spindle_rpm = 10000;
  break;
 case 'D':
  info->spindle_rpm = 4500;
  break;
 case 'E':
  info->spindle_rpm = 5400;
  info->platters = 1;
  break;
 case 'F':
  info->spindle_rpm = 10000;
  info->cache_bytes = 2097152;
  break;
 case 'G':
  info->spindle_rpm = 10000;
  info->cache_bytes = 8388608;
  break;
 case 'H':
  info->spindle_rpm = 10000;
  info->cache_bytes = 4194304;
  break;
 case 'J':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  break;
 case 'K':
  info->spindle_rpm = 7200;
  info->cache_bytes = 16777216;
  info->family = HDID_FAMILY_WD_DESKTOP;
  break;
 case 'L':
  info->spindle_rpm = 7200;
  break;
 case 'M':
  info->spindle_rpm = 5400;
  break;
 case 'N':
  info->spindle_rpm = 5400;
  info->family = HDID_FAMILY_WD_PROTEGE;
  break;
 case 'P':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  break;
 case 'R':
  info->spindle_rpm = 10000;
  info->cache_bytes = 8388608;
  break;
 case 'S':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  info->family = HDID_FAMILY_WD_SERVER;
  break;
 case 'T':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  info->family = HDID_FAMILY_WD_SERVER;
  break;
 case 'U':
  info->spindle_rpm = 5400;
  info->cache_bytes = 2097152;
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'V':
  info->spindle_rpm = 5400;
  info->cache_bytes = 8388608;
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'W':
  info->spindle_rpm = 3600;
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'X':
  info->spindle_rpm = 4200;
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'Y':
  info->spindle_rpm = 7200;
  info->cache_bytes = 16777216;
  info->family = HDID_FAMILY_WD_SERVER;
  break;
 case 'Z':
  info->spindle_rpm = 7200;
  info->cache_bytes = 2097152;
  break;
 }
 switch (suffix[1]) {
 case 'A':
  info->interface = HDID_INTERFACE_ATA66;
  info->form = HDID_FORM_350_254;
  break;
 case 'B':
  info->interface = HDID_INTERFACE_ATA100;
  info->form = HDID_FORM_350_254;
  break;
 case 'C':
  info->interface = HDID_INTERFACE_FIREWIRE;
  info->form = HDID_FORM_350_254;
  break;
 case 'D':
  info->interface = HDID_INTERFACE_SATA1;
  info->form = HDID_FORM_350_254;
  break;
 case 'E':
  info->interface = HDID_INTERFACE_ATA133;
  info->form = HDID_FORM_350_254;
  break;
 case 'P':
  info->interface = HDID_INTERFACE_CFPLUS2;
  info->form = HDID_FORM_CF_50;
  break;
 case 'R':
 case 'S':
  info->interface = HDID_INTERFACE_SATA2;
  info->form = HDID_FORM_350_254;
  break;
 case 'W':
  info->form = HDID_FORM_350_254;
  break;
 }
}

variable_types: struct hdid_info { enum hdid_man_t { HDID_MAN_UNKNOWN=0, HDID_MAN_WD=1, HDID_MAN_SEAGATE=2, HDID_MAN_MAXTOR=3, HDID_MAN_SAMSUNG=4, HDID_MAN_HITACHI=5, HDID_MAN_TOSHIBA=6, HDID_MAN_CONNER=7, HDID_MAN_QUANTUM=8, HDID_MAN_IBM=9 } manufacturer; int spindle_rpm; long nominal_megabytes; enum hdid_interface_t { HDID_INTERFACE_UNKNOWN=0, HDID_INTERFACE_ATA33=1, HDID_INTERFACE_ATA66=2, HDID_INTERFACE_ATA100=3, HDID_INTERFACE_ATA133=4, HDID_INTERFACE_SATA1=5, HDID_INTERFACE_SATA2=6, HDID_INTERFACE_SATA3=7, HDID_INTERFACE_FIREWIRE=8, HDID_INTERFACE_CFPLUS2=9, HDID_INTERFACE_SAS10=10, HDID_INTERFACE_SAS11=11, HDID_INTERFACE_SAS20=12, HDID_INTERFACE_SAS30=13, HDID_INTERFACE_ZIF33=14 } interface; enum hdid_form_t { HDID_FORM_UNKNOWN=0, HDID_FORM_100=1, HDID_FORM_180=2, HDID_FORM_180_50=3, HDID_FORM_180_80=4, HDID_FORM_250=5, HDID_FORM_250_50=6, HDID_FORM_250_70=7, HDID_FORM_250_95=8, HDID_FORM_250_125=9, HDID_FORM_250_150=10, HDID_FORM_350=11, HDID_FORM_350_190=12, HDID_FORM_350_254=13, HDID_FORM_525=14, HDID_FORM_525_414=15, HDID_FORM_525_826=16, HDID_FORM_800=17, HDID_FORM_800_1175=18, HDID_FORM_CF_33=19, HDID_FORM_CF_50=20, HDID_FORM_250_350_INCORRECT=21, HDID_FORM_250_350_CORRECT=22 } form; int sector_bytes; int platters; long cache_bytes; enum hdid_family_t { HDID_FAMILY_UNKNOWN=0, HDID_FAMILY_WD_DESKTOP=1, HDID_FAMILY_WD_RE=2, HDID_FAMILY_WD_RAPTOR=3, HDID_FAMILY_WD_RAPTORX=4, HDID_FAMILY_WD_MOBILE=5, HDID_FAMILY_WD_NAS=6, HDID_FAMILY_WD_VR=7, HDID_FAMILY_WD_XE=8, HDID_FAMILY_WD_S25=9, HDID_FAMILY_WD_BRAND=10, HDID_FAMILY_WD_AV=11, HDID_FAMILY_WD_SERVER=12, HDID_FAMILY_WD_PROTEGE=13 } family; } *

variable_types:
model
char *

variable_types:
suffix
char *


original_code:
void hdid_wd_new_oem_internal(struct hdid_info *info, const char *model) {
 int raw_capacity = atoi(model + 2);
 const char *suffix = hdid_wd_suffix(model);
 if (raw_capacity >= 1000)
  raw_capacity = raw_capacity / 10 * 10;
 switch (suffix[0]) {
 case 'A':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_350_254;
  break;
 case 'B':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250;
  break;
 case 'C':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250;
  break;
 case 'D':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250_350_CORRECT;
  break;
 case 'E':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_350_254;
  break;
 case 'F':
  info->nominal_megabytes = raw_capacity * 1000;
  info->form = HDID_FORM_350_254;
  break;
 case 'G':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_350_INCORRECT;
  break;
 case 'H':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_350_CORRECT;
  break;
 case 'J':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250;
  break;
 case 'K':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_125;
  break;
 case 'L':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_70;
  break;
 case 'N':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250_150;
  break;
 case 'S':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250_70;
  break;
 case 'T':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250_125;
  break;
 }
 switch (suffix[1]) {
 case 'A':
  info->family = HDID_FAMILY_WD_DESKTOP;
  info->sector_bytes = 512;
  break;
 case 'B':
  info->family = HDID_FAMILY_WD_RE;
  info->sector_bytes = 512;
  info->platters = 3;
  break;
 case 'D':
  info->family = HDID_FAMILY_WD_RAPTOR;
  info->sector_bytes = 512;
  break;
 case 'E':
  info->family = HDID_FAMILY_WD_MOBILE;
  info->sector_bytes = 512;
  break;
 case 'F':
  info->family = HDID_FAMILY_WD_NAS;
  info->sector_bytes = 4096;
  break;
 case 'H':
  info->family = HDID_FAMILY_WD_VR;
  info->sector_bytes = 512;
  break;
 case 'K':
  info->family = HDID_FAMILY_WD_XE;
  info->sector_bytes = 512;
  break;
 case 'L':
  info->family = HDID_FAMILY_WD_VR;
  info->sector_bytes = 512;
  break;
 case 'M':
  info->family = HDID_FAMILY_WD_BRAND;
  info->sector_bytes = 512;
  break;
 case 'N':
  info->family = HDID_FAMILY_WD_BRAND;
  info->sector_bytes = 4096;
  break;
 case 'P':
  info->family = HDID_FAMILY_WD_MOBILE;
  info->sector_bytes = 4096;
  break;
 case 'R':
  info->family = HDID_FAMILY_WD_RE;
  info->sector_bytes = 4096;
  break;
 case 'U':
  info->family = HDID_FAMILY_WD_AV;
  info->sector_bytes = 4096;
  break;
 case 'V':
  info->family = HDID_FAMILY_WD_AV;
  info->sector_bytes = 512;
  break;
 case 'W':
  info->family = HDID_FAMILY_WD_VR;
  info->sector_bytes = 4096;
  break;
 case 'Y':
  info->family = HDID_FAMILY_WD_RE;
  info->sector_bytes = 512;
  info->platters = 4;
  break;
 case 'Z':
  info->family = HDID_FAMILY_WD_DESKTOP;
  info->sector_bytes = 4096;
  break;
 }
 switch (suffix[2]) {
 case 'A':
  info->spindle_rpm = 5400;
  info->cache_bytes = 2097152;
  break;
 case 'B':
  info->spindle_rpm = 7200;
  info->cache_bytes = 2097152;
  break;
 case 'C':
  info->spindle_rpm = 5400;
  info->cache_bytes = 16777216;
  break;
 case 'D':
  info->spindle_rpm = 5400;
  info->cache_bytes = 33554432;
  break;
 case 'E':
  info->spindle_rpm = 7200;
  info->cache_bytes = 67108864;
  break;
 case 'F':
  info->spindle_rpm = 10000;
  info->cache_bytes = 16777216;
  break;
 case 'G':
  info->spindle_rpm = 10000;
  info->cache_bytes = 8388608;
  break;
 case 'H':
  info->spindle_rpm = 10000;
  info->cache_bytes = 33554432;
  break;
 case 'J':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  break;
 case 'K':
  info->spindle_rpm = 7200;
  info->cache_bytes = 16777216;
  break;
 case 'L':
  info->spindle_rpm = 7200;
  info->cache_bytes = 33554432;
  break;
 case 'P':
  info->spindle_rpm = 5400;
  break;
 case 'R':
  info->spindle_rpm = 5400;
  info->cache_bytes = 67108864;
  break;
 case 'S':
  info->spindle_rpm = 7200;
  info->cache_bytes = 67108864;
  break;
 case 'T':
  info->spindle_rpm = 10000;
  break;
 case 'V':
  info->spindle_rpm = 5400;
  info->cache_bytes = 8388608;
  break;
 case 'Y':
  info->spindle_rpm = 7200;
  break;
 }
 switch (suffix[3]) {
 case 'A':
  info->interface = HDID_INTERFACE_ATA66;
  break;
 case 'B':
  info->interface = HDID_INTERFACE_ATA100;
  break;
 case 'C':
  info->interface = HDID_INTERFACE_ZIF33;
  break;
 case 'D':
  info->interface = HDID_INTERFACE_SATA1;
  break;
 case 'E':
  info->interface = HDID_INTERFACE_ATA133;
  break;
 case 'F':
  info->interface = HDID_INTERFACE_SAS11;
  break;
 case 'G':
  info->interface = HDID_INTERFACE_SAS20;
  break;
 case 'S':
  if (info->family == HDID_FAMILY_WD_MOBILE)
   info->interface = HDID_INTERFACE_SATA1;
  else
   info->interface = HDID_INTERFACE_SATA2;
  break;
 case 'T':
  info->interface = HDID_INTERFACE_SATA2;
  break;
 case 'X':
  info->interface = HDID_INTERFACE_SATA3;
  break;
 case 'Z':
  info->interface = HDID_INTERFACE_SATA3;
  break;
 }
}

canonical_original_code:
void hdid_wd_new_oem_internal(struct hdid_info *info, char *model) {
 int raw_capacity = atoi(model + 2);
 char *suffix = hdid_wd_suffix(model);
 if (raw_capacity >= 1000)
  raw_capacity = raw_capacity / 10 * 10;
 switch (suffix[0]) {
 case 'A':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_350_254;
  break;
 case 'B':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250;
  break;
 case 'C':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250;
  break;
 case 'D':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250_350_CORRECT;
  break;
 case 'E':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_350_254;
  break;
 case 'F':
  info->nominal_megabytes = raw_capacity * 1000;
  info->form = HDID_FORM_350_254;
  break;
 case 'G':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_350_INCORRECT;
  break;
 case 'H':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_350_CORRECT;
  break;
 case 'J':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250;
  break;
 case 'K':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_125;
  break;
 case 'L':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_70;
  break;
 case 'N':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250_150;
  break;
 case 'S':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250_70;
  break;
 case 'T':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250_125;
  break;
 }
 switch (suffix[1]) {
 case 'A':
  info->family = HDID_FAMILY_WD_DESKTOP;
  info->sector_bytes = 512;
  break;
 case 'B':
  info->family = HDID_FAMILY_WD_RE;
  info->sector_bytes = 512;
  info->platters = 3;
  break;
 case 'D':
  info->family = HDID_FAMILY_WD_RAPTOR;
  info->sector_bytes = 512;
  break;
 case 'E':
  info->family = HDID_FAMILY_WD_MOBILE;
  info->sector_bytes = 512;
  break;
 case 'F':
  info->family = HDID_FAMILY_WD_NAS;
  info->sector_bytes = 4096;
  break;
 case 'H':
  info->family = HDID_FAMILY_WD_VR;
  info->sector_bytes = 512;
  break;
 case 'K':
  info->family = HDID_FAMILY_WD_XE;
  info->sector_bytes = 512;
  break;
 case 'L':
  info->family = HDID_FAMILY_WD_VR;
  info->sector_bytes = 512;
  break;
 case 'M':
  info->family = HDID_FAMILY_WD_BRAND;
  info->sector_bytes = 512;
  break;
 case 'N':
  info->family = HDID_FAMILY_WD_BRAND;
  info->sector_bytes = 4096;
  break;
 case 'P':
  info->family = HDID_FAMILY_WD_MOBILE;
  info->sector_bytes = 4096;
  break;
 case 'R':
  info->family = HDID_FAMILY_WD_RE;
  info->sector_bytes = 4096;
  break;
 case 'U':
  info->family = HDID_FAMILY_WD_AV;
  info->sector_bytes = 4096;
  break;
 case 'V':
  info->family = HDID_FAMILY_WD_AV;
  info->sector_bytes = 512;
  break;
 case 'W':
  info->family = HDID_FAMILY_WD_VR;
  info->sector_bytes = 4096;
  break;
 case 'Y':
  info->family = HDID_FAMILY_WD_RE;
  info->sector_bytes = 512;
  info->platters = 4;
  break;
 case 'Z':
  info->family = HDID_FAMILY_WD_DESKTOP;
  info->sector_bytes = 4096;
  break;
 }
 switch (suffix[2]) {
 case 'A':
  info->spindle_rpm = 5400;
  info->cache_bytes = 2097152;
  break;
 case 'B':
  info->spindle_rpm = 7200;
  info->cache_bytes = 2097152;
  break;
 case 'C':
  info->spindle_rpm = 5400;
  info->cache_bytes = 16777216;
  break;
 case 'D':
  info->spindle_rpm = 5400;
  info->cache_bytes = 33554432;
  break;
 case 'E':
  info->spindle_rpm = 7200;
  info->cache_bytes = 67108864;
  break;
 case 'F':
  info->spindle_rpm = 10000;
  info->cache_bytes = 16777216;
  break;
 case 'G':
  info->spindle_rpm = 10000;
  info->cache_bytes = 8388608;
  break;
 case 'H':
  info->spindle_rpm = 10000;
  info->cache_bytes = 33554432;
  break;
 case 'J':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  break;
 case 'K':
  info->spindle_rpm = 7200;
  info->cache_bytes = 16777216;
  break;
 case 'L':
  info->spindle_rpm = 7200;
  info->cache_bytes = 33554432;
  break;
 case 'P':
  info->spindle_rpm = 5400;
  break;
 case 'R':
  info->spindle_rpm = 5400;
  info->cache_bytes = 67108864;
  break;
 case 'S':
  info->spindle_rpm = 7200;
  info->cache_bytes = 67108864;
  break;
 case 'T':
  info->spindle_rpm = 10000;
  break;
 case 'V':
  info->spindle_rpm = 5400;
  info->cache_bytes = 8388608;
  break;
 case 'Y':
  info->spindle_rpm = 7200;
  break;
 }
 switch (suffix[3]) {
 case 'A':
  info->interface = HDID_INTERFACE_ATA66;
  break;
 case 'B':
  info->interface = HDID_INTERFACE_ATA100;
  break;
 case 'C':
  info->interface = HDID_INTERFACE_ZIF33;
  break;
 case 'D':
  info->interface = HDID_INTERFACE_SATA1;
  break;
 case 'E':
  info->interface = HDID_INTERFACE_ATA133;
  break;
 case 'F':
  info->interface = HDID_INTERFACE_SAS11;
  break;
 case 'G':
  info->interface = HDID_INTERFACE_SAS20;
  break;
 case 'S':
  if (info->family == HDID_FAMILY_WD_MOBILE)
   info->interface = HDID_INTERFACE_SATA1;
  else
   info->interface = HDID_INTERFACE_SATA2;
  break;
 case 'T':
  info->interface = HDID_INTERFACE_SATA2;
  break;
 case 'X':
  info->interface = HDID_INTERFACE_SATA3;
  break;
 case 'Z':
  info->interface = HDID_INTERFACE_SATA3;
  break;
 }
}

user_defined_types: enum hdid_man_t { HDID_MAN_UNKNOWN=0, HDID_MAN_WD=1, HDID_MAN_SEAGATE=2, HDID_MAN_MAXTOR=3, HDID_MAN_SAMSUNG=4, HDID_MAN_HITACHI=5, HDID_MAN_TOSHIBA=6, HDID_MAN_CONNER=7, HDID_MAN_QUANTUM=8, HDID_MAN_IBM=9 }

user_defined_types: enum hdid_interface_t { HDID_INTERFACE_UNKNOWN=0, HDID_INTERFACE_ATA33=1, HDID_INTERFACE_ATA66=2, HDID_INTERFACE_ATA100=3, HDID_INTERFACE_ATA133=4, HDID_INTERFACE_SATA1=5, HDID_INTERFACE_SATA2=6, HDID_INTERFACE_SATA3=7, HDID_INTERFACE_FIREWIRE=8, HDID_INTERFACE_CFPLUS2=9, HDID_INTERFACE_SAS10=10, HDID_INTERFACE_SAS11=11, HDID_INTERFACE_SAS20=12, HDID_INTERFACE_SAS30=13, HDID_INTERFACE_ZIF33=14 }

user_defined_types: enum hdid_family_t { HDID_FAMILY_UNKNOWN=0, HDID_FAMILY_WD_DESKTOP=1, HDID_FAMILY_WD_RE=2, HDID_FAMILY_WD_RAPTOR=3, HDID_FAMILY_WD_RAPTORX=4, HDID_FAMILY_WD_MOBILE=5, HDID_FAMILY_WD_NAS=6, HDID_FAMILY_WD_VR=7, HDID_FAMILY_WD_XE=8, HDID_FAMILY_WD_S25=9, HDID_FAMILY_WD_BRAND=10, HDID_FAMILY_WD_AV=11, HDID_FAMILY_WD_SERVER=12, HDID_FAMILY_WD_PROTEGE=13 }


original_code:
void hdid_wd_2009_retail_internal(struct hdid_info *info, const char *model) {
 int raw_capacity = atoi(model + 2);
 const char *suffix = hdid_wd_suffix(model);
 if (raw_capacity >= 1000)
  raw_capacity = raw_capacity / 10 * 10;
 switch (suffix[0]) {
 case 'A':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_350_254;
  break;
 case 'B':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250;
  break;
 case 'C':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_100;
  break;
 case 'E':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_350_254;
  break;
 case 'F':
  info->nominal_megabytes = raw_capacity * 1000;
  info->form = HDID_FORM_350_254;
  break;
 case 'G':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_350_INCORRECT;
  break;
 case 'H':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_350_CORRECT;
  break;
 case 'J':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250;
  break;
 }
 switch (suffix[1]) {
 case 'A':
  info->family = HDID_FAMILY_WD_DESKTOP;
  break;
 case 'B':
  info->family = HDID_FAMILY_WD_RE;
  info->platters = 3;
  break;
 case 'C':
  info->family = HDID_FAMILY_WD_PROTEGE;
  break;
 case 'D':
  info->family = HDID_FAMILY_WD_RAPTOR;
  break;
 case 'E':
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'H':
  info->family = HDID_FAMILY_WD_RAPTORX;
  break;
 case 'J':
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'K':
  info->family = HDID_FAMILY_WD_S25;
  break;
 case 'L':
  info->family = HDID_FAMILY_WD_VR;
  break;
 case 'M':
  info->family = HDID_FAMILY_WD_BRAND;
  break;
 case 'V':
  info->family = HDID_FAMILY_WD_AV;
  break;
 case 'Y':
  info->family = HDID_FAMILY_WD_RE;
  info->platters = 4;
  break;
 }
 switch (suffix[2]) {
 case 'A':
  info->spindle_rpm = 5400;
  info->cache_bytes = 2097152;
  break;
 case 'B':
  info->spindle_rpm = 7200;
  info->cache_bytes = 2097152;
  break;
 case 'C':
  info->spindle_rpm = 5400;
  info->cache_bytes = 16777216;
  break;
 case 'D':
  info->spindle_rpm = 5400;
  info->cache_bytes = 33554432;
  break;
 case 'F':
  info->spindle_rpm = 10000;
  info->cache_bytes = 16777216;
  break;
 case 'G':
  info->spindle_rpm = 10000;
  info->cache_bytes = 8388608;
  break;
 case 'H':
  info->spindle_rpm = 10000;
  info->cache_bytes = 33554432;
  break;
 case 'J':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  break;
 case 'K':
  info->spindle_rpm = 7200;
  info->cache_bytes = 16777216;
  break;
 case 'L':
  info->spindle_rpm = 7200;
  info->cache_bytes = 33554432;
  break;
 case 'P':
  info->spindle_rpm = 5400;
  break;
 case 'V':
  info->spindle_rpm = 5400;
  info->cache_bytes = 8388608;
  break;
 case 'Y':
  info->spindle_rpm = 7200;
  break;
 }
 switch (suffix[3]) {
 case 'A':
  info->interface = HDID_INTERFACE_ATA66;
  break;
 case 'B':
  info->interface = HDID_INTERFACE_ATA100;
  break;
 case 'C':
  info->interface = HDID_INTERFACE_ZIF33;
  break;
 case 'D':
  info->interface = HDID_INTERFACE_SATA1;
  break;
 case 'E':
  info->interface = HDID_INTERFACE_ATA133;
  break;
 case 'F':
  info->interface = HDID_INTERFACE_SAS11;
  break;
 case 'G':
  info->interface = HDID_INTERFACE_SAS20;
  break;
 case 'S':
  if (info->family == HDID_FAMILY_WD_MOBILE)
   info->interface = HDID_INTERFACE_SATA1;
  else
   info->interface = HDID_INTERFACE_SATA2;
  break;
 case 'T':
  info->interface = HDID_INTERFACE_SATA2;
  break;
 }
}

canonical_original_code:
void hdid_wd_2009_retail_internal(struct hdid_info *info, char *model) {
 int raw_capacity = atoi(model + 2);
 char *suffix = hdid_wd_suffix(model);
 if (raw_capacity >= 1000)
  raw_capacity = raw_capacity / 10 * 10;
 switch (suffix[0]) {
 case 'A':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_350_254;
  break;
 case 'B':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250;
  break;
 case 'C':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_100;
  break;
 case 'E':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_350_254;
  break;
 case 'F':
  info->nominal_megabytes = raw_capacity * 1000;
  info->form = HDID_FORM_350_254;
  break;
 case 'G':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_350_INCORRECT;
  break;
 case 'H':
  info->nominal_megabytes = raw_capacity * 100;
  info->form = HDID_FORM_250_350_CORRECT;
  break;
 case 'J':
  info->nominal_megabytes = raw_capacity * 100000;
  info->form = HDID_FORM_250;
  break;
 }
 switch (suffix[1]) {
 case 'A':
  info->family = HDID_FAMILY_WD_DESKTOP;
  break;
 case 'B':
  info->family = HDID_FAMILY_WD_RE;
  info->platters = 3;
  break;
 case 'C':
  info->family = HDID_FAMILY_WD_PROTEGE;
  break;
 case 'D':
  info->family = HDID_FAMILY_WD_RAPTOR;
  break;
 case 'E':
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'H':
  info->family = HDID_FAMILY_WD_RAPTORX;
  break;
 case 'J':
  info->family = HDID_FAMILY_WD_MOBILE;
  break;
 case 'K':
  info->family = HDID_FAMILY_WD_S25;
  break;
 case 'L':
  info->family = HDID_FAMILY_WD_VR;
  break;
 case 'M':
  info->family = HDID_FAMILY_WD_BRAND;
  break;
 case 'V':
  info->family = HDID_FAMILY_WD_AV;
  break;
 case 'Y':
  info->family = HDID_FAMILY_WD_RE;
  info->platters = 4;
  break;
 }
 switch (suffix[2]) {
 case 'A':
  info->spindle_rpm = 5400;
  info->cache_bytes = 2097152;
  break;
 case 'B':
  info->spindle_rpm = 7200;
  info->cache_bytes = 2097152;
  break;
 case 'C':
  info->spindle_rpm = 5400;
  info->cache_bytes = 16777216;
  break;
 case 'D':
  info->spindle_rpm = 5400;
  info->cache_bytes = 33554432;
  break;
 case 'F':
  info->spindle_rpm = 10000;
  info->cache_bytes = 16777216;
  break;
 case 'G':
  info->spindle_rpm = 10000;
  info->cache_bytes = 8388608;
  break;
 case 'H':
  info->spindle_rpm = 10000;
  info->cache_bytes = 33554432;
  break;
 case 'J':
  info->spindle_rpm = 7200;
  info->cache_bytes = 8388608;
  break;
 case 'K':
  info->spindle_rpm = 7200;
  info->cache_bytes = 16777216;
  break;
 case 'L':
  info->spindle_rpm = 7200;
  info->cache_bytes = 33554432;
  break;
 case 'P':
  info->spindle_rpm = 5400;
  break;
 case 'V':
  info->spindle_rpm = 5400;
  info->cache_bytes = 8388608;
  break;
 case 'Y':
  info->spindle_rpm = 7200;
  break;
 }
 switch (suffix[3]) {
 case 'A':
  info->interface = HDID_INTERFACE_ATA66;
  break;
 case 'B':
  info->interface = HDID_INTERFACE_ATA100;
  break;
 case 'C':
  info->interface = HDID_INTERFACE_ZIF33;
  break;
 case 'D':
  info->interface = HDID_INTERFACE_SATA1;
  break;
 case 'E':
  info->interface = HDID_INTERFACE_ATA133;
  break;
 case 'F':
  info->interface = HDID_INTERFACE_SAS11;
  break;
 case 'G':
  info->interface = HDID_INTERFACE_SAS20;
  break;
 case 'S':
  if (info->family == HDID_FAMILY_WD_MOBILE)
   info->interface = HDID_INTERFACE_SATA1;
  else
   info->interface = HDID_INTERFACE_SATA2;
  break;
 case 'T':
  info->interface = HDID_INTERFACE_SATA2;
  break;
 }
}


decompiled_code:
size_t __fastcall hdid_identify_wd(_DWORD *a1, __int64 a2)
{
size_t result; // rax
const char *v3; // rax
bool v4; // cf

*a1 = 1;
result = (unsigned int)(*(char *)(a2 + 2) - 49);
if ( (unsigned int)result <= 8 )
{
v3 = hdid_wd_suffix(a2);
result = strlen(v3);
if ( result == 4 )
{
result = hdid_wd_new_oem_internal((__int64)a1, a2);
}
else if ( result > 4 )
{
v4 = result == 8;
result -= 8LL;
if ( v4 || result == 1 )
result = hdid_wd_2009_retail_internal((__int64)a1, a2);
}
else if ( result == 2 )
{
result = hdid_wd_2005_oem_internal((__int64)a1, a2);
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(_DWORD *a1, __int64 a2)
{
size_t result; // rax
const char *v3; // rax
bool v4; // cf

*a1 = 1;
result = (unsigned int)(*(char *)(a2 + 2) - 49);
if ( (unsigned int)result <= 8 )
{
v3 = hdid_wd_suffix(a2);
result = strlen(v3);
if ( result == 4 )
{
result = func1((__int64)a1, a2);
}
else if ( result > 4 )
{
v4 = result == 8;
result -= 8LL;
if ( v4 || result == 1 )
result = func2((__int64)a1, a2);
}
else if ( result == 2 )
{
result = func0((__int64)a1, a2);
}
}
return result;
}

original_code:
void hdid_identify_wd(struct hdid_info *info, const char *model) {
 const char *suffix;
 info->manufacturer = HDID_MAN_WD;
 switch (model[2]) {
 case '1':
 case '2':
 case '3':
 case '4':
 case '5':
 case '6':
 case '7':
 case '8':
 case '9':
  suffix = hdid_wd_suffix(model);
  switch (strlen(suffix)) {
  case 2:
   hdid_wd_2005_oem_internal(info, model);
   break;
  case 4:
   hdid_wd_new_oem_internal(info, model);
   break;
  case 8:
  case 9:
   hdid_wd_2009_retail_internal(info, model);
   break;
  }
 case 'A':
 case 'B':
 case 'C':
 case 'E':
 case 'F':
 case 'G':
 case 'H':
 case 'M':
 case 'P':
 case 'Q':
 case 'S':
 case 'T':
 case 'U':
 case 'X':
  break;
 }
}

canonical_original_code:
void hdid_identify_wd(struct hdid_info *info, char *model) {
 char *suffix;
 info->manufacturer = HDID_MAN_WD;
 switch (model[2]) {
 case '1':
 case '2':
 case '3':
 case '4':
 case '5':
 case '6':
 case '7':
 case '8':
 case '9':
  suffix = hdid_wd_suffix(model);
  switch (strlen(suffix)) {
  case 2:
   hdid_wd_2005_oem_internal(info, model);
   break;
  case 4:
   hdid_wd_new_oem_internal(info, model);
   break;
  case 8:
  case 9:
   hdid_wd_2009_retail_internal(info, model);
   break;
  }
 case 'A':
 case 'B':
 case 'C':
 case 'E':
 case 'F':
 case 'G':
 case 'H':
 case 'M':
 case 'P':
 case 'Q':
 case 'S':
 case 'T':
 case 'U':
 case 'X':
  break;
 }
}


decompiled_code:
char *__fastcall hdid_minstr(char *src, size_t a2)
{
size_t v2; // rbp
size_t v3; // r12
char *v4; // rax

v2 = a2;
v3 = strlen(src);
if ( v3 >= a2 )
v2 = v3 + 1;
v4 = (char *)calloc(v2, 1uLL);
return strncpy(v4, src, v3);
}

canonical_decompiled_code:
char *__fastcall func0(char *src, size_t a2)
{
size_t v2; // rbp
size_t v3; // r12
char *v4; // rax

v2 = a2;
v3 = strlen(src);
if ( v3 >= a2 )
v2 = v3 + 1;
v4 = (char *)calloc(v2, 1uLL);
return strncpy(v4, src, v3);
}

original_code:
char *hdid_minstr(const char *in, size_t min) {
 size_t len = strlen(in);
 char *out = calloc(
  len < min ? min : len + 1,
  sizeof(char)
 );
 strncpy(out, in, len);
 return out;
}

canonical_original_code:
char *hdid_minstr(char *in, unsigned long min) {
 unsigned long len = strlen(in);
 char *out = calloc(
  len < min ? min : len + 1,
  sizeof(char)
 );
 strncpy(out, in, len);
 return out;
}

variable_types:
in
char *

variable_types:
min
unsigned long

variable_types:
len
unsigned long

variable_types:
out
char *


repo: delan/ucpcal

decompiled_code:
void *ucpcal_event_new()
{
return calloc(0x30uLL, 1uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(0x30uLL, 1uLL);
}

original_code:
ucpcal_event *ucpcal_event_new(void) {
 ucpcal_event *event = (ucpcal_event *) calloc(sizeof(ucpcal_event), 1);
 event->name = ((void *)0);
 event->location = ((void *)0);
 return event;
}

canonical_original_code:
struct ucpcal_event *ucpcal_event_new() {
 struct ucpcal_event *event = (ucpcal_event *) calloc(sizeof(ucpcal_event), 1);
 event->name = ((void *)0);
 event->location = ((void *)0);
 return event;
}

variable_types: struct ucpcal_event { struct ucpcal_date { int good; int year; int month; int day; int hour; int minute; } date; unsigned int duration; char *name; char *location; } *

user_defined_types: struct ucpcal_event { struct ucpcal_date date; unsigned int duration; char *name; char *location; }


decompiled_code:
void __fastcall ucpcal_event_free(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}
}

original_code:
void ucpcal_event_free(ucpcal_event *event) {
 if (event) {
  free(event->name);
  free(event->location);
  free(event);
 }
}

canonical_original_code:
void ucpcal_event_free(struct ucpcal_event *event) {
 if (event) {
  free(event->name);
  free(event->location);
  free(event);
 }
}

user_defined_types: struct ucpcal_date { int good; int year; int month; int day; int hour; int minute; }


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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
ucpcal_node *ucpcal_node_new(void) {
 ucpcal_node *node = (ucpcal_node *) malloc(sizeof(ucpcal_node));
 node->event = ((void *)0);
 node->next = ((void *)0);
 return node;
}

canonical_original_code:
struct ucpcal_node *ucpcal_node_new() {
 struct ucpcal_node *node = (ucpcal_node *) malloc(sizeof(ucpcal_node));
 node->event = ((void *)0);
 node->next = ((void *)0);
 return node;
}

variable_types: struct ucpcal_node { struct ucpcal_event { struct ucpcal_date { int good; int year; int month; int day; int hour; int minute; } date; unsigned int duration; char *name; char *location; } *event; struct ucpcal_node *next; } *

user_defined_types: struct ucpcal_node { struct ucpcal_event *event; struct ucpcal_node *next; }


decompiled_code:
void __fastcall ucpcal_node_free(void *ptr)
{
ucpcal_event_free(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
ucpcal_event_free(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void ucpcal_node_free(ucpcal_node *node) {
 ucpcal_event_free(node->event);
 free(node);
}

canonical_original_code:
void ucpcal_node_free(struct ucpcal_node *node) {
 ucpcal_event_free(node->event);
 free(node);
}


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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
ucpcal_list *ucpcal_list_new(void) {
 ucpcal_list *list = (ucpcal_list *) malloc(sizeof(ucpcal_list));
 list->head = ((void *)0);
 list->tail = ((void *)0);
 return list;
}

canonical_original_code:
struct ucpcal_list *ucpcal_list_new() {
 struct ucpcal_list *list = (ucpcal_list *) malloc(sizeof(ucpcal_list));
 list->head = ((void *)0);
 list->tail = ((void *)0);
 return list;
}

variable_types: struct ucpcal_list { struct ucpcal_node { struct ucpcal_event { struct ucpcal_date { int good; int year; int month; int day; int hour; int minute; } date; unsigned int duration; char *name; char *location; } *event; struct ucpcal_node *next; } *head; struct ucpcal_node *tail; } *

user_defined_types: struct ucpcal_list { struct ucpcal_node *head; struct ucpcal_node *tail; }


decompiled_code:
void __fastcall ucpcal_list_delete(__int64 a1, const char *a2)
{
_QWORD *v2; // rbp
_QWORD *v3; // rbx
int v4; // er8
__int64 v5; // rax

v2 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v3 = 0LL;
while ( 1 )
{
v4 = strcmp(*(const char **)(*v2 + 32LL), a2);
v5 = v2[1];
if ( !v4 )
break;
v3 = v2;
if ( !v5 )
return;
v2 = (_QWORD *)v2[1];
}
if ( v3 )
v3[1] = v5;
else
*(_QWORD *)a1 = v5;
if ( *(_QWORD **)(a1 + 8) == v2 )
*(_QWORD *)(a1 + 8) = v3;
ucpcal_node_free(v2);
}
}

original_code:
void ucpcal_list_delete(ucpcal_list *list, const char *name) {
 ucpcal_node *cur = list->head, *prev = ((void *)0);
 int done = 0;
 while (cur && !done) {
  if (!strcmp(cur->event->name, name)) {
   if (prev)
    prev->next = cur->next;
   else
    list->head = cur->next;
   if (cur == list->tail)
    list->tail = prev;
   ucpcal_node_free(cur);
   done = 1;
  }
  if (!done) {
   prev = cur;
   cur = cur->next;
  }
 }
}

canonical_original_code:
void ucpcal_list_delete(struct ucpcal_list *list, char *name) {
 struct ucpcal_node *cur = list->head; struct ucpcal_node *prev = ((void *)0);
 int done = 0;
 while (cur && !done) {
  if (!strcmp(cur->event->name, name)) {
   if (prev)
    prev->next = cur->next;
   else
    list->head = cur->next;
   if (cur == list->tail)
    list->tail = prev;
   ucpcal_node_free(cur);
   done = 1;
  }
  if (!done) {
   prev = cur;
   cur = cur->next;
  }
 }
}

variable_types:
name
char *

variable_types: done int


decompiled_code:
__int64 __fastcall ucpcal_list_find(_QWORD **a1, const char *a2)
{
_QWORD *v2; // rbx
__int64 v3; // r12

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = *v2;
if ( !strcmp(*(const char **)(*v2 + 32LL), a2) )
break;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD **a1, const char *a2)
{
_QWORD *v2; // rbx
__int64 v3; // r12

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = *v2;
if ( !strcmp(*(const char **)(*v2 + 32LL), a2) )
break;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
return v3;
}

original_code:
ucpcal_event *ucpcal_list_find(ucpcal_list *list, const char *name) {
 ucpcal_node *cur = list->head;
 ucpcal_event *result = ((void *)0);
 int done = 0;
 while (cur && !done) {
  if (!strcmp(cur->event->name, name)) {
   result = cur->event;
   done = 1;
  }
  cur = cur->next;
 }
 return result;
}

canonical_original_code:
struct ucpcal_event *ucpcal_list_find(struct ucpcal_list *list, char *name) {
 struct ucpcal_node *cur = list->head;
 struct ucpcal_event *result = ((void *)0);
 int done = 0;
 while (cur && !done) {
  if (!strcmp(cur->event->name, name)) {
   result = cur->event;
   done = 1;
  }
  cur = cur->next;
 }
 return result;
}

variable_types: struct ucpcal_list { struct ucpcal_node { struct ucpcal_event *event; struct ucpcal_node *next; } *head; struct ucpcal_node *tail; } *

return_type: struct ucpcal_event { struct ucpcal_date { int good; int year; int month; int day; int hour; int minute; } date; unsigned int duration; char *name; char *location; } *


decompiled_code:
void __fastcall ucpcal_list_free(void *ptr)
{
ucpcal_list_empty(ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
func5(ptr);
free(ptr);
}

original_code:
void ucpcal_list_free(ucpcal_list *list) {
 ucpcal_list_empty(list);
 free(list);
}

canonical_original_code:
void ucpcal_list_free(struct ucpcal_list *list) {
 ucpcal_list_empty(list);
 free(list);
}


freeCallback

decompiled_code:
// attributes: thunk
void freeCallback(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

original_code:
static void freeCallback(gpointer data, GClosure *closure)
{
    free(data);
}

canonical_original_code:
static void freeCallback(void *data, struct _GClosure *closure)
{
    free(data);
}

variable_types:
data
void *

variable_types: struct _GClosure { unsigned int ref_count; unsigned int meta_marshal_nouse; unsigned int n_guards; unsigned int n_fnotifiers; unsigned int n_inotifiers; unsigned int in_inotify; unsigned int floating; unsigned int derivative_flag; unsigned int in_marshal; unsigned int is_invalid; void (*marshal)(struct _GClosure *closure, struct _GValue { unsigned long g_type; union { int v_int; unsigned int v_uint; long v_long; unsigned long v_ulong; long v_int64; unsigned long v_uint64; float v_float; double v_double; void *v_pointer; } data[2]; } *return_value, unsigned int n_param_values, struct _GValue *param_values, void *invocation_hint, void *marshal_data); void *data; struct _GClosureNotifyData { void *data; void (*notify)(void *data, struct _GClosure *closure); } *notifiers; } *

user_defined_types: struct _GClosure { unsigned int ref_count; unsigned int meta_marshal_nouse; unsigned int n_guards; unsigned int n_fnotifiers; unsigned int n_inotifiers; unsigned int in_inotify; unsigned int floating; unsigned int derivative_flag; unsigned int in_marshal; unsigned int is_invalid; void (*marshal)(struct _GClosure *closure, struct _GValue *return_value, unsigned int n_param_values, struct _GValue *param_values, void *invocation_hint, void *marshal_data); void *data; struct _GClosureNotifyData *notifiers; }


freeWindow

decompiled_code:
// attributes: thunk
void freeWindow(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func5(void *ptr)
{
free(ptr);
}

original_code:
void freeWindow(Window *window)
{
    free(window);
}

canonical_original_code:
void freeWindow(struct Window *window)
{
    free(window);
}

variable_types: struct Window { void *gtkWindow; void *buttonBox; void *textBuffer; } *


decompiled_code:
char *__fastcall ucpcal_duration_friendly(unsigned int a1)
{
unsigned __int64 v1; // rdx
__int64 v2; // r8
const char *v3; // rcx
const char *v4; // r9
char *result; // rax
const char *v6; // rcx
const char *v7; // rcx

v1 = a1 / 0x3CuLL;
v2 = a1 % 0x3C;
if ( (_DWORD)v1 && (_DWORD)v2 )
{
v3 = (const char *)&unk_2EF;
v4 = "s";
if ( (_DWORD)v2 == 1 )
v4 = (const char *)&unk_2EF;
if ( (_DWORD)v1 != 1 )
v3 = "s";
sprintf(result_2, "%u hour%s, %u minute%s", v1, v3, v2, v4);
result = result_2;
}
else if ( a1 <= 0x3B )
{
v7 = (const char *)&unk_2EF;
if ( (_DWORD)v2 != 1 )
v7 = "s";
sprintf(result_2, "%u minute%s", (unsigned int)v2, v7);
result = result_2;
}
else
{
v6 = (const char *)&unk_2EF;
if ( (_DWORD)v1 != 1 )
v6 = "s";
sprintf(result_2, "%u hour%s", v1, v6, v2);
result = result_2;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1)
{
unsigned __int64 v1; // rdx
__int64 v2; // r8
const char *v3; // rcx
const char *v4; // r9
char *result; // rax
const char *v6; // rcx
const char *v7; // rcx

v1 = a1 / 0x3CuLL;
v2 = a1 % 0x3C;
if ( (_DWORD)v1 && (_DWORD)v2 )
{
v3 = (const char *)&unk_2EF;
v4 = "s";
if ( (_DWORD)v2 == 1 )
v4 = (const char *)&unk_2EF;
if ( (_DWORD)v1 != 1 )
v3 = "s";
sprintf(result_2, "%u hour%s, %u minute%s", v1, v3, v2, v4);
result = result_2;
}
else if ( a1 <= 0x3B )
{
v7 = (const char *)&unk_2EF;
if ( (_DWORD)v2 != 1 )
v7 = "s";
sprintf(result_2, "%u minute%s", (unsigned int)v2, v7);
result = result_2;
}
else
{
v6 = (const char *)&unk_2EF;
if ( (_DWORD)v1 != 1 )
v6 = "s";
sprintf(result_2, "%u hour%s", v1, v6, v2);
result = result_2;
}
return result;
}

original_code:
const char *ucpcal_duration_friendly(unsigned int minutes) {
 static char result[64] = "";
 int output_hours = minutes / 60;
 int output_minutes = minutes % 60;
 if (output_hours != 0 && output_minutes != 0)
  sprintf(
   result,
   "%u hour%s, %u minute%s",
   output_hours,
   output_hours == 1 ? "" : "s",
   output_minutes,
   output_minutes == 1 ? "" : "s"
  );
 else if (output_hours != 0)
  sprintf(
   result,
   "%u hour%s",
   output_hours,
   output_hours == 1 ? "" : "s"
  );
 else
  sprintf(
   result,
   "%u minute%s",
   output_minutes,
   output_minutes == 1 ? "" : "s"
  );
 return result;
}

variable_types:
minutes
unsigned int

variable_types:
result
char [64]