checkDir

decompiled_code:
__int64 __fastcall checkDir(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 result; // rax
int v5; // er12
int v6; // er13
unsigned int v7; // er14
_BOOL4 v8; // er15
unsigned int v9; // eax
unsigned int *v10; // rbx
__int64 v11; // rdi
unsigned int v12; // eax
size_t v13; // rdx
void *v14; // rsp
bool v15; // zf
__int64 v16; // rcx
size_t v17; // rdx
void *v18; // rsp
__int64 v19; // rcx
_BYTE v20[8]; // [rsp+0h] [rbp-50h] BYREF
__int64 v21; // [rsp+8h] [rbp-48h]
__int64 v22; // [rsp+10h] [rbp-40h]
int v23; // [rsp+18h] [rbp-38h]
int v24; // [rsp+1Ch] [rbp-34h]

v21 = a1;
v22 = a2;
v23 = a4;
result = *(unsigned int *)(a1 + 4);
v24 = result;
if ( (int)result > 0 )
{
v5 = 0;
v6 = 0;
v7 = a3 + 1;
while ( 1 )
{
v10 = (unsigned int *)(v22 + v5);
if ( ++v6 == 1 )
break;
if ( v6 == 2 )
{
if ( *((_BYTE *)v10 + 6) == 2
&& (v17 = strnlen((const char *)v10 + 8, 2uLL),
v18 = alloca(v17 + 9),
v20[v17] = 0,
v15 = strcmp((const char *)memcpy(v20, v10 + 2, v17), "..") == 0,
v8 = !v15,
v15) )
{
v19 = *v10;
if ( (_DWORD)v19 != v23 )
{
printf(
"Error: Partition %d Dir Inode %d: .. has wrong dir->inode %d, change to its parent\n",
partitionNumber,
v7,
v19);
*v10 = v23;
v8 = 1;
}
}
else
{
printf("Error: Partition %d Dir Inode %d: second dir is not .., change to ..\n", partitionNumber, v7);
*((_BYTE *)v10 + 6) = 2;
*((_BYTE *)v10 + 8) = 46;
*((_BYTE *)v10 + 9) = 46;
*v10 = v7;
v8 = 1;
}
LABEL_5:
v9 = localNo(*v10);
checkDirInode(v9, v7);
if ( v8 )
writeDisk(
(unsigned int)(v5 + (start << 9) + blockSize * *(_DWORD *)(v21 + 40)),
*((unsigned __int16 *)v10 + 2),
v10);
goto LABEL_7;
}
v11 = *v10;
if ( (_DWORD)v11 )
{
v12 = localNo(v11);
checkDirInode(v12, v7);
}
LABEL_7:
result = *((unsigned __int16 *)v10 + 2);
v5 += result;
if ( v24 <= v5 )
return result;
}
if ( *((_BYTE *)v10 + 6) == 1
&& (v13 = strnlen((const char *)v10 + 8, 1uLL),
v14 = alloca(v13 + 9),
v20[v13] = 0,
v15 = strcmp((const char *)memcpy(v20, v10 + 2, v13), ".") == 0,
v8 = !v15,
v15) )
{
v16 = *v10;
if ( (_DWORD)v16 != v7 )
{
printf(
"Error: Partition %d Dir Inode %d: . has wrong dir->inode %d, change to itself\n",
partitionNumber,
v7,
v16);
*v10 = v7;
v8 = 1;
}
}
else
{
printf("Error: Partition %d Dir Inode %d: first dir is not ., change to .\n", partitionNumber, v7);
*((_BYTE *)v10 + 6) = 1;
*((_BYTE *)v10 + 8) = 46;
*v10 = v7;
v8 = 1;
}
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 result; // rax
int v5; // er12
int v6; // er13
unsigned int v7; // er14
_BOOL4 v8; // er15
unsigned int v9; // eax
unsigned int *v10; // rbx
__int64 v11; // rdi
unsigned int v12; // eax
size_t v13; // rdx
void *v14; // rsp
bool v15; // zf
__int64 v16; // rcx
size_t v17; // rdx
void *v18; // rsp
__int64 v19; // rcx
_BYTE v20[8]; // [rsp+0h] [rbp-50h] BYREF
__int64 v21; // [rsp+8h] [rbp-48h]
__int64 v22; // [rsp+10h] [rbp-40h]
int v23; // [rsp+18h] [rbp-38h]
int v24; // [rsp+1Ch] [rbp-34h]

v21 = a1;
v22 = a2;
v23 = a4;
result = *(unsigned int *)(a1 + 4);
v24 = result;
if ( (int)result > 0 )
{
v5 = 0;
v6 = 0;
v7 = a3 + 1;
while ( 1 )
{
v10 = (unsigned int *)(v22 + v5);
if ( ++v6 == 1 )
break;
if ( v6 == 2 )
{
if ( *((_BYTE *)v10 + 6) == 2
&& (v17 = strnlen((const char *)v10 + 8, 2uLL),
v18 = alloca(v17 + 9),
v20[v17] = 0,
v15 = strcmp((const char *)memcpy(v20, v10 + 2, v17), "..") == 0,
v8 = !v15,
v15) )
{
v19 = *v10;
if ( (_DWORD)v19 != v23 )
{
printf(
"Error: Partition %d Dir Inode %d: .. has wrong dir->inode %d, change to its parent\n",
partitionNumber,
v7,
v19);
*v10 = v23;
v8 = 1;
}
}
else
{
printf("Error: Partition %d Dir Inode %d: second dir is not .., change to ..\n", partitionNumber, v7);
*((_BYTE *)v10 + 6) = 2;
*((_BYTE *)v10 + 8) = 46;
*((_BYTE *)v10 + 9) = 46;
*v10 = v7;
v8 = 1;
}
LABEL_5:
v9 = localNo(*v10);
func0(v9, v7);
if ( v8 )
writeDisk(
(unsigned int)(v5 + (start << 9) + blockSize * *(_DWORD *)(v21 + 40)),
*((unsigned __int16 *)v10 + 2),
v10);
goto LABEL_7;
}
v11 = *v10;
if ( (_DWORD)v11 )
{
v12 = localNo(v11);
func0(v12, v7);
}
LABEL_7:
result = *((unsigned __int16 *)v10 + 2);
v5 += result;
if ( v24 <= v5 )
return result;
}
if ( *((_BYTE *)v10 + 6) == 1
&& (v13 = strnlen((const char *)v10 + 8, 1uLL),
v14 = alloca(v13 + 9),
v20[v13] = 0,
v15 = strcmp((const char *)memcpy(v20, v10 + 2, v13), ".") == 0,
v8 = !v15,
v15) )
{
v16 = *v10;
if ( (_DWORD)v16 != v7 )
{
printf(
"Error: Partition %d Dir Inode %d: . has wrong dir->inode %d, change to itself\n",
partitionNumber,
v7,
v16);
*v10 = v7;
v8 = 1;
}
}
else
{
printf("Error: Partition %d Dir Inode %d: first dir is not ., change to .\n", partitionNumber, v7);
*((_BYTE *)v10 + 6) = 1;
*((_BYTE *)v10 + 8) = 46;
*v10 = v7;
v8 = 1;
}
goto LABEL_5;
}
return result;
}

original_code:
void checkDir(struct ext2_inode *inode, unsigned char *buf, int localId, int parent) {
 int changeDir = 0;
 int n = 0;
 int tempSize = 0;
 int totalSize = inode->i_size;
 struct ext2_dir_entry_2 *dir;
 while (tempSize < totalSize) {
  changeDir = 0;
  dir = (struct ext2_dir_entry_2 *)(buf + tempSize);
  ++n;
  if (n == 1) {
   if (dir->name_len == 1 && strcmp((__extension__ ({ const char *__old = (dir->name); size_t __len = strnlen (__old, (dir->name_len)); char *__new = (char *) __builtin_alloca (__len + 1); __new[__len] = '\0'; (char *) memcpy (__new, __old, __len); })), ".") == 0) {
    if (dir->inode != localId + 1) {
     printf("Error: Partition %d Dir Inode %d: . has wrong dir->inode %d, change to itself\n", partitionNumber, localId + 1, dir->inode);
     dir->inode = localId + 1;
     changeDir = 1;
    }
   } else {
    printf("Error: Partition %d Dir Inode %d: first dir is not ., change to .\n", partitionNumber, localId + 1);
    dir->name_len = 1;
    dir->name[0] = '.';
    dir->inode = localId + 1;
    changeDir = 1;
   }
   checkDirInode(localNo(dir->inode), localId + 1);
  } else if (n == 2) {
   if (dir->name_len == 2 && strcmp((__extension__ ({ const char *__old = (dir->name); size_t __len = strnlen (__old, (dir->name_len)); char *__new = (char *) __builtin_alloca (__len + 1); __new[__len] = '\0'; (char *) memcpy (__new, __old, __len); })), "..") == 0) {
    if (dir->inode != parent) {
     printf("Error: Partition %d Dir Inode %d: .. has wrong dir->inode %d, change to its parent\n", partitionNumber, localId + 1, dir->inode);
     dir->inode = parent;
     changeDir = 1;
    }
   } else {
    printf("Error: Partition %d Dir Inode %d: second dir is not .., change to ..\n", partitionNumber, localId + 1);
    dir->name_len = 2;
    dir->name[0] = '.';
    dir->name[1] = '.';
    dir->inode = localId + 1;
    changeDir = 1;
   }
   checkDirInode(localNo(dir->inode), localId + 1);
  } else {
   if (dir->inode != 0)
    checkDirInode(localNo(dir->inode), localId + 1);
  }
  if (changeDir)
   writeDisk(start * 512 + inode->i_block[0] * blockSize + tempSize, dir->rec_len, dir);
  tempSize += dir->rec_len;
 }
}

canonical_original_code:
void checkDir(struct ext2_inode *inode, unsigned char *buf, int localId, int parent) {
 int changeDir = 0;
 int n = 0;
 int tempSize = 0;
 int totalSize = inode->i_size;
 struct ext2_dir_entry_2 *dir;
 while (tempSize < totalSize) {
  changeDir = 0;
  dir = (struct ext2_dir_entry_2 *)(buf + tempSize);
  ++n;
  if (n == 1) {
   if (dir->name_len == 1 && strcmp((__extension__ ({ char *__old = (dir->name); unsigned long __len = strnlen (__old, (dir->name_len)); char *__new = (char *) __builtin_alloca (__len + 1); __new[__len] = '\0'; (char *) memcpy (__new, __old, __len); })), ".") == 0) {
    if (dir->inode != localId + 1) {
     printf("Error: Partition %d Dir Inode %d: . has wrong dir->inode %d, change to itself\n", partitionNumber, localId + 1, dir->inode);
     dir->inode = localId + 1;
     changeDir = 1;
    }
   } else {
    printf("Error: Partition %d Dir Inode %d: first dir is not ., change to .\n", partitionNumber, localId + 1);
    dir->name_len = 1;
    dir->name[0] = '.';
    dir->inode = localId + 1;
    changeDir = 1;
   }
   checkDirInode(localNo(dir->inode), localId + 1);
  } else if (n == 2) {
   if (dir->name_len == 2 && strcmp((__extension__ ({ char *__old = (dir->name); unsigned long __len = strnlen (__old, (dir->name_len)); char *__new = (char *) __builtin_alloca (__len + 1); __new[__len] = '\0'; (char *) memcpy (__new, __old, __len); })), "..") == 0) {
    if (dir->inode != parent) {
     printf("Error: Partition %d Dir Inode %d: .. has wrong dir->inode %d, change to its parent\n", partitionNumber, localId + 1, dir->inode);
     dir->inode = parent;
     changeDir = 1;
    }
   } else {
    printf("Error: Partition %d Dir Inode %d: second dir is not .., change to ..\n", partitionNumber, localId + 1);
    dir->name_len = 2;
    dir->name[0] = '.';
    dir->name[1] = '.';
    dir->inode = localId + 1;
    changeDir = 1;
   }
   checkDirInode(localNo(dir->inode), localId + 1);
  } else {
   if (dir->inode != 0)
    checkDirInode(localNo(dir->inode), localId + 1);
  }
  if (changeDir)
   writeDisk(start * 512 + inode->i_block[0] * blockSize + tempSize, dir->rec_len, dir);
  tempSize += dir->rec_len;
 }
}

variable_types: changeDir int

variable_types: n int

variable_types: tempSize int

variable_types: totalSize int

variable_types: struct ext2_dir_entry_2 { unsigned int inode; unsigned short rec_len; unsigned char name_len; unsigned char file_type; char name[255]; } *

user_defined_types: struct ext2_inode { unsigned short i_mode; unsigned short i_uid; unsigned int i_size; unsigned int i_atime; unsigned int i_ctime; unsigned int i_mtime; unsigned int i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned int i_blocks; unsigned int i_flags; union { struct { unsigned int l_i_reserved1; } linux1; struct { unsigned int h_i_translator; } hurd1; struct { unsigned int m_i_reserved1; } masix1; } osd1; unsigned int i_block[-1]; unsigned int i_generation; unsigned int i_file_acl; unsigned int i_dir_acl; unsigned int i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned int l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned int h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned int m_i_reserved2[2]; } masix2; } osd2; }


repo: Vvnesaa/fsck

decompiled_code:
__int64 pass1()
{
unsigned int v0; // eax
__int64 v1; // rbx
__int64 result; // rax

v0 = localNo(2LL);
checkDirInode(v0, 2u);
v1 = inodeLink;
result = (int)localNo(2LL);
--*(_DWORD *)(v1 + 4LL * (int)result);
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // eax
__int64 v1; // rbx
__int64 result; // rax

v0 = localNo(2LL);
func0(v0, 2u);
v1 = inodeLink;
result = (int)localNo(2LL);
--*(_DWORD *)(v1 + 4LL * (int)result);
return result;
}

original_code:
void pass1() {
 checkDirInode(localNo(2), 2);
 inodeLink[localNo(2)]--;
}

return_type: void


findDirInode

