output

decompiled_code:
signed __int64 __fastcall output(unsigned __int8 *a1, size_t a2)
{
int v2; // edx
signed __int64 result; // rax
int v4; // edx

if ( io == 1 )
{
v4 = fputc(*a1, stdout);
result = 1LL;
if ( v4 != -1 )
return result;
goto LABEL_4;
}
if ( io != 2 )
{
if ( io )
goto LABEL_4;
result = fwrite(a1, a2, 1uLL, stdout);
if ( result == 1 )
result = a2;
LABEL_8:
if ( result > 0 )
return result;
goto LABEL_4;
}
if ( fputs((const char *)a1, stdout) > 0 )
{
result = a2;
goto LABEL_8;
}
LABEL_4:
v2 = feof(stdout);
result = 0LL;
if ( !v2 )
{
if ( ferror(stdout) )
*_errno_location() = 5;
else
*_errno_location() = 22;
perror("fwrite");
result = -1LL;
}
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func4(unsigned __int8 *a1, size_t a2)
{
int v2; // edx
signed __int64 result; // rax
int v4; // edx

if ( io == 1 )
{
v4 = fputc(*a1, stdout);
result = 1LL;
if ( v4 != -1 )
return result;
goto LABEL_4;
}
if ( io != 2 )
{
if ( io )
goto LABEL_4;
result = fwrite(a1, a2, 1uLL, stdout);
if ( result == 1 )
result = a2;
LABEL_8:
if ( result > 0 )
return result;
goto LABEL_4;
}
if ( fputs((const char *)a1, stdout) > 0 )
{
result = a2;
goto LABEL_8;
}
LABEL_4:
v2 = feof(stdout);
result = 0LL;
if ( !v2 )
{
if ( ferror(stdout) )
*_errno_location() = 5;
else
*_errno_location() = 22;
perror("fwrite");
result = -1LL;
}
return result;
}

original_code:
static ssize_t output(const uint8_t * buffer, size_t size)
{
    ssize_t rc = 0;
    int ch = 0;
    switch (io) {
    case BLOCK:
        if ((rc = fwrite(buffer, size, 1, stdout)) == 1) {
            rc = size;
        }
        break;
    case CHARACTER:
        ch = *buffer;
        if (fputc(ch, stdout) != (-1)) {
            rc = 1;
        }
        break;
    case LINE:
        if (fputs((char *)buffer, stdout) > 0) {
            rc = size;
        }
        break;
    default:
        break;
    }
    if (rc > 0) {
    } else if (feof(stdout)) {
        rc = 0;
    } else if (ferror(stdout)) {
        (*__errno_location ()) = 5;
        perror("fwrite");
        rc = -1;
    } else {
        (*__errno_location ()) = 22;
        perror("fwrite");
        rc = -1;
    }
    return rc;
}

canonical_original_code:
static long output(unsigned char *buffer, unsigned long size)
{
    long rc = 0;
    int ch = 0;
    switch (io) {
    case BLOCK:
        if ((rc = fwrite(buffer, size, 1, stdout)) == 1) {
            rc = size;
        }
        break;
    case CHARACTER:
        ch = *buffer;
        if (fputc(ch, stdout) != (-1)) {
            rc = 1;
        }
        break;
    case LINE:
        if (fputs((char *)buffer, stdout) > 0) {
            rc = size;
        }
        break;
    default:
        break;
    }
    if (rc > 0) {
    } else if (feof(stdout)) {
        rc = 0;
    } else if (ferror(stdout)) {
        (*__errno_location ()) = 5;
        perror("fwrite");
        rc = -1;
    } else {
        (*__errno_location ()) = 22;
        perror("fwrite");
        rc = -1;
    }
    return rc;
}


repo: coverclock/com-diag-diminuto

decompiled_code:
__int64 diminuto_throttle_now()
{
return diminuto_time_elapsed();
}

canonical_decompiled_code:
__int64 func6()
{
return diminuto_time_elapsed();
}

original_code:
static inline diminuto_sticks_t diminuto_throttle_now(void)
{
    return diminuto_time_elapsed();
}

canonical_original_code:
static inline long diminuto_throttle_now()
{
    return diminuto_time_elapsed();
}

return_type: long


decompiled_code:
__int64 diminuto_shaper_now()
{
return diminuto_throttle_now();
}

canonical_decompiled_code:
__int64 func7()
{
return func6();
}

original_code:
static inline diminuto_sticks_t diminuto_shaper_now(void)
{
    return diminuto_throttle_now();
}

canonical_original_code:
static inline long diminuto_shaper_now()
{
    return diminuto_throttle_now();
}


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

result = a2 - 8;
if ( *a1 > a2 )
result = *(_QWORD *)(a1[1] + 8 * a2);
return result;
}

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

result = a2 - 8;
if ( *a1 > a2 )
result = *(_QWORD *)(a1[1] + 8 * a2);
return result;
}

original_code:
static inline size_t buffer_pool_size(diminuto_buffer_meta_t * poolp, size_t item)
{
    return (item < poolp->count) ? poolp->sizes[item] : item - sizeof(diminuto_buffer_t);
}

canonical_original_code:
static inline unsigned long buffer_pool_size(struct DiminutoBufferMeta *poolp, unsigned long item)
{
    return (item < poolp->count) ? poolp->sizes[item] : item - sizeof(diminuto_buffer_t);
}

variable_types: struct DiminutoBufferMeta { unsigned long count; unsigned long *sizes; struct DiminutoBuffer { unsigned long align[]; union { unsigned long item; struct DiminutoBuffer *next; } header; unsigned long payload[]; } **pool; } *

variable_types:
item
unsigned long

return_type: unsigned long

user_defined_types: struct DiminutoBufferMeta { unsigned long count; unsigned long *sizes; struct DiminutoBuffer **pool; }


