decompiled_code:
void __fastcall print_block_hexa(int fd, __int64 a2, unsigned int a3)
{
int v4; // er15
unsigned __int8 *v5; // r13
unsigned __int8 *v6; // r12
unsigned __int8 *v7; // rbp
int v8; // er14
unsigned __int8 *v9; // rbx
unsigned __int8 *v10; // rbx
unsigned __int8 *v11; // rbx
unsigned __int8 *ptr; // [rsp+8h] [rbp-40h]

v4 = 1024 << *(_DWORD *)(a2 + 24);
ptr = (unsigned __int8 *)malloc(v4);
if ( (unsigned int)read_block(fd, a2, a3, ptr) == -1 )
exit(1);
if ( v4 > 0 )
{
v5 = ptr;
v6 = ptr + 16;
v7 = ptr + 8;
v8 = 0;
do
{
printf(" %.8x ", (unsigned int)v8);
v10 = v5;
do
printf("%.2x ", *v10++);
while ( v10 != v7 );
putchar(32);
v11 = v5;
do
{
printf("%.2x ", v11[8]);
++v11;
}
while ( v11 != v7 );
printf(" |");
v9 = v5;
do
{
if ( (unsigned __int8)(*v9 - 32) > 0x5Eu )
putchar(46);
else
putchar((char)*v9);
++v9;
}
while ( v9 != v6 );
puts("|");
v8 += 16;
v6 += 16;
v5 += 16;
v7 += 16;
}
while ( v4 > v8 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(int fd, __int64 a2, unsigned int a3)
{
int v4; // er15
unsigned __int8 *v5; // r13
unsigned __int8 *v6; // r12
unsigned __int8 *v7; // rbp
int v8; // er14
unsigned __int8 *v9; // rbx
unsigned __int8 *v10; // rbx
unsigned __int8 *v11; // rbx
unsigned __int8 *ptr; // [rsp+8h] [rbp-40h]

v4 = 1024 << *(_DWORD *)(a2 + 24);
ptr = (unsigned __int8 *)malloc(v4);
if ( (unsigned int)func0(fd, a2, a3, ptr) == -1 )
exit(1);
if ( v4 > 0 )
{
v5 = ptr;
v6 = ptr + 16;
v7 = ptr + 8;
v8 = 0;
do
{
printf(" %.8x ", (unsigned int)v8);
v10 = v5;
do
printf("%.2x ", *v10++);
while ( v10 != v7 );
putchar(32);
v11 = v5;
do
{
printf("%.2x ", v11[8]);
++v11;
}
while ( v11 != v7 );
printf(" |");
v9 = v5;
do
{
if ( (unsigned __int8)(*v9 - 32) > 0x5Eu )
putchar(46);
else
putchar((char)*v9);
++v9;
}
while ( v9 != v6 );
puts("|");
v8 += 16;
v6 += 16;
v5 += 16;
v7 += 16;
}
while ( v4 > v8 );
}
free(ptr);
}

original_code:
void print_block_hexa ( int fd, struct ext3_super_block *sb, __u32 block_num ) {
  int cc, c;
  int blocksize = (1024 << (sb)->s_log_block_size);
  char *block;
  int ret;
  block = malloc ( blocksize );
  ret = read_block( fd, sb, block_num, block );
  if ( ret == -1 )
    exit(1);
  for ( cc = 0 ; cc < blocksize ; cc+= 16) {
    printf(" %.8x  ", cc);
    for ( c = 0 ; c < 8 ; c++ )
      printf("%.2x ", (__u8) block[cc+c]);
    printf(" ");
    for ( ; c < 16 ; c++ )
      printf("%.2x ", (__u8)block[cc+c]);
    printf(" |");
    for ( c = 0 ; c < 16 ; c++ )
      if ( block[c+cc] >= 32 && block[c+cc] <= 126 )
        putchar(block[c+cc]);
      else
        putchar('.');
    printf("|\n");
  }
  free ( block );
}

canonical_original_code:
void print_block_hexa(int fd, struct ext3_super_block *sb, unsigned int block_num) {
  int cc; int c;
  int blocksize = (1024 << (sb)->s_log_block_size);
  char *block;
  int ret;
  block = malloc ( blocksize );
  ret = read_block( fd, sb, block_num, block );
  if ( ret == -1 )
    exit(1);
  for ( cc = 0 ; cc < blocksize ; cc+= 16) {
    printf(" %.8x  ", cc);
    for ( c = 0 ; c < 8 ; c++ )
      printf("%.2x ", (unsigned char) block[cc+c]);
    printf(" ");
    for ( ; c < 16 ; c++ )
      printf("%.2x ", (unsigned char)block[cc+c]);
    printf(" |");
    for ( c = 0 ; c < 16 ; c++ )
      if ( block[c+cc] >= 32 && block[c+cc] <= 126 )
        putchar(block[c+cc]);
      else
        putchar('.');
    printf("|\n");
  }
  free ( block );
}

variable_types: cc int

variable_types: c int

variable_types: blocksize int


decompiled_code:
void __fastcall print_block_hexa_noline(int fd, __int64 a2, unsigned int a3)
{
int v4; // er15
unsigned __int8 *v5; // r13
unsigned __int8 *v6; // r12
unsigned __int8 *v7; // rbp
int v8; // er14
unsigned __int8 *v9; // rbx
unsigned __int8 *v10; // rbx
unsigned __int8 *v11; // rbx
unsigned __int8 *ptr; // [rsp+8h] [rbp-40h]

v4 = 1024 << *(_DWORD *)(a2 + 24);
ptr = (unsigned __int8 *)malloc(v4);
if ( (unsigned int)read_block(fd, a2, a3, ptr) == -1 )
exit(1);
if ( v4 > 0 )
{
v5 = ptr;
v6 = ptr + 16;
v7 = ptr + 8;
v8 = 0;
do
{
printf(" ");
v10 = v5;
do
printf("%.2x ", *v10++);
while ( v10 != v7 );
putchar(32);
v11 = v5;
do
{
printf("%.2x ", v11[8]);
++v11;
}
while ( v11 != v7 );
printf(" |");
v9 = v5;
do
{
if ( (unsigned __int8)(*v9 - 32) > 0x5Eu )
putchar(46);
else
putchar((char)*v9);
++v9;
}
while ( v9 != v6 );
puts("|");
v8 += 16;
v6 += 16;
v5 += 16;
v7 += 16;
}
while ( v4 > v8 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(int fd, __int64 a2, unsigned int a3)
{
int v4; // er15
unsigned __int8 *v5; // r13
unsigned __int8 *v6; // r12
unsigned __int8 *v7; // rbp
int v8; // er14
unsigned __int8 *v9; // rbx
unsigned __int8 *v10; // rbx
unsigned __int8 *v11; // rbx
unsigned __int8 *ptr; // [rsp+8h] [rbp-40h]

v4 = 1024 << *(_DWORD *)(a2 + 24);
ptr = (unsigned __int8 *)malloc(v4);
if ( (unsigned int)func0(fd, a2, a3, ptr) == -1 )
exit(1);
if ( v4 > 0 )
{
v5 = ptr;
v6 = ptr + 16;
v7 = ptr + 8;
v8 = 0;
do
{
printf(" ");
v10 = v5;
do
printf("%.2x ", *v10++);
while ( v10 != v7 );
putchar(32);
v11 = v5;
do
{
printf("%.2x ", v11[8]);
++v11;
}
while ( v11 != v7 );
printf(" |");
v9 = v5;
do
{
if ( (unsigned __int8)(*v9 - 32) > 0x5Eu )
putchar(46);
else
putchar((char)*v9);
++v9;
}
while ( v9 != v6 );
puts("|");
v8 += 16;
v6 += 16;
v5 += 16;
v7 += 16;
}
while ( v4 > v8 );
}
free(ptr);
}

original_code:
void print_block_hexa_noline ( int fd, struct ext3_super_block *sb,
    __u32 block_num ) {
  int cc, c;
  int blocksize = (1024 << (sb)->s_log_block_size);
  char *block;
  int ret;
  block = malloc ( blocksize );
  ret = read_block( fd, sb, block_num, block );
  if ( ret == -1 )
    exit(1);
  for ( cc = 0 ; cc < blocksize ; cc+= 16) {
    printf("     ");
    for ( c = 0 ; c < 8 ; c++ )
      printf("%.2x ", (__u8) block[cc+c]);
    printf(" ");
    for ( ; c < 16 ; c++ )
      printf("%.2x ", (__u8)block[cc+c]);
    printf(" |");
    for ( c = 0 ; c < 16 ; c++ )
      if ( block[c+cc] >= 32 && block[c+cc] <= 126 )
        putchar(block[c+cc]);
      else
        putchar('.');
    printf("|\n");
  }
  free ( block );
}

canonical_original_code:
void print_block_hexa_noline(int fd, struct ext3_super_block *sb, unsigned int block_num) {
  int cc; int c;
  int blocksize = (1024 << (sb)->s_log_block_size);
  char *block;
  int ret;
  block = malloc ( blocksize );
  ret = read_block( fd, sb, block_num, block );
  if ( ret == -1 )
    exit(1);
  for ( cc = 0 ; cc < blocksize ; cc+= 16) {
    printf("     ");
    for ( c = 0 ; c < 8 ; c++ )
      printf("%.2x ", (unsigned char) block[cc+c]);
    printf(" ");
    for ( ; c < 16 ; c++ )
      printf("%.2x ", (unsigned char)block[cc+c]);
    printf(" |");
    for ( c = 0 ; c < 16 ; c++ )
      if ( block[c+cc] >= 32 && block[c+cc] <= 126 )
        putchar(block[c+cc]);
      else
        putchar('.');
    printf("|\n");
  }
  free ( block );
}

variable_types: fd int

variable_types: struct ext3_super_block { unsigned int s_inodes_count; unsigned int s_blocks_count; unsigned int s_r_blocks_count; unsigned int s_free_blocks_count; unsigned int s_free_inodes_count; unsigned int s_first_data_block; unsigned int s_log_block_size; unsigned int s_log_frag_size; unsigned int s_blocks_per_group; unsigned int s_frags_per_group; unsigned int s_inodes_per_group; unsigned int s_mtime; unsigned int s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_errors; unsigned short s_minor_rev_level; unsigned int s_lastcheck; unsigned int s_checkinterval; unsigned int s_creator_os; unsigned int s_rev_level; unsigned short s_def_resuid; unsigned short s_def_resgid; unsigned int s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned int s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_reserved_gdt_blocks; unsigned char s_journal_uuid[16]; unsigned int s_journal_inum; unsigned int s_journal_dev; unsigned int s_last_orphan; unsigned int s_hash_seed[4]; unsigned char s_def_hash_version; unsigned char s_reserved_char_pad; unsigned short s_reserved_word_pad; unsigned int s_default_mount_opts; unsigned int s_first_meta_bg; unsigned int s_mkfs_time; unsigned int s_jnl_blocks[17]; unsigned int s_blocks_count_hi; unsigned int s_r_blocks_count_hi; unsigned int s_free_blocks_count_hi; unsigned short s_min_extra_isize; unsigned short s_want_extra_isize; unsigned int s_flags; unsigned short s_raid_stride; unsigned short s_mmp_interval; unsigned long long s_mmp_block; unsigned int s_raid_stripe_width; unsigned char s_log_groups_per_flex; unsigned char s_reserved_char_pad2; unsigned short s_reserved_pad; unsigned int s_reserved[162]; } *

variable_types:
block
char *

variable_types: ret int

return_type: void


decompiled_code:
void __fastcall print_blocks(int fd, __int64 a2, unsigned int a3, __int16 a4, int a5)
{
unsigned int v7; // er12
__int64 v8; // r13
unsigned int v9; // er12
int v10; // [rsp+18h] [rbp-40h] BYREF
char buf[57]; // [rsp+1Fh] [rbp-39h] BYREF

if ( a4 )
{
if ( a3 )
{
v8 = a3;
if ( lseek64(fd, a3 * (__int64)(1024 << *(_DWORD *)(a2 + 24)), 0) <= 0 )
{
perror("ext3Viewer error - lseek 2 print_blocks");
exit(-1);
}
if ( !read(fd, &v10, 4uLL) )
{
perror("ext3Viewer error - read 2 print_blocks");
exit(-1);
}
v9 = 0;
while ( v10 && (1024 << *(_DWORD *)(a2 + 24)) / 4 > v9 )
{
print_blocks(fd);
++v9;
if ( lseek64(fd, 4 * v9 + v8 * (1024 << *(_DWORD *)(a2 + 24)), 0) <= 0 )
{
perror("ext3Viewer error - lseek 3 print_blocks");
exit(-1);
}
if ( !read(fd, &v10, 4uLL) )
{
perror("ext3Viewer error - read 3 print_blocks");
exit(-1);
}
}
}
}
else
{
if ( lseek64(fd, a3 * (__int64)(1024 << *(_DWORD *)(a2 + 24)), 0) <= 0 )
{
perror("ext3Viewer error - lseek block print_blocks");
exit(-1);
}
if ( a5 )
{
if ( a5 == 1 && 1024 << *(_DWORD *)(a2 + 24) )
{
v7 = 0;
do
{
if ( !read(fd, buf, 1uLL) )
{
perror("ext3Viewer error - read octet print_blocks");
exit(-1);
}
putchar(buf[0]);
++v7;
}
while ( 1024 << *(_DWORD *)(a2 + 24) > v7 );
}
}
else
{
print_block_hexa_noline(fd, a2, a3);
}
}
}

canonical_decompiled_code:
void __fastcall func5(int fd, __int64 a2, unsigned int a3, __int16 a4, int a5)
{
unsigned int v7; // er12
__int64 v8; // r13
unsigned int v9; // er12
int v10; // [rsp+18h] [rbp-40h] BYREF
char buf[57]; // [rsp+1Fh] [rbp-39h] BYREF

if ( a4 )
{
if ( a3 )
{
v8 = a3;
if ( lseek64(fd, a3 * (__int64)(1024 << *(_DWORD *)(a2 + 24)), 0) <= 0 )
{
perror("ext3Viewer error - lseek 2 print_blocks");
exit(-1);
}
if ( !read(fd, &v10, 4uLL) )
{
perror("ext3Viewer error - read 2 print_blocks");
exit(-1);
}
v9 = 0;
while ( v10 && (1024 << *(_DWORD *)(a2 + 24)) / 4 > v9 )
{
func5(fd);
++v9;
if ( lseek64(fd, 4 * v9 + v8 * (1024 << *(_DWORD *)(a2 + 24)), 0) <= 0 )
{
perror("ext3Viewer error - lseek 3 print_blocks");
exit(-1);
}
if ( !read(fd, &v10, 4uLL) )
{
perror("ext3Viewer error - read 3 print_blocks");
exit(-1);
}
}
}
}
else
{
if ( lseek64(fd, a3 * (__int64)(1024 << *(_DWORD *)(a2 + 24)), 0) <= 0 )
{
perror("ext3Viewer error - lseek block print_blocks");
exit(-1);
}
if ( a5 )
{
if ( a5 == 1 && 1024 << *(_DWORD *)(a2 + 24) )
{
v7 = 0;
do
{
if ( !read(fd, buf, 1uLL) )
{
perror("ext3Viewer error - read octet print_blocks");
exit(-1);
}
putchar(buf[0]);
++v7;
}
while ( 1024 << *(_DWORD *)(a2 + 24) > v7 );
}
}
else
{
func4(fd, a2, a3);
}
}
}

original_code:
void print_blocks ( int fd, struct ext3_super_block *sb,
    __u32 block_num, short rec_level, int mode ) {
  unsigned int c = 0;
  char octet;
  __u32 iblock_num;
  off_t lret;
  size_t sret;
  if ( rec_level == 0 ) {
    ;
    lret = lseek( fd, ((off_t) block_num)*(1024 << (sb)->s_log_block_size), 0);
    if ( lret <= 0 ) {
      perror("ext3Viewer error - lseek block print_blocks");
      exit (-1);
    }
    if ( mode == 0 ) {
      print_block_hexa_noline ( fd, sb, block_num );
    }
    else if ( mode == 1 ) {
      for ( c = 0 ; c < (1024 << (sb)->s_log_block_size) ; c++ )
      {
        sret = read ( fd, &octet, sizeof(char) );
        if ( sret <= 0 ) {
          perror("ext3Viewer error - read octet print_blocks");
          exit (-1);
        }
        putchar(octet);
      }
    }
  }
  else {
    if ( block_num > 0 ) {
      ;
      lret = lseek( fd, ((off_t) block_num)*(1024 << (sb)->s_log_block_size), 0);
      if ( lret <= 0 ) {
        perror("ext3Viewer error - lseek 2 print_blocks");
        exit (-1);
      }
      sret = read ( fd, &iblock_num, 4 );
      if ( sret <= 0 ) {
        perror("ext3Viewer error - read 2 print_blocks");
        exit (-1);
      }
      while ( iblock_num != 0 && c < ((1024 << (sb)->s_log_block_size)/4) )
      {
        print_blocks ( fd, sb, iblock_num, rec_level-1, mode );
        c++;
        lret = lseek( fd, ((off_t) block_num)*(1024 << (sb)->s_log_block_size)+(c*4),
            0);
        if ( lret <= 0 ) {
          perror("ext3Viewer error - lseek 3 print_blocks");
          exit (-1);
        }
        sret = read ( fd, &iblock_num, 4 );
        if ( sret <= 0 ) {
          perror("ext3Viewer error - read 3 print_blocks");
          exit (-1);
        }
      }
    }
  }
}

canonical_original_code:
void print_blocks(int fd, struct ext3_super_block *sb, unsigned int block_num, short rec_level, int mode) {
  unsigned int c = 0;
  char octet;
  unsigned int iblock_num;
  long lret;
  unsigned long sret;
  if ( rec_level == 0 ) {
    ;
    lret = lseek( fd, ((long) block_num)*(1024 << (sb)->s_log_block_size), 0);
    if ( lret <= 0 ) {
      perror("ext3Viewer error - lseek block print_blocks");
      exit (-1);
    }
    if ( mode == 0 ) {
      print_block_hexa_noline ( fd, sb, block_num );
    }
    else if ( mode == 1 ) {
      for ( c = 0 ; c < (1024 << (sb)->s_log_block_size) ; c++ )
      {
        sret = read ( fd, &octet, sizeof(char) );
        if ( sret <= 0 ) {
          perror("ext3Viewer error - read octet print_blocks");
          exit (-1);
        }
        putchar(octet);
      }
    }
  }
  else {
    if ( block_num > 0 ) {
      ;
      lret = lseek( fd, ((long) block_num)*(1024 << (sb)->s_log_block_size), 0);
      if ( lret <= 0 ) {
        perror("ext3Viewer error - lseek 2 print_blocks");
        exit (-1);
      }
      sret = read ( fd, &iblock_num, 4 );
      if ( sret <= 0 ) {
        perror("ext3Viewer error - read 2 print_blocks");
        exit (-1);
      }
      while ( iblock_num != 0 && c < ((1024 << (sb)->s_log_block_size)/4) )
      {
        print_blocks ( fd, sb, iblock_num, rec_level-1, mode );
        c++;
        lret = lseek( fd, ((long) block_num)*(1024 << (sb)->s_log_block_size)+(c*4),
            0);
        if ( lret <= 0 ) {
          perror("ext3Viewer error - lseek 3 print_blocks");
          exit (-1);
        }
        sret = read ( fd, &iblock_num, 4 );
        if ( sret <= 0 ) {
          perror("ext3Viewer error - read 3 print_blocks");
          exit (-1);
        }
      }
    }
  }
}

variable_types: mode int

variable_types:
c
unsigned int

variable_types: octet char

variable_types: lret long

variable_types:
sret
unsigned long

user_defined_types: struct ext3_super_block { unsigned int s_inodes_count; unsigned int s_blocks_count; unsigned int s_r_blocks_count; unsigned int s_free_blocks_count; unsigned int s_free_inodes_count; unsigned int s_first_data_block; unsigned int s_log_block_size; unsigned int s_log_frag_size; unsigned int s_blocks_per_group; unsigned int s_frags_per_group; unsigned int s_inodes_per_group; unsigned int s_mtime; unsigned int s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_errors; unsigned short s_minor_rev_level; unsigned int s_lastcheck; unsigned int s_checkinterval; unsigned int s_creator_os; unsigned int s_rev_level; unsigned short s_def_resuid; unsigned short s_def_resgid; unsigned int s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned int s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_reserved_gdt_blocks; unsigned char s_journal_uuid[16]; unsigned int s_journal_inum; unsigned int s_journal_dev; unsigned int s_last_orphan; unsigned int s_hash_seed[4]; unsigned char s_def_hash_version; unsigned char s_reserved_char_pad; unsigned short s_reserved_word_pad; unsigned int s_default_mount_opts; unsigned int s_first_meta_bg; unsigned int s_mkfs_time; unsigned int s_jnl_blocks[17]; unsigned int s_blocks_count_hi; unsigned int s_r_blocks_count_hi; unsigned int s_free_blocks_count_hi; unsigned short s_min_extra_isize; unsigned short s_want_extra_isize; unsigned int s_flags; unsigned short s_raid_stride; unsigned short s_mmp_interval; unsigned long long s_mmp_block; unsigned int s_raid_stripe_width; unsigned char s_log_groups_per_flex; unsigned char s_reserved_char_pad2; unsigned short s_reserved_pad; unsigned int s_reserved[162]; }


original_code:
void print_t_bin(char content)
{
  printf("%d", content&1);
  printf("%d",(content&2)>>1);
  printf("%d",(content&4)>>2);
  printf("%d",(content&8)>>3);
  printf("%d",(content&16)>>4);
  printf("%d",(content&32)>>5);
  printf("%d",(content&64)>>6);
  printf("%d",(content&128)>>7);
}

variable_types: content char


decompiled_code:
__int64 __fastcall open_fs(const char *a1)
{
unsigned int v1; // ebx

v1 = open64(a1, 0);
if ( v1 == -1 )
perror("Could not open the filesystem ");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
unsigned int v1; // ebx

v1 = open64(a1, 0);
if ( v1 == -1 )
perror("Could not open the filesystem ");
return v1;
}

original_code:
int open_fs ( char * path ) {
  int fd;
  ;
  if ( ( fd = open ( path, 00 ) )== -1) {
    perror("Could not open the filesystem ");
    return -1;
  }
  else return fd;
}

canonical_original_code:
int open_fs(char *path) {
  int fd;
  ;
  if ( ( fd = open ( path, 00 ) )== -1) {
    perror("Could not open the filesystem ");
    return -1;
  }
  else return fd;
}

variable_types:
path
char *

return_type: int


decompiled_code:
__int64 __fastcall close_fs(int a1)
{
unsigned int v1; // ebx

if ( close(a1) != -1 )
return 0;
v1 = -1;
perror("close_fs error");
return v1;
}

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

if ( close(a1) != -1 )
return 0;
v1 = -1;
perror("close_fs error");
return v1;
}

original_code:
int close_fs ( int fd ) {
  ;
  if ( close( fd ) == -1 ) {
    perror("close_fs error");
    return -1;
  }
  return 0;
}

canonical_original_code:
int close_fs(int fd) {
  ;
  if ( close( fd ) == -1 ) {
    perror("close_fs error");
    return -1;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall read_journal_superblock(int fd, int a2, unsigned int a3, void *a4)
{
__int64 result; // rax

if ( lseek64(fd, a2 * (unsigned __int64)a3, 0) == -1 )
{
perror("ext3Viewer - lseek error: journal superblock");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, a4, 0x400uLL) == -1 )
{
perror("ext3Viewer - read error: journal superblock");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, int a2, unsigned int a3, void *a4)
{
__int64 result; // rax

if ( lseek64(fd, a2 * (unsigned __int64)a3, 0) == -1 )
{
perror("ext3Viewer - lseek error: journal superblock");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, a4, 0x400uLL) == -1 )
{
perror("ext3Viewer - read error: journal superblock");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int read_journal_superblock(int fd, int block_size, __u32 jsb_block_num, struct journal_superblock_s *jsb ) {
  off_t lret;
  ssize_t sret;
  __u64 jsb_pos =(__u64)(jsb_block_num) * block_size;
  lret = lseek( fd, jsb_pos, 0);
  if ( lret == -1 ) {
    perror("ext3Viewer - lseek error: journal superblock");
    return -1;
  }
  sret = read( fd, jsb, sizeof(struct journal_superblock_s) );
  if ( sret == -1 ) {
    perror("ext3Viewer - read error: journal superblock");
    return -1;
  }
  return 0;
}

canonical_original_code:
int read_journal_superblock(int fd, int block_size, unsigned int jsb_block_num, struct journal_superblock_s *jsb) {
  long lret;
  long sret;
  unsigned long long jsb_pos = (__u64)(jsb_block_num) * block_size;
  lret = lseek( fd, jsb_pos, 0);
  if ( lret == -1 ) {
    perror("ext3Viewer - lseek error: journal superblock");
    return -1;
  }
  sret = read( fd, jsb, sizeof(struct journal_superblock_s) );
  if ( sret == -1 ) {
    perror("ext3Viewer - read error: journal superblock");
    return -1;
  }
  return 0;
}

variable_types: struct journal_superblock_s { struct journal_header_s { unsigned int h_magic; unsigned int h_blocktype; unsigned int h_sequence; } s_header; unsigned int s_blocksize; unsigned int s_maxlen; unsigned int s_first; unsigned int s_sequence; unsigned int s_start; unsigned int s_errno; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned char s_uuid[16]; unsigned int s_nr_users; unsigned int s_dynsuper; unsigned int s_max_transaction; unsigned int s_max_trans_data; unsigned int s_padding[44]; unsigned char s_users[-1]; } *

variable_types: sret long

user_defined_types: struct journal_superblock_s { struct journal_header_s s_header; unsigned int s_blocksize; unsigned int s_maxlen; unsigned int s_first; unsigned int s_sequence; unsigned int s_start; unsigned int s_errno; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned char s_uuid[16]; unsigned int s_nr_users; unsigned int s_dynsuper; unsigned int s_max_transaction; unsigned int s_max_trans_data; unsigned int s_padding[44]; unsigned char s_users[-1]; }


decompiled_code:
__int64 __fastcall read_journal_header(int fd, int a2, unsigned int a3, void *a4)
{
__int64 result; // rax

if ( lseek64(fd, a2 * (unsigned __int64)a3, 0) == -1 )
{
perror("ext3Viewer - lseek error: journal header");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, a4, 0xCuLL) == -1 )
{
perror("ext3Viewer - read error: journal header");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, int a2, unsigned int a3, void *a4)
{
__int64 result; // rax

if ( lseek64(fd, a2 * (unsigned __int64)a3, 0) == -1 )
{
perror("ext3Viewer - lseek error: journal header");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, a4, 0xCuLL) == -1 )
{
perror("ext3Viewer - read error: journal header");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int read_journal_header( int fd, int block_size,
    __u32 journal_block_num, struct journal_header_s *header ) {
  off_t lret;
  ssize_t sret;
  __u64 journal_offset = (__u64)(journal_block_num) * block_size;
  lret = lseek( fd, journal_offset, 0 );
  if ( lret == -1 ) {
    perror("ext3Viewer - lseek error: journal header");
    return -1;
  }
  sret = read( fd, header, sizeof(struct journal_header_s) );
  if ( sret == -1 ) {
    perror("ext3Viewer - read error: journal header");
    return -1;
  }
  return 0;
}

canonical_original_code:
int read_journal_header(int fd, int block_size, unsigned int journal_block_num, struct journal_header_s *header) {
  long lret;
  long sret;
  unsigned long long journal_offset = (__u64)(journal_block_num) * block_size;
  lret = lseek( fd, journal_offset, 0 );
  if ( lret == -1 ) {
    perror("ext3Viewer - lseek error: journal header");
    return -1;
  }
  sret = read( fd, header, sizeof(struct journal_header_s) );
  if ( sret == -1 ) {
    perror("ext3Viewer - read error: journal header");
    return -1;
  }
  return 0;
}

variable_types: struct journal_header_s { unsigned int h_magic; unsigned int h_blocktype; unsigned int h_sequence; } *


decompiled_code:
__int64 __fastcall read_journal_revoke_header(int fd, int a2, unsigned int a3, int a4, void *a5)
{
__int64 result; // rax

if ( lseek64(fd, a3 * (__int64)a2 + a4, 0) == -1 )
{
perror("ext3Viewer - lseek error: journal header");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, a5, 0x10uLL) == -1 )
{
perror("ext3Viewer - read error: journal header");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, int a2, unsigned int a3, int a4, void *a5)
{
__int64 result; // rax

if ( lseek64(fd, a3 * (__int64)a2 + a4, 0) == -1 )
{
perror("ext3Viewer - lseek error: journal header");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, a5, 0x10uLL) == -1 )
{
perror("ext3Viewer - read error: journal header");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int read_journal_revoke_header(int fd, int block_size,
    __u32 journal_block, int offset, struct journal_revoke_header_s *header ) {
  off_t lret;
  ssize_t sret;
  __u64 journal_offset = (__u64)(journal_block) * block_size;
  lret = lseek( fd, journal_offset + offset , 0 );
  if ( lret == -1 ) {
    perror("ext3Viewer - lseek error: journal header");
    return -1;
  }
  sret = read( fd, header, sizeof(struct journal_revoke_header_s) );
  if ( sret == -1 ) {
    perror("ext3Viewer - read error: journal header");
    return -1;
  }
  return 0;
}

canonical_original_code:
int read_journal_revoke_header(int fd, int block_size, unsigned int journal_block, int offset, struct journal_revoke_header_s *header) {
  long lret;
  long sret;
  unsigned long long journal_offset = (__u64)(journal_block) * block_size;
  lret = lseek( fd, journal_offset + offset , 0 );
  if ( lret == -1 ) {
    perror("ext3Viewer - lseek error: journal header");
    return -1;
  }
  sret = read( fd, header, sizeof(struct journal_revoke_header_s) );
  if ( sret == -1 ) {
    perror("ext3Viewer - read error: journal header");
    return -1;
  }
  return 0;
}

variable_types: offset int

variable_types: struct journal_revoke_header_s { struct journal_header_s { unsigned int h_magic; unsigned int h_blocktype; unsigned int h_sequence; } r_header; unsigned int r_count; } *

user_defined_types: struct journal_revoke_header_s { struct journal_header_s r_header; unsigned int r_count; }


decompiled_code:
int __fastcall print_journal_header(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
int result; // eax

if ( (unsigned int)_fswab32(*a1) != -1069860456 )
puts("ERROR ---------------------");
puts("Journal superblock header:");
v1 = _fswab32(*a1);
printf("Journal magic number:%#x, should be %#x \n", v1, 3225106840LL);
v2 = _fswab32(a1[1]);
printf("Journal block type:%u ", v2);
switch ( (unsigned int)_fswab32(a1[1]) )
{
case 1u:
puts("JFS_DESCRIPTOR_BLOCK");
goto LABEL_5;
case 2u:
puts("JFS_COMMIT_BLOCK");
goto LABEL_5;
case 3u:
puts("JFS_SUPERBLOCK_V1");
goto LABEL_5;
case 4u:
puts("JFS_SUPERBLOCK_V2");
goto LABEL_5;
case 5u:
puts("JFS_REVOKE_BLOCK");
LABEL_5:
v3 = _fswab32(a1[2]);
result = printf("Journal sequence:%u \n\n", v3);
break;
default:
result = puts("Unexpected block type");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
int result; // eax

if ( (unsigned int)func1(*a1) != -1069860456 )
puts("ERROR ---------------------");
puts("Journal superblock header:");
v1 = func1(*a1);
printf("Journal magic number:%#x, should be %#x \n", v1, 3225106840LL);
v2 = func1(a1[1]);
printf("Journal block type:%u ", v2);
switch ( (unsigned int)func1(a1[1]) )
{
case 1u:
puts("JFS_DESCRIPTOR_BLOCK");
goto LABEL_5;
case 2u:
puts("JFS_COMMIT_BLOCK");
goto LABEL_5;
case 3u:
puts("JFS_SUPERBLOCK_V1");
goto LABEL_5;
case 4u:
puts("JFS_SUPERBLOCK_V2");
goto LABEL_5;
case 5u:
puts("JFS_REVOKE_BLOCK");
LABEL_5:
v3 = func1(a1[2]);
result = printf("Journal sequence:%u \n\n", v3);
break;
default:
result = puts("Unexpected block type");
break;
}
return result;
}

user_defined_types: struct journal_header_s { unsigned int h_magic; unsigned int h_blocktype; unsigned int h_sequence; }


decompiled_code:
int __fastcall print_journal_revoke_header(unsigned int *a1)
{
int result; // eax
unsigned int v2; // eax

print_journal_header(a1);
result = _fswab32(a1[1]);
if ( result == 5 )
{
v2 = _fswab32(a1[3]);
result = printf("Count of bytes used in the block: %u\n", v2);
}
return result;
}

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

func5(a1);
result = func1(a1[1]);
if ( result == 5 )
{
v2 = func1(a1[3]);
result = printf("Count of bytes used in the block: %u\n", v2);
}
return result;
}

canonical_original_code:
void print_journal_revoke_header(struct journal_revoke_header_s *header) {
  print_journal_header( &header->r_header );
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)(header->r_header.h_blocktype))) ? ((__u32)( (((__u32)((__u32)(__be32)(header->r_header.h_blocktype)) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(header->r_header.h_blocktype)) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(header->r_header.h_blocktype)) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(header->r_header.h_blocktype)) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(header->r_header.h_blocktype))) == 5 )
    printf("Count of bytes used in the block: %u\n", (__builtin_constant_p((__u32)((__u32)(__be32)(header->r_count))) ? ((__u32)( (((__u32)((__u32)(__be32)(header->r_count)) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(header->r_count)) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(header->r_count)) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(header->r_count)) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(header->r_count))));
}


decompiled_code:
__int64 __fastcall dump_journal_block(int fd, int a2, unsigned int a3)
{
int v4; // edx
__int64 result; // rax
unsigned __int64 v6; // r12
int v7; // ebx
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10[6]; // [rsp+0h] [rbp-48h] BYREF
unsigned int buf; // [rsp+18h] [rbp-30h] BYREF
unsigned int v12; // [rsp+1Ch] [rbp-2Ch]

read_journal_revoke_header(fd, a2, a3, 0, v10);
v4 = _fswab32(v10[0]);
result = 0LL;
if ( v4 == -1069860456 )
{
print_journal_revoke_header(v10);
if ( (unsigned int)_fswab32(v10[1]) == 1 )
{
v6 = a2 * (unsigned __int64)a3;
v7 = 12;
while ( 1 )
{
if ( lseek64(fd, v6 + v7, 0) == -1 )
{
perror("lseek dump journal block");
return 0xFFFFFFFFLL;
}
if ( read(fd, &buf, 8uLL) == -1 )
break;
v8 = _fswab32(buf);
printf("Concerned block number : %u\n", v8);
v9 = _fswab32(v12);
printf("flag: %u\n", v9);
if ( (_fswab32(v12) & 1) != 0 )
puts("JFS_FLAG_ESPACE: on-disk block is escaped");
if ( (_fswab32(v12) & 2) != 0 )
puts("JFS_FLAG_SAME_UUID: block has same uuid as previous");
else
v7 += 16;
if ( (_fswab32(v12) & 4) != 0 )
puts("JFS_FLAG_DELETED: block deleted by this transaction");
if ( (_fswab32(v12) & 8) != 0 )
{
puts("JFS_FLAG_LAST_TAG: last tag in this descriptor block");
v7 += 8;
if ( (_fswab32(v12) & 8) != 0 )
goto LABEL_19;
}
else
{
v7 += 8;
}
if ( v7 >= a2 )
goto LABEL_19;
}
perror("read dump journal block");
result = 0xFFFFFFFFLL;
}
else
{
LABEL_19:
puts("+------------------------------------------------------------------------------+");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, int a2, unsigned int a3)
{
int v4; // edx
__int64 result; // rax
unsigned __int64 v6; // r12
int v7; // ebx
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10[6]; // [rsp+0h] [rbp-48h] BYREF
unsigned int buf; // [rsp+18h] [rbp-30h] BYREF
unsigned int v12; // [rsp+1Ch] [rbp-2Ch]

func4(fd, a2, a3, 0, v10);
v4 = func1(v10[0]);
result = 0LL;
if ( v4 == -1069860456 )
{
func6(v10);
if ( (unsigned int)func1(v10[1]) == 1 )
{
v6 = a2 * (unsigned __int64)a3;
v7 = 12;
while ( 1 )
{
if ( lseek64(fd, v6 + v7, 0) == -1 )
{
perror("lseek dump journal block");
return 0xFFFFFFFFLL;
}
if ( read(fd, &buf, 8uLL) == -1 )
break;
v8 = func1(buf);
printf("Concerned block number : %u\n", v8);
v9 = func1(v12);
printf("flag: %u\n", v9);
if ( (func1(v12) & 1) != 0 )
puts("JFS_FLAG_ESPACE: on-disk block is escaped");
if ( (func1(v12) & 2) != 0 )
puts("JFS_FLAG_SAME_UUID: block has same uuid as previous");
else
v7 += 16;
if ( (func1(v12) & 4) != 0 )
puts("JFS_FLAG_DELETED: block deleted by this transaction");
if ( (func1(v12) & 8) != 0 )
{
puts("JFS_FLAG_LAST_TAG: last tag in this descriptor block");
v7 += 8;
if ( (func1(v12) & 8) != 0 )
goto LABEL_19;
}
else
{
v7 += 8;
}
if ( v7 >= a2 )
goto LABEL_19;
}
perror("read dump journal block");
result = 0xFFFFFFFFLL;
}
else
{
LABEL_19:
puts("+------------------------------------------------------------------------------+");
result = 0LL;
}
}
return result;
}

original_code:
int dump_journal_block ( int fd, int block_size, __u32 block_num ) {
  int offset = 0;
  struct journal_block_tag_s jb_tag;
  struct journal_revoke_header_s j_rheader;
  off_t lret;
  ssize_t sret;
  read_journal_revoke_header( fd, block_size, block_num, 0, &j_rheader );
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)((j_rheader.r_header.h_magic)))) ? ((__u32)( (((__u32)((__u32)(__be32)((j_rheader.r_header.h_magic))) & (__u32)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)((j_rheader.r_header.h_magic))) & (__u32)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)((j_rheader.r_header.h_magic))) & (__u32)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)((j_rheader.r_header.h_magic))) & (__u32)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)((j_rheader.r_header.h_magic)))) == 0xc03b3998U ) {
    print_journal_revoke_header(&j_rheader);
    if ( (__builtin_constant_p((__u32)((__u32)(__be32)(j_rheader.r_header.h_blocktype))) ? ((__u32)( (((__u32)((__u32)(__be32)(j_rheader.r_header.h_blocktype)) & (__u32)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(j_rheader.r_header.h_blocktype)) & (__u32)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(j_rheader.r_header.h_blocktype)) & (__u32)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(j_rheader.r_header.h_blocktype)) & (__u32)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(j_rheader.r_header.h_blocktype))) ==
  1 ) {
      offset = sizeof( struct journal_header_s );
      do {
  lret = lseek( fd, (__u64)(block_num)*block_size + offset, 0 );
  if ( lret == -1 ) {
    perror("lseek dump journal block");
    return -1;
  }
  sret = read( fd, &jb_tag, sizeof(struct journal_block_tag_s ) );
  if ( sret == -1 ) {
    perror("read dump journal block");
    return -1;
  }
  printf("Concerned block number : %u\n", (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_blocknr))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_blocknr)) & (__u32)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_blocknr)) & (__u32)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_blocknr)) & (__u32)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_blocknr)) & (__u32)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_blocknr))));
  printf("flag: %u\n", (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))));
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))) & 1 ) {
    printf("JFS_FLAG_ESPACE: on-disk block is escaped\n");
  }
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))) & 2 ) {
    printf("JFS_FLAG_SAME_UUID: block has same uuid as previous\n");
  }
  else
    offset += 16;
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))) & 4) {
    printf("JFS_FLAG_DELETED: block deleted by this transaction\n");
        }
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))) & 8 ) {
    printf("JFS_FLAG_LAST_TAG: last tag in this descriptor block\n");
  }
  offset += sizeof( struct journal_block_tag_s );
      }
      while ( !(((__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (__u32)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))) & 8)) &&
    offset < block_size );
    }
  printf("+------------------------------------------------------------------------------+\n");
  }
  return 0;
}

canonical_original_code:
int dump_journal_block(int fd, int block_size, unsigned int block_num) {
  int offset = 0;
  struct journal_block_tag_s jb_tag;
  struct journal_revoke_header_s j_rheader;
  long lret;
  long sret;
  read_journal_revoke_header( fd, block_size, block_num, 0, &j_rheader );
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)((j_rheader.r_header.h_magic)))) ? ((__u32)( (((__u32)((__u32)(__be32)((j_rheader.r_header.h_magic))) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)((j_rheader.r_header.h_magic))) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)((j_rheader.r_header.h_magic))) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)((j_rheader.r_header.h_magic))) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)((j_rheader.r_header.h_magic)))) == 0xc03b3998U ) {
    print_journal_revoke_header(&j_rheader);
    if ( (__builtin_constant_p((__u32)((__u32)(__be32)(j_rheader.r_header.h_blocktype))) ? ((__u32)( (((__u32)((__u32)(__be32)(j_rheader.r_header.h_blocktype)) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(j_rheader.r_header.h_blocktype)) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(j_rheader.r_header.h_blocktype)) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(j_rheader.r_header.h_blocktype)) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(j_rheader.r_header.h_blocktype))) ==
  1 ) {
      offset = sizeof( struct journal_header_s );
      do {
  lret = lseek( fd, (__u64)(block_num)*block_size + offset, 0 );
  if ( lret == -1 ) {
    perror("lseek dump journal block");
    return -1;
  }
  sret = read( fd, &jb_tag, sizeof(struct journal_block_tag_s ) );
  if ( sret == -1 ) {
    perror("read dump journal block");
    return -1;
  }
  printf("Concerned block number : %u\n", (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_blocknr))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_blocknr)) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_blocknr)) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_blocknr)) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_blocknr)) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_blocknr))));
  printf("flag: %u\n", (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))));
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))) & 1 ) {
    printf("JFS_FLAG_ESPACE: on-disk block is escaped\n");
  }
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))) & 2 ) {
    printf("JFS_FLAG_SAME_UUID: block has same uuid as previous\n");
  }
  else
    offset += 16;
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))) & 4) {
    printf("JFS_FLAG_DELETED: block deleted by this transaction\n");
        }
  if ( (__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))) & 8 ) {
    printf("JFS_FLAG_LAST_TAG: last tag in this descriptor block\n");
  }
  offset += sizeof( struct journal_block_tag_s );
      }
      while ( !(((__builtin_constant_p((__u32)((__u32)(__be32)(jb_tag.t_flags))) ? ((__u32)( (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x000000ffUL) << 24) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x0000ff00UL) << 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0x00ff0000UL) >> 8) | (((__u32)((__u32)(__be32)(jb_tag.t_flags)) & (unsigned int)0xff000000UL) >> 24))) : __fswab32((__u32)(__be32)(jb_tag.t_flags))) & 8)) &&
    offset < block_size );
    }
  printf("+------------------------------------------------------------------------------+\n");
  }
  return 0;
}

variable_types: struct journal_block_tag_s { unsigned int t_blocknr; unsigned int t_flags; }

variable_types: struct journal_revoke_header_s { struct journal_header_s { unsigned int h_magic; unsigned int h_blocktype; unsigned int h_sequence; } r_header; unsigned int r_count; }


decompiled_code:
__int64 __fastcall dump_journal_block_rec(unsigned int a1, int a2, unsigned int a3, int a4)
{
unsigned int v5; // ebx
unsigned int *v7; // r14
__int64 v8; // rbp
__int64 v9; // rdx
unsigned int v11; // [rsp+Ch] [rbp-3Ch]

if ( a4 )
{
v7 = (unsigned int *)malloc(a2);
if ( (unsigned int)read_block_pointer(a1, (unsigned int)a2, a3, v7) == -1 )
exit(1);
v8 = 0LL;
v11 = a4 - 1;
if ( a2 > 3 )
{
do
{
v9 = v7[v8];
if ( !(_DWORD)v9 )
break;
v5 = dump_journal_block_rec(a1, (unsigned int)a2, v9, v11);
if ( v5 == -1 )
return v5;
++v8;
}
while ( a2 / 4 > (int)v8 );
}
free(v7);
v5 = 0;
}
else
{
v5 = dump_journal_block(a1, a2, a3);
if ( v5 == -1 )
fwrite("!!error dumping the journal!!\n", 1uLL, 0x1EuLL, stderr);
else
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2, unsigned int a3, int a4)
{
unsigned int v5; // ebx
unsigned int *v7; // r14
__int64 v8; // rbp
__int64 v9; // rdx
unsigned int v11; // [rsp+Ch] [rbp-3Ch]

if ( a4 )
{
v7 = (unsigned int *)malloc(a2);
if ( (unsigned int)read_block_pointer(a1, (unsigned int)a2, a3, v7) == -1 )
exit(1);
v8 = 0LL;
v11 = a4 - 1;
if ( a2 > 3 )
{
do
{
v9 = v7[v8];
if ( !(_DWORD)v9 )
break;
v5 = func8(a1, (unsigned int)a2, v9, v11);
if ( v5 == -1 )
return v5;
++v8;
}
while ( a2 / 4 > (int)v8 );
}
free(v7);
v5 = 0;
}
else
{
v5 = func7(a1, a2, a3);
if ( v5 == -1 )
fwrite("!!error dumping the journal!!\n", 1uLL, 0x1EuLL, stderr);
else
v5 = 0;
}
return v5;
}

original_code:
int dump_journal_block_rec ( int fd, int block_size, __u32 block_num,
    int rec_level ) {
  __u32 *block;
  int i;
  int ret;
  if ( rec_level == 0 ) {
    ret = dump_journal_block( fd, block_size, block_num);
    if ( ret == -1 ) {
      fprintf( stderr, "!!error dumping the journal!!\n" );
      return -1;
    }
  }
  else {
    block = malloc( block_size );
    ret = read_block_pointer ( fd, block_size, block_num, block );
    if ( ret == -1 )
      exit(1);
    i = 0;
    while ( i < block_size/4 && block[i] != 0 ) {
      ret = dump_journal_block_rec( fd, block_size, block[i], rec_level-1 );
      if ( ret == -1 ) {
  return -1;
      }
      i++;
    }
    free( block );
  }
  return 0;
}

canonical_original_code:
int dump_journal_block_rec(int fd, int block_size, unsigned int block_num, int rec_level) {
  unsigned int *block;
  int i;
  int ret;
  if ( rec_level == 0 ) {
    ret = dump_journal_block( fd, block_size, block_num);
    if ( ret == -1 ) {
      fprintf( stderr, "!!error dumping the journal!!\n" );
      return -1;
    }
  }
  else {
    block = malloc( block_size );
    ret = read_block_pointer ( fd, block_size, block_num, block );
    if ( ret == -1 )
      exit(1);
    i = 0;
    while ( i < block_size/4 && block[i] != 0 ) {
      ret = dump_journal_block_rec( fd, block_size, block[i], rec_level-1 );
      if ( ret == -1 ) {
  return -1;
      }
      i++;
    }
    free( block );
  }
  return 0;
}

variable_types: fd int

variable_types:
block
unsigned int *

variable_types: i int


decompiled_code:
__int64 __fastcall dump_journal(unsigned int a1, int a2, _DWORD *a3)
{
unsigned int v4; // edx
__int64 v5; // rbx
bool v6; // cl
unsigned int v7; // edx
unsigned int v8; // edx
unsigned int v9; // edx

v4 = a3[10];
if ( v4 )
{
v5 = 1LL;
do
{
dump_journal_block_rec(a1, a2, v4, 0);
v4 = a3[v5 + 10];
v6 = (int)v5++ <= 11;
}
while ( v4 != 0 && v6 );
}
v7 = a3[22];
if ( v7 )
dump_journal_block_rec(a1, a2, v7, 1);
v8 = a3[23];
if ( v8 )
dump_journal_block_rec(a1, a2, v8, 2);
v9 = a3[24];
if ( v9 )
dump_journal_block_rec(a1, a2, v9, 3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2, _DWORD *a3)
{
unsigned int v4; // edx
__int64 v5; // rbx
bool v6; // cl
unsigned int v7; // edx
unsigned int v8; // edx
unsigned int v9; // edx

v4 = a3[10];
if ( v4 )
{
v5 = 1LL;
do
{
func8(a1, a2, v4, 0);
v4 = a3[v5 + 10];
v6 = (int)v5++ <= 11;
}
while ( v4 != 0 && v6 );
}
v7 = a3[22];
if ( v7 )
func8(a1, a2, v7, 1);
v8 = a3[23];
if ( v8 )
func8(a1, a2, v8, 2);
v9 = a3[24];
if ( v9 )
func8(a1, a2, v9, 3);
return 0LL;
}

original_code:
int dump_journal ( int fd, int block_size, struct ext3_inode *i ) {
  int cc = 0;
  while( i->i_block[cc] != 0 && cc < 12) {
    dump_journal_block_rec( fd, block_size, i->i_block[cc], 0 );
    cc++;
  }
  if ( i->i_block[12] != 0 )
    dump_journal_block_rec( fd, block_size, i->i_block[12], 1 );
  if ( i->i_block[(12 + 1)] != 0 )
    dump_journal_block_rec( fd, block_size, i->i_block[(12 + 1)], 2 );
  if ( i->i_block[((12 + 1) + 1)] != 0 )
    dump_journal_block_rec( fd, block_size, i->i_block[((12 + 1) + 1)], 3 );
  return 0;
}

canonical_original_code:
int dump_journal(int fd, int block_size, struct ext3_inode *i) {
  int cc = 0;
  while( i->i_block[cc] != 0 && cc < 12) {
    dump_journal_block_rec( fd, block_size, i->i_block[cc], 0 );
    cc++;
  }
  if ( i->i_block[12] != 0 )
    dump_journal_block_rec( fd, block_size, i->i_block[12], 1 );
  if ( i->i_block[(12 + 1)] != 0 )
    dump_journal_block_rec( fd, block_size, i->i_block[(12 + 1)], 2 );
  if ( i->i_block[((12 + 1) + 1)] != 0 )
    dump_journal_block_rec( fd, block_size, i->i_block[((12 + 1) + 1)], 3 );
  return 0;
}

variable_types: struct ext3_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; unsigned short i_extra_isize; unsigned short i_pad1; } *

variable_types: cc int


decompiled_code:
__int64 __fastcall is_pow_of(int a1, int a2)
{
float v2; // xmm0_4
__int64 result; // rax

v2 = (float)a1;
result = 1LL;
if ( a1 != a2 )
{
while ( v2 > 1.0 )
{
v2 = v2 / (float)a2;
if ( v2 != (float)(int)v2 )
return 0LL;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
float v2; // xmm0_4
__int64 result; // rax

v2 = (float)a1;
result = 1LL;
if ( a1 != a2 )
{
while ( v2 > 1.0 )
{
v2 = v2 / (float)a2;
if ( v2 != (float)(int)v2 )
return 0LL;
}
result = 1LL;
}
return result;
}

original_code:
int is_pow_of ( int num, int pow ) {
  float nb = (float)num;
  float nb2 = 0;
  if ( num == pow )
    return 1;
  else {
    while ( nb > 1.0f ) {
      nb = nb/pow;
      nb2 = (int)nb;
      if ( nb2 != nb )
  return 0;
    }
    return 1;
  }
}

canonical_original_code:
int is_pow_of(int num, int pow) {
  float nb = (float)num;
  float nb2 = 0;
  if ( num == pow )
    return 1;
  else {
    while ( nb > 1.0f ) {
      nb = nb/pow;
      nb2 = (int)nb;
      if ( nb2 != nb )
  return 0;
    }
    return 1;
  }
}

variable_types: num int

variable_types: pow int

variable_types: nb float


decompiled_code:
int __fastcall print_journal_superblock(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax

print_journal_header(a1);
v1 = _fswab32(a1[3]);
printf("Journal device blocksize:%u \n", v1);
v2 = _fswab32(a1[4]);
printf("Total blocks in journal size:%u \n", v2);
v3 = _fswab32(a1[5]);
printf("First block of log information:%u\n", v3);
v4 = _fswab32(a1[6]);
printf("First commit ID expected in the log:%u\n", v4);
v5 = _fswab32(a1[7]);
printf("Block number of the log start:%u \n", v5);
v6 = _fswab32(a1[8]);
printf("Error value (if any):%u\n", v6);
puts("The following fields are only valid in a version 2 superblock.");
v7 = _fswab32(a1[9]);
printf("Compatible features set:%#x\n", v7);
v8 = _fswab32(a1[10]);
printf("Incompatible features set:%#x\n", v8);
v9 = _fswab32(a1[11]);
printf("Read-only compatible feature set:%#x\n", v9);
print_UUID(a1 + 12);
v10 = _fswab32(a1[16]);
printf("Number of filesystem sharing log:%u\n", v10);
v11 = _fswab32(a1[17]);
printf("Block number of dynamic superblock copy:%u\n", v11);
v12 = _fswab32(a1[18]);
printf("Limit of journal blocks per transaction:%u\n", v12);
v13 = _fswab32(a1[19]);
printf("Limit of data blocks per transaction:%u\n", v13);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func11(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax

func5(a1);
v1 = func1(a1[3]);
printf("Journal device blocksize:%u \n", v1);
v2 = func1(a1[4]);
printf("Total blocks in journal size:%u \n", v2);
v3 = func1(a1[5]);
printf("First block of log information:%u\n", v3);
v4 = func1(a1[6]);
printf("First commit ID expected in the log:%u\n", v4);
v5 = func1(a1[7]);
printf("Block number of the log start:%u \n", v5);
v6 = func1(a1[8]);
printf("Error value (if any):%u\n", v6);
puts("The following fields are only valid in a version 2 superblock.");
v7 = func1(a1[9]);
printf("Compatible features set:%#x\n", v7);
v8 = func1(a1[10]);
printf("Incompatible features set:%#x\n", v8);
v9 = func1(a1[11]);
printf("Read-only compatible feature set:%#x\n", v9);
print_UUID(a1 + 12);
v10 = func1(a1[16]);
printf("Number of filesystem sharing log:%u\n", v10);
v11 = func1(a1[17]);
printf("Block number of dynamic superblock copy:%u\n", v11);
v12 = func1(a1[18]);
printf("Limit of journal blocks per transaction:%u\n", v12);
v13 = func1(a1[19]);
printf("Limit of data blocks per transaction:%u\n", v13);
return putchar(10);
}


decompiled_code:
__int64 __fastcall read_inodebitmap(int fd, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 v5; // rdx
unsigned int v6; // er13

v5 = *(unsigned int *)(a3 + 4);
*a4 = 0LL;
if ( (unsigned int)lseek64(fd, v5 * (1024 << *(_DWORD *)(a2 + 24)), 0) == -1 )
{
v6 = -1;
perror("ext3Viewer - lseek error: Inode Bitmap");
}
else
{
v6 = read(fd, a4, *(_DWORD *)(a2 + 40) >> 3);
if ( v6 == -1 )
perror("ext3Viewer - read error: Inode Bitmap");
else
v6 = 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 v5; // rdx
unsigned int v6; // er13

v5 = *(unsigned int *)(a3 + 4);
*a4 = 0LL;
if ( (unsigned int)lseek64(fd, v5 * (1024 << *(_DWORD *)(a2 + 24)), 0) == -1 )
{
v6 = -1;
perror("ext3Viewer - lseek error: Inode Bitmap");
}
else
{
v6 = read(fd, a4, *(_DWORD *)(a2 + 40) >> 3);
if ( v6 == -1 )
perror("ext3Viewer - read error: Inode Bitmap");
else
v6 = 0;
}
return v6;
}

original_code:
int read_inodebitmap( int fd, const struct ext3_super_block *sb,
    const struct ext3_group_desc *gd, char * inodebitmap) {
  __u64 block_num = gd->bg_inode_bitmap;
  int ret;
  bzero(inodebitmap, sizeof(inodebitmap));
  ret = lseek( fd, block_num * (1024 << (sb)->s_log_block_size), 0);
  if ( ret == -1 ) {
    perror("ext3Viewer - lseek error: Inode Bitmap");
    return -1;
  }
  ret = read( fd, inodebitmap, (((sb)->s_inodes_per_group)/8) );
  if ( ret == -1 ) {
    perror("ext3Viewer - read error: Inode Bitmap");
    return -1;
  }
  return 0;
}

canonical_original_code:
int read_inodebitmap(int fd, struct ext3_super_block *sb, struct ext3_group_desc *gd, char *inodebitmap) {
  unsigned long long block_num = gd->bg_inode_bitmap;
  int ret;
  bzero(inodebitmap, sizeof(inodebitmap));
  ret = lseek( fd, block_num * (1024 << (sb)->s_log_block_size), 0);
  if ( ret == -1 ) {
    perror("ext3Viewer - lseek error: Inode Bitmap");
    return -1;
  }
  ret = read( fd, inodebitmap, (((sb)->s_inodes_per_group)/8) );
  if ( ret == -1 ) {
    perror("ext3Viewer - read error: Inode Bitmap");
    return -1;
  }
  return 0;
}

variable_types: struct ext3_super_block { unsigned int s_inodes_count; unsigned int s_blocks_count; unsigned int s_r_blocks_count; unsigned int s_free_blocks_count; unsigned int s_free_inodes_count; unsigned int s_first_data_block; unsigned int s_log_block_size; unsigned int s_log_frag_size; unsigned int s_blocks_per_group; unsigned int s_frags_per_group; unsigned int s_inodes_per_group; unsigned int s_mtime; unsigned int s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_errors; unsigned short s_minor_rev_level; unsigned int s_lastcheck; unsigned int s_checkinterval; unsigned int s_creator_os; unsigned int s_rev_level; unsigned short s_def_resuid; unsigned short s_def_resgid; unsigned int s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned int s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_reserved_gdt_blocks; unsigned char s_journal_uuid[16]; unsigned int s_journal_inum; unsigned int s_journal_dev; unsigned int s_last_orphan; unsigned int s_hash_seed[4]; unsigned char s_def_hash_version; unsigned char s_reserved_char_pad; unsigned short s_reserved_word_pad; unsigned int s_default_mount_opts; unsigned int s_first_meta_bg; unsigned int s_mkfs_time; unsigned int s_jnl_blocks[17]; unsigned int s_blocks_count_hi; unsigned int s_r_blocks_count_hi; unsigned int s_free_blocks_count_hi; unsigned short s_min_extra_isize; unsigned short s_want_extra_isize; unsigned int s_flags; unsigned short s_raid_stride; unsigned short s_mmp_interval; unsigned long long s_mmp_block; unsigned int s_raid_stripe_width; unsigned char s_log_groups_per_flex; unsigned char s_reserved_char_pad2; unsigned short s_reserved_pad; unsigned int s_reserved[162]; } *

variable_types: struct ext3_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]; } *

variable_types:
inodebitmap
char *

variable_types: ret int


decompiled_code:
__int64 __fastcall read_datablockbitmap(int fd, _DWORD *a2, unsigned int *a3, int a4, _QWORD *a5)
{
__int64 v8; // rdi
int v9; // ebp
unsigned int v10; // er15

v8 = *a3;
v9 = a2[1] / a2[8];
*a5 = 0LL;
if ( (unsigned int)lseek64(fd, v8 * (1024 << a2[6]), 0) == -1 )
{
v10 = -1;
perror("ext3Viewer - lseek error: Data Block Bitmap");
return v10;
}
if ( v9 == a4 )
{
v10 = read(fd, a5, (unsigned int)(a2[1] - a2[8] * v9) >> 3);
if ( v10 != -1 )
return 0;
LABEL_9:
perror("ext3Viewer - read error: Data Block Bitmap");
return v10;
}
v10 = read(fd, a5, a2[8] >> 3);
if ( v10 == -1 )
goto LABEL_9;
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, _DWORD *a2, unsigned int *a3, int a4, _QWORD *a5)
{
__int64 v8; // rdi
int v9; // ebp
unsigned int v10; // er15

v8 = *a3;
v9 = a2[1] / a2[8];
*a5 = 0LL;
if ( (unsigned int)lseek64(fd, v8 * (1024 << a2[6]), 0) == -1 )
{
v10 = -1;
perror("ext3Viewer - lseek error: Data Block Bitmap");
return v10;
}
if ( v9 == a4 )
{
v10 = read(fd, a5, (unsigned int)(a2[1] - a2[8] * v9) >> 3);
if ( v10 != -1 )
return 0;
LABEL_9:
perror("ext3Viewer - read error: Data Block Bitmap");
return v10;
}
v10 = read(fd, a5, a2[8] >> 3);
if ( v10 == -1 )
goto LABEL_9;
return 0;
}

original_code:
int read_datablockbitmap( int fd, const struct ext3_super_block *sb,
    const struct ext3_group_desc *gd,
    const __u32 group_num, char *datablockbitmap)
{
  __u64 block_num = gd->bg_block_bitmap;
  int ret;
  int group_count = sb->s_blocks_count/((sb)->s_blocks_per_group);
  int otherblockscount;
  memset(datablockbitmap, 0, sizeof(datablockbitmap));
  ret = lseek( fd, block_num * (1024 << (sb)->s_log_block_size), 0);
  if ( ret == -1 ) {
    perror("ext3Viewer - lseek error: Data Block Bitmap");
    return -1;
  }
  if( group_num == group_count )
    {
      otherblockscount =(group_count * ((sb)->s_blocks_per_group));
      ret = read( fd, datablockbitmap,(sb->s_blocks_count
            - otherblockscount )/8 );
      if ( ret == -1 ) {
        perror("ext3Viewer - read error: Data Block Bitmap");
        return -1;
      }
    }
  else
  {
    ret = read( fd, datablockbitmap, (((sb)->s_blocks_per_group)/8) );
    if ( ret == -1 ) {
      perror("ext3Viewer - read error: Data Block Bitmap");
      return -1;
    }
  }
  return 0;
}

canonical_original_code:
int read_datablockbitmap(int fd, struct ext3_super_block *sb, struct ext3_group_desc *gd, unsigned int group_num, char *datablockbitmap)
{
  unsigned long long block_num = gd->bg_block_bitmap;
  int ret;
  int group_count = sb->s_blocks_count/((sb)->s_blocks_per_group);
  int otherblockscount;
  memset(datablockbitmap, 0, sizeof(datablockbitmap));
  ret = lseek( fd, block_num * (1024 << (sb)->s_log_block_size), 0);
  if ( ret == -1 ) {
    perror("ext3Viewer - lseek error: Data Block Bitmap");
    return -1;
  }
  if( group_num == group_count )
    {
      otherblockscount =(group_count * ((sb)->s_blocks_per_group));
      ret = read( fd, datablockbitmap,(sb->s_blocks_count
            - otherblockscount )/8 );
      if ( ret == -1 ) {
        perror("ext3Viewer - read error: Data Block Bitmap");
        return -1;
      }
    }
  else
  {
    ret = read( fd, datablockbitmap, (((sb)->s_blocks_per_group)/8) );
    if ( ret == -1 ) {
      perror("ext3Viewer - read error: Data Block Bitmap");
      return -1;
    }
  }
  return 0;
}

variable_types:
datablockbitmap
char *

variable_types: otherblockscount int

user_defined_types: struct ext3_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]; }


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

result = 1LL;
if ( (a1 & 1) != 0 )
{
result = 2LL;
if ( (a1 & 2) != 0 )
{
result = 3LL;
if ( (a1 & 4) != 0 )
{
result = 4LL;
if ( (a1 & 8) != 0 )
{
result = 5LL;
if ( (a1 & 0x10) != 0 )
{
result = 6LL;
if ( (a1 & 0x20) != 0 )
{
result = 7LL;
if ( (a1 & 0x40) != 0 )
result = 8 * (unsigned int)(a1 >= 0);
}
}
}
}
}
}
return result;
}

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

result = 1LL;
if ( (a1 & 1) != 0 )
{
result = 2LL;
if ( (a1 & 2) != 0 )
{
result = 3LL;
if ( (a1 & 4) != 0 )
{
result = 4LL;
if ( (a1 & 8) != 0 )
{
result = 5LL;
if ( (a1 & 0x10) != 0 )
{
result = 6LL;
if ( (a1 & 0x20) != 0 )
{
result = 7LL;
if ( (a1 & 0x40) != 0 )
result = 8 * (unsigned int)(a1 >= 0);
}
}
}
}
}
}
return result;
}

original_code:
int bitmap_test_free(char content )
{
  if(!(content&1)){return 1;}
  if(!((content&2)>>1)){return 2;}
  if(!((content&4)>>2)){return 3;}
  if(!((content&8)>>3)){return 4;}
  if(!((content&16)>>4)){return 5;}
  if(!((content&32)>>5)){return 6;}
  if(!((content&64)>>6)){return 7;}
  if(!((content&128)>>7)){return 8;}
  return 0;
}

canonical_original_code:
int bitmap_test_free(char content)
{
  if(!(content&1)){return 1;}
  if(!((content&2)>>1)){return 2;}
  if(!((content&4)>>2)){return 3;}
  if(!((content&8)>>3)){return 4;}
  if(!((content&16)>>4)){return 5;}
  if(!((content&32)>>5)){return 6;}
  if(!((content&64)>>6)){return 7;}
  if(!((content&128)>>7)){return 8;}
  return 0;
}