decompiled_code:
__int64 __fastcall findDirInode(int a1, char *a2)
{
__int64 v2; // rbx
int v3; // er15
int v4; // er12
char *v5; // rbx
size_t v6; // rcx
void *v7; // rsp
const char *v8; // rax
unsigned int v9; // er13
char *s2; // [rsp+0h] [rbp-40h] BYREF
void *ptr; // [rsp+8h] [rbp-38h]

s2 = a2;
v2 = inodeTable + ((__int64)a1 << 7);
if ( (unsigned int)isDirectory(v2) )
{
ptr = malloc(*(unsigned int *)(v2 + 4));
getData(start, v2, blockSize, ptr);
v3 = *(_DWORD *)(v2 + 4);
if ( v3 <= 0 )
{
v9 = 0;
}
else
{
v4 = 0;
while ( 1 )
{
v5 = (char *)ptr + v4;
v6 = strnlen(v5 + 8, (unsigned __int8)v5[6]);
v7 = alloca(16 * ((v6 + 24) / 0x10));
*((_BYTE *)&s2 + v6) = 0;
v8 = (const char *)memcpy(&s2, v5 + 8, v6);
if ( !strcmp(v8, s2) )
break;
v4 += *((unsigned __int16 *)v5 + 2);
if ( v3 <= v4 )
{
v9 = 0;
goto LABEL_9;
}
}
v9 = *(_DWORD *)v5;
}
LABEL_9:
free(ptr);
}
else
{
v9 = 0;
printf("inode %d is not a directory\n", (unsigned int)(a1 + 1));
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, char *a2)
{
__int64 v2; // rbx
int v3; // er15
int v4; // er12
char *v5; // rbx
size_t v6; // rcx
void *v7; // rsp
const char *v8; // rax
unsigned int v9; // er13
char *s2; // [rsp+0h] [rbp-40h] BYREF
void *ptr; // [rsp+8h] [rbp-38h]

s2 = a2;
v2 = inodeTable + ((__int64)a1 << 7);
if ( (unsigned int)isDirectory(v2) )
{
ptr = malloc(*(unsigned int *)(v2 + 4));
getData(start, v2, blockSize, ptr);
v3 = *(_DWORD *)(v2 + 4);
if ( v3 <= 0 )
{
v9 = 0;
}
else
{
v4 = 0;
while ( 1 )
{
v5 = (char *)ptr + v4;
v6 = strnlen(v5 + 8, (unsigned __int8)v5[6]);
v7 = alloca(16 * ((v6 + 24) / 0x10));
*((_BYTE *)&s2 + v6) = 0;
v8 = (const char *)memcpy(&s2, v5 + 8, v6);
if ( !strcmp(v8, s2) )
break;
v4 += *((unsigned __int16 *)v5 + 2);
if ( v3 <= v4 )
{
v9 = 0;
goto LABEL_9;
}
}
v9 = *(_DWORD *)v5;
}
LABEL_9:
free(ptr);
}
else
{
v9 = 0;
printf("inode %d is not a directory\n", (unsigned int)(a1 + 1));
}
return v9;
}

original_code:
int findDirInode(int localId, const char *dirName) {
 int result = 0;
 struct ext2_dir_entry_2 *dir = 0;
 struct ext2_inode *root = inodeTable + localId;
 if (!isDirectory(root)) {
  printf("inode %d is not a directory\n", localId + 1);
  return result;
 }
 unsigned char *buf = malloc(root->i_size);
 getData(start, root, blockSize, buf);
 int tempSize = 0;
 int totalSize = root->i_size;
 while (tempSize < totalSize) {
  dir = (struct ext2_dir_entry_2 *)(buf + tempSize);
  if (strcmp((__extension__ ({ const char *__old = (dir->name); size_t __len = strnlen (__old, (dir->name_len)); char *__new = (char *) __builtin_alloca (__len + 1); __new[__len] = '\0'; (char *) memcpy (__new, __old, __len); })), dirName) == 0) {
   result = dir->inode;
   break;
  }
  tempSize += dir->rec_len;
 }
 free(buf);
 return result;
}

canonical_original_code:
int findDirInode(int localId, char *dirName) {
 int result = 0;
 struct ext2_dir_entry_2 *dir = 0;
 struct ext2_inode *root = inodeTable + localId;
 if (!isDirectory(root)) {
  printf("inode %d is not a directory\n", localId + 1);
  return result;
 }
 unsigned char *buf = malloc(root->i_size);
 getData(start, root, blockSize, buf);
 int tempSize = 0;
 int totalSize = root->i_size;
 while (tempSize < totalSize) {
  dir = (struct ext2_dir_entry_2 *)(buf + tempSize);
  if (strcmp((__extension__ ({ char *__old = (dir->name); unsigned long __len = strnlen (__old, (dir->name_len)); char *__new = (char *) __builtin_alloca (__len + 1); __new[__len] = '\0'; (char *) memcpy (__new, __old, __len); })), dirName) == 0) {
   result = dir->inode;
   break;
  }
  tempSize += dir->rec_len;
 }
 free(buf);
 return result;
}

variable_types: localId int

variable_types:
dirName
char *

variable_types: result int

variable_types: struct ext2_inode { unsigned short i_mode; unsigned short i_uid; unsigned int i_size; unsigned int i_atime; unsigned int i_ctime; unsigned int i_mtime; unsigned int i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned int i_blocks; unsigned int i_flags; union { struct { unsigned int l_i_reserved1; } linux1; struct { unsigned int h_i_translator; } hurd1; struct { unsigned int m_i_reserved1; } masix1; } osd1; unsigned int i_block[-1]; unsigned int i_generation; unsigned int i_file_acl; unsigned int i_dir_acl; unsigned int i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned int l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned int h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned int m_i_reserved2[2]; } masix2; } osd2; } *

variable_types:
buf
unsigned char *

return_type: int

user_defined_types: struct ext2_dir_entry_2 { unsigned int inode; unsigned short rec_len; unsigned char name_len; unsigned char file_type; char name[255]; }


setFileType