decompiled_code:
unsigned __int64 *__fastcall diminuto_buffer_pool_get(unsigned __int64 *a1, unsigned __int64 a2, int a3)
{
unsigned __int64 v4; // rbp
unsigned __int64 *result; // rax
size_t v6[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a2 )
{
v6[0] = 0LL;
v4 = (unsigned int)buffer_pool_hash(a1, a2, v6);
if ( buffer_pool_isexternal(a1, v4) || !buffer_pool_first((__int64)a1, v4) )
result = (unsigned __int64 *)buffer_pool_malloc((__int64)a1, v6[0], a3);
else
result = buffer_pool_get((__int64)a1, v4);
if ( result )
result = buffer_pool_init(a1, result, v4, v6[0]);
}
else
{
*_errno_location() = 0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 *__fastcall func7(unsigned __int64 *a1, unsigned __int64 a2, int a3)
{
unsigned __int64 v4; // rbp
unsigned __int64 *result; // rax
size_t v6[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a2 )
{
v6[0] = 0LL;
v4 = (unsigned int)func0(a1, a2, v6);
if ( func4(a1, v4) || !func5((__int64)a1, v4) )
result = (unsigned __int64 *)func6((__int64)a1, v6[0], a3);
else
result = buffer_pool_get((__int64)a1, v4);
if ( result )
result = func3(a1, result, v4, v6[0]);
}
else
{
*_errno_location() = 0;
result = 0LL;
}
return result;
}

original_code:
void * diminuto_buffer_pool_get(diminuto_buffer_pool_t * poolp, size_t size, int nomalloc)
{
    void * ptr = (void *)0;
    if (size == 0) {
        (*__errno_location ()) = 0;
    } else {
        diminuto_buffer_meta_t * that = (diminuto_buffer_meta_t *)0;
        size_t item = 0;
        size_t actual = 0;
        diminuto_buffer_t * buffer = (diminuto_buffer_t *)0;
        that = (diminuto_buffer_meta_t *)poolp;
        item = buffer_pool_hash(that, size, &actual);
        if (buffer_pool_isexternal(that, item)) {
            buffer = buffer_pool_malloc(that, actual, nomalloc);
        } else if (buffer_pool_first(that, item) == (diminuto_buffer_t *)0) {
            buffer = buffer_pool_malloc(that, actual, nomalloc);
        } else {
            buffer = buffer_pool_get(that, item);
        }
        if (buffer != (diminuto_buffer_t *)0) {
            ptr = buffer_pool_init(that, buffer, item, actual);
        }
    }
    return ptr;
}

canonical_original_code:
void *diminuto_buffer_pool_get(struct DiminutoBufferPool *poolp, unsigned long size, int nomalloc)
{
    void *ptr = (void *)0;
    if (size == 0) {
        (*__errno_location ()) = 0;
    } else {
        struct DiminutoBufferMeta *that = (diminuto_buffer_meta_t *)0;
        unsigned long item = 0;
        unsigned long actual = 0;
        struct DiminutoBuffer *buffer = (diminuto_buffer_t *)0;
        that = (struct DiminutoBufferMeta *)poolp;
        item = buffer_pool_hash(that, size, &actual);
        if (buffer_pool_isexternal(that, item)) {
            buffer = buffer_pool_malloc(that, actual, nomalloc);
        } else if (buffer_pool_first(that, item) == (struct DiminutoBuffer *)0) {
            buffer = buffer_pool_malloc(that, actual, nomalloc);
        } else {
            buffer = buffer_pool_get(that, item);
        }
        if (buffer != (struct DiminutoBuffer *)0) {
            ptr = buffer_pool_init(that, buffer, item, actual);
        }
    }
    return ptr;
}

variable_types: struct DiminutoBufferPool { unsigned long count; unsigned long *sizes; void **pool; } *

variable_types:
size
unsigned long

variable_types: nomalloc int

variable_types:
ptr
void *

variable_types:
actual
unsigned long

variable_types: struct DiminutoBuffer { unsigned long align[]; union { unsigned long item; struct DiminutoBuffer *next; } header; unsigned long payload[]; } *

return_type: void *


decompiled_code:
void __fastcall diminuto_buffer_pool_put(unsigned __int64 *a1, __int64 a2)
{
_QWORD *v2; // r12
unsigned __int64 v3; // rbp

if ( a2 )
{
v2 = (_QWORD *)(a2 - 8);
v3 = *(_QWORD *)(a2 - 8);
if ( buffer_pool_isexternal(a1, v3) )
free(v2);
else
buffer_pool_put((__int64)a1, v2, v3);
}
}

canonical_decompiled_code:
void __fastcall func8(unsigned __int64 *a1, __int64 a2)
{
_QWORD *v2; // r12
unsigned __int64 v3; // rbp

if ( a2 )
{
v2 = (_QWORD *)(a2 - 8);
v3 = *(_QWORD *)(a2 - 8);
if ( func4(a1, v3) )
free(v2);
else
func2((__int64)a1, v2, v3);
}
}

original_code:
void diminuto_buffer_pool_put(diminuto_buffer_pool_t * poolp, void * ptr)
{
    if (ptr != (void *)0) {
        diminuto_buffer_meta_t * that = (diminuto_buffer_meta_t *)0;
        size_t item = 0;
        diminuto_buffer_t * buffer = (diminuto_buffer_t *)0;
        that = (diminuto_buffer_meta_t *)poolp;
        buffer = ((diminuto_buffer_t *)(((char *)(ptr)) - ((size_t)(((char *)&(((diminuto_buffer_t *)0)->payload)) - ((char *)((diminuto_buffer_t *)0))))));
        item = buffer->header.item;
        if (buffer_pool_isexternal(that, item)) {
            free(buffer);
        } else {
            buffer_pool_put(that, buffer, item);
        }
    }
}

canonical_original_code:
void diminuto_buffer_pool_put(struct DiminutoBufferPool *poolp, void *ptr)
{
    if (ptr != (void *)0) {
        struct DiminutoBufferMeta *that = (diminuto_buffer_meta_t *)0;
        unsigned long item = 0;
        struct DiminutoBuffer *buffer = (diminuto_buffer_t *)0;
        that = (struct DiminutoBufferMeta *)poolp;
        buffer = ((struct DiminutoBuffer *)(((char *)(ptr)) - ((unsigned long)(((char *)&(((struct DiminutoBuffer *)0)->payload)) - ((char *)((struct DiminutoBuffer *)0))))));
        item = buffer->header.item;
        if (buffer_pool_isexternal(that, item)) {
            free(buffer);
        } else {
            buffer_pool_put(that, buffer, item);
        }
    }
}

return_type: void

user_defined_types: struct DiminutoBufferPool { unsigned long count; unsigned long *sizes; void **pool; }

user_defined_types: struct DiminutoBuffer { unsigned long align[]; union { unsigned long item; struct DiminutoBuffer *next; } header; unsigned long payload[]; }


decompiled_code:
_BOOL8 __fastcall diminuto_buffer_pool_free(unsigned __int64 *a1)
{
unsigned __int64 i; // rbx
_QWORD *v3; // rdi
_BOOL8 result; // rax

for ( i = 0LL; ; ++i )
{
result = buffer_pool_isexternal(a1, i);
if ( result )
break;
while ( 1 )
{
v3 = buffer_pool_get((__int64)a1, i);
if ( !v3 )
break;
free(v3);
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(unsigned __int64 *a1)
{
unsigned __int64 i; // rbx
_QWORD *v3; // rdi
_BOOL8 result; // rax

for ( i = 0LL; ; ++i )
{
result = func4(a1, i);
if ( result )
break;
while ( 1 )
{
v3 = buffer_pool_get((__int64)a1, i);
if ( !v3 )
break;
free(v3);
}
}
return result;
}

original_code:
void diminuto_buffer_pool_free(diminuto_buffer_pool_t * poolp)
{
    diminuto_buffer_meta_t * that = (diminuto_buffer_meta_t *)0;
    size_t item = 0;
    diminuto_buffer_t * buffer = (diminuto_buffer_t *)0;
    that = (diminuto_buffer_meta_t *)poolp;
    for (item = 0; !buffer_pool_isexternal(that, item); ++item) {
        while ((buffer = buffer_pool_get(that, item)) != (diminuto_buffer_t *)0) {
            free(buffer);
        }
    }
}

canonical_original_code:
void diminuto_buffer_pool_free(struct DiminutoBufferPool *poolp)
{
    struct DiminutoBufferMeta *that = (diminuto_buffer_meta_t *)0;
    unsigned long item = 0;
    struct DiminutoBuffer *buffer = (diminuto_buffer_t *)0;
    that = (struct DiminutoBufferMeta *)poolp;
    for (item = 0; !buffer_pool_isexternal(that, item); ++item) {
        while ((buffer = buffer_pool_get(that, item)) != (struct DiminutoBuffer *)0) {
            free(buffer);
        }
    }
}


decompiled_code:
__int64 __fastcall diminuto_buffer_pool_prealloc(unsigned __int64 *a1, __int64 a2, unsigned __int64 a3)
{
__int64 v3; // rbx
__int64 v4; // r12
unsigned __int64 v6; // r13
_QWORD *v7; // rsi
size_t v8[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = a2;
v8[0] = 0LL;
if ( !a2 || !a3 )
return 0LL;
v6 = (unsigned int)buffer_pool_hash(a1, a3, v8);
v4 = 0LL;
if ( !buffer_pool_isexternal(a1, v6) )
{
do
{
v7 = buffer_pool_malloc((__int64)a1, v8[0], 0);
if ( !v7 )
break;
buffer_pool_put((__int64)a1, v7, v6);
v4 += v8[0];
--v3;
}
while ( v3 );
}
return v4;
}

original_code:
size_t diminuto_buffer_pool_prealloc(diminuto_buffer_pool_t * poolp, size_t nmemb, size_t size)
{
    size_t total = 0;
    diminuto_buffer_meta_t * that = (diminuto_buffer_meta_t *)0;
    size_t item = 0;
    size_t actual = 0;
    diminuto_buffer_t * buffer = (diminuto_buffer_t *)0;
    that = (diminuto_buffer_meta_t *)poolp;
    if (size == 0) {
    } else if (nmemb == 0) {
    } else if (buffer_pool_isexternal(that, item = buffer_pool_hash(that, size, &actual))) {
    } else {
        while ((nmemb--) > 0) {
            buffer = (diminuto_buffer_t *)buffer_pool_malloc(that, actual, 0);
            if (buffer == (diminuto_buffer_t *)0) {
                break;
            }
            buffer_pool_put(that, buffer, item);
            total += actual;
        }
    }
    return total;
}

canonical_original_code:
unsigned long diminuto_buffer_pool_prealloc(struct DiminutoBufferPool *poolp, unsigned long nmemb, unsigned long size)
{
    unsigned long total = 0;
    struct DiminutoBufferMeta *that = (diminuto_buffer_meta_t *)0;
    unsigned long item = 0;
    unsigned long actual = 0;
    struct DiminutoBuffer *buffer = (diminuto_buffer_t *)0;
    that = (struct DiminutoBufferMeta *)poolp;
    if (size == 0) {
    } else if (nmemb == 0) {
    } else if (buffer_pool_isexternal(that, item = buffer_pool_hash(that, size, &actual))) {
    } else {
        while ((nmemb--) > 0) {
            buffer = (struct DiminutoBuffer *)buffer_pool_malloc(that, actual, 0);
            if (buffer == (struct DiminutoBuffer *)0) {
                break;
            }
            buffer_pool_put(that, buffer, item);
            total += actual;
        }
    }
    return total;
}

variable_types:
nmemb
unsigned long

variable_types:
total
unsigned long


decompiled_code:
__int64 __fastcall diminuto_buffer_pool_log(unsigned __int64 *a1)
{
__int64 v1; // r14
unsigned __int64 v2; // rbp
__int64 v3; // r13
__int64 v4; // rbx
unsigned __int64 v5; // rcx
__int64 v6; // rax
_QWORD *v7; // rax

v1 = 0LL;
v2 = 0LL;
v3 = 0LL;
while ( !buffer_pool_isexternal(a1, v2) )
{
v7 = (_QWORD *)buffer_pool_first((__int64)a1, v2);
if ( v7 )
{
v4 = 0LL;
do
{
++v4;
v7 = (_QWORD *)*v7;
}
while ( v7 );
}
else
{
v4 = 0LL;
}
v5 = buffer_pool_size(a1, v2);
v6 = v4 * (v5 + 8);
v1 += v4;
v3 += v6;
diminuto_log_emit(
"diminuto_buffer_pool_log: pool=%p index=%zu length=%zubytes size=%zubytes subcount=%zu subtotal=%zubytes\n",
a1,
v2++,
v5,
v5 + 8,
v4,
v6);
}
diminuto_log_emit("diminuto_buffer_pool_log: pool=%p count=%zu total=%zubytes\n", a1, v1, v3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int64 *a1)
{
__int64 v1; // r14
unsigned __int64 v2; // rbp
__int64 v3; // r13
__int64 v4; // rbx
unsigned __int64 v5; // rcx
__int64 v6; // rax
_QWORD *v7; // rax

v1 = 0LL;
v2 = 0LL;
v3 = 0LL;
while ( !func4(a1, v2) )
{
v7 = (_QWORD *)func5((__int64)a1, v2);
if ( v7 )
{
v4 = 0LL;
do
{
++v4;
v7 = (_QWORD *)*v7;
}
while ( v7 );
}
else
{
v4 = 0LL;
}
v5 = func1(a1, v2);
v6 = v4 * (v5 + 8);
v1 += v4;
v3 += v6;
diminuto_log_emit(
"diminuto_buffer_pool_log: pool=%p index=%zu length=%zubytes size=%zubytes subcount=%zu subtotal=%zubytes\n",
a1,
v2++,
v5,
v5 + 8,
v4,
v6);
}
diminuto_log_emit("diminuto_buffer_pool_log: pool=%p count=%zu total=%zubytes\n", a1, v1, v3);
return v3;
}

original_code:
size_t diminuto_buffer_pool_log(diminuto_buffer_pool_t * poolp)
{
    size_t total = 0;
    diminuto_buffer_meta_t * that = (diminuto_buffer_meta_t *)0;
    size_t subtotal = 0;
    size_t item = 0;
    size_t count = 0;
    size_t subcount = 0;
    size_t length = 0;
    size_t size = 0;
    diminuto_buffer_t * buffer = (diminuto_buffer_t *)0;
    that = (diminuto_buffer_meta_t *)poolp;
    total = 0;
    count = 0;
    for (item = 0; !buffer_pool_isexternal(that, item); ++item) {
        subcount = 0;
        for (buffer = buffer_pool_first(that, item); buffer != (diminuto_buffer_t *)0; buffer = buffer->header.next) {
            ++subcount;
        }
        length = buffer_pool_size(that, item);
        size = length + sizeof(diminuto_buffer_t);
        subtotal = subcount * size;
        count += subcount;
        total += subtotal;
        diminuto_log_emit("diminuto_buffer_pool_log: pool=%p index=%zu length=%zubytes size=%zubytes subcount=%zu subtotal=%zubytes\n", poolp, item, length, size, subcount, subtotal);
    }
    diminuto_log_emit("diminuto_buffer_pool_log: pool=%p count=%zu total=%zubytes\n", poolp, count, total);
    return total;
}

canonical_original_code:
unsigned long diminuto_buffer_pool_log(struct DiminutoBufferPool *poolp)
{
    unsigned long total = 0;
    struct DiminutoBufferMeta *that = (diminuto_buffer_meta_t *)0;
    unsigned long subtotal = 0;
    unsigned long item = 0;
    unsigned long count = 0;
    unsigned long subcount = 0;
    unsigned long length = 0;
    unsigned long size = 0;
    struct DiminutoBuffer *buffer = (diminuto_buffer_t *)0;
    that = (struct DiminutoBufferMeta *)poolp;
    total = 0;
    count = 0;
    for (item = 0; !buffer_pool_isexternal(that, item); ++item) {
        subcount = 0;
        for (buffer = buffer_pool_first(that, item); buffer != (struct DiminutoBuffer *)0; buffer = buffer->header.next) {
            ++subcount;
        }
        length = buffer_pool_size(that, item);
        size = length + sizeof(diminuto_buffer_t);
        subtotal = subcount * size;
        count += subcount;
        total += subtotal;
        diminuto_log_emit("diminuto_buffer_pool_log: pool=%p index=%zu length=%zubytes size=%zubytes subcount=%zu subtotal=%zubytes\n", poolp, item, length, size, subcount, subtotal);
    }
    diminuto_log_emit("diminuto_buffer_pool_log: pool=%p count=%zu total=%zubytes\n", poolp, count, total);
    return total;
}

variable_types:
subtotal
unsigned long

variable_types:
count
unsigned long

variable_types:
subcount
unsigned long

variable_types:
length
unsigned long


original_code:
int diminuto_serial_set(int fd, int bitspersecond, int databits, int paritybit, int stopbits, int modemcontrol, int xonxoff, int rtscts)
{
    int rc = -1;
    int error = 0;
    struct termios tios = { 0 };
    int speed;
    int data;
    int parity;
    int stop;
    int clocal;
    int hupcl;
    int ixon;
    int ixoff;
    int crtscts;
    do {
        switch (bitspersecond) {
        case -1:
            break;
        case 0:
            speed = 0000000;
            break;
        case 50:
            speed = 0000001;
            break;
        case 75:
            speed = 0000002;
            break;
        case 110:
            speed = 0000003;
            break;
        case 134:
            speed = 0000004;
            break;
        case 150:
            speed = 0000005;
            break;
        case 200:
            speed = 0000006;
            break;
        case 300:
            speed = 0000007;
            break;
        case 600:
            speed = 0000010;
            break;
        case 1200:
            speed = 0000011;
            break;
        case 1800:
            speed = 0000012;
            break;
        case 2400:
            speed = 0000013;
            break;
        case 4800:
            speed = 0000014;
            break;
        case 9600:
            speed = 0000015;
            break;
        case 19200:
            speed = 0000016;
            break;
        case 38400:
            speed = 0000017;
            break;
        case 57600:
            speed = 0010001;
            break;
        case 115200:
            speed = 0010002;
            break;
        case 230400:
            speed = 0010003;
            break;
        default:
            bitspersecond = -1;
            error = !0;
            (*__errno_location ()) = 22;
            diminuto_log_perror("src/diminuto_serial.c", 103, "diminuto_serial_set: bitspersecond");
            break;
        }
        switch (databits) {
        case 5:
            data = 0000000;
            break;
        case 6:
            data = 0000020;
            break;
        case 7:
            data = 0000040;
            break;
        case 8:
            data = 0000060;
            break;
        default:
            error = !0;
            (*__errno_location ()) = 22;
            diminuto_log_perror("src/diminuto_serial.c", 123, "diminuto_serial_set: databits");
            break;
        }
        if (paritybit == 0) {
            parity = 0;
        } else if ((paritybit % 2) != 0) {
            parity = 0000400 | 0001000;
        } else {
            parity = 0000400;
        }
        switch (stopbits) {
        case 1:
            stop = 0;
            break;
        case 2:
            stop = 0000100;
            break;
        default:
            error = !0;
            (*__errno_location ()) = 22;
            diminuto_log_perror("src/diminuto_serial.c", 145, "diminuto_serial_set: stopbits");
            break;
        }
        if (modemcontrol) {
            clocal = 0;
            hupcl = 0002000;
        } else {
            clocal = 0004000;
            hupcl = 0;
        }
        if (xonxoff) {
            ixon = 0002000;
            ixoff = 0010000;
        } else {
            ixon = 0;
            ixoff = 0;
        }
        if (rtscts) {
            crtscts = 020000000000;
        } else {
            crtscts = 0;
        }
        if (error) {
            break;
        }
        if (!isatty(fd)) {
            (*__errno_location ()) = 25;
            diminuto_log_perror("src/diminuto_serial.c", 177, "diminuto_serial_set: isatty");
            break;
        }
        if (tcgetattr(fd, &tios) < 0) {
            diminuto_log_perror("src/diminuto_serial.c", 182, "diminuto_serial_set: tcgetattr");
            break;
        }
        tios.c_iflag &= ~(0000001 | 0000002 | 0000010 | 0000040 | 0000100 | 0000200 | 0000400 | 0002000 | 0010000);
        tios.c_oflag &= ~(0000001);
        tios.c_cflag &= ~(0000060 | 0000400 | 0001000 | 0000100 | 0004000 | 0002000 | 020000000000);
        tios.c_lflag &= ~(0000010 | 0000100 | 0000002 | 0000001 | 0100000);
        tios.c_iflag |= ixon;
        tios.c_iflag |= ixoff;
        tios.c_cflag |= 0000200;
        tios.c_cflag |= data;
        tios.c_cflag |= parity;
        tios.c_cflag |= stop;
        tios.c_cflag |= clocal;
        tios.c_cflag |= hupcl;
        tios.c_cflag |= crtscts;
        if (bitspersecond >= 0) {
            if (cfsetospeed(&tios, speed) < 0) {
                diminuto_log_perror("src/diminuto_serial.c", 204, "diminuto_serial_set: cfsetospeed");
                break;
            }
            if (cfsetispeed(&tios, speed) < 0) {
                diminuto_log_perror("src/diminuto_serial.c", 208, "diminuto_serial_set: cfsetispeed");
                break;
            }
        }
        tios.c_cc[5] = 0;
        tios.c_cc[6] = 1;
        if (tcsetattr(fd, 0, &tios) < 0) {
            diminuto_log_perror("src/diminuto_serial.c", 217, "diminuto_serial_set: tcsetattr");
            break;
        }
        if (tcflush(fd, 2) < 0) {
            diminuto_log_perror("src/diminuto_serial.c", 222, "diminuto_serial_set: tcflush");
        }
        rc = 0;
    } while (0);
    return rc;
}

variable_types: fd int

variable_types: bitspersecond int

variable_types: databits int

variable_types: paritybit int

variable_types: stopbits int

variable_types: modemcontrol int

variable_types: xonxoff int

variable_types: rtscts int

variable_types: rc int

variable_types: error int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: speed int

variable_types: data int

variable_types: parity int

variable_types: stop int

variable_types: clocal int

variable_types: hupcl int

variable_types: ixon int

variable_types: ixoff int

variable_types: crtscts int

return_type: int


decompiled_code:
__int64 __fastcall diminuto_serial_raw(int fd)
{
int v1; // edx
__int64 result; // rax
struct termios v3; // [rsp+0h] [rbp-48h] BYREF

*(_QWORD *)&v3.c_iflag = 0LL;
*(_QWORD *)&v3.c_cflag = 0LL;
*(_QWORD *)&v3.c_line = 0LL;
*(_QWORD *)&v3.c_cc[7] = 0LL;
*(_QWORD *)&v3.c_cc[15] = 0LL;
*(_QWORD *)&v3.c_cc[23] = 0LL;
*(_QWORD *)&v3.c_cc[31] = 0LL;
v3.c_ospeed = 0;
if ( isatty(fd) )
{
if ( tcgetattr(fd, &v3) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 247LL, "diminuto_serial_raw: tcgetattr");
result = 0xFFFFFFFFLL;
}
else
{
v3.c_iflag &= 0xFFFFFA14;
v3.c_oflag &= 0xFFFFFFFE;
v3.c_cflag = v3.c_cflag & 0xFFFFFECF | 0x8B0;
v3.c_lflag &= 0xFFFF7FB4;
*(_WORD *)&v3.c_cc[5] = 256;
if ( tcsetattr(fd, 0, &v3) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 263LL, "diminuto_serial_raw: tcsetattr");
result = 0xFFFFFFFFLL;
}
else
{
v1 = tcflush(fd, 2);
result = 0LL;
if ( v1 < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 268LL, "diminuto_serial_raw: tcflush");
result = 0LL;
}
}
}
}
else
{
*_errno_location() = 22;
diminuto_log_perror("src/diminuto_serial.c", 242LL, "diminuto_serial_raw: isatty");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd)
{
int v1; // edx
__int64 result; // rax
struct termios v3; // [rsp+0h] [rbp-48h] BYREF

*(_QWORD *)&v3.c_iflag = 0LL;
*(_QWORD *)&v3.c_cflag = 0LL;
*(_QWORD *)&v3.c_line = 0LL;
*(_QWORD *)&v3.c_cc[7] = 0LL;
*(_QWORD *)&v3.c_cc[15] = 0LL;
*(_QWORD *)&v3.c_cc[23] = 0LL;
*(_QWORD *)&v3.c_cc[31] = 0LL;
v3.c_ospeed = 0;
if ( isatty(fd) )
{
if ( tcgetattr(fd, &v3) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 247LL, "diminuto_serial_raw: tcgetattr");
result = 0xFFFFFFFFLL;
}
else
{
v3.c_iflag &= 0xFFFFFA14;
v3.c_oflag &= 0xFFFFFFFE;
v3.c_cflag = v3.c_cflag & 0xFFFFFECF | 0x8B0;
v3.c_lflag &= 0xFFFF7FB4;
*(_WORD *)&v3.c_cc[5] = 256;
if ( tcsetattr(fd, 0, &v3) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 263LL, "diminuto_serial_raw: tcsetattr");
result = 0xFFFFFFFFLL;
}
else
{
v1 = tcflush(fd, 2);
result = 0LL;
if ( v1 < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 268LL, "diminuto_serial_raw: tcflush");
result = 0LL;
}
}
}
}
else
{
*_errno_location() = 22;
diminuto_log_perror("src/diminuto_serial.c", 242LL, "diminuto_serial_raw: isatty");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int diminuto_serial_raw(int fd)
{
    int rc = -1;
    struct termios tios = { 0 };
    do {
        if (!isatty(fd)) {
            (*__errno_location ()) = 22;
            diminuto_log_perror("src/diminuto_serial.c", 242, "diminuto_serial_raw: isatty");
            break;
        }
        if (tcgetattr(fd, &tios) < 0) {
            diminuto_log_perror("src/diminuto_serial.c", 247, "diminuto_serial_raw: tcgetattr");
            break;
        }
        tios.c_iflag &= ~(0000001 | 0000002 | 0000010 | 0000040 | 0000100 | 0000200 | 0000400 | 0002000 );
        tios.c_oflag &= ~0000001;
        tios.c_cflag &= ~(0000060 | 0000400);
        tios.c_cflag |= (0000060 | 0000200 | 0004000);
        tios.c_lflag &= ~(0000010 | 0000100 | 0000002 | 0000001 | 0100000);
        tios.c_cc[5] = 0;
        tios.c_cc[6] = 1;
        if (tcsetattr(fd, 0, &tios) < 0) {
            diminuto_log_perror("src/diminuto_serial.c", 263, "diminuto_serial_raw: tcsetattr");
            break;
        }
        if (tcflush(fd, 2) < 0) {
            diminuto_log_perror("src/diminuto_serial.c", 268, "diminuto_serial_raw: tcflush");
        }
        rc = 0;
    } while (0);
    return rc;
}

variable_types: fd int

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall diminuto_serial_wait(int fd)
{
__int64 result; // rax

if ( isatty(fd) )
{
if ( ioctl(fd, 0x545CuLL, 64LL) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 316LL, "diminuto_serial_wait: ioctl(TIOCMIWAIT)");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
*_errno_location() = 22;
diminuto_log_perror("src/diminuto_serial.c", 311LL, "diminuto_serial_wait: isatty");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( isatty(fd) )
{
if ( ioctl(fd, 0x545CuLL, 64LL) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 316LL, "diminuto_serial_wait: ioctl(TIOCMIWAIT)");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
*_errno_location() = 22;
diminuto_log_perror("src/diminuto_serial.c", 311LL, "diminuto_serial_wait: isatty");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int diminuto_serial_wait(int fd)
{
    int rc = -1;
    do {
        if (!isatty(fd)) {
            (*__errno_location ()) = 22;
            diminuto_log_perror("src/diminuto_serial.c", 311, "diminuto_serial_wait: isatty");
            break;
        }
        if (ioctl(fd, 0x545C, 0x040) < 0) {
            diminuto_log_perror("src/diminuto_serial.c", 316, "diminuto_serial_wait: ioctl(TIOCMIWAIT)");
            break;
        }
        rc = 0;
    } while (0);
    return rc;
}


decompiled_code:
__int64 __fastcall diminuto_serial_status(int fd)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = -2;
if ( isatty(fd) )
{
if ( ioctl(fd, 0x5415uLL, v2) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 352LL, "diminuto_serial_status: ioctl(TIOCMGET)");
result = 0xFFFFFFFFLL;
}
else
{
result = (v2[0] >> 6) & 1;
}
}
else
{
*_errno_location() = 22;
diminuto_log_perror("src/diminuto_serial.c", 347LL, "diminuto_serial_status: isatty");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = -2;
if ( isatty(fd) )
{
if ( ioctl(fd, 0x5415uLL, v2) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 352LL, "diminuto_serial_status: ioctl(TIOCMGET)");
result = 0xFFFFFFFFLL;
}
else
{
result = (v2[0] >> 6) & 1;
}
}
else
{
*_errno_location() = 22;
diminuto_log_perror("src/diminuto_serial.c", 347LL, "diminuto_serial_status: isatty");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int diminuto_serial_status(int fd)
{
    int rc = -1;
    int status = -2;
    do {
        if (!isatty(fd)) {
            (*__errno_location ()) = 22;
            diminuto_log_perror("src/diminuto_serial.c", 347, "diminuto_serial_status: isatty");
            break;
        }
        if (ioctl(fd, 0x5415, &status) < 0) {
            diminuto_log_perror("src/diminuto_serial.c", 352, "diminuto_serial_status: ioctl(TIOCMGET)");
            break;
        }
        rc = !!(status & 0x040);
    } while (0);
    return rc;
}

variable_types: status int


decompiled_code:
__int64 __fastcall diminuto_serial_available(int fd)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = -2;
if ( isatty(fd) )
{
if ( ioctl(fd, 0x541BuLL, v2) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 378LL, "diminuto_serial_available: ioctl(FIONREAD)");
result = 0xFFFFFFFFLL;
}
else
{
result = v2[0];
}
}
else
{
*_errno_location() = 22;
diminuto_log_perror("src/diminuto_serial.c", 373LL, "diminuto_serial_available: isatty");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = -2;
if ( isatty(fd) )
{
if ( ioctl(fd, 0x541BuLL, v2) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 378LL, "diminuto_serial_available: ioctl(FIONREAD)");
result = 0xFFFFFFFFLL;
}
else
{
result = v2[0];
}
}
else
{
*_errno_location() = 22;
diminuto_log_perror("src/diminuto_serial.c", 373LL, "diminuto_serial_available: isatty");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int diminuto_serial_available(int fd)
{
    int rc = -1;
    int bytes = -2;
    do {
        if (!isatty(fd)) {
            (*__errno_location ()) = 22;
            diminuto_log_perror("src/diminuto_serial.c", 373, "diminuto_serial_available: isatty");
            break;
        }
        if (ioctl(fd, 0x541B, &bytes) < 0) {
            diminuto_log_perror("src/diminuto_serial.c", 378, "diminuto_serial_available: ioctl(FIONREAD)");
            break;
        }
        rc = bytes;
    } while (0);
    return rc;
}

variable_types: bytes int


decompiled_code:
_BOOL8 __fastcall diminuto_serial_valid(int a1)
{
return isatty(a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(int a1)
{
return isatty(a1) != 0;
}

original_code:
int diminuto_serial_valid(int fd)
{
    return !!isatty(fd);
}


decompiled_code:
__int64 __fastcall diminuto_i2c_open(unsigned int a1)
{
int v1; // ebx
char s[8]; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+Ch] [rbp-Ch]

*(_QWORD *)s = 0LL;
v4 = 0;
snprintf(s, 0xCuLL, "/dev/i2c-%d", a1);
HIBYTE(v4) = 0;
v1 = open(s, 2);
if ( v1 < 0 )
diminuto_log_perror("src/diminuto_i2c.c", 46LL, "diminuto_i2c_open: open");
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
int v1; // ebx
char s[8]; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+Ch] [rbp-Ch]

*(_QWORD *)s = 0LL;
v4 = 0;
snprintf(s, 0xCuLL, "/dev/i2c-%d", a1);
HIBYTE(v4) = 0;
v1 = open(s, 2);
if ( v1 < 0 )
diminuto_log_perror("src/diminuto_i2c.c", 46LL, "diminuto_i2c_open: open");
return (unsigned int)v1;
}

original_code:
int diminuto_i2c_open(int bus)
{
    int fd = -1;
    char buffer[sizeof(DIMINUTO_I2C_FILENAME)] = { '\0' };
    snprintf(buffer, sizeof(buffer), DIMINUTO_I2C_FILENAME, bus);
    buffer[sizeof(buffer) - 1] = '\0';
    if ((fd = open(buffer, 02)) < 0) {
        diminuto_log_perror("src/diminuto_i2c.c", 46, "diminuto_i2c_open: open");
    }
    return fd;
}

canonical_original_code:
int diminuto_i2c_open(int bus)
{
    int fd = -1;
    char buffer[-1] = { '\0' };
    snprintf(buffer, sizeof(buffer), DIMINUTO_I2C_FILENAME, bus);
    buffer[sizeof(buffer) - 1] = '\0';
    if ((fd = open(buffer, 02)) < 0) {
        diminuto_log_perror("src/diminuto_i2c.c", 46, "diminuto_i2c_open: open");
    }
    return fd;
}

variable_types: bus int

variable_types:
buffer
char [-1]


decompiled_code:
__int64 __fastcall diminuto_i2c_use(int a1, unsigned __int8 a2)
{
int v2; // ebx

v2 = ioctl(a1, 0x703uLL, a2);
if ( v2 < 0 )
diminuto_log_perror("src/diminuto_i2c.c", 57LL, "diminuto_i2c_use: ioctl");
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, unsigned __int8 a2)
{
int v2; // ebx

v2 = ioctl(a1, 0x703uLL, a2);
if ( v2 < 0 )
diminuto_log_perror("src/diminuto_i2c.c", 57LL, "diminuto_i2c_use: ioctl");
return (unsigned int)v2;
}

original_code:
int diminuto_i2c_use(int fd, uint8_t addr)
{
    int rc = -1;
    if ((rc = ioctl(fd, 0x0703, addr)) < 0) {
        diminuto_log_perror("src/diminuto_i2c.c", 57, "diminuto_i2c_use: ioctl");
    }
    return rc;
}

canonical_original_code:
int diminuto_i2c_use(int fd, unsigned char addr)
{
    int rc = -1;
    if ((rc = ioctl(fd, 0x0703, addr)) < 0) {
        diminuto_log_perror("src/diminuto_i2c.c", 57, "diminuto_i2c_use: ioctl");
    }
    return rc;
}

variable_types:
addr
unsigned char

variable_types: rc int


decompiled_code:
__int64 __fastcall diminuto_i2c_read(int a1, void *a2, size_t a3)
{
ssize_t v4; // rax
__int64 v5; // rbx

v4 = read(a1, a2, a3);
v5 = v4;
if ( v4 < 0 )
{
diminuto_log_perror("src/diminuto_i2c.c", 68LL, "diminuto_i2c_read: read");
}
else if ( v4 > a3 )
{
*_errno_location() = 7;
diminuto_log_perror("src/diminuto_i2c.c", 71LL, "diminuto_i2c_read: read");
v5 = -1LL;
}
else if ( !v4 )
{
*_errno_location() = 19;
diminuto_log_perror("src/diminuto_i2c.c", 75LL, "diminuto_i2c_read: read");
v5 = -1LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, void *a2, size_t a3)
{
ssize_t v4; // rax
__int64 v5; // rbx

v4 = read(a1, a2, a3);
v5 = v4;
if ( v4 < 0 )
{
diminuto_log_perror("src/diminuto_i2c.c", 68LL, "diminuto_i2c_read: read");
}
else if ( v4 > a3 )
{
*_errno_location() = 7;
diminuto_log_perror("src/diminuto_i2c.c", 71LL, "diminuto_i2c_read: read");
v5 = -1LL;
}
else if ( !v4 )
{
*_errno_location() = 19;
diminuto_log_perror("src/diminuto_i2c.c", 75LL, "diminuto_i2c_read: read");
v5 = -1LL;
}
return v5;
}

original_code:
ssize_t diminuto_i2c_read(int fd, void * bufferp, size_t size)
{
    ssize_t rc = -1;
    if ((rc = read(fd, bufferp, size)) < 0) {
        diminuto_log_perror("src/diminuto_i2c.c", 68, "diminuto_i2c_read: read");
    } else if (rc > size) {
        (*__errno_location ()) = 7;
        diminuto_log_perror("src/diminuto_i2c.c", 71, "diminuto_i2c_read: read");
        rc = -1;
    } else if (rc == 0) {
        (*__errno_location ()) = 19;
        diminuto_log_perror("src/diminuto_i2c.c", 75, "diminuto_i2c_read: read");
        rc = -1;
    } else {
    }
    return rc;
}

canonical_original_code:
long diminuto_i2c_read(int fd, void *bufferp, unsigned long size)
{
    long rc = -1;
    if ((rc = read(fd, bufferp, size)) < 0) {
        diminuto_log_perror("src/diminuto_i2c.c", 68, "diminuto_i2c_read: read");
    } else if (rc > size) {
        (*__errno_location ()) = 7;
        diminuto_log_perror("src/diminuto_i2c.c", 71, "diminuto_i2c_read: read");
        rc = -1;
    } else if (rc == 0) {
        (*__errno_location ()) = 19;
        diminuto_log_perror("src/diminuto_i2c.c", 75, "diminuto_i2c_read: read");
        rc = -1;
    } else {
    }
    return rc;
}

variable_types:
bufferp
void *

variable_types:
size
unsigned long

variable_types: rc long


decompiled_code:
__int64 __fastcall diminuto_i2c_write(int a1, const void *a2, size_t a3)
{
ssize_t v4; // rax
__int64 v5; // rbx

v4 = write(a1, a2, a3);
v5 = v4;
if ( v4 < 0 )
{
diminuto_log_perror("src/diminuto_i2c.c", 89LL, "diminuto_i2c_write: write");
}
else if ( v4 > a3 )
{
*_errno_location() = 7;
diminuto_log_perror("src/diminuto_i2c.c", 92LL, "diminuto_i2c_write: write");
v5 = -1LL;
}
else if ( !v4 )
{
*_errno_location() = 19;
diminuto_log_perror("src/diminuto_i2c.c", 96LL, "diminuto_i2c_write: write");
v5 = -1LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, const void *a2, size_t a3)
{
ssize_t v4; // rax
__int64 v5; // rbx

v4 = write(a1, a2, a3);
v5 = v4;
if ( v4 < 0 )
{
diminuto_log_perror("src/diminuto_i2c.c", 89LL, "diminuto_i2c_write: write");
}
else if ( v4 > a3 )
{
*_errno_location() = 7;
diminuto_log_perror("src/diminuto_i2c.c", 92LL, "diminuto_i2c_write: write");
v5 = -1LL;
}
else if ( !v4 )
{
*_errno_location() = 19;
diminuto_log_perror("src/diminuto_i2c.c", 96LL, "diminuto_i2c_write: write");
v5 = -1LL;
}
return v5;
}

original_code:
ssize_t diminuto_i2c_write(int fd, const void * bufferp, size_t size)
{
    ssize_t rc = -1;
    if ((rc = write(fd, bufferp, size)) < 0) {
        diminuto_log_perror("src/diminuto_i2c.c", 89, "diminuto_i2c_write: write");
    } else if (rc > size) {
        (*__errno_location ()) = 7;
        diminuto_log_perror("src/diminuto_i2c.c", 92, "diminuto_i2c_write: write");
        rc = -1;
    } else if (rc == 0) {
        (*__errno_location ()) = 19;
        diminuto_log_perror("src/diminuto_i2c.c", 96, "diminuto_i2c_write: write");
        rc = -1;
    } else {
    }
    return rc;
}

canonical_original_code:
long diminuto_i2c_write(int fd, void *bufferp, unsigned long size)
{
    long rc = -1;
    if ((rc = write(fd, bufferp, size)) < 0) {
        diminuto_log_perror("src/diminuto_i2c.c", 89, "diminuto_i2c_write: write");
    } else if (rc > size) {
        (*__errno_location ()) = 7;
        diminuto_log_perror("src/diminuto_i2c.c", 92, "diminuto_i2c_write: write");
        rc = -1;
    } else if (rc == 0) {
        (*__errno_location ()) = 19;
        diminuto_log_perror("src/diminuto_i2c.c", 96, "diminuto_i2c_write: write");
        rc = -1;
    } else {
    }
    return rc;
}


decompiled_code:
__int64 __fastcall diminuto_i2c_close(unsigned int a1)
{
if ( close(a1) >= 0 )
return 0xFFFFFFFFLL;
diminuto_log_perror("src/diminuto_i2c.c", 108LL, "close");
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
if ( close(a1) >= 0 )
return 0xFFFFFFFFLL;
diminuto_log_perror("src/diminuto_i2c.c", 108LL, "close");
return a1;
}

original_code:
int diminuto_i2c_close(int fd)
{
    if (close(fd) < 0) {
        diminuto_log_perror("src/diminuto_i2c.c", 108, "close");
    } else {
        fd = -1;
    }
    return fd;
}


decompiled_code:
__int64 __fastcall diminuto_i2c_get(int a1, unsigned __int8 a2, char a3, void *a4, size_t a5)
{
int v5; // ebx
char v9[4]; // [rsp+1Ch] [rbp-8Ch] BYREF
__pthread_unwind_buf_t buf; // [rsp+20h] [rbp-88h] BYREF

v9[0] = a3;
if ( (unsigned int)diminuto_criticalsection_lock(&diminuto_i2c_mutex) )
{
v5 = -1;
}
else
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
_pthread_unwind_next(&buf);
}
_pthread_register_cancel(&buf);
v5 = diminuto_i2c_use(a1, a2);
if ( v5 >= 0 )
{
v5 = diminuto_i2c_write(a1, v9, 1uLL);
if ( v5 >= 0 )
v5 = diminuto_i2c_read(a1, a4, a5);
}
_pthread_unregister_cancel(&buf);
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, unsigned __int8 a2, char a3, void *a4, size_t a5)
{
int v5; // ebx
char v9[4]; // [rsp+1Ch] [rbp-8Ch] BYREF
__pthread_unwind_buf_t buf; // [rsp+20h] [rbp-88h] BYREF

v9[0] = a3;
if ( (unsigned int)diminuto_criticalsection_lock(&diminuto_i2c_mutex) )
{
v5 = -1;
}
else
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
_pthread_unwind_next(&buf);
}
_pthread_register_cancel(&buf);
v5 = func1(a1, a2);
if ( v5 >= 0 )
{
v5 = func3(a1, v9, 1uLL);
if ( v5 >= 0 )
v5 = func2(a1, a4, a5);
}
_pthread_unregister_cancel(&buf);
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
}
return (unsigned int)v5;
}

original_code:
int diminuto_i2c_get(int fd, uint8_t addr, uint8_t reg, void * bufferp, size_t size)
{
    int rc = -1;
    do { pthread_mutex_t * _diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&diminuto_i2c_mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        if ((rc = diminuto_i2c_use(fd, addr)) < 0) {
        } else if ((rc = diminuto_i2c_write(fd, &reg, sizeof(reg))) < 0) {
        } else {
            rc = diminuto_i2c_read(fd, bufferp, size);
        }
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    return rc;
}

canonical_original_code:
int diminuto_i2c_get(int fd, unsigned char addr, unsigned char reg, void *bufferp, unsigned long size)
{
    int rc = -1;
    do { union pthread_mutex_t *_diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&diminuto_i2c_mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        if ((rc = diminuto_i2c_use(fd, addr)) < 0) {
        } else if ((rc = diminuto_i2c_write(fd, &reg, sizeof(reg))) < 0) {
        } else {
            rc = diminuto_i2c_read(fd, bufferp, size);
        }
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    return rc;
}

variable_types:
reg
unsigned char

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

variable_types: struct __pthread_unwind_buf_t { struct { long __cancel_jmp_buf[8]; int __mask_was_saved; } __cancel_jmp_buf[1]; void *__pad[4]; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall diminuto_i2c_set(int a1, unsigned __int8 a2, char a3, const void *a4, size_t a5)
{
int v5; // ebx
char v9[4]; // [rsp+1Ch] [rbp-8Ch] BYREF
__pthread_unwind_buf_t buf; // [rsp+20h] [rbp-88h] BYREF

v9[0] = a3;
if ( (unsigned int)diminuto_criticalsection_lock(&diminuto_i2c_mutex) )
{
v5 = -1;
}
else
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
_pthread_unwind_next(&buf);
}
_pthread_register_cancel(&buf);
v5 = diminuto_i2c_use(a1, a2);
if ( v5 >= 0 )
{
v5 = diminuto_i2c_write(a1, v9, 1uLL);
if ( v5 >= 0 )
v5 = diminuto_i2c_write(a1, a4, a5);
}
_pthread_unregister_cancel(&buf);
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, unsigned __int8 a2, char a3, const void *a4, size_t a5)
{
int v5; // ebx
char v9[4]; // [rsp+1Ch] [rbp-8Ch] BYREF
__pthread_unwind_buf_t buf; // [rsp+20h] [rbp-88h] BYREF

v9[0] = a3;
if ( (unsigned int)diminuto_criticalsection_lock(&diminuto_i2c_mutex) )
{
v5 = -1;
}
else
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
_pthread_unwind_next(&buf);
}
_pthread_register_cancel(&buf);
v5 = func1(a1, a2);
if ( v5 >= 0 )
{
v5 = func3(a1, v9, 1uLL);
if ( v5 >= 0 )
v5 = func3(a1, a4, a5);
}
_pthread_unregister_cancel(&buf);
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
}
return (unsigned int)v5;
}

original_code:
int diminuto_i2c_set(int fd, uint8_t addr, uint8_t reg, const void * datap, size_t size)
{
    int rc = -1;
    do { pthread_mutex_t * _diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&diminuto_i2c_mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        if ((rc = diminuto_i2c_use(fd, addr)) < 0) {
        } else if ((rc = diminuto_i2c_write(fd, &reg, sizeof(reg))) < 0) {
        } else {
            rc = diminuto_i2c_write(fd, datap, size);
        }
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    return rc;
}

canonical_original_code:
int diminuto_i2c_set(int fd, unsigned char addr, unsigned char reg, void *datap, unsigned long size)
{
    int rc = -1;
    do { union pthread_mutex_t *_diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&diminuto_i2c_mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        if ((rc = diminuto_i2c_use(fd, addr)) < 0) {
        } else if ((rc = diminuto_i2c_write(fd, &reg, sizeof(reg))) < 0) {
        } else {
            rc = diminuto_i2c_write(fd, datap, size);
        }
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    return rc;
}

variable_types:
datap
void *

user_defined_types: struct __pthread_unwind_buf_t { struct { long __cancel_jmp_buf[8]; int __mask_was_saved; } __cancel_jmp_buf[1]; void *__pad[4]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall diminuto_i2c_send(int a1, unsigned __int8 a2, const void *a3, size_t a4)
{
int v4; // ebx
__pthread_unwind_buf_t buf; // [rsp+20h] [rbp-88h] BYREF

if ( (unsigned int)diminuto_criticalsection_lock(&diminuto_i2c_mutex) )
{
v4 = -1;
}
else
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
_pthread_unwind_next(&buf);
}
_pthread_register_cancel(&buf);
v4 = diminuto_i2c_use(a1, a2);
if ( v4 >= 0 )
v4 = diminuto_i2c_write(a1, a3, a4);
_pthread_unregister_cancel(&buf);
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned __int8 a2, const void *a3, size_t a4)
{
int v4; // ebx
__pthread_unwind_buf_t buf; // [rsp+20h] [rbp-88h] BYREF

if ( (unsigned int)diminuto_criticalsection_lock(&diminuto_i2c_mutex) )
{
v4 = -1;
}
else
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
_pthread_unwind_next(&buf);
}
_pthread_register_cancel(&buf);
v4 = func1(a1, a2);
if ( v4 >= 0 )
v4 = func3(a1, a3, a4);
_pthread_unregister_cancel(&buf);
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
}
return (unsigned int)v4;
}

original_code:
int diminuto_i2c_send(int fd, uint8_t addr, const void * datap, size_t size)
{
    int rc = -1;
    do { pthread_mutex_t * _diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&diminuto_i2c_mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        if ((rc = diminuto_i2c_use(fd, addr)) < 0) {
        } else {
            rc = diminuto_i2c_write(fd, datap, size);
        }
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    return rc;
}

canonical_original_code:
int diminuto_i2c_send(int fd, unsigned char addr, void *datap, unsigned long size)
{
    int rc = -1;
    do { union pthread_mutex_t *_diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&diminuto_i2c_mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        if ((rc = diminuto_i2c_use(fd, addr)) < 0) {
        } else {
            rc = diminuto_i2c_write(fd, datap, size);
        }
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    return rc;
}


decompiled_code:
__int64 __fastcall diminuto_i2c_get_set(int a1, unsigned __int8 a2, char a3, void *a4, const void *a5, size_t a6)
{
int v7; // [rsp+8h] [rbp-B0h]
char v11[4]; // [rsp+2Ch] [rbp-8Ch] BYREF
__pthread_unwind_buf_t buf; // [rsp+30h] [rbp-88h] BYREF

v11[0] = a3;
v7 = -1;
if ( !(unsigned int)diminuto_criticalsection_lock(&diminuto_i2c_mutex) )
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
_pthread_unwind_next(&buf);
}
_pthread_register_cancel(&buf);
if ( (int)diminuto_i2c_use(a1, a2) >= 0 && diminuto_i2c_write(a1, v11, 1uLL) >= 0 )
{
v7 = diminuto_i2c_read(a1, a4, a6);
if ( v7 >= 0 )
v7 = diminuto_i2c_write(a1, a5, a6);
}
_pthread_unregister_cancel(&buf);
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
}
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned __int8 a2, char a3, void *a4, const void *a5, size_t a6)
{
int v7; // [rsp+8h] [rbp-B0h]
char v11[4]; // [rsp+2Ch] [rbp-8Ch] BYREF
__pthread_unwind_buf_t buf; // [rsp+30h] [rbp-88h] BYREF

v11[0] = a3;
v7 = -1;
if ( !(unsigned int)diminuto_criticalsection_lock(&diminuto_i2c_mutex) )
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
_pthread_unwind_next(&buf);
}
_pthread_register_cancel(&buf);
if ( (int)func1(a1, a2) >= 0 && func3(a1, v11, 1uLL) >= 0 )
{
v7 = func2(a1, a4, a6);
if ( v7 >= 0 )
v7 = func3(a1, a5, a6);
}
_pthread_unregister_cancel(&buf);
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
}
return (unsigned int)v7;
}

original_code:
int diminuto_i2c_get_set(int fd, uint8_t addr, uint8_t reg, void * bufferp, const void * datap, size_t size)
{
    int rc = -1;
    do { pthread_mutex_t * _diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&diminuto_i2c_mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        if (diminuto_i2c_use(fd, addr) < 0) {
        } else if (diminuto_i2c_write(fd, &reg, sizeof(reg)) < 0) {
        } else if ((rc = diminuto_i2c_read(fd, bufferp, size)) < 0) {
        } else {
            rc = diminuto_i2c_write(fd, datap, size);
        }
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    return rc;
}

canonical_original_code:
int diminuto_i2c_get_set(int fd, unsigned char addr, unsigned char reg, void *bufferp, void *datap, unsigned long size)
{
    int rc = -1;
    do { union pthread_mutex_t *_diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&diminuto_i2c_mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        if (diminuto_i2c_use(fd, addr) < 0) {
        } else if (diminuto_i2c_write(fd, &reg, sizeof(reg)) < 0) {
        } else if ((rc = diminuto_i2c_read(fd, bufferp, size)) < 0) {
        } else {
            rc = diminuto_i2c_write(fd, datap, size);
        }
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    return rc;
}


decompiled_code:
__int64 __fastcall diminuto_i2c_set_get(int a1, unsigned __int8 a2, char a3, const void *a4, void *a5, size_t a6)
{
int v7; // [rsp+8h] [rbp-B0h]
char v11[4]; // [rsp+2Ch] [rbp-8Ch] BYREF
__pthread_unwind_buf_t buf; // [rsp+30h] [rbp-88h] BYREF

v11[0] = a3;
v7 = -1;
if ( !(unsigned int)diminuto_criticalsection_lock(&diminuto_i2c_mutex) )
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
_pthread_unwind_next(&buf);
}
_pthread_register_cancel(&buf);
if ( (int)diminuto_i2c_use(a1, a2) >= 0 && diminuto_i2c_write(a1, v11, 1uLL) >= 0 )
{
v7 = diminuto_i2c_write(a1, a4, a6);
if ( v7 >= 0 )
v7 = diminuto_i2c_read(a1, a5, a6);
}
_pthread_unregister_cancel(&buf);
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
}
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, unsigned __int8 a2, char a3, const void *a4, void *a5, size_t a6)
{
int v7; // [rsp+8h] [rbp-B0h]
char v11[4]; // [rsp+2Ch] [rbp-8Ch] BYREF
__pthread_unwind_buf_t buf; // [rsp+30h] [rbp-88h] BYREF

v11[0] = a3;
v7 = -1;
if ( !(unsigned int)diminuto_criticalsection_lock(&diminuto_i2c_mutex) )
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
_pthread_unwind_next(&buf);
}
_pthread_register_cancel(&buf);
if ( (int)func1(a1, a2) >= 0 && func3(a1, v11, 1uLL) >= 0 )
{
v7 = func3(a1, a4, a6);
if ( v7 >= 0 )
v7 = func2(a1, a5, a6);
}
_pthread_unregister_cancel(&buf);
diminuto_criticalsection_cleanup(&diminuto_i2c_mutex);
}
return (unsigned int)v7;
}

original_code:
int diminuto_i2c_set_get(int fd, uint8_t addr, uint8_t reg, const void * datap, void * bufferp, size_t size)
{
    int rc = -1;
    do { pthread_mutex_t * _diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&diminuto_i2c_mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        if (diminuto_i2c_use(fd, addr) < 0) {
        } else if (diminuto_i2c_write(fd, &reg, sizeof(reg)) < 0) {
        } else if ((rc = diminuto_i2c_write(fd, datap, size)) < 0) {
        } else {
            rc = diminuto_i2c_read(fd, bufferp, size);
        }
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    return rc;
}

canonical_original_code:
int diminuto_i2c_set_get(int fd, unsigned char addr, unsigned char reg, void *datap, void *bufferp, unsigned long size)
{
    int rc = -1;
    do { union pthread_mutex_t *_diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&diminuto_i2c_mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        if (diminuto_i2c_use(fd, addr) < 0) {
        } else if (diminuto_i2c_write(fd, &reg, sizeof(reg)) < 0) {
        } else if ((rc = diminuto_i2c_write(fd, datap, size)) < 0) {
        } else {
            rc = diminuto_i2c_read(fd, bufferp, size);
        }
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    return rc;
}


decompiled_code:
void __fastcall diminuto_pipe_handler(int a1)
{
if ( a1 == 13 && signaled != 0x7FFFFFFF )
++signaled;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 13 && signaled != 0x7FFFFFFF )
++signaled;
}

original_code:
static void diminuto_pipe_handler(int signum)
{
    int mysignaled = -1;
    static const int MAXIMUM = ~(((int)1) << ((sizeof(signaled) * 8) - 1));
    if (signum == 13) {
        mysignaled = signaled;
        if (mysignaled < MAXIMUM) {
            mysignaled += 1;
            signaled = mysignaled;
        }
    }
}

canonical_original_code:
static void diminuto_pipe_handler(int signum)
{
    int mysignaled = -1;
    static int MAXIMUM = ~(((int)1) << ((sizeof(signaled) * 8) - 1));
    if (signum == 13) {
        mysignaled = signaled;
        if (mysignaled < MAXIMUM) {
            mysignaled += 1;
            signaled = mysignaled;
        }
    }
}

variable_types: signum int

variable_types: mysignaled int

variable_types: MAXIMUM int


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

if ( kill(a1, 13) < 0 )
{
diminuto_log_perror("src/diminuto_pipe.c", 32LL, "diminuto_pipe_signal: kill");
result = 0xFFFFFFFFLL;
}
else
{
result = diminuto_pipe_debug[0];
if ( diminuto_pipe_debug[0] )
{
result = diminuto_log_mask & 1;
if ( (diminuto_log_mask & 1) != 0 )
{
diminuto_log_log(7LL, "diminuto_pipe_signal: SIGPIPE");
result = 0LL;
}
}
}
return result;
}

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

if ( kill(a1, 13) < 0 )
{
diminuto_log_perror("src/diminuto_pipe.c", 32LL, "diminuto_pipe_signal: kill");
result = 0xFFFFFFFFLL;
}
else
{
result = diminuto_pipe_debug[0];
if ( diminuto_pipe_debug[0] )
{
result = diminuto_log_mask & 1;
if ( (diminuto_log_mask & 1) != 0 )
{
diminuto_log_log(7LL, "diminuto_pipe_signal: SIGPIPE");
result = 0LL;
}
}
}
return result;
}

original_code:
int diminuto_pipe_signal(pid_t pid)
{
    int rc = 0;
    if (kill(pid, 13) < 0) {
        diminuto_log_perror("src/diminuto_pipe.c", 32, "diminuto_pipe_signal: kill");
        rc = -1;
    } else if (diminuto_pipe_debug) {
        ((((diminuto_log_mask) & (DIMINUTO_LOG_MASK_DEBUG)) != 0) ? diminuto_log_log(DIMINUTO_LOG_PRIORITY_DEBUG, "diminuto_pipe_signal: SIGPIPE") : ((void)0));
    } else {
    }
    return rc;
}

canonical_original_code:
int diminuto_pipe_signal(int pid)
{
    int rc = 0;
    if (kill(pid, 13) < 0) {
        diminuto_log_perror("src/diminuto_pipe.c", 32, "diminuto_pipe_signal: kill");
        rc = -1;
    } else if (diminuto_pipe_debug) {
        ((((diminuto_log_mask) & (DIMINUTO_LOG_MASK_DEBUG)) != 0) ? diminuto_log_log(DIMINUTO_LOG_PRIORITY_DEBUG, "diminuto_pipe_signal: SIGPIPE") : ((void)0));
    } else {
    }
    return rc;
}

variable_types: pid int


decompiled_code:
__int64 diminuto_pipe_check()
{
unsigned int v1; // [rsp+Ch] [rbp-17Ch]
int v2; // [rsp+1Ch] [rbp-16Ch] BYREF
struct __jmp_buf_tag env; // [rsp+20h] [rbp-168h] BYREF
char v4[136]; // [rsp+100h] [rbp-88h] BYREF

v1 = -1;
if ( (unsigned int)diminuto_criticalsection_lock(&mutex) )
{
v1 = -1;
LABEL_11:
if ( diminuto_pipe_debug[0] && (diminuto_log_mask & 1) != 0 )
diminuto_log_log(7LL, "diminuto_pipe_check: SIGPIPE");
return v1;
}
if ( _sigsetjmp(&env, 0) )
{
diminuto_criticalsection_cleanup(&mutex);
_pthread_unwind_next((__pthread_unwind_buf_t *)&env);
}
_pthread_register_cancel((__pthread_unwind_buf_t *)&env);
v2 = 13;
if ( !(unsigned int)diminuto_uninterruptiblesection_block(&v2, 1LL, v4) )
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&env.__saved_mask.__val[5], 0) )
{
diminuto_uninterruptiblesection_cleanup(v4);
_pthread_unwind_next((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
}
_pthread_register_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
v1 = signaled;
signaled = 0;
_pthread_unregister_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
diminuto_uninterruptiblesection_cleanup(v4);
}
_pthread_unregister_cancel((__pthread_unwind_buf_t *)&env);
diminuto_criticalsection_cleanup(&mutex);
if ( v1 )
goto LABEL_11;
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v1; // [rsp+Ch] [rbp-17Ch]
int v2; // [rsp+1Ch] [rbp-16Ch] BYREF
struct __jmp_buf_tag env; // [rsp+20h] [rbp-168h] BYREF
char v4[136]; // [rsp+100h] [rbp-88h] BYREF

v1 = -1;
if ( (unsigned int)diminuto_criticalsection_lock(&mutex) )
{
v1 = -1;
LABEL_11:
if ( diminuto_pipe_debug[0] && (diminuto_log_mask & 1) != 0 )
diminuto_log_log(7LL, "diminuto_pipe_check: SIGPIPE");
return v1;
}
if ( _sigsetjmp(&env, 0) )
{
diminuto_criticalsection_cleanup(&mutex);
_pthread_unwind_next((__pthread_unwind_buf_t *)&env);
}
_pthread_register_cancel((__pthread_unwind_buf_t *)&env);
v2 = 13;
if ( !(unsigned int)diminuto_uninterruptiblesection_block(&v2, 1LL, v4) )
{
if ( _sigsetjmp((struct __jmp_buf_tag *)&env.__saved_mask.__val[5], 0) )
{
diminuto_uninterruptiblesection_cleanup(v4);
_pthread_unwind_next((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
}
_pthread_register_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
v1 = signaled;
signaled = 0;
_pthread_unregister_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
diminuto_uninterruptiblesection_cleanup(v4);
}
_pthread_unregister_cancel((__pthread_unwind_buf_t *)&env);
diminuto_criticalsection_cleanup(&mutex);
if ( v1 )
goto LABEL_11;
return v1;
}

original_code:
int diminuto_pipe_check(void)
{
    int mysignaled = -1;
    do { pthread_mutex_t * _diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        do { const int _diminuto_uninterrutiblesection_signals[] = { 13 }; sigset_t _diminuto_uninterruptiblesection_set; if (diminuto_uninterruptiblesection_block(_diminuto_uninterrutiblesection_signals, (sizeof(_diminuto_uninterrutiblesection_signals) / sizeof(_diminuto_uninterrutiblesection_signals[0])), &_diminuto_uninterruptiblesection_set) == 0) { do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (diminuto_uninterruptiblesection_cleanup); void *__cancel_arg = (&_diminuto_uninterruptiblesection_set); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
            mysignaled = signaled;
            signaled = 0;
        } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    if (!mysignaled) {
    } else if (diminuto_pipe_debug) {
        ((((diminuto_log_mask) & (DIMINUTO_LOG_MASK_DEBUG)) != 0) ? diminuto_log_log(DIMINUTO_LOG_PRIORITY_DEBUG, "diminuto_pipe_check: SIGPIPE") : ((void)0));
    } else {
    }
    return mysignaled;
}

canonical_original_code:
int diminuto_pipe_check()
{
    int mysignaled = -1;
    do { union pthread_mutex_t *_diminuto_criticalsection_mp; _diminuto_criticalsection_mp = (&mutex); if (diminuto_criticalsection_lock(_diminuto_criticalsection_mp) == 0) { do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (diminuto_criticalsection_cleanup); void *__cancel_arg = (_diminuto_criticalsection_mp); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
        do { int _diminuto_uninterrutiblesection_signals[] = { 13 }; struct __sigset_t _diminuto_uninterruptiblesection_set; if (diminuto_uninterruptiblesection_block(_diminuto_uninterrutiblesection_signals, (sizeof(_diminuto_uninterrutiblesection_signals) / sizeof(_diminuto_uninterrutiblesection_signals[0])), &_diminuto_uninterruptiblesection_set) == 0) { do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (diminuto_uninterruptiblesection_cleanup); void *__cancel_arg = (&_diminuto_uninterruptiblesection_set); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {; do { ((void)0);
            mysignaled = signaled;
            signaled = 0;
        } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    } while (0); do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (!0) __cancel_routine (__cancel_arg); } while (0); } } while (0);
    if (!mysignaled) {
    } else if (diminuto_pipe_debug) {
        ((((diminuto_log_mask) & (DIMINUTO_LOG_MASK_DEBUG)) != 0) ? diminuto_log_log(DIMINUTO_LOG_PRIORITY_DEBUG, "diminuto_pipe_check: SIGPIPE") : ((void)0));
    } else {
    }
    return mysignaled;
}

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


decompiled_code:
__int64 __fastcall diminuto_pipe_install(int a1)
{
int v1; // edx
__int64 result; // rax
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v1 = a1;
memset(&v3.sa_mask, 0, 0x90uLL);
v3.sa_handler = diminuto_pipe_handler;
if ( a1 )
v1 = 0x10000000;
v3.sa_flags = v1;
if ( sigaction(13, &v3, 0LL) < 0 )
{
diminuto_log_perror("src/diminuto_pipe.c", 91LL, "diminuto_pipe_install: sigaction");
result = 0xFFFFFFFFLL;
}
else
{
result = diminuto_pipe_debug[0];
if ( diminuto_pipe_debug[0] )
{
result = diminuto_log_mask & 1;
if ( (diminuto_log_mask & 1) != 0 )
{
diminuto_log_log(7LL, "diminuto_pipe_install: SIGPIPE");
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // edx
__int64 result; // rax
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v1 = a1;
memset(&v3.sa_mask, 0, 0x90uLL);
v3.sa_handler = diminuto_pipe_handler;
if ( a1 )
v1 = 0x10000000;
v3.sa_flags = v1;
if ( sigaction(13, &v3, 0LL) < 0 )
{
diminuto_log_perror("src/diminuto_pipe.c", 91LL, "diminuto_pipe_install: sigaction");
result = 0xFFFFFFFFLL;
}
else
{
result = diminuto_pipe_debug[0];
if ( diminuto_pipe_debug[0] )
{
result = diminuto_log_mask & 1;
if ( (diminuto_log_mask & 1) != 0 )
{
diminuto_log_log(7LL, "diminuto_pipe_install: SIGPIPE");
result = 0LL;
}
}
}
return result;
}

original_code:
int diminuto_pipe_install(int restart)
{
    int rc = 0;
    struct sigaction alarm = { 0 };
    alarm.__sigaction_handler.sa_handler = diminuto_pipe_handler;
    alarm.sa_flags = restart ? 0x10000000 : 0;
    if (sigaction(13, &alarm, (struct sigaction *)0) < 0) {
        diminuto_log_perror("src/diminuto_pipe.c", 91, "diminuto_pipe_install: sigaction");
        rc = -1;
    } else if (diminuto_pipe_debug) {
        ((((diminuto_log_mask) & (DIMINUTO_LOG_MASK_DEBUG)) != 0) ? diminuto_log_log(DIMINUTO_LOG_PRIORITY_DEBUG, "diminuto_pipe_install: SIGPIPE") : ((void)0));
    } else {
    }
    return rc;
}

variable_types: restart int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
__int64 __fastcall diminuto_framer_fini(__int64 a1)
{
*(_DWORD *)(a1 + 40) = 73;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
*(_DWORD *)(a1 + 40) = 73;
return 0LL;
}

original_code:
static inline diminuto_framer_t * diminuto_framer_fini(diminuto_framer_t * that) {
    that->state = DIMINUTO_FRAMER_STATE_IDLE;
    return (diminuto_framer_t *)0;
}

canonical_original_code:
static inline struct DiminutoFramer *diminuto_framer_fini(struct DiminutoFramer *that) {
    that->state = DIMINUTO_FRAMER_STATE_IDLE;
    return (struct DiminutoFramer *)0;
}

variable_types:
that
struct DiminutoFramer *

return_type: struct DiminutoFramer { void *buffer; unsigned char *here; unsigned long size; unsigned long limit; unsigned long total; enum DiminutoFramerState { DIMINUTO_FRAMER_STATE_ABORT=expr, DIMINUTO_FRAMER_STATE_COMPLETE=expr, DIMINUTO_FRAMER_STATE_FAILED=expr, DIMINUTO_FRAMER_STATE_FINAL=expr, DIMINUTO_FRAMER_STATE_FLAG=expr, DIMINUTO_FRAMER_STATE_FLETCHER=expr, DIMINUTO_FRAMER_STATE_FLETCHER_ESCAPED=expr, DIMINUTO_FRAMER_STATE_IDLE=expr, DIMINUTO_FRAMER_STATE_INVALID=expr, DIMINUTO_FRAMER_STATE_KERMIT=expr, DIMINUTO_FRAMER_STATE_LENGTH=expr, DIMINUTO_FRAMER_STATE_LENGTH_ESCAPED=expr, DIMINUTO_FRAMER_STATE_NEWLINE=expr, DIMINUTO_FRAMER_STATE_OVERFLOW=expr, DIMINUTO_FRAMER_STATE_PAYLOAD=expr, DIMINUTO_FRAMER_STATE_PAYLOAD_ESCAPED=expr, DIMINUTO_FRAMER_STATE_RESET=expr, DIMINUTO_FRAMER_STATE_SEQUENCE=expr, DIMINUTO_FRAMER_STATE_SEQUENCE_ESCAPED=expr } state; unsigned short length0; unsigned short length; unsigned short sequence0; unsigned short sequence; unsigned short previous; unsigned short generated; unsigned short crc; unsigned short crc0; unsigned char a; unsigned char b; unsigned char sum[2]; unsigned char check[3]; _Bool throttle; _Bool debug; } *

user_defined_types: struct DiminutoFramer { void *buffer; unsigned char *here; unsigned long size; unsigned long limit; unsigned long total; enum DiminutoFramerState state; unsigned short length0; unsigned short length; unsigned short sequence0; unsigned short sequence; unsigned short previous; unsigned short generated; unsigned short crc; unsigned short crc0; unsigned char a; unsigned char b; unsigned char sum[2]; unsigned char check[3]; _Bool throttle; _Bool debug; }


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

result = a1;
*(_DWORD *)(a1 + 40) = 82;
return result;
}

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

result = a1;
*(_DWORD *)(a1 + 40) = 82;
return result;
}

original_code:
static inline diminuto_framer_t * diminuto_framer_reset(diminuto_framer_t * that) {
    that->state = DIMINUTO_FRAMER_STATE_RESET;
    return that;
}

canonical_original_code:
static inline struct DiminutoFramer *diminuto_framer_reset(struct DiminutoFramer *that) {
    that->state = DIMINUTO_FRAMER_STATE_RESET;
    return that;
}

user_defined_types: enum DiminutoFramerState { DIMINUTO_FRAMER_STATE_ABORT=expr, DIMINUTO_FRAMER_STATE_COMPLETE=expr, DIMINUTO_FRAMER_STATE_FAILED=expr, DIMINUTO_FRAMER_STATE_FINAL=expr, DIMINUTO_FRAMER_STATE_FLAG=expr, DIMINUTO_FRAMER_STATE_FLETCHER=expr, DIMINUTO_FRAMER_STATE_FLETCHER_ESCAPED=expr, DIMINUTO_FRAMER_STATE_IDLE=expr, DIMINUTO_FRAMER_STATE_INVALID=expr, DIMINUTO_FRAMER_STATE_KERMIT=expr, DIMINUTO_FRAMER_STATE_LENGTH=expr, DIMINUTO_FRAMER_STATE_LENGTH_ESCAPED=expr, DIMINUTO_FRAMER_STATE_NEWLINE=expr, DIMINUTO_FRAMER_STATE_OVERFLOW=expr, DIMINUTO_FRAMER_STATE_PAYLOAD=expr, DIMINUTO_FRAMER_STATE_PAYLOAD_ESCAPED=expr, DIMINUTO_FRAMER_STATE_RESET=expr, DIMINUTO_FRAMER_STATE_SEQUENCE=expr, DIMINUTO_FRAMER_STATE_SEQUENCE_ESCAPED=expr }


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

if ( diminuto_framer_iscomplete(a1) )
result = *(unsigned __int16 *)(a1 + 46);
else
result = -1LL;
return result;
}

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

if ( func10(a1) )
result = *(unsigned __int16 *)(a1 + 46);
else
result = -1LL;
return result;
}

original_code:
static inline ssize_t diminuto_framer_getlength(const diminuto_framer_t * that) {
    return diminuto_framer_iscomplete(that) ? (ssize_t)(that->length) : (ssize_t)(-1);
}

canonical_original_code:
static inline long diminuto_framer_getlength(struct DiminutoFramer *that) {
    return diminuto_framer_iscomplete(that) ? (long)(that->length) : (long)(-1);
}

variable_types: struct DiminutoFramer { void *buffer; unsigned char *here; unsigned long size; unsigned long limit; unsigned long total; enum DiminutoFramerState { DIMINUTO_FRAMER_STATE_ABORT=expr, DIMINUTO_FRAMER_STATE_COMPLETE=expr, DIMINUTO_FRAMER_STATE_FAILED=expr, DIMINUTO_FRAMER_STATE_FINAL=expr, DIMINUTO_FRAMER_STATE_FLAG=expr, DIMINUTO_FRAMER_STATE_FLETCHER=expr, DIMINUTO_FRAMER_STATE_FLETCHER_ESCAPED=expr, DIMINUTO_FRAMER_STATE_IDLE=expr, DIMINUTO_FRAMER_STATE_INVALID=expr, DIMINUTO_FRAMER_STATE_KERMIT=expr, DIMINUTO_FRAMER_STATE_LENGTH=expr, DIMINUTO_FRAMER_STATE_LENGTH_ESCAPED=expr, DIMINUTO_FRAMER_STATE_NEWLINE=expr, DIMINUTO_FRAMER_STATE_OVERFLOW=expr, DIMINUTO_FRAMER_STATE_PAYLOAD=expr, DIMINUTO_FRAMER_STATE_PAYLOAD_ESCAPED=expr, DIMINUTO_FRAMER_STATE_RESET=expr, DIMINUTO_FRAMER_STATE_SEQUENCE=expr, DIMINUTO_FRAMER_STATE_SEQUENCE_ESCAPED=expr } state; unsigned short length0; unsigned short length; unsigned short sequence0; unsigned short sequence; unsigned short previous; unsigned short generated; unsigned short crc; unsigned short crc0; unsigned char a; unsigned char b; unsigned char sum[2]; unsigned char check[3]; _Bool throttle; _Bool debug; } *


decompiled_code:
__int64 __fastcall diminuto_framer_getbuffer(__int64 *a1)
{
bool v1; // dl
__int64 result; // rax

v1 = diminuto_framer_iscomplete((__int64)a1);
result = 0LL;
if ( v1 )
result = *a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 *a1)
{
bool v1; // dl
__int64 result; // rax

v1 = func10((__int64)a1);
result = 0LL;
if ( v1 )
result = *a1;
return result;
}

original_code:
static inline void * diminuto_framer_getbuffer(const diminuto_framer_t * that) {
    return diminuto_framer_iscomplete(that) ? that->buffer : (void *)0;
}

canonical_original_code:
static inline void *diminuto_framer_getbuffer(struct DiminutoFramer *that) {
    return diminuto_framer_iscomplete(that) ? that->buffer : (void *)0;
}


decompiled_code:
bool __fastcall diminuto_framer_didrollover(__int64 a1)
{
return (*(_QWORD *)(a1 + 48) & 0xFFFFFFFF0000LL) == 0xFFFF00000000LL;
}

canonical_decompiled_code:
bool __fastcall func15(__int64 a1)
{
return (*(_QWORD *)(a1 + 48) & 0xFFFFFFFF0000LL) == 0xFFFF00000000LL;
}

original_code:
static inline _Bool diminuto_framer_didrollover(const diminuto_framer_t * that) {
    return (that->previous == ((65536) - 1)) && (that->sequence == 0);
}

canonical_original_code:
static inline _Bool diminuto_framer_didrollover(struct DiminutoFramer *that) {
    return (that->previous == ((65536) - 1)) && (that->sequence == 0);
}


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

result = *(unsigned __int8 *)(a1 + 68);
*(_BYTE *)(a1 + 68) = a2;
return result;
}

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

result = *(unsigned __int8 *)(a1 + 68);
*(_BYTE *)(a1 + 68) = a2;
return result;
}

original_code:
_Bool diminuto_framer_debug(diminuto_framer_t * that, _Bool debug) {
    _Bool prior = that->debug;
    that->debug = debug;
    return prior;
}

canonical_original_code:
_Bool diminuto_framer_debug(struct DiminutoFramer *that, _Bool debug) {
    _Bool prior = that->debug;
    that->debug = debug;
    return prior;
}


decompiled_code:
__int64 __fastcall diminuto_inet_checksum(_BYTE *a1, unsigned __int64 a2)
{
char v2; // r8
unsigned __int64 v3; // rsi
unsigned int v4; // eax
unsigned __int16 v5; // dx
unsigned int i; // edx

v2 = a2;
if ( a2 <= 1 )
{
if ( !a2 )
{
v4 = 0;
return ~v4;
}
v4 = 0;
goto LABEL_5;
}
v3 = (unsigned __int64)&a1[2 * ((a2 - 2) >> 1) + 2];
v4 = 0;
do
{
LOBYTE(v5) = *a1;
a1 += 2;
HIBYTE(v5) = *(a1 - 1);
v4 += v5;
}
while ( (_BYTE *)v3 != a1 );
if ( (v2 & 1) != 0 )
LABEL_5:
v4 += (unsigned __int8)*a1;
for ( i = HIWORD(v4); HIWORD(v4); i = HIWORD(v4) )
v4 = i + (unsigned __int16)v4;
return ~v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, unsigned __int64 a2)
{
char v2; // r8
unsigned __int64 v3; // rsi
unsigned int v4; // eax
unsigned __int16 v5; // dx
unsigned int i; // edx

v2 = a2;
if ( a2 <= 1 )
{
if ( !a2 )
{
v4 = 0;
return ~v4;
}
v4 = 0;
goto LABEL_5;
}
v3 = (unsigned __int64)&a1[2 * ((a2 - 2) >> 1) + 2];
v4 = 0;
do
{
LOBYTE(v5) = *a1;
a1 += 2;
HIBYTE(v5) = *(a1 - 1);
v4 += v5;
}
while ( (_BYTE *)v3 != a1 );
if ( (v2 & 1) != 0 )
LABEL_5:
v4 += (unsigned __int8)*a1;
for ( i = HIWORD(v4); HIWORD(v4); i = HIWORD(v4) )
v4 = i + (unsigned __int16)v4;
return ~v4;
}

original_code:
uint16_t diminuto_inet_checksum(void * buffer, size_t size)
{
    inet_checksum_t datum;
    uint32_t accumulator = 0;
    uint8_t * here;
    here = (uint8_t *)buffer;
    while (size > 1) {
        datum.byte[0] = *(here++);
        datum.byte[1] = *(here++);
        accumulator += datum.word;
        size -= sizeof(uint16_t);
    }
    if (size > 0) {
        datum.byte[0] = *(here++);
        datum.byte[1] = 0;
        accumulator += datum.word;
    }
    while ((datum.word = accumulator >> (sizeof(uint16_t) * 8))) {
        accumulator = (accumulator & (uint16_t)~0) + datum.word;
    }
    return ~accumulator;
}

canonical_original_code:
unsigned short diminuto_inet_checksum(void *buffer, unsigned long size)
{
    union inet_checksum_t datum;
    unsigned int accumulator = 0;
    unsigned char *here;
    here = (unsigned char *)buffer;
    while (size > 1) {
        datum.byte[0] = *(here++);
        datum.byte[1] = *(here++);
        accumulator += datum.word;
        size -= sizeof(unsigned short);
    }
    if (size > 0) {
        datum.byte[0] = *(here++);
        datum.byte[1] = 0;
        accumulator += datum.word;
    }
    while ((datum.word = accumulator >> (sizeof(unsigned short) * 8))) {
        accumulator = (accumulator & (unsigned short)~0) + datum.word;
    }
    return ~accumulator;
}

variable_types:
buffer
void *

variable_types: union inet_checksum_t { unsigned short word; unsigned char byte[-1]; }

variable_types:
accumulator
unsigned int

variable_types:
here
unsigned char *

return_type: unsigned short


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

v0 = socket(2, 3, 1);
if ( v0 < 0 )
{
if ( *_errno_location() == 1 )
diminuto_log_perror("src/diminuto_ping4.c", 74LL, "diminuto_ping4_datagram_peer: socket: must be root");
else
diminuto_log_perror("src/diminuto_ping4.c", 76LL, "diminuto_ping4_datagram_peer: socket");
}
return (unsigned int)v0;
}

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

v0 = socket(2, 3, 1);
if ( v0 < 0 )
{
if ( *_errno_location() == 1 )
diminuto_log_perror("src/diminuto_ping4.c", 74LL, "diminuto_ping4_datagram_peer: socket: must be root");
else
diminuto_log_perror("src/diminuto_ping4.c", 76LL, "diminuto_ping4_datagram_peer: socket");
}
return (unsigned int)v0;
}

