decompiled_code:
__int64 __fastcall chaser_init(__int64 a1, __int64 a2, char a3)
{
__int64 result; // rax

*(_BYTE *)a1 = a3;
result = a1;
*(_QWORD *)(a1 + 8) = a2;
*(_WORD *)(a1 + 32) = 256;
*(_DWORD *)(a1 + 36) = 0;
return result;
}

original_code:
chaser_t
chaser_init (chaser_obj_t *dev, flasher_t *flashers,
             uint8_t flasher_num)
{
    dev->flasher_num = flasher_num;
    dev->flashers = flashers;
    dev->step = 0;
    dev->dir = 1;
    dev->mode = CHASER_MODE_NORMAL;
    return dev;
}

canonical_original_code:
struct chaser_private_t *chaser_init(struct chaser_private_t *dev, struct flasher_obj_t **flashers, unsigned char flasher_num)
{
    dev->flasher_num = flasher_num;
    dev->flashers = flashers;
    dev->step = 0;
    dev->dir = 1;
    dev->mode = CHASER_MODE_NORMAL;
    return dev;
}

variable_types:
dev
struct chaser_private_t *

variable_types:
flashers
struct flasher_obj_t **

return_type: struct chaser_private_t { unsigned char flasher_num; struct flasher_obj_t { char dummy[-1]; } **flashers; char *seq; struct font_t { unsigned char flags; unsigned char width; unsigned char height; unsigned char offset; unsigned char size; unsigned char data[]; } *font; unsigned char step; char dir; enum chaser_mode_t { CHASER_MODE_NORMAL=0, CHASER_MODE_CYCLE=1, CHASER_MODE_INVERT=2, CHASER_MODE_CYCLE_INVERT=3, CHASER_MODE_NUM=4 } mode; struct flasher_pattern_t { unsigned char mod_period; unsigned char mod_duty; unsigned char flasher_period; unsigned char flasher_duty; unsigned char flashes; unsigned char period; } *on_pattern; struct flasher_pattern_t *off_pattern; } *


repo: mph-/mmculib

decompiled_code:
__int64 __fastcall chaser_sequence_set(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = 256LL;
*(_QWORD *)(a1 + 16) = a2;
*(_WORD *)(a1 + 32) = 256;
return result;
}

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

result = 256LL;
*(_QWORD *)(a1 + 16) = a2;
*(_WORD *)(a1 + 32) = 256;
return result;
}

original_code:
void
chaser_sequence_set (chaser_t chaser, chaser_sequence_t seq)
{
    chaser_obj_t *dev = chaser;
    dev->seq = seq;
    dev->step = 0;
    dev->dir = 1;
}

canonical_original_code:
void chaser_sequence_set(struct chaser_private_t *chaser, char *seq)
{
    struct chaser_private_t *dev = chaser;
    dev->seq = seq;
    dev->step = 0;
    dev->dir = 1;
}

variable_types: struct chaser_private_t { unsigned char flasher_num; struct flasher_obj_t { char dummy[-1]; } **flashers; char *seq; struct font_t { unsigned char flags; unsigned char width; unsigned char height; unsigned char offset; unsigned char size; unsigned char data[]; } *font; unsigned char step; char dir; enum chaser_mode_t { CHASER_MODE_NORMAL=0, CHASER_MODE_CYCLE=1, CHASER_MODE_INVERT=2, CHASER_MODE_CYCLE_INVERT=3, CHASER_MODE_NUM=4 } mode; struct flasher_pattern_t { unsigned char mod_period; unsigned char mod_duty; unsigned char flasher_period; unsigned char flasher_duty; unsigned char flashes; unsigned char period; } *on_pattern; struct flasher_pattern_t *off_pattern; } *

variable_types:
seq
char *

return_type: void

user_defined_types: struct chaser_private_t { unsigned char flasher_num; struct flasher_obj_t **flashers; char *seq; struct font_t *font; unsigned char step; char dir; enum chaser_mode_t mode; struct flasher_pattern_t *on_pattern; struct flasher_pattern_t *off_pattern; }


decompiled_code:
__int64 __fastcall chaser_mode_set(__int64 a1, int a2)
{
__int64 result; // rax

result = 256LL;
*(_DWORD *)(a1 + 36) = a2;
*(_WORD *)(a1 + 32) = 256;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
__int64 result; // rax

result = 256LL;
*(_DWORD *)(a1 + 36) = a2;
*(_WORD *)(a1 + 32) = 256;
return result;
}

original_code:
void
chaser_mode_set (chaser_t chaser, chaser_mode_t mode)
{
    chaser_obj_t *dev = chaser;
    dev->mode = mode;
    dev->step = 0;
    dev->dir = 1;
}

canonical_original_code:
void chaser_mode_set(struct chaser_private_t *chaser, enum chaser_mode_t mode)
{
    struct chaser_private_t *dev = chaser;
    dev->mode = mode;
    dev->step = 0;
    dev->dir = 1;
}

variable_types: enum chaser_mode_t { CHASER_MODE_NORMAL=0, CHASER_MODE_CYCLE=1, CHASER_MODE_INVERT=2, CHASER_MODE_CYCLE_INVERT=3, CHASER_MODE_NUM=4 }

user_defined_types: struct font_t { unsigned char flags; unsigned char width; unsigned char height; unsigned char offset; unsigned char size; unsigned char data[]; }

user_defined_types: struct flasher_pattern_t { unsigned char mod_period; unsigned char mod_duty; unsigned char flasher_period; unsigned char flasher_duty; unsigned char flashes; unsigned char period; }

user_defined_types: struct flasher_obj_t { char dummy[-1]; }


original_code:
int8_t
chaser_update (chaser_t chaser)
{
    chaser_obj_t *dev = chaser;
    bool cycle;
    if (!dev->seq)
        return 0;
    cycle = dev->mode == CHASER_MODE_CYCLE
        || dev->mode == CHASER_MODE_CYCLE_INVERT;
    font_display (dev->seq[dev->step], dev->font,
                  chaser_pixel_set, dev);
    if (dev->dir > 0)
    {
        dev->step++;
        if (!dev->seq[dev->step])
        {
            if (! cycle)
            {
                dev->step = 0;
                return 1;
            }
            dev->dir = -1;
            dev->step -= 2;
        }
    }
    else
    {
        if (!dev->step)
        {
            dev->dir = 1;
            dev->step = 1;
            return 1;
        }
        else
        {
            dev->step--;
        }
    }
    return 0;
}

canonical_original_code:
char chaser_update(struct chaser_private_t *chaser)
{
    struct chaser_private_t *dev = chaser;
    unsigned char cycle;
    if (!dev->seq)
        return 0;
    cycle = dev->mode == CHASER_MODE_CYCLE
        || dev->mode == CHASER_MODE_CYCLE_INVERT;
    font_display (dev->seq[dev->step], dev->font,
                  chaser_pixel_set, dev);
    if (dev->dir > 0)
    {
        dev->step++;
        if (!dev->seq[dev->step])
        {
            if (! cycle)
            {
                dev->step = 0;
                return 1;
            }
            dev->dir = -1;
            dev->step -= 2;
        }
    }
    else
    {
        if (!dev->step)
        {
            dev->dir = 1;
            dev->step = 1;
            return 1;
        }
        else
        {
            dev->step--;
        }
    }
    return 0;
}

variable_types:
cycle
unsigned char

return_type: char

user_defined_types: enum chaser_mode_t { CHASER_MODE_NORMAL=0, CHASER_MODE_CYCLE=1, CHASER_MODE_INVERT=2, CHASER_MODE_CYCLE_INVERT=3, CHASER_MODE_NUM=4 }


decompiled_code:
__int64 __fastcall flasher_pattern_set(__int64 a1, __int64 a2)
{
__int64 result; // rax

*(_QWORD *)a1 = a2;
result = 1LL;
*(_DWORD *)(a1 + 8) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
__int64 result; // rax

*(_QWORD *)a1 = a2;
result = 1LL;
*(_DWORD *)(a1 + 8) = 0;
return result;
}

original_code:
int8_t
flasher_pattern_set (flasher_t flasher, flasher_pattern_t *pattern)
{
    flasher->pattern = pattern;
    flasher->mod_count = 0;
    flasher->flasher_count = 0;
    flasher->flashes_count = 0;
    flasher->flasher_prescale = 0;
    return 1;
}

canonical_original_code:
char flasher_pattern_set(struct flasher_private_t *flasher, struct flasher_pattern_t *pattern)
{
    flasher->pattern = pattern;
    flasher->mod_count = 0;
    flasher->flasher_count = 0;
    flasher->flashes_count = 0;
    flasher->flasher_prescale = 0;
    return 1;
}

variable_types: struct flasher_private_t { struct flasher_pattern_t { unsigned char mod_period; unsigned char mod_duty; unsigned char flasher_period; unsigned char flasher_duty; unsigned char flashes; unsigned char period; } *pattern; unsigned char mod_count; unsigned char flasher_count; unsigned char flashes_count; unsigned char flasher_prescale; } *

variable_types:
pattern
struct flasher_pattern_t *

user_defined_types: struct flasher_private_t { struct flasher_pattern_t *pattern; unsigned char mod_count; unsigned char flasher_count; unsigned char flashes_count; unsigned char flasher_prescale; }