decompiled_code:
__int64 __fastcall setFileType(int a1)
{
__int64 v1; // rbx
int v2; // edx
__int64 result; // rax
int v4; // edx

v1 = inodeTable + ((__int64)a1 << 7);
v2 = isDirectory(v1);
result = 2LL;
if ( !v2 )
{
v4 = isRegFile(v1);
result = 1LL;
if ( !v4 )
{
result = isSymbolicLink(v1);
if ( (_DWORD)result )
result = 7LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rbx
int v2; // edx
__int64 result; // rax
int v4; // edx

v1 = inodeTable + ((__int64)a1 << 7);
v2 = isDirectory(v1);
result = 2LL;
if ( !v2 )
{
v4 = isRegFile(v1);
result = 1LL;
if ( !v4 )
{
result = isSymbolicLink(v1);
if ( (_DWORD)result )
result = 7LL;
}
}
return result;
}

original_code:
int setFileType(int localId) {
 struct ext2_inode *inode = inodeTable + localId;
 if (isDirectory(inode)) return EXT2_FT_DIR;
 if (isRegFile(inode)) return EXT2_FT_REG_FILE;
 if (isSymbolicLink(inode))return EXT2_FT_SYMLINK;
 return EXT2_FT_UNKNOWN;
}


addToLost

original_code:
void addToLost(struct ext2_inode *lost, int ID) {
 int totalSize = lost->i_size;
 unsigned char *buf = malloc(lost->i_size);
 getData(start, lost, blockSize, buf);
 int len = 2 + (int) floor(log10(ID));
 char *fileName = malloc(len);
 sprintf(fileName, "#%d", ID);
 int tempSize = 0;
 int n = 0;
 struct ext2_dir_entry_2 *temp;
 struct ext2_dir_entry_2 *other;
 int change = 0;
 while (tempSize < totalSize) {
  temp = (struct ext2_dir_entry_2 *)(buf + tempSize);
  ++n;
  if (n > 2) {
   if (temp->inode == 0 && temp->rec_len >= (((len) + 8 + (4 - 1)) & ~(4 - 1))) {
    temp->inode = ID;
    temp->file_type = setFileType(localNo(ID));
    printf("%d %d\n", ID, temp->file_type);
    temp->name_len = len;
    strcpy(temp->name, fileName);
    change = 1;
    break;
   } else if (temp->rec_len - (((temp->name_len) + 8 + (4 - 1)) & ~(4 - 1)) >= (((len) + 8 + (4 - 1)) & ~(4 - 1))) {
    other = (struct ext2_dir_entry_2 *)(buf + tempSize + (((temp->name_len) + 8 + (4 - 1)) & ~(4 - 1)));
    other->rec_len = temp->rec_len - (((temp->name_len) + 8 + (4 - 1)) & ~(4 - 1));
    other->inode = ID;
    other->file_type = setFileType(localNo(ID));
    printf("%d %d\n", ID, other->file_type);
    other->name_len = len;
    strcpy(other->name, fileName);
    temp->rec_len = (((temp->name_len) + 8 + (4 - 1)) & ~(4 - 1));
    change = 1;
    break;
   }
  }
  tempSize += temp->rec_len;
 }
 int i;
 tempSize = 0;
 for (i = 0; i < 12; ++i) {
  writeDisk(start * 512 + blockSize * lost->i_block[i], blockSize, buf + tempSize);
  tempSize += blockSize;
  if (tempSize >= totalSize) break;
 }
 free(buf);
 free(fileName);
}

variable_types: ID int

variable_types: len int

variable_types:
fileName
char *

variable_types: change int

variable_types: i int


updateParent

decompiled_code:
__int64 __fastcall updateParent(int *a1, int a2, double a3, double a4, double a5, double a6)
{
__int64 result; // rax
char *v8; // r15
__int64 v9; // rcx
int v10; // er13
int v11; // er12
int i; // ebp
char *v13; // rbx
__int64 v14; // rdi
int v15; // eax
_DWORD *v16; // rbp
_DWORD *v17; // r14
int v18; // ebx
__int64 v19; // rsi
__int64 v20; // [rsp+8h] [rbp-40h]

result = isDirectory(a1);
if ( (_DWORD)result )
{
v8 = (char *)malloc((unsigned int)a1[1]);
getData(start, a1, blockSize, v8);
v10 = a1[1];
if ( v10 > 0 )
{
v11 = 0;
for ( i = 0; i < v10; i += *((unsigned __int16 *)v13 + 2) )
{
++v11;
v13 = &v8[i];
if ( v11 == 2 )
{
puts("change inode's parent to lost+found");
*(_DWORD *)v13 = a2;
}
else if ( v11 > 2 )
{
v14 = *(unsigned int *)v13;
if ( (_DWORD)v14 )
{
v20 = inodeTable;
v15 = localNo(v14, a3, a4, a5, a6);
if ( (unsigned int)isDirectory(v20 + ((__int64)v15 << 7)) )
*(_DWORD *)v13 = 0;
}
}
}
}
v16 = a1 + 10;
v17 = a1 + 22;
v18 = 0;
do
{
v19 = (unsigned int)(v10 - v18);
if ( (int)v19 > blockSize )
v19 = blockSize;
writeDisk((unsigned int)((start << 9) + *v16 * blockSize), v19, &v8[v18], v9, a3, a4, a5, a6);
result = (unsigned int)(blockSize + v18);
v18 = result;
if ( v10 <= (int)result )
break;
++v16;
}
while ( v16 != v17 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, int a2, double a3, double a4, double a5, double a6)
{
__int64 result; // rax
char *v8; // r15
__int64 v9; // rcx
int v10; // er13
int v11; // er12
int i; // ebp
char *v13; // rbx
__int64 v14; // rdi
int v15; // eax
_DWORD *v16; // rbp
_DWORD *v17; // r14
int v18; // ebx
__int64 v19; // rsi
__int64 v20; // [rsp+8h] [rbp-40h]

result = isDirectory(a1);
if ( (_DWORD)result )
{
v8 = (char *)malloc((unsigned int)a1[1]);
getData(start, a1, blockSize, v8);
v10 = a1[1];
if ( v10 > 0 )
{
v11 = 0;
for ( i = 0; i < v10; i += *((unsigned __int16 *)v13 + 2) )
{
++v11;
v13 = &v8[i];
if ( v11 == 2 )
{
puts("change inode's parent to lost+found");
*(_DWORD *)v13 = a2;
}
else if ( v11 > 2 )
{
v14 = *(unsigned int *)v13;
if ( (_DWORD)v14 )
{
v20 = inodeTable;
v15 = localNo(v14, a3, a4, a5, a6);
if ( (unsigned int)isDirectory(v20 + ((__int64)v15 << 7)) )
*(_DWORD *)v13 = 0;
}
}
}
}
v16 = a1 + 10;
v17 = a1 + 22;
v18 = 0;
do
{
v19 = (unsigned int)(v10 - v18);
if ( (int)v19 > blockSize )
v19 = blockSize;
writeDisk((unsigned int)((start << 9) + *v16 * blockSize), v19, &v8[v18], v9, a3, a4, a5, a6);
result = (unsigned int)(blockSize + v18);
v18 = result;
if ( v10 <= (int)result )
break;
++v16;
}
while ( v16 != v17 );
}
return result;
}

original_code:
void updateParent(struct ext2_inode *inode, int parent) {
 if (!isDirectory(inode)) return;
 unsigned char *buf = malloc(inode->i_size);
 getData(start, inode, blockSize, buf);
 int tempSize = 0;
 int n = 0;
 int totalSize = inode->i_size;
 struct ext2_dir_entry_2 *dir;
 while (tempSize < totalSize) {
  ++n;
  dir = (struct ext2_dir_entry_2 *)(buf + tempSize);
  if (n == 2) {
   printf("change inode's parent to lost+found\n");
   dir->inode = parent;
  } else if (n > 2 && dir->inode != 0 && isDirectory(inodeTable + localNo(dir->inode))) {
   dir->inode = 0;
  }
  tempSize += dir->rec_len;
 }
 tempSize = 0;
 int i;
 int currentTemp;
 for (i = 0; i < 12; ++i) {
  if (totalSize - tempSize < blockSize)
   currentTemp = totalSize - tempSize;
  else
   currentTemp = blockSize;
  writeDisk(start * 512 + inode->i_block[i] * blockSize, currentTemp, buf + tempSize);
  tempSize += blockSize;
  if (tempSize >= totalSize) break;
 }
}

variable_types: parent int

variable_types: currentTemp int


decompiled_code:
int __fastcall pass2(double a1, double a2, double a3, double a4)
{
int v4; // eax
unsigned int v5; // eax
unsigned int v6; // er13
__int64 v7; // rdi
unsigned int v8; // er12
__int64 v9; // rbp
__int64 v11; // rbx
__int64 v12; // r14
int v13; // eax
__int64 v14; // rax

v4 = localNo(2LL, a1, a2, a3, a4);
v5 = findDirInode(v4, "lost+found");
if ( !v5 )
return puts("/lost+found is not found");
v6 = v5;
v7 = 11LL;
if ( x[19] )
v7 = x[21];
v8 = localNo(v7, a1, a2, a3, a4);
if ( groupNum * x[10] > v8 )
{
v9 = 4LL * (int)v8;
do
{
v11 = inodeTable + 32 * v9;
if ( *(_WORD *)(v11 + 26) && !*(_DWORD *)(inodeLink + v9) )
{
printf("partition %d inode %d should be put into lost+found\n", partitionNumber, v8 + 1);
v12 = inodeTable;
v13 = localNo(v6, a1, a2, a3, a4);
addToLost((int *)(v12 + ((__int64)v13 << 7)), v8 + 1);
updateParent((int *)v11, v6, a1, a2, a3, a4);
}
++v8;
v9 += 4LL;
}
while ( groupNum * x[10] > v8 );
}
if ( groupNum * x[10] )
{
v14 = 0LL;
do
*(_DWORD *)(inodeLink + 4 * v14++) = 0;
while ( groupNum * x[10] > (unsigned int)v14 );
}
return pass1();
}

canonical_decompiled_code:
int __fastcall func4(double a1, double a2, double a3, double a4)
{
int v4; // eax
unsigned int v5; // eax
unsigned int v6; // er13
__int64 v7; // rdi
unsigned int v8; // er12
__int64 v9; // rbp
__int64 v11; // rbx
__int64 v12; // r14
int v13; // eax
__int64 v14; // rax

v4 = localNo(2LL, a1, a2, a3, a4);
v5 = func0(v4, "lost+found");
if ( !v5 )
return puts("/lost+found is not found");
v6 = v5;
v7 = 11LL;
if ( x[19] )
v7 = x[21];
v8 = localNo(v7, a1, a2, a3, a4);
if ( groupNum * x[10] > v8 )
{
v9 = 4LL * (int)v8;
do
{
v11 = inodeTable + 32 * v9;
if ( *(_WORD *)(v11 + 26) && !*(_DWORD *)(inodeLink + v9) )
{
printf("partition %d inode %d should be put into lost+found\n", partitionNumber, v8 + 1);
v12 = inodeTable;
v13 = localNo(v6, a1, a2, a3, a4);
func2((int *)(v12 + ((__int64)v13 << 7)), v8 + 1);
func3((int *)v11, v6, a1, a2, a3, a4);
}
++v8;
v9 += 4LL;
}
while ( groupNum * x[10] > v8 );
}
if ( groupNum * x[10] )
{
v14 = 0LL;
do
*(_DWORD *)(inodeLink + 4 * v14++) = 0;
while ( groupNum * x[10] > (unsigned int)v14 );
}
return pass1();
}

original_code:
void pass2() {
 int lostInodeId = findDirInode(localNo(2), "lost+found");
 if (lostInodeId == 0) {
  printf("/lost+found is not found\n");
  return;
 }
 int i;
 struct ext2_inode *inode;
 for (i = localNo((((&x)->s_rev_level == 0) ? 11 : (&x)->s_first_ino)); i < groupNum * ((&x)->s_inodes_per_group); ++i) {
  inode = inodeTable + i;
  if (inode->i_links_count > 0 && inodeLink[i] == 0) {
   printf("partition %d inode %d should be put into lost+found\n", partitionNumber, i + 1);
   addToLost(inodeTable + localNo(lostInodeId), i + 1);
   updateParent(inode, lostInodeId);
  }
 }
 for (i = 0; i < groupNum * ((&x)->s_inodes_per_group); ++i)
  inodeLink[i] = 0;
 pass1();
}

variable_types: lostInodeId int


checkDataBlock

decompiled_code:
void __fastcall checkDataBlock(int a1)
{
int *v1; // rax
int v2; // ebx
int v3; // er15
int v4; // er14
unsigned int *v5; // rbx
unsigned int v6; // er13
unsigned int v7; // er12
void *v8; // rbp
unsigned int v9; // eax
unsigned int v10; // er12
unsigned int v11; // ebp
void *v12; // rbx
unsigned int v13; // eax
unsigned int *v14; // rbx
unsigned int v15; // er13
unsigned int v16; // er12
void *v17; // rbp
unsigned int v18; // eax
unsigned int v19; // er12
unsigned int v20; // ebp
void *v21; // rbx
unsigned int v22; // eax
__int64 v23; // rax
unsigned int v24; // er12
unsigned int v25; // ebp
void *v26; // rbx
unsigned int v27; // eax
unsigned int *v28; // rbx
unsigned int v29; // er13
unsigned int v30; // er12
void *v31; // rbp
unsigned int v32; // eax
unsigned int v33; // ebx
unsigned int v34; // ebp
void *v35; // r12
unsigned int v36; // eax
__int64 v37; // rax
unsigned int v38; // er12
unsigned int v39; // ebp
void *v40; // rbx
unsigned int v41; // eax
unsigned int v42; // er12
unsigned int v43; // ebp
void *v44; // rbx
unsigned int v45; // eax
unsigned int *v46; // rbx
unsigned int v47; // er13
unsigned int v48; // er12
void *v49; // rbp
unsigned int v50; // eax
char *v51; // r12
char *v52; // rbp
unsigned int v53; // eax
unsigned int *v54; // [rsp+0h] [rbp-78h]
unsigned int *v55; // [rsp+0h] [rbp-78h]
_DWORD *v56; // [rsp+8h] [rbp-70h]
_DWORD *v57; // [rsp+8h] [rbp-70h]
char *ptr; // [rsp+10h] [rbp-68h]
_DWORD *v59; // [rsp+18h] [rbp-60h]
_DWORD *v60; // [rsp+20h] [rbp-58h]
unsigned __int64 v61; // [rsp+28h] [rbp-50h]
_DWORD *v62; // [rsp+28h] [rbp-50h]
_DWORD *v63; // [rsp+28h] [rbp-50h]
unsigned __int64 v64; // [rsp+30h] [rbp-48h]
_DWORD *v65; // [rsp+30h] [rbp-48h]
_DWORD *v66; // [rsp+38h] [rbp-40h]
_DWORD *v67; // [rsp+38h] [rbp-40h]

v1 = (int *)((char *)inodeFlag + 4 * a1);
v2 = *v1;
if ( !*v1 )
{
*v1 = 1;
v56 = (_DWORD *)(inodeTable + ((__int64)a1 << 7));
v3 = v56[1];
if ( (unsigned int)isDirectory() )
{
v51 = (char *)malloc((unsigned int)v56[1]);
getData(start, v56, blockSize, v51);
if ( v3 > 0 )
{
do
{
v52 = &v51[v2];
if ( *(_DWORD *)v52 )
{
v53 = ((__int64 (*)(void))localNo)();
checkDataBlock(v53);
}
v2 += *((unsigned __int16 *)v52 + 2);
}
while ( v3 > v2 );
}
free(v51);
}
v4 = isSymbolicLink(v56);
if ( !v4 )
{
v61 = blockSize;
ptr = (char *)malloc(blockSize);
v59 = malloc(blockSize);
v60 = malloc(blockSize);
v5 = v56 + 10;
while ( 1 )
{
v6 = blockSize;
v7 = groupNum;
v8 = newBitmap;
v9 = localNo(*v5);
setBlockBitmapSet(v9, v8, v7, v6, &x, 1LL);
v4 += blockSize;
if ( v3 <= v4 )
break;
if ( ++v5 == v56 + 22 )
{
v64 = v61 >> 2;
readDisk((unsigned int)(v56[22] * blockSize + (start << 9)), blockSize, ptr);
v10 = blockSize;
v11 = groupNum;
v12 = newBitmap;
v13 = localNo((unsigned int)v56[22]);
setBlockBitmapSet(v13, v12, v11, v10, &x, 1LL);
if ( (int)(v61 >> 2) <= 0 )
{
LABEL_12:
readDisk((unsigned int)(v56[23] * blockSize + (start << 9)), blockSize, v59);
v19 = blockSize;
v20 = groupNum;
v21 = newBitmap;
v22 = localNo((unsigned int)v56[23]);
setBlockBitmapSet(v22, v21, v20, v19, &x, 1LL);
if ( (int)v64 <= 0 )
{
LABEL_18:
readDisk((unsigned int)(v56[24] * blockSize + (start << 9)), blockSize, v60);
v33 = blockSize;
v34 = groupNum;
v35 = newBitmap;
v36 = localNo((unsigned int)v56[24]);
setBlockBitmapSet(v36, v35, v34, v33, &x, 1LL);
if ( (int)v64 > 0 )
{
v63 = v60;
v37 = 4LL * (unsigned int)(v64 - 1) + 4;
v67 = (_DWORD *)((char *)v60 + v37);
v65 = (_DWORD *)((char *)v59 + v37);
v55 = (unsigned int *)&ptr[v37];
LABEL_20:
readDisk((unsigned int)(*v63 * blockSize + (start << 9)), blockSize, v59);
v38 = blockSize;
v39 = groupNum;
v40 = newBitmap;
v41 = localNo((unsigned int)*v63);
setBlockBitmapSet(v41, v40, v39, v38, &x, 1LL);
v57 = v59;
LABEL_21:
readDisk((unsigned int)(*v57 * blockSize + (start << 9)), blockSize, ptr);
v42 = blockSize;
v43 = groupNum;
v44 = newBitmap;
v45 = localNo((unsigned int)*v57);
setBlockBitmapSet(v45, v44, v43, v42, &x, 1LL);
v46 = (unsigned int *)ptr;
while ( 1 )
{
v47 = blockSize;
v48 = groupNum;
v49 = newBitmap;
v50 = localNo(*v46);
setBlockBitmapSet(v50, v49, v48, v47, &x, 1LL);
v4 += blockSize;
if ( v3 <= v4 )
break;
if ( ++v46 == v55 )
{
if ( ++v57 != v65 )
goto LABEL_21;
if ( v67 != ++v63 )
goto LABEL_20;
goto LABEL_26;
}
}
}
}
else
{
v62 = v59;
v23 = 4LL * (unsigned int)(v64 - 1) + 4;
v66 = (_DWORD *)((char *)v59 + v23);
v54 = (unsigned int *)&ptr[v23];
LABEL_14:
readDisk((unsigned int)(*v62 * blockSize + (start << 9)), blockSize, ptr);
v24 = blockSize;
v25 = groupNum;
v26 = newBitmap;
v27 = localNo((unsigned int)*v62);
setBlockBitmapSet(v27, v26, v25, v24, &x, 1LL);
v28 = (unsigned int *)ptr;
while ( 1 )
{
v29 = blockSize;
v30 = groupNum;
v31 = newBitmap;
v32 = localNo(*v28);
setBlockBitmapSet(v32, v31, v30, v29, &x, 1LL);
v4 += blockSize;
if ( v3 <= v4 )
break;
if ( v54 == ++v28 )
{
if ( ++v62 != v66 )
goto LABEL_14;
goto LABEL_18;
}
}
}
}
else
{
v14 = (unsigned int *)ptr;
while ( 1 )
{
v15 = blockSize;
v16 = groupNum;
v17 = newBitmap;
v18 = localNo(*v14);
setBlockBitmapSet(v18, v17, v16, v15, &x, 1LL);
v4 += blockSize;
if ( v3 <= v4 )
break;
if ( ++v14 == (unsigned int *)&ptr[4 * (unsigned int)(v61 >> 2)] )
goto LABEL_12;
}
}
break;
}
}
LABEL_26:
free(ptr);
free(v59);
free(v60);
}
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int *v1; // rax
int v2; // ebx
int v3; // er15
int v4; // er14
unsigned int *v5; // rbx
unsigned int v6; // er13
unsigned int v7; // er12
void *v8; // rbp
unsigned int v9; // eax
unsigned int v10; // er12
unsigned int v11; // ebp
void *v12; // rbx
unsigned int v13; // eax
unsigned int *v14; // rbx
unsigned int v15; // er13
unsigned int v16; // er12
void *v17; // rbp
unsigned int v18; // eax
unsigned int v19; // er12
unsigned int v20; // ebp
void *v21; // rbx
unsigned int v22; // eax
__int64 v23; // rax
unsigned int v24; // er12
unsigned int v25; // ebp
void *v26; // rbx
unsigned int v27; // eax
unsigned int *v28; // rbx
unsigned int v29; // er13
unsigned int v30; // er12
void *v31; // rbp
unsigned int v32; // eax
unsigned int v33; // ebx
unsigned int v34; // ebp
void *v35; // r12
unsigned int v36; // eax
__int64 v37; // rax
unsigned int v38; // er12
unsigned int v39; // ebp
void *v40; // rbx
unsigned int v41; // eax
unsigned int v42; // er12
unsigned int v43; // ebp
void *v44; // rbx
unsigned int v45; // eax
unsigned int *v46; // rbx
unsigned int v47; // er13
unsigned int v48; // er12
void *v49; // rbp
unsigned int v50; // eax
char *v51; // r12
char *v52; // rbp
unsigned int v53; // eax
unsigned int *v54; // [rsp+0h] [rbp-78h]
unsigned int *v55; // [rsp+0h] [rbp-78h]
_DWORD *v56; // [rsp+8h] [rbp-70h]
_DWORD *v57; // [rsp+8h] [rbp-70h]
char *ptr; // [rsp+10h] [rbp-68h]
_DWORD *v59; // [rsp+18h] [rbp-60h]
_DWORD *v60; // [rsp+20h] [rbp-58h]
unsigned __int64 v61; // [rsp+28h] [rbp-50h]
_DWORD *v62; // [rsp+28h] [rbp-50h]
_DWORD *v63; // [rsp+28h] [rbp-50h]
unsigned __int64 v64; // [rsp+30h] [rbp-48h]
_DWORD *v65; // [rsp+30h] [rbp-48h]
_DWORD *v66; // [rsp+38h] [rbp-40h]
_DWORD *v67; // [rsp+38h] [rbp-40h]

v1 = (int *)((char *)inodeFlag + 4 * a1);
v2 = *v1;
if ( !*v1 )
{
*v1 = 1;
v56 = (_DWORD *)(inodeTable + ((__int64)a1 << 7));
v3 = v56[1];
if ( (unsigned int)isDirectory() )
{
v51 = (char *)malloc((unsigned int)v56[1]);
getData(start, v56, blockSize, v51);
if ( v3 > 0 )
{
do
{
v52 = &v51[v2];
if ( *(_DWORD *)v52 )
{
v53 = ((__int64 (*)(void))localNo)();
func0(v53);
}
v2 += *((unsigned __int16 *)v52 + 2);
}
while ( v3 > v2 );
}
free(v51);
}
v4 = isSymbolicLink(v56);
if ( !v4 )
{
v61 = blockSize;
ptr = (char *)malloc(blockSize);
v59 = malloc(blockSize);
v60 = malloc(blockSize);
v5 = v56 + 10;
while ( 1 )
{
v6 = blockSize;
v7 = groupNum;
v8 = newBitmap;
v9 = localNo(*v5);
setBlockBitmapSet(v9, v8, v7, v6, &x, 1LL);
v4 += blockSize;
if ( v3 <= v4 )
break;
if ( ++v5 == v56 + 22 )
{
v64 = v61 >> 2;
readDisk((unsigned int)(v56[22] * blockSize + (start << 9)), blockSize, ptr);
v10 = blockSize;
v11 = groupNum;
v12 = newBitmap;
v13 = localNo((unsigned int)v56[22]);
setBlockBitmapSet(v13, v12, v11, v10, &x, 1LL);
if ( (int)(v61 >> 2) <= 0 )
{
LABEL_12:
readDisk((unsigned int)(v56[23] * blockSize + (start << 9)), blockSize, v59);
v19 = blockSize;
v20 = groupNum;
v21 = newBitmap;
v22 = localNo((unsigned int)v56[23]);
setBlockBitmapSet(v22, v21, v20, v19, &x, 1LL);
if ( (int)v64 <= 0 )
{
LABEL_18:
readDisk((unsigned int)(v56[24] * blockSize + (start << 9)), blockSize, v60);
v33 = blockSize;
v34 = groupNum;
v35 = newBitmap;
v36 = localNo((unsigned int)v56[24]);
setBlockBitmapSet(v36, v35, v34, v33, &x, 1LL);
if ( (int)v64 > 0 )
{
v63 = v60;
v37 = 4LL * (unsigned int)(v64 - 1) + 4;
v67 = (_DWORD *)((char *)v60 + v37);
v65 = (_DWORD *)((char *)v59 + v37);
v55 = (unsigned int *)&ptr[v37];
LABEL_20:
readDisk((unsigned int)(*v63 * blockSize + (start << 9)), blockSize, v59);
v38 = blockSize;
v39 = groupNum;
v40 = newBitmap;
v41 = localNo((unsigned int)*v63);
setBlockBitmapSet(v41, v40, v39, v38, &x, 1LL);
v57 = v59;
LABEL_21:
readDisk((unsigned int)(*v57 * blockSize + (start << 9)), blockSize, ptr);
v42 = blockSize;
v43 = groupNum;
v44 = newBitmap;
v45 = localNo((unsigned int)*v57);
setBlockBitmapSet(v45, v44, v43, v42, &x, 1LL);
v46 = (unsigned int *)ptr;
while ( 1 )
{
v47 = blockSize;
v48 = groupNum;
v49 = newBitmap;
v50 = localNo(*v46);
setBlockBitmapSet(v50, v49, v48, v47, &x, 1LL);
v4 += blockSize;
if ( v3 <= v4 )
break;
if ( ++v46 == v55 )
{
if ( ++v57 != v65 )
goto LABEL_21;
if ( v67 != ++v63 )
goto LABEL_20;
goto LABEL_26;
}
}
}
}
else
{
v62 = v59;
v23 = 4LL * (unsigned int)(v64 - 1) + 4;
v66 = (_DWORD *)((char *)v59 + v23);
v54 = (unsigned int *)&ptr[v23];
LABEL_14:
readDisk((unsigned int)(*v62 * blockSize + (start << 9)), blockSize, ptr);
v24 = blockSize;
v25 = groupNum;
v26 = newBitmap;
v27 = localNo((unsigned int)*v62);
setBlockBitmapSet(v27, v26, v25, v24, &x, 1LL);
v28 = (unsigned int *)ptr;
while ( 1 )
{
v29 = blockSize;
v30 = groupNum;
v31 = newBitmap;
v32 = localNo(*v28);
setBlockBitmapSet(v32, v31, v30, v29, &x, 1LL);
v4 += blockSize;
if ( v3 <= v4 )
break;
if ( v54 == ++v28 )
{
if ( ++v62 != v66 )
goto LABEL_14;
goto LABEL_18;
}
}
}
}
else
{
v14 = (unsigned int *)ptr;
while ( 1 )
{
v15 = blockSize;
v16 = groupNum;
v17 = newBitmap;
v18 = localNo(*v14);
setBlockBitmapSet(v18, v17, v16, v15, &x, 1LL);
v4 += blockSize;
if ( v3 <= v4 )
break;
if ( ++v14 == (unsigned int *)&ptr[4 * (unsigned int)(v61 >> 2)] )
goto LABEL_12;
}
}
break;
}
}
LABEL_26:
free(ptr);
free(v59);
free(v60);
}
}
}

original_code:
void checkDataBlock(int localId) {
 if (inodeFlag[localId]) return;
 inodeFlag[localId] = 1;
 struct ext2_inode *inode;
 inode = inodeTable + localId;
 int tempSize;
 int totalSize = inode->i_size;
 if (isDirectory(inode)) {
  unsigned char *buf = malloc(inode->i_size);
  getData(start, inode, blockSize, buf);
  tempSize = 0;
  struct ext2_dir_entry_2 *dir;
  while (tempSize < totalSize) {
   dir = (struct ext2_dir_entry_2 *)(buf + tempSize);
   if (dir->inode != 0)
    checkDataBlock(localNo(dir->inode));
   tempSize += dir->rec_len;
  }
  free(buf);
 }
 if (isSymbolicLink(inode)) return;
 tempSize = 0;
 int i, j, k;
 int len = blockSize / sizeof(int);
 int* indblock = malloc(blockSize);
 int* dindblock = malloc(blockSize);
 int* tindblock = malloc(blockSize);
 for (i = 0; i < 12; ++i) {
  setBlockBitmapSet(localNo(inode->i_block[i]), newBitmap, groupNum, blockSize, &x, 1);
  tempSize += blockSize;
  if (tempSize >= totalSize) goto FREE_MEMORY;
 }
 readDisk(start * 512 + blockSize * inode->i_block[12], blockSize, indblock);
 setBlockBitmapSet(localNo(inode->i_block[12]), newBitmap, groupNum, blockSize, &x, 1);
 for (i = 0; i < len; ++i) {
  setBlockBitmapSet(localNo(indblock[i]), newBitmap, groupNum, blockSize, &x, 1);
  tempSize += blockSize;
  if (tempSize >= totalSize) goto FREE_MEMORY;
 }
 readDisk(start * 512 + blockSize * inode->i_block[(12 + 1)], blockSize, dindblock);
 setBlockBitmapSet(localNo(inode->i_block[(12 + 1)]), newBitmap, groupNum, blockSize, &x, 1);
 for (i = 0; i < len; ++i) {
  readDisk(start * 512 + blockSize * dindblock[i], blockSize, indblock);
  setBlockBitmapSet(localNo(dindblock[i]), newBitmap, groupNum, blockSize, &x, 1);
  for (j = 0; j < len; ++j) {
   setBlockBitmapSet(localNo(indblock[j]), newBitmap, groupNum, blockSize, &x, 1);
   tempSize += blockSize;
   if (tempSize >= totalSize) goto FREE_MEMORY;
  }
 }
 readDisk(start * 512 + blockSize * inode->i_block[((12 + 1) + 1)], blockSize, tindblock);
 setBlockBitmapSet(localNo(inode->i_block[((12 + 1) + 1)]), newBitmap, groupNum, blockSize, &x, 1);
 for (i = 0; i < len; ++i) {
  readDisk(start * 512 + blockSize * tindblock[i], blockSize, dindblock);
  setBlockBitmapSet(localNo(tindblock[i]), newBitmap, groupNum, blockSize, &x, 1);
  for (j = 0; j < len; ++j) {
   readDisk(start * 512 + blockSize * dindblock[j], blockSize, indblock);
   setBlockBitmapSet(localNo(dindblock[j]), newBitmap, groupNum, blockSize, &x, 1);
   for (k = 0; k < len; ++k) {
    setBlockBitmapSet(localNo(indblock[k]), newBitmap, groupNum, blockSize, &x, 1);
    tempSize += blockSize;
    if (tempSize >= totalSize) goto FREE_MEMORY;
   }
  }
 }
 FREE_MEMORY:
  free(indblock);
  free(dindblock);
  free(tindblock);
}

canonical_original_code:
void checkDataBlock(int localId) {
 if (inodeFlag[localId]) return;
 inodeFlag[localId] = 1;
 struct ext2_inode *inode;
 inode = inodeTable + localId;
 int tempSize;
 int totalSize = inode->i_size;
 if (isDirectory(inode)) {
  unsigned char *buf = malloc(inode->i_size);
  getData(start, inode, blockSize, buf);
  tempSize = 0;
  struct ext2_dir_entry_2 *dir;
  while (tempSize < totalSize) {
   dir = (struct ext2_dir_entry_2 *)(buf + tempSize);
   if (dir->inode != 0)
    checkDataBlock(localNo(dir->inode));
   tempSize += dir->rec_len;
  }
  free(buf);
 }
 if (isSymbolicLink(inode)) return;
 tempSize = 0;
 int i; int j; int k;
 int len = blockSize / sizeof(int);
 int *indblock = malloc(blockSize);
 int *dindblock = malloc(blockSize);
 int *tindblock = malloc(blockSize);
 for (i = 0; i < 12; ++i) {
  setBlockBitmapSet(localNo(inode->i_block[i]), newBitmap, groupNum, blockSize, &x, 1);
  tempSize += blockSize;
  if (tempSize >= totalSize) goto FREE_MEMORY;
 }
 readDisk(start * 512 + blockSize * inode->i_block[12], blockSize, indblock);
 setBlockBitmapSet(localNo(inode->i_block[12]), newBitmap, groupNum, blockSize, &x, 1);
 for (i = 0; i < len; ++i) {
  setBlockBitmapSet(localNo(indblock[i]), newBitmap, groupNum, blockSize, &x, 1);
  tempSize += blockSize;
  if (tempSize >= totalSize) goto FREE_MEMORY;
 }
 readDisk(start * 512 + blockSize * inode->i_block[(12 + 1)], blockSize, dindblock);
 setBlockBitmapSet(localNo(inode->i_block[(12 + 1)]), newBitmap, groupNum, blockSize, &x, 1);
 for (i = 0; i < len; ++i) {
  readDisk(start * 512 + blockSize * dindblock[i], blockSize, indblock);
  setBlockBitmapSet(localNo(dindblock[i]), newBitmap, groupNum, blockSize, &x, 1);
  for (j = 0; j < len; ++j) {
   setBlockBitmapSet(localNo(indblock[j]), newBitmap, groupNum, blockSize, &x, 1);
   tempSize += blockSize;
   if (tempSize >= totalSize) goto FREE_MEMORY;
  }
 }
 readDisk(start * 512 + blockSize * inode->i_block[((12 + 1) + 1)], blockSize, tindblock);
 setBlockBitmapSet(localNo(inode->i_block[((12 + 1) + 1)]), newBitmap, groupNum, blockSize, &x, 1);
 for (i = 0; i < len; ++i) {
  readDisk(start * 512 + blockSize * tindblock[i], blockSize, dindblock);
  setBlockBitmapSet(localNo(tindblock[i]), newBitmap, groupNum, blockSize, &x, 1);
  for (j = 0; j < len; ++j) {
   readDisk(start * 512 + blockSize * dindblock[j], blockSize, indblock);
   setBlockBitmapSet(localNo(dindblock[j]), newBitmap, groupNum, blockSize, &x, 1);
   for (k = 0; k < len; ++k) {
    setBlockBitmapSet(localNo(indblock[k]), newBitmap, groupNum, blockSize, &x, 1);
    tempSize += blockSize;
    if (tempSize >= totalSize) goto FREE_MEMORY;
   }
  }
 }
 FREE_MEMORY:
  free(indblock);
  free(dindblock);
  free(tindblock);
}

variable_types: j int

variable_types: k int

variable_types:
indblock
int *

variable_types:
dindblock
int *

variable_types:
tindblock
int *


checkBlockBitmap

decompiled_code:
void checkBlockBitmap()
{
int v0; // ebx
__int64 v1; // rdx
unsigned int v2; // er12
__int64 v3; // r13
unsigned int v4; // ebp
unsigned int v5; // er15
unsigned int v6; // er14
__int64 v7; // rbp
unsigned int v8; // eax
unsigned int v9; // er15
unsigned int v10; // er14
unsigned int v11; // eax
unsigned int v12; // er15
unsigned int v13; // er14
unsigned int v14; // eax
unsigned int v15; // er15
unsigned int v16; // er14
unsigned int v17; // eax
int v18; // er14
unsigned int v19; // ebp
int v20; // er14
unsigned int v21; // ebx
__int64 v22; // rax
int v23; // eax
__int64 v24; // [rsp+0h] [rbp-48h]
void *v25; // [rsp+0h] [rbp-48h]
__int64 v26; // [rsp+0h] [rbp-48h]
void *v27; // [rsp+0h] [rbp-48h]
int v28; // [rsp+8h] [rbp-40h]
int v29; // [rsp+Ch] [rbp-3Ch]

v28 = x[8];
v0 = roundUp((unsigned int)(32 * groupNum), blockSize);
v29 = roundUp((unsigned int)(x[10] << 7), blockSize);
v1 = groupNum;
if ( groupNum > 0 )
{
v2 = 0;
v3 = 0LL;
do
{
if ( !(unsigned int)isBlockBitmapSet(v2, blockBitmap, v1, blockSize, x) )
{
printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, v2 + 1, 0LL, 1LL);
change = 1;
}
setBlockBitmapSet(v2, newBitmap, groupNum, blockSize, x, 1LL);
if ( v0 > 0 )
{
v4 = v2 + 2;
do
{
if ( !(unsigned int)isBlockBitmapSet(v4 - 1, blockBitmap, groupNum, blockSize, x) )
{
printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, v4, 0LL, 1LL);
change = 1;
}
setBlockBitmapSet(v4++ - 1, newBitmap, groupNum, blockSize, x, 1LL);
}
while ( v0 >= (int)(~v2 + v4) );
}
v5 = blockSize;
v6 = groupNum;
v24 = blockBitmap;
v7 = 32 * v3;
v8 = localNo(*(unsigned int *)(groupDescs + 32 * v3));
if ( !(unsigned int)isBlockBitmapSet(v8, v24, v6, v5, x) )
{
printf(
"partition %d block %d : bitmap wrong: %d Vs %d\n",
partitionNumber,
*(unsigned int *)(groupDescs + 32 * v3),
0LL,
1LL);
change = 1;
}
v9 = blockSize;
v10 = groupNum;
v25 = newBitmap;
v11 = localNo(*(unsigned int *)(groupDescs + 32 * v3));
setBlockBitmapSet(v11, v25, v10, v9, x, 1LL);
v12 = blockSize;
v13 = groupNum;
v26 = blockBitmap;
v14 = localNo(*(unsigned int *)(groupDescs + v7 + 4));
if ( !(unsigned int)isBlockBitmapSet(v14, v26, v13, v12, x) )
{
printf(
"partition %d block %d : bitmap wrong: %d Vs %d\n",
partitionNumber,
*(unsigned int *)(groupDescs + v7 + 4),
0LL,
1LL);
change = 1;
}
v15 = blockSize;
v16 = groupNum;
v27 = newBitmap;
v17 = localNo(*(unsigned int *)(groupDescs + v7 + 4));
setBlockBitmapSet(v17, v27, v16, v15, x, 1LL);
v18 = *(_DWORD *)(groupDescs + v7 + 8);
v19 = v18 - 1;
v20 = v29 + v18;
if ( v29 >= 0 )
{
do
{
if ( !(unsigned int)isBlockBitmapSet(v19, blockBitmap, groupNum, blockSize, x) )
{
printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, v19 + 1, 0LL, 1LL);
change = 1;
}
setBlockBitmapSet(v19++, newBitmap, groupNum, blockSize, x, 1LL);
}
while ( (int)v19 < v20 );
}
v1 = groupNum;
++v3;
v2 += v28;
}
while ( groupNum > (int)v3 );
}
v21 = x[10];
inodeFlag = malloc(4 * v21 * (__int64)(int)v1);
if ( groupNum * v21 )
{
v22 = 0LL;
do
*((_DWORD *)inodeFlag + v22++) = 0;
while ( groupNum * x[10] > (unsigned int)v22 );
}
v23 = localNo(2LL);
checkDataBlock(v23);
free(inodeFlag);
}

canonical_decompiled_code:
void func1()
{
int v0; // ebx
__int64 v1; // rdx
unsigned int v2; // er12
__int64 v3; // r13
unsigned int v4; // ebp
unsigned int v5; // er15
unsigned int v6; // er14
__int64 v7; // rbp
unsigned int v8; // eax
unsigned int v9; // er15
unsigned int v10; // er14
unsigned int v11; // eax
unsigned int v12; // er15
unsigned int v13; // er14
unsigned int v14; // eax
unsigned int v15; // er15
unsigned int v16; // er14
unsigned int v17; // eax
int v18; // er14
unsigned int v19; // ebp
int v20; // er14
unsigned int v21; // ebx
__int64 v22; // rax
int v23; // eax
__int64 v24; // [rsp+0h] [rbp-48h]
void *v25; // [rsp+0h] [rbp-48h]
__int64 v26; // [rsp+0h] [rbp-48h]
void *v27; // [rsp+0h] [rbp-48h]
int v28; // [rsp+8h] [rbp-40h]
int v29; // [rsp+Ch] [rbp-3Ch]

v28 = x[8];
v0 = roundUp((unsigned int)(32 * groupNum), blockSize);
v29 = roundUp((unsigned int)(x[10] << 7), blockSize);
v1 = groupNum;
if ( groupNum > 0 )
{
v2 = 0;
v3 = 0LL;
do
{
if ( !(unsigned int)isBlockBitmapSet(v2, blockBitmap, v1, blockSize, x) )
{
printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, v2 + 1, 0LL, 1LL);
change = 1;
}
setBlockBitmapSet(v2, newBitmap, groupNum, blockSize, x, 1LL);
if ( v0 > 0 )
{
v4 = v2 + 2;
do
{
if ( !(unsigned int)isBlockBitmapSet(v4 - 1, blockBitmap, groupNum, blockSize, x) )
{
printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, v4, 0LL, 1LL);
change = 1;
}
setBlockBitmapSet(v4++ - 1, newBitmap, groupNum, blockSize, x, 1LL);
}
while ( v0 >= (int)(~v2 + v4) );
}
v5 = blockSize;
v6 = groupNum;
v24 = blockBitmap;
v7 = 32 * v3;
v8 = localNo(*(unsigned int *)(groupDescs + 32 * v3));
if ( !(unsigned int)isBlockBitmapSet(v8, v24, v6, v5, x) )
{
printf(
"partition %d block %d : bitmap wrong: %d Vs %d\n",
partitionNumber,
*(unsigned int *)(groupDescs + 32 * v3),
0LL,
1LL);
change = 1;
}
v9 = blockSize;
v10 = groupNum;
v25 = newBitmap;
v11 = localNo(*(unsigned int *)(groupDescs + 32 * v3));
setBlockBitmapSet(v11, v25, v10, v9, x, 1LL);
v12 = blockSize;
v13 = groupNum;
v26 = blockBitmap;
v14 = localNo(*(unsigned int *)(groupDescs + v7 + 4));
if ( !(unsigned int)isBlockBitmapSet(v14, v26, v13, v12, x) )
{
printf(
"partition %d block %d : bitmap wrong: %d Vs %d\n",
partitionNumber,
*(unsigned int *)(groupDescs + v7 + 4),
0LL,
1LL);
change = 1;
}
v15 = blockSize;
v16 = groupNum;
v27 = newBitmap;
v17 = localNo(*(unsigned int *)(groupDescs + v7 + 4));
setBlockBitmapSet(v17, v27, v16, v15, x, 1LL);
v18 = *(_DWORD *)(groupDescs + v7 + 8);
v19 = v18 - 1;
v20 = v29 + v18;
if ( v29 >= 0 )
{
do
{
if ( !(unsigned int)isBlockBitmapSet(v19, blockBitmap, groupNum, blockSize, x) )
{
printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, v19 + 1, 0LL, 1LL);
change = 1;
}
setBlockBitmapSet(v19++, newBitmap, groupNum, blockSize, x, 1LL);
}
while ( (int)v19 < v20 );
}
v1 = groupNum;
++v3;
v2 += v28;
}
while ( groupNum > (int)v3 );
}
v21 = x[10];
inodeFlag = malloc(4 * v21 * (__int64)(int)v1);
if ( groupNum * v21 )
{
v22 = 0LL;
do
*((_DWORD *)inodeFlag + v22++) = 0;
while ( groupNum * x[10] > (unsigned int)v22 );
}
v23 = localNo(2LL);
func0(v23);
free(inodeFlag);
}