original_code:
int diminuto_ping4_datagram_peer(void)
{
    int fd;
    if ((fd = socket(2, SOCK_RAW, IPPROTO_ICMP)) >= 0) {
    } else if ((*__errno_location ()) == 1) {
        diminuto_log_perror("src/diminuto_ping4.c", 74, "diminuto_ping4_datagram_peer: socket: must be root");
    } else {
        diminuto_log_perror("src/diminuto_ping4.c", 76, "diminuto_ping4_datagram_peer: socket");
    }
    return fd;
}

canonical_original_code:
int diminuto_ping4_datagram_peer()
{
    int fd;
    if ((fd = socket(2, SOCK_RAW, IPPROTO_ICMP)) >= 0) {
    } else if ((*__errno_location ()) == 1) {
        diminuto_log_perror("src/diminuto_ping4.c", 74, "diminuto_ping4_datagram_peer: socket: must be root");
    } else {
        diminuto_log_perror("src/diminuto_ping4.c", 76, "diminuto_ping4_datagram_peer: socket");
    }
    return fd;
}

variable_types: fd int


decompiled_code:
ssize_t __fastcall diminuto_ping4_datagram_send(__int64 fd, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int16 v6; // r13
__int16 v7; // r12
__int64 v8; // rbp
ssize_t v9; // rbx
int v11; // eax
struct sockaddr v12; // [rsp+0h] [rbp-78h] BYREF
__int64 buf[13]; // [rsp+10h] [rbp-68h] BYREF

v6 = a3;
v7 = a4;
buf[2] = 0LL;
buf[3] = 0LL;
buf[4] = 0LL;
buf[5] = 0LL;
buf[6] = 0LL;
buf[7] = 0LL;
v8 = diminuto_time_clock(fd, a2, a3, a4, a5, a6, 0LL, 0LL, 0LL, 0LL);
v12.sa_family = 2;
*(_DWORD *)&v12.sa_data[2] = _bswap_32(a2);
LOBYTE(buf[0]) = 8;
WORD2(buf[0]) = v6;
HIWORD(buf[0]) = v7;
buf[1] = v8;
WORD1(buf[0]) = diminuto_inet_checksum(buf, 0x40uLL);
if ( diminuto_ping4_debug )
diminuto_dump((__int64)stderr, (__int64)buf, 64LL);
v9 = sendto(fd, buf, 0x40uLL, 0, &v12, 0x10u);
if ( v9 < 0 )
{
v11 = *_errno_location();
if ( v11 != 4 && v11 != 11 )
diminuto_log_perror("src/diminuto_ping4.c", 116LL, "diminuto_ping4_datagram_send: sendto");
}
return v9;
}