decompiled_code:
__int64 __fastcall flasher_pattern_get(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
flasher_pattern_t *
flasher_pattern_get (flasher_t flasher)
{
    return flasher->pattern;
}

canonical_original_code:
struct flasher_pattern_t *flasher_pattern_get(struct flasher_private_t *flasher)
{
    return flasher->pattern;
}

variable_types: struct flasher_private_t { struct flasher_pattern_t *pattern; unsigned char mod_count; unsigned char flasher_count; unsigned char flashes_count; unsigned char flasher_prescale; } *

return_type: struct flasher_pattern_t { unsigned char mod_period; unsigned char mod_duty; unsigned char flasher_period; unsigned char flasher_duty; unsigned char flashes; unsigned char period; } *


decompiled_code:
__int64 __fastcall flasher_phase_set(__int64 a1, char a2)
{
*(_BYTE *)(a1 + 10) = a2;
*(_WORD *)(a1 + 8) = 0;
return 1LL;
}

original_code:
int8_t
flasher_phase_set (flasher_t flasher, uint8_t phase)
{
    flasher->mod_count = 0;
    flasher->flasher_count = 0;
    flasher->flashes_count = phase;
    return 1;
}

canonical_original_code:
char flasher_phase_set(struct flasher_private_t *flasher, unsigned char phase)
{
    flasher->mod_count = 0;
    flasher->flasher_count = 0;
    flasher->flashes_count = phase;
    return 1;
}

variable_types:
phase
unsigned char


original_code:
bool
flasher_update (flasher_t flasher)
{
    if (!flasher->pattern)
        return 0;
    flasher->mod_count++;
    if (flasher->mod_count >= flasher->pattern->mod_period)
    {
        flasher->mod_count = 0;
        flasher->flasher_prescale++;
        if (flasher->flasher_prescale >= 8)
        {
            flasher->flasher_prescale = 0;
            flasher->flasher_count++;
            if (flasher->flasher_count >= flasher->pattern->flasher_period)
            {
                flasher->flasher_count = 0;
                flasher->flashes_count++;
                if (!flasher->pattern->period)
                {
                    if (flasher->flashes_count >= flasher->pattern->flashes)
                    {
                        flasher->pattern = 0;
                        return 1;
                    }
                }
                else if (flasher->flashes_count >= flasher->pattern->period)
                {
                    flasher->flashes_count = 0;
                }
            }
        }
    }
    return flasher->mod_count < flasher->pattern->mod_duty
        && flasher->flasher_count < flasher->pattern->flasher_duty
        && flasher->flashes_count < flasher->pattern->flashes;
}

canonical_original_code:
unsigned char flasher_update(struct flasher_private_t *flasher)
{
    if (!flasher->pattern)
        return 0;
    flasher->mod_count++;
    if (flasher->mod_count >= flasher->pattern->mod_period)
    {
        flasher->mod_count = 0;
        flasher->flasher_prescale++;
        if (flasher->flasher_prescale >= 8)
        {
            flasher->flasher_prescale = 0;
            flasher->flasher_count++;
            if (flasher->flasher_count >= flasher->pattern->flasher_period)
            {
                flasher->flasher_count = 0;
                flasher->flashes_count++;
                if (!flasher->pattern->period)
                {
                    if (flasher->flashes_count >= flasher->pattern->flashes)
                    {
                        flasher->pattern = 0;
                        return 1;
                    }
                }
                else if (flasher->flashes_count >= flasher->pattern->period)
                {
                    flasher->flashes_count = 0;
                }
            }
        }
    }
    return flasher->mod_count < flasher->pattern->mod_duty
        && flasher->flasher_count < flasher->pattern->flasher_duty
        && flasher->flashes_count < flasher->pattern->flashes;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall flasher_init(__int64 a1)
{
flasher_pattern_set(a1, 0LL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
func14(a1, 0LL);
return a1;
}

original_code:
flasher_t
flasher_init (flasher_obj_t *flasher)
{
    flasher_pattern_set (flasher, 0);
    return flasher;
}

canonical_original_code:
struct flasher_private_t *flasher_init(struct flasher_private_t *flasher)
{
    flasher_pattern_set (flasher, 0);
    return flasher;
}

variable_types:
flasher
struct flasher_private_t *

return_type: struct flasher_private_t { struct flasher_pattern_t { unsigned char mod_period; unsigned char mod_duty; unsigned char flasher_period; unsigned char flasher_duty; unsigned char flashes; unsigned char period; } *pattern; unsigned char mod_count; unsigned char flasher_count; unsigned char flashes_count; unsigned char flasher_prescale; } *


original_code:
bool
font_display (char ch, font_t *font,
              font_callback_t display,
              void *data)
{
    int8_t index;
    font_data_t *char_data;
    uint8_t i;
    uint8_t j;
    uint8_t k;
    uint8_t bytes_per_char;
    uint8_t char_byte;
    uint8_t pixels_per_byte;
    index = ch - font->offset;
    if (index < 0 || index >= font->size)
        return 0;
    bytes_per_char = (font->width * font->height + 8 - 1) >> 3;
    pixels_per_byte = 8;
    char_data = &font->data[index * bytes_per_char];
    k = 0;
    char_byte = *char_data++;
    for (j = 0; j < font->height; j++)
    {
        for (i = 0; i < font->width; i++)
        {
            display (data, font, i, j, (char_byte & 1) != 0);
            char_byte >>= 1;
            k++;
            if (k >= pixels_per_byte)
            {
                k = 0;
                char_byte = *char_data++;
            }
        }
    }
    return 1;
}

canonical_original_code:
unsigned char font_display(char ch, struct font_t *font, void (*display)(void *data, struct font_t *font, unsigned char col, unsigned char row, unsigned char val), void *data)
{
    char index;
    unsigned char *char_data;
    unsigned char i;
    unsigned char j;
    unsigned char k;
    unsigned char bytes_per_char;
    unsigned char char_byte;
    unsigned char pixels_per_byte;
    index = ch - font->offset;
    if (index < 0 || index >= font->size)
        return 0;
    bytes_per_char = (font->width * font->height + 8 - 1) >> 3;
    pixels_per_byte = 8;
    char_data = &font->data[index * bytes_per_char];
    k = 0;
    char_byte = *char_data++;
    for (j = 0; j < font->height; j++)
    {
        for (i = 0; i < font->width; i++)
        {
            display (data, font, i, j, (char_byte & 1) != 0);
            char_byte >>= 1;
            k++;
            if (k >= pixels_per_byte)
            {
                k = 0;
                char_byte = *char_data++;
            }
        }
    }
    return 1;
}

variable_types: ch char

variable_types: struct font_t { unsigned char flags; unsigned char width; unsigned char height; unsigned char offset; unsigned char size; unsigned char data[]; } *

variable_types: void (*)(void *data, struct font_t *font, unsigned char col, unsigned char row, unsigned char val)

variable_types:
data
void *

variable_types: index char

variable_types:
i
unsigned char

variable_types:
j
unsigned char

variable_types:
k
unsigned char


decompiled_code:
// attributes: thunk
__int64 fat_debug_dir_dump()
{
return fat_de_dir_dump();
}

canonical_decompiled_code:
__int64 func0()
{
return fat_de_dir_dump();
}

original_code:
void
fat_debug_dir_dump (fat_t *fat, uint32_t dir_cluster)
{
    fat_de_dir_dump (fat, dir_cluster);
}

canonical_original_code:
void fat_debug_dir_dump(struct fat_struct *fat, unsigned int dir_cluster)
{
    fat_de_dir_dump (fat, dir_cluster);
}

variable_types: struct fat_struct { void *dev; unsigned short (*dev_read)(void *dev, unsigned int addr, void *buffer, unsigned short size); unsigned short (*dev_write)(void *dev, unsigned int addr, void *buffer, unsigned short size); enum fat_fs_type_t { FAT_UNKNOWN=0, FAT_FAT12=1, FAT_FAT16=2, FAT_FAT32=3 } type; unsigned int first_sector; unsigned int fsinfo_sector; unsigned int first_fat_sector; unsigned int first_data_sector; unsigned int num_fat_sectors; unsigned int first_dir_sector; unsigned int root_dir_cluster; unsigned int num_clusters; unsigned int free_clusters; unsigned int prev_free_cluster; unsigned short root_dir_sectors; unsigned short bytes_per_sector; unsigned short bytes_per_cluster; unsigned short sectors_per_cluster; struct fat_io_cache_struct { unsigned int sector; unsigned char buffer[512]; int dirty; } cache; int fsinfo_dirty; } *

user_defined_types: struct fat_struct { void *dev; unsigned short (*dev_read)(void *dev, unsigned int addr, void *buffer, unsigned short size); unsigned short (*dev_write)(void *dev, unsigned int addr, void *buffer, unsigned short size); enum fat_fs_type_t type; unsigned int first_sector; unsigned int fsinfo_sector; unsigned int first_fat_sector; unsigned int first_data_sector; unsigned int num_fat_sectors; unsigned int first_dir_sector; unsigned int root_dir_cluster; unsigned int num_clusters; unsigned int free_clusters; unsigned int prev_free_cluster; unsigned short root_dir_sectors; unsigned short bytes_per_sector; unsigned short bytes_per_cluster; unsigned short sectors_per_cluster; struct fat_io_cache_struct cache; int fsinfo_dirty; }


decompiled_code:
__int64 __fastcall fat_debug_rootdir_dump(__int64 a1)
{
return fat_debug_dir_dump(a1, *(unsigned int *)(a1 + 52));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return func0(a1, *(unsigned int *)(a1 + 52));
}

original_code:
void
fat_debug_rootdir_dump (fat_t *fat)
{
    fat_debug_dir_dump (fat, fat->root_dir_cluster);
}

canonical_original_code:
void fat_debug_rootdir_dump(struct fat_struct *fat)
{
    fat_debug_dir_dump (fat, fat->root_dir_cluster);
}

user_defined_types: enum fat_fs_type_t { FAT_UNKNOWN=0, FAT_FAT12=1, FAT_FAT16=2, FAT_FAT32=3 }

user_defined_types: struct fat_io_cache_struct { unsigned int sector; unsigned char buffer[512]; int dirty; }


decompiled_code:
int __fastcall fat_debug_partition(__int64 a1)
{
fprintf(stderr, "FAT:Clusters = %ld\n", *(unsigned int *)(a1 + 56));
fprintf(stderr, "FAT:Bytes/sector = %u\n", *(unsigned __int16 *)(a1 + 70));
fprintf(stderr, "FAT:Sectors/cluster = %u\n", *(unsigned __int16 *)(a1 + 74));
fprintf(stderr, "FAT:First sector = %u\n", *(unsigned int *)(a1 + 28));
fprintf(stderr, "FAT:FirstFATSector = %u\n", *(unsigned int *)(a1 + 36));
fprintf(stderr, "FAT:FirstDataSector = %u\n", *(unsigned int *)(a1 + 40));
fprintf(stderr, "FAT:FirstDirSector = %u\n", *(unsigned int *)(a1 + 48));
return fprintf(stderr, "FAT:RootDirCluster = %u\n", *(unsigned int *)(a1 + 52));
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
fprintf(stderr, "FAT:Clusters = %ld\n", *(unsigned int *)(a1 + 56));
fprintf(stderr, "FAT:Bytes/sector = %u\n", *(unsigned __int16 *)(a1 + 70));
fprintf(stderr, "FAT:Sectors/cluster = %u\n", *(unsigned __int16 *)(a1 + 74));
fprintf(stderr, "FAT:First sector = %u\n", *(unsigned int *)(a1 + 28));
fprintf(stderr, "FAT:FirstFATSector = %u\n", *(unsigned int *)(a1 + 36));
fprintf(stderr, "FAT:FirstDataSector = %u\n", *(unsigned int *)(a1 + 40));
fprintf(stderr, "FAT:FirstDirSector = %u\n", *(unsigned int *)(a1 + 48));
return fprintf(stderr, "FAT:RootDirCluster = %u\n", *(unsigned int *)(a1 + 52));
}

original_code:
void
fat_debug_partition (fat_t *fat)
{
    fprintf (stderr, "FAT:Clusters = %ld\n", fat->num_clusters);
    fprintf (stderr, "FAT:Bytes/sector = %u\n", (unsigned int)fat->bytes_per_sector);
    fprintf (stderr, "FAT:Sectors/cluster = %u\n", (unsigned int)fat->sectors_per_cluster);
    fprintf (stderr, "FAT:First sector = %u\n", (unsigned int)fat->first_sector);
    fprintf (stderr, "FAT:FirstFATSector = %u\n", (unsigned int)fat->first_fat_sector);
    fprintf (stderr, "FAT:FirstDataSector = %u\n", (unsigned int)fat->first_data_sector);
    fprintf (stderr, "FAT:FirstDirSector = %u\n", (unsigned int)fat->first_dir_sector);
    fprintf (stderr, "FAT:RootDirCluster = %u\n", (unsigned int)fat->root_dir_cluster);
}

canonical_original_code:
void fat_debug_partition(struct fat_struct *fat)
{
    fprintf (stderr, "FAT:Clusters = %ld\n", fat->num_clusters);
    fprintf (stderr, "FAT:Bytes/sector = %u\n", (unsigned int)fat->bytes_per_sector);
    fprintf (stderr, "FAT:Sectors/cluster = %u\n", (unsigned int)fat->sectors_per_cluster);
    fprintf (stderr, "FAT:First sector = %u\n", (unsigned int)fat->first_sector);
    fprintf (stderr, "FAT:FirstFATSector = %u\n", (unsigned int)fat->first_fat_sector);
    fprintf (stderr, "FAT:FirstDataSector = %u\n", (unsigned int)fat->first_data_sector);
    fprintf (stderr, "FAT:FirstDirSector = %u\n", (unsigned int)fat->first_dir_sector);
    fprintf (stderr, "FAT:RootDirCluster = %u\n", (unsigned int)fat->root_dir_cluster);
}


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

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

original_code:
static inline uint16_t le16_to_cpu (uint16_t val)
{
    return val;
}

canonical_original_code:
static inline unsigned short le16_to_cpu(unsigned short val)
{
    return val;
}

variable_types:
val
unsigned short

return_type: unsigned short


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

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

original_code:
static inline uint32_t le32_to_cpu (uint32_t val)
{
    return val;
}

canonical_original_code:
static inline unsigned int le32_to_cpu(unsigned int val)
{
    return val;
}

variable_types:
val
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall le16_get(unsigned __int16 *a1)
{
return le16_to_cpu(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 *a1)
{
return func0(*a1);
}

original_code:
static inline uint16_t le16_get (void *ptr)
{
    return le16_to_cpu (*(uint16_t *)ptr);
}

canonical_original_code:
static inline unsigned short le16_get(void *ptr)
{
    return le16_to_cpu (*(unsigned short *)ptr);
}

variable_types:
ptr
void *


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

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

original_code:
static inline uint32_t le32_get (void *ptr)
{
    return le32_to_cpu (*(uint32_t *)ptr);
}

canonical_original_code:
static inline unsigned int le32_get(void *ptr)
{
    return le32_to_cpu (*(unsigned int *)ptr);
}


decompiled_code:
__int64 __fastcall le16_set(__int64 a1, unsigned __int16 a2)
{
__int64 result; // rax
_WORD *v3; // rdx

result = le16_to_cpu(a2);
*v3 = result;
return result;
}

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

result = func0(a2);
*v3 = result;
return result;
}

original_code:
static inline void le16_set (void *ptr, uint16_t val)
{
    *(uint16_t *)ptr = cpu_to_le16 (val);
}

canonical_original_code:
static inline void le16_set(void *ptr, unsigned short val)
{
    *(unsigned short *)ptr = cpu_to_le16 (val);
}


decompiled_code:
__int64 __fastcall le32_set(__int64 a1, unsigned int a2)
{
__int64 result; // rax
_DWORD *v3; // rdx

result = le32_to_cpu(a2);
*v3 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 result; // rax
_DWORD *v3; // rdx

result = func1(a2);
*v3 = result;
return result;
}

original_code:
static inline void le32_set (void *ptr, uint32_t val)
{
    *(uint32_t *)ptr = cpu_to_le32 (val);
}

canonical_original_code:
static inline void le32_set(void *ptr, unsigned int val)
{
    *(unsigned int *)ptr = cpu_to_le32 (val);
}


decompiled_code:
__int64 __fastcall fat_cluster_entry_get(__int64 a1, int a2)
{
unsigned int v3; // ebx
unsigned int v4; // er13
int v5; // er12
unsigned int *v6; // rdi
unsigned int v7; // eax
unsigned int v8; // er12
bool v9; // cf
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) == 3 )
{
v3 = 4 * a2;
v4 = 268435448;
v5 = 0xFFFFFFF;
}
else
{
v3 = 2 * a2;
v4 = 65528;
v5 = 0xFFFF;
}
v6 = (unsigned int *)(v3 % *(unsigned __int16 *)(a1 + 70)
+ fat_io_cache_read(
a1,
*(_DWORD *)(a1 + 36) + v3 / *(unsigned __int16 *)(a1 + 70),
v3 % *(unsigned __int16 *)(a1 + 70)));
if ( *(_DWORD *)(a1 + 24) == 3 )
v7 = le32_get(v6);
else
v7 = (unsigned __int16)le16_get((unsigned __int16 *)v6);
v8 = v7 & v5;
v9 = v7 < v4;
result = 4294967288LL;
if ( v9 )
result = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
unsigned int v3; // ebx
unsigned int v4; // er13
int v5; // er12
unsigned int *v6; // rdi
unsigned int v7; // eax
unsigned int v8; // er12
bool v9; // cf
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) == 3 )
{
v3 = 4 * a2;
v4 = 268435448;
v5 = 0xFFFFFFF;
}
else
{
v3 = 2 * a2;
v4 = 65528;
v5 = 0xFFFF;
}
v6 = (unsigned int *)(v3 % *(unsigned __int16 *)(a1 + 70)
+ fat_io_cache_read(
a1,
*(_DWORD *)(a1 + 36) + v3 / *(unsigned __int16 *)(a1 + 70),
v3 % *(unsigned __int16 *)(a1 + 70)));
if ( *(_DWORD *)(a1 + 24) == 3 )
v7 = func3(v6);
else
v7 = (unsigned __int16)func2((unsigned __int16 *)v6);
v8 = v7 & v5;
v9 = v7 < v4;
result = 4294967288LL;
if ( v9 )
result = v8;
return result;
}

original_code:
static uint32_t
fat_cluster_entry_get (fat_t *fat, uint32_t cluster)
{
    uint32_t sector, offset, cluster_new, mask;
    uint8_t *buffer;
    if (fat->type == FAT_FAT32)
    {
        offset = cluster << 2;
        mask = 0x0fffffff;
    }
    else
    {
        offset = cluster << 1;
        mask = 0x0000ffff;
    }
    sector = fat->first_fat_sector + offset / fat->bytes_per_sector;
    buffer = fat_io_cache_read (fat, sector);
    offset = offset % fat->bytes_per_sector;
    if (fat->type == FAT_FAT32)
        cluster_new = le32_get (buffer + offset);
    else
        cluster_new = le16_get (buffer + offset);
    if (cluster_new >= (0xfffffff8u & mask))
        return 0xfffffff8u;
    return cluster_new & mask;
}

canonical_original_code:
static unsigned int fat_cluster_entry_get(struct fat_struct *fat, unsigned int cluster)
{
    unsigned int sector; unsigned int offset; unsigned int cluster_new; unsigned int mask;
    unsigned char *buffer;
    if (fat->type == FAT_FAT32)
    {
        offset = cluster << 2;
        mask = 0x0fffffff;
    }
    else
    {
        offset = cluster << 1;
        mask = 0x0000ffff;
    }
    sector = fat->first_fat_sector + offset / fat->bytes_per_sector;
    buffer = fat_io_cache_read (fat, sector);
    offset = offset % fat->bytes_per_sector;
    if (fat->type == FAT_FAT32)
        cluster_new = le32_get (buffer + offset);
    else
        cluster_new = le16_get (buffer + offset);
    if (cluster_new >= (0xfffffff8u & mask))
        return 0xfffffff8u;
    return cluster_new & mask;
}

variable_types:
cluster
unsigned int

variable_types:
sector
unsigned int

variable_types:
offset
unsigned int

variable_types:
mask
unsigned int

variable_types:
buffer
unsigned char *


decompiled_code:
__int64 __fastcall fat_cluster_entry_set(__int64 a1, int a2, unsigned int a3)
{
unsigned int v5; // ebx
__int64 v6; // r13
__int64 v7; // rdi
unsigned int v8; // edx

if ( *(_DWORD *)(a1 + 24) == 3 )
v5 = 4 * a2;
else
v5 = 2 * a2;
v6 = *(_DWORD *)(a1 + 36) + v5 / *(unsigned __int16 *)(a1 + 70);
v7 = fat_io_cache_read(a1, v6, v5 % *(unsigned __int16 *)(a1 + 70));
v8 = v5 % *(unsigned __int16 *)(a1 + 70);
if ( *(_DWORD *)(a1 + 24) == 3 )
le32_set(v8 + v7, a3);
else
le16_set(v8 + v7, a3);
return fat_io_cache_write(a1, (unsigned int)v6);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, unsigned int a3)
{
unsigned int v5; // ebx
__int64 v6; // r13
__int64 v7; // rdi
unsigned int v8; // edx

if ( *(_DWORD *)(a1 + 24) == 3 )
v5 = 4 * a2;
else
v5 = 2 * a2;
v6 = *(_DWORD *)(a1 + 36) + v5 / *(unsigned __int16 *)(a1 + 70);
v7 = fat_io_cache_read(a1, v6, v5 % *(unsigned __int16 *)(a1 + 70));
v8 = v5 % *(unsigned __int16 *)(a1 + 70);
if ( *(_DWORD *)(a1 + 24) == 3 )
func5(v8 + v7, a3);
else
func4(v8 + v7, a3);
return fat_io_cache_write(a1, (unsigned int)v6);
}

original_code:
static void
fat_cluster_entry_set (fat_t *fat, uint32_t cluster, uint32_t cluster_new)
{
    uint32_t sector, offset;
    uint8_t *buffer;
    if (fat->type == FAT_FAT32)
    {
        offset = cluster << 2;
    }
    else
    {
        offset = cluster << 1;
    }
    sector = fat->first_fat_sector + offset / fat->bytes_per_sector;
    buffer = fat_io_cache_read (fat, sector);
    offset = offset % fat->bytes_per_sector;
    if (fat->type == FAT_FAT32)
    {
        le32_set (buffer + offset, cluster_new);
    }
    else
    {
        le16_set (buffer + offset, cluster_new);
    }
    fat_io_cache_write (fat, sector);
}

canonical_original_code:
static void fat_cluster_entry_set(struct fat_struct *fat, unsigned int cluster, unsigned int cluster_new)
{
    unsigned int sector; unsigned int offset;
    unsigned char *buffer;
    if (fat->type == FAT_FAT32)
    {
        offset = cluster << 2;
    }
    else
    {
        offset = cluster << 1;
    }
    sector = fat->first_fat_sector + offset / fat->bytes_per_sector;
    buffer = fat_io_cache_read (fat, sector);
    offset = offset % fat->bytes_per_sector;
    if (fat->type == FAT_FAT32)
    {
        le32_set (buffer + offset, cluster_new);
    }
    else
    {
        le16_set (buffer + offset, cluster_new);
    }
    fat_io_cache_write (fat, sector);
}


decompiled_code:
_BOOL8 __fastcall fat_cluster_free_p(int a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1)
{
return a1 == 0;
}

original_code:
bool
fat_cluster_free_p (uint32_t cluster)
{
    return cluster == 0;
}

canonical_original_code:
int fat_cluster_free_p(unsigned int cluster)
{
    return cluster == 0;
}

return_type: int


decompiled_code:
_BOOL8 __fastcall fat_cluster_last_p(unsigned int a1)
{
return a1 > 0xFFFFFFF7;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(unsigned int a1)
{
return a1 > 0xFFFFFFF7;
}

original_code:
bool
fat_cluster_last_p (uint32_t cluster)
{
    return cluster >= 0xfffffff8u;
}

canonical_original_code:
int fat_cluster_last_p(unsigned int cluster)
{
    return cluster >= 0xfffffff8u;
}


decompiled_code:
__int64 __fastcall fat_cluster_to_sector(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 )
result = *(_DWORD *)(a1 + 40) + (unsigned int)*(unsigned __int16 *)(a1 + 74) * (a2 - 2);
else
result = *(unsigned int *)(a1 + 48);
return result;
}

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

if ( a2 )
result = *(_DWORD *)(a1 + 40) + (unsigned int)*(unsigned __int16 *)(a1 + 74) * (a2 - 2);
else
result = *(unsigned int *)(a1 + 48);
return result;
}

original_code:
uint32_t
fat_cluster_to_sector (fat_t *fat, uint32_t cluster)
{
    if (cluster == 0)
        return fat->first_dir_sector;
    return ((uint32_t) (cluster - 2) * fat->sectors_per_cluster)
        + fat->first_data_sector;
}

canonical_original_code:
unsigned int fat_cluster_to_sector(struct fat_struct *fat, unsigned int cluster)
{
    if (cluster == 0)
        return fat->first_dir_sector;
    return ((unsigned int) (cluster - 2) * fat->sectors_per_cluster)
        + fat->first_data_sector;
}


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

v2 = fat_cluster_entry_get(a1, a2);
if ( !fat_cluster_free_p(v2) )
return v3;
fprintf(stderr, "FAT:Entry %u free\n", a2);
return 0xFFFFFFFFLL;
}

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

v2 = func6(a1, a2);
if ( !func8(v2) )
return v3;
fprintf(stderr, "FAT:Entry %u free\n", a2);
return 0xFFFFFFFFLL;
}

original_code:
uint32_t
fat_cluster_next (fat_t *fat, uint32_t cluster)
{
    uint32_t cluster_new;
   cluster_new = fat_cluster_entry_get (fat, cluster);
   if (fat_cluster_free_p (cluster_new))
   {
       fprintf (stderr, "FAT:Entry %u free\n", (unsigned int) cluster);
       return 0xffffffffu;
   }
   return cluster_new;
}

canonical_original_code:
unsigned int fat_cluster_next(struct fat_struct *fat, unsigned int cluster)
{
    unsigned int cluster_new;
   cluster_new = fat_cluster_entry_get (fat, cluster);
   if (fat_cluster_free_p (cluster_new))
   {
       fprintf (stderr, "FAT:Entry %u free\n", (unsigned int) cluster);
       return 0xffffffffu;
   }
   return cluster_new;
}


decompiled_code:
__int64 __fastcall fat_cluster_chain_length(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12

v2 = 0;
if ( a2 )
{
do
{
++v2;
a2 = fat_cluster_next(a1, a2);
}
while ( !fat_cluster_last_p(a2) );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12

v2 = 0;
if ( a2 )
{
do
{
++v2;
a2 = func12(a1, a2);
}
while ( !func9(a2) );
}
return v2;
}

original_code:
uint16_t
fat_cluster_chain_length (fat_t *fat, uint32_t cluster)
{
    uint16_t length;
    if (!cluster)
        return 0;
    length = 0;
    while (1)
    {
        length++;
        cluster = fat_cluster_next (fat, cluster);
        if (fat_cluster_last_p (cluster))
            break;
    }
    return length;
}

canonical_original_code:
unsigned short fat_cluster_chain_length(struct fat_struct *fat, unsigned int cluster)
{
    unsigned short length;
    if (!cluster)
        return 0;
    length = 0;
    while (1)
    {
        length++;
        cluster = fat_cluster_next (fat, cluster);
        if (fat_cluster_last_p (cluster))
            break;
    }
    return length;
}

variable_types:
length
unsigned short


decompiled_code:
__int64 __fastcall fat_cluster_free_search(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // ebx
int v5; // eax

if ( a2 >= a3 )
return 0LL;
v4 = a2;
do
{
v5 = fat_cluster_entry_get(a1, v4);
if ( fat_cluster_free_p(v5) )
return v4;
++v4;
}
while ( a3 != v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // ebx
int v5; // eax

if ( a2 >= a3 )
return 0LL;
v4 = a2;
do
{
v5 = func6(a1, v4);
if ( func8(v5) )
return v4;
++v4;
}
while ( a3 != v4 );
return 0LL;
}

original_code:
uint32_t
fat_cluster_free_search (fat_t *fat, uint32_t start, uint32_t stop)
{
    uint32_t cluster;
    for (cluster = start; cluster < stop; cluster++)
    {
        if (fat_cluster_free_p (fat_cluster_entry_get (fat, cluster)))
            return cluster;
    }
    return 0;
}

canonical_original_code:
unsigned int fat_cluster_free_search(struct fat_struct *fat, unsigned int start, unsigned int stop)
{
    unsigned int cluster;
    for (cluster = start; cluster < stop; cluster++)
    {
        if (fat_cluster_free_p (fat_cluster_entry_get (fat, cluster)))
            return cluster;
    }
    return 0;
}

variable_types:
start
unsigned int

variable_types:
stop
unsigned int


decompiled_code:
__int64 __fastcall fat_cluster_free_find(__int64 a1)
{
unsigned int v1; // er13
unsigned int v2; // er12

v1 = fat_fsinfo_prev_free_cluster_get() + 1;
v2 = fat_cluster_free_search(a1, v1, *(_DWORD *)(a1 + 56));
if ( !v2 )
{
v2 = fat_cluster_free_search(a1, 2u, v1);
if ( !v2 )
return 0LL;
}
fat_fsinfo_free_clusters_update(a1, 0xFFFFFFFFLL);
fat_fsinfo_prev_free_cluster_set(a1, v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
unsigned int v1; // er13
unsigned int v2; // er12

v1 = fat_fsinfo_prev_free_cluster_get() + 1;
v2 = func14(a1, v1, *(_DWORD *)(a1 + 56));
if ( !v2 )
{
v2 = func14(a1, 2u, v1);
if ( !v2 )
return 0LL;
}
fat_fsinfo_free_clusters_update(a1, 0xFFFFFFFFLL);
fat_fsinfo_prev_free_cluster_set(a1, v2);
return v2;
}

original_code:
uint32_t
fat_cluster_free_find (fat_t *fat)
{
    uint32_t cluster;
    uint32_t cluster_start;
    cluster_start = fat_fsinfo_prev_free_cluster_get (fat) + 1;
    cluster = fat_cluster_free_search (fat, cluster_start,
                                       fat->num_clusters);
    if (!cluster)
        cluster = fat_cluster_free_search (fat, 2,
                                           cluster_start);
    if (!cluster)
        return 0;
    fat_fsinfo_free_clusters_update (fat, -1);
    fat_fsinfo_prev_free_cluster_set (fat, cluster);
    return cluster;
}

canonical_original_code:
unsigned int fat_cluster_free_find(struct fat_struct *fat)
{
    unsigned int cluster;
    unsigned int cluster_start;
    cluster_start = fat_fsinfo_prev_free_cluster_get (fat) + 1;
    cluster = fat_cluster_free_search (fat, cluster_start,
                                       fat->num_clusters);
    if (!cluster)
        cluster = fat_cluster_free_search (fat, 2,
                                           cluster_start);
    if (!cluster)
        return 0;
    fat_fsinfo_free_clusters_update (fat, -1);
    fat_fsinfo_prev_free_cluster_set (fat, cluster);
    return cluster;
}


decompiled_code:
__int64 __fastcall fat_cluster_allocate(__int64 a1, int a2)
{
int v2; // eax
unsigned int v3; // er12

v2 = fat_cluster_free_find(a1);
v3 = v2;
if ( !v2 )
return v3;
fat_cluster_entry_set(a1, v2, 0xFFFFFFFF);
if ( !a2 )
return v3;
fat_cluster_chain_append_isra_0(a1, a2, v3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int a2)
{
int v2; // eax
unsigned int v3; // er12

v2 = func15(a1);
v3 = v2;
if ( !v2 )
return v3;
func7(a1, v2, 0xFFFFFFFF);
if ( !a2 )
return v3;
func10(a1, a2, v3);
return v3;
}

original_code:
static uint32_t
fat_cluster_allocate (fat_t *fat, uint32_t cluster_start)
{
    uint32_t cluster;
    cluster = fat_cluster_free_find (fat);
    if (!cluster)
        return 0;
    fat_cluster_entry_set (fat, cluster, 0xffffffffu);
    if (cluster_start)
        fat_cluster_chain_append (fat, cluster_start, cluster);
    return cluster;
}

canonical_original_code:
static unsigned int fat_cluster_allocate(struct fat_struct *fat, unsigned int cluster_start)
{
    unsigned int cluster;
    cluster = fat_cluster_free_find (fat);
    if (!cluster)
        return 0;
    fat_cluster_entry_set (fat, cluster, 0xffffffffu);
    if (cluster_start)
        fat_cluster_chain_append (fat, cluster_start, cluster);
    return cluster;
}


decompiled_code:
__int64 __fastcall fat_cluster_chain_free(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
unsigned int v4; // ebx

v2 = 0;
while ( !fat_cluster_last_p(a2) )
{
++v2;
v4 = fat_cluster_next(a1, a2);
fat_cluster_entry_set(a1, a2, 0);
a2 = v4;
}
fat_fsinfo_free_clusters_update(a1, v2);
return fat_fsinfo_write(a1);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
unsigned int v4; // ebx

v2 = 0;
while ( !func9(a2) )
{
++v2;
v4 = func12(a1, a2);
func7(a1, a2, 0);
a2 = v4;
}
fat_fsinfo_free_clusters_update(a1, v2);
return fat_fsinfo_write(a1);
}

original_code:
void
fat_cluster_chain_free (fat_t *fat, uint32_t cluster_start)
{
    uint32_t cluster_last;
    uint32_t cluster;
    int count;
    count = 0;
    for (cluster = cluster_start; !fat_cluster_last_p (cluster);)
    {
        cluster_last = cluster;
        cluster = fat_cluster_next (fat, cluster);
        fat_cluster_entry_set (fat, cluster_last, 0x00000000);
        count++;
    }
    fat_fsinfo_free_clusters_update (fat, count);
    fat_fsinfo_write (fat);
}

canonical_original_code:
void fat_cluster_chain_free(struct fat_struct *fat, unsigned int cluster_start)
{
    unsigned int cluster_last;
    unsigned int cluster;
    int count;
    count = 0;
    for (cluster = cluster_start; !fat_cluster_last_p (cluster);)
    {
        cluster_last = cluster;
        cluster = fat_cluster_next (fat, cluster);
        fat_cluster_entry_set (fat, cluster_last, 0x00000000);
        count++;
    }
    fat_fsinfo_free_clusters_update (fat, count);
    fat_fsinfo_write (fat);
}

variable_types: count int


decompiled_code:
__int64 __fastcall fat_cluster_chain_extend(__int64 a1, unsigned int a2, int a3)
{
unsigned int v3; // ebp
int v5; // eax
unsigned int v6; // er13
int v7; // ebx
int v8; // esi
unsigned int v10; // er13

v3 = a2;
fat_fsinfo_read();
if ( a2 )
{
do
{
v10 = v3;
v3 = fat_cluster_next(a1, v3);
}
while ( !fat_cluster_last_p(v3) );
v3 = v10;
}
v5 = fat_cluster_allocate(a1, v3);
v6 = v5;
v7 = a3 - 1;
if ( v7 )
{
v8 = v5;
do
{
v8 = fat_cluster_allocate(a1, v8);
--v7;
}
while ( v7 );
}
fat_fsinfo_write(a1);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned int a2, int a3)
{
unsigned int v3; // ebp
int v5; // eax
unsigned int v6; // er13
int v7; // ebx
int v8; // esi
unsigned int v10; // er13

v3 = a2;
fat_fsinfo_read();
if ( a2 )
{
do
{
v10 = v3;
v3 = func12(a1, v3);
}
while ( !func9(v3) );
v3 = v10;
}
v5 = func16(a1, v3);
v6 = v5;
v7 = a3 - 1;
if ( v7 )
{
v8 = v5;
do
{
v8 = func16(a1, v8);
--v7;
}
while ( v7 );
}
fat_fsinfo_write(a1);
return v6;
}

original_code:
uint32_t
fat_cluster_chain_extend (fat_t *fat, uint32_t cluster_start,
                  uint32_t num_clusters)
{
    uint32_t first_cluster;
    fat_fsinfo_read (fat);
    if (cluster_start)
    {
        while (1)
        {
            uint32_t cluster;
            cluster = fat_cluster_next (fat, cluster_start);
            if (fat_cluster_last_p (cluster))
                break;
            cluster_start = cluster;
        }
    }
    first_cluster = fat_cluster_allocate (fat, cluster_start);
    cluster_start = first_cluster;
    while (--num_clusters)
    {
        cluster_start = fat_cluster_allocate (fat, cluster_start);
    }
    fat_fsinfo_write (fat);
    return first_cluster;
}

canonical_original_code:
unsigned int fat_cluster_chain_extend(struct fat_struct *fat, unsigned int cluster_start, unsigned int num_clusters)
{
    unsigned int first_cluster;
    fat_fsinfo_read (fat);
    if (cluster_start)
    {
        while (1)
        {
            unsigned int cluster;
            cluster = fat_cluster_next (fat, cluster_start);
            if (fat_cluster_last_p (cluster))
                break;
            cluster_start = cluster;
        }
    }
    first_cluster = fat_cluster_allocate (fat, cluster_start);
    cluster_start = first_cluster;
    while (--num_clusters)
    {
        cluster_start = fat_cluster_allocate (fat, cluster_start);
    }
    fat_fsinfo_write (fat);
    return first_cluster;
}


decompiled_code:
int __fastcall fat_cluster_stats_dump(__int64 a1)
{
int v2[6]; // [rsp+0h] [rbp-18h] BYREF

fat_cluster_stats(a1, v2);
fprintf(stderr, "Free %u\n", (unsigned int)v2[1]);
fprintf(stderr, "Alloc %u\n", (unsigned int)v2[2]);
return fprintf(stderr, "Total %u\n", (unsigned int)v2[0]);
}

canonical_decompiled_code:
int __fastcall func20(__int64 a1)
{
int v2[6]; // [rsp+0h] [rbp-18h] BYREF

func19(a1, v2);
fprintf(stderr, "Free %u\n", (unsigned int)v2[1]);
fprintf(stderr, "Alloc %u\n", (unsigned int)v2[2]);
return fprintf(stderr, "Total %u\n", (unsigned int)v2[0]);
}

original_code:
void
fat_cluster_stats_dump (fat_t *fat)
{
    fat_cluster_stats_t stats;
    fat_cluster_stats (fat, &stats);
    fprintf (stderr, "Free  %" "u" "\n", stats.free);
    fprintf (stderr, "Alloc %" "u" "\n", stats.alloc);
    fprintf (stderr, "Total %" "u" "\n", stats.total);
}

canonical_original_code:
void fat_cluster_stats_dump(struct fat_struct *fat)
{
    struct fat_cluster_stats_struct stats;
    fat_cluster_stats (fat, &stats);
    fprintf (stderr, "Free  %" "u" "\n", stats.free);
    fprintf (stderr, "Alloc %" "u" "\n", stats.alloc);
    fprintf (stderr, "Total %" "u" "\n", stats.total);
}

variable_types: struct fat_cluster_stats_struct { unsigned int total; unsigned int free; unsigned int alloc; unsigned int prev_free_cluster; }


decompiled_code:
int __fastcall fat_cluster_chain_dump(__int64 a1, unsigned int a2)
{
do
{
fprintf(stderr, "%lu ", a2);
if ( !a2 )
break;
a2 = fat_cluster_next(a1, a2);
}
while ( !fat_cluster_last_p(a2) );
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func21(__int64 a1, unsigned int a2)
{
do
{
fprintf(stderr, "%lu ", a2);
if ( !a2 )
break;
a2 = func12(a1, a2);
}
while ( !func9(a2) );
return fputc(10, stderr);
}

original_code:
void
fat_cluster_chain_dump (fat_t *fat, uint32_t cluster)
{
    while (1)
    {
        fprintf (stderr, "%lu ", cluster);
        if (!cluster)
            break;
        cluster = fat_cluster_next (fat, cluster);
        if (fat_cluster_last_p (cluster))
            break;
    }
    fprintf (stderr, "\n");
}

canonical_original_code:
void fat_cluster_chain_dump(struct fat_struct *fat, unsigned int cluster)
{
    while (1)
    {
        fprintf (stderr, "%lu ", cluster);
        if (!cluster)
            break;
        cluster = fat_cluster_next (fat, cluster);
        if (fat_cluster_last_p (cluster))
            break;
    }
    fprintf (stderr, "\n");
}


original_code:
static void
fat_io_cache_init (fat_t *fat)
{
    fat->cache.sector = -1;
    fat->cache.dirty = 0;
}

canonical_original_code:
static void fat_io_cache_init(struct fat_struct *fat)
{
    fat->cache.sector = -1;
    fat->cache.dirty = 0;
}


decompiled_code:
__int64 __fastcall fat_io_read(__int64 a1, int a2, unsigned __int16 a3, __int64 a4, unsigned __int16 a5)
{
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64, _QWORD))(a1 + 8))(
*(_QWORD *)a1,
a3 + a2 * (unsigned int)*(unsigned __int16 *)(a1 + 70),
a4,
a5);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, unsigned __int16 a3, __int64 a4, unsigned __int16 a5)
{
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64, _QWORD))(a1 + 8))(
*(_QWORD *)a1,
a3 + a2 * (unsigned int)*(unsigned __int16 *)(a1 + 70),
a4,
a5);
}

original_code:
uint16_t
fat_io_read (fat_t *fat, fat_sector_t sector,
             uint16_t offset, void *buffer, uint16_t size)
{
    return fat->dev_read (fat->dev,
                          sector * fat->bytes_per_sector + offset,
                          buffer, size);
}

canonical_original_code:
unsigned short fat_io_read(struct fat_struct *fat, unsigned int sector, unsigned short offset, void *buffer, unsigned short size)
{
    return fat->dev_read (fat->dev,
                          sector * fat->bytes_per_sector + offset,
                          buffer, size);
}

variable_types:
offset
unsigned short

variable_types:
buffer
void *

variable_types:
size
unsigned short


decompiled_code:
__int64 __fastcall fat_io_write(__int64 a1, int a2, unsigned __int16 a3, __int64 a4, unsigned __int16 a5)
{
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64, _QWORD))(a1 + 16))(
*(_QWORD *)a1,
a3 + a2 * (unsigned int)*(unsigned __int16 *)(a1 + 70),
a4,
a5);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, unsigned __int16 a3, __int64 a4, unsigned __int16 a5)
{
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64, _QWORD))(a1 + 16))(
*(_QWORD *)a1,
a3 + a2 * (unsigned int)*(unsigned __int16 *)(a1 + 70),
a4,
a5);
}

original_code:
uint16_t
fat_io_write (fat_t *fat, fat_sector_t sector,
               uint16_t offset, const void *buffer, uint16_t size)
{
    return fat->dev_write (fat->dev,
                           sector * fat->bytes_per_sector + offset,
                           buffer, size);
}

canonical_original_code:
unsigned short fat_io_write(struct fat_struct *fat, unsigned int sector, unsigned short offset, void *buffer, unsigned short size)
{
    return fat->dev_write (fat->dev,
                           sector * fat->bytes_per_sector + offset,
                           buffer, size);
}

variable_types: struct fat_struct { void *dev; unsigned short (*dev_read)(void *dev, unsigned int addr, void *buffer, unsigned short size); unsigned short (*dev_write)(void *dev, unsigned int addr, void *buffer, unsigned short size); enum fat_fs_type_t { FAT_UNKNOWN=0, FAT_FAT12=1, FAT_FAT16=2, FAT_FAT32=3 } type; unsigned int first_sector; unsigned int fsinfo_sector; unsigned int first_fat_sector; unsigned int first_data_sector; unsigned int num_fat_sectors; unsigned int first_dir_sector; unsigned int root_dir_cluster; unsigned int num_clusters; unsigned int free_clusters; unsigned int prev_free_cluster; unsigned short root_dir_sectors; unsigned short bytes_per_sector; unsigned short bytes_per_cluster; unsigned short sectors_per_cluster; struct fat_io_cache_struct { unsigned int sector; unsigned char buffer[512]; int dirty; } cache; int fsinfo_dirty; } *


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

result = *(unsigned int *)(a1 + 592);
if ( (_DWORD)result )
{
result = fat_io_write(a1, *(_DWORD *)(a1 + 76), 0, a1 + 80, *(_WORD *)(a1 + 70));
*(_DWORD *)(a1 + 592) = 0;
}
return result;
}

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

result = *(unsigned int *)(a1 + 592);
if ( (_DWORD)result )
{
result = func2(a1, *(_DWORD *)(a1 + 76), 0, a1 + 80, *(_WORD *)(a1 + 70));
*(_DWORD *)(a1 + 592) = 0;
}
return result;
}

original_code:
void
fat_io_cache_flush (fat_t *fat)
{
    if (fat->cache.dirty)
    {
        fat_io_write (fat, fat->cache.sector, 0, fat->cache.buffer,
                       fat->bytes_per_sector);
        fat->cache.dirty = 0;
    }
}

canonical_original_code:
void fat_io_cache_flush(struct fat_struct *fat)
{
    if (fat->cache.dirty)
    {
        fat_io_write (fat, fat->cache.sector, 0, fat->cache.buffer,
                       fat->bytes_per_sector);
        fat->cache.dirty = 0;
    }
}


decompiled_code:
__int64 __fastcall fat_io_cache_read(__int64 a1, unsigned int a2)
{
if ( *(_DWORD *)(a1 + 76) == a2 )
return a1 + 80;
fat_io_cache_flush(a1);
*(_DWORD *)(a1 + 76) = a2;
if ( (unsigned __int16)fat_io_read(a1, a2, 0, a1 + 80, *(_WORD *)(a1 + 70)) == *(_WORD *)(a1 + 70) )
return a1 + 80;
fprintf(stderr, "FAT:Cannot read sector = %ld\n", a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
if ( *(_DWORD *)(a1 + 76) == a2 )
return a1 + 80;
func3(a1);
*(_DWORD *)(a1 + 76) = a2;
if ( (unsigned __int16)func1(a1, a2, 0, a1 + 80, *(_WORD *)(a1 + 70)) == *(_WORD *)(a1 + 70) )
return a1 + 80;
fprintf(stderr, "FAT:Cannot read sector = %ld\n", a2);
return 0LL;
}

original_code:
uint8_t *
fat_io_cache_read (fat_t *fat, fat_sector_t sector)
{
    if (sector == fat->cache.sector)
        return fat->cache.buffer;
    fat_io_cache_flush (fat);
    fat->cache.sector = sector;
    if (fat_io_read (fat, fat->cache.sector, 0,
                     fat->cache.buffer, fat->bytes_per_sector)
        != fat->bytes_per_sector)
    {
        fprintf (stderr, "FAT:Cannot read sector = %ld\n", sector);
        return 0;
    }
    return fat->cache.buffer;
}

canonical_original_code:
unsigned char *fat_io_cache_read(struct fat_struct *fat, unsigned int sector)
{
    if (sector == fat->cache.sector)
        return fat->cache.buffer;
    fat_io_cache_flush (fat);
    fat->cache.sector = sector;
    if (fat_io_read (fat, fat->cache.sector, 0,
                     fat->cache.buffer, fat->bytes_per_sector)
        != fat->bytes_per_sector)
    {
        fprintf (stderr, "FAT:Cannot read sector = %ld\n", sector);
        return 0;
    }
    return fat->cache.buffer;
}

return_type: unsigned char *


decompiled_code:
__int64 __fastcall fat_io_cache_write(__int64 a1, int a2)
{
__int64 result; // rax

*(_DWORD *)(a1 + 76) = a2;
result = *(unsigned __int16 *)(a1 + 70);
*(_DWORD *)(a1 + 592) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 result; // rax

*(_DWORD *)(a1 + 76) = a2;
result = *(unsigned __int16 *)(a1 + 70);
*(_DWORD *)(a1 + 592) = 1;
return result;
}

original_code:
uint16_t
fat_io_cache_write (fat_t *fat, fat_sector_t sector)
{
    fat->cache.sector = sector;
    fat->cache.dirty = 1;
    return fat->bytes_per_sector;
}

canonical_original_code:
unsigned short fat_io_cache_write(struct fat_struct *fat, unsigned int sector)
{
    fat->cache.sector = sector;
    fat->cache.dirty = 1;
    return fat->bytes_per_sector;
}


original_code:
void
fat_io_init (fat_t *fat, void * dev, fat_dev_read_t dev_read, fat_dev_write_t dev_write)
{
    fat->dev = dev;
    fat->dev_read = dev_read;
    fat->dev_write = dev_write;
    fat_io_cache_init (fat);
}

canonical_original_code:
void fat_io_init(struct fat_struct *fat, void *dev, unsigned short (*dev_read)(void *dev, unsigned int addr, void *buffer, unsigned short size), unsigned short (*dev_write)(void *dev, unsigned int addr, void *buffer, unsigned short size))
{
    fat->dev = dev;
    fat->dev_read = dev_read;
    fat->dev_write = dev_write;
    fat_io_cache_init (fat);
}

variable_types:
dev
void *

variable_types: unsigned short (*)(void *dev, unsigned int addr, void *buffer, unsigned short size)


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

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

original_code:
static inline uint32_t le32_to_cpu (uint32_t val)
{
    return val;
}

canonical_original_code:
static inline unsigned int le32_to_cpu(unsigned int val)
{
    return val;
}

variable_types:
val
unsigned int


decompiled_code:
void __fastcall fat_fsinfo_free_clusters_set(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 60) = a2;
*(_DWORD *)(a1 + 596) = 1;
}

original_code:
void
fat_fsinfo_free_clusters_set (fat_t *fat, int count)
{
    fat->free_clusters = count;
    fat->fsinfo_dirty = 1;
}