original_code:
void checkBlockBitmap() {
 int i, j, temp;
 int blockPerGroup = ((&x)->s_blocks_per_group);
 int bitmap;
 int groupBlock = roundUp(sizeof(struct ext2_group_desc) * groupNum, blockSize);
 int inodeTableBlock = roundUp(sizeof(struct ext2_inode) * ((&x)->s_inodes_per_group), blockSize);
 int used = 0;
 for (i = 0; i < groupNum; ++i) {
  ++used;
  bitmap = isBlockBitmapSet(i * blockPerGroup + 0, blockBitmap, groupNum, blockSize, &x);
  if (!bitmap) {
   printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, i * blockPerGroup + 1, 0, 1);
   change = 1;
  }
  setBlockBitmapSet(i * blockPerGroup + 0, newBitmap, groupNum, blockSize, &x, 1);
  for (j = 1; j <= groupBlock; ++j) {
   ++used;
   bitmap = isBlockBitmapSet(i * blockPerGroup + j, blockBitmap, groupNum, blockSize, &x);
   if (!bitmap) {
    printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, i * blockPerGroup + j + 1, 0, 1);
    change = 1;
   }
   setBlockBitmapSet(i * blockPerGroup + j, newBitmap, groupNum, blockSize, &x, 1);
  }
  ++used;
  bitmap = isBlockBitmapSet(localNo(groupDescs[i].bg_block_bitmap), blockBitmap, groupNum, blockSize, &x);
  if (!bitmap) {
   printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, groupDescs[i].bg_block_bitmap, 0, 1);
   change = 1;
  }
  setBlockBitmapSet(localNo(groupDescs[i].bg_block_bitmap), newBitmap, groupNum, blockSize, &x, 1);
  ++used;
  bitmap = isBlockBitmapSet(localNo(groupDescs[i].bg_inode_bitmap), blockBitmap, groupNum, blockSize, &x);
  if (!bitmap) {
   printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, groupDescs[i].bg_inode_bitmap, 0, 1);
   change = 1;
  }
  setBlockBitmapSet(localNo(groupDescs[i].bg_inode_bitmap), newBitmap, groupNum, blockSize, &x, 1);
  temp = groupDescs[i].bg_inode_table;
  for (j = temp - 1; j < temp + inodeTableBlock; ++j) {
   ++used;
   bitmap = isBlockBitmapSet(j, blockBitmap, groupNum, blockSize, &x);
   if (!bitmap) {
    printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, j + 1, 0, 1);
    change = 1;
   }
   setBlockBitmapSet(j, newBitmap, groupNum, blockSize, &x, 1);
  }
 }
 inodeFlag = malloc(sizeof(int) * groupNum * ((&x)->s_inodes_per_group));
 for (i = 0; i < groupNum * ((&x)->s_inodes_per_group); ++i)
  inodeFlag[i] = 0;
 checkDataBlock(localNo(2));
 free(inodeFlag);
}