canonical_decompiled_code:
ssize_t __fastcall func5(__int64 fd, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int16 v6; // r13
__int16 v7; // r12
__int64 v8; // rbp
ssize_t v9; // rbx
int v11; // eax
struct sockaddr v12; // [rsp+0h] [rbp-78h] BYREF
__int64 buf[13]; // [rsp+10h] [rbp-68h] BYREF

v6 = a3;
v7 = a4;
buf[2] = 0LL;
buf[3] = 0LL;
buf[4] = 0LL;
buf[5] = 0LL;
buf[6] = 0LL;
buf[7] = 0LL;
v8 = diminuto_time_clock(fd, a2, a3, a4, a5, a6, 0LL, 0LL, 0LL, 0LL);
v12.sa_family = 2;
*(_DWORD *)&v12.sa_data[2] = func0(a2);
LOBYTE(buf[0]) = 8;
WORD2(buf[0]) = v6;
HIWORD(buf[0]) = v7;
buf[1] = v8;
WORD1(buf[0]) = func3(buf, 0x40uLL);
if ( diminuto_ping4_debug )
func2((__int64)stderr, (__int64)buf, 64LL);
v9 = sendto(fd, buf, 0x40uLL, 0, &v12, 0x10u);
if ( v9 < 0 )
{
v11 = *_errno_location();
if ( v11 != 4 && v11 != 11 )
diminuto_log_perror("src/diminuto_ping4.c", 116LL, "diminuto_ping4_datagram_send: sendto");
}
return v9;
}