canonical_original_code:
void fat_fsinfo_free_clusters_set(struct fat_struct *fat, int count)
{
    fat->free_clusters = count;
    fat->fsinfo_dirty = 1;
}


decompiled_code:
__int64 __fastcall fat_fsinfo_free_clusters_update(__int64 a1, int a2)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 60);
if ( (_DWORD)result != -1 )
{
*(_DWORD *)(a1 + 596) = 1;
*(_DWORD *)(a1 + 60) = result + a2;
}
return result;
}

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

result = *(unsigned int *)(a1 + 60);
if ( (_DWORD)result != -1 )
{
*(_DWORD *)(a1 + 596) = 1;
*(_DWORD *)(a1 + 60) = result + a2;
}
return result;
}

original_code:
void
fat_fsinfo_free_clusters_update (fat_t *fat, int count)
{
    if (fat->free_clusters == ~0u)
        return;
    fat->free_clusters += count;
    fat->fsinfo_dirty = 1;
}

canonical_original_code:
void fat_fsinfo_free_clusters_update(struct fat_struct *fat, int count)
{
    if (fat->free_clusters == ~0u)
        return;
    fat->free_clusters += count;
    fat->fsinfo_dirty = 1;
}


decompiled_code:
void __fastcall fat_fsinfo_prev_free_cluster_set(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 64) = a2;
*(_DWORD *)(a1 + 596) = 1;
}

original_code:
void
fat_fsinfo_prev_free_cluster_set (fat_t *fat, uint32_t cluster)
{
    fat->prev_free_cluster = cluster;
    fat->fsinfo_dirty = 1;
}

canonical_original_code:
void fat_fsinfo_prev_free_cluster_set(struct fat_struct *fat, unsigned int cluster)
{
    fat->prev_free_cluster = cluster;
    fat->fsinfo_dirty = 1;
}

variable_types:
cluster
unsigned int


decompiled_code:
__int64 __fastcall fat_fsinfo_prev_free_cluster_get(__int64 a1)
{
return *(unsigned int *)(a1 + 64);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 64);
}

original_code:
uint32_t
fat_fsinfo_prev_free_cluster_get (fat_t *fat)
{
    return fat->prev_free_cluster;
}

canonical_original_code:
unsigned int fat_fsinfo_prev_free_cluster_get(struct fat_struct *fat)
{
    return fat->prev_free_cluster;
}


decompiled_code:
__int64 __fastcall fat_fsinfo_free_clusters_get(__int64 a1)
{
return *(unsigned int *)(a1 + 60);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 60);
}

original_code:
uint32_t
fat_fsinfo_free_clusters_get (fat_t *fat)
{
    return fat->free_clusters;
}

canonical_original_code:
unsigned int fat_fsinfo_free_clusters_get(struct fat_struct *fat)
{
    return fat->free_clusters;
}


decompiled_code:
__int64 __fastcall fat_fsinfo_read(unsigned int *a1)
{
__int64 v2; // rax
unsigned int v3; // eax
__int64 v4; // rdx
unsigned int v5; // edi
unsigned int v6; // eax
unsigned int v7; // ecx

v2 = fat_io_cache_read(a1, a1[8]);
if ( !v2 )
return 0LL;
v3 = le32_to_cpu(*(_DWORD *)(v2 + 488));
v5 = *(_DWORD *)(v4 + 492);
if ( v3 > a1[14] )
v3 = -1;
a1[15] = v3;
v6 = le32_to_cpu(v5);
if ( v7 > v6 && v6 > 1 )
a1[16] = v6;
else
a1[16] = 2;
a1[149] = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1)
{
__int64 v2; // rax
unsigned int v3; // eax
__int64 v4; // rdx
unsigned int v5; // edi
unsigned int v6; // eax
unsigned int v7; // ecx

v2 = fat_io_cache_read(a1, a1[8]);
if ( !v2 )
return 0LL;
v3 = func0(*(_DWORD *)(v2 + 488));
v5 = *(_DWORD *)(v4 + 492);
if ( v3 > a1[14] )
v3 = -1;
a1[15] = v3;
v6 = func0(v5);
if ( v7 > v6 && v6 > 1 )
a1[16] = v6;
else
a1[16] = 2;
a1[149] = 0;
return 1LL;
}

original_code:
bool
fat_fsinfo_read (fat_t *fat)
{
    struct fsinfo *fsinfo;
    fsinfo = (void *)fat_io_cache_read (fat, fat->fsinfo_sector);
    if (!fsinfo)
        return 0;
    fat->free_clusters = le32_to_cpu (fsinfo->fsinfree);
    if (fat->free_clusters > fat->num_clusters)
        fat->free_clusters = ~0u;
    fat->prev_free_cluster = le32_to_cpu (fsinfo->fsinxtfree);
    if (fat->prev_free_cluster < 2
        || fat->prev_free_cluster >= fat->num_clusters)
        fat->prev_free_cluster = 2;
    fat->fsinfo_dirty = 0;
    return 1;
}

canonical_original_code:
int fat_fsinfo_read(struct fat_struct *fat)
{
    struct fsinfo *fsinfo;
    fsinfo = (void *)fat_io_cache_read (fat, fat->fsinfo_sector);
    if (!fsinfo)
        return 0;
    fat->free_clusters = le32_to_cpu (fsinfo->fsinfree);
    if (fat->free_clusters > fat->num_clusters)
        fat->free_clusters = ~0u;
    fat->prev_free_cluster = le32_to_cpu (fsinfo->fsinxtfree);
    if (fat->prev_free_cluster < 2
        || fat->prev_free_cluster >= fat->num_clusters)
        fat->prev_free_cluster = 2;
    fat->fsinfo_dirty = 0;
    return 1;
}

variable_types: struct fsinfo { unsigned int fsisig1; unsigned char fsifill1[480]; unsigned int fsisig2; unsigned int fsinfree; unsigned int fsinxtfree; unsigned char fsifill2[12]; unsigned char fsisig3[4]; unsigned char fsifill3[508]; unsigned char fsisig4[4]; } *