canonical_original_code:
void checkBlockBitmap() {
 int i; int j; int temp;
 int blockPerGroup = ((&x)->s_blocks_per_group);
 int bitmap;
 int groupBlock = roundUp(sizeof(struct ext2_group_desc) * groupNum, blockSize);
 int inodeTableBlock = roundUp(sizeof(struct ext2_inode) * ((&x)->s_inodes_per_group), blockSize);
 int used = 0;
 for (i = 0; i < groupNum; ++i) {
  ++used;
  bitmap = isBlockBitmapSet(i * blockPerGroup + 0, blockBitmap, groupNum, blockSize, &x);
  if (!bitmap) {
   printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, i * blockPerGroup + 1, 0, 1);
   change = 1;
  }
  setBlockBitmapSet(i * blockPerGroup + 0, newBitmap, groupNum, blockSize, &x, 1);
  for (j = 1; j <= groupBlock; ++j) {
   ++used;
   bitmap = isBlockBitmapSet(i * blockPerGroup + j, blockBitmap, groupNum, blockSize, &x);
   if (!bitmap) {
    printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, i * blockPerGroup + j + 1, 0, 1);
    change = 1;
   }
   setBlockBitmapSet(i * blockPerGroup + j, newBitmap, groupNum, blockSize, &x, 1);
  }
  ++used;
  bitmap = isBlockBitmapSet(localNo(groupDescs[i].bg_block_bitmap), blockBitmap, groupNum, blockSize, &x);
  if (!bitmap) {
   printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, groupDescs[i].bg_block_bitmap, 0, 1);
   change = 1;
  }
  setBlockBitmapSet(localNo(groupDescs[i].bg_block_bitmap), newBitmap, groupNum, blockSize, &x, 1);
  ++used;
  bitmap = isBlockBitmapSet(localNo(groupDescs[i].bg_inode_bitmap), blockBitmap, groupNum, blockSize, &x);
  if (!bitmap) {
   printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, groupDescs[i].bg_inode_bitmap, 0, 1);
   change = 1;
  }
  setBlockBitmapSet(localNo(groupDescs[i].bg_inode_bitmap), newBitmap, groupNum, blockSize, &x, 1);
  temp = groupDescs[i].bg_inode_table;
  for (j = temp - 1; j < temp + inodeTableBlock; ++j) {
   ++used;
   bitmap = isBlockBitmapSet(j, blockBitmap, groupNum, blockSize, &x);
   if (!bitmap) {
    printf("partition %d block %d : bitmap wrong: %d Vs %d\n", partitionNumber, j + 1, 0, 1);
    change = 1;
   }
   setBlockBitmapSet(j, newBitmap, groupNum, blockSize, &x, 1);
  }
 }
 inodeFlag = malloc(sizeof(int) * groupNum * ((&x)->s_inodes_per_group));
 for (i = 0; i < groupNum * ((&x)->s_inodes_per_group); ++i)
  inodeFlag[i] = 0;
 checkDataBlock(localNo(2));
 free(inodeFlag);
}

variable_types: temp int

variable_types: blockPerGroup int

variable_types: bitmap int

variable_types: groupBlock int

variable_types: inodeTableBlock int

variable_types: used int


decompiled_code:
void pass4()
{
unsigned int v0; // ebx
__int64 v1; // rdx
__int64 v2; // rbp
__int64 v3; // r8
unsigned int v4; // eax
__int64 v5; // rbx
__int64 v6; // rax
unsigned int v7; // ebx
unsigned int v8; // er12
unsigned int v9; // eax
unsigned int v10; // ebp
__int64 v11; // rbx

change = 0;
v0 = localNo(2LL);
v1 = groupNum;
if ( x[10] * groupNum > v0 )
{
v2 = 4LL * (int)v0;
do
{
if ( v0 - 2 > 7 )
{
v4 = isInodeBitmapSet(v0, inodeBitmap, v1, blockSize, x);
if ( v4 )
{
if ( !*(_DWORD *)(inodeLink + v2) )
{
printf(
"partition %d inode %d : bitmap is inconsistent with inode table: %d Vs %d\n",
partitionNumber,
v0 + 1,
v4,
0LL);
setInodeBitmapSet(v0, inodeBitmap, groupNum, blockSize, x, 0LL);
change = 1;
}
}
else
{
v3 = *(unsigned int *)(inodeLink + v2);
if ( (_DWORD)v3 )
{
printf(
"partition %d inode %d : bitmap is inconsistent with inode table: %d Vs %d\n",
partitionNumber,
v0 + 1,
0LL,
v3);
setInodeBitmapSet(v0, inodeBitmap, groupNum, blockSize, x, 1LL);
change = 1;
}
}
}
++v0;
v1 = groupNum;
v2 += 4LL;
}
while ( x[10] * groupNum > v0 );
}
if ( change && groupNum > 0 )
{
v5 = 0LL;
do
{
writeDisk(
(unsigned int)((start << 9) + *(_DWORD *)(groupDescs + 32 * v5 + 4) * blockSize),
blockSize,
inodeBitmap + (int)v5 * blockSize);
++v5;
}
while ( groupNum > (int)v5 );
}
newBitmap = malloc(groupNum * blockSize + 1);
if ( groupNum * blockSize >= 0 )
{
v6 = 0LL;
do
*((_BYTE *)newBitmap + v6++) = 0;
while ( groupNum * blockSize >= (int)v6 );
}
checkBlockBitmap();
if ( x[1] != 1 )
{
v7 = 0;
do
{
v8 = isBlockBitmapSet(v7, blockBitmap, groupNum, blockSize, x);
v9 = isBlockBitmapSet(v7, newBitmap, groupNum, blockSize, x);
v10 = v9;
if ( v8 != v9 )
{
printf("partition %d block bitmap: block %d: %d Vs %d\n", partitionNumber, v7 + 1, v8, v9);
setBlockBitmapSet(v7, blockBitmap, groupNum, blockSize, x, v10);
}
++v7;
}
while ( x[1] - 1 > v7 );
}
free(newBitmap);
if ( groupNum > 0 )
{
v11 = 0LL;
do
{
writeDisk(
(unsigned int)((start << 9) + *(_DWORD *)(groupDescs + 32 * v11) * blockSize),
blockSize,
blockBitmap + (int)v11 * blockSize);
++v11;
}
while ( groupNum > (int)v11 );
}
}