original_code:
ssize_t diminuto_ping4_datagram_send(int fd, diminuto_ipv4_t address, uint16_t id, uint16_t seq)
{
    ssize_t total;
    icmp_echo_request_datagram_t buffer = { 0 };
    struct sockaddr_in sa = { 0 };
    struct icmp * icmpp;
    diminuto_ticks_t now;
    now = diminuto_time_clock();
    sa.sin_family = 2;
    sa.sin_addr.s_addr = htonl(address);
    icmpp = (struct icmp *)(&buffer);
    icmpp->icmp_type = 8;
    icmpp->icmp_hun.ih_idseq.icd_id = id;
    icmpp->icmp_hun.ih_idseq.icd_seq = seq;
    memcpy(icmpp->icmp_dun.id_data, &now, sizeof(diminuto_ticks_t));
    icmpp->icmp_cksum = diminuto_inet_checksum(&buffer, sizeof(buffer));
    if (diminuto_ping4_debug) { diminuto_dump(stderr, &buffer, sizeof(buffer)); }
    if ((total = sendto(fd, &buffer, sizeof(buffer), 0, (struct sockaddr *)&sa, sizeof(sa))) == 0) {
    } else if (total > 0) {
    } else if (((*__errno_location ()) != 4) && ((*__errno_location ()) != 11) && ((*__errno_location ()) != 11)) {
        diminuto_log_perror("src/diminuto_ping4.c", 116, "diminuto_ping4_datagram_send: sendto");
    } else {
    }
    return total;
}

