fsBlockAllocate

decompiled_code:
__int64 __fastcall fsBlockAllocate(unsigned __int16 a1)
{
__int64 v2; // r13
unsigned __int16 v3; // r12
unsigned __int16 v4; // r14
unsigned __int16 v5; // r15
__int16 v6; // ax
unsigned __int16 v7; // di
__int16 v8; // ax
int v9; // er13
char v10; // al
int v11; // ebx
__int16 v12; // ax
unsigned int v13; // eax
char v14; // al
char v15; // al
unsigned __int16 v16; // ax
unsigned int v17; // eax
char v18; // al
unsigned __int16 v20[29]; // [rsp+Eh] [rbp-3Ah] BYREF

v20[0] = -1;
if ( a1 != 0xFFFF )
{
v6 = segNum(a1);
v20[0] = findFreeBlock(v6);
if ( v20[0] != 0xFFFF )
goto LABEL_4;
}
v2 = randomNumber() & 0x1F;
v3 = v2;
v4 = -1;
v5 = -1;
while ( 1 )
{
v15 = readSeg(v3);
if ( v15 == 85 )
break;
if ( (v15 & 0xAA) != 0 )
{
if ( (v15 & 0x55) != 0 )
v4 = v3;
}
else
{
v5 = v3;
}
v3 = ((_BYTE)v3 + 1) & 0x1F;
if ( (_WORD)v2 == v3 )
goto LABEL_8;
}
v14 = randomNumber();
v20[0] = makeBlock(v3, v14 & 3);
LABEL_8:
if ( v20[0] == 0xFFFF )
{
if ( v5 == 0xFFFF )
{
if ( v4 == 0xFFFF )
{
LABEL_21:
fsSetError(3LL);
return v20[0];
}
v20[0] = findFreeBlock(v4);
}
else
{
writeSeg(v5, 85);
v16 = makeBlock(v5, 0);
v17 = flashAddr(v16, 0);
blkExtFlashEraseSector(v17);
v18 = randomNumber();
v20[0] = makeBlock(v5, v18 & 3);
}
v7 = v20[0];
if ( v20[0] == 0xFFFF )
goto LABEL_21;
}
else
{
LABEL_4:
v7 = v20[0];
}
v8 = segNum(v7);
v9 = readSeg(v8);
v10 = segOffset(v20[0]);
v11 = (2 << (2 * v10)) | v9 & ~(3 << (2 * v10));
v12 = segNum(v20[0]);
writeSeg(v12, v11);
if ( a1 != 0xFFFF )
{
v13 = flashAddr(a1, 16382);
blkExtFlashWrite(v13, (__int64)v20, 2u);
}
return v20[0];
}

original_code:
blk_t fsBlockAllocate(blk_t old)
{
    blk_t res = ((blk_t)-1);
    mutexLock(&fsBlkTableMutex);
    if (old != ((blk_t)-1))
    {
        res = findFreeBlock(segNum(old));
    }
    if (res == ((blk_t)-1))
    {
        segnum_t start = randomNumber() % 32,
                 i = start,
                 avail = ((blk_t)-1), partial = ((blk_t)-1);
        do
        {
            segment_t s = readSeg(i);
            if (s == 0x55)
            {
                res = makeBlock(i, randomNumber() % 4);
                break;
            }
            else if (!(s & 0xAA))
            {
                avail = i;
            }
            else if (s & 0x55)
            {
                partial = i;
            }
            i = (i + 1) % 32;
        }
        while (i != start);
        if (res == ((blk_t)-1))
        {
            if (avail != ((blk_t)-1))
            {
                writeSeg(avail, 0x55);
                blkExtFlashEraseSector(flashAddr(makeBlock(avail, 0), 0));
                res = makeBlock(avail, randomNumber() % 4);
            }
            else if (partial != ((blk_t)-1))
            {
                res = findFreeBlock(partial);
            }
        }
    }
    if (res == ((blk_t)-1))
        fsSetError(FS_ERR_NOSPC);
    else
    {
        segment_t s = readSeg(segNum(res));
        ((s) = ((s) & ~((segment_t)0x3 << 2 * (segOffset(res)))) | (segment_t)(BLOCK_USED) << 2 * (segOffset(res)));
        writeSeg(segNum(res), s);
        if (old != ((blk_t)-1))
        {
            blkExtFlashWrite(flashAddr(old, (0x10000 / 4) - sizeof(blk_t)),
                             &res, sizeof(blk_t));
        }
    }
    mutexUnlock(&fsBlkTableMutex);
    return res;
}

canonical_original_code:
unsigned short fsBlockAllocate(unsigned short old)
{
    unsigned short res = ((blk_t)-1);
    mutexLock(&fsBlkTableMutex);
    if (old != ((blk_t)-1))
    {
        res = findFreeBlock(segNum(old));
    }
    if (res == ((blk_t)-1))
    {
        unsigned short start = randomNumber() % 32; unsigned short i = start; unsigned short avail = ((blk_t)-1); unsigned short partial = ((blk_t)-1);
        do
        {
            unsigned char s = readSeg(i);
            if (s == 0x55)
            {
                res = makeBlock(i, randomNumber() % 4);
                break;
            }
            else if (!(s & 0xAA))
            {
                avail = i;
            }
            else if (s & 0x55)
            {
                partial = i;
            }
            i = (i + 1) % 32;
        }
        while (i != start);
        if (res == ((blk_t)-1))
        {
            if (avail != ((blk_t)-1))
            {
                writeSeg(avail, 0x55);
                blkExtFlashEraseSector(flashAddr(makeBlock(avail, 0), 0));
                res = makeBlock(avail, randomNumber() % 4);
            }
            else if (partial != ((blk_t)-1))
            {
                res = findFreeBlock(partial);
            }
        }
    }
    if (res == ((blk_t)-1))
        fsSetError(FS_ERR_NOSPC);
    else
    {
        unsigned char s = readSeg(segNum(res));
        ((s) = ((s) & ~((unsigned char)0x3 << 2 * (segOffset(res)))) | (segment_t)(BLOCK_USED) << 2 * (segOffset(res)));
        writeSeg(segNum(res), s);
        if (old != ((blk_t)-1))
        {
            blkExtFlashWrite(flashAddr(old, (0x10000 / 4) - sizeof(blk_t)),
                             &res, sizeof(blk_t));
        }
    }
    mutexUnlock(&fsBlkTableMutex);
    return res;
}

variable_types:
old
unsigned short

variable_types:
res
unsigned short

variable_types:
avail
unsigned short

variable_types:
partial
unsigned short


fsBlockGetNext

repo: atiselsts/osw

decompiled_code:
__int64 __fastcall fsBlockGetNext(unsigned __int16 a1)
{
unsigned int v1; // eax
unsigned __int16 v3[5]; // [rsp+Eh] [rbp-Ah] BYREF

v1 = flashAddr(a1, 16382);
blkExtFlashRead(v1, (__int64)v3, 2u);
return v3[0];
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int16 a1)
{
unsigned int v1; // eax
unsigned __int16 v3[5]; // [rsp+Eh] [rbp-Ah] BYREF

v1 = func0(a1, 16382);
func11(v1, (__int64)v3, 2u);
return v3[0];
}

original_code:
blk_t fsBlockGetNext(blk_t prev)
{
    blk_t res;
    blkExtFlashRead(flashAddr(prev, (0x10000 / 4) - sizeof(blk_t)),
                    &res, sizeof(blk_t));
    return res;
}

canonical_original_code:
unsigned short fsBlockGetNext(unsigned short prev)
{
    unsigned short res;
    blkExtFlashRead(flashAddr(prev, (0x10000 / 4) - sizeof(blk_t)),
                    &res, sizeof(blk_t));
    return res;
}

variable_types:
prev
unsigned short

return_type: unsigned short


fsBlockFree

decompiled_code:
__int64 __fastcall fsBlockFree(__int16 a1)
{
__int16 v1; // bx
char v2; // bp
char v3; // al

v1 = segNum(a1);
v2 = readSeg(v1);
v3 = segOffset(a1);
return writeSeg(v1, v2 & (unsigned __int8)~(3 << (2 * v3)));
}

canonical_decompiled_code:
__int64 __fastcall func14(__int16 a1)
{
__int16 v1; // bx
char v2; // bp
char v3; // al

v1 = func1(a1);
v2 = func7(v1);
v3 = func2(a1);
return func9(v1, v2 & (unsigned __int8)~(3 << (2 * v3)));
}

original_code:
void fsBlockFree(blk_t block)
{
    segment_t s;
    mutexLock(&fsBlkTableMutex);
    s = readSeg(segNum(block));
    ((s) = ((s) & ~((segment_t)0x3 << 2 * (segOffset(block)))) | (segment_t)(BLOCK_AVAIL) << 2 * (segOffset(block)));
    writeSeg(segNum(block), s);
    mutexUnlock(&fsBlkTableMutex);
}

canonical_original_code:
void fsBlockFree(unsigned short block)
{
    unsigned char s;
    mutexLock(&fsBlkTableMutex);
    s = readSeg(segNum(block));
    ((s) = ((s) & ~((unsigned char)0x3 << 2 * (segOffset(block)))) | (segment_t)(BLOCK_AVAIL) << 2 * (segOffset(block)));
    writeSeg(segNum(block), s);
    mutexUnlock(&fsBlkTableMutex);
}

variable_types:
block
unsigned short

variable_types:
s
unsigned char

return_type: void


fsBlockFreeAll

decompiled_code:
__int64 fsBlockFreeAll()
{
int i; // ebx
__int64 result; // rax

for ( i = 0; i != 32; ++i )
result = writeSeg(i, 0);
return result;
}

canonical_decompiled_code:
__int64 func15()
{
int i; // ebx
__int64 result; // rax

for ( i = 0; i != 32; ++i )
result = func9(i, 0);
return result;
}

original_code:
void fsBlockFreeAll(void)
{
    segnum_t i;
    for (i = 0; i < 32; i++)
        writeSeg(i, 0x0);
}

canonical_original_code:
void fsBlockFreeAll()
{
    unsigned short i;
    for (i = 0; i < 32; i++)
        writeSeg(i, 0x0);
}

variable_types:
i
unsigned short


parseGPSGetChar