canonical_decompiled_code:
void func2()
{
unsigned int v0; // ebx
__int64 v1; // rdx
__int64 v2; // rbp
__int64 v3; // r8
unsigned int v4; // eax
__int64 v5; // rbx
__int64 v6; // rax
unsigned int v7; // ebx
unsigned int v8; // er12
unsigned int v9; // eax
unsigned int v10; // ebp
__int64 v11; // rbx

change = 0;
v0 = localNo(2LL);
v1 = groupNum;
if ( x[10] * groupNum > v0 )
{
v2 = 4LL * (int)v0;
do
{
if ( v0 - 2 > 7 )
{
v4 = isInodeBitmapSet(v0, inodeBitmap, v1, blockSize, x);
if ( v4 )
{
if ( !*(_DWORD *)(inodeLink + v2) )
{
printf(
"partition %d inode %d : bitmap is inconsistent with inode table: %d Vs %d\n",
partitionNumber,
v0 + 1,
v4,
0LL);
setInodeBitmapSet(v0, inodeBitmap, groupNum, blockSize, x, 0LL);
change = 1;
}
}
else
{
v3 = *(unsigned int *)(inodeLink + v2);
if ( (_DWORD)v3 )
{
printf(
"partition %d inode %d : bitmap is inconsistent with inode table: %d Vs %d\n",
partitionNumber,
v0 + 1,
0LL,
v3);
setInodeBitmapSet(v0, inodeBitmap, groupNum, blockSize, x, 1LL);
change = 1;
}
}
}
++v0;
v1 = groupNum;
v2 += 4LL;
}
while ( x[10] * groupNum > v0 );
}
if ( change && groupNum > 0 )
{
v5 = 0LL;
do
{
writeDisk(
(unsigned int)((start << 9) + *(_DWORD *)(groupDescs + 32 * v5 + 4) * blockSize),
blockSize,
inodeBitmap + (int)v5 * blockSize);
++v5;
}
while ( groupNum > (int)v5 );
}
newBitmap = malloc(groupNum * blockSize + 1);
if ( groupNum * blockSize >= 0 )
{
v6 = 0LL;
do
*((_BYTE *)newBitmap + v6++) = 0;
while ( groupNum * blockSize >= (int)v6 );
}
func1();
if ( x[1] != 1 )
{
v7 = 0;
do
{
v8 = isBlockBitmapSet(v7, blockBitmap, groupNum, blockSize, x);
v9 = isBlockBitmapSet(v7, newBitmap, groupNum, blockSize, x);
v10 = v9;
if ( v8 != v9 )
{
printf("partition %d block bitmap: block %d: %d Vs %d\n", partitionNumber, v7 + 1, v8, v9);
setBlockBitmapSet(v7, blockBitmap, groupNum, blockSize, x, v10);
}
++v7;
}
while ( x[1] - 1 > v7 );
}
free(newBitmap);
if ( groupNum > 0 )
{
v11 = 0LL;
do
{
writeDisk(
(unsigned int)((start << 9) + *(_DWORD *)(groupDescs + 32 * v11) * blockSize),
blockSize,
blockBitmap + (int)v11 * blockSize);
++v11;
}
while ( groupNum > (int)v11 );
}
}

original_code:
void pass4() {
 int i;
 int bitmap;
 change = 0;
 for (i = localNo(2); i < groupNum * ((&x)->s_inodes_per_group); ++i) {
  if (i >= 2 && i <= 9) continue;
  bitmap = isInodeBitmapSet(i, inodeBitmap, groupNum, blockSize, &x);
  if (bitmap && !inodeLink[i]) {
   printf("partition %d inode %d : bitmap is inconsistent with inode table: %d Vs %d\n", partitionNumber, i + 1, bitmap, inodeLink[i]);
   setInodeBitmapSet(i, inodeBitmap, groupNum, blockSize, &x, 0);
   change = 1;
  } else if (!bitmap && inodeLink[i]) {
   printf("partition %d inode %d : bitmap is inconsistent with inode table: %d Vs %d\n", partitionNumber, i + 1, bitmap, inodeLink[i]);
   setInodeBitmapSet(i, inodeBitmap, groupNum, blockSize, &x, 1);
   change = 1;
  }
 }
 if (change) {
  for (i = 0; i < groupNum; ++i)
   writeDisk(start * 512 + groupDescs[i].bg_inode_bitmap * blockSize, blockSize, inodeBitmap + i * blockSize);
 }
 newBitmap = malloc(blockSize * groupNum + 1);
 for (i = 0; i < blockSize * groupNum + 1; ++i)
  newBitmap[i] = 0;
 checkBlockBitmap();
 int oldbit;
 int newbit;
 for (i = 0; i < x.s_blocks_count - 1; ++i) {
  oldbit = isBlockBitmapSet(i, blockBitmap, groupNum, blockSize, &x);
  newbit = isBlockBitmapSet(i, newBitmap, groupNum, blockSize, &x);
  if (oldbit != newbit) {
   printf("partition %d block bitmap: block %d: %d Vs %d\n", partitionNumber, i + 1, oldbit, newbit);
   setBlockBitmapSet(i, blockBitmap, groupNum, blockSize, &x, newbit);
  }
 }
 free(newBitmap);
 for (i = 0; i < groupNum; ++i)
  writeDisk(start * 512 + groupDescs[i].bg_block_bitmap * blockSize, blockSize, blockBitmap + i * blockSize);
}

variable_types: oldbit int

variable_types: newbit int


decompiled_code:
__int64 pass3()
{
unsigned int v0; // ebp
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // r13
__int64 v4; // rcx
__int64 v5; // r8
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = localNo(2LL);
result = (unsigned int)(groupNum * x[10]);
if ( (unsigned int)result > v0 )
{
v2 = 4LL * (int)v0;
do
{
v3 = inodeTable + 32 * v2;
v4 = *(unsigned __int16 *)(v3 + 26);
v5 = *(unsigned int *)(inodeLink + v2);
if ( (_DWORD)v4 != (_DWORD)v5 )
{
printf("partition %d inode %d inconsistent link count: %d Vs %d\n", partitionNumber, v0 + 1, v4, v5);
*(_WORD *)(v3 + 26) = *(_DWORD *)(inodeLink + v2);
getInodeGroupBlock(v0, &v6, v7, x);
writeDisk(
(unsigned int)((v7[0] << 7) + (start << 9) + blockSize * *(_DWORD *)(groupDescs + 32LL * v6 + 8)),
128LL,
inodeTable + 32 * v2);
}
++v0;
v2 += 4LL;
result = (unsigned int)(groupNum * x[10]);
}
while ( (unsigned int)result > v0 );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebp
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // r13
__int64 v4; // rcx
__int64 v5; // r8
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = localNo(2LL);
result = (unsigned int)(groupNum * x[10]);
if ( (unsigned int)result > v0 )
{
v2 = 4LL * (int)v0;
do
{
v3 = inodeTable + 32 * v2;
v4 = *(unsigned __int16 *)(v3 + 26);
v5 = *(unsigned int *)(inodeLink + v2);
if ( (_DWORD)v4 != (_DWORD)v5 )
{
printf("partition %d inode %d inconsistent link count: %d Vs %d\n", partitionNumber, v0 + 1, v4, v5);
*(_WORD *)(v3 + 26) = *(_DWORD *)(inodeLink + v2);
getInodeGroupBlock(v0, &v6, v7, x);
writeDisk(
(unsigned int)((v7[0] << 7) + (start << 9) + blockSize * *(_DWORD *)(groupDescs + 32LL * v6 + 8)),
128LL,
inodeTable + 32 * v2);
}
++v0;
v2 += 4LL;
result = (unsigned int)(groupNum * x[10]);
}
while ( (unsigned int)result > v0 );
}
return result;
}

original_code:
void pass3() {
 int i;
 struct ext2_inode *inode;
 for (i = localNo(2); i< groupNum * ((&x)->s_inodes_per_group); ++i) {
  inode = inodeTable + i;
  if (inode->i_links_count != inodeLink[i]) {
   printf("partition %d inode %d inconsistent link count: %d Vs %d\n", partitionNumber, i + 1, inode->i_links_count, inodeLink[i]);
   inode->i_links_count = inodeLink[i];
   int groupNo;
   int groupInodeNo;
   getInodeGroupBlock(i, &groupNo, &groupInodeNo, &x);
   writeDisk(start * 512 + groupDescs[groupNo].bg_inode_table * blockSize + sizeof(struct ext2_inode) * groupInodeNo, sizeof(struct ext2_inode), inodeTable + i);
  }
 }
}

variable_types: i int

variable_types: struct ext2_inode { unsigned short i_mode; unsigned short i_uid; unsigned int i_size; unsigned int i_atime; unsigned int i_ctime; unsigned int i_mtime; unsigned int i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned int i_blocks; unsigned int i_flags; union { struct { unsigned int l_i_reserved1; } linux1; struct { unsigned int h_i_translator; } hurd1; struct { unsigned int m_i_reserved1; } masix1; } osd1; unsigned int i_block[-1]; unsigned int i_generation; unsigned int i_file_acl; unsigned int i_dir_acl; unsigned int i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned int l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned int h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned int m_i_reserved2[2]; } masix2; } osd2; } *

variable_types: groupNo int

variable_types: groupInodeNo int


init