canonical_original_code:
long diminuto_ping4_datagram_send(int fd, unsigned int address, unsigned short id, unsigned short seq)
{
    long total;
    union icmp_echo_request_datagram_t buffer = { 0 };
    struct sockaddr_in sa = { 0 };
    struct icmp *icmpp;
    unsigned long now;
    now = diminuto_time_clock();
    sa.sin_family = 2;
    sa.sin_addr.s_addr = htonl(address);
    icmpp = (struct icmp *)(&buffer);
    icmpp->icmp_type = 8;
    icmpp->icmp_hun.ih_idseq.icd_id = id;
    icmpp->icmp_hun.ih_idseq.icd_seq = seq;
    memcpy(icmpp->icmp_dun.id_data, &now, sizeof(diminuto_ticks_t));
    icmpp->icmp_cksum = diminuto_inet_checksum(&buffer, sizeof(buffer));
    if (diminuto_ping4_debug) { diminuto_dump(stderr, &buffer, sizeof(buffer)); }
    if ((total = sendto(fd, &buffer, sizeof(buffer), 0, (struct sockaddr *)&sa, sizeof(sa))) == 0) {
    } else if (total > 0) {
    } else if (((*__errno_location ()) != 4) && ((*__errno_location ()) != 11) && ((*__errno_location ()) != 11)) {
        diminuto_log_perror("src/diminuto_ping4.c", 116, "diminuto_ping4_datagram_send: sendto");
    } else {
    }
    return total;
}