variable_types: content char


decompiled_code:
ssize_t __fastcall read_group_desc(int fd, __int64 a2, unsigned __int16 a3, void *a4)
{
ssize_t result; // rax

if ( lseek64(fd, 32LL * a3 + (unsigned int)((1024 << *(_DWORD *)(a2 + 24)) * (*(_DWORD *)(a2 + 20) + 1)), 0) <= 0 )
{
perror("ext3Viewer error - lseek error group_desc");
exit(1);
}
result = read(fd, a4, 0x20uLL);
if ( !result )
{
perror("ext3Viewer error - error reading group_desc");
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int fd, __int64 a2, unsigned __int16 a3, void *a4)
{
ssize_t result; // rax

if ( lseek64(fd, 32LL * a3 + (unsigned int)((1024 << *(_DWORD *)(a2 + 24)) * (*(_DWORD *)(a2 + 20) + 1)), 0) <= 0 )
{
perror("ext3Viewer error - lseek error group_desc");
exit(1);
}
result = read(fd, a4, 0x20uLL);
if ( !result )
{
perror("ext3Viewer error - error reading group_desc");
exit(1);
}
return result;
}

original_code:
void read_group_desc(int fd, const struct ext3_super_block *sb,
    __u16 group_num, struct ext3_group_desc *gd) {
  off_t lret;
  size_t sret;
  lret = lseek ( fd, (sb->s_first_data_block+1) * (1024 << (sb)->s_log_block_size) +
      sizeof(struct ext3_group_desc) * group_num, 0 );
  if ( lret <= 0) {
    perror("ext3Viewer error - lseek error group_desc");
    exit(1);
  }
  ;
  ;
  ;
  ;
  ;
  sret = read ( fd, gd, sizeof(struct ext3_group_desc) );
  if( sret <= 0 ) {
    perror("ext3Viewer error - error reading group_desc");
    exit(1);
  }
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
}

canonical_original_code:
void read_group_desc(int fd, struct ext3_super_block *sb, unsigned short group_num, struct ext3_group_desc *gd) {
  long lret;
  unsigned long sret;
  lret = lseek ( fd, (sb->s_first_data_block+1) * (1024 << (sb)->s_log_block_size) +
      sizeof(struct ext3_group_desc) * group_num, 0 );
  if ( lret <= 0) {
    perror("ext3Viewer error - lseek error group_desc");
    exit(1);
  }
  ;
  ;
  ;
  ;
  ;
  sret = read ( fd, gd, sizeof(struct ext3_group_desc) );
  if( sret <= 0 ) {
    perror("ext3Viewer error - error reading group_desc");
    exit(1);
  }
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
}

variable_types: lret long

variable_types:
sret
unsigned long


decompiled_code:
int __fastcall print_groupdesc(unsigned int *a1)
{
printf("Block bitmap block (number)= %u\n", *a1);
printf("Inode bitmap block number = %u\n", a1[1]);
printf("First Inode table block number = %u\n", a1[2]);
printf("Free blocks count (in this group) = %hd\n", *((unsigned __int16 *)a1 + 6));
printf("Free inodes count (in this group) = %hd\n", *((unsigned __int16 *)a1 + 7));
return printf("Directories count (in this group) = %hd\n", *((unsigned __int16 *)a1 + 8));
}

canonical_decompiled_code:
int __fastcall func4(unsigned int *a1)
{
printf("Block bitmap block (number)= %u\n", *a1);
printf("Inode bitmap block number = %u\n", a1[1]);
printf("First Inode table block number = %u\n", a1[2]);
printf("Free blocks count (in this group) = %hd\n", *((unsigned __int16 *)a1 + 6));
printf("Free inodes count (in this group) = %hd\n", *((unsigned __int16 *)a1 + 7));
return printf("Directories count (in this group) = %hd\n", *((unsigned __int16 *)a1 + 8));
}

original_code:
void print_groupdesc ( const struct ext3_group_desc *gd)
{
  printf("Block bitmap block (number)= %u\n", gd->bg_block_bitmap);
  printf("Inode bitmap block number =  %u\n", gd->bg_inode_bitmap);
  printf("First Inode table block number = %u\n", gd->bg_inode_table);
  printf("Free blocks count (in this group) = %hd\n", gd->bg_free_blocks_count);
  printf("Free inodes count (in this group) = %hd\n", gd->bg_free_inodes_count);
  printf("Directories count (in this group) = %hd\n", gd->bg_used_dirs_count);
}

canonical_original_code:
void print_groupdesc(struct ext3_group_desc *gd)
{
  printf("Block bitmap block (number)= %u\n", gd->bg_block_bitmap);
  printf("Inode bitmap block number =  %u\n", gd->bg_inode_bitmap);
  printf("First Inode table block number = %u\n", gd->bg_inode_table);
  printf("Free blocks count (in this group) = %hd\n", gd->bg_free_blocks_count);
  printf("Free inodes count (in this group) = %hd\n", gd->bg_free_inodes_count);
  printf("Directories count (in this group) = %hd\n", gd->bg_used_dirs_count);
}


decompiled_code:
int __fastcall print_inodeblocknumber(__int64 a1, int a2, unsigned __int16 a3)
{
return printf("0x%08x", *(_DWORD *)(a1 + 40) * (unsigned int)a3 + a2 + 1);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, int a2, unsigned __int16 a3)
{
return printf("0x%08x", *(_DWORD *)(a1 + 40) * (unsigned int)a3 + a2 + 1);
}

original_code:
void print_inodeblocknumber(const struct ext3_super_block *sb,
    __u32 inode_num_g, __u16 gb_num)
{
  __u32 i_num;
  i_num = inode_num_g+(((sb)->s_inodes_per_group)*gb_num);
  printf("0x%08x", i_num+1);
}

canonical_original_code:
void print_inodeblocknumber(struct ext3_super_block *sb, unsigned int inode_num_g, unsigned short gb_num)
{
  unsigned int i_num;
  i_num = inode_num_g+(((sb)->s_inodes_per_group)*gb_num);
  printf("0x%08x", i_num+1);
}


variable_types:
i
unsigned long long

variable_types: charcount int

variable_types:
imax
unsigned int


decompiled_code:
int __fastcall print_datablock_blocknumber(__int64 a1, int a2, unsigned __int16 a3)
{
return printf("0x%08x", *(_DWORD *)(a1 + 32) * (unsigned int)a3 + *(_DWORD *)(a1 + 20) + a2);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, int a2, unsigned __int16 a3)
{
return printf("0x%08x", *(_DWORD *)(a1 + 32) * (unsigned int)a3 + *(_DWORD *)(a1 + 20) + a2);
}

original_code:
void print_datablock_blocknumber(const struct ext3_super_block* sb,
    __u32 block_num_g, __u16 gb_num)
{
  __u32 b_num;
  b_num = block_num_g+(((sb)->s_blocks_per_group)*gb_num);
  printf("0x%08x", b_num+sb->s_first_data_block);
}

canonical_original_code:
void print_datablock_blocknumber(struct ext3_super_block *sb, unsigned int block_num_g, unsigned short gb_num)
{
  unsigned int b_num;
  b_num = block_num_g+(((sb)->s_blocks_per_group)*gb_num);
  printf("0x%08x", b_num+sb->s_first_data_block);
}


original_code:
void print_datablockbitmap(const struct ext3_super_block *sb,
    char *datablockbitmap, __u16 gb_num)
{
  unsigned long long int b = 0;
  int charcount = 0;
  __u32 bmax;
  int group_count = sb->s_blocks_count/((sb)->s_blocks_per_group);
  if(gb_num == group_count)
  {
    bmax = ((__u32)
        (sb->s_blocks_count - (group_count * ((sb)->s_blocks_per_group)))/8);
  }
  else
  {
    bmax = ((__u32)
        ((sb)->s_blocks_per_group)) / 8;
  }
  printf("Data blocks Bitmap: 0 means free Data Block, 1 means Data Block in use\n");
  printf("%s", "+------------------------------------------------------------------------------+\n");
  printf("|Databl. n.|    Bits values\n");
  printf("%s", "+------------------------------------------------------------------------------+\n");
  while ( b < bmax )
  {
    if(b%6 == 0)
    {
      if(b == 0) {
        printf("|");
      }
      else {
        printf("\n|");
      }
      print_datablock_blocknumber(sb, b*8, gb_num);
    }
    if( charcount%8 == 0)
    {
      printf("|");
    }
    print_t_bin(datablockbitmap[b]);
    b++;
    charcount = charcount+8;
  }
  printf("\n%s", "+------------------------------------------------------------------------------+\n");
}

canonical_original_code:
void print_datablockbitmap(struct ext3_super_block *sb, char *datablockbitmap, unsigned short gb_num)
{
  unsigned long long b = 0;
  int charcount = 0;
  unsigned int bmax;
  int group_count = sb->s_blocks_count/((sb)->s_blocks_per_group);
  if(gb_num == group_count)
  {
    bmax = ((__u32)
        (sb->s_blocks_count - (group_count * ((sb)->s_blocks_per_group)))/8);
  }
  else
  {
    bmax = ((__u32)
        ((sb)->s_blocks_per_group)) / 8;
  }
  printf("Data blocks Bitmap: 0 means free Data Block, 1 means Data Block in use\n");
  printf("%s", "+------------------------------------------------------------------------------+\n");
  printf("|Databl. n.|    Bits values\n");
  printf("%s", "+------------------------------------------------------------------------------+\n");
  while ( b < bmax )
  {
    if(b%6 == 0)
    {
      if(b == 0) {
        printf("|");
      }
      else {
        printf("\n|");
      }
      print_datablock_blocknumber(sb, b*8, gb_num);
    }
    if( charcount%8 == 0)
    {
      printf("|");
    }
    print_t_bin(datablockbitmap[b]);
    b++;
    charcount = charcount+8;
  }
  printf("\n%s", "+------------------------------------------------------------------------------+\n");
}

variable_types:
b
unsigned long long

variable_types:
bmax
unsigned int


decompiled_code:
int open_file()
{
int v0; // eax
int v1; // eax
int result; // eax

v0 = open_fs();
fd[0] = v0;
if ( v0 < 0 )
return open_error_dialog();
v1 = read_superblock_gui((unsigned int)v0, (unsigned int)((_DWORD)fd + 8));
if ( v1 == -1 )
{
superblock_error_dialog();
fd[1] = 0;
result = close(fd[0]);
}
else if ( v1 == 1 && (unsigned int)superblock_warning_dialog() == -1 )
{
fd[1] = 0;
result = close_fs((unsigned int)fd[0]);
}
else
{
fd[1] = 1;
init_tree();
result = explore_dir((unsigned int)fd[0], (unsigned int)((_DWORD)fd + 8), 2LL);
}
return result;
}

canonical_decompiled_code:
int func3()
{
int v0; // eax
int v1; // eax
int result; // eax

v0 = open_fs();
fd[0] = v0;
if ( v0 < 0 )
return func0();
v1 = read_superblock_gui((unsigned int)v0, (unsigned int)((_DWORD)fd + 8));
if ( v1 == -1 )
{
func1();
fd[1] = 0;
result = close(fd[0]);
}
else if ( v1 == 1 && (unsigned int)func2() == -1 )
{
fd[1] = 0;
result = close_fs((unsigned int)fd[0]);
}
else
{
fd[1] = 1;
init_tree();
result = explore_dir((unsigned int)fd[0], (unsigned int)((_DWORD)fd + 8), 2LL);
}
return result;
}

original_code:
void open_file( gchar *path )
{
  int ret;
  fs.fd = open_fs ( (char*)path );
  if ( fs.fd < 0 ) {
    open_error_dialog();
    return;
  }
  ret = read_superblock_gui( fs.fd, &fs.sb );
  if ( ret == -1 ) {
    superblock_error_dialog();
    fs.isopen = 0;
    close(fs.fd);
  }
  else if ( ret == 1 ) {
    ret = superblock_warning_dialog();
    if ( ret == -1 ) {
      fs.isopen = 0;
      close_fs( fs.fd );
    }
    else {
      fs.isopen = 1;
      init_tree();
      explore_dir ( fs.fd, &fs.sb, 2, tree.iter);
    }
  }
  else {
    fs.isopen = 1;
    init_tree();
    explore_dir ( fs.fd, &fs.sb, 2, tree.iter );
  }
}

canonical_original_code:
void open_file(char *path)
{
  int ret;
  fs.fd = open_fs ( (char *)path );
  if ( fs.fd < 0 ) {
    open_error_dialog();
    return;
  }
  ret = read_superblock_gui( fs.fd, &fs.sb );
  if ( ret == -1 ) {
    superblock_error_dialog();
    fs.isopen = 0;
    close(fs.fd);
  }
  else if ( ret == 1 ) {
    ret = superblock_warning_dialog();
    if ( ret == -1 ) {
      fs.isopen = 0;
      close_fs( fs.fd );
    }
    else {
      fs.isopen = 1;
      init_tree();
      explore_dir ( fs.fd, &fs.sb, 2, tree.iter);
    }
  }
  else {
    fs.isopen = 1;
    init_tree();
    explore_dir ( fs.fd, &fs.sb, 2, tree.iter );
  }
}

variable_types:
path
char *


decompiled_code:
int __fastcall hace_stack(struct __jmp_buf_tag *a1, void (*a2)(void), unsigned int a3, __int64 a4)
{
int result; // eax
unsigned int v5; // [rsp+Ch] [rbp-Ch] BYREF

v5 = a3;
if ( a4 - (__int64)&v5 < a3 )
return hace_stack(a1, a2, a3);
result = _setjmp(a1);
if ( result )
{
a2();
abort();
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(struct __jmp_buf_tag *a1, void (*a2)(void), unsigned int a3, __int64 a4)
{
int result; // eax
unsigned int v5; // [rsp+Ch] [rbp-Ch] BYREF

v5 = a3;
if ( a4 - (__int64)&v5 < a3 )
return func7(a1, a2, a3);
result = _setjmp(a1);
if ( result )
{
a2();
abort();
}
return result;
}

original_code:
static void hace_stack (jmp_buf buf, void (*pf)(), unsigned prof, char *dummy) {
 if((dummy - (char*) & prof) >= prof) {
  if(_setjmp (buf) != 0) {
   pf(); abort();
  }
 } else {
  hace_stack(buf,pf,prof,dummy);
 }
}

canonical_original_code:
static void hace_stack(struct __jmp_buf_tag buf[1], void (*pf)(), unsigned int prof, char *dummy) {
 if((dummy - (char *) & prof) >= prof) {
  if(_setjmp (buf) != 0) {
   pf(); abort();
  }
 } else {
  hace_stack(buf,pf,prof,dummy);
 }
}

variable_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } [1]

variable_types:
pf
void (*)()

variable_types:
prof
unsigned int

variable_types:
dummy
char *

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


stack

decompiled_code:
int __fastcall stack(struct __jmp_buf_tag *a1, void (*a2)(void))
{
int result; // eax
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

result = hace_stack(a1, a2, ctas_0 << 12, (__int64)v3);
--ctas_0;
return result;
}

canonical_decompiled_code:
int __fastcall func8(struct __jmp_buf_tag *a1, void (*a2)(void))
{
int result; // eax
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

result = func7(a1, a2, ctas_0 << 12, (__int64)v3);
--ctas_0;
return result;
}

original_code:
void stack (jmp_buf buf, void (*pf)()) {
 static int ctas = 10;
 char dummy;
 hace_stack(buf, pf, 4096 *ctas, &dummy);
 ctas--;
}

canonical_original_code:
void stack(struct __jmp_buf_tag buf[1], void (*pf)()) {
 static int ctas = 10;
 char dummy;
 hace_stack(buf, pf, 4096 *ctas, &dummy);
 ctas--;
}

variable_types: ctas int

variable_types: dummy char

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


decompiled_code:
void __noreturn ft1()
{
do
printf("d = %f", -1.0);
while ( _setjmp(t1) );
longjmp(t2, 1);
}

canonical_decompiled_code:
void __noreturn func9()
{
do
printf("d = %f", -1.0);
while ( _setjmp(t1) );
longjmp(t2, 1);
}

variable_types: d double


decompiled_code:
int ft2()
{
int result; // eax
int i; // [rsp+Ch] [rbp-Ch]

for ( i = 0; i <= 9999; ++i )
{
printf("i = %d", (unsigned int)i);
if ( !_setjmp(t2) )
longjmp(t1, 1);
}
result = _setjmp(t2);
if ( !result )
longjmp(taskmain, 1);
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax
int i; // [rsp+Ch] [rbp-Ch]

for ( i = 0; i <= 9999; ++i )
{
printf("i = %d", (unsigned int)i);
if ( !_setjmp(t2) )
longjmp(t1, 1);
}
result = _setjmp(t2);
if ( !result )
longjmp(taskmain, 1);
return result;
}

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
stack(t1, (void (*)(void))ft1);
stack(t2, (void (*)(void))ft2);
if ( !_setjmp(taskmain) )
longjmp(t1, 1);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(t1, (void (*)(void))ft1);
func8(t2, (void (*)(void))ft2);
if ( !_setjmp(taskmain) )
longjmp(t1, 1);
return 0;
}

original_code:
int main (int argc, char **argv) {
 stack(t1, ft1);
 stack(t2, ft2);
 (_setjmp (taskmain) == 0 ? (longjmp(t1,1), 0) : 0);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 stack(t1, ft1);
 stack(t2, ft2);
 (_setjmp (taskmain) == 0 ? (longjmp(t1,1), 0) : 0);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


randomInit

repo: lawlesmj/showdown-combo

decompiled_code:
void __fastcall randomInit(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp

if ( (_DWORD)numTypes )
{
v1 = 0LL;
do
{
v2 = *((_DWORD *)claim + v1) - *((_DWORD *)allocated + v1);
*(_DWORD *)(a1 + 4 * v1++) = v2 % rand();
}
while ( (unsigned int)numTypes > (unsigned int)v1 );
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp

if ( (_DWORD)numTypes )
{
v1 = 0LL;
do
{
v2 = *((_DWORD *)claim + v1) - *((_DWORD *)allocated + v1);
*(_DWORD *)(a1 + 4 * v1++) = v2 % rand();
}
while ( (unsigned int)numTypes > (unsigned int)v1 );
}
}

original_code:
void randomInit(unsigned int request[]){
        int i;
        for(i = 0; i < numTypes; i++){
                request[i] = (claim[i] - allocated[i] ) % ((unsigned int)rand());
        }
}

variable_types:
request
unsigned int []


randomRelease

decompiled_code:
void __fastcall randomRelease(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp

if ( (_DWORD)numTypes )
{
v1 = 0LL;
do
{
v2 = *((_DWORD *)allocated + v1);
*(_DWORD *)(a1 + 4 * v1++) = v2 % rand();
}
while ( (unsigned int)numTypes > (unsigned int)v1 );
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp

if ( (_DWORD)numTypes )
{
v1 = 0LL;
do
{
v2 = *((_DWORD *)allocated + v1);
*(_DWORD *)(a1 + 4 * v1++) = v2 % rand();
}
while ( (unsigned int)numTypes > (unsigned int)v1 );
}
}

original_code:
void randomRelease(unsigned int request[]){
        int i;
        for(i = 0; i < numTypes; i++){
                request[i] = (allocated[i] ) % ((unsigned int)rand());
        }
}


wait

decompiled_code:
int wait()
{
unsigned int v0; // eax

v0 = rand();
return usleep(0x2328 % v0 + 1000);
}

canonical_decompiled_code:
int func9()
{
unsigned int v0; // eax

v0 = rand();
return usleep(0x2328 % v0 + 1000);
}

original_code:
void wait(){
        unsigned int time = 1000 + 9000 % ((unsigned int)rand());
        usleep(time);
}

variable_types:
time
unsigned int


cleanUp

decompiled_code:
void __fastcall cleanUp(int a1, void *a2, void *a3)
{
switch ( a1 )
{
case -1:
case 4:
if ( msgctl(myqid, 0, 0LL) == -1 )
perror("msgctl");
goto LABEL_4;
case 0:
goto LABEL_7;
case 1:
goto LABEL_6;
case 2:
goto LABEL_5;
case 3:
LABEL_4:
free(a3);
LABEL_5:
free(a2);
LABEL_6:
free(allocated);
LABEL_7:
free(claim);
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func10(int a1, void *a2, void *a3)
{
switch ( a1 )
{
case -1:
case 4:
if ( msgctl(myqid, 0, 0LL) == -1 )
perror("msgctl");
goto LABEL_4;
case 0:
goto LABEL_7;
case 1:
goto LABEL_6;
case 2:
goto LABEL_5;
case 3:
LABEL_4:
free(a3);
LABEL_5:
free(a2);
LABEL_6:
free(allocated);
LABEL_7:
free(claim);
break;
default:
return;
}
}

original_code:
void cleanUp(int instance, msgbuf_t * msgBuf, msgbuf_t * rspBuf){
        switch(instance){
         case -1:
                case 4:
                        if(msgctl(myqid, 0, ((void *)0)) == -1)
                         perror("msgctl");
                case 3:
                        free(rspBuf);
  case 2:
                        free(msgBuf);
                case 1:
                        free(allocated);
                case 0:
                        free(claim);
                default:
                        break;
        }
}

canonical_original_code:
void cleanUp(int instance, struct msgbuf_t *msgBuf, struct msgbuf_t *rspBuf){
        switch(instance){
         case -1:
                case 4:
                        if(msgctl(myqid, 0, ((void *)0)) == -1)
                         perror("msgctl");
                case 3:
                        free(rspBuf);
  case 2:
                        free(msgBuf);
                case 1:
                        free(allocated);
                case 0:
                        free(claim);
                default:
                        break;
        }
}

variable_types: instance int

variable_types: struct msgbuf_t { long mtype; struct { unsigned int sender; unsigned int serialNum; unsigned int inReply; int retAddr; int resourceVector[1]; } request; } *

variable_types:
rspBuf
struct msgbuf_t *


decompiled_code:
int __fastcall display_msg(unsigned int *a1, int a2)
{
__int64 v3; // rsi
unsigned int *v4; // rbx

printf("\tClient id: %d\n", a1[2]);
v3 = a1[4];
if ( (_DWORD)v3 )
printf("\tSerial number: %u\n", v3);
else
printf("\tSerial number: %u\n", a1[3]);
printf("\tReturn address: queueID %u\n", a1[5]);
printf("\tMessage type: %d-", *a1);
switch ( *(_QWORD *)a1 )
{
case 1LL:
printf("Request");
break;
case 2LL:
printf("Release");
break;
case 3LL:
printf("Register");
break;
case 4LL:
printf("Request granted");
break;
case 5LL:
printf("Request denied: unsafe");
break;
case 6LL:
printf("Request denied: excessive");
break;
case 7LL:
printf("Release successful");
break;
case 8LL:
printf("Release failed");
break;
case 9LL:
printf("Registration accepted");
break;
case 0xALL:
printf("Registration denied");
break;
case 0xBLL:
printf("Release All");
break;
case 0xCLL:
printf("Request denied: Unavailable");
break;
default:
puts("UNKNOWN");
break;
}
putchar(10);
printf("\tresources: { ");
if ( a2 )
{
v4 = a1 + 6;
do
printf("%u, ", *v4++);
while ( v4 != &a1[a2 - 1 + 7] );
}
return puts("}");
}

canonical_decompiled_code:
int __fastcall func12(unsigned int *a1, int a2)
{
__int64 v3; // rsi
unsigned int *v4; // rbx

printf("\tClient id: %d\n", a1[2]);
v3 = a1[4];
if ( (_DWORD)v3 )
printf("\tSerial number: %u\n", v3);
else
printf("\tSerial number: %u\n", a1[3]);
printf("\tReturn address: queueID %u\n", a1[5]);
printf("\tMessage type: %d-", *a1);
switch ( *(_QWORD *)a1 )
{
case 1LL:
printf("Request");
break;
case 2LL:
printf("Release");
break;
case 3LL:
printf("Register");
break;
case 4LL:
printf("Request granted");
break;
case 5LL:
printf("Request denied: unsafe");
break;
case 6LL:
printf("Request denied: excessive");
break;
case 7LL:
printf("Release successful");
break;
case 8LL:
printf("Release failed");
break;
case 9LL:
printf("Registration accepted");
break;
case 0xALL:
printf("Registration denied");
break;
case 0xBLL:
printf("Release All");
break;
case 0xCLL:
printf("Request denied: Unavailable");
break;
default:
puts("UNKNOWN");
break;
}
putchar(10);
printf("\tresources: { ");
if ( a2 )
{
v4 = a1 + 6;
do
printf("%u, ", *v4++);
while ( v4 != &a1[a2 - 1 + 7] );
}
return puts("}");
}

original_code:
void display_msg(msgbuf_t * msgbuf, unsigned int numTypes) {
        int i;
        printf("\tClient id: %d\n", msgbuf->request.sender);
        if(msgbuf->request.inReply > 0)
         printf("\tSerial number: %u\n",msgbuf->request.inReply);
 else
  printf("\tSerial number: %u\n",msgbuf->request.serialNum);
        printf("\tReturn address: queueID %u\n", msgbuf->request.retAddr);
        printf("\tMessage type: %d-", (int) msgbuf->mtype);
        switch(msgbuf->mtype) {
                case 1:
                        printf("Request");
                        break;
                case 2:
                        printf("Release");
                        break;
                case 3:
                        printf("Register");
                        break;
                case 11:
                        printf("Release All");
                        break;
                case 4:
                        printf("Request granted");
                        break;
                case 5:
                        printf("Request denied: unsafe");
                        break;
                case 6:
                        printf("Request denied: excessive");
                        break;
                case 12:
                        printf("Request denied: Unavailable");
                        break;
                case 7:
                        printf("Release successful");
                        break;
                case 8:
                        printf("Release failed");
                        break;
                case 9:
                        printf("Registration accepted");
                        break;
                case 10:
                        printf("Registration denied");
                        break;
                default:
                        printf("UNKNOWN\n");
        }
        printf("\n");
        printf("\tresources: { ");
        for(i=0; i < numTypes; i++) {
                printf("%u, ", msgbuf->request.resourceVector[i]);
        }
        printf("}\n");
}

canonical_original_code:
void display_msg(struct msgbuf_t *msgbuf, unsigned int numTypes) {
        int i;
        printf("\tClient id: %d\n", msgbuf->request.sender);
        if(msgbuf->request.inReply > 0)
         printf("\tSerial number: %u\n",msgbuf->request.inReply);
 else
  printf("\tSerial number: %u\n",msgbuf->request.serialNum);
        printf("\tReturn address: queueID %u\n", msgbuf->request.retAddr);
        printf("\tMessage type: %d-", (int) msgbuf->mtype);
        switch(msgbuf->mtype) {
                case 1:
                        printf("Request");
                        break;
                case 2:
                        printf("Release");
                        break;
                case 3:
                        printf("Register");
                        break;
                case 11:
                        printf("Release All");
                        break;
                case 4:
                        printf("Request granted");
                        break;
                case 5:
                        printf("Request denied: unsafe");
                        break;
                case 6:
                        printf("Request denied: excessive");
                        break;
                case 12:
                        printf("Request denied: Unavailable");
                        break;
                case 7:
                        printf("Release successful");
                        break;
                case 8:
                        printf("Release failed");
                        break;
                case 9:
                        printf("Registration accepted");
                        break;
                case 10:
                        printf("Registration denied");
                        break;
                default:
                        printf("UNKNOWN\n");
        }
        printf("\n");
        printf("\tresources: { ");
        for(i=0; i < numTypes; i++) {
                printf("%u, ", msgbuf->request.resourceVector[i]);
        }
        printf("}\n");
}

variable_types:
numTypes
unsigned int

user_defined_types: struct msgbuf_t { long mtype; struct { unsigned int sender; unsigned int serialNum; unsigned int inReply; int retAddr; int resourceVector[1]; } request; }