decompiled_code:
char *__fastcall init(int a1, unsigned int a2)
{
int v2; // ebx
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // ebx
int v8; // ebx
unsigned int v9; // ebp
char *result; // rax

partitionNumber = a1;
start = a2;
getSuperBlock(a2, x);
v2 = getGroupNumber(x);
groupNum = v2;
blockSize = 1024 << x[6];
groupDescs = malloc(32LL * v2);
getGroupDescs((unsigned int)start, groupDescs, (unsigned int)v2);
v3 = blockSize;
v4 = groupNum;
blockBitmap = malloc(groupNum * blockSize + 1);
getBlockBitmap((unsigned int)start, groupDescs, v4, blockBitmap, v3);
v5 = blockSize;
v6 = groupNum;
inodeBitmap = malloc(groupNum * blockSize + 1);
getInodeBitmap((unsigned int)start, groupDescs, v6, inodeBitmap, v5);
v7 = groupNum;
inodeTable = malloc((groupNum * (unsigned __int64)x[10]) << 7);
getInodeTable((unsigned int)start, x, groupDescs, v7, inodeTable, (unsigned int)blockSize);
v8 = groupNum;
v9 = x[10];
result = (char *)malloc(4 * v9 * (__int64)groupNum);
inodeLink = result;
if ( v9 * v8 )
{
result = 0LL;
do
*((_DWORD *)inodeLink + (_QWORD)result++) = 0;
while ( groupNum * x[10] > (unsigned int)result );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int a1, unsigned int a2)
{
int v2; // ebx
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // ebx
int v8; // ebx
unsigned int v9; // ebp
char *result; // rax

partitionNumber = a1;
start = a2;
getSuperBlock(a2, x);
v2 = getGroupNumber(x);
groupNum = v2;
blockSize = 1024 << x[6];
groupDescs = malloc(32LL * v2);
getGroupDescs((unsigned int)start, groupDescs, (unsigned int)v2);
v3 = blockSize;
v4 = groupNum;
blockBitmap = malloc(groupNum * blockSize + 1);
getBlockBitmap((unsigned int)start, groupDescs, v4, blockBitmap, v3);
v5 = blockSize;
v6 = groupNum;
inodeBitmap = malloc(groupNum * blockSize + 1);
getInodeBitmap((unsigned int)start, groupDescs, v6, inodeBitmap, v5);
v7 = groupNum;
inodeTable = malloc((groupNum * (unsigned __int64)x[10]) << 7);
getInodeTable((unsigned int)start, x, groupDescs, v7, inodeTable, (unsigned int)blockSize);
v8 = groupNum;
v9 = x[10];
result = (char *)malloc(4 * v9 * (__int64)groupNum);
inodeLink = result;
if ( v9 * v8 )
{
result = 0LL;
do
*((_DWORD *)inodeLink + (_QWORD)result++) = 0;
while ( groupNum * x[10] > (unsigned int)result );
}
return result;
}

original_code:
void init(int pN, int parStart) {
 partitionNumber = pN;
 start = parStart;
 getSuperBlock(start, &x);
 groupNum = getGroupNumber(&x);
 blockSize = (1024 << (&x)->s_log_block_size);
 groupDescs = malloc(groupNum * sizeof(struct ext2_group_desc));
 getGroupDescs(start, groupDescs, groupNum);
 blockBitmap = malloc(blockSize * groupNum + 1);
 getBlockBitmap(start, groupDescs, groupNum, blockBitmap, blockSize);
 inodeBitmap = malloc(blockSize * groupNum + 1);
 getInodeBitmap(start, groupDescs, groupNum, inodeBitmap, blockSize);
 inodeTable = malloc(sizeof(struct ext2_inode) * groupNum * ((&x)->s_inodes_per_group));
 getInodeTable(start, &x, groupDescs, groupNum, inodeTable, blockSize);
 inodeLink = malloc(sizeof(int) * groupNum * ((&x)->s_inodes_per_group));
 int i;
 for (i = 0; i < groupNum * ((&x)->s_inodes_per_group); ++i)
  inodeLink[i] = 0;
}

variable_types: pN int

variable_types: parStart int

user_defined_types: struct ext2_group_desc { unsigned int bg_block_bitmap; unsigned int bg_inode_bitmap; unsigned int bg_inode_table; unsigned short bg_free_blocks_count; unsigned short bg_free_inodes_count; unsigned short bg_used_dirs_count; unsigned short bg_pad; unsigned int bg_reserved[3]; }


cleanup

decompiled_code:
void cleanup()
{
free(groupDescs);
free(blockBitmap);
free(inodeBitmap);
free(inodeTable);
free(inodeLink);
}

canonical_decompiled_code:
void func1()
{
free(groupDescs);
free(blockBitmap);
free(inodeBitmap);
free(inodeTable);
free(inodeLink);
}


printPartitionInfo

decompiled_code:
void __fastcall printPartitionInfo(int a1)
{
int *v1; // r14
int *v2; // rbp
__int64 i; // rbx
int v4; // ebx
int v5; // er12
int v6; // eax
__int64 v7; // r14
__int64 v8; // rbp
_BYTE v9[4]; // [rsp+0h] [rbp-98h] BYREF
char v10[148]; // [rsp+4h] [rbp-94h]

device = open(diskFileName, 2);
if ( device == -1 )
{
perror("Open disk image error");
}
else
{
readDisk(446LL, 64LL, v9);
v1 = par;
v2 = par;
for ( i = 0LL; i != 64; i += 16LL )
{
*((_BYTE *)v2 + 12) = v10[i];
v2[4] = getIntFromBuf(v9, (unsigned int)(i + 8));
v2[5] = getIntFromBuf(v9, (unsigned int)(i + 12));
v2 += 3;
}
pNum = 4;
v4 = -1;
v5 = -1;
do
{
if ( *((_BYTE *)v1 + 12) == 5 )
{
v5 = v1[4];
v4 = v5;
}
v1 += 3;
}
while ( (int *)(unsigned int)((_DWORD)par + 48) != v1 );
while ( v4 != -1 )
{
readDisk((unsigned int)((v4 << 9) + 446), 64LL, v9);
LOBYTE(par[3 * ++pNum]) = v10[0];
v6 = getIntFromBuf(v9, 8LL);
v7 = pNum;
v8 = 2LL * pNum;
par[3 * pNum + 1] = v6 + v4;
par[v7 + 2 + v8] = getIntFromBuf(v9, 12LL);
if ( v10[16] != 5 )
break;
v4 = getIntFromBuf(v9, 24LL) + v5;
getIntFromBuf(v9, 28LL);
}
if ( !a1 )
{
if ( theParNum > 0 && theParNum <= pNum )
printf(
"0x%02X %d %d\n",
LOBYTE(par[3 * theParNum]),
(unsigned int)par[3 * theParNum + 1],
(unsigned int)par[3 * theParNum + 2]);
else
puts("-1");
}
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int *v1; // r14
int *v2; // rbp
__int64 i; // rbx
int v4; // ebx
int v5; // er12
int v6; // eax
__int64 v7; // r14
__int64 v8; // rbp
_BYTE v9[4]; // [rsp+0h] [rbp-98h] BYREF
char v10[148]; // [rsp+4h] [rbp-94h]

device = open(diskFileName, 2);
if ( device == -1 )
{
perror("Open disk image error");
}
else
{
readDisk(446LL, 64LL, v9);
v1 = par;
v2 = par;
for ( i = 0LL; i != 64; i += 16LL )
{
*((_BYTE *)v2 + 12) = v10[i];
v2[4] = getIntFromBuf(v9, (unsigned int)(i + 8));
v2[5] = getIntFromBuf(v9, (unsigned int)(i + 12));
v2 += 3;
}
pNum = 4;
v4 = -1;
v5 = -1;
do
{
if ( *((_BYTE *)v1 + 12) == 5 )
{
v5 = v1[4];
v4 = v5;
}
v1 += 3;
}
while ( (int *)(unsigned int)((_DWORD)par + 48) != v1 );
while ( v4 != -1 )
{
readDisk((unsigned int)((v4 << 9) + 446), 64LL, v9);
LOBYTE(par[3 * ++pNum]) = v10[0];
v6 = getIntFromBuf(v9, 8LL);
v7 = pNum;
v8 = 2LL * pNum;
par[3 * pNum + 1] = v6 + v4;
par[v7 + 2 + v8] = getIntFromBuf(v9, 12LL);
if ( v10[16] != 5 )
break;
v4 = getIntFromBuf(v9, 24LL) + v5;
getIntFromBuf(v9, 28LL);
}
if ( !a1 )
{
if ( theParNum > 0 && theParNum <= pNum )
printf(
"0x%02X %d %d\n",
LOBYTE(par[3 * theParNum]),
(unsigned int)par[3 * theParNum + 1],
(unsigned int)par[3 * theParNum + 2]);
else
puts("-1");
}
}
}

original_code:
void printPartitionInfo(int fsckFlag) {
 if ((device = open(diskFileName, 02)) == -1) {
  perror("Open disk image error");
  return;
 }
 int i;
 unsigned char buf[100];
 readDisk(446, 64, buf);
 for (i = 0; i < 4; ++i) {
  par[i + 1].type = buf[i*16 + 4];
  par[i + 1].start = getIntFromBuf(buf, i*16 + 8);
  par[i + 1].length = getIntFromBuf(buf, i*16 + 12);
 }
 pNum = 4;
 int extendBase = -1;
 int extendStart = -1;
 int extendLength = 0;
 for (i = 1; i <= pNum; ++i)
  if (par[i].type == 5) {
   extendBase = par[i].start;
   extendStart = par[i].start;
   extendLength = par[i].length;
  }
 while (extendStart != -1) {
  readDisk(446 + extendStart * 512, 64, buf);
  ++pNum;
  par[pNum].type = buf[4];
  par[pNum].start = extendStart + getIntFromBuf(buf, 8);
  par[pNum].length = getIntFromBuf(buf, 12);
  if (buf[16 + 4] != 5) {
   extendStart = -1;
  } else {
   extendStart = extendBase + getIntFromBuf(buf, 16 + 8);
   extendLength = getIntFromBuf(buf, 16 + 12);
  }
 }
 if (fsckFlag) return;
 if (theParNum > 0 && theParNum <= pNum)
  printf("0x%02X %d %d\n", par[theParNum].type, par[theParNum].start, par[theParNum].length);
 else
  printf("-1\n");
 return;
}

variable_types: fsckFlag int

variable_types:
buf
unsigned char [100]

variable_types: extendBase int

variable_types: extendStart int

variable_types: extendLength int


original_code:
int app_singleton(char *pid_file)
{
    int fd = -1;
    int m = 0;
    int n = 0;
    char buf[64] = {0};
    struct flock lock;
    fd = open(pid_file, 02|0100, 0400|0200);
    if(-1 == fd){
        return -1;
    }
    lock.l_type = 1;
    lock.l_whence = 0;
    if (fcntl(fd, 6, &lock) < 0){
        close(fd);
        return -1;
    }
    m = snprintf(buf, 64, "%u", (unsigned int)getpid());
    n = write(fd, buf, m);
    if(n != m){
        return -1;
    }
    return fd;
}

variable_types: fd int

variable_types: m int

variable_types: n int

variable_types:
buf
char [64]

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


repo: Wescoeur/Reversi

original_code:
int ia_eval_grid(Reversi *reversi, Player player)
{
  int i, n = 0;
  for(i = 0; i < 8 * 8; i++)
    if(reversi->array[i] == player)
      n += grid[i];
    else if(reversi->array[i] == (player == 'X' ? 'O' : 'X'))
      n -= grid[i];
  return n;
}

canonical_original_code:
int ia_eval_grid(struct Reversi *reversi, char player)
{
  int i; int n = 0;
  for(i = 0; i < 8 * 8; i++)
    if(reversi->array[i] == player)
      n += grid[i];
    else if(reversi->array[i] == (player == 'X' ? 'O' : 'X'))
      n -= grid[i];
  return n;
}

variable_types: struct Reversi { char *array; unsigned int n_moves; } *

variable_types: player char


decompiled_code:
__int64 __fastcall ia_alphabeta_bis(__int64 *a1, int a2, unsigned int a3, unsigned int a4, char a5, int a6)
{
char v6; // r12
__int64 result; // rax
int v10; // er15
int i; // er15
int j; // er13
__m128i **v13; // r12
int k; // er13
__m128i **v15; // r12
unsigned int v18; // [rsp+18h] [rbp-50h]
unsigned int v19; // [rsp+1Ch] [rbp-4Ch]
int v20; // [rsp+28h] [rbp-40h] BYREF
int v21; // [rsp+2Ch] [rbp-3Ch]

v6 = a5;
if ( !a2 || (unsigned int)reversi_game_over() )
return ia_eval_grid(a1, v6);
v10 = a6;
if ( a6 )
{
v18 = 9 * (v6 != 88) + 79;
for ( i = 0; i != 8; ++i )
{
for ( j = 0; j != 8; ++j )
{
v20 = j;
v21 = i;
v13 = _grid_copy((const __m128i **)a1);
if ( (unsigned int)reversi_set_ia_move(v13, (unsigned int)a5, &v20) )
{
if ( (int)ia_alphabeta_bis(v13, (unsigned int)(a2 - 1), a3, a4, v18, 0LL) >= (int)a3 )
a3 = ia_alphabeta_bis(v13, (unsigned int)(a2 - 1), a3, a4, v18, 0LL);
if ( (int)a3 >= (int)a4 )
{
reversi_free(v13);
return a3;
}
}
reversi_free(v13);
}
}
result = a3;
}
else
{
v19 = 9 * (v6 != 88) + 79;
do
{
for ( k = 0; k != 8; ++k )
{
v20 = k;
v21 = v10;
v15 = _grid_copy((const __m128i **)a1);
if ( (unsigned int)reversi_set_ia_move(v15, (unsigned int)a5, &v20) )
{
if ( (int)ia_alphabeta_bis(v15, (unsigned int)(a2 - 1), a3, a4, v19, 1LL) <= (int)a4 )
a4 = ia_alphabeta_bis(v15, (unsigned int)(a2 - 1), a3, a4, v19, 1LL);
if ( (int)a4 <= (int)a3 )
{
reversi_free(v15);
return a4;
}
}
reversi_free(v15);
}
++v10;
}
while ( v10 != 8 );
result = a4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, int a2, unsigned int a3, unsigned int a4, char a5, int a6)
{
char v6; // r12
__int64 result; // rax
int v10; // er15
int i; // er15
int j; // er13
__m128i **v13; // r12
int k; // er13
__m128i **v15; // r12
unsigned int v18; // [rsp+18h] [rbp-50h]
unsigned int v19; // [rsp+1Ch] [rbp-4Ch]
int v20; // [rsp+28h] [rbp-40h] BYREF
int v21; // [rsp+2Ch] [rbp-3Ch]

v6 = a5;
if ( !a2 || (unsigned int)reversi_game_over() )
return func0(a1, v6);
v10 = a6;
if ( a6 )
{
v18 = 9 * (v6 != 88) + 79;
for ( i = 0; i != 8; ++i )
{
for ( j = 0; j != 8; ++j )
{
v20 = j;
v21 = i;
v13 = _grid_copy((const __m128i **)a1);
if ( (unsigned int)reversi_set_ia_move(v13, (unsigned int)a5, &v20) )
{
if ( (int)func1(v13, (unsigned int)(a2 - 1), a3, a4, v18, 0LL) >= (int)a3 )
a3 = func1(v13, (unsigned int)(a2 - 1), a3, a4, v18, 0LL);
if ( (int)a3 >= (int)a4 )
{
reversi_free(v13);
return a3;
}
}
reversi_free(v13);
}
}
result = a3;
}
else
{
v19 = 9 * (v6 != 88) + 79;
do
{
for ( k = 0; k != 8; ++k )
{
v20 = k;
v21 = v10;
v15 = _grid_copy((const __m128i **)a1);
if ( (unsigned int)reversi_set_ia_move(v15, (unsigned int)a5, &v20) )
{
if ( (int)func1(v15, (unsigned int)(a2 - 1), a3, a4, v19, 1LL) <= (int)a4 )
a4 = func1(v15, (unsigned int)(a2 - 1), a3, a4, v19, 1LL);
if ( (int)a4 <= (int)a3 )
{
reversi_free(v15);
return a4;
}
}
reversi_free(v15);
}
++v10;
}
while ( v10 != 8 );
result = a4;
}
return result;
}

original_code:
int ia_alphabeta_bis (Reversi *reversi, int depth, int alpha, int beta, Player player, int maximizingPlayer)
{
  int i,j;
  Reversi *reversiCpy = ((void *)0);
  Pos playedPos;
  if (depth == 0 || reversi_game_over(reversi))
  {
    return ia_eval_grid(reversi, player);
  }
  if (maximizingPlayer)
  {
    for(j = 0; j < 8; j++)
    {
      for(i = 0; i < 8; i++)
      {
        playedPos.x = i;
        playedPos.y = j;
        reversiCpy = __grid_copy(reversi);
        if (reversi_set_ia_move(reversiCpy, player, &playedPos))
        {
          alpha = (((alpha) > (ia_alphabeta_bis(reversiCpy, depth - 1, alpha, beta, (player == 'X' ? 'O' : 'X'), 0))) ? (alpha) : (ia_alphabeta_bis(reversiCpy, depth - 1, alpha, beta, (player == 'X' ? 'O' : 'X'), 0)));
          if (beta <= alpha)
          {
            reversi_free(reversiCpy);
            return alpha;
          }
        }
        reversi_free(reversiCpy);
      }
    }
    return alpha;
  }
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if (reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        beta = (((beta) < (ia_alphabeta_bis(reversiCpy, depth - 1, alpha, beta, (player == 'X' ? 'O' : 'X'), 1))) ? (beta) : (ia_alphabeta_bis(reversiCpy, depth - 1, alpha, beta, (player == 'X' ? 'O' : 'X'), 1)));
        if (beta <= alpha)
        {
          reversi_free(reversiCpy);
          return beta;
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return beta;
}

canonical_original_code:
int ia_alphabeta_bis(struct Reversi *reversi, int depth, int alpha, int beta, char player, int maximizingPlayer)
{
  int i; int j;
  struct Reversi *reversiCpy = ((void *)0);
  struct Pos playedPos;
  if (depth == 0 || reversi_game_over(reversi))
  {
    return ia_eval_grid(reversi, player);
  }
  if (maximizingPlayer)
  {
    for(j = 0; j < 8; j++)
    {
      for(i = 0; i < 8; i++)
      {
        playedPos.x = i;
        playedPos.y = j;
        reversiCpy = __grid_copy(reversi);
        if (reversi_set_ia_move(reversiCpy, player, &playedPos))
        {
          alpha = (((alpha) > (ia_alphabeta_bis(reversiCpy, depth - 1, alpha, beta, (player == 'X' ? 'O' : 'X'), 0))) ? (alpha) : (ia_alphabeta_bis(reversiCpy, depth - 1, alpha, beta, (player == 'X' ? 'O' : 'X'), 0)));
          if (beta <= alpha)
          {
            reversi_free(reversiCpy);
            return alpha;
          }
        }
        reversi_free(reversiCpy);
      }
    }
    return alpha;
  }
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if (reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        beta = (((beta) < (ia_alphabeta_bis(reversiCpy, depth - 1, alpha, beta, (player == 'X' ? 'O' : 'X'), 1))) ? (beta) : (ia_alphabeta_bis(reversiCpy, depth - 1, alpha, beta, (player == 'X' ? 'O' : 'X'), 1)));
        if (beta <= alpha)
        {
          reversi_free(reversiCpy);
          return beta;
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return beta;
}

variable_types: depth int

variable_types: alpha int

variable_types: beta int

variable_types: maximizingPlayer int

variable_types: i int

variable_types: j int

variable_types:
playedPos
struct Pos { int x; int y; }

user_defined_types: struct Reversi { char *array; unsigned int n_moves; }


decompiled_code:
__int64 __fastcall ia_alphabeta(const __m128i **a1, char a2, unsigned int a3)
{
signed int v3; // er13
int i; // er12
int j; // ebp
__int64 *v6; // rbx
signed int v7; // eax
__int128 v9; // [rsp+10h] [rbp-58h]
int v10[16]; // [rsp+28h] [rbp-40h] BYREF

*(_QWORD *)&v9 = a3 | 0xFFFFFFFF00000000LL;
DWORD2(v9) = -1;
v3 = 0x80000000;
for ( i = 0; i != 8; ++i )
{
for ( j = 0; j != 8; ++j )
{
v10[0] = j;
v10[1] = i;
v6 = (__int64 *)_grid_copy(a1);
if ( (unsigned int)reversi_set_ia_move(v6, (unsigned int)a2, v10) )
{
v7 = ia_alphabeta_bis(v6, (int)v9 - 1, v3, 0x7FFFFFFFu, 9 * (a2 != 88) + 79, 0);
if ( v7 >= v3 )
{
DWORD2(v9) = i;
DWORD1(v9) = j;
v3 = v7;
}
}
reversi_free(v6);
}
}
return v9 >> 32;
}

canonical_decompiled_code:
__int64 __fastcall func2(const __m128i **a1, char a2, unsigned int a3)
{
signed int v3; // er13
int i; // er12
int j; // ebp
__int64 *v6; // rbx
signed int v7; // eax
__int128 v9; // [rsp+10h] [rbp-58h]
int v10[16]; // [rsp+28h] [rbp-40h] BYREF

*(_QWORD *)&v9 = a3 | 0xFFFFFFFF00000000LL;
DWORD2(v9) = -1;
v3 = 0x80000000;
for ( i = 0; i != 8; ++i )
{
for ( j = 0; j != 8; ++j )
{
v10[0] = j;
v10[1] = i;
v6 = (__int64 *)_grid_copy(a1);
if ( (unsigned int)reversi_set_ia_move(v6, (unsigned int)a2, v10) )
{
v7 = func1(v6, (int)v9 - 1, v3, 0x7FFFFFFFu, 9 * (a2 != 88) + 79, 0);
if ( v7 >= v3 )
{
DWORD2(v9) = i;
DWORD1(v9) = j;
v3 = v7;
}
}
reversi_free(v6);
}
}
return v9 >> 32;
}

original_code:
Pos ia_alphabeta (Reversi *reversi, Player player, int depth)
{
  int i, j, temp;
  Reversi *reversiCpy = ((void *)0);
  Pos playedPos, bestPos;
  int alpha = (-0x7fffffff - 1), beta = 0x7fffffff;
  bestPos.x = -1;
  bestPos.y = -1;
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if (reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        temp = ia_alphabeta_bis(reversiCpy, depth - 1, alpha, beta, (player == 'X' ? 'O' : 'X'), 0);
        if (temp >= alpha)
        {
          alpha = temp;
          bestPos.x = i;
          bestPos.y = j;
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return bestPos;
}

canonical_original_code:
struct Pos ia_alphabeta(struct Reversi *reversi, char player, int depth)
{
  int i; int j; int temp;
  struct Reversi *reversiCpy = ((void *)0);
  struct Pos playedPos; struct Pos bestPos;
  int alpha = (-0x7fffffff - 1); int beta = 0x7fffffff;
  bestPos.x = -1;
  bestPos.y = -1;
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if (reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        temp = ia_alphabeta_bis(reversiCpy, depth - 1, alpha, beta, (player == 'X' ? 'O' : 'X'), 0);
        if (temp >= alpha)
        {
          alpha = temp;
          bestPos.x = i;
          bestPos.y = j;
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return bestPos;
}

variable_types: temp int

variable_types:
bestPos
struct Pos { int x; int y; }

return_type: struct Pos { int x; int y; }


original_code:
int ia_eval_grid_2(Reversi *reversi, Player player)
{
  int pos, pos_bis, n = 0, c;
  int GGood = 512, Ggood = 32, good = 8, bad = -256, Bad = -1024;
  Player player2 = (player == 'X' ? 'O' : 'X');
  for (pos = 0; pos < 8 * 8; ++pos)
  {
    if (reversi->array[pos] == player)
    {
      if (pos == 0 || pos == (8 - 1) || pos == (8 * (8 - 1)) || pos == ((8 * 8) -1))
      {
        n += 500;
      }
      else if (pos == 0 + 1)
      {
        if (reversi->array[0] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos + 1, c = 1;
            pos_bis <= (8 - 1) && reversi->array[pos_bis] == player;
            ++pos_bis, ++c);
          if (pos_bis > (8 - 1))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[0] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[0] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == 0 + 8)
      {
        if (reversi->array[0] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos + 8, c = 1;
            pos_bis <= (8 * (8 - 1)) && reversi->array[pos_bis] == player;
            pos_bis += 8, ++c);
          if (pos_bis > (8 * (8 - 1)))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[0] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[0] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == 0 + 8 + 1)
      {
        if (reversi->array[0] == player)
        {
          n += good;
        } else {
          n += Bad;
        }
      }
      else if (pos == (8 - 1) - 1)
      {
        if (reversi->array[(8 - 1)] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos - 1, c = 1;
            pos_bis >= 0 && reversi->array[pos_bis] == player;
            --pos_bis, ++c);
          if (pos_bis < 0)
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[(8 - 1)] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[(8 - 1)] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == (8 - 1) + 8)
      {
        if (reversi->array[(8 - 1)] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos + 8, c = 1;
            pos_bis <= ((8 * 8) -1) && reversi->array[pos_bis] == player;
            pos_bis += 8 , ++c);
          if (pos_bis > ((8 * 8) -1))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[(8 - 1)] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[(8 - 1)] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == (8 - 1) + 8 - 1)
      {
        if (reversi->array[(8 - 1)] == player)
        {
          n += good;
        } else {
          n += Bad;
        }
      }
      else if (pos == (8 * (8 - 1)) + 1)
      {
        if (reversi->array[(8 * (8 - 1))] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos + 1, c = 1;
            pos_bis <= ((8 * 8) -1) && reversi->array[pos_bis] == player;
            ++pos_bis, ++c);
          if (pos_bis > ((8 * 8) -1))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[(8 * (8 - 1))] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[(8 * (8 - 1))] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == (8 * (8 - 1)) - 8)
      {
        if (reversi->array[(8 * (8 - 1))] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos - 8, c = 1;
            pos_bis >= 0 && reversi->array[pos_bis] == player;
            pos_bis -= 8, ++c);
          if (pos_bis < (8 * (8 - 1)))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[0] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[0] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == (8 * (8 - 1)) - 8 + 1)
      {
        if (reversi->array[(8 * (8 - 1))] == player)
        {
          n += good;
        } else {
          n += Bad;
        }
      }
      else if (pos == ((8 * 8) -1) - 1)
      {
        if (reversi->array[((8 * 8) -1)] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos - 1, c = 1;
            pos_bis >= (8 * (8 - 1)) && reversi->array[pos_bis] == player;
            --pos_bis, ++c);
          if (pos_bis < (8 * (8 - 1)))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[((8 * 8) -1)] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[((8 * 8) -1)] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == ((8 * 8) -1) - 8)
      {
        if (reversi->array[((8 * 8) -1)] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos - 8, c = 1;
            pos_bis >= (8 - 1) && reversi->array[pos_bis] == player;
            pos_bis -= 8, ++c);
          if (pos_bis < (8 - 1))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[((8 * 8) -1)] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              n += (c * Bad);
            }
          }
        }
      }
      else if (pos == ((8 * 8) -1) - 8 - 1)
      {
        if (reversi->array[((8 * 8) -1)] == player)
        {
          n += good;
        } else {
          n += Bad;
        }
      }
      else {
        n += good;
      }
    }
  }
  return n;
}

canonical_original_code:
int ia_eval_grid_2(struct Reversi *reversi, char player)
{
  int pos; int pos_bis; int n = 0; int c;
  int GGood = 512; int Ggood = 32; int good = 8; int bad = -256; int Bad = -1024;
  char player2 = (player == 'X' ? 'O' : 'X');
  for (pos = 0; pos < 8 * 8; ++pos)
  {
    if (reversi->array[pos] == player)
    {
      if (pos == 0 || pos == (8 - 1) || pos == (8 * (8 - 1)) || pos == ((8 * 8) -1))
      {
        n += 500;
      }
      else if (pos == 0 + 1)
      {
        if (reversi->array[0] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos + 1, c = 1;
            pos_bis <= (8 - 1) && reversi->array[pos_bis] == player;
            ++pos_bis, ++c);
          if (pos_bis > (8 - 1))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[0] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[0] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == 0 + 8)
      {
        if (reversi->array[0] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos + 8, c = 1;
            pos_bis <= (8 * (8 - 1)) && reversi->array[pos_bis] == player;
            pos_bis += 8, ++c);
          if (pos_bis > (8 * (8 - 1)))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[0] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[0] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == 0 + 8 + 1)
      {
        if (reversi->array[0] == player)
        {
          n += good;
        } else {
          n += Bad;
        }
      }
      else if (pos == (8 - 1) - 1)
      {
        if (reversi->array[(8 - 1)] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos - 1, c = 1;
            pos_bis >= 0 && reversi->array[pos_bis] == player;
            --pos_bis, ++c);
          if (pos_bis < 0)
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[(8 - 1)] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[(8 - 1)] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == (8 - 1) + 8)
      {
        if (reversi->array[(8 - 1)] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos + 8, c = 1;
            pos_bis <= ((8 * 8) -1) && reversi->array[pos_bis] == player;
            pos_bis += 8 , ++c);
          if (pos_bis > ((8 * 8) -1))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[(8 - 1)] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[(8 - 1)] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == (8 - 1) + 8 - 1)
      {
        if (reversi->array[(8 - 1)] == player)
        {
          n += good;
        } else {
          n += Bad;
        }
      }
      else if (pos == (8 * (8 - 1)) + 1)
      {
        if (reversi->array[(8 * (8 - 1))] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos + 1, c = 1;
            pos_bis <= ((8 * 8) -1) && reversi->array[pos_bis] == player;
            ++pos_bis, ++c);
          if (pos_bis > ((8 * 8) -1))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[(8 * (8 - 1))] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[(8 * (8 - 1))] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == (8 * (8 - 1)) - 8)
      {
        if (reversi->array[(8 * (8 - 1))] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos - 8, c = 1;
            pos_bis >= 0 && reversi->array[pos_bis] == player;
            pos_bis -= 8, ++c);
          if (pos_bis < (8 * (8 - 1)))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[0] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[0] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == (8 * (8 - 1)) - 8 + 1)
      {
        if (reversi->array[(8 * (8 - 1))] == player)
        {
          n += good;
        } else {
          n += Bad;
        }
      }
      else if (pos == ((8 * 8) -1) - 1)
      {
        if (reversi->array[((8 * 8) -1)] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos - 1, c = 1;
            pos_bis >= (8 * (8 - 1)) && reversi->array[pos_bis] == player;
            --pos_bis, ++c);
          if (pos_bis < (8 * (8 - 1)))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[((8 * 8) -1)] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              if (reversi->array[((8 * 8) -1)] == player2)
              {
                n += (c * Bad);
              } else {
                n += (c * bad);
              }
            }
          }
        }
      }
      else if (pos == ((8 * 8) -1) - 8)
      {
        if (reversi->array[((8 * 8) -1)] == player)
        {
          n += Ggood;
        } else {
          for (pos_bis = pos - 8, c = 1;
            pos_bis >= (8 - 1) && reversi->array[pos_bis] == player;
            pos_bis -= 8, ++c);
          if (pos_bis < (8 - 1))
          {
            n += GGood;
          } else {
            if (reversi->array[pos_bis] == player2)
            {
              if (reversi->array[((8 * 8) -1)] == player2)
              {
                n += GGood;
              } else {
                n += (c * Bad);
              }
            } else {
              n += (c * Bad);
            }
          }
        }
      }
      else if (pos == ((8 * 8) -1) - 8 - 1)
      {
        if (reversi->array[((8 * 8) -1)] == player)
        {
          n += good;
        } else {
          n += Bad;
        }
      }
      else {
        n += good;
      }
    }
  }
  return n;
}

variable_types: pos int

variable_types: c int

variable_types: GGood int

variable_types: Ggood int

variable_types: good int

variable_types: bad int

variable_types: Bad int


decompiled_code:
void INIT_SOCKET()
{
if ( !_is_started )
_is_started = 1;
}

canonical_decompiled_code:
void func1()
{
if ( !_is_started )
_is_started = 1;
}

original_code:
void INIT_SOCKET(void)
{
  if(__is_started)
    return;
  __is_started = 1;
  return;
}

canonical_original_code:
void INIT_SOCKET()
{
  if(__is_started)
    return;
  __is_started = 1;
  return;
}


decompiled_code:
void END_SOCKET()
{
if ( _is_started )
_is_started = 0;
}

canonical_decompiled_code:
void func2()
{
if ( _is_started )
_is_started = 0;
}

original_code:
void END_SOCKET(void)
{
  if(!__is_started)
    return;
  __is_started = 0;
  return;
}

canonical_original_code:
void END_SOCKET()
{
  if(!__is_started)
    return;
  __is_started = 0;
  return;
}


decompiled_code:
__int64 __fastcall server_resolve_host(void *dest, char *name, __int16 a3)
{
in_addr_t v4; // eax
struct hostent *v5; // rax

if ( !name )
{
*(_DWORD *)dest = 0;
goto LABEL_6;
}
v4 = inet_addr(name);
*(_DWORD *)dest = v4;
if ( v4 != -1 )
{
LABEL_6:
*((_WORD *)dest + 2) = _bswap_16(a3);
return 0LL;
}
v5 = gethostbyname(name);
if ( v5 )
{
memcpy(dest, *(const void **)v5->h_addr_list, v5->h_length);
goto LABEL_6;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *dest, char *name, __int16 a3)
{
in_addr_t v4; // eax
struct hostent *v5; // rax

if ( !name )
{
*(_DWORD *)dest = 0;
goto LABEL_6;
}
v4 = inet_addr(name);
*(_DWORD *)dest = v4;
if ( v4 != -1 )
{
LABEL_6:
*((_WORD *)dest + 2) = func0(a3);
return 0LL;
}
v5 = gethostbyname(name);
if ( v5 )
{
memcpy(dest, *(const void **)v5->h_addr_list, v5->h_length);
goto LABEL_6;
}
return 0xFFFFFFFFLL;
}

original_code:
int server_resolve_host(IP *ip, const char *hostname, in_port_t port)
{
  struct hostent *h;
  if(hostname == ((void *)0))
    ip->host = ((in_addr_t) 0x00000000);
  else if((ip->host = inet_addr(hostname)) == ((in_addr_t) 0xffffffff))
  {
    if((h = gethostbyname(hostname)) == ((void *)0))
      return -1;
    memcpy(&ip->host, h->h_addr_list[0], h->h_length);
  }
  ip->port = htons(port);
  return 0;
}

canonical_original_code:
int server_resolve_host(struct IP *ip, char *hostname, unsigned short port)
{
  struct hostent *h;
  if(hostname == ((void *)0))
    ip->host = ((unsigned int) 0x00000000);
  else if((ip->host = inet_addr(hostname)) == ((unsigned int) 0xffffffff))
  {
    if((h = gethostbyname(hostname)) == ((void *)0))
      return -1;
    memcpy(&ip->host, h->h_addr_list[0], h->h_length);
  }
  ip->port = htons(port);
  return 0;
}

variable_types: struct IP { unsigned int host; unsigned short port; } *

variable_types:
hostname
char *

variable_types:
port
unsigned short

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *