decompiled_code:
int __fastcall print_perm(char *a1, int a2)
{
char *v2; // rbx
char *v3; // rax
int result; // eax

if ( a1 )
{
if ( a2 > 0 )
{
v2 = a1;
do
{
printf("%c ", (unsigned int)*v2);
v3 = v2++;
}
while ( v3 != &a1[a2 - 1] );
}
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(char *a1, int a2)
{
char *v2; // rbx
char *v3; // rax
int result; // eax

if ( a1 )
{
if ( a2 > 0 )
{
v2 = a1;
do
{
printf("%c ", (unsigned int)*v2);
v3 = v2++;
}
while ( v3 != &a1[a2 - 1] );
}
result = putchar(10);
}
return result;
}

original_code:
void print_perm(const char *v, const int size)
{
  int i = 0;
  if (v != 0) {
    for (i = 0; i < size; i++) {
      printf("%c ", v[i] );
    }
    printf("\n");
  }
}

canonical_original_code:
void print_perm(char *v, int size)
{
  int i = 0;
  if (v != 0) {
    for (i = 0; i < size; i++) {
      printf("%c ", v[i] );
    }
    printf("\n");
  }
}

variable_types:
v
char *

variable_types: size int


permute

repo: justinethier/rosalind

decompiled_code:
int __fastcall permute(char *a1, int a2, int a3)
{
int result; // eax
char *v5; // rbp
unsigned __int8 *v6; // rbx
__int64 v7; // r15
unsigned __int8 v8; // r12

result = a3 - 1;
if ( a3 - 1 == a2 )
return print_perm(a1, a3);
if ( a3 > a2 )
{
v5 = &a1[a2];
v6 = (unsigned __int8 *)v5;
v7 = (__int64)&v5[a3 - a2 - 1 + 1];
do
{
v8 = *v6;
*v6 = *v5;
*v5 = v8;
permute(a1, (unsigned int)(a2 + 1), (unsigned int)a3);
result = *v6;
*v5 = result;
*v6++ = v8;
}
while ( v6 != (unsigned __int8 *)v7 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *a1, int a2, int a3)
{
int result; // eax
char *v5; // rbp
unsigned __int8 *v6; // rbx
__int64 v7; // r15
unsigned __int8 v8; // r12

result = a3 - 1;
if ( a3 - 1 == a2 )
return func8(a1, a3);
if ( a3 > a2 )
{
v5 = &a1[a2];
v6 = (unsigned __int8 *)v5;
v7 = (__int64)&v5[a3 - a2 - 1 + 1];
do
{
v8 = *v6;
*v6 = *v5;
*v5 = v8;
func9(a1, (unsigned int)(a2 + 1), (unsigned int)a3);
result = *v6;
*v5 = result;
*v6++ = v8;
}
while ( v6 != (unsigned __int8 *)v7 );
}
return result;
}

original_code:
void permute(char *v, const int start, const int n)
{
  int i;
  if (start == n-1) {
    print_perm(v, n);
  }
  else {
    for (i = start; i < n; i++) {
      char tmp = v[i];
      v[i] = v[start];
      v[start] = tmp;
      permute(v, start+1, n);
      v[start] = v[i];
      v[i] = tmp;
    }
  }
}

canonical_original_code:
void permute(char *v, int start, int n)
{
  int i;
  if (start == n-1) {
    print_perm(v, n);
  }
  else {
    for (i = start; i < n; i++) {
      char tmp = v[i];
      v[i] = v[start];
      v[start] = tmp;
      permute(v, start+1, n);
      v[start] = v[i];
      v[i] = tmp;
    }
  }
}

variable_types: start int

variable_types: n int

variable_types: i int

variable_types: tmp char

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // eax
unsigned int v5; // eax
int v6; // eax
_BYTE v8[7]; // [rsp+7h] [rbp-11h] BYREF
char nptr[2]; // [rsp+Eh] [rbp-Ah] BYREF

strcpy(nptr, "3");
v3 = nptr;
if ( argc > 1 )
v3 = (char *)argv[1];
v4 = atoi(v3);
v5 = num_perm(v4);
printf("%d\n", v5);
qmemcpy(v8, "1234567", sizeof(v8));
v6 = atoi(v3);
permute(v8, 0, v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // eax
unsigned int v5; // eax
int v6; // eax
_BYTE v8[7]; // [rsp+7h] [rbp-11h] BYREF
char nptr[2]; // [rsp+Eh] [rbp-Ah] BYREF

strcpy(nptr, "3");
v3 = nptr;
if ( argc > 1 )
v3 = (char *)argv[1];
v4 = atoi(v3);
v5 = func7(v4);
printf("%d\n", v5);
qmemcpy(v8, "1234567", sizeof(v8));
v6 = atoi(v3);
func9(v8, 0, v6);
return 0;
}

original_code:
int main(int argc, char **argv){
    char sample[] = "3";
    char *data = sample;
    int num;
    if (argc > 1){
        data = argv[1];
    }
    num = num_perm( atoi(data) );
    printf("%d\n", num);
    char v[] = {'1', '2', '3', '4', '5', '6', '7'};
    permute(v, 0, atoi(data));
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
sample
char []

variable_types:
data
char *

variable_types: num int

variable_types:
v
char []

return_type: int


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

result = 84LL;
if ( (_BYTE)a1 != 65 )
{
result = 65LL;
if ( (_BYTE)a1 != 84 )
{
result = 71LL;
if ( (_BYTE)a1 != 67 )
{
result = 67LL;
if ( (_BYTE)a1 != 71 )
result = a1;
}
}
}
return result;
}

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

result = 84LL;
if ( (_BYTE)a1 != 65 )
{
result = 65LL;
if ( (_BYTE)a1 != 84 )
{
result = 71LL;
if ( (_BYTE)a1 != 67 )
{
result = 67LL;
if ( (_BYTE)a1 != 71 )
result = a1;
}
}
}
return result;
}

original_code:
char dna_complement(char dna)
{
    if (dna == 'A') dna = 'T';
    else if (dna == 'T') dna = 'A';
    else if (dna == 'C') dna = 'G';
    else if (dna == 'G') dna = 'C';
    return dna;
}

variable_types: dna char

return_type: char


decompiled_code:
char *__fastcall dna_reverse_complement(char *src)
{
int v1; // ebx
char *v2; // rbp
char v3; // di
char *v4; // rbx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
strncpy(v2, src, v1);
reverse(v2);
v3 = *v2;
if ( *v2 )
{
v4 = v2;
do
{
*v4++ = dna_complement(v3);
v3 = *v4;
}
while ( *v4 );
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
int v1; // ebx
char *v2; // rbp
char v3; // di
char *v4; // rbx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
strncpy(v2, src, v1);
reverse(v2);
v3 = *v2;
if ( *v2 )
{
v4 = v2;
do
{
*v4++ = func0(v3);
v3 = *v4;
}
while ( *v4 );
}
return v2;
}

original_code:
char *dna_reverse_complement(char *dna)
{
    int i = 0, len = strlen(dna);
    char *result = (char *)malloc((len+1)*sizeof(char));
    strncpy(result, dna, len);
    reverse(result);
    while (result[i]){
        result[i] = dna_complement(result[i]);
        i++;
    }
    return result;
}

canonical_original_code:
char *dna_reverse_complement(char *dna)
{
    int i = 0; int len = strlen(dna);
    char *result = (char *)malloc((len+1)*sizeof(char));
    strncpy(result, dna, len);
    reverse(result);
    while (result[i]){
        result[i] = dna_complement(result[i]);
        i++;
    }
    return result;
}

variable_types:
dna
char *

variable_types: len int

variable_types:
result
char *

return_type: char *


decompiled_code:
__int64 __fastcall dna_is_reverse_palindrome(__int64 a1, int a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // rbx
char v5; // r13

LODWORD(v3) = a2 + a3 - 1;
if ( a2 >= (int)v3 )
return 1LL;
v4 = a2;
v3 = (int)v3;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4);
if ( v5 != (unsigned __int8)dna_complement(*(char *)(a1 + v3)) )
break;
if ( (int)++v4 >= (int)--v3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // rbx
char v5; // r13

LODWORD(v3) = a2 + a3 - 1;
if ( a2 >= (int)v3 )
return 1LL;
v4 = a2;
v3 = (int)v3;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4);
if ( v5 != (unsigned __int8)func0(*(char *)(a1 + v3)) )
break;
if ( (int)++v4 >= (int)--v3 )
return 1LL;
}
return 0LL;
}

original_code:
int dna_is_reverse_palindrome(char *dna, int pos, int len)
{
    int i, ii;
    for (i = pos, ii = pos + len - 1; i < ii; i++, ii--){
        if (dna[i] != dna_complement(dna[ii]))
            return 0;
    }
    return 1;
}

canonical_original_code:
int dna_is_reverse_palindrome(char *dna, int pos, int len)
{
    int i; int ii;
    for (i = pos, ii = pos + len - 1; i < ii; i++, ii--){
        if (dna[i] != dna_complement(dna[ii]))
            return 0;
    }
    return 1;
}

variable_types: pos int

variable_types: ii int


decompiled_code:
_BOOL8 __fastcall start_codon(const void *a1)
{
return memcmp(a1, "AUG", 3uLL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const void *a1)
{
return memcmp(a1, "AUG", 3uLL) == 0;
}

original_code:
int start_codon(char *codon){
    return (strncmp(codon, "AUG", 3) == 0);
}

variable_types:
codon
char *


decompiled_code:
__int64 __fastcall encode_codon(char *s1)
{
__int64 result; // rax
int v3; // edx

result = 70LL;
if ( memcmp(s1, "UUU", 3uLL) )
{
if ( memcmp(s1, "UUC", 3uLL) )
{
result = 76LL;
if ( memcmp(s1, "UUA", 3uLL) )
{
if ( memcmp(s1, "UUG", 3uLL) )
{
result = 83LL;
if ( memcmp(s1, "UCU", 3uLL) )
{
if ( memcmp(s1, "UCC", 3uLL) )
{
if ( memcmp(s1, "UCA", 3uLL) )
{
if ( memcmp(s1, "UCG", 3uLL) )
{
result = 89LL;
if ( memcmp(s1, "UAU", 3uLL) )
{
if ( memcmp(s1, "UAC", 3uLL) )
{
result = 0LL;
if ( memcmp(s1, "UAA", 3uLL) )
{
if ( memcmp(s1, "UAG", 3uLL) )
{
result = 67LL;
if ( memcmp(s1, "UGU", 3uLL) )
{
if ( memcmp(s1, "UGC", 3uLL) )
{
result = 0LL;
if ( memcmp(s1, "UGA", 3uLL) )
{
result = 87LL;
if ( memcmp(s1, "UGG", 3uLL) )
{
result = 76LL;
if ( memcmp(s1, "CUU", 3uLL) )
{
if ( memcmp(s1, "CUC", 3uLL) )
{
if ( memcmp(s1, "CUA", 3uLL) )
{
if ( memcmp(s1, "CUG", 3uLL) )
{
result = 80LL;
if ( memcmp(s1, "CCU", 3uLL) )
{
if ( memcmp(s1, "CCC", 3uLL) )
{
if ( memcmp(s1, "CCA", 3uLL) )
{
if ( memcmp(s1, "CCG", 3uLL) )
{
result = 72LL;
if ( memcmp(s1, "CAU", 3uLL) )
{
if ( memcmp(s1, "CAC", 3uLL) )
{
result = 81LL;
if ( memcmp(s1, "CAA", 3uLL) )
{
if ( !strncmp(s1, "CAG", 3uLL) )
{
result = 81LL;
}
else if ( !strncmp(s1, "CGU", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "CGC", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "CGA", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "CGG", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "AUU", 3uLL) )
{
result = 73LL;
}
else if ( !strncmp(s1, "AUC", 3uLL) )
{
result = 73LL;
}
else if ( !strncmp(s1, "AUA", 3uLL) )
{
result = 73LL;
}
else if ( !strncmp(s1, "AUG", 3uLL) )
{
result = 77LL;
}
else if ( !strncmp(s1, "ACU", 3uLL) )
{
result = 84LL;
}
else if ( !strncmp(s1, "ACC", 3uLL) )
{
result = 84LL;
}
else if ( !strncmp(s1, "ACA", 3uLL) )
{
result = 84LL;
}
else if ( !strncmp(s1, "ACG", 3uLL) )
{
result = 84LL;
}
else if ( !strncmp(s1, "AAU", 3uLL) )
{
result = 78LL;
}
else if ( !strncmp(s1, "AAC", 3uLL) )
{
result = 78LL;
}
else if ( !strncmp(s1, "AAA", 3uLL) )
{
result = 75LL;
}
else if ( !strncmp(s1, "AAG", 3uLL) )
{
result = 75LL;
}
else if ( !strncmp(s1, "AGU", 3uLL) )
{
result = 83LL;
}
else if ( !strncmp(s1, "AGC", 3uLL) )
{
result = 83LL;
}
else if ( !strncmp(s1, "AGA", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "AGG", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "GUU", 3uLL) )
{
result = 86LL;
}
else if ( !strncmp(s1, "GUC", 3uLL) )
{
result = 86LL;
}
else if ( !strncmp(s1, "GUA", 3uLL) )
{
result = 86LL;
}
else if ( !strncmp(s1, "GUG", 3uLL) )
{
result = 86LL;
}
else if ( !strncmp(s1, "GCU", 3uLL) )
{
result = 65LL;
}
else if ( !strncmp(s1, "GCC", 3uLL) )
{
result = 65LL;
}
else if ( !strncmp(s1, "GCA", 3uLL) )
{
result = 65LL;
}
else if ( !strncmp(s1, "GCG", 3uLL) )
{
result = 65LL;
}
else if ( !strncmp(s1, "GAU", 3uLL) )
{
result = 68LL;
}
else if ( !strncmp(s1, "GAC", 3uLL) )
{
result = 68LL;
}
else if ( !strncmp(s1, "GAA", 3uLL) )
{
result = 69LL;
}
else if ( !strncmp(s1, "GAG", 3uLL) )
{
result = 69LL;
}
else if ( !strncmp(s1, "GGU", 3uLL) )
{
result = 71LL;
}
else if ( !strncmp(s1, "GGC", 3uLL) )
{
result = 71LL;
}
else if ( !strncmp(s1, "GGA", 3uLL) )
{
result = 71LL;
}
else
{
v3 = strncmp(s1, "GGG", 3uLL);
result = 71LL;
if ( v3 )
{
printf(
"ERROR: Unexpected codon %c%c%c\n",
(unsigned int)*s1,
(unsigned int)s1[1],
(unsigned int)s1[2]);
result = 0xFFFFFFFFLL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
__int64 result; // rax
int v3; // edx

result = 70LL;
if ( memcmp(s1, "UUU", 3uLL) )
{
if ( memcmp(s1, "UUC", 3uLL) )
{
result = 76LL;
if ( memcmp(s1, "UUA", 3uLL) )
{
if ( memcmp(s1, "UUG", 3uLL) )
{
result = 83LL;
if ( memcmp(s1, "UCU", 3uLL) )
{
if ( memcmp(s1, "UCC", 3uLL) )
{
if ( memcmp(s1, "UCA", 3uLL) )
{
if ( memcmp(s1, "UCG", 3uLL) )
{
result = 89LL;
if ( memcmp(s1, "UAU", 3uLL) )
{
if ( memcmp(s1, "UAC", 3uLL) )
{
result = 0LL;
if ( memcmp(s1, "UAA", 3uLL) )
{
if ( memcmp(s1, "UAG", 3uLL) )
{
result = 67LL;
if ( memcmp(s1, "UGU", 3uLL) )
{
if ( memcmp(s1, "UGC", 3uLL) )
{
result = 0LL;
if ( memcmp(s1, "UGA", 3uLL) )
{
result = 87LL;
if ( memcmp(s1, "UGG", 3uLL) )
{
result = 76LL;
if ( memcmp(s1, "CUU", 3uLL) )
{
if ( memcmp(s1, "CUC", 3uLL) )
{
if ( memcmp(s1, "CUA", 3uLL) )
{
if ( memcmp(s1, "CUG", 3uLL) )
{
result = 80LL;
if ( memcmp(s1, "CCU", 3uLL) )
{
if ( memcmp(s1, "CCC", 3uLL) )
{
if ( memcmp(s1, "CCA", 3uLL) )
{
if ( memcmp(s1, "CCG", 3uLL) )
{
result = 72LL;
if ( memcmp(s1, "CAU", 3uLL) )
{
if ( memcmp(s1, "CAC", 3uLL) )
{
result = 81LL;
if ( memcmp(s1, "CAA", 3uLL) )
{
if ( !strncmp(s1, "CAG", 3uLL) )
{
result = 81LL;
}
else if ( !strncmp(s1, "CGU", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "CGC", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "CGA", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "CGG", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "AUU", 3uLL) )
{
result = 73LL;
}
else if ( !strncmp(s1, "AUC", 3uLL) )
{
result = 73LL;
}
else if ( !strncmp(s1, "AUA", 3uLL) )
{
result = 73LL;
}
else if ( !strncmp(s1, "AUG", 3uLL) )
{
result = 77LL;
}
else if ( !strncmp(s1, "ACU", 3uLL) )
{
result = 84LL;
}
else if ( !strncmp(s1, "ACC", 3uLL) )
{
result = 84LL;
}
else if ( !strncmp(s1, "ACA", 3uLL) )
{
result = 84LL;
}
else if ( !strncmp(s1, "ACG", 3uLL) )
{
result = 84LL;
}
else if ( !strncmp(s1, "AAU", 3uLL) )
{
result = 78LL;
}
else if ( !strncmp(s1, "AAC", 3uLL) )
{
result = 78LL;
}
else if ( !strncmp(s1, "AAA", 3uLL) )
{
result = 75LL;
}
else if ( !strncmp(s1, "AAG", 3uLL) )
{
result = 75LL;
}
else if ( !strncmp(s1, "AGU", 3uLL) )
{
result = 83LL;
}
else if ( !strncmp(s1, "AGC", 3uLL) )
{
result = 83LL;
}
else if ( !strncmp(s1, "AGA", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "AGG", 3uLL) )
{
result = 82LL;
}
else if ( !strncmp(s1, "GUU", 3uLL) )
{
result = 86LL;
}
else if ( !strncmp(s1, "GUC", 3uLL) )
{
result = 86LL;
}
else if ( !strncmp(s1, "GUA", 3uLL) )
{
result = 86LL;
}
else if ( !strncmp(s1, "GUG", 3uLL) )
{
result = 86LL;
}
else if ( !strncmp(s1, "GCU", 3uLL) )
{
result = 65LL;
}
else if ( !strncmp(s1, "GCC", 3uLL) )
{
result = 65LL;
}
else if ( !strncmp(s1, "GCA", 3uLL) )
{
result = 65LL;
}
else if ( !strncmp(s1, "GCG", 3uLL) )
{
result = 65LL;
}
else if ( !strncmp(s1, "GAU", 3uLL) )
{
result = 68LL;
}
else if ( !strncmp(s1, "GAC", 3uLL) )
{
result = 68LL;
}
else if ( !strncmp(s1, "GAA", 3uLL) )
{
result = 69LL;
}
else if ( !strncmp(s1, "GAG", 3uLL) )
{
result = 69LL;
}
else if ( !strncmp(s1, "GGU", 3uLL) )
{
result = 71LL;
}
else if ( !strncmp(s1, "GGC", 3uLL) )
{
result = 71LL;
}
else if ( !strncmp(s1, "GGA", 3uLL) )
{
result = 71LL;
}
else
{
v3 = strncmp(s1, "GGG", 3uLL);
result = 71LL;
if ( v3 )
{
printf(
"ERROR: Unexpected codon %c%c%c\n",
(unsigned int)*s1,
(unsigned int)s1[1],
(unsigned int)s1[2]);
result = 0xFFFFFFFFLL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
char encode_codon(char *codon)
{
    if (strncmp(codon, "UUU", 3) == 0) return 'F';
    if (strncmp(codon, "UUC", 3) == 0) return 'F';
    if (strncmp(codon, "UUA", 3) == 0) return 'L';
    if (strncmp(codon, "UUG", 3) == 0) return 'L';
    if (strncmp(codon, "UCU", 3) == 0) return 'S';
    if (strncmp(codon, "UCC", 3) == 0) return 'S';
    if (strncmp(codon, "UCA", 3) == 0) return 'S';
    if (strncmp(codon, "UCG", 3) == 0) return 'S';
    if (strncmp(codon, "UAU", 3) == 0) return 'Y';
    if (strncmp(codon, "UAC", 3) == 0) return 'Y';
    if (strncmp(codon, "UAA", 3) == 0) return '\0';
    if (strncmp(codon, "UAG", 3) == 0) return '\0';
    if (strncmp(codon, "UGU", 3) == 0) return 'C';
    if (strncmp(codon, "UGC", 3) == 0) return 'C';
    if (strncmp(codon, "UGA", 3) == 0) return '\0';
    if (strncmp(codon, "UGG", 3) == 0) return 'W';
    if (strncmp(codon, "CUU", 3) == 0) return 'L';
    if (strncmp(codon, "CUC", 3) == 0) return 'L';
    if (strncmp(codon, "CUA", 3) == 0) return 'L';
    if (strncmp(codon, "CUG", 3) == 0) return 'L';
    if (strncmp(codon, "CCU", 3) == 0) return 'P';
    if (strncmp(codon, "CCC", 3) == 0) return 'P';
    if (strncmp(codon, "CCA", 3) == 0) return 'P';
    if (strncmp(codon, "CCG", 3) == 0) return 'P';
    if (strncmp(codon, "CAU", 3) == 0) return 'H';
    if (strncmp(codon, "CAC", 3) == 0) return 'H';
    if (strncmp(codon, "CAA", 3) == 0) return 'Q';
    if (strncmp(codon, "CAG", 3) == 0) return 'Q';
    if (strncmp(codon, "CGU", 3) == 0) return 'R';
    if (strncmp(codon, "CGC", 3) == 0) return 'R';
    if (strncmp(codon, "CGA", 3) == 0) return 'R';
    if (strncmp(codon, "CGG", 3) == 0) return 'R';
    if (strncmp(codon, "AUU", 3) == 0) return 'I';
    if (strncmp(codon, "AUC", 3) == 0) return 'I';
    if (strncmp(codon, "AUA", 3) == 0) return 'I';
    if (strncmp(codon, "AUG", 3) == 0) return 'M';
    if (strncmp(codon, "ACU", 3) == 0) return 'T';
    if (strncmp(codon, "ACC", 3) == 0) return 'T';
    if (strncmp(codon, "ACA", 3) == 0) return 'T';
    if (strncmp(codon, "ACG", 3) == 0) return 'T';
    if (strncmp(codon, "AAU", 3) == 0) return 'N';
    if (strncmp(codon, "AAC", 3) == 0) return 'N';
    if (strncmp(codon, "AAA", 3) == 0) return 'K';
    if (strncmp(codon, "AAG", 3) == 0) return 'K';
    if (strncmp(codon, "AGU", 3) == 0) return 'S';
    if (strncmp(codon, "AGC", 3) == 0) return 'S';
    if (strncmp(codon, "AGA", 3) == 0) return 'R';
    if (strncmp(codon, "AGG", 3) == 0) return 'R';
    if (strncmp(codon, "GUU", 3) == 0) return 'V';
    if (strncmp(codon, "GUC", 3) == 0) return 'V';
    if (strncmp(codon, "GUA", 3) == 0) return 'V';
    if (strncmp(codon, "GUG", 3) == 0) return 'V';
    if (strncmp(codon, "GCU", 3) == 0) return 'A';
    if (strncmp(codon, "GCC", 3) == 0) return 'A';
    if (strncmp(codon, "GCA", 3) == 0) return 'A';
    if (strncmp(codon, "GCG", 3) == 0) return 'A';
    if (strncmp(codon, "GAU", 3) == 0) return 'D';
    if (strncmp(codon, "GAC", 3) == 0) return 'D';
    if (strncmp(codon, "GAA", 3) == 0) return 'E';
    if (strncmp(codon, "GAG", 3) == 0) return 'E';
    if (strncmp(codon, "GGU", 3) == 0) return 'G';
    if (strncmp(codon, "GGC", 3) == 0) return 'G';
    if (strncmp(codon, "GGA", 3) == 0) return 'G';
    if (strncmp(codon, "GGG", 3) == 0) return 'G';
    printf("ERROR: Unexpected codon %c%c%c\n", codon[0], codon[1], codon[2]);
    ((void) sizeof ((1) ? 1 : 0), __extension__ ({ if (1) ; else __assert_fail ("1", "src/lib/prot_lib.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    return -1;
}


decompiled_code:
char *__fastcall set_max(char *a1, double *a2, const char *a3, double a4, double a5)
{
double v5; // xmm0_8
char *result; // rax

v5 = a4 * 100.0 / a5;
if ( v5 > *a2 )
{
*a2 = v5;
result = strncpy(a1, a3, 0x50uLL);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char *a1, double *a2, const char *a3, double a4, double a5)
{
double v5; // xmm0_8
char *result; // rax

v5 = a4 * 100.0 / a5;
if ( v5 > *a2 )
{
*a2 = v5;
result = strncpy(a1, a3, 0x50uLL);
}
return result;
}

original_code:
void set_max(char *max_id, double *max_gc, char *id, double gc, double total){
    double gc_content = 100 * gc / ((double) total);
    if (*max_gc < gc_content) {
        *max_gc = gc_content;
        strncpy(max_id, id, 80);
    }
}

variable_types:
id
char *

variable_types: gc double

variable_types: total double


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rdi
char v6[20]; // [rsp+4h] [rbp-14h] BYREF

strcpy(v6, "data/gc.fas");
v4 = v6;
if ( argc > 1 )
v4 = argv[1];
read_data(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rdi
char v6[20]; // [rsp+4h] [rbp-14h] BYREF

strcpy(v6, "data/gc.fas");
v4 = v6;
if ( argc > 1 )
v4 = argv[1];
func8(v4);
return 0;
}

original_code:
int main(int argc, char **argv){
    char sample[] = "data/gc.fas", *data = sample;
    if (argc > 1)
        data = argv[1];
    read_data(data);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv){
    char sample[] = "data/gc.fas"; char *data = sample;
    if (argc > 1)
        data = argv[1];
    read_data(data);
    return 0;
}


reverse

decompiled_code:
__int64 __fastcall reverse(const char *a1)
{
__int64 result; // rax
__int64 v2; // rdx
char v3; // cl

result = (unsigned int)strlen(a1) - 1;
if ( (int)result > 0 )
{
result = (int)result;
v2 = 0LL;
do
{
v3 = a1[v2];
a1[v2] = a1[result];
a1[result] = v3;
++v2;
--result;
}
while ( (int)v2 < (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 result; // rax
__int64 v2; // rdx
char v3; // cl

result = (unsigned int)strlen(a1) - 1;
if ( (int)result > 0 )
{
result = (int)result;
v2 = 0LL;
do
{
v3 = a1[v2];
a1[v2] = a1[result];
a1[result] = v3;
++v2;
--result;
}
while ( (int)v2 < (int)result );
}
return result;
}

original_code:
void reverse(char s[])
{
    int c, i, j;
    for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
        c = s[i];
        s[i] = s[j];
        s[j] = c;
    }
}

canonical_original_code:
void reverse(char s[])
{
    int c; int i; int j;
    for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
        c = s[i];
        s[i] = s[j];
        s[j] = c;
    }
}

variable_types:
s
char []

variable_types: c int

variable_types: i int

variable_types: j int


original_code:
struct ntc count_nt(char *data, int len){
    int i = 0;
    struct ntc result;
    memset(&result, 0, sizeof(result));
    for (i = 0; i < len; i++){
        switch(data[i]){
            case 'A': result.a++; break;
            case 'C': result.c++; break;
            case 'G': result.g++; break;
            case 'T': result.t++; break;
        }
    }
    return result;
}

variable_types:
data
char *

variable_types: struct ntc { int a; int c; int g; int t; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // eax
__int64 v5; // rax
unsigned __int64 v6; // rdx
char v8[88]; // [rsp+0h] [rbp-58h] BYREF

strcpy(v8, "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC");
v3 = v8;
if ( argc > 1 )
v3 = (char *)argv[1];
v4 = strlen(v3);
v5 = count_nt(v3, v4);
printf("%d %d %d %d\n", v5, v5 >> 32, v6, HIDWORD(v6));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // eax
__int64 v5; // rax
unsigned __int64 v6; // rdx
char v8[88]; // [rsp+0h] [rbp-58h] BYREF

strcpy(v8, "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC");
v3 = v8;
if ( argc > 1 )
v3 = (char *)argv[1];
v4 = strlen(v3);
v5 = func7(v3, v4);
printf("%d %d %d %d\n", v5, v5 >> 32, v6, HIDWORD(v6));
return 0;
}

original_code:
int main(int argc, char **argv){
    char sample[] = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";
    char *data = sample;
    if (argc > 1) data = argv[1];
    struct ntc result = count_nt(data, strlen(data));
    printf("%d %d %d %d\n", result.a, result.c, result.g, result.t);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
sample
char []

user_defined_types: struct ntc { int a; int c; int g; int t; }


decompiled_code:
__int64 __fastcall hamm_dist(const char *a1, const char *a2)
{
size_t v2; // r12
char v3; // dl
unsigned int v4; // ecx
__int64 i; // rax

v2 = strlen(a1);
if ( v2 != strlen(a2) )
__assert_fail("strlen(a) == strlen(b)", "src/hamm.c", 0x12u, "hamm_dist");
v3 = *a1;
v4 = 0;
for ( i = 0LL; v3; v3 = a1[i] )
v4 += a2[i++] != (unsigned __int8)v3;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, const char *a2)
{
size_t v2; // r12
char v3; // dl
unsigned int v4; // ecx
__int64 i; // rax

v2 = strlen(a1);
if ( v2 != strlen(a2) )
__assert_fail("strlen(a) == strlen(b)", "src/hamm.c", 0x12u, "hamm_dist");
v3 = *a1;
v4 = 0;
for ( i = 0LL; v3; v3 = a1[i] )
v4 += a2[i++] != (unsigned __int8)v3;
return v4;
}

original_code:
int hamm_dist(char *a, char *b){
    int dist = 0, i = 0;
    ((void) sizeof ((strlen(a) == strlen(b)) ? 1 : 0), __extension__ ({ if (strlen(a) == strlen(b)) ; else __assert_fail ("strlen(a) == strlen(b)", "src/hamm.c", 18, __extension__ __PRETTY_FUNCTION__); }));
    while(a[i]){
        if (a[i] != b[i])
            dist++;
        i++;
    }
    return dist;
}

canonical_original_code:
int hamm_dist(char *a, char *b){
    int dist = 0; int i = 0;
    ((void) sizeof ((strlen(a) == strlen(b)) ? 1 : 0), __extension__ ({ if (strlen(a) == strlen(b)) ; else __assert_fail ("strlen(a) == strlen(b)", "src/hamm.c", 18, __extension__ __PRETTY_FUNCTION__); }));
    while(a[i]){
        if (a[i] != b[i])
            dist++;
        i++;
    }
    return dist;
}

variable_types:
a
char *

variable_types:
b
char *

variable_types: dist int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
const char *v4; // rsi
unsigned int v5; // eax
char v7[32]; // [rsp+0h] [rbp-48h] BYREF
char v8[40]; // [rsp+20h] [rbp-28h] BYREF

strcpy(v8, "GAGCCTACTAACGGGAT");
strcpy(v7, "CATCGTAATGACGGCCT");
if ( argc <= 2 )
{
v4 = v7;
v3 = v8;
}
else
{
v3 = argv[1];
v4 = argv[2];
}
v5 = hamm_dist(v3, v4);
printf("%d\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
const char *v4; // rsi
unsigned int v5; // eax
char v7[32]; // [rsp+0h] [rbp-48h] BYREF
char v8[40]; // [rsp+20h] [rbp-28h] BYREF

strcpy(v8, "GAGCCTACTAACGGGAT");
strcpy(v7, "CATCGTAATGACGGCCT");
if ( argc <= 2 )
{
v4 = v7;
v3 = v8;
}
else
{
v3 = argv[1];
v4 = argv[2];
}
v5 = func7(v3, v4);
printf("%d\n", v5);
return 0;
}

original_code:
int main(int argc, char **argv){
    char sample1[] = "GAGCCTACTAACGGGAT", sample2[] = "CATCGTAATGACGGCCT";
    char *data1 = sample1, *data2 = sample2;
    int dist;
    if (argc > 2){
        data1 = argv[1];
        data2 = argv[2];
    }
    dist = hamm_dist(data1, data2);
    printf("%d\n", dist);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv){
    char sample1[] = "GAGCCTACTAACGGGAT"; char sample2[] = "CATCGTAATGACGGCCT";
    char *data1 = sample1; char *data2 = sample2;
    int dist;
    if (argc > 2){
        data1 = argv[1];
        data2 = argv[2];
    }
    dist = hamm_dist(data1, data2);
    printf("%d\n", dist);
    return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 i; // rbx
double *v5; // rbx
double v6; // xmm0_8
__int64 v8; // [rsp+0h] [rbp-D0h]
__int64 v9; // [rsp+8h] [rbp-C8h] BYREF
__int64 v10[24]; // [rsp+10h] [rbp-C0h] BYREF

v9 = 0x3FCD70A3D70A3D71LL;
v10[0] = 0x3FD3D70A3D70A3D7LL;
v10[1] = 0x3FE8000000000000LL;
v3 = 3;
if ( argc > 2 )
{
v3 = argc - 1;
for ( i = 1LL; i != argc; ++i )
*((double *)&v8 + i) = atof(argv[i]);
}
v5 = (double *)&v9;
do
{
v6 = prob(*v5);
printf("%lf ", v6);
++v5;
}
while ( v5 != (double *)&v10[v3 - 1] );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 i; // rbx
double *v5; // rbx
double v6; // xmm0_8
__int64 v8; // [rsp+0h] [rbp-D0h]
__int64 v9; // [rsp+8h] [rbp-C8h] BYREF
__int64 v10[24]; // [rsp+10h] [rbp-C0h] BYREF

v9 = 0x3FCD70A3D70A3D71LL;
v10[0] = 0x3FD3D70A3D70A3D7LL;
v10[1] = 0x3FE8000000000000LL;
v3 = 3;
if ( argc > 2 )
{
v3 = argc - 1;
for ( i = 1LL; i != argc; ++i )
*((double *)&v8 + i) = atof(argv[i]);
}
v5 = (double *)&v9;
do
{
v6 = func7(*v5);
printf("%lf ", v6);
++v5;
}
while ( v5 != (double *)&v10[v3 - 1] );
return 0;
}

original_code:
int main(int argc, char **argv)
{
    double data[20];
    int len = 3, i;
    data[0] = 0.23;
    data[1] = 0.31;
    data[2] = 0.75;
    if (argc > 2){
        len = argc - 1;
        for (i = 0; i < len; i++){
            data[i] = atof(argv[i + 1]);
        }
    }
    for (i = 0; i < len; i++){
        printf("%lf ", prob(data[i]));
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    double data[20];
    int len = 3; int i;
    data[0] = 0.23;
    data[1] = 0.31;
    data[2] = 0.75;
    if (argc > 2){
        len = argc - 1;
        for (i = 0; i < len; i++){
            data[i] = atof(argv[i + 1]);
        }
    }
    for (i = 0; i < len; i++){
        printf("%lf ", prob(data[i]));
    }
    return 0;
}

variable_types:
data
double [20]

variable_types: len int


decompiled_code:
unsigned __int64 __fastcall safe_read(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
ssize_t v6; // rax

v4 = 0LL;
if ( !a3 )
return 0LL;
do
{
v6 = read(fd, (void *)(a2 + v4), a3 - v4);
if ( !v6 )
break;
if ( v6 < 0 )
{
if ( *_errno_location() != 4 )
return -1LL;
}
else
{
v4 += v6;
}
}
while ( v4 < a3 );
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
ssize_t v6; // rax

v4 = 0LL;
if ( !a3 )
return 0LL;
do
{
v6 = read(fd, (void *)(a2 + v4), a3 - v4);
if ( !v6 )
break;
if ( v6 < 0 )
{
if ( *_errno_location() != 4 )
return -1LL;
}
else
{
v4 += v6;
}
}
while ( v4 < a3 );
return v4;
}

original_code:
ssize_t
safe_read (int fd, void *buf, size_t count)
{
 ssize_t r;
 size_t reads = 0;
 while (reads < count &&
        (r = read(fd, (char *)buf + reads, count - reads)) != 0)
 {
  if (r < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   return -1;
  }
  reads += r;
 }
 return reads;
}

canonical_original_code:
long safe_read(int fd, void *buf, unsigned long count)
{
 long r;
 unsigned long reads = 0;
 while (reads < count &&
        (r = read(fd, (char *)buf + reads, count - reads)) != 0)
 {
  if (r < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   return -1;
  }
  reads += r;
 }
 return reads;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: r long

variable_types:
reads
unsigned long

return_type: long


decompiled_code:
unsigned __int64 __fastcall safe_write(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
ssize_t v6; // rax

v4 = 0LL;
if ( !a3 )
return 0LL;
do
{
v6 = write(fd, (const void *)(a2 + v4), a3 - v4);
if ( !v6 )
break;
if ( v6 < 0 )
{
if ( *_errno_location() != 4 )
return -1LL;
}
else
{
v4 += v6;
}
}
while ( v4 < a3 );
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
ssize_t v6; // rax

v4 = 0LL;
if ( !a3 )
return 0LL;
do
{
v6 = write(fd, (const void *)(a2 + v4), a3 - v4);
if ( !v6 )
break;
if ( v6 < 0 )
{
if ( *_errno_location() != 4 )
return -1LL;
}
else
{
v4 += v6;
}
}
while ( v4 < a3 );
return v4;
}

original_code:
ssize_t
safe_write (int fd, const void *buf, size_t count)
{
 ssize_t w;
 size_t written = 0;
 while (written < count &&
        (w = write(fd, (char *)buf + written, count - written)) != 0)
 {
  if (w < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   return -1;
  }
  written += w;
 }
 return written;
}

canonical_original_code:
long safe_write(int fd, void *buf, unsigned long count)
{
 long w;
 unsigned long written = 0;
 while (written < count &&
        (w = write(fd, (char *)buf + written, count - written)) != 0)
 {
  if (w < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   return -1;
  }
  written += w;
 }
 return written;
}

variable_types: w long

variable_types:
written
unsigned long


original_code:
static void
unspare2_endian_transform (nand_ecclayout_t *oob)
{
 unsigned i, eccpos_entries, oobfree_entries;
 eccpos_entries = sizeof(oob->eccpos) / sizeof(unsigned);
 oobfree_entries = sizeof(oob->oobfree) / sizeof(struct nand_oobfree);
 oob->eccbytes = ((((oob->eccbytes) & 0x000000ff) << 24) | (((oob->eccbytes) & 0x0000ff00) << 8) | (((oob->eccbytes) & 0x00ff0000) >> 8) | (((oob->eccbytes) & 0xff000000) >> 24));
 oob->oobavail = ((((oob->oobavail) & 0x000000ff) << 24) | (((oob->oobavail) & 0x0000ff00) << 8) | (((oob->oobavail) & 0x00ff0000) >> 8) | (((oob->oobavail) & 0xff000000) >> 24));
 for (i = 0; i < eccpos_entries; i++)
  oob->eccpos[i] = ((((oob->eccpos[i]) & 0x000000ff) << 24) | (((oob->eccpos[i]) & 0x0000ff00) << 8) | (((oob->eccpos[i]) & 0x00ff0000) >> 8) | (((oob->eccpos[i]) & 0xff000000) >> 24));
 for (i = 0; i < oobfree_entries; i++) {
  oob->oobfree[i].offset = ((((oob->oobfree[i].offset) & 0x000000ff) << 24) | (((oob->oobfree[i].offset) & 0x0000ff00) << 8) | (((oob->oobfree[i].offset) & 0x00ff0000) >> 8) | (((oob->oobfree[i].offset) & 0xff000000) >> 24));
  oob->oobfree[i].length = ((((oob->oobfree[i].length) & 0x000000ff) << 24) | (((oob->oobfree[i].length) & 0x0000ff00) << 8) | (((oob->oobfree[i].length) & 0x00ff0000) >> 8) | (((oob->oobfree[i].length) & 0xff000000) >> 24));
 }
}

canonical_original_code:
static void unspare2_endian_transform(struct nand_ecclayout_user *oob)
{
 unsigned int i; unsigned int eccpos_entries; unsigned int oobfree_entries;
 eccpos_entries = sizeof(oob->eccpos) / sizeof(unsigned int);
 oobfree_entries = sizeof(oob->oobfree) / sizeof(struct nand_oobfree);
 oob->eccbytes = ((((oob->eccbytes) & 0x000000ff) << 24) | (((oob->eccbytes) & 0x0000ff00) << 8) | (((oob->eccbytes) & 0x00ff0000) >> 8) | (((oob->eccbytes) & 0xff000000) >> 24));
 oob->oobavail = ((((oob->oobavail) & 0x000000ff) << 24) | (((oob->oobavail) & 0x0000ff00) << 8) | (((oob->oobavail) & 0x00ff0000) >> 8) | (((oob->oobavail) & 0xff000000) >> 24));
 for (i = 0; i < eccpos_entries; i++)
  oob->eccpos[i] = ((((oob->eccpos[i]) & 0x000000ff) << 24) | (((oob->eccpos[i]) & 0x0000ff00) << 8) | (((oob->eccpos[i]) & 0x00ff0000) >> 8) | (((oob->eccpos[i]) & 0xff000000) >> 24));
 for (i = 0; i < oobfree_entries; i++) {
  oob->oobfree[i].offset = ((((oob->oobfree[i].offset) & 0x000000ff) << 24) | (((oob->oobfree[i].offset) & 0x0000ff00) << 8) | (((oob->oobfree[i].offset) & 0x00ff0000) >> 8) | (((oob->oobfree[i].offset) & 0xff000000) >> 24));
  oob->oobfree[i].length = ((((oob->oobfree[i].length) & 0x000000ff) << 24) | (((oob->oobfree[i].length) & 0x0000ff00) << 8) | (((oob->oobfree[i].length) & 0x00ff0000) >> 8) | (((oob->oobfree[i].length) & 0xff000000) >> 24));
 }
}

variable_types: struct nand_ecclayout_user { unsigned int eccbytes; unsigned int eccpos[64]; unsigned int oobavail; struct nand_oobfree { unsigned int offset; unsigned int length; } oobfree[8]; } *

variable_types:
i
unsigned int

user_defined_types: struct nand_ecclayout_user { unsigned int eccbytes; unsigned int eccpos[64]; unsigned int oobavail; struct nand_oobfree oobfree[8]; }


decompiled_code:
size_t unspare2_helper()
{
fwrite("Usage: unspare2 devfile imgfile\n", 1uLL, 0x20uLL, stderr);
fwrite("unspare2: A utility to extract the OOB layout\n", 1uLL, 0x2EuLL, stderr);
fprintf(stderr, "version: %s\n", "0.2.8");
fwrite("options:\n", 1uLL, 9uLL, stderr);
fwrite(" -h\t", 1uLL, 4uLL, stderr);
fwrite("display this help message and exit\n", 1uLL, 0x23uLL, stderr);
fwrite(" -e\t", 1uLL, 4uLL, stderr);
return fwrite("convert the endian differed from the local machine\n", 1uLL, 0x33uLL, stderr);
}

canonical_decompiled_code:
size_t func1()
{
fwrite("Usage: unspare2 devfile imgfile\n", 1uLL, 0x20uLL, stderr);
fwrite("unspare2: A utility to extract the OOB layout\n", 1uLL, 0x2EuLL, stderr);
fprintf(stderr, "version: %s\n", "0.2.8");
fwrite("options:\n", 1uLL, 9uLL, stderr);
fwrite(" -h\t", 1uLL, 4uLL, stderr);
fwrite("display this help message and exit\n", 1uLL, 0x23uLL, stderr);
fwrite(" -e\t", 1uLL, 4uLL, stderr);
return fwrite("convert the endian differed from the local machine\n", 1uLL, 0x33uLL, stderr);
}

original_code:
static void
unspare2_helper (void)
{
 fprintf(stderr, "Usage: unspare2 devfile imgfile\n");
 fprintf(stderr, "unspare2: A utility to extract the OOB layout\n");
 fprintf(stderr, "version: %s\n", "0.2.8");
 fprintf(stderr, "options:\n");
 fprintf(stderr, " -h	");
 fprintf(stderr, "display this help message and exit\n");
 fprintf(stderr, " -e	");
 fprintf(stderr, "convert the endian differed from the local machine\n");
}

canonical_original_code:
static void unspare2_helper()
{
 fprintf(stderr, "Usage: unspare2 devfile imgfile\n");
 fprintf(stderr, "unspare2: A utility to extract the OOB layout\n");
 fprintf(stderr, "version: %s\n", "0.2.8");
 fprintf(stderr, "options:\n");
 fprintf(stderr, " -h	");
 fprintf(stderr, "display this help message and exit\n");
 fprintf(stderr, " -e	");
 fprintf(stderr, "convert the endian differed from the local machine\n");
}


decompiled_code:
__int64 __fastcall unspare2_dump(char *file, char *name)
{
int v2; // ebx
unsigned int v3; // ebp
int v4; // eax
unsigned int v5; // ebx
int v7[90]; // [rsp+0h] [rbp-168h] BYREF

memset(v7, 0, 0x148uLL);
v2 = open(file, 2);
if ( v2 < 0 )
fprintf(stderr, "cannot open the device %s\n", file);
v3 = ioctl(v2, 0x81484D11uLL, v7);
if ( (v3 & 0x80000000) != 0 )
{
fwrite("ioctl failed\n", 1uLL, 0xDuLL, stderr);
close(v2);
return v3;
}
close(v2);
if ( !v3 )
{
if ( (unspare2_flags & 1) != 0 )
unspare2_endian_transform(v7);
v4 = open(name, 577, 420LL);
v5 = v4;
if ( v4 < 0 )
{
fprintf(stderr, "cannot open the image %s\n", name);
if ( safe_write(v5, v7, 328LL) == 328 )
{
close(v5);
goto LABEL_14;
}
}
else if ( safe_write((unsigned int)v4, v7, 328LL) == 328 )
{
close(v5);
return v3;
}
fwrite("write oob info back to image failed\n", 1uLL, 0x24uLL, stderr);
close(v5);
LABEL_14:
unlink(name);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *file, char *name)
{
int v2; // ebx
unsigned int v3; // ebp
int v4; // eax
unsigned int v5; // ebx
int v7[90]; // [rsp+0h] [rbp-168h] BYREF

memset(v7, 0, 0x148uLL);
v2 = open(file, 2);
if ( v2 < 0 )
fprintf(stderr, "cannot open the device %s\n", file);
v3 = ioctl(v2, 0x81484D11uLL, v7);
if ( (v3 & 0x80000000) != 0 )
{
fwrite("ioctl failed\n", 1uLL, 0xDuLL, stderr);
close(v2);
return v3;
}
close(v2);
if ( !v3 )
{
if ( (unspare2_flags & 1) != 0 )
func0(v7);
v4 = open(name, 577, 420LL);
v5 = v4;
if ( v4 < 0 )
{
fprintf(stderr, "cannot open the image %s\n", name);
if ( safe_write(v5, v7, 328LL) == 328 )
{
close(v5);
goto LABEL_14;
}
}
else if ( safe_write((unsigned int)v4, v7, 328LL) == 328 )
{
close(v5);
return v3;
}
fwrite("write oob info back to image failed\n", 1uLL, 0x24uLL, stderr);
close(v5);
LABEL_14:
unlink(name);
v3 = -1;
}
return v3;
}

original_code:
static int
unspare2_dump (const char *devfile, const char *imgfile)
{
 int fd, retval = 0;
 ssize_t written;
 nand_ecclayout_t oob;
 memset(&oob, 0, sizeof(nand_ecclayout_t));
 if ((fd = open(devfile, 02)) < 0) {
  retval = -1;
  fprintf(stderr, "cannot open the device %s\n", devfile);
 }
 if ((retval = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('M')) << (0 +8)) | (((17)) << 0) | ((((sizeof(struct nand_ecclayout_user)))) << ((0 +8)+8))), &oob)) < 0)
  fprintf(stderr, "ioctl failed\n");
 close(fd);
 if (retval)
  return retval;
 if ((unspare2_flags & 0x01))
  unspare2_endian_transform(&oob);
 if ((fd = open(imgfile, 01 | 0100 | 01000, 0644)) < 0) {
  retval = -1;
  fprintf(stderr, "cannot open the image %s\n", imgfile);
 }
 written = safe_write(fd, &oob, sizeof(nand_ecclayout_t));
 if (written != sizeof(nand_ecclayout_t)) {
  retval = -1;
  fprintf(stderr, "write oob info back to image failed\n");
 }
 close(fd);
 if (retval)
  unlink(imgfile);
 return retval;
}

canonical_original_code:
static int unspare2_dump(char *devfile, char *imgfile)
{
 int fd; int retval = 0;
 long written;
 struct nand_ecclayout_user oob;
 memset(&oob, 0, sizeof(nand_ecclayout_t));
 if ((fd = open(devfile, 02)) < 0) {
  retval = -1;
  fprintf(stderr, "cannot open the device %s\n", devfile);
 }
 if ((retval = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('M')) << (0 +8)) | (((17)) << 0) | ((((sizeof(struct nand_ecclayout_user)))) << ((0 +8)+8))), &oob)) < 0)
  fprintf(stderr, "ioctl failed\n");
 close(fd);
 if (retval)
  return retval;
 if ((unspare2_flags & 0x01))
  unspare2_endian_transform(&oob);
 if ((fd = open(imgfile, 01 | 0100 | 01000, 0644)) < 0) {
  retval = -1;
  fprintf(stderr, "cannot open the image %s\n", imgfile);
 }
 written = safe_write(fd, &oob, sizeof(nand_ecclayout_t));
 if (written != sizeof(nand_ecclayout_t)) {
  retval = -1;
  fprintf(stderr, "write oob info back to image failed\n");
 }
 close(fd);
 if (retval)
  unlink(imgfile);
 return retval;
}

variable_types:
devfile
char *

variable_types:
imgfile
char *

variable_types: retval int

variable_types: written long

variable_types: struct nand_ecclayout_user { unsigned int eccbytes; unsigned int eccpos[64]; unsigned int oobavail; struct nand_oobfree { unsigned int offset; unsigned int length; } oobfree[8]; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v5; // rbp
char *v6; // r12
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

printf("unspare2-%s: OOB extracting tool for yaffs2utils\n", "0.2.8");
if ( getuid() )
fwrite("warning: non-root users\n", 1uLL, 0x18uLL, stderr);
while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "he", &long_options_0, longind);
if ( v3 == -1 )
break;
if ( v3 != 101 )
{
unspare2_helper();
if ( v3 == 104 )
v3 = 0;
else
v3 = -1;
return v3;
}
unspare2_flags |= 1u;
}
if ( argc - optind <= 1 )
{
unspare2_helper();
}
else
{
v5 = (char *)argv[optind];
v6 = (char *)argv[optind + 1];
v3 = unspare2_dump(v5, v6);
if ( v3 )
fwrite("failed", 1uLL, 6uLL, stderr);
else
printf("OOB info for %s was saved in %s\n", v5, v6);
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v5; // rbp
char *v6; // r12
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

printf("unspare2-%s: OOB extracting tool for yaffs2utils\n", "0.2.8");
if ( getuid() )
fwrite("warning: non-root users\n", 1uLL, 0x18uLL, stderr);
while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "he", &long_options_0, longind);
if ( v3 == -1 )
break;
if ( v3 != 101 )
{
func1();
if ( v3 == 104 )
v3 = 0;
else
v3 = -1;
return v3;
}
unspare2_flags |= 1u;
}
if ( argc - optind <= 1 )
{
func1();
}
else
{
v5 = (char *)argv[optind];
v6 = (char *)argv[optind + 1];
v3 = func2(v5, v6);
if ( v3 )
fwrite("failed", 1uLL, 6uLL, stderr);
else
printf("OOB info for %s was saved in %s\n", v5, v6);
}
return v3;
}

original_code:
int
main (int argc, char **argv)
{
 int retval;
 char *devpath, *imgpath;
 int option, option_index;
 static const char *short_options = "he";
 static const struct option long_options[] = {
  {"help", 0, 0, 'h'},
  {"endian", 0, 0, 'e'},
 };
 printf("unspare2-%s: OOB extracting tool for yaffs2utils\n",
  "0.2.8");
 if (getuid() != 0)
  fprintf(stderr, "warning: non-root users\n");
 while ((option = getopt_long(argc, argv, short_options,
         long_options, &option_index)) != (-1))
 {
  switch (option) {
  case 'e':
   unspare2_flags |= 0x01;
   break;
  case 'h':
   unspare2_helper();
   return 0;
  default:
   unspare2_helper();
   return -1;
  }
 }
 if (argc - optind < 2) {
  unspare2_helper();
  return -1;
 }
 devpath = argv[optind];
 imgpath = argv[optind + 1];
 retval = unspare2_dump(devpath, imgpath);
 if (!retval)
  printf("OOB info for %s was saved in %s\n", devpath, imgpath);
 else
  fprintf(stderr, "failed");
 return retval;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int retval;
 char *devpath; char *imgpath;
 int option; int option_index;
 static char *short_options = "he";
 static struct option long_options[] = {
  {"help", 0, 0, 'h'},
  {"endian", 0, 0, 'e'},
 };
 printf("unspare2-%s: OOB extracting tool for yaffs2utils\n",
  "0.2.8");
 if (getuid() != 0)
  fprintf(stderr, "warning: non-root users\n");
 while ((option = getopt_long(argc, argv, short_options,
         long_options, &option_index)) != (-1))
 {
  switch (option) {
  case 'e':
   unspare2_flags |= 0x01;
   break;
  case 'h':
   unspare2_helper();
   return 0;
  default:
   unspare2_helper();
   return -1;
  }
 }
 if (argc - optind < 2) {
  unspare2_helper();
  return -1;
 }
 devpath = argv[optind];
 imgpath = argv[optind + 1];
 retval = unspare2_dump(devpath, imgpath);
 if (!retval)
  printf("OOB info for %s was saved in %s\n", devpath, imgpath);
 else
  fprintf(stderr, "failed");
 return retval;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
devpath
char *

variable_types:
imgpath
char *

variable_types: option int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


original_code:
void yaffs_pack_tags1(struct yaffs_packed_tags1 *pt,
        const struct yaffs_ext_tags *t)
{
 pt->chunk_id = t->chunk_id;
 pt->serial_number = t->serial_number;
 pt->n_bytes = t->n_bytes;
 pt->obj_id = t->obj_id;
 pt->ecc = 0;
 pt->deleted = (t->is_deleted) ? 0 : 1;
 pt->unused_stuff = 0;
 pt->should_be_ff = 0xffffffff;
}

canonical_original_code:
void yaffs_pack_tags1(struct yaffs_packed_tags1 *pt, struct yaffs_ext_tags *t)
{
 pt->chunk_id = t->chunk_id;
 pt->serial_number = t->serial_number;
 pt->n_bytes = t->n_bytes;
 pt->obj_id = t->obj_id;
 pt->ecc = 0;
 pt->deleted = (t->is_deleted) ? 0 : 1;
 pt->unused_stuff = 0;
 pt->should_be_ff = 0xffffffff;
}

variable_types: struct yaffs_packed_tags1 { unsigned int chunk_id; unsigned int serial_number; unsigned int n_bytes; unsigned int obj_id; unsigned int ecc; unsigned int deleted; unsigned int unused_stuff; unsigned int should_be_ff; } *

variable_types: struct yaffs_ext_tags { unsigned int chunk_used; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; enum yaffs_ecc_result { YAFFS_ECC_RESULT_UNKNOWN=0, YAFFS_ECC_RESULT_NO_ERROR=1, YAFFS_ECC_RESULT_FIXED=2, YAFFS_ECC_RESULT_UNFIXED=3 } ecc_result; unsigned int block_bad; unsigned int is_deleted; unsigned int serial_number; unsigned int seq_number; unsigned int extra_available; unsigned int extra_parent_id; unsigned int extra_is_shrink; unsigned int extra_shadows; enum yaffs_obj_type { YAFFS_OBJECT_TYPE_UNKNOWN=0, YAFFS_OBJECT_TYPE_FILE=1, YAFFS_OBJECT_TYPE_SYMLINK=2, YAFFS_OBJECT_TYPE_DIRECTORY=3, YAFFS_OBJECT_TYPE_HARDLINK=4, YAFFS_OBJECT_TYPE_SPECIAL=5 } extra_obj_type; long extra_file_size; unsigned int extra_equiv_id; } *

user_defined_types: struct yaffs_ext_tags { unsigned int chunk_used; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; enum yaffs_ecc_result ecc_result; unsigned int block_bad; unsigned int is_deleted; unsigned int serial_number; unsigned int seq_number; unsigned int extra_available; unsigned int extra_parent_id; unsigned int extra_is_shrink; unsigned int extra_shadows; enum yaffs_obj_type extra_obj_type; long extra_file_size; unsigned int extra_equiv_id; }


original_code:
void yaffs_unpack_tags1(struct yaffs_ext_tags *t,
   const struct yaffs_packed_tags1 *pt)
{
 if (memcmp(all_ff, pt, sizeof(struct yaffs_packed_tags1))) {
  t->block_bad = 0;
  if (pt->should_be_ff != 0xffffffff)
   t->block_bad = 1;
  t->chunk_used = 1;
  t->obj_id = pt->obj_id;
  t->chunk_id = pt->chunk_id;
  t->n_bytes = pt->n_bytes;
  t->ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
  t->is_deleted = (pt->deleted) ? 0 : 1;
  t->serial_number = pt->serial_number;
 } else {
  memset(t, 0, sizeof(struct yaffs_ext_tags));
 }
}

canonical_original_code:
void yaffs_unpack_tags1(struct yaffs_ext_tags *t, struct yaffs_packed_tags1 *pt)
{
 if (memcmp(all_ff, pt, sizeof(struct yaffs_packed_tags1))) {
  t->block_bad = 0;
  if (pt->should_be_ff != 0xffffffff)
   t->block_bad = 1;
  t->chunk_used = 1;
  t->obj_id = pt->obj_id;
  t->chunk_id = pt->chunk_id;
  t->n_bytes = pt->n_bytes;
  t->ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
  t->is_deleted = (pt->deleted) ? 0 : 1;
  t->serial_number = pt->serial_number;
 } else {
  memset(t, 0, sizeof(struct yaffs_ext_tags));
 }
}

user_defined_types: struct yaffs_packed_tags1 { unsigned int chunk_id; unsigned int serial_number; unsigned int n_bytes; unsigned int obj_id; unsigned int ecc; unsigned int deleted; unsigned int unused_stuff; unsigned int should_be_ff; }

user_defined_types: enum yaffs_ecc_result { YAFFS_ECC_RESULT_UNKNOWN=0, YAFFS_ECC_RESULT_NO_ERROR=1, YAFFS_ECC_RESULT_FIXED=2, YAFFS_ECC_RESULT_UNFIXED=3 }

user_defined_types: enum yaffs_obj_type { YAFFS_OBJECT_TYPE_UNKNOWN=0, YAFFS_OBJECT_TYPE_FILE=1, YAFFS_OBJECT_TYPE_SYMLINK=2, YAFFS_OBJECT_TYPE_DIRECTORY=3, YAFFS_OBJECT_TYPE_HARDLINK=4, YAFFS_OBJECT_TYPE_SPECIAL=5 }


original_code:
int yaffs_ecc_correct(unsigned char *data, unsigned char *read_ecc,
        const unsigned char *test_ecc)
{
 unsigned char d0, d1, d2;
 d0 = read_ecc[0] ^ test_ecc[0];
 d1 = read_ecc[1] ^ test_ecc[1];
 d2 = read_ecc[2] ^ test_ecc[2];
 if ((d0 | d1 | d2) == 0)
  return 0;
 if (((d0 ^ (d0 >> 1)) & 0x55) == 0x55 &&
     ((d1 ^ (d1 >> 1)) & 0x55) == 0x55 &&
     ((d2 ^ (d2 >> 1)) & 0x54) == 0x54) {
  unsigned byte;
  unsigned bit;
  bit = byte = 0;
  if (d1 & 0x80)
   byte |= 0x80;
  if (d1 & 0x20)
   byte |= 0x40;
  if (d1 & 0x08)
   byte |= 0x20;
  if (d1 & 0x02)
   byte |= 0x10;
  if (d0 & 0x80)
   byte |= 0x08;
  if (d0 & 0x20)
   byte |= 0x04;
  if (d0 & 0x08)
   byte |= 0x02;
  if (d0 & 0x02)
   byte |= 0x01;
  if (d2 & 0x80)
   bit |= 0x04;
  if (d2 & 0x20)
   bit |= 0x02;
  if (d2 & 0x08)
   bit |= 0x01;
  data[byte] ^= (1 << bit);
  return 1;
 }
 if ((yaffs_hweight8(d0) +
      yaffs_hweight8(d1) +
      yaffs_hweight8(d2)) == 1) {
  read_ecc[0] = test_ecc[0];
  read_ecc[1] = test_ecc[1];
  read_ecc[2] = test_ecc[2];
  return 1;
 }
 return -1;
}

canonical_original_code:
int yaffs_ecc_correct(unsigned char *data, unsigned char *read_ecc, unsigned char *test_ecc)
{
 unsigned char d0; unsigned char d1; unsigned char d2;
 d0 = read_ecc[0] ^ test_ecc[0];
 d1 = read_ecc[1] ^ test_ecc[1];
 d2 = read_ecc[2] ^ test_ecc[2];
 if ((d0 | d1 | d2) == 0)
  return 0;
 if (((d0 ^ (d0 >> 1)) & 0x55) == 0x55 &&
     ((d1 ^ (d1 >> 1)) & 0x55) == 0x55 &&
     ((d2 ^ (d2 >> 1)) & 0x54) == 0x54) {
  unsigned int byte;
  unsigned int bit;
  bit = byte = 0;
  if (d1 & 0x80)
   byte |= 0x80;
  if (d1 & 0x20)
   byte |= 0x40;
  if (d1 & 0x08)
   byte |= 0x20;
  if (d1 & 0x02)
   byte |= 0x10;
  if (d0 & 0x80)
   byte |= 0x08;
  if (d0 & 0x20)
   byte |= 0x04;
  if (d0 & 0x08)
   byte |= 0x02;
  if (d0 & 0x02)
   byte |= 0x01;
  if (d2 & 0x80)
   bit |= 0x04;
  if (d2 & 0x20)
   bit |= 0x02;
  if (d2 & 0x08)
   bit |= 0x01;
  data[byte] ^= (1 << bit);
  return 1;
 }
 if ((yaffs_hweight8(d0) +
      yaffs_hweight8(d1) +
      yaffs_hweight8(d2)) == 1) {
  read_ecc[0] = test_ecc[0];
  read_ecc[1] = test_ecc[1];
  read_ecc[2] = test_ecc[2];
  return 1;
 }
 return -1;
}

variable_types:
data
unsigned char *

variable_types:
byte
unsigned int

variable_types:
bit
unsigned int


original_code:
void yaffs_ecc_calc_other(const unsigned char *data, unsigned n_bytes,
     struct yaffs_ecc_other *ecc_other)
{
 unsigned int i;
 unsigned char col_parity = 0;
 unsigned line_parity = 0;
 unsigned line_parity_prime = 0;
 unsigned char b;
 for (i = 0; i < n_bytes; i++) {
  b = column_parity_table[*data++];
  col_parity ^= b;
  if (b & 0x01) {
   line_parity ^= i;
   line_parity_prime ^= ~i;
  }
 }
 ecc_other->col_parity = (col_parity >> 2) & 0x3f;
 ecc_other->line_parity = line_parity;
 ecc_other->line_parity_prime = line_parity_prime;
}

canonical_original_code:
void yaffs_ecc_calc_other(unsigned char *data, unsigned int n_bytes, struct yaffs_ecc_other *ecc_other)
{
 unsigned int i;
 unsigned char col_parity = 0;
 unsigned int line_parity = 0;
 unsigned int line_parity_prime = 0;
 unsigned char b;
 for (i = 0; i < n_bytes; i++) {
  b = column_parity_table[*data++];
  col_parity ^= b;
  if (b & 0x01) {
   line_parity ^= i;
   line_parity_prime ^= ~i;
  }
 }
 ecc_other->col_parity = (col_parity >> 2) & 0x3f;
 ecc_other->line_parity = line_parity;
 ecc_other->line_parity_prime = line_parity_prime;
}

variable_types: struct yaffs_ecc_other { unsigned char col_parity; unsigned int line_parity; unsigned int line_parity_prime; } *

variable_types:
i
unsigned int

variable_types:
b
unsigned char


decompiled_code:
__int64 __fastcall yaffs_ecc_correct_other(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4)
{
unsigned int v7; // ebp
__int64 v8; // rdi
unsigned int v9; // er14
__int64 result; // rax
__int64 v11; // rcx
int v12; // ebx
__int64 v13; // rdx
__int64 v14; // rcx
__int64 v15; // r8
int v16; // ebx
int v17; // ecx

v7 = *a3;
LOBYTE(v7) = *(_BYTE *)a4 ^ v7;
v8 = (unsigned int)(*(_DWORD *)(a4 + 4) ^ *((_DWORD *)a3 + 1));
v9 = *(_DWORD *)(a4 + 8) ^ *((_DWORD *)a3 + 2);
result = 0LL;
v11 = (unsigned __int8)v7 | v9 | *(_DWORD *)(a4 + 4) ^ *((_DWORD *)a3 + 1);
if ( (_DWORD)v11 )
{
if ( ~v9 == (_DWORD)v8 && (((unsigned __int8)v7 ^ ((unsigned __int8)v7 >> 1)) & 0x15) == 21 )
{
v17 = (v7 >> 3) & 4;
if ( (v7 & 8) != 0 )
v17 = (v7 >> 3) & 4 | 2;
if ( (v7 & 2) != 0 )
LOBYTE(v17) = v17 | 1;
result = 0xFFFFFFFFLL;
if ( (unsigned int)v8 < (unsigned int)a2 )
{
*(_BYTE *)(a1 + (unsigned int)v8) ^= 1 << v17;
result = 1LL;
}
}
else
{
v12 = yaffs_hweight32(v8, a2, (unsigned __int8)v7, v11, a1);
v16 = yaffs_hweight32(v9, a2, v13, v14, v15) + v12;
result = v16 + (unsigned int)yaffs_hweight8((unsigned __int8)v7);
if ( (_DWORD)result == 1 )
{
*(_QWORD *)a3 = *(_QWORD *)a4;
*((_DWORD *)a3 + 2) = *(_DWORD *)(a4 + 8);
}
else
{
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4)
{
unsigned int v7; // ebp
__int64 v8; // rdi
unsigned int v9; // er14
__int64 result; // rax
__int64 v11; // rcx
int v12; // ebx
__int64 v13; // rdx
__int64 v14; // rcx
__int64 v15; // r8
int v16; // ebx
int v17; // ecx

v7 = *a3;
LOBYTE(v7) = *(_BYTE *)a4 ^ v7;
v8 = (unsigned int)(*(_DWORD *)(a4 + 4) ^ *((_DWORD *)a3 + 1));
v9 = *(_DWORD *)(a4 + 8) ^ *((_DWORD *)a3 + 2);
result = 0LL;
v11 = (unsigned __int8)v7 | v9 | *(_DWORD *)(a4 + 4) ^ *((_DWORD *)a3 + 1);
if ( (_DWORD)v11 )
{
if ( ~v9 == (_DWORD)v8 && (((unsigned __int8)v7 ^ ((unsigned __int8)v7 >> 1)) & 0x15) == 21 )
{
v17 = (v7 >> 3) & 4;
if ( (v7 & 8) != 0 )
v17 = (v7 >> 3) & 4 | 2;
if ( (v7 & 2) != 0 )
LOBYTE(v17) = v17 | 1;
result = 0xFFFFFFFFLL;
if ( (unsigned int)v8 < (unsigned int)a2 )
{
*(_BYTE *)(a1 + (unsigned int)v8) ^= 1 << v17;
result = 1LL;
}
}
else
{
v12 = yaffs_hweight32(v8, a2, (unsigned __int8)v7, v11, a1);
v16 = yaffs_hweight32(v9, a2, v13, v14, v15) + v12;
result = v16 + (unsigned int)yaffs_hweight8((unsigned __int8)v7);
if ( (_DWORD)result == 1 )
{
*(_QWORD *)a3 = *(_QWORD *)a4;
*((_DWORD *)a3 + 2) = *(_DWORD *)(a4 + 8);
}
else
{
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int yaffs_ecc_correct_other(unsigned char *data, unsigned n_bytes,
       struct yaffs_ecc_other *read_ecc,
       const struct yaffs_ecc_other *test_ecc)
{
 unsigned char delta_col;
 unsigned delta_line;
 unsigned delta_line_prime;
 unsigned bit;
 delta_col = read_ecc->col_parity ^ test_ecc->col_parity;
 delta_line = read_ecc->line_parity ^ test_ecc->line_parity;
 delta_line_prime =
     read_ecc->line_parity_prime ^ test_ecc->line_parity_prime;
 if ((delta_col | delta_line | delta_line_prime) == 0)
  return 0;
 if (delta_line == ~delta_line_prime &&
     (((delta_col ^ (delta_col >> 1)) & 0x15) == 0x15)) {
  bit = 0;
  if (delta_col & 0x20)
   bit |= 0x04;
  if (delta_col & 0x08)
   bit |= 0x02;
  if (delta_col & 0x02)
   bit |= 0x01;
  if (delta_line >= n_bytes)
   return -1;
  data[delta_line] ^= (1 << bit);
  return 1;
 }
 if ((yaffs_hweight32(delta_line) +
      yaffs_hweight32(delta_line_prime) +
      yaffs_hweight8(delta_col)) == 1) {
  *read_ecc = *test_ecc;
  return 1;
 }
 return -1;
}

canonical_original_code:
int yaffs_ecc_correct_other(unsigned char *data, unsigned int n_bytes, struct yaffs_ecc_other *read_ecc, struct yaffs_ecc_other *test_ecc)
{
 unsigned char delta_col;
 unsigned int delta_line;
 unsigned int delta_line_prime;
 unsigned int bit;
 delta_col = read_ecc->col_parity ^ test_ecc->col_parity;
 delta_line = read_ecc->line_parity ^ test_ecc->line_parity;
 delta_line_prime =
     read_ecc->line_parity_prime ^ test_ecc->line_parity_prime;
 if ((delta_col | delta_line | delta_line_prime) == 0)
  return 0;
 if (delta_line == ~delta_line_prime &&
     (((delta_col ^ (delta_col >> 1)) & 0x15) == 0x15)) {
  bit = 0;
  if (delta_col & 0x20)
   bit |= 0x04;
  if (delta_col & 0x08)
   bit |= 0x02;
  if (delta_col & 0x02)
   bit |= 0x01;
  if (delta_line >= n_bytes)
   return -1;
  data[delta_line] ^= (1 << bit);
  return 1;
 }
 if ((yaffs_hweight32(delta_line) +
      yaffs_hweight32(delta_line_prime) +
      yaffs_hweight8(delta_col)) == 1) {
  *read_ecc = *test_ecc;
  return 1;
 }
 return -1;
}

user_defined_types: struct yaffs_ecc_other { unsigned char col_parity; unsigned int line_parity; unsigned int line_parity_prime; }


variable_types: struct yaffs_obj_hdr { enum yaffs_obj_type { YAFFS_OBJECT_TYPE_UNKNOWN=0, YAFFS_OBJECT_TYPE_FILE=1, YAFFS_OBJECT_TYPE_SYMLINK=2, YAFFS_OBJECT_TYPE_DIRECTORY=3, YAFFS_OBJECT_TYPE_HARDLINK=4, YAFFS_OBJECT_TYPE_SPECIAL=5 } type; int parent_obj_id; unsigned short sum_no_longer_used; char name[-1]; unsigned int yst_mode; unsigned int yst_uid; unsigned int yst_gid; unsigned int yst_atime; unsigned int yst_mtime; unsigned int yst_ctime; unsigned int file_size_low; int equiv_id; char alias[-1]; unsigned int yst_rdev; unsigned int win_ctime[2]; unsigned int win_atime[2]; unsigned int win_mtime[2]; unsigned int inband_shadowed_obj_id; unsigned int inband_is_shrink; unsigned int file_size_high; unsigned int reserved[1]; int shadows_obj; unsigned int is_shrink; } *

user_defined_types: struct yaffs_obj_hdr { enum yaffs_obj_type type; int parent_obj_id; unsigned short sum_no_longer_used; char name[-1]; unsigned int yst_mode; unsigned int yst_uid; unsigned int yst_gid; unsigned int yst_atime; unsigned int yst_mtime; unsigned int yst_ctime; unsigned int file_size_low; int equiv_id; char alias[-1]; unsigned int yst_rdev; unsigned int win_ctime[2]; unsigned int win_atime[2]; unsigned int win_mtime[2]; unsigned int inband_shadowed_obj_id; unsigned int inband_is_shrink; unsigned int file_size_high; unsigned int reserved[1]; int shadows_obj; unsigned int is_shrink; }


variable_types:
reverse
unsigned int

variable_types: union yaffs_tags_union { struct yaffs_tags { unsigned int chunk_id; unsigned int serial_number; unsigned int n_bytes_lsb; unsigned int obj_id; unsigned int ecc; unsigned int n_bytes_msb; } as_tags; unsigned char as_bytes[8]; } *

variable_types:
pb
unsigned char *

variable_types:
tb
unsigned char *

user_defined_types: union yaffs_tags_union { struct yaffs_tags as_tags; unsigned char as_bytes[8]; }


variable_types: struct yaffs_packed_tags2 { struct yaffs_packed_tags2_tags_only { unsigned int seq_number; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; } t; struct yaffs_ecc_other { unsigned char col_parity; unsigned int line_parity; unsigned int line_parity_prime; } ecc; } *

variable_types: struct yaffs_packed_tags2_tags_only { unsigned int seq_number; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; } *

user_defined_types: struct yaffs_packed_tags2 { struct yaffs_packed_tags2_tags_only t; struct yaffs_ecc_other ecc; }


original_code:
void
packedtags2_eccother_endian_transform (struct yaffs_packed_tags2 *t)
{
 struct yaffs_ecc_other *e = &t->ecc;
 e->line_parity = ((((e->line_parity) & 0x000000ff) << 24) | (((e->line_parity) & 0x0000ff00) << 8) | (((e->line_parity) & 0x00ff0000) >> 8) | (((e->line_parity) & 0xff000000) >> 24));
 e->line_parity_prime = ((((e->line_parity_prime) & 0x000000ff) << 24) | (((e->line_parity_prime) & 0x0000ff00) << 8) | (((e->line_parity_prime) & 0x00ff0000) >> 8) | (((e->line_parity_prime) & 0xff000000) >> 24));
}

canonical_original_code:
void packedtags2_eccother_endian_transform(struct yaffs_packed_tags2 *t)
{
 struct yaffs_ecc_other *e = &t->ecc;
 e->line_parity = ((((e->line_parity) & 0x000000ff) << 24) | (((e->line_parity) & 0x0000ff00) << 8) | (((e->line_parity) & 0x00ff0000) >> 8) | (((e->line_parity) & 0xff000000) >> 24));
 e->line_parity_prime = ((((e->line_parity_prime) & 0x000000ff) << 24) | (((e->line_parity_prime) & 0x0000ff00) << 8) | (((e->line_parity_prime) & 0x00ff0000) >> 8) | (((e->line_parity_prime) & 0xff000000) >> 24));
}

user_defined_types: struct yaffs_packed_tags2_tags_only { unsigned int seq_number; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; }


decompiled_code:
__int64 __fastcall yaffs_hweight8(unsigned __int8 a1)
{
return (unsigned int)yaffs_count_bits_table[a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
return (unsigned int)yaffs_count_bits_table[a1];
}

original_code:
int yaffs_hweight8(u8 x)
{
 int ret_val;
 ret_val = yaffs_count_bits_table[x];
 return ret_val;
}

canonical_original_code:
int yaffs_hweight8(unsigned char x)
{
 int ret_val;
 ret_val = yaffs_count_bits_table[x];
 return ret_val;
}

variable_types:
x
unsigned char


decompiled_code:
__int64 __fastcall yaffs_hweight32(int a1)
{
int v1; // ebx
int v2; // ebx
int v3; // ebx

v1 = yaffs_hweight8(a1);
v2 = yaffs_hweight8(BYTE1(a1)) + v1;
v3 = yaffs_hweight8(BYTE2(a1)) + v2;
return v3 + (unsigned int)yaffs_hweight8(HIBYTE(a1));
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // ebx
int v2; // ebx
int v3; // ebx

v1 = func0(a1);
v2 = func0(BYTE1(a1)) + v1;
v3 = func0(BYTE2(a1)) + v2;
return v3 + (unsigned int)func0(HIBYTE(a1));
}

original_code:
int yaffs_hweight32(u32 x)
{
 return yaffs_hweight8(x & 0xff) +
  yaffs_hweight8((x >> 8) & 0xff) +
  yaffs_hweight8((x >> 16) & 0xff) +
  yaffs_hweight8((x >> 24) & 0xff);
}

canonical_original_code:
int yaffs_hweight32(unsigned int x)
{
 return yaffs_hweight8(x & 0xff) +
  yaffs_hweight8((x >> 8) & 0xff) +
  yaffs_hweight8((x >> 16) & 0xff) +
  yaffs_hweight8((x >> 24) & 0xff);
}

variable_types:
x
unsigned int


decompiled_code:
void __fastcall progress_winch_updater(int a1)
{
int v1; // edx
int v2; // eax
char v3[2]; // [rsp+0h] [rbp-10h] BYREF
unsigned __int16 v4; // [rsp+2h] [rbp-Eh]

if ( a1 == 28 )
{
v1 = ioctl(1, 0x5413uLL, v3);
v2 = 80;
if ( v1 >= 0 )
v2 = v4;
yaffs2_progress_columns = v2;
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int v1; // edx
int v2; // eax
char v3[2]; // [rsp+0h] [rbp-10h] BYREF
unsigned __int16 v4; // [rsp+2h] [rbp-Eh]

if ( a1 == 28 )
{
v1 = ioctl(1, 0x5413uLL, v3);
v2 = 80;
if ( v1 >= 0 )
v2 = v4;
yaffs2_progress_columns = v2;
}
}

original_code:
static void
progress_winch_updater (int sig)
{
 int retval;
 struct winsize wsize;
 if (sig != 28)
  return;
 retval = ioctl(1, 0x5413, &wsize);
 yaffs2_progress_columns = retval < 0 ? 80 : wsize.ws_col;
}

canonical_original_code:
static void progress_winch_updater(int sig)
{
 int retval;
 struct winsize wsize;
 if (sig != 28)
  return;
 retval = ioctl(1, 0x5413, &wsize);
 yaffs2_progress_columns = retval < 0 ? 80 : wsize.ws_col;
}

variable_types: sig int

variable_types: retval int

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


original_code:
void
progress_bar (unsigned current, unsigned max)
{
 int maxdigits = ceil(log10(max));
 int used = maxdigits * 2 + 10;
 int hashes = (current * (yaffs2_progress_columns - used)) / max;
 int spaces = yaffs2_progress_columns - used - hashes;
 if (yaffs2_progress_columns - used < 0)
  return;
 printf("\r[");
 while (hashes-- > 0)
  putchar('=');
 while (spaces-- > 0)
  putchar(' ');
 printf("] %*u/%*u", maxdigits, current, maxdigits, max);
 printf(" %3u%%", current * 100 / max);
 fflush(stdout);
}

canonical_original_code:
void progress_bar(unsigned int current, unsigned int max)
{
 int maxdigits = ceil(log10(max));
 int used = maxdigits * 2 + 10;
 int hashes = (current * (yaffs2_progress_columns - used)) / max;
 int spaces = yaffs2_progress_columns - used - hashes;
 if (yaffs2_progress_columns - used < 0)
  return;
 printf("\r[");
 while (hashes-- > 0)
  putchar('=');
 while (spaces-- > 0)
  putchar(' ');
 printf("] %*u/%*u", maxdigits, current, maxdigits, max);
 printf(" %3u%%", current * 100 / max);
 fflush(stdout);
}

variable_types:
current
unsigned int

variable_types:
max
unsigned int

variable_types: maxdigits int

variable_types: used int

variable_types: hashes int

variable_types: spaces int


decompiled_code:
__int64 progress_init()
{
progress_winch_updater(28);
signal(28, progress_winch_updater);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
func0(28);
signal(28, progress_winch_updater);
return 0LL;
}

original_code:
int
progress_init (void)
{
 progress_winch_updater(28);
 signal(28, progress_winch_updater);
 return 0;
}

canonical_original_code:
int progress_init()
{
 progress_winch_updater(28);
 signal(28, progress_winch_updater);
 return 0;
}


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

result = 0LL;
if ( !*(_DWORD *)(a1 + 8) && *(_DWORD *)(a1 + 36) )
{
result = 1LL;
if ( *(_DWORD *)(a1 + 52) == 1 )
result = *(_QWORD *)(a1 + 56) >> 31 == 0LL;
}
return result;
}

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

result = 0LL;
if ( !*(_DWORD *)(a1 + 8) && *(_DWORD *)(a1 + 36) )
{
result = 1LL;
if ( *(_DWORD *)(a1 + 52) == 1 )
result = *(_QWORD *)(a1 + 56) >> 31 == 0LL;
}
return result;
}

original_code:
static int yaffs_check_tags_extra_packable(const struct yaffs_ext_tags *t)
{
 if(t->chunk_id != 0 || !t->extra_available)
  return 0;
 if (t->extra_obj_type == YAFFS_OBJECT_TYPE_FILE &&
     (t->extra_file_size>> 31) != 0)
  return 0;
 return 1;
}

canonical_original_code:
static int yaffs_check_tags_extra_packable(struct yaffs_ext_tags *t)
{
 if(t->chunk_id != 0 || !t->extra_available)
  return 0;
 if (t->extra_obj_type == YAFFS_OBJECT_TYPE_FILE &&
     (t->extra_file_size>> 31) != 0)
  return 0;
 return 1;
}

variable_types: struct yaffs_ext_tags { unsigned int chunk_used; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; enum yaffs_ecc_result { YAFFS_ECC_RESULT_UNKNOWN=0, YAFFS_ECC_RESULT_NO_ERROR=1, YAFFS_ECC_RESULT_FIXED=2, YAFFS_ECC_RESULT_UNFIXED=3 } ecc_result; unsigned int block_bad; unsigned int is_deleted; unsigned int serial_number; unsigned int seq_number; unsigned int extra_available; unsigned int extra_parent_id; unsigned int extra_is_shrink; unsigned int extra_shadows; enum yaffs_obj_type { YAFFS_OBJECT_TYPE_UNKNOWN=0, YAFFS_OBJECT_TYPE_FILE=1, YAFFS_OBJECT_TYPE_SYMLINK=2, YAFFS_OBJECT_TYPE_DIRECTORY=3, YAFFS_OBJECT_TYPE_HARDLINK=4, YAFFS_OBJECT_TYPE_SPECIAL=5 } extra_obj_type; long extra_file_size; unsigned int extra_equiv_id; } *


original_code:
void yaffs_pack_tags2_tags_only(struct yaffs_packed_tags2_tags_only *ptt,
    const struct yaffs_ext_tags *t)
{
 ptt->chunk_id = t->chunk_id;
 ptt->seq_number = t->seq_number;
 ptt->n_bytes = t->n_bytes;
 ptt->obj_id = t->obj_id;
 if (yaffs_check_tags_extra_packable(t)) {
  ptt->chunk_id = 0x80000000 | t->extra_parent_id;
  if (t->extra_is_shrink)
   ptt->chunk_id |= 0x40000000;
  if (t->extra_shadows)
   ptt->chunk_id |= 0x20000000;
  ptt->obj_id &= ~((0x0f) << (28));
  ptt->obj_id |= (t->extra_obj_type << (28));
  if (t->extra_obj_type == YAFFS_OBJECT_TYPE_HARDLINK)
   ptt->n_bytes = t->extra_equiv_id;
  else if (t->extra_obj_type == YAFFS_OBJECT_TYPE_FILE)
   ptt->n_bytes = (unsigned) t->extra_file_size;
  else
   ptt->n_bytes = 0;
 }
 yaffs_dump_packed_tags2_tags_only(ptt);
 yaffs_dump_tags2(t);
}

canonical_original_code:
void yaffs_pack_tags2_tags_only(struct yaffs_packed_tags2_tags_only *ptt, struct yaffs_ext_tags *t)
{
 ptt->chunk_id = t->chunk_id;
 ptt->seq_number = t->seq_number;
 ptt->n_bytes = t->n_bytes;
 ptt->obj_id = t->obj_id;
 if (yaffs_check_tags_extra_packable(t)) {
  ptt->chunk_id = 0x80000000 | t->extra_parent_id;
  if (t->extra_is_shrink)
   ptt->chunk_id |= 0x40000000;
  if (t->extra_shadows)
   ptt->chunk_id |= 0x20000000;
  ptt->obj_id &= ~((0x0f) << (28));
  ptt->obj_id |= (t->extra_obj_type << (28));
  if (t->extra_obj_type == YAFFS_OBJECT_TYPE_HARDLINK)
   ptt->n_bytes = t->extra_equiv_id;
  else if (t->extra_obj_type == YAFFS_OBJECT_TYPE_FILE)
   ptt->n_bytes = (unsigned int) t->extra_file_size;
  else
   ptt->n_bytes = 0;
 }
 yaffs_dump_packed_tags2_tags_only(ptt);
 yaffs_dump_tags2(t);
}


decompiled_code:
__int64 __fastcall yaffs_pack_tags2(_DWORD *a1, __int64 a2, int a3)
{
__int64 result; // rax

result = yaffs_pack_tags2_tags_only(a1, a2);
if ( a3 )
result = yaffs_ecc_calc_other(a1, 16LL, a1 + 4);
return result;
}

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

result = func1(a1, a2);
if ( a3 )
result = yaffs_ecc_calc_other(a1, 16LL, a1 + 4);
return result;
}

original_code:
void yaffs_pack_tags2(struct yaffs_packed_tags2 *pt,
        const struct yaffs_ext_tags *t, int tags_ecc)
{
 yaffs_pack_tags2_tags_only(&pt->t, t);
 if (tags_ecc)
  yaffs_ecc_calc_other((unsigned char *)&pt->t,
        sizeof(struct yaffs_packed_tags2_tags_only),
        &pt->ecc);
}

canonical_original_code:
void yaffs_pack_tags2(struct yaffs_packed_tags2 *pt, struct yaffs_ext_tags *t, int tags_ecc)
{
 yaffs_pack_tags2_tags_only(&pt->t, t);
 if (tags_ecc)
  yaffs_ecc_calc_other((unsigned char *)&pt->t,
        sizeof(struct yaffs_packed_tags2_tags_only),
        &pt->ecc);
}


original_code:
void yaffs_unpack_tags2_tags_only(struct yaffs_ext_tags *t,
      struct yaffs_packed_tags2_tags_only *ptt)
{
 memset(t, 0, sizeof(struct yaffs_ext_tags));
 if (ptt->seq_number == 0xffffffff)
  return;
 t->block_bad = 0;
 t->chunk_used = 1;
 t->obj_id = ptt->obj_id;
 t->chunk_id = ptt->chunk_id;
 t->n_bytes = ptt->n_bytes;
 t->is_deleted = 0;
 t->serial_number = 0;
 t->seq_number = ptt->seq_number;
 if (ptt->chunk_id & 0x80000000) {
  t->chunk_id = 0;
  t->n_bytes = 0;
  t->extra_available = 1;
  t->extra_parent_id = ptt->chunk_id & (~(0xf0000000));
  t->extra_is_shrink = ptt->chunk_id & 0x40000000 ? 1 : 0;
  t->extra_shadows = ptt->chunk_id & 0x20000000 ? 1 : 0;
  t->extra_obj_type = ptt->obj_id >> (28);
  t->obj_id &= ~((0x0f) << (28));
  if (t->extra_obj_type == YAFFS_OBJECT_TYPE_HARDLINK)
   t->extra_equiv_id = ptt->n_bytes;
  else
   t->extra_file_size = ptt->n_bytes;
 }
 yaffs_dump_packed_tags2_tags_only(ptt);
 yaffs_dump_tags2(t);
}


decompiled_code:
void __fastcall yaffs_unpack_tags2(__int64 a1, _DWORD *a2, int a3)
{
int v3; // ebp
int v4; // eax
char v5[36]; // [rsp+4h] [rbp-24h] BYREF

if ( *a2 != -1 && a3 )
{
yaffs_ecc_calc_other(a2, 16LL, v5);
v4 = yaffs_ecc_correct_other(a2, 16LL, a2 + 4, v5);
v3 = 1;
if ( v4 )
{
v3 = 2;
if ( v4 != 1 )
v3 = 3 * (v4 == -1);
}
}
else
{
v3 = 1;
}
yaffs_unpack_tags2_tags_only(a1, a2);
*(_DWORD *)(a1 + 16) = v3;
}

original_code:
void yaffs_unpack_tags2(struct yaffs_ext_tags *t, struct yaffs_packed_tags2 *pt,
   int tags_ecc)
{
 enum yaffs_ecc_result ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
 if (pt->t.seq_number != 0xffffffff && tags_ecc) {
  struct yaffs_ecc_other ecc;
  int result;
  yaffs_ecc_calc_other((unsigned char *)&pt->t,
    sizeof(struct yaffs_packed_tags2_tags_only),
    &ecc);
  result =
      yaffs_ecc_correct_other((unsigned char *)&pt->t,
    sizeof(struct yaffs_packed_tags2_tags_only),
    &pt->ecc, &ecc);
  switch (result) {
  case 0:
   ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
   break;
  case 1:
   ecc_result = YAFFS_ECC_RESULT_FIXED;
   break;
  case -1:
   ecc_result = YAFFS_ECC_RESULT_UNFIXED;
   break;
  default:
   ecc_result = YAFFS_ECC_RESULT_UNKNOWN;
  }
 }
 yaffs_unpack_tags2_tags_only(t, &pt->t);
 t->ecc_result = ecc_result;
 yaffs_dump_packed_tags2(pt);
 yaffs_dump_tags2(t);
}

variable_types: enum yaffs_ecc_result { YAFFS_ECC_RESULT_UNKNOWN=0, YAFFS_ECC_RESULT_NO_ERROR=1, YAFFS_ECC_RESULT_FIXED=2, YAFFS_ECC_RESULT_UNFIXED=3 }

variable_types: struct yaffs_ecc_other { unsigned char col_parity; unsigned int line_parity; unsigned int line_parity_prime; }

variable_types: result int


repo: juur/FailOS

decompiled_code:
__int64 __fastcall pci_write_conf32(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned int a5)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return outportl(3324LL, a5);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned int a5)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return outportl(3324LL, a5);
}

original_code:
void pci_write_conf32(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t val)
{
 uint32_t port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 outportl(0xcfc, val);
}

canonical_original_code:
void pci_write_conf32(unsigned char bus, unsigned char dev, unsigned char func, unsigned char reg, unsigned int val)
{
 unsigned int port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 outportl(0xcfc, val);
}

variable_types:
bus
unsigned char

variable_types:
dev
unsigned char

variable_types:
func
unsigned char

variable_types:
reg
unsigned char

variable_types:
val
unsigned int

variable_types:
port
unsigned int


decompiled_code:
__int64 __fastcall pci_write_conf16(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int16 a5)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return outportw((a4 & 2u) + 3324, a5);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int16 a5)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return outportw((a4 & 2u) + 3324, a5);
}

original_code:
void pci_write_conf16(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint16_t val)
{
 uint32_t port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 outportw((uint16_t)(0xcfc + (reg&2)), val);
}

canonical_original_code:
void pci_write_conf16(unsigned char bus, unsigned char dev, unsigned char func, unsigned char reg, unsigned short val)
{
 unsigned int port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 outportw((unsigned short)(0xcfc + (reg&2)), val);
}

variable_types:
val
unsigned short


decompiled_code:
__int64 __fastcall pci_read_conf32(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportl(3324LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportl(3324LL);
}

original_code:
uint32_t pci_read_conf32(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
{
 uint32_t ret;
 uint32_t port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportl(0xcfc);
 return ret;
}

canonical_original_code:
unsigned int pci_read_conf32(unsigned char bus, unsigned char dev, unsigned char func, unsigned char reg)
{
 unsigned int ret;
 unsigned int port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportl(0xcfc);
 return ret;
}

variable_types:
ret
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall pci_read_conf16(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportw((a4 & 2u) + 3324);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportw((a4 & 2u) + 3324);
}

original_code:
uint16_t pci_read_conf16(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
{
 uint16_t ret;
 uint32_t port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportw((uint16_t)(0xcfc + (reg&2)));
 return ret;
}

canonical_original_code:
unsigned short pci_read_conf16(unsigned char bus, unsigned char dev, unsigned char func, unsigned char reg)
{
 unsigned short ret;
 unsigned int port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportw((unsigned short)(0xcfc + (reg&2)));
 return ret;
}

variable_types:
ret
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall pci_read_conf8(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportb((a4 & 3u) + 3324);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportb((a4 & 3u) + 3324);
}

original_code:
uint8_t pci_read_conf8(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
{
 uint8_t ret;
 uint32_t port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportb((uint16_t)(0xcfc + (reg&3)));
 return ret;
}

canonical_original_code:
unsigned char pci_read_conf8(unsigned char bus, unsigned char dev, unsigned char func, unsigned char reg)
{
 unsigned char ret;
 unsigned int port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportb((unsigned short)(0xcfc + (reg&3)));
 return ret;
}

variable_types:
ret
unsigned char

return_type: unsigned char


decompiled_code:
int __fastcall print_pci_dev(__int64 a1)
{
int result; // eax
unsigned int *v2; // rbx
unsigned int i; // ebp
__int64 v4; // rdx
const char *v5; // r8

printf(
"pci_dev: %x:%x [%x,%x,%x] REV:%x %x:%x",
*(unsigned __int16 *)(a1 + 11),
*(unsigned __int16 *)(a1 + 13),
*(unsigned __int8 *)(a1 + 22),
*(unsigned __int8 *)(a1 + 21),
*(unsigned __int8 *)(a1 + 20),
*(unsigned __int8 *)(a1 + 19),
*(unsigned __int16 *)(a1 + 55),
*(unsigned __int16 *)(a1 + 57));
if ( *(_WORD *)(a1 + 71) )
printf(" int[0x%x,0x%x]", *(unsigned __int8 *)(a1 + 71), *(unsigned __int8 *)(a1 + 72));
result = printf("\n");
v2 = (unsigned int *)(a1 + 76);
for ( i = 0; i != 6; ++i )
{
v4 = *v2;
if ( (_DWORD)v4 )
{
v5 = (const char *)&unk_644;
if ( *((_BYTE *)v2 + 10) )
v5 = (const char *)&unk_640;
result = printf("pci_dev: bar[%x] 0x%x[%x] %s\n", i, v4, v2[1], v5);
}
v2 += 3;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int result; // eax
unsigned int *v2; // rbx
unsigned int i; // ebp
__int64 v4; // rdx
const char *v5; // r8

printf(
"pci_dev: %x:%x [%x,%x,%x] REV:%x %x:%x",
*(unsigned __int16 *)(a1 + 11),
*(unsigned __int16 *)(a1 + 13),
*(unsigned __int8 *)(a1 + 22),
*(unsigned __int8 *)(a1 + 21),
*(unsigned __int8 *)(a1 + 20),
*(unsigned __int8 *)(a1 + 19),
*(unsigned __int16 *)(a1 + 55),
*(unsigned __int16 *)(a1 + 57));
if ( *(_WORD *)(a1 + 71) )
printf(" int[0x%x,0x%x]", *(unsigned __int8 *)(a1 + 71), *(unsigned __int8 *)(a1 + 72));
result = printf("\n");
v2 = (unsigned int *)(a1 + 76);
for ( i = 0; i != 6; ++i )
{
v4 = *v2;
if ( (_DWORD)v4 )
{
v5 = (const char *)&unk_644;
if ( *((_BYTE *)v2 + 10) )
v5 = (const char *)&unk_640;
result = printf("pci_dev: bar[%x] 0x%x[%x] %s\n", i, v4, v2[1], v5);
}
v2 += 3;
}
return result;
}

original_code:
void print_pci_dev(struct pci_dev *d)
{
 int i;
 printf("pci_dev: %x:%x [%x,%x,%x] REV:%x %x:%x",
   d->cfg.vendor_id,
   d->cfg.device_id,
   d->cfg.class_code,
   d->cfg.subclass,
   d->cfg.progif,
   d->cfg.rev,
   d->cfg.sub_vendor_id,
   d->cfg.sub_id
    );
 if(d->cfg.int_line || d->cfg.int_pin) {
  printf(" int[0x%x,0x%x]", d->cfg.int_line, d->cfg.int_pin);
 }
 printf("\n");
 for(i=0;i<6;i++)
 {
  if(!d->bars[i].addr) continue;
  printf("pci_dev:   bar[%x] 0x%x[%x] %s\n",
    i, d->bars[i].addr, d->bars[i].len,
    d->bars[i].mem ? "MEM" : "IO");
 }
}

variable_types: struct pci_dev { struct pci_dev *next; unsigned char bus; struct pcicfg { unsigned short vendor_id; unsigned short device_id; unsigned short cmd_reg; unsigned short status_reg; unsigned int rev; unsigned char progif; unsigned char subclass; unsigned char class_code; unsigned char pad0; unsigned char pad1; unsigned char header_type; unsigned char pad2; unsigned int bar[6]; unsigned int pad3; unsigned short sub_vendor_id; unsigned short sub_id; unsigned int pad4; unsigned int pad5; unsigned int res0; unsigned int res1; unsigned char int_line; unsigned char int_pin; unsigned char pad6; unsigned char pad7; } cfg; struct pcibar { unsigned int addr; unsigned int len; union { struct { unsigned char pad; } io; struct { unsigned char bits; unsigned char prefs; } mem; } un; _Bool mem; } bars[6]; } *

variable_types: i int

user_defined_types: struct pci_dev { struct pci_dev *next; unsigned char bus; struct pcicfg cfg; struct pcibar bars[6]; }


original_code:
struct pci_dev *add_pci_device(int bus, int dev, int func)
{
 struct pci_dev *ret;
 uint32_t vend_id,dev_id,class,subclass,prog,rev_id,subsys,subsysvend,header,intr,intrl;
 uint32_t bar_save,bar_addr,bits,pref;
 int bar;
 int tmp,off;
 dev_id = pci_read_conf16(bus,dev,func,0x2);
 vend_id = pci_read_conf16(bus,dev,func,0x0);
 class = pci_read_conf8(bus,dev,func,0x9 +2);
 subclass = pci_read_conf8(bus,dev,func,0x9 +1);
 prog = pci_read_conf8(bus,dev,func,0x9);
 if(class == 0xff && subclass == 0xff) return ((void*)0);
 rev_id = pci_read_conf8(bus,dev,func,0x8);
 subsys = pci_read_conf16(bus,dev,func,0x2e);
 subsysvend = pci_read_conf16(bus,dev,func,0x2c);
 header = pci_read_conf8(bus,dev,func,0xe);
 intr = pci_read_conf8(bus,dev,func,0x3d);
 intrl = pci_read_conf8(bus,dev,func,0x3c);
 if(header != 0x80 && header != 0x00 ) {
  printf("add_pci: %x:%x does not support header=%x PCI-to-PCI/Cardbus\n", vend_id, dev_id, header);
  return ((void*)0);
 }
 ret = kmalloc(sizeof(struct pci_dev),"pcidev", ((void*)0), 0);
 if(!ret) return ((void*)0);
 ret->cfg.vendor_id = vend_id;
 ret->cfg.device_id = dev_id;
 ret->cfg.rev = rev_id;
 ret->cfg.class_code = class;
 ret->cfg.subclass = subclass;
 ret->cfg.progif = prog;
 ret->cfg.header_type = header;
 ret->cfg.sub_vendor_id = subsysvend;
 ret->cfg.sub_id = subsys;
 ret->cfg.int_line = intrl;
 ret->cfg.int_pin = intr;
 ret->bus = bus;
 ret->dev = dev;
 ret->func = func;
 for(bar=0;bar<6;bar++) {
  bar_save = bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
  if(bar_addr == 0x0) {
   continue;
  } else if(bar_addr & 1) {
   ret->bars[bar].mem = 0;
   bar_addr &= 0xfffffffc;
   ret->bars[bar].addr = bar_addr;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)),0xffffffff);
   bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
   bar_addr &= 0xfffffffc;
   ret->bars[bar].len = (~bar_addr)+1;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)), bar_save);
  } else {
   ret->bars[bar].mem = 1;
   ret->bars[bar].un.mem.bits = bits = (bar_addr & 0x06) >> 1;
   ret->bars[bar].un.mem.prefs = pref = (bar_addr & 0x08) >> 3;
   if(bits) {
    printf("PCI: non-32bit BARs unsupported");
    bar = 6;
    continue;
   }
   bar_addr &= 0xfffffff0;
   ret->bars[bar].addr = bar_addr;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)),0xffffffff);
   bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
   bar_addr &= 0xfffffff0;
   ret->bars[bar].len = (~bar_addr)+1;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)), bar_save);
   tmp = ret->bars[bar].len;
   off = 0;
   while(tmp>0) {
    if(!create_page_entry_4k(kernel_pd,
      ret->bars[bar].addr + off,
      ret->bars[bar].addr + off,
      0x001|0x002, ((void*)0)))
     goto fail;
    tmp -= (1024*4);
    off += (1024*4);
   }
  }
 }
 ret->next = pci_devs;
 pci_devs = ret;
 print_pci_dev(ret);
 switch(ret->cfg.vendor_id) {
  case 0x1022:
   switch(ret->cfg.device_id) {
    case 0x2000:
     init_nic_pcnet(ret);
     break;
    default:
     goto unknown;
   }
   break;
  case 0x8086:
   switch(ret->cfg.device_id) {
    case 0x7010:
    case 0x7111:
     if(ret->cfg.class_code == 0x01) {
      init_ide(ret);
      goto unknown;
      break;
     }
     goto unknown;
     break;
    case 0x2922:
     init_ahci(ret);
     break;
    default:
     goto unknown;
   }
   break;
  default:
   goto unknown;
 }
 return(ret);
unknown:
 return(ret);
fail:
 if(ret) kfree(ret);
 return ((void*)0);
}

canonical_original_code:
struct pci_dev *add_pci_device(int bus, int dev, int func)
{
 struct pci_dev *ret;
 unsigned int vend_id; unsigned int dev_id; unsigned int class; unsigned int subclass; unsigned int prog; unsigned int rev_id; unsigned int subsys; unsigned int subsysvend; unsigned int header; unsigned int intr; unsigned int intrl;
 unsigned int bar_save; unsigned int bar_addr; unsigned int bits; unsigned int pref;
 int bar;
 int tmp; int off;
 dev_id = pci_read_conf16(bus,dev,func,0x2);
 vend_id = pci_read_conf16(bus,dev,func,0x0);
 class = pci_read_conf8(bus,dev,func,0x9 +2);
 subclass = pci_read_conf8(bus,dev,func,0x9 +1);
 prog = pci_read_conf8(bus,dev,func,0x9);
 if(class == 0xff && subclass == 0xff) return ((void *)0);
 rev_id = pci_read_conf8(bus,dev,func,0x8);
 subsys = pci_read_conf16(bus,dev,func,0x2e);
 subsysvend = pci_read_conf16(bus,dev,func,0x2c);
 header = pci_read_conf8(bus,dev,func,0xe);
 intr = pci_read_conf8(bus,dev,func,0x3d);
 intrl = pci_read_conf8(bus,dev,func,0x3c);
 if(header != 0x80 && header != 0x00 ) {
  printf("add_pci: %x:%x does not support header=%x PCI-to-PCI/Cardbus\n", vend_id, dev_id, header);
  return ((void *)0);
 }
 ret = kmalloc(sizeof(struct pci_dev),"pcidev", ((void *)0), 0);
 if(!ret) return ((void *)0);
 ret->cfg.vendor_id = vend_id;
 ret->cfg.device_id = dev_id;
 ret->cfg.rev = rev_id;
 ret->cfg.class_code = class;
 ret->cfg.subclass = subclass;
 ret->cfg.progif = prog;
 ret->cfg.header_type = header;
 ret->cfg.sub_vendor_id = subsysvend;
 ret->cfg.sub_id = subsys;
 ret->cfg.int_line = intrl;
 ret->cfg.int_pin = intr;
 ret->bus = bus;
 ret->dev = dev;
 ret->func = func;
 for(bar=0;bar<6;bar++) {
  bar_save = bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
  if(bar_addr == 0x0) {
   continue;
  } else if(bar_addr & 1) {
   ret->bars[bar].mem = 0;
   bar_addr &= 0xfffffffc;
   ret->bars[bar].addr = bar_addr;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)),0xffffffff);
   bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
   bar_addr &= 0xfffffffc;
   ret->bars[bar].len = (~bar_addr)+1;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)), bar_save);
  } else {
   ret->bars[bar].mem = 1;
   ret->bars[bar].un.mem.bits = bits = (bar_addr & 0x06) >> 1;
   ret->bars[bar].un.mem.prefs = pref = (bar_addr & 0x08) >> 3;
   if(bits) {
    printf("PCI: non-32bit BARs unsupported");
    bar = 6;
    continue;
   }
   bar_addr &= 0xfffffff0;
   ret->bars[bar].addr = bar_addr;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)),0xffffffff);
   bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
   bar_addr &= 0xfffffff0;
   ret->bars[bar].len = (~bar_addr)+1;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)), bar_save);
   tmp = ret->bars[bar].len;
   off = 0;
   while(tmp>0) {
    if(!create_page_entry_4k(kernel_pd,
      ret->bars[bar].addr + off,
      ret->bars[bar].addr + off,
      0x001|0x002, ((void *)0)))
     goto fail;
    tmp -= (1024*4);
    off += (1024*4);
   }
  }
 }
 ret->next = pci_devs;
 pci_devs = ret;
 print_pci_dev(ret);
 switch(ret->cfg.vendor_id) {
  case 0x1022:
   switch(ret->cfg.device_id) {
    case 0x2000:
     init_nic_pcnet(ret);
     break;
    default:
     goto unknown;
   }
   break;
  case 0x8086:
   switch(ret->cfg.device_id) {
    case 0x7010:
    case 0x7111:
     if(ret->cfg.class_code == 0x01) {
      init_ide(ret);
      goto unknown;
      break;
     }
     goto unknown;
     break;
    case 0x2922:
     init_ahci(ret);
     break;
    default:
     goto unknown;
   }
   break;
  default:
   goto unknown;
 }
 return(ret);
unknown:
 return(ret);
fail:
 if(ret) kfree(ret);
 return ((void *)0);
}

variable_types: bus int

variable_types: dev int

variable_types: func int

variable_types:
class
unsigned int

variable_types:
subclass
unsigned int

variable_types:
prog
unsigned int

variable_types:
subsys
unsigned int

variable_types:
subsysvend
unsigned int

variable_types:
header
unsigned int

variable_types:
intr
unsigned int

variable_types:
intrl
unsigned int

variable_types:
bits
unsigned int

variable_types:
pref
unsigned int

variable_types: bar int

variable_types: tmp int

variable_types: off int

return_type: struct pci_dev { struct pci_dev *next; unsigned char bus; struct pcicfg { unsigned short vendor_id; unsigned short device_id; unsigned short cmd_reg; unsigned short status_reg; unsigned int rev; unsigned char progif; unsigned char subclass; unsigned char class_code; unsigned char pad0; unsigned char pad1; unsigned char header_type; unsigned char pad2; unsigned int bar[6]; unsigned int pad3; unsigned short sub_vendor_id; unsigned short sub_id; unsigned int pad4; unsigned int pad5; unsigned int res0; unsigned int res1; unsigned char int_line; unsigned char int_pin; unsigned char pad6; unsigned char pad7; } cfg; struct pcibar { unsigned int addr; unsigned int len; union { struct { unsigned char pad; } io; struct { unsigned char bits; unsigned char prefs; } mem; } un; _Bool mem; } bars[6]; } *


original_code:
void init_ahci(struct pci_dev *d)
{
 uint32_t mem = d->bars[5].addr;
 struct GHC *ghc;
 struct PORT *port;
 struct _PxCMD cmd;
 int num,i;
 ghc = (struct GHC *)(0L + mem);
 if(ghc->CAP2 & (1 << 0)) {
  printf("init_ahci: BOH\n");
  ghc->BOHC |= 0x2;
 }
 ghc->GHC |= (1 << 0);
 ghc->GHC |= (1 << 31);
 printf("init_ahci: CAP: %x CAP2: %x GHC: %x BOHC: %x\n"
   "init_ahci: CAP.NP: %x CAP.S64A: %x CAP.NCS: %x\n",
   ghc->CAP.b,
   ghc->CAP2,
   ghc->GHC,
   ghc->BOHC,
   ghc->CAP.a.NP,
   ghc->CAP.a.S64A,
   ghc->CAP.a.NCS
   );
 printf("init_ahci: PI: %x VS: %x\n",
   ghc->PI,
   ghc->VS
    );
 for(num = 0; num < ghc->CAP.a.NP; num++) {
  if(!((1 << num) & ghc->PI)) continue;
  printf("init_ahci: port[%x]: ", num);
  port = (struct PORT *)(0L + mem + 0x100 + (num * 0x80));
  if( port->PxSSTS.a.det != 0x3 ) {
   printf("DET failed\n");
   continue;
  }
  cmd = port->PxCMD.a;
  printf("cmd=%x ", port->PxCMD.b);
  if( !(cmd.ST || cmd.CR || cmd.FRE || cmd.FR) ) {
   printf("port not idle %d%d%d%d ",
     cmd.ST,
     cmd.CR,
     cmd.FRE,
     cmd.FR
     );
  }
  printf("PxIS: %x ", port->PxIS);
  printf("PxCMD: %x (ATAPI:%s POD:%x) ",
    port->PxCMD.b,
    port->PxCMD.a.ATAPI ? "Y" : "N",
    port->PxCMD.a.POD);
  printf("\ninit_ahci: port[%x]: CH %p ", num, (void *)port->PxCLB);
  struct SIG pxsig;
  uint32_t pxsigtmp = port->PxSIG.b;
  if (pxsigtmp != 0xffffffff) {
   pxsig = *(struct SIG *)&pxsigtmp;
   printf("PxSIG: [%x %x.%x.%x] ",
     pxsig.sector,
     pxsig.lba_low, pxsig.lba_mid, pxsig.lba_high);
  }
  printf("PxSSTS{ DET:%x SPD:%x IPM:%x } ",
    port->PxSSTS.a.det,
    port->PxSSTS.a.spd,
    port->PxSSTS.a.ipm);
  if((port->PxCLB = (struct CommandHeader *)kmalloc_align((sizeof(struct CommandHeader) * 32), "PxCLB", ((void*)0), 0)) == ((void*)0)) {
   printf("malloc failed PxCLB\n");
   continue;
  }
  if((port->PxFB = (uint64_t)kmalloc_align(4096, "PxFB", ((void*)0),0)) == 0) {
   printf("malloc failed PxCLB\n");
   kfree(port->PxCLB);
   continue;
  }
  port->PxCLB->CFL = 4;
  port->PxCMD.a.FRE = 1;
  port->PxSERR = 0;
  port->PxCMD.a.ST = 1;
  for(i=0;i<10000000;i++) ;
  pxsigtmp = port->PxSIG.b;
  if (pxsigtmp != 0xffffffff) {
   pxsig = *(struct SIG *)&pxsigtmp;
   printf("PxSIG: [%x %x.%x.%x] ",
     pxsig.sector,
     pxsig.lba_low, pxsig.lba_mid, pxsig.lba_high);
  }
  printf("\n");
 }
}

canonical_original_code:
void init_ahci(struct pci_dev *d)
{
 unsigned int mem = d->bars[5].addr;
 struct GHC *ghc;
 struct PORT *port;
 struct _PxCMD cmd;
 int num; int i;
 ghc = (struct GHC *)(0L + mem);
 if(ghc->CAP2 & (1 << 0)) {
  printf("init_ahci: BOH\n");
  ghc->BOHC |= 0x2;
 }
 ghc->GHC |= (1 << 0);
 ghc->GHC |= (1 << 31);
 printf("init_ahci: CAP: %x CAP2: %x GHC: %x BOHC: %x\n"
   "init_ahci: CAP.NP: %x CAP.S64A: %x CAP.NCS: %x\n",
   ghc->CAP.b,
   ghc->CAP2,
   ghc->GHC,
   ghc->BOHC,
   ghc->CAP.a.NP,
   ghc->CAP.a.S64A,
   ghc->CAP.a.NCS
   );
 printf("init_ahci: PI: %x VS: %x\n",
   ghc->PI,
   ghc->VS
    );
 for(num = 0; num < ghc->CAP.a.NP; num++) {
  if(!((1 << num) & ghc->PI)) continue;
  printf("init_ahci: port[%x]: ", num);
  port = (struct PORT *)(0L + mem + 0x100 + (num * 0x80));
  if( port->PxSSTS.a.det != 0x3 ) {
   printf("DET failed\n");
   continue;
  }
  cmd = port->PxCMD.a;
  printf("cmd=%x ", port->PxCMD.b);
  if( !(cmd.ST || cmd.CR || cmd.FRE || cmd.FR) ) {
   printf("port not idle %d%d%d%d ",
     cmd.ST,
     cmd.CR,
     cmd.FRE,
     cmd.FR
     );
  }
  printf("PxIS: %x ", port->PxIS);
  printf("PxCMD: %x (ATAPI:%s POD:%x) ",
    port->PxCMD.b,
    port->PxCMD.a.ATAPI ? "Y" : "N",
    port->PxCMD.a.POD);
  printf("\ninit_ahci: port[%x]: CH %p ", num, (void *)port->PxCLB);
  struct SIG pxsig;
  unsigned int pxsigtmp = port->PxSIG.b;
  if (pxsigtmp != 0xffffffff) {
   pxsig = *(struct SIG *)&pxsigtmp;
   printf("PxSIG: [%x %x.%x.%x] ",
     pxsig.sector,
     pxsig.lba_low, pxsig.lba_mid, pxsig.lba_high);
  }
  printf("PxSSTS{ DET:%x SPD:%x IPM:%x } ",
    port->PxSSTS.a.det,
    port->PxSSTS.a.spd,
    port->PxSSTS.a.ipm);
  if((port->PxCLB = (struct CommandHeader *)kmalloc_align((sizeof(struct CommandHeader) * 32), "PxCLB", ((void *)0), 0)) == ((void *)0)) {
   printf("malloc failed PxCLB\n");
   continue;
  }
  if((port->PxFB = (unsigned long)kmalloc_align(4096, "PxFB", ((void *)0),0)) == 0) {
   printf("malloc failed PxCLB\n");
   kfree(port->PxCLB);
   continue;
  }
  port->PxCLB->CFL = 4;
  port->PxCMD.a.FRE = 1;
  port->PxSERR = 0;
  port->PxCMD.a.ST = 1;
  for(i=0;i<10000000;i++) ;
  pxsigtmp = port->PxSIG.b;
  if (pxsigtmp != 0xffffffff) {
   pxsig = *(struct SIG *)&pxsigtmp;
   printf("PxSIG: [%x %x.%x.%x] ",
     pxsig.sector,
     pxsig.lba_low, pxsig.lba_mid, pxsig.lba_high);
  }
  printf("\n");
 }
}

variable_types: struct pci_dev { struct pci_dev *next; unsigned char bus; struct pcicfg { unsigned short vendor_id; unsigned short device_id; unsigned short cmd_reg; unsigned short status_reg; unsigned int rev; unsigned char progif; unsigned char subclass; unsigned char class_code; unsigned char pad0; unsigned char pad1; unsigned char header_type; unsigned char pad2; unsigned int bar[6]; unsigned int pad3; unsigned short sub_vendor_id; unsigned short sub_id; unsigned int pad4; unsigned int pad5; unsigned int res0; unsigned int res1; unsigned char int_line; unsigned char int_pin; unsigned char pad6; unsigned char pad7; } cfg; struct pcibar { unsigned int addr; unsigned int len; union { struct { unsigned char pad; } io; struct { unsigned char bits; unsigned char prefs; } mem; } un; _Bool mem; } bars[6]; } *

variable_types:
mem
unsigned int

variable_types: struct GHC { union { struct _CAP { int NP; int SXS; int EMS; int CCCS; int NCS; int PSC; int SSC; int PMD; int FBSS; int SPM; int SAM; int res; int ISS; int SCLO; int SAL; int SALP; int SSS; int SMPS; int SSNTF; int SNCQ; int S64A; } a; unsigned int b; } CAP; unsigned int GHC; unsigned int IS; unsigned int PI; unsigned int VS; unsigned int CCC_CTL; unsigned int CCC_PORTS; unsigned int EM_LOC; unsigned int EM_CTL; unsigned int CAP2; unsigned int BOHC; } *

variable_types: struct PORT { struct CommandHeader { int CFL; int A; int W; int P; int R; int B; int C; int res; int PMP; int PRDTL; unsigned int PRDBC; struct CommandTable { unsigned char CFIS[64]; unsigned char ACMD[16]; unsigned char res[32]; } *CTBA; unsigned int dw_res[4]; } *PxCLB; unsigned long PxFB; unsigned int PxIS; unsigned int PxIE; union { struct _PxCMD { unsigned int ST; unsigned int SUD; unsigned int POD; unsigned int CLO; unsigned int FRE; unsigned int res; unsigned int CCS; unsigned int MPSS; unsigned int FR; unsigned int CR; unsigned int CPS; unsigned int PMA; unsigned int HPCP; unsigned int MPSP; unsigned int CPD; unsigned int ESP; unsigned int FBSCP; unsigned int APSTE; unsigned int ATAPI; unsigned int DLAE; unsigned int ALPE; unsigned int ASP; unsigned int ICC; } a; unsigned int b; } PxCMD; unsigned int res0; unsigned int PxTFD; union { struct SIG { unsigned int sector; unsigned int lba_low; unsigned int lba_mid; unsigned int lba_high; } a; unsigned int b; } PxSIG; union { struct SSTS { unsigned int det; unsigned int spd; unsigned int ipm; unsigned int res; } a; unsigned int b; } PxSSTS; unsigned int PxSCTL; unsigned int PxSERR; unsigned int PxSACT; unsigned int PxCI; unsigned int PxSNTF; unsigned int PxFBS; unsigned char res1[44]; unsigned char PxVS[16]; } *

variable_types: num int

variable_types: i int

variable_types:
pxsigtmp
unsigned int

user_defined_types: struct CommandHeader { int CFL; int A; int W; int P; int R; int B; int C; int res; int PMP; int PRDTL; unsigned int PRDBC; struct CommandTable *CTBA; unsigned int dw_res[4]; }

user_defined_types: struct GHC { union { struct _CAP a; unsigned int b; } CAP; unsigned int GHC; unsigned int IS; unsigned int PI; unsigned int VS; unsigned int CCC_CTL; unsigned int CCC_PORTS; unsigned int EM_LOC; unsigned int EM_CTL; unsigned int CAP2; unsigned int BOHC; }

user_defined_types: struct PORT { struct CommandHeader *PxCLB; unsigned long PxFB; unsigned int PxIS; unsigned int PxIE; union { struct _PxCMD a; unsigned int b; } PxCMD; unsigned int res0; unsigned int PxTFD; union { struct SIG a; unsigned int b; } PxSIG; union { struct SSTS a; unsigned int b; } PxSSTS; unsigned int PxSCTL; unsigned int PxSERR; unsigned int PxSACT; unsigned int PxCI; unsigned int PxSNTF; unsigned int PxFBS; unsigned char res1[44]; unsigned char PxVS[16]; }


decompiled_code:
unsigned __int64 get_cr3()
{
return __readcr3();
}

canonical_decompiled_code:
unsigned __int64 func0()
{
return __readcr3();
}

original_code:
static inline pt_t *get_cr3(void)
{
 uint64_t ret;
 __asm__ volatile("mov %%cr3, %0":"=r"(ret));
 return (pt_t*)ret;
}

canonical_original_code:
static inline union pt_t *get_cr3()
{
 unsigned long ret;
 __asm__ volatile("mov %%cr3, %0":"=r"(ret));
 return (union pt_t *)ret;
}

variable_types:
ret
unsigned long

return_type: union pt_t { struct pe_t { unsigned int present; unsigned int write; unsigned int user; unsigned int pwt; unsigned int pcd; unsigned int access; unsigned int dirty; unsigned int last; unsigned int global; unsigned int cow; unsigned int avl; unsigned long base; unsigned int avail; unsigned int nx; } table_pe[512]; unsigned long table_u64[512]; } *

user_defined_types: union pt_t { struct pe_t table_pe[512]; unsigned long table_u64[512]; }


decompiled_code:
unsigned __int64 get_cr2()
{
return __readcr2();
}

canonical_decompiled_code:
unsigned __int64 func1()
{
return __readcr2();
}

original_code:
static inline uint64_t get_cr2(void)
{
 uint64_t ret;
 __asm__ volatile("mov %%cr2, %0":"=r"(ret));
 return ret;
}

canonical_original_code:
static inline unsigned long get_cr2()
{
 unsigned long ret;
 __asm__ volatile("mov %%cr2, %0":"=r"(ret));
 return ret;
}

return_type: unsigned long


decompiled_code:
unsigned __int64 get_cr0()
{
return __readcr0();
}

canonical_decompiled_code:
unsigned __int64 func2()
{
return __readcr0();
}

original_code:
static inline uint64_t get_cr0(void)
{
 uint64_t ret;
 __asm__ volatile("mov %%cr0, %0":"=r"(ret));
 return ret;
}

canonical_original_code:
static inline unsigned long get_cr0()
{
 unsigned long ret;
 __asm__ volatile("mov %%cr0, %0":"=r"(ret));
 return ret;
}