decompiled_code:
__int64 __fastcall fat_fsinfo_write(unsigned int *a1)
{
__int64 result; // rax
int v3; // eax
unsigned int v4; // edi
__int64 v5; // rdx
int v6; // eax
__int64 v7; // rsi
__int64 v8; // rdx

result = a1[149];
if ( (_DWORD)result )
{
fat_io_cache_read(a1, a1[8]);
v3 = le32_to_cpu(a1[15]);
v4 = a1[16];
*(_DWORD *)(v5 + 488) = v3;
v6 = le32_to_cpu(v4);
v7 = a1[8];
*(_DWORD *)(v8 + 492) = v6;
fat_io_cache_write(a1, v7);
result = fat_io_cache_flush(a1);
a1[149] = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
__int64 result; // rax
int v3; // eax
unsigned int v4; // edi
__int64 v5; // rdx
int v6; // eax
__int64 v7; // rsi
__int64 v8; // rdx

result = a1[149];
if ( (_DWORD)result )
{
fat_io_cache_read(a1, a1[8]);
v3 = func0(a1[15]);
v4 = a1[16];
*(_DWORD *)(v5 + 488) = v3;
v6 = func0(v4);
v7 = a1[8];
*(_DWORD *)(v8 + 492) = v6;
fat_io_cache_write(a1, v7);
result = fat_io_cache_flush(a1);
a1[149] = 0;
}
return result;
}

original_code:
void
fat_fsinfo_write (fat_t *fat)
{
    struct fsinfo *fsinfo;
    if (!fat->fsinfo_dirty)
        return;
    fsinfo = (void *)fat_io_cache_read (fat, fat->fsinfo_sector);
    fsinfo->fsinfree = cpu_to_le32 (fat->free_clusters);
    fsinfo->fsinxtfree = cpu_to_le32 (fat->prev_free_cluster);
    fat_io_cache_write (fat, fat->fsinfo_sector);
    fat_io_cache_flush (fat);
    fat->fsinfo_dirty = 0;
}

canonical_original_code:
void fat_fsinfo_write(struct fat_struct *fat)
{
    struct fsinfo *fsinfo;
    if (!fat->fsinfo_dirty)
        return;
    fsinfo = (void *)fat_io_cache_read (fat, fat->fsinfo_sector);
    fsinfo->fsinfree = cpu_to_le32 (fat->free_clusters);
    fsinfo->fsinxtfree = cpu_to_le32 (fat->prev_free_cluster);
    fat_io_cache_write (fat, fat->fsinfo_sector);
    fat_io_cache_flush (fat);
    fat->fsinfo_dirty = 0;
}

user_defined_types: struct fsinfo { unsigned int fsisig1; unsigned char fsifill1[480]; unsigned int fsisig2; unsigned int fsinfree; unsigned int fsinxtfree; unsigned char fsifill2[12]; unsigned char fsisig3[4]; unsigned char fsifill3[508]; unsigned char fsisig4[4]; }


decompiled_code:
__int64 __fastcall fat_fsinfo_fix(unsigned int *a1)
{
int v2[6]; // [rsp+0h] [rbp-18h] BYREF

fat_cluster_stats(a1, v2);
fat_fsinfo_prev_free_cluster_set((__int64)a1, v2[3]);
fat_fsinfo_free_clusters_set((__int64)a1, v2[1]);
return fat_fsinfo_write(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
int v2[6]; // [rsp+0h] [rbp-18h] BYREF

fat_cluster_stats(a1, v2);
func3((__int64)a1, v2[3]);
func1((__int64)a1, v2[1]);
return func7(a1);
}

original_code:
void
fat_fsinfo_fix (fat_t *fat)
{
    fat_cluster_stats_t stats;
    fat_cluster_stats (fat, &stats);
    fat_fsinfo_prev_free_cluster_set (fat, stats.prev_free_cluster);
    fat_fsinfo_free_clusters_set (fat, stats.free);
    fat_fsinfo_write (fat);
}

canonical_original_code:
void fat_fsinfo_fix(struct fat_struct *fat)
{
    struct fat_cluster_stats_struct stats;
    fat_cluster_stats (fat, &stats);
    fat_fsinfo_prev_free_cluster_set (fat, stats.prev_free_cluster);
    fat_fsinfo_free_clusters_set (fat, stats.free);
    fat_fsinfo_write (fat);
}

user_defined_types: struct fat_cluster_stats_struct { unsigned int total; unsigned int free; unsigned int alloc; unsigned int prev_free_cluster; }


decompiled_code:
__int64 __fastcall fat_partition_read(__int64 a1)
{
__int64 v1; // rdx
int v2; // eax
FILE *v3; // rcx
__int64 v4; // rdx
char v5; // al
__int64 result; // rax

*(_WORD *)(a1 + 70) = 512;
*(_DWORD *)(a1 + 24) = 0;
v1 = fat_io_cache_read(a1, 0LL);
if ( (*(_BYTE *)v1 & 0xFD) == 0xE9 )
{
*(_DWORD *)(a1 + 28) = 0;
fwrite("FAT:Found MBR\n", 1uLL, 0xEuLL, stderr);
}
else
{
v2 = le32_to_cpu(*(_DWORD *)(v1 + 454));
v3 = stderr;
*(_DWORD *)(a1 + 28) = v2;
v5 = *(_BYTE *)(v4 + 450);
if ( v5 == 6 )
{
fwrite("FAT:FAT16\n", 1uLL, 0xAuLL, v3);
*(_DWORD *)(a1 + 24) = 2;
}
else
{
if ( (unsigned __int8)(v5 - 11) > 1u )
{
fwrite("FAT:Unknown\n", 1uLL, 0xCuLL, v3);
return 0LL;
}
fwrite("FAT:FAT32\n", 1uLL, 0xAuLL, v3);
*(_DWORD *)(a1 + 24) = 3;
}
}
result = fat_boot_read(a1);
if ( (_DWORD)result )
result = (unsigned int)fat_fsinfo_read(a1) != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rdx
int v2; // eax
FILE *v3; // rcx
__int64 v4; // rdx
char v5; // al
__int64 result; // rax

*(_WORD *)(a1 + 70) = 512;
*(_DWORD *)(a1 + 24) = 0;
v1 = fat_io_cache_read(a1, 0LL);
if ( (*(_BYTE *)v1 & 0xFD) == 0xE9 )
{
*(_DWORD *)(a1 + 28) = 0;
fwrite("FAT:Found MBR\n", 1uLL, 0xEuLL, stderr);
}
else
{
v2 = func0(*(_DWORD *)(v1 + 454));
v3 = stderr;
*(_DWORD *)(a1 + 28) = v2;
v5 = *(_BYTE *)(v4 + 450);
if ( v5 == 6 )
{
fwrite("FAT:FAT16\n", 1uLL, 0xAuLL, v3);
*(_DWORD *)(a1 + 24) = 2;
}
else
{
if ( (unsigned __int8)(v5 - 11) > 1u )
{
fwrite("FAT:Unknown\n", 1uLL, 0xCuLL, v3);
return 0LL;
}
fwrite("FAT:FAT32\n", 1uLL, 0xAuLL, v3);
*(_DWORD *)(a1 + 24) = 3;
}
}
result = fat_boot_read(a1);
if ( (_DWORD)result )
result = (unsigned int)fat_fsinfo_read(a1) != 0;
return result;
}

original_code:
bool
fat_partition_read (fat_t *fat)
{
    uint8_t *buffer;
    struct partrecord *pr;
    struct partsector *ps;
    fat->bytes_per_sector = 512;
    fat->type = FAT_UNKNOWN;
    buffer = fat_io_cache_read (fat, 0);
    if (*buffer == 0xE9 || *buffer == 0xEB)
    {
        fat->first_sector = 0;
        fprintf (stderr, "FAT:Found MBR\n");
    }
    else
    {
        ps = (struct partsector *) buffer;
        pr = (struct partrecord *) ps->psPart;
        fat->first_sector = le32_to_cpu (pr->prStartLBA);
        switch (pr->prPartType)
        {
        case 0x06:
            fprintf (stderr, "FAT:FAT16\n");
            fat->type = FAT_FAT16;
            break;
        case 0x0B:
        case 0x0C:
            fprintf (stderr, "FAT:FAT32\n");
            fat->type = FAT_FAT32;
            break;
        default:
            fprintf (stderr, "FAT:Unknown\n");
            return 0;
        }
    }
    if (!fat_boot_read (fat))
        return 0;
    if (!fat_fsinfo_read (fat))
        return 0;
    return 1;
}

canonical_original_code:
int fat_partition_read(struct fat_struct *fat)
{
    unsigned char *buffer;
    struct partrecord *pr;
    struct partsector *ps;
    fat->bytes_per_sector = 512;
    fat->type = FAT_UNKNOWN;
    buffer = fat_io_cache_read (fat, 0);
    if (*buffer == 0xE9 || *buffer == 0xEB)
    {
        fat->first_sector = 0;
        fprintf (stderr, "FAT:Found MBR\n");
    }
    else
    {
        ps = (struct partsector *) buffer;
        pr = (struct partrecord *) ps->psPart;
        fat->first_sector = le32_to_cpu (pr->prStartLBA);
        switch (pr->prPartType)
        {
        case 0x06:
            fprintf (stderr, "FAT:FAT16\n");
            fat->type = FAT_FAT16;
            break;
        case 0x0B:
        case 0x0C:
            fprintf (stderr, "FAT:FAT32\n");
            fat->type = FAT_FAT32;
            break;
        default:
            fprintf (stderr, "FAT:Unknown\n");
            return 0;
        }
    }
    if (!fat_boot_read (fat))
        return 0;
    if (!fat_fsinfo_read (fat))
        return 0;
    return 1;
}

variable_types: struct partrecord { unsigned char prIsActive; unsigned char prStartHead; unsigned short prStartCylSect; unsigned char prPartType; unsigned char prEndHead; unsigned short prEndCylSect; unsigned int prStartLBA; unsigned int prSize; } *

variable_types: struct partsector { unsigned char psBoot[446]; struct partrecord { unsigned char prIsActive; unsigned char prStartHead; unsigned short prStartCylSect; unsigned char prPartType; unsigned char prEndHead; unsigned short prEndCylSect; unsigned int prStartLBA; unsigned int prSize; } psPart[4]; unsigned char psBootSectSig0; unsigned char psBootSectSig1; } *

user_defined_types: struct partsector { unsigned char psBoot[446]; struct partrecord psPart[4]; unsigned char psBootSectSig0; unsigned char psBootSectSig1; }


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

original_code:
static inline uint16_t le16_to_cpu (uint16_t val)
{
    return val;
}

canonical_original_code:
static inline unsigned short le16_to_cpu(unsigned short val)
{
    return val;
}

variable_types:
val
unsigned short


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


original_code:
bool
fat_boot_read (fat_t *fat)
{
    uint8_t *buffer;
    struct bootsector710 *pb;
    struct bpb710 *bpb;
    struct extboot *bsext;
    uint32_t tot_sectors;
    uint32_t data_sectors;
    char label[12];
    int i;
    buffer = fat_io_cache_read (fat, fat->first_sector);
    if (!buffer)
        return 0;
    pb = (struct bootsector710 *) buffer;
    bpb = &pb->bsBPB;
    bsext = &pb->bsExt;
    for (i = 0; i < 11; i++)
        label[i] = bsext->exVolumeLabel[i];
    label[i] = 0;
    fprintf (stderr, "FAT:%s\n", label);
    if (fat->type == FAT_UNKNOWN)
    {
        if (strncmp (bsext->exFileSysType, "FAT32", 5) == 0)
            fat->type = FAT_FAT32;
        else if (strncmp (bsext->exFileSysType, "FAT16", 5) == 0)
            fat->type = FAT_FAT16;
    }
    fat->bytes_per_sector = le16_to_cpu (bpb->bpbBytesPerSec);
    fat->fsinfo_sector = le16_to_cpu (bpb->bpbFSInfo);
    if (!fat->fsinfo_sector)
        fat->fsinfo_sector = 1;
    fat->fsinfo_sector += fat->first_sector;
    fat->num_fat_sectors = le16_to_cpu (bpb->bpbFATsecs);
    if (!fat->num_fat_sectors)
        fat->num_fat_sectors = le32_to_cpu (bpb->bpbBigFATsecs);
    fat->root_dir_sectors
        = ((le16_to_cpu (bpb->bpbRootDirEnts) * 32)
           + (fat->bytes_per_sector - 1)) / fat->bytes_per_sector;
    fat->first_data_sector = bpb->bpbResSectors + bpb->bpbFATs
        * fat->num_fat_sectors + fat->root_dir_sectors;
    tot_sectors = le16_to_cpu (bpb->bpbSectors);
    if (!tot_sectors)
        tot_sectors = le32_to_cpu (bpb->bpbHugeSectors);
    data_sectors = tot_sectors - fat->first_data_sector;
    fat->num_clusters = data_sectors / bpb->bpbSecPerClust;
    fat->first_data_sector += fat->first_sector;
    fat->sectors_per_cluster = bpb->bpbSecPerClust;
    fat->first_fat_sector = bpb->bpbResSectors + fat->first_sector;
    fat->first_dir_sector = bpb->bpbResSectors
        + bpb->bpbFATs * fat->num_fat_sectors + fat->first_sector;
    if (fat->type == FAT_FAT32)
        fat->root_dir_cluster = le32_to_cpu (bpb->bpbRootClust);
    else
        fat->root_dir_cluster = 0;
    fat->bytes_per_cluster
        = fat->sectors_per_cluster * fat->bytes_per_sector;
    return 1;
}

canonical_original_code:
int fat_boot_read(struct fat_struct *fat)
{
    unsigned char *buffer;
    struct bootsector710 *pb;
    struct bpb710 *bpb;
    struct extboot *bsext;
    unsigned int tot_sectors;
    unsigned int data_sectors;
    char label[12];
    int i;
    buffer = fat_io_cache_read (fat, fat->first_sector);
    if (!buffer)
        return 0;
    pb = (struct bootsector710 *) buffer;
    bpb = &pb->bsBPB;
    bsext = &pb->bsExt;
    for (i = 0; i < 11; i++)
        label[i] = bsext->exVolumeLabel[i];
    label[i] = 0;
    fprintf (stderr, "FAT:%s\n", label);
    if (fat->type == FAT_UNKNOWN)
    {
        if (strncmp (bsext->exFileSysType, "FAT32", 5) == 0)
            fat->type = FAT_FAT32;
        else if (strncmp (bsext->exFileSysType, "FAT16", 5) == 0)
            fat->type = FAT_FAT16;
    }
    fat->bytes_per_sector = le16_to_cpu (bpb->bpbBytesPerSec);
    fat->fsinfo_sector = le16_to_cpu (bpb->bpbFSInfo);
    if (!fat->fsinfo_sector)
        fat->fsinfo_sector = 1;
    fat->fsinfo_sector += fat->first_sector;
    fat->num_fat_sectors = le16_to_cpu (bpb->bpbFATsecs);
    if (!fat->num_fat_sectors)
        fat->num_fat_sectors = le32_to_cpu (bpb->bpbBigFATsecs);
    fat->root_dir_sectors
        = ((le16_to_cpu (bpb->bpbRootDirEnts) * 32)
           + (fat->bytes_per_sector - 1)) / fat->bytes_per_sector;
    fat->first_data_sector = bpb->bpbResSectors + bpb->bpbFATs
        * fat->num_fat_sectors + fat->root_dir_sectors;
    tot_sectors = le16_to_cpu (bpb->bpbSectors);
    if (!tot_sectors)
        tot_sectors = le32_to_cpu (bpb->bpbHugeSectors);
    data_sectors = tot_sectors - fat->first_data_sector;
    fat->num_clusters = data_sectors / bpb->bpbSecPerClust;
    fat->first_data_sector += fat->first_sector;
    fat->sectors_per_cluster = bpb->bpbSecPerClust;
    fat->first_fat_sector = bpb->bpbResSectors + fat->first_sector;
    fat->first_dir_sector = bpb->bpbResSectors
        + bpb->bpbFATs * fat->num_fat_sectors + fat->first_sector;
    if (fat->type == FAT_FAT32)
        fat->root_dir_cluster = le32_to_cpu (bpb->bpbRootClust);
    else
        fat->root_dir_cluster = 0;
    fat->bytes_per_cluster
        = fat->sectors_per_cluster * fat->bytes_per_sector;
    return 1;
}

variable_types:
buffer
unsigned char *

variable_types: struct bootsector710 { unsigned char bsJump[3]; char bsOEMName[8]; struct bpb710 { unsigned short bpbBytesPerSec; unsigned char bpbSecPerClust; unsigned short bpbResSectors; unsigned char bpbFATs; unsigned short bpbRootDirEnts; unsigned short bpbSectors; unsigned char bpbMedia; unsigned short bpbFATsecs; unsigned short bpbSecPerTrack; unsigned short bpbHeads; unsigned int bpbHiddenSecs; unsigned int bpbHugeSectors; unsigned int bpbBigFATsecs; unsigned short bpbExtFlags; unsigned short bpbFSVers; unsigned int bpbRootClust; unsigned short bpbFSInfo; unsigned short bpbBackup; unsigned char bpbFiller[12]; } bsBPB; struct extboot { unsigned char exDriveNumber; unsigned char exReserved1; unsigned char exBootSignature; unsigned char exVolumeID[4]; unsigned char exVolumeLabel[11]; char exFileSysType[8]; } bsExt; unsigned char bsBootCode[418]; unsigned char bsBootSectSig2; unsigned char bsBootSectSig3; unsigned char bsBootSectSig0; unsigned char bsBootSectSig1; } *

variable_types: struct bpb710 { unsigned short bpbBytesPerSec; unsigned char bpbSecPerClust; unsigned short bpbResSectors; unsigned char bpbFATs; unsigned short bpbRootDirEnts; unsigned short bpbSectors; unsigned char bpbMedia; unsigned short bpbFATsecs; unsigned short bpbSecPerTrack; unsigned short bpbHeads; unsigned int bpbHiddenSecs; unsigned int bpbHugeSectors; unsigned int bpbBigFATsecs; unsigned short bpbExtFlags; unsigned short bpbFSVers; unsigned int bpbRootClust; unsigned short bpbFSInfo; unsigned short bpbBackup; unsigned char bpbFiller[12]; } *

variable_types: struct extboot { unsigned char exDriveNumber; unsigned char exReserved1; unsigned char exBootSignature; unsigned char exVolumeID[4]; unsigned char exVolumeLabel[11]; char exFileSysType[8]; } *

variable_types:
label
char [12]

variable_types: i int

user_defined_types: struct bootsector710 { unsigned char bsJump[3]; char bsOEMName[8]; struct bpb710 bsBPB; struct extboot bsExt; unsigned char bsBootCode[418]; unsigned char bsBootSectSig2; unsigned char bsBootSectSig3; unsigned char bsBootSectSig0; unsigned char bsBootSectSig1; }


decompiled_code:
int __fastcall print_czas(unsigned __int64 a1, unsigned int a2)
{
return printf("%02d:%02d:%02d", (unsigned int)a1, HIDWORD(a1), a2);
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int64 a1, unsigned int a2)
{
return printf("%02d:%02d:%02d", (unsigned int)a1, HIDWORD(a1), a2);
}

original_code:
void print_czas(czas c)
{
 printf("%02d:%02d:%02d",c.godzina,c.minuta,c.sekunda);
}

canonical_original_code:
void print_czas(struct czas c)
{
 printf("%02d:%02d:%02d",c.godzina,c.minuta,c.sekunda);
}

variable_types: struct czas { int godzina; int minuta; int sekunda; }


decompiled_code:
__int64 __fastcall get_czas_from_s(int a1)
{
div_t v1; // rax
__int64 v3; // [rsp+14h] [rbp-14h]

v1 = div(a1, 3600);
LODWORD(v3) = v1.quot;
HIDWORD(v3) = div(v1.rem, 60).quot;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
div_t v1; // rax
__int64 v3; // [rsp+14h] [rbp-14h]

v1 = div(a1, 3600);
LODWORD(v3) = v1.quot;
HIDWORD(v3) = div(v1.rem, 60).quot;
return v3;
}

original_code:
czas get_czas_from_s(int s)
{
 czas wynik;
 div_t d = div(s,60*60);
 wynik.godzina = d.quot;
 d = div(d.rem,60);
 wynik.minuta = d.quot;
 wynik.sekunda = d.rem;
 return wynik;
}

canonical_original_code:
struct czas get_czas_from_s(int s)
{
 struct czas wynik;
 struct div_t d = div(s,60*60);
 wynik.godzina = d.quot;
 d = div(d.rem,60);
 wynik.minuta = d.quot;
 wynik.sekunda = d.rem;
 return wynik;
}

variable_types: s int

variable_types:
d
struct div_t { int quot; int rem; }

return_type: struct czas { int godzina; int minuta; int sekunda; }


decompiled_code:
__int64 __fastcall get_s_from_czas(__int64 a1, int a2)
{
return (unsigned int)(60 * HIDWORD(a1) + 3600 * a1 + a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
return (unsigned int)(60 * HIDWORD(a1) + 3600 * a1 + a2);
}

original_code:
int get_s_from_czas(czas c)
{
 return c.godzina*60*60 + c.minuta*60+c.sekunda;
}

canonical_original_code:
int get_s_from_czas(struct czas c)
{
 return c.godzina*60*60 + c.minuta*60+c.sekunda;
}

user_defined_types: struct czas { int godzina; int minuta; int sekunda; }


diff

decompiled_code:
__int64 __fastcall diff(__int64 a1, int a2)
{
int v2; // ecx
__int64 v3; // r8
int v4; // eax
int v5; // edx

get_s_from_czas(a1, a2);
v4 = get_s_from_czas(v3, v2);
return get_czas_from_s(abs32(v5 - v4));
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
int v2; // ecx
__int64 v3; // r8
int v4; // eax
int v5; // edx

func9(a1, a2);
v4 = func9(v3, v2);
return func8(abs32(v5 - v4));
}

original_code:
czas diff(czas c1, czas c2)
{
 return get_czas_from_s(abs(get_s_from_czas(c1)-get_s_from_czas(c2)));
}

canonical_original_code:
struct czas diff(struct czas c1, struct czas c2)
{
 return get_czas_from_s(abs(get_s_from_czas(c1)-get_s_from_czas(c2)));
}


test

original_code:
void test(void)
{
  int vals[] = {0,0,0,0,0,0,0,0,0,0};
  czas test;
  int i;
  for(i = 0; i <= 86399; i++)
  {
   test = get_czas_from_s(i);
   vals[(test.godzina % 10)]++;
   vals[(test.godzina / 10)]++;
   vals[(test.minuta % 10)]++;
   vals[(test.minuta / 10)]++;
   vals[(test.sekunda % 10)]++;
   vals[(test.sekunda / 10)]++;
  }
  int max, maxpos;
  max = vals[0];
  maxpos = 0;
  printf("Wystapienia poszczegolnych cyfr na wyswietlaczu od 00:00:00 do 23:59:59:\n");
  for(i = 0; i < 10; i++)
  {
   printf("%d: %d\n", i, vals[i]);
   if(vals[i] > max)
   {
    max = vals[i];
    maxpos = i;
   }
  }
  printf("\nCyfra/y najczesciej wystepujaca/e to %d", (maxpos));
  for(i = 0; i < 10; i++)
  {
   if(i!= maxpos && vals[i] == max)
   {
    printf(" i %d", i);
   }
  }
  printf("\n");
}

canonical_original_code:
void test()
{
  int vals[] = {0,0,0,0,0,0,0,0,0,0};
  struct czas test;
  int i;
  for(i = 0; i <= 86399; i++)
  {
   test = get_czas_from_s(i);
   vals[(test.godzina % 10)]++;
   vals[(test.godzina / 10)]++;
   vals[(test.minuta % 10)]++;
   vals[(test.minuta / 10)]++;
   vals[(test.sekunda % 10)]++;
   vals[(test.sekunda / 10)]++;
  }
  int max; int maxpos;
  max = vals[0];
  maxpos = 0;
  printf("Wystapienia poszczegolnych cyfr na wyswietlaczu od 00:00:00 do 23:59:59:\n");
  for(i = 0; i < 10; i++)
  {
   printf("%d: %d\n", i, vals[i]);
   if(vals[i] > max)
   {
    max = vals[i];
    maxpos = i;
   }
  }
  printf("\nCyfra/y najczesciej wystepujaca/e to %d", (maxpos));
  for(i = 0; i < 10; i++)
  {
   if(i!= maxpos && vals[i] == max)
   {
    printf(" i %d", i);
   }
  }
  printf("\n");
}

variable_types:
vals
int []

variable_types: max int

variable_types: maxpos int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rdx
__int64 v6; // [rsp+0h] [rbp-38h]
unsigned int v7; // [rsp+8h] [rbp-30h]

test(argc, argv, envp);
puts("Wpisz -1 aby zakonczyc");
while ( 1 )
{
puts("Podaj 1. czas w formacie HH:MM:SS");
__isoc99_scanf();
if ( (_DWORD)v6 == -1 )
break;
puts("\nPodaj 2. czas w formacie HH:MM:SS");
__isoc99_scanf();
printf("\nWynik to: ");
v3 = diff(v6, v7, v6, v7);
print_czas(v3, v4);
puts("\n----");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rdx
__int64 v6; // [rsp+0h] [rbp-38h]
unsigned int v7; // [rsp+8h] [rbp-30h]

func11(argc, argv, envp);
puts("Wpisz -1 aby zakonczyc");
while ( 1 )
{
puts("Podaj 1. czas w formacie HH:MM:SS");
__isoc99_scanf();
if ( (_DWORD)v6 == -1 )
break;
puts("\nPodaj 2. czas w formacie HH:MM:SS");
__isoc99_scanf();
printf("\nWynik to: ");
v3 = func10(v6, v7, v6, v7);
func7(v3, v4);
puts("\n----");
}
return 0;
}

original_code:
int main(int argc, char** argv)
{
 test();
 int h,m,s;
 czas c1,c2;
 printf("Wpisz -1 aby zakonczyc\n");
 while(1)
 {
  printf("Podaj 1. czas w formacie HH:MM:SS\n");
  scanf("%d:%d:%d", &h,&m,&s);
  if(h == -1)
  {
   break;
  }
  c1.godzina = h;
  c1.minuta = m;
  c1.sekunda = s;
  printf("\nPodaj 2. czas w formacie HH:MM:SS\n");
  scanf("%d:%d:%d", &h,&m,&s);
  if(h == -1)
  {
   break;
  }
  c2.godzina = h;
  c2.minuta = m;
  c2.sekunda = s;
  printf("\nWynik to: ");
  print_czas(diff(c1,c2));
  printf("\n----\n");
 }
}

canonical_original_code:
int main(int argc, char **argv)
{
 test();
 int h; int m; int s;
 struct czas c1; struct czas c2;
 printf("Wpisz -1 aby zakonczyc\n");
 while(1)
 {
  printf("Podaj 1. czas w formacie HH:MM:SS\n");
  scanf("%d:%d:%d", &h,&m,&s);
  if(h == -1)
  {
   break;
  }
  c1.godzina = h;
  c1.minuta = m;
  c1.sekunda = s;
  printf("\nPodaj 2. czas w formacie HH:MM:SS\n");
  scanf("%d:%d:%d", &h,&m,&s);
  if(h == -1)
  {
   break;
  }
  c2.godzina = h;
  c2.minuta = m;
  c2.sekunda = s;
  printf("\nWynik to: ");
  print_czas(diff(c1,c2));
  printf("\n----\n");
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: h int

variable_types: m int


GetCode

decompiled_code:
__int64 __fastcall GetCode(char a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax

v1 = 0LL;
v2 = -1;
do
{
if ( cipher[v1] == a1 )
v2 = v1;
++v1;
}
while ( v1 != 25 );
result = 0LL;
if ( v2 != -1 )
result = (unsigned int)(v2 % 5 + 2 * (5 * (v2 / 5) + 5) + 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax

v1 = 0LL;
v2 = -1;
do
{
if ( cipher[v1] == a1 )
v2 = v1;
++v1;
}
while ( v1 != 25 );
result = 0LL;
if ( v2 != -1 )
result = (unsigned int)(v2 % 5 + 2 * (5 * (v2 / 5) + 5) + 1);
return result;
}

original_code:
int GetCode(char c)
{
 int raw = -1;
 int i;
 for(i = 0; i < 25; i++)
 {
  if(cipher[i] == c)
  {
   raw = i;
  }
 }
 if(raw == -1)
 {
  return 0;
 }
 return ((raw / 5)+1)*10 + (raw%5)+1;
}

variable_types: c char

variable_types: raw int


GetCharFromCode

decompiled_code:
__int64 __fastcall GetCharFromCode(int a1)
{
div_t v1; // rax

if ( !a1 )
return 32LL;
v1 = div(a1, 10);
return (unsigned __int8)cipher[5 * v1.quot - 6 + v1.rem];
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
div_t v1; // rax

if ( !a1 )
return 32LL;
v1 = div(a1, 10);
return (unsigned __int8)cipher[5 * v1.quot - 6 + v1.rem];
}

original_code:
char GetCharFromCode(int code)
{
 if(code == 0)
 {
 return ' ';
 }
 div_t d = div(code, 10);
 return cipher[(d.quot-1)*5+d.rem-1];
}

canonical_original_code:
char GetCharFromCode(int code)
{
 if(code == 0)
 {
 return ' ';
 }
 struct div_t d = div(code, 10);
 return cipher[(d.quot-1)*5+d.rem-1];
}

variable_types: code int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rdi
char v6; // al
size_t v7; // rax
char *v8; // r12
char *v9; // rbp
char v10; // al
unsigned int v11; // eax
_DWORD v13[256]; // [rsp+10h] [rbp-2418h]
char s[8216]; // [rsp+410h] [rbp-2018h] BYREF

while ( 1 )
{
puts("Chcesz (o)dszyfrowac wiadomosc czy (z)aszyfrowac? (q zeby wyjsc)\n");
gets();
if ( s[0] == 113 )
break;
if ( s[0] == 122 )
{
puts("Podaj wiadomosc do zaszyfrowania:\n");
gets();
v7 = strlen(s);
if ( v7 )
{
v8 = s;
v9 = &s[(unsigned int)(v7 - 1) + 1];
do
{
v10 = tolower(*v8);
if ( v10 == 106 )
v10 = 105;
v11 = GetCode((unsigned int)v10, argv);
if ( v11 )
{
argv = (const char **)v11;
printf("%d ", v11);
}
++v8;
}
while ( v9 != v8 );
}
}
else
{
v3 = 0LL;
puts("Podawaj kolejne znaki zaszyfrowanej wiadomosci, podaj\t0 aby zakonczyc wpisywanie\n");
do
{
gets();
argv = (const char **)"%d";
__isoc99_sscanf();
v13[v3++] = 0;
}
while ( v3 != 256 );
v4 = 0LL;
puts("Odszyfrowana wiadomosc to:\n");
do
{
v5 = (unsigned int)v13[v4++];
v6 = GetCharFromCode(v5, "%d");
putchar(v6);
}
while ( (int)v4 < 256 );
}
puts("\n");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rdi
char v6; // al
size_t v7; // rax
char *v8; // r12
char *v9; // rbp
char v10; // al
unsigned int v11; // eax
_DWORD v13[256]; // [rsp+10h] [rbp-2418h]
char s[8216]; // [rsp+410h] [rbp-2018h] BYREF

while ( 1 )
{
puts("Chcesz (o)dszyfrowac wiadomosc czy (z)aszyfrowac? (q zeby wyjsc)\n");
gets();
if ( s[0] == 113 )
break;
if ( s[0] == 122 )
{
puts("Podaj wiadomosc do zaszyfrowania:\n");
gets();
v7 = strlen(s);
if ( v7 )
{
v8 = s;
v9 = &s[(unsigned int)(v7 - 1) + 1];
do
{
v10 = tolower(*v8);
if ( v10 == 106 )
v10 = 105;
v11 = func7((unsigned int)v10, argv);
if ( v11 )
{
argv = (const char **)v11;
printf("%d ", v11);
}
++v8;
}
while ( v9 != v8 );
}
}
else
{
v3 = 0LL;
puts("Podawaj kolejne znaki zaszyfrowanej wiadomosci, podaj\t0 aby zakonczyc wpisywanie\n");
do
{
gets();
argv = (const char **)"%d";
__isoc99_sscanf();
v13[v3++] = 0;
}
while ( v3 != 256 );
v4 = 0LL;
puts("Odszyfrowana wiadomosc to:\n");
do
{
v5 = (unsigned int)v13[v4++];
v6 = func8(v5, "%d");
putchar(v6);
}
while ( (int)v4 < 256 );
}
puts("\n");
}
return 0;
}

original_code:
int main(int argc, char** argv)
{
  char buff[8192];
  int len,i;
  char tmp;
  int code;
  int codes[256];
  int codesCount;
  while(1)
  {
   puts("Chcesz (o)dszyfrowac wiadomosc czy (z)aszyfrowac? (q zeby wyjsc)\n");
   gets(buff);
   if(buff[0] == 'q')
   {
    break;
   }
   if(buff[0] == 'z')
   {
    puts("Podaj wiadomosc do zaszyfrowania:\n");
    gets(buff);
    len = strlen(buff);
    int i;
    for(i = 0; i<len; i++)
    {
      tmp = buff[i];
      tmp = tolower(tmp);
      if(tmp == 'j')
       tmp = 'i';
      code = GetCode(tmp);
      if(code != 0)
      {
       printf("%d ", code);
      }
    }
    puts("\n");
   }
   else
   {
    puts("Podawaj kolejne znaki zaszyfrowanej wiadomosci, podaj	0 aby zakonczyc wpisywanie\n");
    codesCount = 0;
    for(i = 0; i < 256; i++)
    {
     gets(buff);
     code = -1;
     sscanf(buff, "%d", &code);
     if(code == -1)
     {
      codes[codesCount] = 0;
     }
     else if(code == 0)
     {
      break;
     }
     else
     {
      codes[codesCount] = code;
     }
     codesCount++;
    }
    if(codesCount > 0)
    {
     puts("Odszyfrowana wiadomosc to:\n");
     for(i = 0; i < codesCount; i++)
     {
      printf("%c", GetCharFromCode(codes[i]));
     }
    }
    puts("\n");
   }
  }
}

canonical_original_code:
int main(int argc, char **argv)
{
  char buff[8192];
  int len; int i;
  char tmp;
  int code;
  int codes[256];
  int codesCount;
  while(1)
  {
   puts("Chcesz (o)dszyfrowac wiadomosc czy (z)aszyfrowac? (q zeby wyjsc)\n");
   gets(buff);
   if(buff[0] == 'q')
   {
    break;
   }
   if(buff[0] == 'z')
   {
    puts("Podaj wiadomosc do zaszyfrowania:\n");
    gets(buff);
    len = strlen(buff);
    int i;
    for(i = 0; i<len; i++)
    {
      tmp = buff[i];
      tmp = tolower(tmp);
      if(tmp == 'j')
       tmp = 'i';
      code = GetCode(tmp);
      if(code != 0)
      {
       printf("%d ", code);
      }
    }
    puts("\n");
   }
   else
   {
    puts("Podawaj kolejne znaki zaszyfrowanej wiadomosci, podaj	0 aby zakonczyc wpisywanie\n");
    codesCount = 0;
    for(i = 0; i < 256; i++)
    {
     gets(buff);
     code = -1;
     sscanf(buff, "%d", &code);
     if(code == -1)
     {
      codes[codesCount] = 0;
     }
     else if(code == 0)
     {
      break;
     }
     else
     {
      codes[codesCount] = code;
     }
     codesCount++;
    }
    if(codesCount > 0)
    {
     puts("Odszyfrowana wiadomosc to:\n");
     for(i = 0; i < codesCount; i++)
     {
      printf("%c", GetCharFromCode(codes[i]));
     }
    }
    puts("\n");
   }
  }
}

variable_types:
buff
char [8192]

variable_types: len int

variable_types: tmp char

variable_types:
codes
int [256]

variable_types: codesCount int


code

original_code:
char* code(char* src, int decode)
{
 int len = strlen(src);
 unsigned char tmp;
 for(int i = 0; i < len; i++)
 {
  tmp = src[i];
  tmp = tolower(tmp);
  if(tmp == 32)
  {
   continue;
  }
  else if(tmp < 97 || tmp > 122)
  {
   tmp = 32;
   continue;
  }
  if(!decode)
  {
   tmp += 13;
   if(tmp > 122)
   {
    tmp = 97 + tmp - 122 -1;
   }
  }
  else
  {
   tmp -= 13;
   if(tmp < 97)
   {
    tmp = 122 - 97 +tmp+1;
   }
  }
  src[i] = tmp;
 }
 return src;
}

canonical_original_code:
char *code(char *src, int decode)
{
 int len = strlen(src);
 unsigned char tmp;
 for(int i = 0; i < len; i++)
 {
  tmp = src[i];
  tmp = tolower(tmp);
  if(tmp == 32)
  {
   continue;
  }
  else if(tmp < 97 || tmp > 122)
  {
   tmp = 32;
   continue;
  }
  if(!decode)
  {
   tmp += 13;
   if(tmp > 122)
   {
    tmp = 97 + tmp - 122 -1;
   }
  }
  else
  {
   tmp -= 13;
   if(tmp < 97)
   {
    tmp = 122 - 97 +tmp+1;
   }
  }
  src[i] = tmp;
 }
 return src;
}

variable_types:
src
char *

variable_types: decode int

variable_types:
tmp
unsigned char

variable_types: i int

return_type: char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
const char *v4; // rax
__int64 v6; // [rsp+0h] [rbp-408h] BYREF

puts("Wpisz tekst do zakodowania:\n");
gets();
v3 = (const char *)code(&v6, 0LL);
printf("Zakodowany: %s\n", v3);
v4 = (const char *)code(v3, 1LL);
printf("Odkodowany: %s\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
const char *v4; // rax
__int64 v6; // [rsp+0h] [rbp-408h] BYREF

puts("Wpisz tekst do zakodowania:\n");
gets();
v3 = (const char *)func7(&v6, 0LL);
printf("Zakodowany: %s\n", v3);
v4 = (const char *)func7(v3, 1LL);
printf("Odkodowany: %s\n", v4);
return 0;
}

original_code:
int main(int argc, char** argv)
{
 puts("Wpisz tekst do zakodowania:\n");
 char buff[1024];
 gets(buff);
 char* c = code(buff, 0);
 printf("Zakodowany: %s\n", c);
 c = code(c, 1);
 printf("Odkodowany: %s\n", c);
}

canonical_original_code:
int main(int argc, char **argv)
{
 puts("Wpisz tekst do zakodowania:\n");
 char buff[1024];
 gets(buff);
 char *c = code(buff, 0);
 printf("Zakodowany: %s\n", c);
 c = code(c, 1);
 printf("Odkodowany: %s\n", c);
}

variable_types:
buff
char [1024]

variable_types:
c
char *


decompiled_code:
__int64 update_error()
{
__int64 result; // rax
long double v1; // fst6
long double v2; // fst5

result = 2LL;
v1 = (*(long double *)&expected - *(long double *)&vout) * ((1.0 - *(long double *)&vout) * *(long double *)&vout);
*(long double *)&eout = v1;
emid[0] = vmid[0] * (1.0 - vmid[0]) * (wout[0] * v1) + 0.0;
emid[1] = vmid[1] * (1.0 - vmid[1]) * (wout[1] * v1) + 0.0;
do
{
v2 = vmid[result];
result += 6LL;
emid[result - 6] = v2 * (1.0 - v2) * (wout[result - 6] * v1) + 0.0;
emid[result - 5] = vmid[result - 5] * (1.0 - vmid[result - 5]) * (wout[result - 5] * v1) + 0.0;
emid[result - 4] = vmid[result - 4] * (1.0 - vmid[result - 4]) * (wout[result - 4] * v1) + 0.0;
emid[result - 3] = vmid[result - 3] * (1.0 - vmid[result - 3]) * (wout[result - 3] * v1) + 0.0;
emid[result - 2] = vmid[result - 2] * (1.0 - vmid[result - 2]) * (wout[result - 2] * v1) + 0.0;
emid[result - 1] = vmid[result - 1] * (1.0 - vmid[result - 1]) * (wout[result - 1] * v1) + 0.0;
}
while ( result != 20 );
return result * 16;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
long double v1; // fst6
long double v2; // fst5

result = 2LL;
v1 = (*(long double *)&expected - *(long double *)&vout) * ((1.0 - *(long double *)&vout) * *(long double *)&vout);
*(long double *)&eout = v1;
emid[0] = vmid[0] * (1.0 - vmid[0]) * (wout[0] * v1) + 0.0;
emid[1] = vmid[1] * (1.0 - vmid[1]) * (wout[1] * v1) + 0.0;
do
{
v2 = vmid[result];
result += 6LL;
emid[result - 6] = v2 * (1.0 - v2) * (wout[result - 6] * v1) + 0.0;
emid[result - 5] = vmid[result - 5] * (1.0 - vmid[result - 5]) * (wout[result - 5] * v1) + 0.0;
emid[result - 4] = vmid[result - 4] * (1.0 - vmid[result - 4]) * (wout[result - 4] * v1) + 0.0;
emid[result - 3] = vmid[result - 3] * (1.0 - vmid[result - 3]) * (wout[result - 3] * v1) + 0.0;
emid[result - 2] = vmid[result - 2] * (1.0 - vmid[result - 2]) * (wout[result - 2] * v1) + 0.0;
emid[result - 1] = vmid[result - 1] * (1.0 - vmid[result - 1]) * (wout[result - 1] * v1) + 0.0;
}
while ( result != 20 );
return result * 16;
}

original_code:
static void update_error(void)
{
 int j, i;
 for(j = 0; j < 1; j++) {
  eout[j] = vout[j]
   * (1.0 - vout[j])
   * (expected[j] - vout[j]);
 }
 for(i = 0; i < 20; i++) {
  int j;
  for(j = 0, emid[i] = 0; j < 1; j++) {
   emid[i] += vmid[i]
    * (1.0 - vmid[i])
    * (wout[i][j] * eout[j]);
  }
 }
}

canonical_original_code:
static void update_error()
{
 int j; int i;
 for(j = 0; j < 1; j++) {
  eout[j] = vout[j]
   * (1.0 - vout[j])
   * (expected[j] - vout[j]);
 }
 for(i = 0; i < 20; i++) {
  int j;
  for(j = 0, emid[i] = 0; j < 1; j++) {
   emid[i] += vmid[i]
    * (1.0 - vmid[i])
    * (wout[i][j] * eout[j]);
  }
 }
}

variable_types: j int


decompiled_code:
__int64 update_weights()
{
__int64 result; // rax
long double v1; // fst6
long double v2; // fst5
long double *v3; // rsi
__int64 i; // rcx
long double v5; // fst6
unsigned __int64 v6; // rdx
long double v7; // fst5
long double v8; // fst5
long double v9; // fst5
long double v10; // fst5
long double v11; // fst5
long double v12; // fst5
long double v13; // fst5
long double v14; // fst5
long double v15; // fst4

result = 0LL;
v1 = *(long double *)&eout * 0.2;
v2 = *(long double *)&out_offset;
do
{
result += 10LL;
wout[result - 10] = vmid[result - 10] * v1 + wout[result - 10];
wout[result - 9] = vmid[result - 9] * v1 + wout[result - 9];
wout[result - 8] = vmid[result - 8] * v1 + wout[result - 8];
wout[result - 7] = vmid[result - 7] * v1 + wout[result - 7];
wout[result - 6] = vmid[result - 6] * v1 + wout[result - 6];
wout[result - 5] = vmid[result - 5] * v1 + wout[result - 5];
wout[result - 4] = vmid[result - 4] * v1 + wout[result - 4];
wout[result - 3] = vmid[result - 3] * v1 + wout[result - 3];
wout[result - 2] = vmid[result - 2] * v1 + wout[result - 2];
wout[result - 1] = vmid[result - 1] * v1 + wout[result - 1];
v2 = v2 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1;
}
while ( result != 20 );
*(long double *)&out_offset = v2;
v3 = (long double *)&vin;
for ( i = 0LL; i != 160; i += 32LL )
{
v5 = *v3;
v6 = 2LL;
v7 = emid[0] * 0.2;
*(long double *)&wmid[i] = emid[0] * 0.2 * v5 + *(long double *)&wmid[i];
mid_offset[0] = v7 + mid_offset[0];
v8 = emid[1] * 0.2;
*(long double *)((char *)&wmid[i + 1] + 6) = v8 * v5 + *(long double *)((char *)&wmid[i + 1] + 6);
mid_offset[1] = v8 + mid_offset[1];
do
{
v9 = emid[v6] * 0.2;
*(long double *)((char *)&wmid[i] + v6 * 16) = v9 * v5 + *(long double *)((char *)&wmid[i] + v6 * 16);
mid_offset[v6] = v9 + mid_offset[v6];
v10 = emid[v6 + 1] * 0.2;
*(long double *)((char *)&wmid[i + 1] + v6 * 16 + 6) = v10 * v5
+ *(long double *)((char *)&wmid[i + 1] + v6 * 16 + 6);
mid_offset[v6 + 1] = v10 + mid_offset[v6 + 1];
v11 = emid[v6 + 2] * 0.2;
*(long double *)((char *)&wmid[i + 3] + v6 * 16 + 2) = v11 * v5
+ *(long double *)((char *)&wmid[i + 3] + v6 * 16 + 2);
mid_offset[v6 + 2] = v11 + mid_offset[v6 + 2];
v12 = emid[v6 + 3] * 0.2;
*(long double *)((char *)&wmid[i + 4] + v6 * 16 + 8) = v12 * v5
+ *(long double *)((char *)&wmid[i + 4] + v6 * 16 + 8);
mid_offset[v6 + 3] = v12 + mid_offset[v6 + 3];
v13 = emid[v6 + 4] * 0.2;
*(long double *)((char *)&wmid[i + 6] + v6 * 16 + 4) = v13 * v5
+ *(long double *)((char *)&wmid[i + 6] + v6 * 16 + 4);
mid_offset[v6 + 4] = v13 + mid_offset[v6 + 4];
v14 = emid[v6 + 5] * 0.2;
*(long double *)((char *)&wmid[i + 8] + v6 * 16) = v14 * v5 + *(long double *)((char *)&wmid[i + 8] + v6 * 16);
v15 = mid_offset[v6 + 5];
v6 += 6LL;
mid_offset[v6 - 1] = v14 + v15;
}
while ( v6 != 20 );
++v3;
}
return result * 16;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
long double v1; // fst6
long double v2; // fst5
long double *v3; // rsi
__int64 i; // rcx
long double v5; // fst6
unsigned __int64 v6; // rdx
long double v7; // fst5
long double v8; // fst5
long double v9; // fst5
long double v10; // fst5
long double v11; // fst5
long double v12; // fst5
long double v13; // fst5
long double v14; // fst5
long double v15; // fst4

result = 0LL;
v1 = *(long double *)&eout * 0.2;
v2 = *(long double *)&out_offset;
do
{
result += 10LL;
wout[result - 10] = vmid[result - 10] * v1 + wout[result - 10];
wout[result - 9] = vmid[result - 9] * v1 + wout[result - 9];
wout[result - 8] = vmid[result - 8] * v1 + wout[result - 8];
wout[result - 7] = vmid[result - 7] * v1 + wout[result - 7];
wout[result - 6] = vmid[result - 6] * v1 + wout[result - 6];
wout[result - 5] = vmid[result - 5] * v1 + wout[result - 5];
wout[result - 4] = vmid[result - 4] * v1 + wout[result - 4];
wout[result - 3] = vmid[result - 3] * v1 + wout[result - 3];
wout[result - 2] = vmid[result - 2] * v1 + wout[result - 2];
wout[result - 1] = vmid[result - 1] * v1 + wout[result - 1];
v2 = v2 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1;
}
while ( result != 20 );
*(long double *)&out_offset = v2;
v3 = (long double *)&vin;
for ( i = 0LL; i != 160; i += 32LL )
{
v5 = *v3;
v6 = 2LL;
v7 = emid[0] * 0.2;
*(long double *)&wmid[i] = emid[0] * 0.2 * v5 + *(long double *)&wmid[i];
mid_offset[0] = v7 + mid_offset[0];
v8 = emid[1] * 0.2;
*(long double *)((char *)&wmid[i + 1] + 6) = v8 * v5 + *(long double *)((char *)&wmid[i + 1] + 6);
mid_offset[1] = v8 + mid_offset[1];
do
{
v9 = emid[v6] * 0.2;
*(long double *)((char *)&wmid[i] + v6 * 16) = v9 * v5 + *(long double *)((char *)&wmid[i] + v6 * 16);
mid_offset[v6] = v9 + mid_offset[v6];
v10 = emid[v6 + 1] * 0.2;
*(long double *)((char *)&wmid[i + 1] + v6 * 16 + 6) = v10 * v5
+ *(long double *)((char *)&wmid[i + 1] + v6 * 16 + 6);
mid_offset[v6 + 1] = v10 + mid_offset[v6 + 1];
v11 = emid[v6 + 2] * 0.2;
*(long double *)((char *)&wmid[i + 3] + v6 * 16 + 2) = v11 * v5
+ *(long double *)((char *)&wmid[i + 3] + v6 * 16 + 2);
mid_offset[v6 + 2] = v11 + mid_offset[v6 + 2];
v12 = emid[v6 + 3] * 0.2;
*(long double *)((char *)&wmid[i + 4] + v6 * 16 + 8) = v12 * v5
+ *(long double *)((char *)&wmid[i + 4] + v6 * 16 + 8);
mid_offset[v6 + 3] = v12 + mid_offset[v6 + 3];
v13 = emid[v6 + 4] * 0.2;
*(long double *)((char *)&wmid[i + 6] + v6 * 16 + 4) = v13 * v5
+ *(long double *)((char *)&wmid[i + 6] + v6 * 16 + 4);
mid_offset[v6 + 4] = v13 + mid_offset[v6 + 4];
v14 = emid[v6 + 5] * 0.2;
*(long double *)((char *)&wmid[i + 8] + v6 * 16) = v14 * v5 + *(long double *)((char *)&wmid[i + 8] + v6 * 16);
v15 = mid_offset[v6 + 5];
v6 += 6LL;
mid_offset[v6 - 1] = v14 + v15;
}
while ( v6 != 20 );
++v3;
}
return result * 16;
}

original_code:
static void update_weights(void)
{
 int j;
 for(j = 0; j < 20; j++) {
  int i;
  for(i = 0; i < 1; i++) {
   wout[j][i] += 0.2
    * eout[i]
    * vmid[j];
   out_offset[i] += 0.2 * eout[i];
  }
 }
 for(j = 0; j < 5; j++) {
  int i;
  for(i = 0; i < 20; i++) {
   wmid[j][i] += 0.2
    * emid[i]
    * vin[j];
   mid_offset[i] += 0.2 * emid[i];
  }
 }
}

canonical_original_code:
static void update_weights()
{
 int j;
 for(j = 0; j < 20; j++) {
  int i;
  for(i = 0; i < 1; i++) {
   wout[j][i] += 0.2
    * eout[i]
    * vmid[j];
   out_offset[i] += 0.2 * eout[i];
  }
 }
 for(j = 0; j < 5; j++) {
  int i;
  for(i = 0; i < 20; i++) {
   wmid[j][i] += 0.2
    * emid[i]
    * vin[j];
   mid_offset[i] += 0.2 * emid[i];
  }
 }
}


init

original_code:
static void init(void)
{
 int i;
 long double *ptr;
 srand(time(((void *)0)));
 for(i = 0, ptr = (long double *)&wmid[0]; i < 5 * 20; i++) {
  *ptr++ = ((long double)rand())/(0x7fffffff * 2U + 1U) - 0.5;
 }
 for(i = 0, ptr = (long double *)&wout[0]; i < 20 * 1; i++) {
  *ptr++ = ((long double)rand())/(0x7fffffff * 2U + 1U) - 0.5;
 }
}

canonical_original_code:
static void init()
{
 int i;
 long double *ptr;
 srand(time(((void *)0)));
 for(i = 0, ptr = (long double *)&wmid[0]; i < 5 * 20; i++) {
  *ptr++ = ((long double)rand())/(0x7fffffff * 2U + 1U) - 0.5;
 }
 for(i = 0, ptr = (long double *)&wout[0]; i < 20 * 1; i++) {
  *ptr++ = ((long double)rand())/(0x7fffffff * 2U + 1U) - 0.5;
 }
}

variable_types:
ptr
long double *


sigmoid

decompiled_code:
long double __fastcall sigmoid(long double a1)
{
return 1.0 / (exp(COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a1) ^ LC6)) + 1.0);
}

canonical_decompiled_code:
long double __fastcall func3(long double a1)
{
return 1.0 / (exp(COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a1) ^ LC6)) + 1.0);
}

original_code:
static long double sigmoid(long double h)
{
 return 1.0/(1.0 + exp(-h));
}

variable_types:
h
long double

return_type: long double