variable_types:
address
unsigned int

variable_types:
id
unsigned short

variable_types:
seq
unsigned short

variable_types: total long

variable_types: union icmp_echo_request_datagram_t { struct { struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr { unsigned int s_addr; } ih_gwaddr; struct ih_idseq { unsigned short icd_id; unsigned short icd_seq; } ih_idseq; unsigned int ih_void; struct ih_pmtu { unsigned short ipm_void; unsigned short ipm_nextmtu; } ih_pmtu; struct ih_rtradv { unsigned char irt_num_addrs; unsigned char irt_wpa; unsigned short irt_lifetime; } ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; } idi_ip; } id_ip; struct icmp_ra_addr { unsigned int ira_addr; unsigned int ira_preference; } id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; } icmp; } header; char payload[-1]; }

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]; }

variable_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr { unsigned int s_addr; } ih_gwaddr; struct ih_idseq { unsigned short icd_id; unsigned short icd_seq; } ih_idseq; unsigned int ih_void; struct ih_pmtu { unsigned short ipm_void; unsigned short ipm_nextmtu; } ih_pmtu; struct ih_rtradv { unsigned char irt_num_addrs; unsigned char irt_wpa; unsigned short irt_lifetime; } ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; } idi_ip; } id_ip; struct icmp_ra_addr { unsigned int ira_addr; unsigned int ira_preference; } id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; } *

variable_types:
now
unsigned long

user_defined_types: union icmp_echo_request_datagram_t { struct { struct icmp icmp; } header; char payload[-1]; }

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 icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr ih_gwaddr; struct ih_idseq ih_idseq; unsigned int ih_void; struct ih_pmtu ih_pmtu; struct ih_rtradv ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip idi_ip; } id_ip; struct icmp_ra_addr id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; }

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