decompiled_code:
__int64 __fastcall parseGPSGetChar(_QWORD *a1, _DWORD *a2)
{
unsigned int v2; // edx

v2 = 0;
if ( *a2 )
{
--*a2;
v2 = *(unsigned __int8 *)(*a1)++;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _DWORD *a2)
{
unsigned int v2; // edx

v2 = 0;
if ( *a2 )
{
--*a2;
v2 = *(unsigned __int8 *)(*a1)++;
}
return v2;
}

original_code:
uint8_t parseGPSGetChar(const uint8_t **buf, uint_t *len)
{
    if (*len == 0) return 0;
    --(*len);
    const uint8_t ch = **buf;
    ++(*buf);
    return ch;
}

canonical_original_code:
unsigned char parseGPSGetChar(unsigned char **buf, unsigned int *len)
{
    if (*len == 0) return 0;
    --(*len);
    unsigned char ch = **buf;
    ++(*buf);
    return ch;
}

variable_types:
buf
unsigned char **

variable_types:
len
unsigned int *

variable_types:
ch
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall parseGPSu32(_QWORD *a1, _DWORD *a2, _DWORD *a3, _WORD *a4)
{
int v6; // er12
unsigned __int8 v7; // al

*a3 = 0;
if ( a4 )
*a4 = 0;
v6 = 1;
do
{
while ( 1 )
{
while ( 1 )
{
v7 = parseGPSGetChar(a1, a2);
if ( !v7 )
return 0LL;
if ( (unsigned __int8)(v7 - 48) > 9u )
break;
if ( v6 )
{
*a3 = 10 * *a3 - 48 + v7;
}
else if ( a4 )
{
*a4 = 10 * *a4 - 48 + v7;
}
}
if ( v7 != 46 )
break;
if ( !v6 )
{
*a3 = -1;
return 0xFFFFFFFFLL;
}
v6 = 0;
}
}
while ( v7 != 44 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, _DWORD *a2, _DWORD *a3, _WORD *a4)
{
int v6; // er12
unsigned __int8 v7; // al

*a3 = 0;
if ( a4 )
*a4 = 0;
v6 = 1;
do
{
while ( 1 )
{
while ( 1 )
{
v7 = func0(a1, a2);
if ( !v7 )
return 0LL;
if ( (unsigned __int8)(v7 - 48) > 9u )
break;
if ( v6 )
{
*a3 = 10 * *a3 - 48 + v7;
}
else if ( a4 )
{
*a4 = 10 * *a4 - 48 + v7;
}
}
if ( v7 != 46 )
break;
if ( !v6 )
{
*a3 = -1;
return 0xFFFFFFFFLL;
}
v6 = 0;
}
}
while ( v7 != 44 );
return 0LL;
}

original_code:
uint_t parseGPSu32(const uint8_t **buf, uint_t *len, uint32_t *u32, uint16_t *dec)
{
    uint_t mainPart = 1;
    *u32 = 0;
    if (dec) *dec = 0;
    uint8_t ch = 0;
    while ((ch = parseGPSGetChar(buf, len)) != 0) {
        if (ch >= '0' && ch <= '9') {
            if (mainPart) {
                *u32 = ((*u32 << 3) + (*u32 << 1)) + (ch - '0');
            } else {
                if (dec) *dec = ((*dec << 3) + (*dec << 1)) + (ch - '0');
            }
        } else if (ch == '.') {
            if (mainPart) {
                mainPart = 0;
            } else {
                *u32 = -1u;
                return -1;
            }
        } else if (ch == ',') {
            break;
        }
    }
    return 0;
}

canonical_original_code:
unsigned int parseGPSu32(unsigned char **buf, unsigned int *len, unsigned int *u32, unsigned short *dec)
{
    unsigned int mainPart = 1;
    *u32 = 0;
    if (dec) *dec = 0;
    unsigned char ch = 0;
    while ((ch = parseGPSGetChar(buf, len)) != 0) {
        if (ch >= '0' && ch <= '9') {
            if (mainPart) {
                *u32 = ((*u32 << 3) + (*u32 << 1)) + (ch - '0');
            } else {
                if (dec) *dec = ((*dec << 3) + (*dec << 1)) + (ch - '0');
            }
        } else if (ch == '.') {
            if (mainPart) {
                mainPart = 0;
            } else {
                *u32 = -1u;
                return -1;
            }
        } else if (ch == ',') {
            break;
        }
    }
    return 0;
}

variable_types:
dec
unsigned short *

variable_types:
mainPart
unsigned int

return_type: unsigned int


parseGPSTime

decompiled_code:
__int64 __fastcall parseGPSTime(_QWORD *a1, _DWORD *a2, _BYTE *a3)
{
unsigned int v4; // edx
unsigned int v5; // eax
__int16 v7; // [rsp+Ah] [rbp-Eh] BYREF
unsigned int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4 = parseGPSu32(a1, a2, v8, &v7);
if ( !v4 )
{
v5 = v8[0] / 0x64;
a3[4] = v8[0] % 0x64;
a3[3] = v5 % 0x64;
a3[2] = v5 / 0x64;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, _DWORD *a2, _BYTE *a3)
{
unsigned int v4; // edx
unsigned int v5; // eax
__int16 v7; // [rsp+Ah] [rbp-Eh] BYREF
unsigned int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4 = func1(a1, a2, v8, &v7);
if ( !v4 )
{
v5 = v8[0] / 0x64;
a3[4] = v8[0] % 0x64;
a3[3] = v5 % 0x64;
a3[2] = v5 / 0x64;
}
return v4;
}

original_code:
uint_t parseGPSTime(const uint8_t **buf, uint_t *len, GPSFix_t *fix)
{
    uint32_t t;
    uint16_t dec;
    uint_t res = parseGPSu32(buf, len, &t, &dec);
    if (res) return res;
    fix->s = t % 100;
    t /= 100;
    fix->m = t % 100;
    fix->h = t / 100;
    return 0;
}

canonical_original_code:
unsigned int parseGPSTime(unsigned char **buf, unsigned int *len, struct GPSFix_t *fix)
{
    unsigned int t;
    unsigned short dec;
    unsigned int res = parseGPSu32(buf, len, &t, &dec);
    if (res) return res;
    fix->s = t % 100;
    t /= 100;
    fix->m = t % 100;
    fix->h = t / 100;
    return 0;
}

variable_types: struct GPSFix_t { struct GPSDate_t { unsigned short day; } d; unsigned char h; unsigned char m; unsigned char s; struct GPSFixQuality_t { unsigned char fix; } q; struct GPSPos_t { unsigned char deg; unsigned char min; unsigned short mindec; } lat; struct GPSPos_t lon; } *

variable_types:
t
unsigned int

variable_types:
dec
unsigned short

variable_types:
res
unsigned int

user_defined_types: struct GPSFix_t { struct GPSDate_t d; unsigned char h; unsigned char m; unsigned char s; struct GPSFixQuality_t q; struct GPSPos_t lat; struct GPSPos_t lon; }


parseGPSSatCnt

original_code:
uint_t parseGPSSatCnt(const uint8_t **buf, uint_t *len, GPSFix_t *fix)
{
    uint32_t satcnt;
    parseGPSu32(buf, len, &satcnt, 0);
    if (satcnt != -1u) {
        if (satcnt > 8) {
            fix->q.satcnt = SAT_COUNT_OVER_8;
        } else if (satcnt > 6) {
            fix->q.satcnt = SAT_COUNT_7_8;
        } else if (satcnt > 4) {
            fix->q.satcnt = SAT_COUNT_5_6;
        } else {
            fix->q.satcnt = satcnt;
        }
        return 0;
    } else {
        return -1;
    }
}

canonical_original_code:
unsigned int parseGPSSatCnt(unsigned char **buf, unsigned int *len, struct GPSFix_t *fix)
{
    unsigned int satcnt;
    parseGPSu32(buf, len, &satcnt, 0);
    if (satcnt != -1u) {
        if (satcnt > 8) {
            fix->q.satcnt = SAT_COUNT_OVER_8;
        } else if (satcnt > 6) {
            fix->q.satcnt = SAT_COUNT_7_8;
        } else if (satcnt > 4) {
            fix->q.satcnt = SAT_COUNT_5_6;
        } else {
            fix->q.satcnt = satcnt;
        }
        return 0;
    } else {
        return -1;
    }
}

variable_types:
satcnt
unsigned int

user_defined_types: struct GPSDate_t { unsigned short day; }

user_defined_types: struct GPSFixQuality_t { unsigned char fix; }

user_defined_types: struct GPSPos_t { unsigned char deg; unsigned char min; unsigned short mindec; }


parseGPSDOP

original_code:
uint_t parseGPSDOP(const uint8_t **buf, uint_t *len, GPSFix_t *fix)
{
    uint32_t dop;
    uint16_t dopdec;
    parseGPSu32(buf, len, &dop, &dopdec);
    if (dop != -1u) {
        if (dop == 1) {
            if (dopdec == 0) {
                fix->q.dop = DOP_IDEAL;
            } else {
                fix->q.dop = DOP_EXCELLENT;
            }
        } else if (dop == 0) {
            fix->q.dop = DOP_POOR;
            fix->q.fix = FT_NO_FIX;
        } else if (dop < 5) {
            fix->q.dop = DOP_GOOD;
        } else if (dop < 10) {
            fix->q.dop = DOP_MODERATE;
        } else if (dop < 20) {
            fix->q.dop = DOP_FAIR;
        } else {
            fix->q.dop = DOP_POOR;
        }
        return 0;
    } else {
        fix->q.dop = -1;
        return -1;
    }
}

canonical_original_code:
unsigned int parseGPSDOP(unsigned char **buf, unsigned int *len, struct GPSFix_t *fix)
{
    unsigned int dop;
    unsigned short dopdec;
    parseGPSu32(buf, len, &dop, &dopdec);
    if (dop != -1u) {
        if (dop == 1) {
            if (dopdec == 0) {
                fix->q.dop = DOP_IDEAL;
            } else {
                fix->q.dop = DOP_EXCELLENT;
            }
        } else if (dop == 0) {
            fix->q.dop = DOP_POOR;
            fix->q.fix = FT_NO_FIX;
        } else if (dop < 5) {
            fix->q.dop = DOP_GOOD;
        } else if (dop < 10) {
            fix->q.dop = DOP_MODERATE;
        } else if (dop < 20) {
            fix->q.dop = DOP_FAIR;
        } else {
            fix->q.dop = DOP_POOR;
        }
        return 0;
    } else {
        fix->q.dop = -1;
        return -1;
    }
}

variable_types:
dop
unsigned int

variable_types:
dopdec
unsigned short


parseGPSFixQual

decompiled_code:
__int64 __fastcall parseGPSFixQual(_QWORD *a1, _DWORD *a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

parseGPSu32(a1, a2, v5, 0LL);
result = v5[0];
if ( v5[0] != -1 )
{
if ( v5[0] == 3 )
{
*(_BYTE *)(a3 + 5) = *(_BYTE *)(a3 + 5) & 0xFC | 2;
result = 0LL;
}
else
{
if ( v5[0] == 2 )
*(_BYTE *)(a3 + 5) = *(_BYTE *)(a3 + 5) & 0xFC | 1;
else
*(_BYTE *)(a3 + 5) &= 0xFCu;
result = 0LL;
}
}
return result;
}

original_code:
uint_t parseGPSFixQual(const uint8_t **buf, uint_t *len, GPSFix_t *fix)
{
    uint32_t fixq;
    parseGPSu32(buf, len, &fixq, 0);
    if (fixq != -1u) {
        if (fixq == 3) {
            fix->q.fix = FT_3D_FIX;
        } else if (fixq == 2) {
            fix->q.fix = FT_2D_FIX;
        } else {
            fix->q.fix = FT_NO_FIX;
        }
        return 0;
    } else {
        return -1;
    }
}

canonical_original_code:
unsigned int parseGPSFixQual(unsigned char **buf, unsigned int *len, struct GPSFix_t *fix)
{
    unsigned int fixq;
    parseGPSu32(buf, len, &fixq, 0);
    if (fixq != -1u) {
        if (fixq == 3) {
            fix->q.fix = FT_3D_FIX;
        } else if (fixq == 2) {
            fix->q.fix = FT_2D_FIX;
        } else {
            fix->q.fix = FT_NO_FIX;
        }
        return 0;
    } else {
        return -1;
    }
}

variable_types:
fixq
unsigned int


parseGPSDate

original_code:
uint_t parseGPSDate(const uint8_t **buf, uint_t *len, GPSFix_t *fix)
{
    uint32_t d;
    uint_t res = parseGPSu32(buf, len, &d, 0);
    if (res) return res;
    fix->d.year = d % 100;
    d /= 100;
    fix->d.mon = d % 100;
    fix->d.day = d / 100;
    return 0;
}

canonical_original_code:
unsigned int parseGPSDate(unsigned char **buf, unsigned int *len, struct GPSFix_t *fix)
{
    unsigned int d;
    unsigned int res = parseGPSu32(buf, len, &d, 0);
    if (res) return res;
    fix->d.year = d % 100;
    d /= 100;
    fix->d.mon = d % 100;
    fix->d.day = d / 100;
    return 0;
}

variable_types:
d
unsigned int


parseGPSChar

decompiled_code:
__int64 __fastcall parseGPSChar(_QWORD *a1, _DWORD *a2)
{
unsigned int v2; // er12

v2 = parseGPSGetChar(a1, a2);
parseGPSGetChar(a1, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, _DWORD *a2)
{
unsigned int v2; // er12

v2 = func0(a1, a2);
func0(a1, a2);
return v2;
}

original_code:
uint8_t parseGPSChar(const uint8_t **buf, uint_t *len)
{
    uint8_t ch = parseGPSGetChar(buf, len);
    parseGPSGetChar(buf, len);
    return ch;
}

canonical_original_code:
unsigned char parseGPSChar(unsigned char **buf, unsigned int *len)
{
    unsigned char ch = parseGPSGetChar(buf, len);
    parseGPSGetChar(buf, len);
    return ch;
}


parseGPSPos

decompiled_code:
__int64 __fastcall parseGPSPos(_QWORD *a1, _DWORD *a2, __int64 a3)
{
unsigned int v4; // ebx
unsigned int v5; // eax
unsigned int v7[9]; // [rsp+Ch] [rbp-24h] BYREF

v4 = parseGPSu32(a1, a2, v7, (_WORD *)(a3 + 2));
if ( !v4 )
{
v5 = v7[0];
if ( v7[0] != -1 )
{
*(_BYTE *)(a3 + 1) = v7[0] % 0x64;
*(_BYTE *)a3 = v5 / 0x64;
if ( (parseGPSChar(a1, a2) & 0xFB) == 83 )
*(_WORD *)(a3 + 2) |= 0x8000u;
}
}
return v4;
}

original_code:
uint_t parseGPSPos(const uint8_t **buf, uint_t *len, GPSPos_t *pos)
{
    uint32_t p;
    uint_t res = parseGPSu32(buf, len, &p, &pos->mindec);
    if (res) return res;
    if (p != -1u) {
        pos->min = p % 100;
        pos->deg = p / 100;
        uint8_t ch = parseGPSChar(buf, len);
        if (ch == 'S' || ch == 'W') pos->mindec |= SOUTH_WEST;
    }
    return 0;
}

canonical_original_code:
unsigned int parseGPSPos(unsigned char **buf, unsigned int *len, struct GPSPos_t *pos)
{
    unsigned int p;
    unsigned int res = parseGPSu32(buf, len, &p, &pos->mindec);
    if (res) return res;
    if (p != -1u) {
        pos->min = p % 100;
        pos->deg = p / 100;
        unsigned char ch = parseGPSChar(buf, len);
        if (ch == 'S' || ch == 'W') pos->mindec |= SOUTH_WEST;
    }
    return 0;
}

variable_types: struct GPSPos_t { unsigned char deg; unsigned char min; unsigned short mindec; } *

variable_types:
p
unsigned int


parseGGA

decompiled_code:
__int64 __fastcall parseGGA(__int64 a1, int a2, _BYTE *a3)
{
__int64 result; // rax
char v5; // dl
int v6[3]; // [rsp+4h] [rbp-1Ch] BYREF
__int64 v7[2]; // [rsp+10h] [rbp-10h] BYREF

v6[0] = a2;
v7[0] = a1;
result = parseGPSTime(v7, v6, a3);
if ( !(_DWORD)result )
{
result = parseGPSPos(v7, v6, (__int64)(a3 + 6));
if ( !(_DWORD)result )
{
result = parseGPSPos(v7, v6, (__int64)(a3 + 10));
if ( !(_DWORD)result )
{
v5 = parseGPSChar(v7, v6);
result = 0xFFFFFFFFLL;
if ( v5 )
{
result = parseGPSSatCnt(v7, v6, (__int64)a3);
if ( !(_DWORD)result )
result = parseGPSDOP(v7, v6, (__int64)a3);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, _BYTE *a3)
{
__int64 result; // rax
char v5; // dl
int v6[3]; // [rsp+4h] [rbp-1Ch] BYREF
__int64 v7[2]; // [rsp+10h] [rbp-10h] BYREF

v6[0] = a2;
v7[0] = a1;
result = func2(v7, v6, a3);
if ( !(_DWORD)result )
{
result = func8(v7, v6, (__int64)(a3 + 6));
if ( !(_DWORD)result )
{
result = func8(v7, v6, (__int64)(a3 + 10));
if ( !(_DWORD)result )
{
v5 = func7(v7, v6);
result = 0xFFFFFFFFLL;
if ( v5 )
{
result = func3(v7, v6, (__int64)a3);
if ( !(_DWORD)result )
result = func4(v7, v6, (__int64)a3);
}
}
}
}
return result;
}

original_code:
uint_t parseGGA(const void *buf, uint_t len, GPSFix_t *fix)
{
    const uint8_t *p = (uint8_t *) buf;
    uint_t res;
    if ((res = parseGPSTime(&p, &len, fix))) return res;
    if ((res = parseGPSPos(&p, &len, &fix->lat))) return res;
    if ((res = parseGPSPos(&p, &len, &fix->lon))) return res;
    if (parseGPSChar(&p, &len) == 0) return -1;
    if ((res = parseGPSSatCnt(&p, &len, fix))) return res;
    if ((res = parseGPSDOP(&p, &len, fix))) return res;
    return 0;
}

canonical_original_code:
unsigned int parseGGA(void *buf, unsigned int len, struct GPSFix_t *fix)
{
    unsigned char *p = (uint8_t *) buf;
    unsigned int res;
    if ((res = parseGPSTime(&p, &len, fix))) return res;
    if ((res = parseGPSPos(&p, &len, &fix->lat))) return res;
    if ((res = parseGPSPos(&p, &len, &fix->lon))) return res;
    if (parseGPSChar(&p, &len) == 0) return -1;
    if ((res = parseGPSSatCnt(&p, &len, fix))) return res;
    if ((res = parseGPSDOP(&p, &len, fix))) return res;
    return 0;
}

variable_types:
buf
void *

variable_types:
len
unsigned int

variable_types:
p
unsigned char *


parseGSA

decompiled_code:
__int64 __fastcall parseGSA(__int64 a1, int a2, __int64 a3)
{
char v4; // dl
__int64 result; // rax
int v6[3]; // [rsp+4h] [rbp-1Ch] BYREF
__int64 v7[2]; // [rsp+10h] [rbp-10h] BYREF

v6[0] = a2;
v7[0] = a1;
v4 = parseGPSChar(v7, v6);
result = 0xFFFFFFFFLL;
if ( v4 )
result = parseGPSFixQual(v7, v6, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, __int64 a3)
{
char v4; // dl
__int64 result; // rax
int v6[3]; // [rsp+4h] [rbp-1Ch] BYREF
__int64 v7[2]; // [rsp+10h] [rbp-10h] BYREF

v6[0] = a2;
v7[0] = a1;
v4 = func7(v7, v6);
result = 0xFFFFFFFFLL;
if ( v4 )
result = func5(v7, v6, a3);
return result;
}

original_code:
uint_t parseGSA(const void *buf, uint_t len, GPSFix_t *fix)
{
    const uint8_t *p = (uint8_t *) buf;
    uint_t res;
    if (parseGPSChar(&p, &len) == 0) return -1;
    if ((res = parseGPSFixQual(&p, &len, fix))) return res;
    return 0;
}

canonical_original_code:
unsigned int parseGSA(void *buf, unsigned int len, struct GPSFix_t *fix)
{
    unsigned char *p = (uint8_t *) buf;
    unsigned int res;
    if (parseGPSChar(&p, &len) == 0) return -1;
    if ((res = parseGPSFixQual(&p, &len, fix))) return res;
    return 0;
}


parseRMC

decompiled_code:
__int64 __fastcall parseRMC(__int64 a1, int a2, _BYTE *a3)
{
__int64 result; // rax
char v5; // dl
int v6; // [rsp+4h] [rbp-1Ch] BYREF
int v7; // [rsp+Ch] [rbp-14h] BYREF
__int64 v8[2]; // [rsp+10h] [rbp-10h] BYREF

v6 = a2;
v8[0] = a1;
result = parseGPSTime(v8, &v6, a3);
if ( !(_DWORD)result )
{
v5 = parseGPSChar(v8, &v6);
result = 0xFFFFFFFFLL;
if ( v5 == 65 )
{
result = parseGPSPos(v8, &v6, (__int64)(a3 + 6));
if ( !(_DWORD)result )
{
result = parseGPSPos(v8, &v6, (__int64)(a3 + 10));
if ( !(_DWORD)result )
{
result = parseGPSu32(v8, &v6, &v7, 0LL);
if ( !(_DWORD)result )
{
result = parseGPSu32(v8, &v6, &v7, 0LL);
if ( !(_DWORD)result )
result = parseGPSDate(v8, &v6, a3);
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, _BYTE *a3)
{
__int64 result; // rax
char v5; // dl
int v6; // [rsp+4h] [rbp-1Ch] BYREF
int v7; // [rsp+Ch] [rbp-14h] BYREF
__int64 v8[2]; // [rsp+10h] [rbp-10h] BYREF

v6 = a2;
v8[0] = a1;
result = func2(v8, &v6, a3);
if ( !(_DWORD)result )
{
v5 = func7(v8, &v6);
result = 0xFFFFFFFFLL;
if ( v5 == 65 )
{
result = func8(v8, &v6, (__int64)(a3 + 6));
if ( !(_DWORD)result )
{
result = func8(v8, &v6, (__int64)(a3 + 10));
if ( !(_DWORD)result )
{
result = func1(v8, &v6, &v7, 0LL);
if ( !(_DWORD)result )
{
result = func1(v8, &v6, &v7, 0LL);
if ( !(_DWORD)result )
result = func6(v8, &v6, a3);
}
}
}
}
}
return result;
}

original_code:
uint_t parseRMC(const void *buf, uint_t len, GPSFix_t *fix) {
    const uint8_t *p = (uint8_t *) buf;
    uint_t res;
    if ((res = parseGPSTime(&p, &len, fix))) return res;
    if (parseGPSChar(&p, &len) != 'A') return -1;
    if ((res = parseGPSPos(&p, &len, &fix->lat))) return res;
    if ((res = parseGPSPos(&p, &len, &fix->lon))) return res;
    uint32_t dummy;
    if ((res = parseGPSu32(&p, &len, &dummy, 0))) return res;
    if ((res = parseGPSu32(&p, &len, &dummy, 0))) return res;
    if ((res = parseGPSDate(&p, &len, fix))) return res;
    return 0;
}

canonical_original_code:
unsigned int parseRMC(void *buf, unsigned int len, struct GPSFix_t *fix) {
    unsigned char *p = (uint8_t *) buf;
    unsigned int res;
    if ((res = parseGPSTime(&p, &len, fix))) return res;
    if (parseGPSChar(&p, &len) != 'A') return -1;
    if ((res = parseGPSPos(&p, &len, &fix->lat))) return res;
    if ((res = parseGPSPos(&p, &len, &fix->lon))) return res;
    unsigned int dummy;
    if ((res = parseGPSu32(&p, &len, &dummy, 0))) return res;
    if ((res = parseGPSu32(&p, &len, &dummy, 0))) return res;
    if ((res = parseGPSDate(&p, &len, fix))) return res;
    return 0;
}

variable_types:
dummy
unsigned int


doMsleep

decompiled_code:
int __fastcall doMsleep(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

original_code:
extern inline void doMsleep(uint16_t milliseconds) {
    usleep(milliseconds * 1000);
}

canonical_original_code:
extern inline void doMsleep(unsigned short milliseconds) {
    usleep(milliseconds * 1000);
}

variable_types:
milliseconds
unsigned short


adcInit

decompiled_code:
__int64 adcInit()
{
return hplAdcInit();
}

canonical_decompiled_code:
__int64 func1()
{
return hplAdcInit();
}

original_code:
void adcInit(void)
{
    hplAdcInit();
}

canonical_original_code:
void adcInit()
{
    hplAdcInit();
}


adcSetChannel

decompiled_code:
__int64 __fastcall adcSetChannel(unsigned __int8 a1)
{
return hplAdcSetChannel(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
return hplAdcSetChannel(a1);
}

original_code:
void adcSetChannel(uint8_t ch)
{
    _Bool wasOn = 1;
    if (wasOn) ;
    hplAdcSetChannel(ch);
    if (wasOn) ;
}

canonical_original_code:
void adcSetChannel(unsigned char ch)
{
    _Bool wasOn = 1;
    if (wasOn) ;
    hplAdcSetChannel(ch);
    if (wasOn) ;
}

variable_types:
ch
unsigned char


adcRead

decompiled_code:
__int64 __fastcall adcRead(unsigned __int8 a1)
{
if ( (unsigned __int8)hplAdcGetChannel() != a1 )
hplAdcSetChannel(a1);
return hplAdcGetVal();
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1)
{
if ( (unsigned __int8)hplAdcGetChannel() != a1 )
hplAdcSetChannel(a1);
return hplAdcGetVal();
}

original_code:
uint16_t adcRead(uint8_t ch)
{
    uint16_t retval;
    _Bool wasOn = 1;
    if (hplAdcGetChannel() != ch) {
        if (wasOn) ;
        hplAdcSetChannel(ch);
        if (wasOn) ;
    }
    if (!wasOn) {
        ;
    }
    ;
    while ((0)) {}
    retval = hplAdcGetVal();
    if (!wasOn) {
        ;
    }
    return retval;
}

canonical_original_code:
unsigned short adcRead(unsigned char ch)
{
    unsigned short retval;
    _Bool wasOn = 1;
    if (hplAdcGetChannel() != ch) {
        if (wasOn) ;
        hplAdcSetChannel(ch);
        if (wasOn) ;
    }
    if (!wasOn) {
        ;
    }
    ;
    while ((0)) {}
    retval = hplAdcGetVal();
    if (!wasOn) {
        ;
    }
    return retval;
}

variable_types:
retval
unsigned short


rewind

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

*(_DWORD *)(a1 + 12) = 0;
result = *(unsigned __int16 *)(a1 + 2);
*(_WORD *)(a1 + 4) = result;
return result;
}

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

*(_DWORD *)(a1 + 12) = 0;
result = *(unsigned __int16 *)(a1 + 2);
*(_WORD *)(a1 + 4) = result;
return result;
}

original_code:
static inline void rewind(FILE *fp)
{
    fp->position = 0;
    fp->currentCluster = fp->firstCluster;
}

canonical_original_code:
static inline void rewind(struct FILE_s *fp)
{
    fp->position = 0;
    fp->currentCluster = fp->firstCluster;
}

variable_types: struct FILE_s { _Bool isOpened; unsigned short firstCluster; unsigned short currentCluster; unsigned short directoryEntry; unsigned int fileSize; unsigned int position; unsigned short flags; unsigned char state; _Bool dirEntryDirty; } *


redLedOn

decompiled_code:
__int64 redLedOn()
{
return pinSetPc(255LL, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
return pinSetPc(255LL, 0LL);
}

original_code: static inline void redLedOn(void) { led0On(); }

canonical_original_code: static inline void redLedOn() { led0On(); }


redLedOff

decompiled_code:
__int64 redLedOff()
{
return pinClearPc(255LL, 0LL);
}

canonical_decompiled_code:
__int64 func2()
{
return pinClearPc(255LL, 0LL);
}

original_code: static inline void redLedOff(void) { led0Off(); }

canonical_original_code: static inline void redLedOff() { led0Off(); }


doMsleep

canonical_decompiled_code:
int __fastcall func6(unsigned __int16 a1)
{
return usleep(1000 * a1);
}


flashFileClose

decompiled_code:
void flashFileClose(void)
{
if ( flashFile )
{
fclose(flashFile);
flashFile = 0LL;
}
}

canonical_decompiled_code:
void func0(void)
{
if ( flashFile )
{
fclose(flashFile);
flashFile = 0LL;
}
}

original_code:
static void flashFileClose(void)
{
    if (flashFile) {
        fclose(flashFile);
        flashFile = ((void *)0);
    }
}

canonical_original_code:
static void flashFileClose()
{
    if (flashFile) {
        fclose(flashFile);
        flashFile = ((void *)0);
    }
}


serialPrintV

decompiled_code:
__int64 serialPrintV()
{
return serialPrint();
}

canonical_decompiled_code:
__int64 func1()
{
return serialPrint();
}

original_code:
static inline void serialPrintV(const char* str, ...) {
    serialPrint(str);
}

canonical_original_code:
static inline void serialPrintV(char *str, ...) {
    serialPrint(str);
}

variable_types:
str
char *


doMsleep

canonical_decompiled_code:
int __fastcall func2(unsigned __int16 a1)
{
return usleep(1000 * a1);
}


extFlashSleep

decompiled_code:
int extFlashSleep()
{
int result; // eax

if ( flashFile )
{
result = fclose(flashFile);
flashFile = 0LL;
}
return result;
}

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

if ( flashFile )
{
result = fclose(flashFile);
flashFile = 0LL;
}
return result;
}

original_code:
void extFlashSleep(void)
{
    if (flashFile) {
        fclose(flashFile);
        flashFile = ((void *)0);
    }
}

canonical_original_code:
void extFlashSleep()
{
    if (flashFile) {
        fclose(flashFile);
        flashFile = ((void *)0);
    }
}


extFlashWake

decompiled_code:
void extFlashWake()
{
if ( !flashFile )
flashFile = fopen("extflash.dat", "r+");
}

canonical_decompiled_code:
void func4()
{
if ( !flashFile )
flashFile = fopen("extflash.dat", "r+");
}

original_code:
void extFlashWake(void)
{
    if (!flashFile) {
        flashFile = fopen("extflash.dat", "r+");
    }
}

canonical_original_code:
void extFlashWake()
{
    if (!flashFile) {
        flashFile = fopen("extflash.dat", "r+");
    }
}


extFlashRead

decompiled_code:
void __fastcall extFlashRead(__int64 off, void *ptr, unsigned __int16 a3)
{
if ( flashFile )
{
if ( (unsigned int)off + a3 > 0x200000 )
{
serialPrintV("extFlashRead: address out of bounds!\n", ptr);
}
else if ( fseek(flashFile, (unsigned int)off, 0) )
{
perror("fseek");
}
else if ( a3 != fread(ptr, 1uLL, a3, flashFile) )
{
perror("fread");
}
}
else
{
serialPrintV("extFlashRead: flash not opened\n", ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 off, void *ptr, unsigned __int16 a3)
{
if ( flashFile )
{
if ( (unsigned int)off + a3 > 0x200000 )
{
func1("extFlashRead: address out of bounds!\n", ptr);
}
else if ( fseek(flashFile, (unsigned int)off, 0) )
{
perror("fseek");
}
else if ( a3 != fread(ptr, 1uLL, a3, flashFile) )
{
perror("fread");
}
}
else
{
func1("extFlashRead: flash not opened\n", ptr);
}
}

original_code:
void extFlashRead(uint32_t addr, uint8_t *buf, uint16_t len)
{
    if (!flashFile) {
        if (1 == 1) { serialPrintV("extFlashRead: flash not opened\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashRead: flash not opened\n"); serialPrint(_print_buf); }; };
        return;
    }
    if (addr + len > ((uint32_t)0x10000 * 32)) {
        if (1 == 1) { serialPrintV("extFlashRead: address out of bounds!\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashRead: address out of bounds!\n"); serialPrint(_print_buf); }; };
        return;
    }
    if (fseek(flashFile, addr, 0) != 0) {
        perror("fseek");
        return;
    }
    if (fread(buf, 1, len, flashFile) != len) {
        perror("fread");
    }
}

canonical_original_code:
void extFlashRead(unsigned int addr, unsigned char *buf, unsigned short len)
{
    if (!flashFile) {
        if (1 == 1) { serialPrintV("extFlashRead: flash not opened\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashRead: flash not opened\n"); serialPrint(_print_buf); }; };
        return;
    }
    if (addr + len > ((unsigned int)0x10000 * 32)) {
        if (1 == 1) { serialPrintV("extFlashRead: address out of bounds!\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashRead: address out of bounds!\n"); serialPrint(_print_buf); }; };
        return;
    }
    if (fseek(flashFile, addr, 0) != 0) {
        perror("fseek");
        return;
    }
    if (fread(buf, 1, len, flashFile) != len) {
        perror("fread");
    }
}

variable_types:
addr
unsigned int

variable_types:
buf
unsigned char *

variable_types:
len
unsigned short


extFlashWrite

decompiled_code:
void __fastcall extFlashWrite(__int64 off, const void *a2, unsigned __int16 a3)
{
FILE *v3; // r13
int v5; // er15
size_t v6; // r14
char *v7; // r12
_BYTE *v8; // rax
char *v9; // rbx

v3 = flashFile;
if ( !flashFile )
{
serialPrintV("extFlashWrite: flash not opened\n", a2);
return;
}
v5 = a3;
if ( (unsigned int)off + a3 > 0x200000 )
{
serialPrintV("extFlashWrite: address out of bounds!\n", a2);
return;
}
v6 = a3;
v7 = (char *)malloc(a3);
if ( fseek(v3, (unsigned int)off, 0) )
goto LABEL_18;
if ( v6 != fread(v7, 1uLL, v6, flashFile) )
perror("fread");
if ( !v5 )
{
LABEL_10:
free(v7);
if ( !fseek(flashFile, (unsigned int)off, 0) )
{
if ( v6 != fwrite(a2, 1uLL, v6, flashFile) )
perror("fwrite");
return;
}
LABEL_18:
perror("fseek");
return;
}
v8 = v7;
v9 = &v7[a3];
while ( *v8 == 0xFF )
{
if ( ++v8 == v9 )
goto LABEL_10;
}
serialPrintV("extFlashWrite: attempt to write in a sector that was not erased!\n", 1LL);
}

canonical_decompiled_code:
void __fastcall func6(__int64 off, const void *a2, unsigned __int16 a3)
{
FILE *v3; // r13
int v5; // er15
size_t v6; // r14
char *v7; // r12
_BYTE *v8; // rax
char *v9; // rbx

v3 = flashFile;
if ( !flashFile )
{
func1("extFlashWrite: flash not opened\n", a2);
return;
}
v5 = a3;
if ( (unsigned int)off + a3 > 0x200000 )
{
func1("extFlashWrite: address out of bounds!\n", a2);
return;
}
v6 = a3;
v7 = (char *)malloc(a3);
if ( fseek(v3, (unsigned int)off, 0) )
goto LABEL_18;
if ( v6 != fread(v7, 1uLL, v6, flashFile) )
perror("fread");
if ( !v5 )
{
LABEL_10:
free(v7);
if ( !fseek(flashFile, (unsigned int)off, 0) )
{
if ( v6 != fwrite(a2, 1uLL, v6, flashFile) )
perror("fwrite");
return;
}
LABEL_18:
perror("fseek");
return;
}
v8 = v7;
v9 = &v7[a3];
while ( *v8 == 0xFF )
{
if ( ++v8 == v9 )
goto LABEL_10;
}
func1("extFlashWrite: attempt to write in a sector that was not erased!\n", 1LL);
}

original_code:
void extFlashWrite(uint32_t addr, const uint8_t *buf, uint16_t len)
{
    if (!flashFile) {
        if (1 == 1) { serialPrintV("extFlashWrite: flash not opened\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashWrite: flash not opened\n"); serialPrint(_print_buf); }; };
        return;
    }
    if (addr + len > ((uint32_t)0x10000 * 32)) {
        if (1 == 1) { serialPrintV("extFlashWrite: address out of bounds!\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashWrite: address out of bounds!\n"); serialPrint(_print_buf); }; };
        return;
    }
    uint8_t *oldContents = malloc(len);
    if (fseek(flashFile, addr, 0) != 0) {
        perror("fseek");
        return;
    }
    if (fread(oldContents, 1, len, flashFile) != len) {
        perror("fread");
    }
    uint32_t i;
    for (i = 0; i < len; ++i) {
        if (oldContents[i] != 0xff) {
            if (1 == 1) { serialPrintV("extFlashWrite: attempt to write in a sector that was not erased!\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashWrite: attempt to write in a sector that was not erased!\n"); serialPrint(_print_buf); }; };
            return;
        }
    }
    free(oldContents);
    if (fseek(flashFile, addr, 0) != 0) {
        perror("fseek");
        return;
    }
    if (fwrite(buf, 1, len, flashFile) != len) {
        perror("fwrite");
    }
}

canonical_original_code:
void extFlashWrite(unsigned int addr, unsigned char *buf, unsigned short len)
{
    if (!flashFile) {
        if (1 == 1) { serialPrintV("extFlashWrite: flash not opened\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashWrite: flash not opened\n"); serialPrint(_print_buf); }; };
        return;
    }
    if (addr + len > ((unsigned int)0x10000 * 32)) {
        if (1 == 1) { serialPrintV("extFlashWrite: address out of bounds!\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashWrite: address out of bounds!\n"); serialPrint(_print_buf); }; };
        return;
    }
    unsigned char *oldContents = malloc(len);
    if (fseek(flashFile, addr, 0) != 0) {
        perror("fseek");
        return;
    }
    if (fread(oldContents, 1, len, flashFile) != len) {
        perror("fread");
    }
    unsigned int i;
    for (i = 0; i < len; ++i) {
        if (oldContents[i] != 0xff) {
            if (1 == 1) { serialPrintV("extFlashWrite: attempt to write in a sector that was not erased!\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashWrite: attempt to write in a sector that was not erased!\n"); serialPrint(_print_buf); }; };
            return;
        }
    }
    free(oldContents);
    if (fseek(flashFile, addr, 0) != 0) {
        perror("fseek");
        return;
    }
    if (fwrite(buf, 1, len, flashFile) != len) {
        perror("fwrite");
    }
}

variable_types:
oldContents
unsigned char *

variable_types:
i
unsigned int


extFlashBulkErase

decompiled_code:
size_t __fastcall extFlashBulkErase(__int64 a1, __int64 a2)
{
int v2; // ebx
size_t result; // rax
_BYTE v4[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( !flashFile )
return serialPrintV("extFlashBulkErase: flash not opened\n", a2);
memset(v4, 0xFFu, 0x400uLL);
rewind(flashFile);
v2 = 2048;
do
{
result = fwrite(v4, 1uLL, 0x400uLL, flashFile);
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 a1, __int64 a2)
{
int v2; // ebx
size_t result; // rax
_BYTE v4[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( !flashFile )
return func1("extFlashBulkErase: flash not opened\n", a2);
memset(v4, 0xFFu, 0x400uLL);
rewind(flashFile);
v2 = 2048;
do
{
result = fwrite(v4, 1uLL, 0x400uLL, flashFile);
--v2;
}
while ( v2 );
return result;
}

original_code:
void extFlashBulkErase(void)
{
    if (!flashFile) {
        if (1 == 1) { serialPrintV("extFlashBulkErase: flash not opened\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashBulkErase: flash not opened\n"); serialPrint(_print_buf); }; };
        return;
    }
    uint8_t block[1024];
    memset(block, 0xff, sizeof(block));
    rewind(flashFile);
    uint32_t i;
    for (i = 0; i < ((uint32_t)0x10000 * 32) / sizeof(block); i++) {
        fwrite(block, 1, sizeof(block), flashFile);
    }
}

canonical_original_code:
void extFlashBulkErase()
{
    if (!flashFile) {
        if (1 == 1) { serialPrintV("extFlashBulkErase: flash not opened\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashBulkErase: flash not opened\n"); serialPrint(_print_buf); }; };
        return;
    }
    unsigned char block[1024];
    memset(block, 0xff, sizeof(block));
    rewind(flashFile);
    unsigned int i;
    for (i = 0; i < ((unsigned int)0x10000 * 32) / sizeof(block); i++) {
        fwrite(block, 1, sizeof(block), flashFile);
    }
}

variable_types:
block
unsigned char [1024]


extFlashInit

decompiled_code:
int extFlashInit()
{
int result; // eax
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

atexit(flashFileClose);
result = stat("extflash.dat", &v1);
if ( result || v1.st_size != 0x200000 )
{
flashFile = fopen("extflash.dat", "w+");
extFlashBulkErase((__int64)"extflash.dat", (__int64)"w+");
result = fclose(flashFile);
flashFile = 0LL;
}
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

atexit(flashFileClose);
result = stat("extflash.dat", &v1);
if ( result || v1.st_size != 0x200000 )
{
flashFile = fopen("extflash.dat", "w+");
func7((__int64)"extflash.dat", (__int64)"w+");
result = fclose(flashFile);
flashFile = 0LL;
}
return result;
}

original_code:
void extFlashInit(void)
{
    static _Bool initCalled;
    if (initCalled) {
        if (1 == 1) { serialPrintV("extFlashInit: already called\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashInit: already called\n"); serialPrint(_print_buf); }; };
        return;
    }
    atexit(flashFileClose);
    struct stat st;
    if (stat("extflash.dat", &st) == 0) {
        if (st.st_size == ((uint32_t)0x10000 * 32)) return;
    }
    flashFile = fopen("extflash.dat", "w+");
    extFlashBulkErase();
    fclose(flashFile);
    flashFile = ((void *)0);
}

canonical_original_code:
void extFlashInit()
{
    static _Bool initCalled;
    if (initCalled) {
        if (1 == 1) { serialPrintV("extFlashInit: already called\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashInit: already called\n"); serialPrint(_print_buf); }; };
        return;
    }
    atexit(flashFileClose);
    struct stat st;
    if (stat("extflash.dat", &st) == 0) {
        if (st.st_size == ((unsigned int)0x10000 * 32)) return;
    }
    flashFile = fopen("extflash.dat", "w+");
    extFlashBulkErase();
    fclose(flashFile);
    flashFile = ((void *)0);
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


extFlashEraseSector

decompiled_code:
void __fastcall extFlashEraseSector(unsigned int a1, __int64 a2)
{
int v2; // ebx
_BYTE v3[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( flashFile )
{
LOWORD(a1) = 0;
if ( a1 > 0x1FFFFF )
{
serialPrintV("extFlashEraseSector: address out of bounds!\n", a2);
}
else if ( fseek(flashFile, a1, 0) )
{
perror("fseek");
}
else
{
memset(v3, 0xFFu, 0x400uLL);
v2 = 64;
do
{
fwrite(v3, 1uLL, 0x400uLL, flashFile);
--v2;
}
while ( v2 );
}
}
else
{
serialPrintV("extFlashEraseSector: flash not opened\n", a2);
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1, __int64 a2)
{
int v2; // ebx
_BYTE v3[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( flashFile )
{
LOWORD(a1) = 0;
if ( a1 > 0x1FFFFF )
{
func1("extFlashEraseSector: address out of bounds!\n", a2);
}
else if ( fseek(flashFile, a1, 0) )
{
perror("fseek");
}
else
{
memset(v3, 0xFFu, 0x400uLL);
v2 = 64;
do
{
fwrite(v3, 1uLL, 0x400uLL, flashFile);
--v2;
}
while ( v2 );
}
}
else
{
func1("extFlashEraseSector: flash not opened\n", a2);
}
}

original_code:
void extFlashEraseSector(uint32_t addr)
{
    if (!flashFile) {
        if (1 == 1) { serialPrintV("extFlashEraseSector: flash not opened\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashEraseSector: flash not opened\n"); serialPrint(_print_buf); }; };
        return;
    }
    addr = ((uint32_t)(addr) & ~(0x10000 - 1));
    if (addr >= ((uint32_t)0x10000 * 32)) {
        if (1 == 1) { serialPrintV("extFlashEraseSector: address out of bounds!\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashEraseSector: address out of bounds!\n"); serialPrint(_print_buf); }; };
        return;
    }
    if (fseek(flashFile, addr, 0) != 0) {
        perror("fseek");
        return;
    }
    uint8_t block[1024];
    memset(block, 0xff, sizeof(block));
    uint32_t i;
    for (i = 0; i < 0x10000 / sizeof(block); i++) {
        fwrite(block, 1, sizeof(block), flashFile);
    }
}

canonical_original_code:
void extFlashEraseSector(unsigned int addr)
{
    if (!flashFile) {
        if (1 == 1) { serialPrintV("extFlashEraseSector: flash not opened\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashEraseSector: flash not opened\n"); serialPrint(_print_buf); }; };
        return;
    }
    addr = ((unsigned int)(addr) & ~(0x10000 - 1));
    if (addr >= ((unsigned int)0x10000 * 32)) {
        if (1 == 1) { serialPrintV("extFlashEraseSector: address out of bounds!\n"); } else { if (_print_buf) { debugPrintfFormat("extFlashEraseSector: address out of bounds!\n"); serialPrint(_print_buf); }; };
        return;
    }
    if (fseek(flashFile, addr, 0) != 0) {
        perror("fseek");
        return;
    }
    unsigned char block[1024];
    memset(block, 0xff, sizeof(block));
    unsigned int i;
    for (i = 0; i < 0x10000 / sizeof(block); i++) {
        fwrite(block, 1, sizeof(block), flashFile);
    }
}


doMsleep

canonical_decompiled_code:
int __fastcall func0(unsigned __int16 a1)
{
return usleep(1000 * a1);
}


serialSendString

decompiled_code:
__int64 __fastcall serialSendString(unsigned __int8 a1, _BYTE *a2)
{
_BYTE *v2; // rbx
unsigned __int8 v3; // si
__int64 result; // rax

v2 = a2;
v3 = *a2;
if ( v3 )
{
do
{
result = serialSendByte(a1, v3);
if ( *v2 == 10 )
result = serialSendByte(a1, 13LL);
v3 = *++v2;
}
while ( *v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, _BYTE *a2)
{
_BYTE *v2; // rbx
unsigned __int8 v3; // si
__int64 result; // rax

v2 = a2;
v3 = *a2;
if ( v3 )
{
do
{
result = serialSendByte(a1, v3);
if ( *v2 == 10 )
result = serialSendByte(a1, 13LL);
v3 = *++v2;
}
while ( *v2 );
}
return result;
}

original_code:
void serialSendString(uint8_t id, const char *s) {
    for (; *s; ++s) {
        serialSendByte(id, *s);
        if (*s == '\n') {
            serialSendByte(id, '\r');
        }
    }
}

canonical_original_code:
void serialSendString(unsigned char id, char *s) {
    for (; *s; ++s) {
        serialSendByte(id, *s);
        if (*s == '\n') {
            serialSendByte(id, '\r');
        }
    }
}

variable_types:
id
unsigned char

variable_types:
s
char *


serialSendData

decompiled_code:
__int64 __fastcall serialSendData(unsigned __int8 a1, unsigned __int8 *a2, unsigned __int16 a3)
{
unsigned __int8 *v3; // rbp
unsigned __int8 *v4; // rbx
__int64 result; // rax

v3 = &a2[a3];
if ( a2 < v3 )
{
v4 = a2;
do
result = serialSendByte(a1, *v4++);
while ( v4 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, unsigned __int8 *a2, unsigned __int16 a3)
{
unsigned __int8 *v3; // rbp
unsigned __int8 *v4; // rbx
__int64 result; // rax

v3 = &a2[a3];
if ( a2 < v3 )
{
v4 = a2;
do
result = serialSendByte(a1, *v4++);
while ( v4 != v3 );
}
return result;
}

original_code:
void serialSendData(uint8_t id, const uint8_t *data, uint16_t len) {
    const uint8_t *p;
    for (p = data; p < data + len; ++p) {
        serialSendByte(id, *p);
    }
}

canonical_original_code:
void serialSendData(unsigned char id, unsigned char *data, unsigned short len) {
    unsigned char *p;
    for (p = data; p < data + len; ++p) {
        serialSendByte(id, *p);
    }
}

variable_types:
data
unsigned char *


serialSetReceiveHandle

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

result = 0xFFFFFFFFLL;
if ( !a1 )
{
serialRecvCb = a2;
result = 0LL;
if ( a2 )
{
serialEnableRX(0LL);
result = 0LL;
}
}
return result;
}

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

result = 0xFFFFFFFFLL;
if ( !a1 )
{
serialRecvCb = a2;
result = 0LL;
if ( a2 )
{
serialEnableRX(0LL);
result = 0LL;
}
}
return result;
}

original_code:
uint_t serialSetReceiveHandle(uint8_t id, SerialCallback_t functionHandle) {
    if (id >= 1) return -1;
    serialRecvCb[id] = functionHandle;
    if (functionHandle) {
        serialEnableRX(id);
    }
    return 0;
}

canonical_original_code:
unsigned int serialSetReceiveHandle(unsigned char id, void (*functionHandle)(unsigned char)) {
    if (id >= 1) return -1;
    serialRecvCb[id] = functionHandle;
    if (functionHandle) {
        serialEnableRX(id);
    }
    return 0;
}

variable_types:
functionHandle
void (*)(unsigned char)


doMsleep

decompiled_code:
int __fastcall doMsleep(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

original_code:
extern inline void doMsleep(uint16_t milliseconds) {
    usleep(milliseconds * 1000);
}

canonical_original_code:
extern inline void doMsleep(unsigned short milliseconds) {
    usleep(milliseconds * 1000);
}


sdcardInit

decompiled_code:
__int64 sdcardInit()
{
int v0; // ebx

serialPrintV("Opening SDCARD image `sdcard.dat'...\n");
v0 = open("sdcard.dat", 0);
if ( v0 < 0 )
sdcardBulkErase();
close(v0);
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // ebx

func0("Opening SDCARD image `sdcard.dat'...\n");
v0 = open("sdcard.dat", 0);
if ( v0 < 0 )
func4();
close(v0);
return 1LL;
}

original_code:
_Bool sdcardInit(void)
{
    if (1 == 1) { serialPrintV("Opening SDCARD image `" "sdcard.dat" "'...\n"); } else { if (_print_buf) { debugPrintfFormat("Opening SDCARD image `" "sdcard.dat" "'...\n"); serialPrint(_print_buf); }; };
    int data = open("sdcard.dat", 00);
    if (data < 0) {
        sdcardBulkErase();
    }
    close(data);
    return 1;
}

canonical_original_code:
_Bool sdcardInit()
{
    if (1 == 1) { serialPrintV("Opening SDCARD image `" "sdcard.dat" "'...\n"); } else { if (_print_buf) { debugPrintfFormat("Opening SDCARD image `" "sdcard.dat" "'...\n"); serialPrint(_print_buf); }; };
    int data = open("sdcard.dat", 00);
    if (data < 0) {
        sdcardBulkErase();
    }
    close(data);
    return 1;
}

variable_types: data int


sdcardEraseSector

decompiled_code:
int __fastcall sdcardEraseSector(__off_t offset)
{
int result; // eax
int v2; // ebx

result = open("sdcard.dat", 1);
if ( result >= 0 )
{
v2 = result;
lseek(result, (unsigned int)offset, 0);
result = write(v2, &zeroSector, 0x200uLL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__off_t offset)
{
int result; // eax
int v2; // ebx

result = open("sdcard.dat", 1);
if ( result >= 0 )
{
v2 = result;
lseek(result, (unsigned int)offset, 0);
result = write(v2, &zeroSector, 0x200uLL);
}
return result;
}

original_code:
void sdcardEraseSector(uint32_t address)
{
    int data = open("sdcard.dat", 01);
    if (data < 0) return;
    lseek(data, address, 0);
    int r = write(data, zeroSector, sizeof(zeroSector));
    (void) r;
}

canonical_original_code:
void sdcardEraseSector(unsigned int address)
{
    int data = open("sdcard.dat", 01);
    if (data < 0) return;
    lseek(data, address, 0);
    int r = write(data, zeroSector, sizeof(zeroSector));
    (void) r;
}

variable_types:
address
unsigned int

variable_types: r int


sdcardFlush

decompiled_code:
void sdcardFlush()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void sdcardFlush(void)
{
}

canonical_original_code:
void sdcardFlush()
{
}


sdcardGetSize

decompiled_code:
__int64 sdcardGetSize()
{
return 0x8000LL;
}

canonical_decompiled_code:
__int64 func10()
{
return 0x8000LL;
}

original_code:
uint32_t sdcardGetSize(void)
{
    return 32768;
}

canonical_original_code:
unsigned int sdcardGetSize()
{
    return 32768;
}


radioOff

decompiled_code:
__int64 radioOff()
{
return pcRadioOff();
}

canonical_decompiled_code:
__int64 func3()
{
return pcRadioOff();
}

original_code:
static inline void radioOff(void) {
    pcRadioOff();
}

canonical_original_code:
static inline void radioOff() {
    pcRadioOff();
}


doMsleep

canonical_decompiled_code:
int __fastcall func4(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

variable_types:
milliseconds
unsigned short


readExactly

decompiled_code:
__int64 __fastcall readExactly(unsigned int a1, void *a2, unsigned __int16 a3)
{
unsigned int v3; // ebp
unsigned int v5; // eax
int *v6; // rax
char *v7; // rax

v3 = 0;
if ( a3 )
{
v5 = read(a1, a2, a3);
v3 = v5;
if ( (_WORD)v5 )
{
if ( (v5 & 0x8000u) != 0 && print_buf )
{
v6 = _errno_location();
v7 = strerror(*v6);
debugPrintfFormat("socket %i reading error: %s\n", a1, v7);
serialPrint(print_buf);
}
}
else
{
v3 = -1;
if ( print_buf )
{
debugPrintfFormat("socket %i disconnected\n", a1);
serialPrint(print_buf);
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, void *a2, unsigned __int16 a3)
{
unsigned int v3; // ebp
unsigned int v5; // eax
int *v6; // rax
char *v7; // rax

v3 = 0;
if ( a3 )
{
v5 = read(a1, a2, a3);
v3 = v5;
if ( (_WORD)v5 )
{
if ( (v5 & 0x8000u) != 0 && print_buf )
{
v6 = _errno_location();
v7 = strerror(*v6);
debugPrintfFormat("socket %i reading error: %s\n", a1, v7);
serialPrint(print_buf);
}
}
else
{
v3 = -1;
if ( print_buf )
{
debugPrintfFormat("socket %i disconnected\n", a1);
serialPrint(print_buf);
}
}
}
return v3;
}

original_code:
int16_t readExactly(int sock, void *buf, uint16_t len) {
    if (len == 0) return 0;
    int16_t l = read(sock, buf, len);
    if (l == 0) {
        if (2 == 1) { serialPrintV("socket %i disconnected\n", sock); } else { if (_print_buf) { debugPrintfFormat("socket %i disconnected\n", sock); serialPrint(_print_buf); }; };
        return -1;
    }
    if (l < 0) {
        if (3 == 1) { serialPrintV("socket %i reading error: %s\n", sock, strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("socket %i reading error: %s\n", sock, strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
    }
    return l;
}

canonical_original_code:
short readExactly(int sock, void *buf, unsigned short len) {
    if (len == 0) return 0;
    short l = read(sock, buf, len);
    if (l == 0) {
        if (2 == 1) { serialPrintV("socket %i disconnected\n", sock); } else { if (_print_buf) { debugPrintfFormat("socket %i disconnected\n", sock); serialPrint(_print_buf); }; };
        return -1;
    }
    if (l < 0) {
        if (3 == 1) { serialPrintV("socket %i reading error: %s\n", sock, strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("socket %i reading error: %s\n", sock, strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
    }
    return l;
}

variable_types: sock int

variable_types:
buf
void *

variable_types: l short

return_type: short


pcRadioRecvPack

decompiled_code:
__int64 __fastcall pcRadioRecvPack(unsigned int a1, _WORD *a2)
{
__int64 result; // rax

if ( (unsigned __int16)readExactly(a1, a2, 2u) != 2 )
return 0xFFFFFFFFLL;
result = readExactly(a1, a2 + 1, *a2);
if ( (__int16)result > 0 )
result = (unsigned int)(result + 2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, _WORD *a2)
{
__int64 result; // rax

if ( (unsigned __int16)func5(a1, a2, 2u) != 2 )
return 0xFFFFFFFFLL;
result = func5(a1, a2 + 1, *a2);
if ( (__int16)result > 0 )
result = (unsigned int)(result + 2);
return result;
}

original_code:
int16_t pcRadioRecvPack(int sock, void *buf, uint16_t bufLen) {
    if (readExactly(sock, buf, sizeof(PcRadioPackSize_t))
            != sizeof(PcRadioPackSize_t)) return -1;
    PcRadioPackSize_t len = *((PcRadioPackSize_t *) buf);
    int16_t r = readExactly(sock, buf + sizeof(PcRadioPackSize_t), len);
    return r > 0 ? r + sizeof(PcRadioPackSize_t) : r;
}

canonical_original_code:
short pcRadioRecvPack(int sock, void *buf, unsigned short bufLen) {
    if (readExactly(sock, buf, sizeof(PcRadioPackSize_t))
            != sizeof(PcRadioPackSize_t)) return -1;
    unsigned short len = *((PcRadioPackSize_t *) buf);
    short r = readExactly(sock, buf + sizeof(PcRadioPackSize_t), len);
    return r > 0 ? r + sizeof(PcRadioPackSize_t) : r;
}

variable_types:
bufLen
unsigned short

variable_types: r short


pcRadioSend

decompiled_code:
__int64 __fastcall pcRadioSend(unsigned int a1, const void *a2, unsigned __int16 a3)
{
unsigned int v3; // ebp
unsigned int v5; // eax
int *v6; // rax
char *v7; // rax

v3 = 0;
if ( a3 )
{
v5 = write(a1, a2, a3);
v3 = v5;
if ( (_WORD)v5 )
{
if ( (v5 & 0x8000u) != 0 && print_buf )
{
v6 = _errno_location();
v7 = strerror(*v6);
debugPrintfFormat("socket %i writing error: %s\n", a1, v7);
serialPrint(print_buf);
}
}
else
{
v3 = -1;
if ( print_buf )
{
debugPrintfFormat("socket %i disconnected\n", a1);
serialPrint(print_buf);
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, const void *a2, unsigned __int16 a3)
{
unsigned int v3; // ebp
unsigned int v5; // eax
int *v6; // rax
char *v7; // rax

v3 = 0;
if ( a3 )
{
v5 = write(a1, a2, a3);
v3 = v5;
if ( (_WORD)v5 )
{
if ( (v5 & 0x8000u) != 0 && print_buf )
{
v6 = _errno_location();
v7 = strerror(*v6);
debugPrintfFormat("socket %i writing error: %s\n", a1, v7);
serialPrint(print_buf);
}
}
else
{
v3 = -1;
if ( print_buf )
{
debugPrintfFormat("socket %i disconnected\n", a1);
serialPrint(print_buf);
}
}
}
return v3;
}

original_code:
int16_t pcRadioSend(int sock, const void *buf, uint16_t bufLen) {
    if (bufLen == 0) return 0;
    int16_t l = write(sock, buf, bufLen);
    if (l == 0) {
        if (2 == 1) { serialPrintV("socket %i disconnected\n", sock); } else { if (_print_buf) { debugPrintfFormat("socket %i disconnected\n", sock); serialPrint(_print_buf); }; };
        return -1;
    }
    if (l < 0) {
        if (3 == 1) { serialPrintV("socket %i writing error: %s\n", sock, strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("socket %i writing error: %s\n", sock, strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
    }
    return l;
}

canonical_original_code:
short pcRadioSend(int sock, void *buf, unsigned short bufLen) {
    if (bufLen == 0) return 0;
    short l = write(sock, buf, bufLen);
    if (l == 0) {
        if (2 == 1) { serialPrintV("socket %i disconnected\n", sock); } else { if (_print_buf) { debugPrintfFormat("socket %i disconnected\n", sock); serialPrint(_print_buf); }; };
        return -1;
    }
    if (l < 0) {
        if (3 == 1) { serialPrintV("socket %i writing error: %s\n", sock, strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("socket %i writing error: %s\n", sock, strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
    }
    return l;
}


connectSock

decompiled_code:
__int64 __fastcall connectSock(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
char *v3; // rsi
__int64 v4; // rdi
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
struct sockaddr v11; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 < 0 )
{
if ( print_buf )
{
v6 = _errno_location();
v7 = strerror(*v6);
debugPrintfFormat("error = %s\n", v7);
serialPrint(print_buf);
}
((void (*)(void))radioOff)();
}
else
{
optval[0] = 1;
if ( setsockopt(v1, 1, 2, optval, 4u) )
{
if ( print_buf )
{
v8 = _errno_location();
v9 = strerror(*v8);
debugPrintfFormat("cannot set socket to reuse addr: %s\n", v9);
serialPrint(print_buf);
}
close(v2);
v2 = -1;
}
else
{
*(_DWORD *)&v11.sa_data[10] = 0;
v11.sa_family = 2;
*(_QWORD *)&v11.sa_data[2] = (unsigned int)_bswap_32(0x7F000001u);
*(_WORD *)v11.sa_data = _bswap_16(a1);
v3 = (char *)&v11;
v4 = v2;
if ( connect(v2, &v11, 0x10u) < 0 )
{
if ( print_buf )
{
v10 = _errno_location();
v3 = strerror(*v10);
debugPrintfFormat("can not connect to cloud: %s\n", v3);
v4 = print_buf;
serialPrint(print_buf);
}
radioOff(v4, v3);
close(v2);
v2 = -1;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
char *v3; // rsi
__int64 v4; // rdi
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
struct sockaddr v11; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 < 0 )
{
if ( print_buf )
{
v6 = _errno_location();
v7 = strerror(*v6);
debugPrintfFormat("error = %s\n", v7);
serialPrint(print_buf);
}
((void (*)(void))radioOff)();
}
else
{
optval[0] = 1;
if ( setsockopt(v1, 1, 2, optval, 4u) )
{
if ( print_buf )
{
v8 = _errno_location();
v9 = strerror(*v8);
debugPrintfFormat("cannot set socket to reuse addr: %s\n", v9);
serialPrint(print_buf);
}
close(v2);
v2 = -1;
}
else
{
*(_DWORD *)&v11.sa_data[10] = 0;
v11.sa_family = 2;
*(_QWORD *)&v11.sa_data[2] = (unsigned int)func2(0x7F000001u);
*(_WORD *)v11.sa_data = func1(a1);
v3 = (char *)&v11;
v4 = v2;
if ( connect(v2, &v11, 0x10u) < 0 )
{
if ( print_buf )
{
v10 = _errno_location();
v3 = strerror(*v10);
debugPrintfFormat("can not connect to cloud: %s\n", v3);
v4 = print_buf;
serialPrint(print_buf);
}
func3(v4, v3);
close(v2);
v2 = -1;
}
}
}
return v2;
}

original_code:
int connectSock(unsigned port) {
    int sock = socket(2, SOCK_STREAM, 0);
    if (sock < 0)
    {
        if (2 == 1) { serialPrintV("error = %s\n", strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("error = %s\n", strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
        radioOff();
        return sock;
    }
    int on = 1;
    if (setsockopt(sock, 1, 2, &on, sizeof(on)))
    {
        if (2 == 1) { serialPrintV("cannot set socket to reuse addr: %s\n", strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("cannot set socket to reuse addr: %s\n", strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
        close(sock);
        return -1;
    }
    struct sockaddr_in proxyAddr;
    memset((char *) &proxyAddr, 0, sizeof(proxyAddr));
    proxyAddr.sin_family = 2;
    proxyAddr.sin_addr.s_addr = htonl(LOOPBACK_ADDR);
    proxyAddr.sin_port = htons(port);
    if (connect(sock, (struct sockaddr *) &proxyAddr, sizeof(proxyAddr)) < 0)
    {
        if (2 == 1) { serialPrintV("can not connect to cloud: %s\n", strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("can not connect to cloud: %s\n", strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
        radioOff();
        close(sock);
        return -1;
    }
    return sock;
}

canonical_original_code:
int connectSock(unsigned int port) {
    int sock = socket(2, SOCK_STREAM, 0);
    if (sock < 0)
    {
        if (2 == 1) { serialPrintV("error = %s\n", strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("error = %s\n", strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
        radioOff();
        return sock;
    }
    int on = 1;
    if (setsockopt(sock, 1, 2, &on, sizeof(on)))
    {
        if (2 == 1) { serialPrintV("cannot set socket to reuse addr: %s\n", strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("cannot set socket to reuse addr: %s\n", strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
        close(sock);
        return -1;
    }
    struct sockaddr_in proxyAddr;
    memset((char *) &proxyAddr, 0, sizeof(proxyAddr));
    proxyAddr.sin_family = 2;
    proxyAddr.sin_addr.s_addr = htonl(LOOPBACK_ADDR);
    proxyAddr.sin_port = htons(port);
    if (connect(sock, (struct sockaddr *) &proxyAddr, sizeof(proxyAddr)) < 0)
    {
        if (2 == 1) { serialPrintV("can not connect to cloud: %s\n", strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("can not connect to cloud: %s\n", strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
        radioOff();
        close(sock);
        return -1;
    }
    return sock;
}

variable_types:
port
unsigned int

variable_types: on int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

return_type: int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


makeSocketPair

decompiled_code:
__int64 makeSocketPair()
{
if ( socketpair(1, 1, 0, sockets) )
return 0xFFFFFFFFLL;
mosSendSock = sockets[0];
mosSendPairSock = dword_5DC;
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
if ( socketpair(1, 1, 0, sockets) )
return 0xFFFFFFFFLL;
mosSendSock = sockets[0];
mosSendPairSock = dword_5DC;
return 0LL;
}

original_code:
int8_t makeSocketPair() {
    if (socketpair(1, SOCK_STREAM, 0, sockets) != 0) return -1;
    mosSendSock = sockets[0];
    mosSendPairSock = sockets[1];
    return 0;
}

canonical_original_code:
char makeSocketPair() {
    if (socketpair(1, SOCK_STREAM, 0, sockets) != 0) return -1;
    mosSendSock = sockets[0];
    mosSendPairSock = sockets[1];
    return 0;
}

return_type: char


intHandler

decompiled_code:
void *__fastcall intHandler(void *a1)
{
int v1; // eax
unsigned __int16 v3; // ax
__int16 v4; // ax
__int16 v5; // ax
int *v6; // rax
char *v7; // rax
int v8; // eax
__int16 v9; // ax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

if ( (unsigned __int8)makeSocketPair(a1) )
{
serialPrintV("cannot create outgoing socket pair!\n");
}
else
{
v1 = connectSock(6293);
cloudSock = v1;
if ( v1 != -1 )
{
len = 16;
if ( !getsockname(v1, &addr, &len) )
{
v3 = _bswap_16(*(__int16 *)addr.sa_data);
localAddress = v3;
if ( print_buf )
{
debugPrintfFormat("set local address to port number: 0x%04x\n", v3);
serialPrint(print_buf);
}
}
}
pollFd.fd = cloudSock;
pollFd.events = 1;
*((_DWORD *)&pollFd + 2) = mosSendPairSock;
*((_WORD *)&pollFd + 6) = 1;
do
{
while ( 1 )
{
do
{
while ( 1 )
{
v8 = poll(&pollFd, 2uLL, -1);
if ( v8 > 0 )
break;
if ( v8 && print_buf )
{
v6 = _errno_location();
v7 = strerror(*v6);
debugPrintfFormat("poll error: %s\n", v7);
serialPrint(print_buf);
}
}
if ( (pollFd.revents & 1) != 0 )
{
v4 = pcRadioRecvPack(cloudSock, &pcRadioBuf);
if ( v4 < 0 )
return 0LL;
pcRadioBufLen = v4;
if ( pcRadioIsOn && pcRadioCallback )
pcRadioCallback();
}
if ( (*((_BYTE *)&pollFd + 14) & 1) != 0 )
{
v5 = pcRadioRecvPack(mosSendPairSock, mosOutBuf);
if ( v5 <= 0 )
{
if ( v5 < 0 )
return 0LL;
}
else
{
pollFd.events = 4;
mosOutBufOffset = 0;
mosOutBufLen = v5;
}
}
}
while ( (pollFd.revents & 4) == 0 );
v9 = pcRadioSend(cloudSock, (char *)mosOutBuf + (unsigned int)mosOutBufOffset, mosOutBufLen);
if ( v9 <= 0 )
break;
mosOutBufLen -= v9;
if ( mosOutBufLen )
mosOutBufOffset += v9;
else
pollFd.events = 1;
}
}
while ( v9 >= 0 );
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
int v1; // eax
unsigned __int16 v3; // ax
__int16 v4; // ax
__int16 v5; // ax
int *v6; // rax
char *v7; // rax
int v8; // eax
__int16 v9; // ax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

if ( (unsigned __int8)func9(a1) )
{
func0("cannot create outgoing socket pair!\n");
}
else
{
v1 = func8(6293);
cloudSock = v1;
if ( v1 != -1 )
{
len = 16;
if ( !getsockname(v1, &addr, &len) )
{
v3 = func1(*(__int16 *)addr.sa_data);
localAddress = v3;
if ( print_buf )
{
debugPrintfFormat("set local address to port number: 0x%04x\n", v3);
serialPrint(print_buf);
}
}
}
pollFd.fd = cloudSock;
pollFd.events = 1;
*((_DWORD *)&pollFd + 2) = mosSendPairSock;
*((_WORD *)&pollFd + 6) = 1;
do
{
while ( 1 )
{
do
{
while ( 1 )
{
v8 = poll(&pollFd, 2uLL, -1);
if ( v8 > 0 )
break;
if ( v8 && print_buf )
{
v6 = _errno_location();
v7 = strerror(*v6);
debugPrintfFormat("poll error: %s\n", v7);
serialPrint(print_buf);
}
}
if ( (pollFd.revents & 1) != 0 )
{
v4 = func6(cloudSock, &pcRadioBuf);
if ( v4 < 0 )
return 0LL;
pcRadioBufLen = v4;
if ( pcRadioIsOn && pcRadioCallback )
pcRadioCallback();
}
if ( (*((_BYTE *)&pollFd + 14) & 1) != 0 )
{
v5 = func6(mosSendPairSock, mosOutBuf);
if ( v5 <= 0 )
{
if ( v5 < 0 )
return 0LL;
}
else
{
pollFd.events = 4;
mosOutBufOffset = 0;
mosOutBufLen = v5;
}
}
}
while ( (pollFd.revents & 4) == 0 );
v9 = func7(cloudSock, (char *)mosOutBuf + (unsigned int)mosOutBufOffset, mosOutBufLen);
if ( v9 <= 0 )
break;
mosOutBufLen -= v9;
if ( mosOutBufLen )
mosOutBufOffset += v9;
else
pollFd.events = 1;
}
}
while ( v9 >= 0 );
}
return 0LL;
}

original_code:
void *intHandler(void *dummy) {
    if (makeSocketPair() != 0) {
        if (1 == 1) { serialPrintV("cannot create outgoing socket pair!\n"); } else { if (_print_buf) { debugPrintfFormat("cannot create outgoing socket pair!\n"); serialPrint(_print_buf); }; };
        return ((void *)0);
    }
    cloudSock = connectSock(PROXY_SERVER_PORT);
    if (cloudSock != -1) {
        struct sockaddr_in saddr;
        socklen_t slen = sizeof(saddr);
        if (getsockname(cloudSock, (struct sockaddr *) &saddr, &slen) == 0) {
            localAddress = htons(saddr.sin_port);
            if (2 == 1) { serialPrintV("set local address to port number: 0x%04x\n", localAddress); } else { if (_print_buf) { debugPrintfFormat("set local address to port number: 0x%04x\n", localAddress); serialPrint(_print_buf); }; };
        }
    }
    pollFd[0].fd = cloudSock;
    pollFd[0].events = 0x001;
    pollFd[1].fd = mosSendPairSock;
    pollFd[1].events = 0x001;
    while (1) {
        int p = poll(pollFd, 2, -1);
        if (p > 0) {
            if (pollFd[0].revents & 0x001) {
                int16_t l = pcRadioRecvPack(cloudSock, pcRadioBuf,
                        sizeof(pcRadioBuf));
                if (l < 0) {
                    return ((void *)0);
                }
                pcRadioBufLen = l;
                if (pcRadioIsOn && pcRadioCallback) {
                    pcRadioCallback();
                }
            }
            if (pollFd[1].revents & 0x001) {
                int16_t l = pcRadioRecvPack(mosSendPairSock, mosOutBuf,
                        sizeof(mosOutBuf));
                if (l > 0) {
                    pollFd[0].events = 0x004;
                    mosOutBufOffset = 0;
                    mosOutBufLen = l;
                } else if (l < 0) {
                    return ((void *)0);
                }
            }
            if (pollFd[0].revents & 0x004) {
                int16_t l = pcRadioSend(cloudSock, mosOutBuf + mosOutBufOffset,
                        mosOutBufLen);
                if (l > 0) {
                    mosOutBufLen -= l;
                    if (mosOutBufLen == 0) {
                        pollFd[0].events = 0x001;
                    } else {
                        mosOutBufOffset += l;
                    }
                } else if (l < 0) {
                    return ((void *)0);
                } else {
                }
            }
        } else if (p == 0) {
        } else {
            if (2 == 1) { serialPrintV("poll error: %s\n", strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("poll error: %s\n", strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
        }
    }
    return ((void *)0);
}

canonical_original_code:
void *intHandler(void *dummy) {
    if (makeSocketPair() != 0) {
        if (1 == 1) { serialPrintV("cannot create outgoing socket pair!\n"); } else { if (_print_buf) { debugPrintfFormat("cannot create outgoing socket pair!\n"); serialPrint(_print_buf); }; };
        return ((void *)0);
    }
    cloudSock = connectSock(PROXY_SERVER_PORT);
    if (cloudSock != -1) {
        struct sockaddr_in saddr;
        unsigned int slen = sizeof(saddr);
        if (getsockname(cloudSock, (struct sockaddr *) &saddr, &slen) == 0) {
            localAddress = htons(saddr.sin_port);
            if (2 == 1) { serialPrintV("set local address to port number: 0x%04x\n", localAddress); } else { if (_print_buf) { debugPrintfFormat("set local address to port number: 0x%04x\n", localAddress); serialPrint(_print_buf); }; };
        }
    }
    pollFd[0].fd = cloudSock;
    pollFd[0].events = 0x001;
    pollFd[1].fd = mosSendPairSock;
    pollFd[1].events = 0x001;
    while (1) {
        int p = poll(pollFd, 2, -1);
        if (p > 0) {
            if (pollFd[0].revents & 0x001) {
                short l = pcRadioRecvPack(cloudSock, pcRadioBuf,
                        sizeof(pcRadioBuf));
                if (l < 0) {
                    return ((void *)0);
                }
                pcRadioBufLen = l;
                if (pcRadioIsOn && pcRadioCallback) {
                    pcRadioCallback();
                }
            }
            if (pollFd[1].revents & 0x001) {
                short l = pcRadioRecvPack(mosSendPairSock, mosOutBuf,
                        sizeof(mosOutBuf));
                if (l > 0) {
                    pollFd[0].events = 0x004;
                    mosOutBufOffset = 0;
                    mosOutBufLen = l;
                } else if (l < 0) {
                    return ((void *)0);
                }
            }
            if (pollFd[0].revents & 0x004) {
                short l = pcRadioSend(cloudSock, mosOutBuf + mosOutBufOffset,
                        mosOutBufLen);
                if (l > 0) {
                    mosOutBufLen -= l;
                    if (mosOutBufLen == 0) {
                        pollFd[0].events = 0x001;
                    } else {
                        mosOutBufOffset += l;
                    }
                } else if (l < 0) {
                    return ((void *)0);
                } else {
                }
            }
        } else if (p == 0) {
        } else {
            if (2 == 1) { serialPrintV("poll error: %s\n", strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("poll error: %s\n", strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
        }
    }
    return ((void *)0);
}

variable_types:
dummy
void *

variable_types:
slen
unsigned int

variable_types: p int

return_type: void *


closeSocket

decompiled_code:
int __fastcall closeSocket(int a1)
{
int result; // eax
int *v2; // rax
char *v3; // rax

result = close(a1);
if ( result < 0 )
{
if ( print_buf )
{
v2 = _errno_location();
v3 = strerror(*v2);
debugPrintfFormat("error closing socket: %s\n", v3);
result = serialPrint(print_buf);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(int a1)
{
int result; // eax
int *v2; // rax
char *v3; // rax

result = close(a1);
if ( result < 0 )
{
if ( print_buf )
{
v2 = _errno_location();
v3 = strerror(*v2);
debugPrintfFormat("error closing socket: %s\n", v3);
result = serialPrint(print_buf);
}
}
return result;
}

original_code:
void closeSocket(int sock) {
    if (close(sock) < 0) {
        if (2 == 1) { serialPrintV("error closing socket: %s\n", strerror((*__errno_location ()))); } else { if (_print_buf) { debugPrintfFormat("error closing socket: %s\n", strerror((*__errno_location ()))); serialPrint(_print_buf); }; };
    } else {
    }
}


networkingInitArch

decompiled_code:
int networkingInitArch()
{
mos_sem_init(&alarmMutex, 0LL);
return pthread_create(&intThread, 0LL, intHandler, 0LL);
}

canonical_decompiled_code:
int func12()
{
mos_sem_init(&alarmMutex, 0LL);
return pthread_create(&intThread, 0LL, intHandler, 0LL);
}

original_code:
void networkingInitArch(void)
{
    mos_sem_init(&alarmMutex, 0);
    pthread_create(&intThread, ((void *)0), intHandler, ((void *)0));
}

canonical_original_code:
void networkingInitArch()
{
    mos_sem_init(&alarmMutex, 0);
    pthread_create(&intThread, ((void *)0), intHandler, ((void *)0));
}


redLedOn

decompiled_code:
__int64 redLedOn()
{
return pinSetPc(255LL, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
return pinSetPc(255LL, 0LL);
}

original_code: static inline void redLedOn(void) { led0On(); }

canonical_original_code: static inline void redLedOn() { led0On(); }


redLedToggle

decompiled_code:
__int64 redLedToggle()
{
__int64 result; // rax

if ( (unsigned int)pinReadPc(255LL, 0LL) )
result = pinClearPc(255LL, 0LL);
else
result = pinSetPc(255LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax

if ( (unsigned int)pinReadPc(255LL, 0LL) )
result = pinClearPc(255LL, 0LL);
else
result = pinSetPc(255LL, 0LL);
return result;
}

original_code: static inline void redLedToggle(void) { led0Toggle(); }

canonical_original_code: static inline void redLedToggle() { led0Toggle(); }


doMsleep

canonical_decompiled_code:
int __fastcall func3(unsigned __int16 a1)
{
return usleep(1000 * a1);
}


printBuf

decompiled_code:
__int64 printBuf()
{
__int64 result; // rax

if ( print_buf )
{
debugPrintfFormat(
"%i-%i-%i %i:%i:%i\t",
(unsigned __int16)fix >> 9,
((unsigned __int64)fix >> 5) & 0xF,
fix & 0x1F,
BYTE2(fix),
BYTE3(fix),
BYTE4(fix));
result = serialPrint(print_buf);
if ( print_buf )
{
debugPrintfFormat("%i %i.%i\t", BYTE6(fix), HIBYTE(fix), (unsigned __int16)word_2E8);
result = serialPrint(print_buf);
if ( print_buf )
{
debugPrintfFormat(
"%i %i.%i\t",
(unsigned __int8)byte_2EA,
(unsigned __int8)byte_2EB,
(unsigned __int16)word_2EC);
result = serialPrint(print_buf);
if ( print_buf )
{
debugPrintfFormat(
"%i %i %i\n",
((unsigned __int64)fix >> 45) & 7,
((unsigned __int64)fix >> 40) & 3,
((unsigned __int64)fix >> 42) & 7);
result = serialPrint(print_buf);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax

if ( print_buf )
{
debugPrintfFormat(
"%i-%i-%i %i:%i:%i\t",
(unsigned __int16)fix >> 9,
((unsigned __int64)fix >> 5) & 0xF,
fix & 0x1F,
BYTE2(fix),
BYTE3(fix),
BYTE4(fix));
result = serialPrint(print_buf);
if ( print_buf )
{
debugPrintfFormat("%i %i.%i\t", BYTE6(fix), HIBYTE(fix), (unsigned __int16)word_2E8);
result = serialPrint(print_buf);
if ( print_buf )
{
debugPrintfFormat(
"%i %i.%i\t",
(unsigned __int8)byte_2EA,
(unsigned __int8)byte_2EB,
(unsigned __int16)word_2EC);
result = serialPrint(print_buf);
if ( print_buf )
{
debugPrintfFormat(
"%i %i %i\n",
((unsigned __int64)fix >> 45) & 7,
((unsigned __int64)fix >> 40) & 3,
((unsigned __int64)fix >> 42) & 7);
result = serialPrint(print_buf);
}
}
}
}
return result;
}

original_code:
void printBuf(void *buf)
{
    if (7 == 1) { serialPrintV("%i-%i-%i %i:%i:%i\t", fix.d.year, fix.d.mon, fix.d.day, fix.h, fix.m, fix.s); } else { if (_print_buf) { debugPrintfFormat("%i-%i-%i %i:%i:%i\t", fix.d.year, fix.d.mon, fix.d.day, fix.h, fix.m, fix.s); serialPrint(_print_buf); }; };
    if (4 == 1) { serialPrintV("%i %i.%i\t", fix.lat.deg, fix.lat.min, fix.lat.mindec); } else { if (_print_buf) { debugPrintfFormat("%i %i.%i\t", fix.lat.deg, fix.lat.min, fix.lat.mindec); serialPrint(_print_buf); }; };
    if (4 == 1) { serialPrintV("%i %i.%i\t", fix.lon.deg, fix.lon.min, fix.lon.mindec); } else { if (_print_buf) { debugPrintfFormat("%i %i.%i\t", fix.lon.deg, fix.lon.min, fix.lon.mindec); serialPrint(_print_buf); }; };
    if (4 == 1) { serialPrintV("%i %i %i\n", fix.q.satcnt, fix.q.fix, fix.q.dop); } else { if (_print_buf) { debugPrintfFormat("%i %i %i\n", fix.q.satcnt, fix.q.fix, fix.q.dop); serialPrint(_print_buf); }; };
}


charRecv

decompiled_code:
__int64 charRecv()
{
return redLedToggle();
}

canonical_decompiled_code:
__int64 func5()
{
return func2();
}

original_code:
void charRecv(uint8_t b) {
    redLedToggle();
}

canonical_original_code:
void charRecv(unsigned char b) {
    redLedToggle();
}

variable_types:
b
unsigned char


doMsleep

decompiled_code:
int __fastcall doMsleep(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

original_code:
extern inline void doMsleep(uint16_t milliseconds) {
    usleep(milliseconds * 1000);
}


decompiled_code:
int __fastcall mos_sem_init(sem_t *a1, char a2)
{
return sem_init(a1, 0, a2);
}

canonical_decompiled_code:
int __fastcall func1(sem_t *a1, char a2)
{
return sem_init(a1, 0, a2);
}

original_code:
void mos_sem_init(sem_t *s, int8_t value)
{
    sem_init(s,0,value);
}

canonical_original_code:
void mos_sem_init(union sem_t *s, char value)
{
    sem_init(s,0,value);
}

variable_types: union sem_t { char __size[32]; long __align; } *

variable_types: value char


decompiled_code:
int __fastcall mos_sem_destroy(sem_t *a1)
{
return sem_destroy(a1);
}

canonical_decompiled_code:
int __fastcall func2(sem_t *a1)
{
return sem_destroy(a1);
}

original_code:
void mos_sem_destroy(sem_t *s)
{
    sem_destroy(s);
}

canonical_original_code:
void mos_sem_destroy(union sem_t *s)
{
    sem_destroy(s);
}

user_defined_types: union sem_t { char __size[32]; long __align; }


decompiled_code:
bool __fastcall sem_try_wait(sem_t *a1)
{
return sem_trywait(a1) != 0;
}

canonical_decompiled_code:
bool __fastcall func3(sem_t *a1)
{
return sem_trywait(a1) != 0;
}

original_code:
uint8_t sem_try_wait(sem_t *s)
{
    if (sem_trywait(s)) {
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
unsigned char sem_try_wait(union sem_t *s)
{
    if (sem_trywait(s)) {
        return 1;
    } else {
        return 0;
    }
}


decompiled_code:
int __fastcall mos_sem_wait(sem_t *a1)
{
return sem_wait(a1);
}

canonical_decompiled_code:
int __fastcall func4(sem_t *a1)
{
return sem_wait(a1);
}

original_code:
void mos_sem_wait(sem_t *s)
{
    sem_wait(s);
}

canonical_original_code:
void mos_sem_wait(union sem_t *s)
{
    sem_wait(s);
}


decompiled_code:
int __fastcall mos_sem_post(sem_t *a1)
{
return sem_post(a1);
}

canonical_decompiled_code:
int __fastcall func5(sem_t *a1)
{
return sem_post(a1);
}

original_code:
void mos_sem_post(sem_t *s)
{
    sem_post(s);
}

canonical_original_code:
void mos_sem_post(union sem_t *s)
{
    sem_post(s);
}


decompiled_code:
__int64 __fastcall mos_sem_get_val(sem_t *a1)
{
int v1; // edx
__int64 result; // rax
int sval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = sem_getvalue(a1, sval);
result = LOBYTE(sval[0]);
if ( v1 )
{
perror("sem_getvalue");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(sem_t *a1)
{
int v1; // edx
__int64 result; // rax
int sval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = sem_getvalue(a1, sval);
result = LOBYTE(sval[0]);
if ( v1 )
{
perror("sem_getvalue");
result = 0LL;
}
return result;
}

original_code:
int8_t mos_sem_get_val(sem_t *s)
{
    int val;
    if (sem_getvalue(s, &val)) {
        perror("sem_getvalue");
        return 0;
    }
    return val;
}

canonical_original_code:
char mos_sem_get_val(union sem_t *s)
{
    int val;
    if (sem_getvalue(s, &val)) {
        perror("sem_getvalue");
        return 0;
    }
    return val;
}

variable_types: val int


getJiffies

decompiled_code:
__int64 getJiffies()
{
return jiffies;
}

canonical_decompiled_code:
__int64 func0()
{
return jiffies;
}

original_code:
static inline ticks_t getJiffies(void)
{
    Handle_t handle;
    (handle) = 0;
    ticks_t result = jiffies;
    ((void) handle);
    return result;
}

canonical_original_code:
static inline unsigned int getJiffies()
{
    unsigned short handle;
    (handle) = 0;
    unsigned int result = jiffies;
    ((void) handle);
    return result;
}

variable_types:
handle
unsigned short

variable_types:
result
unsigned int


getTimeMs

decompiled_code:
// attributes: thunk
__int64 getTimeMs()
{
return getJiffies();
}

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

original_code:
static inline uint32_t getTimeMs(void) {
    return (uint32_t) getJiffies();
}

canonical_original_code:
static inline unsigned int getTimeMs() {
    return (unsigned int) getJiffies();
}


serialPrintV

decompiled_code:
__int64 serialPrintV()
{
return serialPrint();
}

canonical_decompiled_code:
__int64 func2()
{
return serialPrint();
}

original_code:
static inline void serialPrintV(const char* str, ...) {
    serialPrint(str);
}

canonical_original_code:
static inline void serialPrintV(char *str, ...) {
    serialPrint(str);
}

variable_types:
str
char *


redLedOn

canonical_decompiled_code:
__int64 func3()
{
return pinSetPc(255LL, 0LL);
}


redLedOff

decompiled_code:
__int64 redLedOff()
{
return pinClearPc(255LL, 0LL);
}

canonical_decompiled_code:
__int64 func5()
{
return pinClearPc(255LL, 0LL);
}

original_code: static inline void redLedOff(void) { led0Off(); }

canonical_original_code: static inline void redLedOff() { led0Off(); }


doMsleep

canonical_decompiled_code:
int __fastcall func8(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

canonical_original_code:
extern inline void doMsleep(unsigned short milliseconds) {
    usleep(milliseconds * 1000);
}

variable_types:
milliseconds
unsigned short


eraseData

decompiled_code:
__int64 eraseData()
{
serialPrintV("erasing flash...");
extFlashEraseSector(4294901779LL);
serialPrintV("+");
extFlashEraseSector(19LL);
serialPrintV("+");
extFlashEraseSector(65555LL);
return serialPrint("+ DONE\n");
}

canonical_decompiled_code:
__int64 func9()
{
func2("erasing flash...");
extFlashEraseSector(4294901779LL);
func2("+");
extFlashEraseSector(19LL);
func2("+");
extFlashEraseSector(65555LL);
return serialPrint("+ DONE\n");
}

original_code:
void eraseData() {
    if (1 == 1) { serialPrintV("erasing flash..."); } else { if (_print_buf) { debugPrintfFormat("erasing flash..."); serialPrint(_print_buf); }; };
    extFlashEraseSector(START_ADDR - 0x10000);
    if (1 == 1) { serialPrintV("+"); } else { if (_print_buf) { debugPrintfFormat("+"); serialPrint(_print_buf); }; };
    extFlashEraseSector(START_ADDR);
    if (1 == 1) { serialPrintV("+"); } else { if (_print_buf) { debugPrintfFormat("+"); serialPrint(_print_buf); }; };
    extFlashEraseSector(START_ADDR + 0x10000);
    serialPrint("+ DONE" "\n");
}


eraseAllBySector

decompiled_code:
__int64 eraseAllBySector()
{
char *v0; // rax
char v1; // dl
unsigned int v2; // ebx

serialPrint("erasing all by sector\n\n");
v0 = &buf;
v1 = 12;
do
*v0++ = v1++;
while ( v0 != "erasing flash..." );
c = v1;
i = 320;
v2 = 13;
while ( 1 )
{
extFlashEraseSector(v2);
extFlashWrite(v2, &buf, 10LL);
data = 0LL;
*((_WORD *)&data + 4) = 0;
extFlashRead(v2, &data, 10LL);
if ( memcmp(&buf, &data, 0xAuLL) )
break;
v2 += 11177;
if ( v2 == 1005943 )
return serialPrint("..done\n\n");
}
assertionFailed("!memcmp(buf, data, 10)", "main.c", 78LL);
return writeData();
}

canonical_decompiled_code:
__int64 func10()
{
char *v0; // rax
char v1; // dl
unsigned int v2; // ebx

serialPrint("erasing all by sector\n\n");
v0 = &buf;
v1 = 12;
do
*v0++ = v1++;
while ( v0 != "erasing flash..." );
c = v1;
i = 320;
v2 = 13;
while ( 1 )
{
extFlashEraseSector(v2);
extFlashWrite(v2, &buf, 10LL);
data = 0LL;
*((_WORD *)&data + 4) = 0;
extFlashRead(v2, &data, 10LL);
if ( memcmp(&buf, &data, 0xAuLL) )
break;
v2 += 11177;
if ( v2 == 1005943 )
return serialPrint("..done\n\n");
}
assertionFailed("!memcmp(buf, data, 10)", "main.c", 78LL);
return func11();
}

original_code:
void eraseAllBySector() {
    serialPrint("erasing all by sector\n" "\n");
    for (i = 0, c = START_BYTE; i < BYTE_COUNT; ++i, ++c) {
        buf[i] = c;
    }
    uint32_t ii;
    for (ii = 13; ii < 1000000; ii += 11177) {
        extFlashEraseSector(ii);
        extFlashWrite(ii, buf, 10);
        memset(data, 0, 10);
        extFlashRead(ii, data, 10);
        ((!memcmp(buf, data, 10)) ? (void)0 : assertionFailed("!memcmp(buf, data, 10)", "main.c", 78));
    }
    serialPrint("..done\n" "\n");
}

canonical_original_code:
void eraseAllBySector() {
    serialPrint("erasing all by sector\n" "\n");
    for (i = 0, c = START_BYTE; i < BYTE_COUNT; ++i, ++c) {
        buf[i] = c;
    }
    unsigned int ii;
    for (ii = 13; ii < 1000000; ii += 11177) {
        extFlashEraseSector(ii);
        extFlashWrite(ii, buf, 10);
        memset(data, 0, 10);
        extFlashRead(ii, data, 10);
        ((!memcmp(buf, data, 10)) ? (void)0 : assertionFailed("!memcmp(buf, data, 10)", "main.c", 78));
    }
    serialPrint("..done\n" "\n");
}

variable_types:
ii
unsigned int


writeData

decompiled_code:
__int64 writeData()
{
char *v0; // rax
char v1; // dl

v0 = &buf;
v1 = 12;
do
*v0++ = v1++;
while ( v0 != "erasing flash..." );
c = v1;
i = 320;
if ( print_buf )
{
debugPrintfFormat("writing flash from %lu to %lu\n", 19LL, 337LL);
serialPrint(print_buf);
}
extFlashWrite(19LL, &buf, 318LL);
return serialPrint("done\n");
}

canonical_decompiled_code:
__int64 func11()
{
char *v0; // rax
char v1; // dl

v0 = &buf;
v1 = 12;
do
*v0++ = v1++;
while ( v0 != "erasing flash..." );
c = v1;
i = 320;
if ( print_buf )
{
debugPrintfFormat("writing flash from %lu to %lu\n", 19LL, 337LL);
serialPrint(print_buf);
}
extFlashWrite(19LL, &buf, 318LL);
return serialPrint("done\n");
}

original_code:
void writeData() {
    for (i = 0, c = START_BYTE; i < BYTE_COUNT; ++i, ++c) {
        buf[i] = c;
    }
    if (3 == 1) { serialPrintV("writing flash from %lu to %lu\n", (uint32_t)START_ADDR, (uint32_t)START_ADDR + BYTE_COUNT - 2); } else { if (_print_buf) { debugPrintfFormat("writing flash from %lu to %lu\n", (uint32_t)START_ADDR, (uint32_t)START_ADDR + BYTE_COUNT - 2); serialPrint(_print_buf); }; };
    extFlashWrite(START_ADDR, buf, BYTE_COUNT - 2);
    serialPrint("done" "\n");
}

canonical_original_code:
void writeData() {
    for (i = 0, c = START_BYTE; i < BYTE_COUNT; ++i, ++c) {
        buf[i] = c;
    }
    if (3 == 1) { serialPrintV("writing flash from %lu to %lu\n", (unsigned int)START_ADDR, (unsigned int)START_ADDR + BYTE_COUNT - 2); } else { if (_print_buf) { debugPrintfFormat("writing flash from %lu to %lu\n", (unsigned int)START_ADDR, (unsigned int)START_ADDR + BYTE_COUNT - 2); serialPrint(_print_buf); }; };
    extFlashWrite(START_ADDR, buf, BYTE_COUNT - 2);
    serialPrint("done" "\n");
}


writeDataSpeedTest

decompiled_code:
__int64 writeDataSpeedTest()
{
int v0; // ebp
unsigned int i; // ebx
__int64 result; // rax
int v3; // eax

v0 = getTimeMs();
for ( i = 19; i != 65619; i += 100 )
result = extFlashWrite(i, &buf, 100LL);
if ( print_buf )
{
v3 = getTimeMs();
debugPrintfFormat("to write 64 kb: %lu ms \n", (unsigned int)(v3 - v0));
result = serialPrint(print_buf);
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // ebp
unsigned int i; // ebx
__int64 result; // rax
int v3; // eax

v0 = func1();
for ( i = 19; i != 65619; i += 100 )
result = extFlashWrite(i, &buf, 100LL);
if ( print_buf )
{
v3 = func1();
debugPrintfFormat("to write 64 kb: %lu ms \n", (unsigned int)(v3 - v0));
result = serialPrint(print_buf);
}
return result;
}

original_code:
void writeDataSpeedTest() {
    uint32_t startTime = getTimeMs();
    uint32_t i;
    for (i = 0; i < 0x10000; i += 100) {
        extFlashWrite(START_ADDR + i, buf, 100);
    }
    if (2 == 1) { serialPrintV("to write 64 kb: %lu ms \n", getTimeMs() - startTime); } else { if (_print_buf) { debugPrintfFormat("to write 64 kb: %lu ms \n", getTimeMs() - startTime); serialPrint(_print_buf); }; };
}

canonical_original_code:
void writeDataSpeedTest() {
    unsigned int startTime = getTimeMs();
    unsigned int i;
    for (i = 0; i < 0x10000; i += 100) {
        extFlashWrite(START_ADDR + i, buf, 100);
    }
    if (2 == 1) { serialPrintV("to write 64 kb: %lu ms \n", getTimeMs() - startTime); } else { if (_print_buf) { debugPrintfFormat("to write 64 kb: %lu ms \n", getTimeMs() - startTime); serialPrint(_print_buf); }; };
}

variable_types:
startTime
unsigned int

variable_types:
i
unsigned int


printResults

decompiled_code:
__int64 printResults()
{
__int64 result; // rax

memset(buf, 0, 0x140uLL);
serialPrintV("reading flash...");
extFlashRead(19LL, buf, 320LL);
serialPrint("done\n");
i = 0;
i32 = 19;
LOWORD(result) = 0;
do
{
if ( print_buf )
{
debugPrintfFormat("[0x%lx] = %u\t", (unsigned int)i32, (unsigned __int8)buf[(unsigned __int16)result]);
serialPrint(print_buf);
}
if ( (i & 3) == 3 )
serialPrint("\n");
result = (unsigned int)(unsigned __int16)i + 1;
i = result;
++i32;
}
while ( (unsigned __int16)result <= 0x13Fu );
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax

memset(buf, 0, 0x140uLL);
func2("reading flash...");
extFlashRead(19LL, buf, 320LL);
serialPrint("done\n");
i = 0;
i32 = 19;
LOWORD(result) = 0;
do
{
if ( print_buf )
{
debugPrintfFormat("[0x%lx] = %u\t", (unsigned int)i32, (unsigned __int8)buf[(unsigned __int16)result]);
serialPrint(print_buf);
}
if ( (i & 3) == 3 )
serialPrint("\n");
result = (unsigned int)(unsigned __int16)i + 1;
i = result;
++i32;
}
while ( (unsigned __int16)result <= 0x13Fu );
return result;
}

original_code:
void printResults() {
    memset(buf, 0, BYTE_COUNT);
    if (1 == 1) { serialPrintV("reading flash..."); } else { if (_print_buf) { debugPrintfFormat("reading flash..."); serialPrint(_print_buf); }; };
    extFlashRead(START_ADDR, buf, BYTE_COUNT);
    serialPrint("done" "\n");
    for (i = 0, i32 = START_ADDR; i < BYTE_COUNT; ++i, ++i32) {
        if (3 == 1) { serialPrintV("[0x%lx] = %u\t", i32, buf[i]); } else { if (_print_buf) { debugPrintfFormat("[0x%lx] = %u\t", i32, buf[i]); serialPrint(_print_buf); }; };
        if (i % 4 == 3) serialPrint("" "\n");
    }
}


writeSimpleData

decompiled_code:
__int64 writeSimpleData()
{
buf[0] = 1;
byte_521 = 2;
byte_522 = 3;
byte_523 = 4;
i = 4;
serialPrintV("writing flash...");
extFlashWrite(19LL, buf, 4LL);
return serialPrint("done\n");
}

canonical_decompiled_code:
__int64 func14()
{
buf[0] = 1;
byte_521 = 2;
byte_522 = 3;
byte_523 = 4;
i = 4;
func2("writing flash...");
extFlashWrite(19LL, buf, 4LL);
return serialPrint("done\n");
}

original_code:
void writeSimpleData() {
    for (i = 0; i < 4; ++i) {
        buf[i] = i + 1;
    }
    if (1 == 1) { serialPrintV("writing flash..."); } else { if (_print_buf) { debugPrintfFormat("writing flash..."); serialPrint(_print_buf); }; };
    extFlashWrite(START_ADDR, buf, 4);
    serialPrint("done" "\n");
}


readData

decompiled_code:
__int64 readData()
{
unsigned __int16 v0; // ax
__int64 v1; // rsi

memset(buf, 0, 0x140uLL);
serialPrintV("reading flash...");
extFlashRead(19LL, buf, 4LL);
serialPrint("done\n");
i = 0;
v0 = 0;
v1 = 19LL;
do
{
if ( print_buf )
{
debugPrintfFormat("[0x%lx] = %u\t", v1, (unsigned __int8)buf[v0]);
serialPrint(print_buf);
v1 = (unsigned int)(v1 + 1);
}
v0 = i + 1;
i = v0;
}
while ( v0 <= 3u );
return serialPrint("\n");
}

canonical_decompiled_code:
__int64 func15()
{
unsigned __int16 v0; // ax
__int64 v1; // rsi

memset(buf, 0, 0x140uLL);
func2("reading flash...");
extFlashRead(19LL, buf, 4LL);
serialPrint("done\n");
i = 0;
v0 = 0;
v1 = 19LL;
do
{
if ( print_buf )
{
debugPrintfFormat("[0x%lx] = %u\t", v1, (unsigned __int8)buf[v0]);
serialPrint(print_buf);
v1 = (unsigned int)(v1 + 1);
}
v0 = i + 1;
i = v0;
}
while ( v0 <= 3u );
return serialPrint("\n");
}

original_code:
void readData() {
    memset(buf, 0, BYTE_COUNT);
    if (1 == 1) { serialPrintV("reading flash..."); } else { if (_print_buf) { debugPrintfFormat("reading flash..."); serialPrint(_print_buf); }; };
    extFlashRead(START_ADDR, buf, 4);
    serialPrint("done" "\n");
    uint32_t addr = START_ADDR;
    for (i = 0; i < 4; ++i) {
        if (3 == 1) { serialPrintV("[0x%lx] = %u\t", addr++, buf[i]); } else { if (_print_buf) { debugPrintfFormat("[0x%lx] = %u\t", addr++, buf[i]); serialPrint(_print_buf); }; };
    }
    serialPrint("" "\n");
}

canonical_original_code:
void readData() {
    memset(buf, 0, BYTE_COUNT);
    if (1 == 1) { serialPrintV("reading flash..."); } else { if (_print_buf) { debugPrintfFormat("reading flash..."); serialPrint(_print_buf); }; };
    extFlashRead(START_ADDR, buf, 4);
    serialPrint("done" "\n");
    unsigned int addr = START_ADDR;
    for (i = 0; i < 4; ++i) {
        if (3 == 1) { serialPrintV("[0x%lx] = %u\t", addr++, buf[i]); } else { if (_print_buf) { debugPrintfFormat("[0x%lx] = %u\t", addr++, buf[i]); serialPrint(_print_buf); }; };
    }
    serialPrint("" "\n");
}

variable_types:
addr
unsigned int


doMsleep

decompiled_code:
int __fastcall doMsleep(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

original_code:
extern inline void doMsleep(uint16_t milliseconds) {
    usleep(milliseconds * 1000);
}


decompiled_code:
void __noreturn alarmTimerInterrupt0()
{
++jiffies;
if ( hasAnyReadyAlarms(jiffies) )
alarmsProcess();
while ( 1 )
++jiffies;
}

canonical_decompiled_code:
void __noreturn func2()
{
++jiffies;
if ( func0(jiffies) )
alarmsProcess();
while ( 1 )
++jiffies;
}

original_code:
void alarmTimerInterrupt0(void)
{
    jiffies += 1;
    if (hasAnyReadyAlarms(jiffies)) {
        alarmsProcess();
    }
    ;
    uint16_t tar = 0 + 1;
    while (!((int16_t) ((tar) - (0)) < 0)) {
        jiffies += 1;
        ;
    }
}

canonical_original_code:
void alarmTimerInterrupt0()
{
    jiffies += 1;
    if (hasAnyReadyAlarms(jiffies)) {
        alarmsProcess();
    }
    ;
    unsigned short tar = 0 + 1;
    while (!((short) ((tar) - (0)) < 0)) {
        jiffies += 1;
        ;
    }
}

variable_types:
tar
unsigned short