decompiled_code:
const char **diminuto_ipc_interfaces()
{
struct ifaddrs *v0; // rbx
__int64 v1; // rbp
__int64 v2; // r13
const char *v3; // rdi
struct ifaddrs *v4; // r12
const char **v5; // r14
char *v6; // r13
const char **v7; // rbp
const char *v8; // r15
const char **v9; // rbx
const char **v10; // rbx
size_t v11; // rax
char *v12; // rbp
struct ifaddrs *ifa; // [rsp+0h] [rbp-58h]
char *src; // [rsp+8h] [rbp-50h]
struct ifaddrs *ifap; // [rsp+18h] [rbp-40h] BYREF

ifap = 0LL;
if ( getifaddrs(&ifap) < 0 )
{
v5 = 0LL;
diminuto_log_perror("src/diminuto_ipc.c", 311LL, "diminuto_ipc_interfaces: getifaddrs");
ifa = ifap;
}
else
{
ifa = ifap;
if ( ifap )
{
v0 = ifap;
v1 = 0LL;
v2 = 1LL;
do
{
v3 = v0->ifa_name;
if ( v3 )
{
++v2;
v1 += strnlen(v3, 0xFFuLL) + 1;
}
v0 = v0->ifa_next;
}
while ( v0 );
v4 = ifa;
v5 = (const char **)malloc(v2 * 8 + v1);
v6 = (char *)&v5[v2];
v7 = v5;
do
{
while ( 1 )
{
v8 = v4->ifa_name;
if ( v8 )
{
if ( v5 >= v7 )
break;
v9 = v5;
while ( strncmp(v8, *v9, 0xFFuLL) )
{
if ( ++v9 >= v7 )
goto LABEL_15;
}
if ( v9 >= v7 )
break;
}
v4 = v4->ifa_next;
if ( !v4 )
goto LABEL_16;
}
LABEL_15:
*v7 = v6;
v10 = v7 + 1;
src = v4->ifa_name;
v11 = strnlen(src, 0xFFuLL);
v12 = &v6[v11];
strncpy(v6, src, v11);
*v12 = 0;
v4 = v4->ifa_next;
v6 = v12 + 1;
v7 = v10;
}
while ( v4 );
}
else
{
v7 = (const char **)malloc(8uLL);
v5 = v7;
}
LABEL_16:
*v7 = 0LL;
}
if ( ifa )
freeifaddrs(ifa);
return v5;
}

canonical_decompiled_code:
const char **func19()
{
struct ifaddrs *v0; // rbx
__int64 v1; // rbp
__int64 v2; // r13
const char *v3; // rdi
struct ifaddrs *v4; // r12
const char **v5; // r14
char *v6; // r13
const char **v7; // rbp
const char *v8; // r15
const char **v9; // rbx
const char **v10; // rbx
size_t v11; // rax
char *v12; // rbp
struct ifaddrs *ifa; // [rsp+0h] [rbp-58h]
char *src; // [rsp+8h] [rbp-50h]
struct ifaddrs *ifap; // [rsp+18h] [rbp-40h] BYREF

ifap = 0LL;
if ( getifaddrs(&ifap) < 0 )
{
v5 = 0LL;
diminuto_log_perror("src/diminuto_ipc.c", 311LL, "diminuto_ipc_interfaces: getifaddrs");
ifa = ifap;
}
else
{
ifa = ifap;
if ( ifap )
{
v0 = ifap;
v1 = 0LL;
v2 = 1LL;
do
{
v3 = v0->ifa_name;
if ( v3 )
{
++v2;
v1 += strnlen(v3, 0xFFuLL) + 1;
}
v0 = v0->ifa_next;
}
while ( v0 );
v4 = ifa;
v5 = (const char **)malloc(v2 * 8 + v1);
v6 = (char *)&v5[v2];
v7 = v5;
do
{
while ( 1 )
{
v8 = v4->ifa_name;
if ( v8 )
{
if ( v5 >= v7 )
break;
v9 = v5;
while ( strncmp(v8, *v9, 0xFFuLL) )
{
if ( ++v9 >= v7 )
goto LABEL_15;
}
if ( v9 >= v7 )
break;
}
v4 = v4->ifa_next;
if ( !v4 )
goto LABEL_16;
}
LABEL_15:
*v7 = v6;
v10 = v7 + 1;
src = v4->ifa_name;
v11 = strnlen(src, 0xFFuLL);
v12 = &v6[v11];
strncpy(v6, src, v11);
*v12 = 0;
v4 = v4->ifa_next;
v6 = v12 + 1;
v7 = v10;
}
while ( v4 );
}
else
{
v7 = (const char **)malloc(8uLL);
v5 = v7;
}
LABEL_16:
*v7 = 0LL;
}
if ( ifa )
freeifaddrs(ifa);
return v5;
}

original_code:
char ** diminuto_ipc_interfaces(void)
{
    char ** rp = (char **)0;
    struct ifaddrs * ifa = (struct ifaddrs *)0;
    struct ifaddrs * ip = (struct ifaddrs *)0;
    char ** vp = (char **)0;
    char * np = (char *)0;
    size_t vs = sizeof(char *);
    size_t ns = 0;
    size_t rs = 0;
    char ** cp = (char **)0;
    do {
        if (getifaddrs(&ifa) < 0) {
            diminuto_log_perror("src/diminuto_ipc.c", 311, "diminuto_ipc_interfaces: getifaddrs");
            break;
        }
        for (ip = ifa; ip != (struct ifaddrs *)0; ip = ip->ifa_next) {
            if (ip->ifa_name != (char *)0) {
                vs += sizeof(char *);
                ns += strnlen(ip->ifa_name, 255) + 1;
            }
        }
        rs = vs + ns;
        rp = (char **)malloc(rs);
        vp = rp;
        np = (char *)vp + vs;
        for (ip = ifa; ip != (struct ifaddrs *)0; ip = ip->ifa_next) {
            if (ip->ifa_name != (char *)0) {
                for (cp = rp; cp < vp; ++cp) {
                    if (strncmp(ip->ifa_name, *cp, 255) == 0) {
                        break;
                    }
                }
                if (cp >= vp) {
                    *(vp++) = np;
                    ns = strnlen(ip->ifa_name, 255);
                    strncpy(np, ip->ifa_name, ns);
                    np += ns;
                    *(np++) = '\0';
                }
            }
        }
        *vp = (char *)0;
    } while (0);
    if (ifa != (struct ifaddrs *)0) {
        freeifaddrs(ifa);
    }
    return rp;
}

canonical_original_code:
char **diminuto_ipc_interfaces()
{
    char **rp = (char **)0;
    struct ifaddrs *ifa = (struct ifaddrs *)0;
    struct ifaddrs *ip = (struct ifaddrs *)0;
    char **vp = (char **)0;
    char *np = (char *)0;
    unsigned long vs = sizeof(char *);
    unsigned long ns = 0;
    unsigned long rs = 0;
    char **cp = (char **)0;
    do {
        if (getifaddrs(&ifa) < 0) {
            diminuto_log_perror("src/diminuto_ipc.c", 311, "diminuto_ipc_interfaces: getifaddrs");
            break;
        }
        for (ip = ifa; ip != (struct ifaddrs *)0; ip = ip->ifa_next) {
            if (ip->ifa_name != (char *)0) {
                vs += sizeof(char *);
                ns += strnlen(ip->ifa_name, 255) + 1;
            }
        }
        rs = vs + ns;
        rp = (char **)malloc(rs);
        vp = rp;
        np = (char *)vp + vs;
        for (ip = ifa; ip != (struct ifaddrs *)0; ip = ip->ifa_next) {
            if (ip->ifa_name != (char *)0) {
                for (cp = rp; cp < vp; ++cp) {
                    if (strncmp(ip->ifa_name, *cp, 255) == 0) {
                        break;
                    }
                }
                if (cp >= vp) {
                    *(vp++) = np;
                    ns = strnlen(ip->ifa_name, 255);
                    strncpy(np, ip->ifa_name, ns);
                    np += ns;
                    *(np++) = '\0';
                }
            }
        }
        *vp = (char *)0;
    } while (0);
    if (ifa != (struct ifaddrs *)0) {
        freeifaddrs(ifa);
    }
    return rp;
}

variable_types:
rp
char **

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types:
vp
char **

variable_types:
np
char *

variable_types:
vs
unsigned long

variable_types:
ns
unsigned long

variable_types:
rs
unsigned long

variable_types:
cp
char **

return_type: char **

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }


repo: coverclock/com-diag-diminuto

decompiled_code:
ssize_t __fastcall diminuto_ipc_message_receive_generic(int a1, struct msghdr *a2, int a3)
{
ssize_t v3; // r12
int v5; // eax

v3 = recvmsg(a1, a2, a3);
if ( v3 < 0 )
{
v5 = *_errno_location();
if ( v5 != 11 && v5 != 4 )
diminuto_log_perror("src/diminuto_ipc.c", 378LL, "diminuto_ipc_receive: recvmsg");
}
return v3;
}

canonical_decompiled_code:
ssize_t __fastcall func20(int a1, struct msghdr *a2, int a3)
{
ssize_t v3; // r12
int v5; // eax

v3 = recvmsg(a1, a2, a3);
if ( v3 < 0 )
{
v5 = *_errno_location();
if ( v5 != 11 && v5 != 4 )
diminuto_log_perror("src/diminuto_ipc.c", 378LL, "diminuto_ipc_receive: recvmsg");
}
return v3;
}

original_code:
ssize_t diminuto_ipc_message_receive_generic(int fd, struct msghdr * message, int flags)
{
    ssize_t total = -1;
    if ((total = recvmsg(fd, message, flags)) > 0) {
    } else if (total == 0) {
    } else if ((*__errno_location ()) == 4) {
    } else if ((*__errno_location ()) == 11) {
    } else if ((*__errno_location ()) == 11) {
    } else {
        diminuto_log_perror("src/diminuto_ipc.c", 378, "diminuto_ipc_receive: recvmsg");
    }
    return total;
}

canonical_original_code:
long diminuto_ipc_message_receive_generic(int fd, struct msghdr *message, int flags)
{
    long total = -1;
    if ((total = recvmsg(fd, message, flags)) > 0) {
    } else if (total == 0) {
    } else if ((*__errno_location ()) == 4) {
    } else if ((*__errno_location ()) == 11) {
    } else if ((*__errno_location ()) == 11) {
    } else {
        diminuto_log_perror("src/diminuto_ipc.c", 378, "diminuto_ipc_receive: recvmsg");
    }
    return total;
}

variable_types: fd int

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; } *

variable_types: flags int

variable_types: total long

return_type: long

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


decompiled_code:
ssize_t __fastcall diminuto_ipc_message_send_generic(int a1, const struct msghdr *a2, int a3)
{
ssize_t v3; // r12
int v5; // eax

v3 = sendmsg(a1, a2, a3);
if ( v3 < 0 )
{
v5 = *_errno_location();
if ( v5 != 11 && v5 != 4 )
diminuto_log_perror("src/diminuto_ipc.c", 399LL, "diminuto_ipc_send: sendmsg");
}
return v3;
}

canonical_decompiled_code:
ssize_t __fastcall func21(int a1, const struct msghdr *a2, int a3)
{
ssize_t v3; // r12
int v5; // eax

v3 = sendmsg(a1, a2, a3);
if ( v3 < 0 )
{
v5 = *_errno_location();
if ( v5 != 11 && v5 != 4 )
diminuto_log_perror("src/diminuto_ipc.c", 399LL, "diminuto_ipc_send: sendmsg");
}
return v3;
}

original_code:
ssize_t diminuto_ipc_message_send_generic(int fd, const struct msghdr * message, int flags)
{
    ssize_t total = -1;
    if ((total = sendmsg(fd, message, flags)) > 0) {
    } else if (total == 0) {
    } else if ((*__errno_location ()) == 4) {
    } else if ((*__errno_location ()) == 11) {
    } else if ((*__errno_location ()) == 11) {
    } else {
        diminuto_log_perror("src/diminuto_ipc.c", 399, "diminuto_ipc_send: sendmsg");
    }
    return total;
}

canonical_original_code:
long diminuto_ipc_message_send_generic(int fd, struct msghdr *message, int flags)
{
    long total = -1;
    if ((total = sendmsg(fd, message, flags)) > 0) {
    } else if (total == 0) {
    } else if ((*__errno_location ()) == 4) {
    } else if ((*__errno_location ()) == 11) {
    } else if ((*__errno_location ()) == 11) {
    } else {
        diminuto_log_perror("src/diminuto_ipc.c", 399, "diminuto_ipc_send: sendmsg");
    }
    return total;
}

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }


decompiled_code:
__int64 diminuto_frequency()
{
return 1000000000LL;
}

original_code:
static inline diminuto_sticks_t diminuto_frequency(void)
{
    return (1000000000LL);
}

canonical_original_code:
static inline long diminuto_frequency()
{
    return (1000000000LL);
}


original_code:
int diminuto_meter_events(diminuto_meter_t * meterp, diminuto_ticks_t now, size_t events)
{
    int result = 0;
    if (now < meterp->last) {
        (*__errno_location ()) = 34;
        result = -1;
    } else if (events == 0) {
        meterp->last = now;
    } else if (meterp->count == 0) {
        meterp->last = now;
        meterp->events = events;
        meterp->burst = events;
        meterp->count = 1;
    } else if ((DIMINUTO_METER_OVERFLOW - meterp->count) < 1) {
        meterp->last = now;
        meterp->count = DIMINUTO_METER_OVERFLOW;
        (*__errno_location ()) = 75;
        result = -1;
    } else if ((DIMINUTO_METER_OVERFLOW - meterp->events) < events) {
        meterp->last = now;
        meterp->events = DIMINUTO_METER_OVERFLOW;
        (*__errno_location ()) = 75;
        result = -1;
    } else if (now == meterp->last) {
        meterp->peak = DIMINUTO_METER_ERROR;
        meterp->last = now;
        meterp->events += events;
        if (events > meterp->burst) {
            meterp->burst = events;
        }
        meterp->count += 1;
    } else {
        diminuto_ticks_t interarrival = 0;
        double rate = 0.0;
        interarrival = now - meterp->last;
        rate = events;
        rate *= diminuto_frequency();
        rate /= interarrival;
        if (rate > meterp->peak) {
            meterp->peak = rate;
        }
        meterp->last = now;
        meterp->events += events;
        if (events > meterp->burst) {
            meterp->burst = events;
        }
        meterp->count += 1;
    }
    return result;
}

canonical_original_code:
int diminuto_meter_events(struct DiminutoMeter *meterp, unsigned long now, unsigned long events)
{
    int result = 0;
    if (now < meterp->last) {
        (*__errno_location ()) = 34;
        result = -1;
    } else if (events == 0) {
        meterp->last = now;
    } else if (meterp->count == 0) {
        meterp->last = now;
        meterp->events = events;
        meterp->burst = events;
        meterp->count = 1;
    } else if ((DIMINUTO_METER_OVERFLOW - meterp->count) < 1) {
        meterp->last = now;
        meterp->count = DIMINUTO_METER_OVERFLOW;
        (*__errno_location ()) = 75;
        result = -1;
    } else if ((DIMINUTO_METER_OVERFLOW - meterp->events) < events) {
        meterp->last = now;
        meterp->events = DIMINUTO_METER_OVERFLOW;
        (*__errno_location ()) = 75;
        result = -1;
    } else if (now == meterp->last) {
        meterp->peak = DIMINUTO_METER_ERROR;
        meterp->last = now;
        meterp->events += events;
        if (events > meterp->burst) {
            meterp->burst = events;
        }
        meterp->count += 1;
    } else {
        unsigned long interarrival = 0;
        double rate = 0.0;
        interarrival = now - meterp->last;
        rate = events;
        rate *= diminuto_frequency();
        rate /= interarrival;
        if (rate > meterp->peak) {
            meterp->peak = rate;
        }
        meterp->last = now;
        meterp->events += events;
        if (events > meterp->burst) {
            meterp->burst = events;
        }
        meterp->count += 1;
    }
    return result;
}

variable_types: struct DiminutoMeter { unsigned long start; unsigned long last; double peak; unsigned long events; unsigned long burst; unsigned long count; } *

variable_types:
now
unsigned long

variable_types:
events
unsigned long

variable_types: result int

variable_types:
interarrival
unsigned long

variable_types: rate double

return_type: int


decompiled_code:
double __fastcall diminuto_meter_sustained(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
double result; // xmm0_8
unsigned __int64 v8; // rdx
double v9; // xmm1_8
double v10; // xmm0_8
__int64 v11; // rdx
__int64 v12; // rcx
__int64 v13; // rdx
double v14; // xmm1_8

v6 = a1[3];
result = 0.0;
if ( v6 )
{
v8 = a1[1];
result = *(double *)&LC1;
if ( v8 > *a1 )
{
if ( v6 < 0 )
{
a2 = a1[3] & 1 | (a1[3] >> 1);
result = (double)(int)a2;
v9 = result + result;
}
else
{
v9 = (double)(int)v6;
}
v10 = (double)(int)diminuto_frequency(a1, a2, v8, *a1, a5, a6, result, v9) * v9;
v13 = v11 - v12;
if ( v13 < 0 )
v14 = (double)(int)(v13 & 1 | ((unsigned __int64)v13 >> 1))
+ (double)(int)(v13 & 1 | ((unsigned __int64)v13 >> 1));
else
v14 = (double)(int)v13;
result = v10 / v14;
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func2(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
double result; // xmm0_8
unsigned __int64 v8; // rdx
double v9; // xmm1_8
double v10; // xmm0_8
__int64 v11; // rdx
__int64 v12; // rcx
__int64 v13; // rdx
double v14; // xmm1_8

v6 = a1[3];
result = 0.0;
if ( v6 )
{
v8 = a1[1];
result = *(double *)&LC1;
if ( v8 > *a1 )
{
if ( v6 < 0 )
{
a2 = a1[3] & 1 | (a1[3] >> 1);
result = (double)(int)a2;
v9 = result + result;
}
else
{
v9 = (double)(int)v6;
}
v10 = (double)(int)func0(a1, a2, v8, *a1, a5, a6, result, v9) * v9;
v13 = v11 - v12;
if ( v13 < 0 )
v14 = (double)(int)(v13 & 1 | ((unsigned __int64)v13 >> 1))
+ (double)(int)(v13 & 1 | ((unsigned __int64)v13 >> 1));
else
v14 = (double)(int)v13;
result = v10 / v14;
}
}
return result;
}

original_code:
double diminuto_meter_sustained(const diminuto_meter_t * meterp)
{
    double result = 0.0;
    if (meterp->events == 0) {
    } else if (meterp->last <= meterp->start) {
        result = DIMINUTO_METER_ERROR;
    } else {
        result = meterp->events;
        result *= diminuto_frequency();
        result /= (meterp->last - meterp->start);
    }
    return result;
}

canonical_original_code:
double diminuto_meter_sustained(struct DiminutoMeter *meterp)
{
    double result = 0.0;
    if (meterp->events == 0) {
    } else if (meterp->last <= meterp->start) {
        result = DIMINUTO_METER_ERROR;
    } else {
        result = meterp->events;
        result *= diminuto_frequency();
        result /= (meterp->last - meterp->start);
    }
    return result;
}

variable_types: result double

return_type: double

user_defined_types: struct DiminutoMeter { unsigned long start; unsigned long last; double peak; unsigned long events; unsigned long burst; unsigned long count; }


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

if ( a1 )
result = diminuto_log_emit(
"diminuto_meter_t@%p[%zu]: { dt=%llu p=%lf e=%zu b=%zu n=%zu }\n",
a1,
48LL,
*(_QWORD *)(a1 + 8) - *(_QWORD *)a1,
*(_QWORD *)(a1 + 24),
*(_QWORD *)(a1 + 32),
*(double *)(a1 + 16),
*(_QWORD *)(a1 + 40));
else
result = diminuto_log_emit("diminuto_meter_t@%p[%zu]\n", 0LL, 0x30uLL);
return result;
}

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

if ( a1 )
result = diminuto_log_emit(
"diminuto_meter_t@%p[%zu]: { dt=%llu p=%lf e=%zu b=%zu n=%zu }\n",
a1,
48LL,
*(_QWORD *)(a1 + 8) - *(_QWORD *)a1,
*(_QWORD *)(a1 + 24),
*(_QWORD *)(a1 + 32),
*(double *)(a1 + 16),
*(_QWORD *)(a1 + 40));
else
result = diminuto_log_emit("diminuto_meter_t@%p[%zu]\n", 0LL, 0x30uLL);
return result;
}

original_code:
void diminuto_meter_log(const diminuto_meter_t * meterp)
{
    if (meterp != (diminuto_meter_t *)0) {
        diminuto_log_emit("diminuto_meter_t@%p[%zu]: { dt=%llu p=%lf e=%zu b=%zu n=%zu }\n", meterp, sizeof(*meterp), (diminuto_llu_t)(meterp->last - meterp->start), meterp->peak, meterp->events, meterp->burst, meterp->count);
    } else {
        diminuto_log_emit("diminuto_meter_t@%p[%zu]\n", meterp, sizeof(*meterp));
    }
}

canonical_original_code:
void diminuto_meter_log(struct DiminutoMeter *meterp)
{
    if (meterp != (struct DiminutoMeter *)0) {
        diminuto_log_emit("diminuto_meter_t@%p[%zu]: { dt=%llu p=%lf e=%zu b=%zu n=%zu }\n", meterp, sizeof(*meterp), (diminuto_llu_t)(meterp->last - meterp->start), meterp->peak, meterp->events, meterp->burst, meterp->count);
    } else {
        diminuto_log_emit("diminuto_meter_t@%p[%zu]\n", meterp, sizeof(*meterp));
    }
}

return_type: void


decompiled_code:
__int64 __fastcall diminuto_list_dataset(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 24) = a2;
return a1;
}

original_code:
static inline diminuto_list_t * diminuto_list_dataset(diminuto_list_t * nodep, void * datap) {
    nodep->data = datap;
    return nodep;
}

canonical_original_code:
static inline struct DiminutoList *diminuto_list_dataset(struct DiminutoList *nodep, void *datap) {
    nodep->data = datap;
    return nodep;
}

variable_types:
nodep
struct DiminutoList *

variable_types:
datap
void *

return_type: struct DiminutoList { struct DiminutoList *next; struct DiminutoList *prev; struct DiminutoList *root; void *data; } *


decompiled_code:
__int64 __fastcall diminuto_list_datainit(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = diminuto_list_init(a1);
return diminuto_list_dataset((__int64)v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

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

original_code:
static inline diminuto_list_t * diminuto_list_datainit(diminuto_list_t * nodep, void * datap) {
    return diminuto_list_dataset(diminuto_list_init(nodep), datap);
}

canonical_original_code:
static inline struct DiminutoList *diminuto_list_datainit(struct DiminutoList *nodep, void *datap) {
    return diminuto_list_dataset(diminuto_list_init(nodep), datap);
}

user_defined_types: struct DiminutoList { struct DiminutoList *next; struct DiminutoList *prev; struct DiminutoList *root; void *data; }


decompiled_code:
_BOOL8 __fastcall diminuto_list_isempty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
static inline int diminuto_list_isempty(const diminuto_list_t * nodep) {
    return (nodep == nodep->next);
}

canonical_original_code:
static inline int diminuto_list_isempty(struct DiminutoList *nodep) {
    return (nodep == nodep->next);
}

variable_types: struct DiminutoList { struct DiminutoList *next; struct DiminutoList *prev; struct DiminutoList *root; void *data; } *


decompiled_code:
__int64 __fastcall diminuto_memory_alignment(__int64 a1, __int64 a2)
{
return -a2 & (a2 + a1 - 1);
}

original_code:
static inline size_t diminuto_memory_alignment(size_t size, size_t alignment)
{
    --alignment;
    return (size + alignment) & (~alignment);
}

canonical_original_code:
static inline unsigned long diminuto_memory_alignment(unsigned long size, unsigned long alignment)
{
    --alignment;
    return (size + alignment) & (~alignment);
}

variable_types:
size
unsigned long

variable_types:
alignment
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall diminuto_well_fini(__int64 a1)
{
void *v1; // rax
void *v2; // rax

v1 = (void *)diminuto_list_data_isra_0(*(_QWORD *)(a1 + 56));
free(v1);
v2 = (void *)diminuto_list_data_isra_0(*(_QWORD *)(a1 + 24));
free(v2);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
void *v1; // rax
void *v2; // rax

v1 = (void *)func4(*(_QWORD *)(a1 + 56));
free(v1);
v2 = (void *)func4(*(_QWORD *)(a1 + 24));
free(v2);
}

original_code:
void diminuto_well_fini(diminuto_well_t * wellp)
{
    free(diminuto_list_data(&wellp[DIMINUTO_WELL_USED]));
    free(diminuto_list_data(&wellp[DIMINUTO_WELL_FREE]));
}

canonical_original_code:
void diminuto_well_fini(struct DiminutoList *wellp)
{
    free(diminuto_list_data(&wellp[DIMINUTO_WELL_USED]));
    free(diminuto_list_data(&wellp[DIMINUTO_WELL_FREE]));
}


decompiled_code:
__int64 __fastcall diminuto_well_alloc(__int64 a1)
{
__int64 *v1; // rbx
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // r12
__int64 v6; // rax
__int64 result; // rax

v1 = (__int64 *)diminuto_list_root_isra_0(*(_QWORD *)(a1 + 16));
if ( diminuto_list_isempty(v1) )
{
*_errno_location() = 12;
result = 0LL;
}
else
{
v2 = diminuto_list_next_isra_0(*v1);
v3 = diminuto_list_remove(v2);
v4 = v3;
if ( v3 )
{
v5 = diminuto_list_data_isra_0(*(_QWORD *)(v3 + 24));
v6 = diminuto_list_prev_isra_0(v1[5]);
diminuto_list_insert(v6, v4);
result = v5;
}
else
{
*_errno_location() = 14;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 *v1; // rbx
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // r12
__int64 v6; // rax
__int64 result; // rax

v1 = (__int64 *)func5(*(_QWORD *)(a1 + 16));
if ( func2(v1) )
{
*_errno_location() = 12;
result = 0LL;
}
else
{
v2 = func7(*v1);
v3 = diminuto_list_remove(v2);
v4 = v3;
if ( v3 )
{
v5 = func4(*(_QWORD *)(v3 + 24));
v6 = func6(v1[5]);
diminuto_list_insert(v6, v4);
result = v5;
}
else
{
*_errno_location() = 14;
result = 0LL;
}
}
return result;
}

original_code:
void * diminuto_well_alloc(diminuto_well_t * wellp)
{
    void * pointer = (void *)0;
    diminuto_list_t * nodep;
    wellp = diminuto_list_root(wellp);
    if (!diminuto_list_isempty(&wellp[DIMINUTO_WELL_FREE])) {
        nodep = diminuto_list_remove(diminuto_list_next(&wellp[DIMINUTO_WELL_FREE]));
        if (nodep != (diminuto_well_t *)0) {
            pointer = diminuto_list_data(nodep);
            diminuto_list_insert(diminuto_list_prev(&wellp[DIMINUTO_WELL_USED]), nodep);
        } else {
            (*__errno_location ()) = 14;
        }
    } else {
        (*__errno_location ()) = 12;
    }
    return pointer;
}

canonical_original_code:
void *diminuto_well_alloc(struct DiminutoList *wellp)
{
    void *pointer = (void *)0;
    struct DiminutoList *nodep;
    wellp = diminuto_list_root(wellp);
    if (!diminuto_list_isempty(&wellp[DIMINUTO_WELL_FREE])) {
        nodep = diminuto_list_remove(diminuto_list_next(&wellp[DIMINUTO_WELL_FREE]));
        if (nodep != (struct DiminutoList *)0) {
            pointer = diminuto_list_data(nodep);
            diminuto_list_insert(diminuto_list_prev(&wellp[DIMINUTO_WELL_USED]), nodep);
        } else {
            (*__errno_location ()) = 14;
        }
    } else {
        (*__errno_location ()) = 12;
    }
    return pointer;
}

variable_types:
pointer
void *

return_type: void *


decompiled_code:
__int64 __fastcall diminuto_well_free(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
__int64 v4; // rax
_QWORD *v5; // rdi
__int64 v6; // rsi
__int64 v7; // rax

v2 = diminuto_list_root_isra_0(*(_QWORD *)(a1 + 16));
if ( diminuto_list_isempty((_QWORD *)(v2 + 32)) )
{
v3 = -1;
*_errno_location() = 12;
}
else
{
v3 = 0;
v4 = diminuto_list_next_isra_0(*(_QWORD *)(v2 + 32));
v5 = (_QWORD *)diminuto_list_remove(v4);
if ( v5 )
{
v6 = diminuto_list_datainit(v5, a2);
v7 = diminuto_list_prev_isra_0(*(_QWORD *)(v2 + 8));
diminuto_list_insert(v7, v6);
}
else
{
v3 = -1;
*_errno_location() = 14;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
__int64 v4; // rax
_QWORD *v5; // rdi
__int64 v6; // rsi
__int64 v7; // rax

v2 = func5(*(_QWORD *)(a1 + 16));
if ( func2((_QWORD *)(v2 + 32)) )
{
v3 = -1;
*_errno_location() = 12;
}
else
{
v3 = 0;
v4 = func7(*(_QWORD *)(v2 + 32));
v5 = (_QWORD *)diminuto_list_remove(v4);
if ( v5 )
{
v6 = func1(v5, a2);
v7 = func6(*(_QWORD *)(v2 + 8));
diminuto_list_insert(v7, v6);
}
else
{
v3 = -1;
*_errno_location() = 14;
}
}
return v3;
}

original_code:
int diminuto_well_free(diminuto_well_t * wellp, void * pointer)
{
    int rc = -1;
    diminuto_list_t * nodep;
    wellp = diminuto_list_root(wellp);
    if (!diminuto_list_isempty(&wellp[DIMINUTO_WELL_USED])) {
        nodep = diminuto_list_remove(diminuto_list_next(&wellp[DIMINUTO_WELL_USED]));
        if (nodep != (diminuto_well_t *)0) {
            diminuto_list_insert(diminuto_list_prev(&wellp[DIMINUTO_WELL_FREE]), diminuto_list_datainit(nodep, pointer));
            rc = 0;
        } else {
            (*__errno_location ()) = 14;
        }
    } else {
        (*__errno_location ()) = 12;
    }
    return rc;
}

canonical_original_code:
int diminuto_well_free(struct DiminutoList *wellp, void *pointer)
{
    int rc = -1;
    struct DiminutoList *nodep;
    wellp = diminuto_list_root(wellp);
    if (!diminuto_list_isempty(&wellp[DIMINUTO_WELL_USED])) {
        nodep = diminuto_list_remove(diminuto_list_next(&wellp[DIMINUTO_WELL_USED]));
        if (nodep != (struct DiminutoList *)0) {
            diminuto_list_insert(diminuto_list_prev(&wellp[DIMINUTO_WELL_FREE]), diminuto_list_datainit(nodep, pointer));
            rc = 0;
        } else {
            (*__errno_location ()) = 14;
        }
    } else {
        (*__errno_location ()) = 12;
    }
    return rc;
}

variable_types: rc int


input

decompiled_code:
__int64 __fastcall input(char *s, size_t n)
{
int v2; // er8
__int64 result; // rax
int v4; // eax
int v5; // ebx
int *v6; // rax

if ( io == 1 )
{
v4 = fgetc(stdin);
if ( v4 != -1 )
{
*s = v4;
return 1LL;
}
goto LABEL_4;
}
if ( io != 2 )
{
if ( io )
goto LABEL_4;
result = fread(s, 1uLL, n, stdin);
LABEL_7:
if ( result > 0 )
return result;
goto LABEL_4;
}
if ( fgets(s, n, stdin) )
{
s[n - 1] = 0;
result = strlen(s);
goto LABEL_7;
}
LABEL_4:
v2 = feof(stdin);
result = 0LL;
if ( !v2 )
{
v5 = ferror(stdin);
v6 = _errno_location();
if ( v5 )
*v6 = 5;
else
*v6 = 22;
perror("fread");
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, size_t n)
{
int v2; // er8
__int64 result; // rax
int v4; // eax
int v5; // ebx
int *v6; // rax

if ( io == 1 )
{
v4 = fgetc(stdin);
if ( v4 != -1 )
{
*s = v4;
return 1LL;
}
goto LABEL_4;
}
if ( io != 2 )
{
if ( io )
goto LABEL_4;
result = fread(s, 1uLL, n, stdin);
LABEL_7:
if ( result > 0 )
return result;
goto LABEL_4;
}
if ( fgets(s, n, stdin) )
{
s[n - 1] = 0;
result = strlen(s);
goto LABEL_7;
}
LABEL_4:
v2 = feof(stdin);
result = 0LL;
if ( !v2 )
{
v5 = ferror(stdin);
v6 = _errno_location();
if ( v5 )
*v6 = 5;
else
*v6 = 22;
perror("fread");
result = -1LL;
}
return result;
}

original_code:
static ssize_t input(uint8_t * buffer, size_t size)
{
    ssize_t rc = 0;
    int ch = '\0';
    switch (io) {
    case BLOCK:
        rc = fread(buffer, 1, size, stdin);
        break;
    case CHARACTER:
        if ((ch = fgetc(stdin)) != (-1)) {
            *buffer = ch;
            rc = 1;
        }
        break;
    case LINE:
        if (fgets((char *)buffer, (int)size, stdin) != ((void *)0)) {
            buffer[size - 1] = '\0';
            rc = (ssize_t)strlen((char *)buffer);
        }
        break;
    default:
        break;
    }
    if (rc > 0) {
    } else if (feof(stdin)) {
        rc = 0;
    } else if (ferror(stdin)) {
        (*__errno_location ()) = 5;
        perror("fread");
        rc = -1;
    } else {
        (*__errno_location ()) = 22;
        perror("fread");
        rc = -1;
    }
    return rc;
}

canonical_original_code:
static long input(unsigned char *buffer, unsigned long size)
{
    long rc = 0;
    int ch = '\0';
    switch (io) {
    case BLOCK:
        rc = fread(buffer, 1, size, stdin);
        break;
    case CHARACTER:
        if ((ch = fgetc(stdin)) != (-1)) {
            *buffer = ch;
            rc = 1;
        }
        break;
    case LINE:
        if (fgets((char *)buffer, (int)size, stdin) != ((void *)0)) {
            buffer[size - 1] = '\0';
            rc = (long)strlen((char *)buffer);
        }
        break;
    default:
        break;
    }
    if (rc > 0) {
    } else if (feof(stdin)) {
        rc = 0;
    } else if (ferror(stdin)) {
        (*__errno_location ()) = 5;
        perror("fread");
        rc = -1;
    } else {
        (*__errno_location ()) = 22;
        perror("fread");
        rc = -1;
    }
    return rc;
}

variable_types:
buffer
unsigned char *

variable_types: rc long

variable_types: ch int


output

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

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 )
{
if ( result > 0 )
return result;
goto LABEL_4;
}
return a2;
}
if ( fputs((const char *)a1, stdout) > 0 )
return a2;
LABEL_4:
v2 = feof(stdout);
result = 0LL;
if ( !v2 )
{
v5 = ferror(stdout);
v6 = _errno_location();
if ( v5 )
*v6 = 5;
else
*v6 = 22;
perror("fwrite");
result = -1LL;
}
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func2(unsigned __int8 *a1, size_t a2)
{
int v2; // er8
signed __int64 result; // rax
int v4; // er8
int v5; // ebx
int *v6; // rax

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 )
{
if ( result > 0 )
return result;
goto LABEL_4;
}
return a2;
}
if ( fputs((const char *)a1, stdout) > 0 )
return a2;
LABEL_4:
v2 = feof(stdout);
result = 0LL;
if ( !v2 )
{
v5 = ferror(stdout);
v6 = _errno_location();
if ( v5 )
*v6 = 5;
else
*v6 = 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;
}


decompiled_code:
// attributes: thunk
__int64 diminuto_throttle_now()
{
return diminuto_time_elapsed();
}

canonical_decompiled_code:
__int64 func3()
{
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();
}


decompiled_code:
// attributes: thunk
__int64 diminuto_shaper_now()
{
return diminuto_throttle_now();
}

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

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 func0(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

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


decompiled_code:
unsigned __int64 *__fastcall diminuto_buffer_pool_get(__int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v3; // r12
int v4; // er9
__int64 v5; // rdi
unsigned __int64 *result; // rax
size_t v7[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a2 )
{
v7[0] = 0LL;
v3 = (unsigned int)buffer_pool_hash_constprop_0(a1, a2, v7);
if ( buffer_pool_isexternal_isra_0(*a1, v3) || (v5 = a1[2], !buffer_pool_first_isra_0(v5, v3)) )
result = (unsigned __int64 *)buffer_pool_malloc_constprop_0(v7[0], v4);
else
result = buffer_pool_get_isra_0(v5, v3);
if ( result )
result = buffer_pool_init_isra_0(*a1, result, v3, v7[0]);
}
else
{
*_errno_location() = 0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 *__fastcall func5(__int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v3; // r12
int v4; // er9
__int64 v5; // rdi
unsigned __int64 *result; // rax
size_t v7[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a2 )
{
v7[0] = 0LL;
v3 = (unsigned int)func2(a1, a2, v7);
if ( func4(*a1, v3) || (v5 = a1[2], !func3(v5, v3)) )
result = (unsigned __int64 *)func1(v7[0], v4);
else
result = buffer_pool_get_isra_0(v5, v3);
if ( result )
result = buffer_pool_init_isra_0(*a1, result, v3, v7[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: 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[]; } *


decompiled_code:
void __fastcall diminuto_buffer_pool_put(unsigned __int64 *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // r8
_QWORD *v4; // r9

if ( a2 )
{
if ( buffer_pool_isexternal_isra_0(*a1, *(_QWORD *)(a2 - 8)) )
free(v4);
else
buffer_pool_put_isra_0(*(_QWORD *)(v2 + 16), v4, v3);
}
}

canonical_decompiled_code:
void __fastcall func6(unsigned __int64 *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // r8
_QWORD *v4; // r9

if ( a2 )
{
if ( func4(*a1, *(_QWORD *)(a2 - 8)) )
free(v4);
else
buffer_pool_put_isra_0(*(_QWORD *)(v2 + 16), v4, 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);
        }
    }
}

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(__int64 a1)
{
unsigned __int64 v2; // rbx
_BOOL8 result; // rax
_QWORD *v4; // rdi

v2 = 0LL;
for ( result = buffer_pool_isexternal_isra_0(*(_QWORD *)a1, 0LL);
!result;
result = buffer_pool_isexternal_isra_0(*(_QWORD *)a1, v2) )
{
while ( 1 )
{
v4 = buffer_pool_get_isra_0(*(_QWORD *)(a1 + 16), v2);
if ( !v4 )
break;
free(v4);
}
++v2;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
unsigned __int64 v2; // rbx
_BOOL8 result; // rax
_QWORD *v4; // rdi

v2 = 0LL;
for ( result = func4(*(_QWORD *)a1, 0LL);
!result;
result = func4(*(_QWORD *)a1, v2) )
{
while ( 1 )
{
v4 = buffer_pool_get_isra_0(*(_QWORD *)(a1 + 16), v2);
if ( !v4 )
break;
free(v4);
}
++v2;
}
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(__int64 *a1, __int64 a2, unsigned __int64 a3)
{
__int64 v3; // rbx
__int64 v4; // r12
unsigned __int64 v7; // r13
size_t v8; // rdi
_QWORD *v9; // rsi
size_t v10[6]; // [rsp+8h] [rbp-30h] BYREF

v10[0] = 0LL;
if ( !a3 )
return 0LL;
v3 = a2;
if ( !a2 )
return 0LL;
v7 = (unsigned int)buffer_pool_hash_constprop_0(a1, a3, v10);
if ( buffer_pool_isexternal_isra_0(*a1, v7) )
return 0LL;
v8 = v10[0];
v4 = 0LL;
do
{
v9 = buffer_pool_malloc_constprop_0(v8, 0);
if ( !v9 )
break;
buffer_pool_put_isra_0(a1[2], v9, v7);
v8 = v10[0];
v4 += v10[0];
--v3;
}
while ( v3 );
return v4;
}

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

v10[0] = 0LL;
if ( !a3 )
return 0LL;
v3 = a2;
if ( !a2 )
return 0LL;
v7 = (unsigned int)func2(a1, a3, v10);
if ( func4(*a1, v7) )
return 0LL;
v8 = v10[0];
v4 = 0LL;
do
{
v9 = func1(v8, 0);
if ( !v9 )
break;
buffer_pool_put_isra_0(a1[2], v9, v7);
v8 = v10[0];
v4 += v10[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(__int64 a1)
{
unsigned __int64 v1; // r14
__int64 v2; // r13
__int64 v3; // r12
_QWORD *v4; // rax
__int64 v5; // r9
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rax
__int64 v8; // r9
size_t v9; // rdx
__int64 v11; // [rsp-10h] [rbp-38h]

v1 = 0LL;
v2 = 0LL;
v3 = 0LL;
while ( !buffer_pool_isexternal_isra_0(*(_QWORD *)a1, v1) )
{
v4 = (_QWORD *)buffer_pool_first_isra_0(*(_QWORD *)(a1 + 16), v1);
if ( v4 )
{
do
{
v4 = (_QWORD *)*v4;
++v5;
}
while ( v4 );
v2 += v5;
}
v6 = v1++;
v7 = buffer_pool_size((unsigned __int64 *)a1, v6);
v11 = v8 * (v7 + 8);
v3 += v11;
diminuto_log_emit(
"diminuto_buffer_pool_log: pool=%p index=%zu length=%zubytes size=%zubytes subcount=%zu subtotal=%zubytes\n",
(const void *)a1,
v9,
v7,
v7 + 8,
v8,
v11);
}
diminuto_log_emit("diminuto_buffer_pool_log: pool=%p count=%zu total=%zubytes\n", (const void *)a1, v2, v3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
unsigned __int64 v1; // r14
__int64 v2; // r13
__int64 v3; // r12
_QWORD *v4; // rax
__int64 v5; // r9
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rax
__int64 v8; // r9
size_t v9; // rdx
__int64 v11; // [rsp-10h] [rbp-38h]

v1 = 0LL;
v2 = 0LL;
v3 = 0LL;
while ( !func4(*(_QWORD *)a1, v1) )
{
v4 = (_QWORD *)func3(*(_QWORD *)(a1 + 16), v1);
if ( v4 )
{
do
{
v4 = (_QWORD *)*v4;
++v5;
}
while ( v4 );
v2 += v5;
}
v6 = v1++;
v7 = func0((unsigned __int64 *)a1, v6);
v11 = v8 * (v7 + 8);
v3 += v11;
diminuto_log_emit(
"diminuto_buffer_pool_log: pool=%p index=%zu length=%zubytes size=%zubytes subcount=%zu subtotal=%zubytes\n",
(const void *)a1,
v9,
v7,
v7 + 8,
v8,
v11);
}
diminuto_log_emit("diminuto_buffer_pool_log: pool=%p count=%zu total=%zubytes\n", (const void *)a1, v2, 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


decompiled_code:
__int64 __fastcall diminuto_serial_raw(int fd)
{
int v1; // er8
__int64 result; // rax
struct termios termios_p; // [rsp+4h] [rbp-58h] BYREF

*(_QWORD *)&termios_p.c_cc[31] = 0LL;
termios_p.c_ospeed = 0;
*(_OWORD *)&termios_p.c_iflag = 0LL;
*(_OWORD *)&termios_p.c_line = 0LL;
*(_OWORD *)&termios_p.c_cc[15] = 0LL;
if ( isatty(fd) )
{
if ( tcgetattr(fd, &termios_p) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 247LL, "diminuto_serial_raw: tcgetattr");
result = 0xFFFFFFFFLL;
}
else
{
termios_p.c_lflag &= 0xFFFF7FB4;
*(_QWORD *)&termios_p.c_iflag &= 0xFFFFFFFEFFFFFA14LL;
termios_p.c_cflag = termios_p.c_cflag & 0xFFFFFECF | 0x8B0;
*(_WORD *)&termios_p.c_cc[5] = 256;
if ( tcsetattr(fd, 0, &termios_p) < 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; // er8
__int64 result; // rax
struct termios termios_p; // [rsp+4h] [rbp-58h] BYREF

*(_QWORD *)&termios_p.c_cc[31] = 0LL;
termios_p.c_ospeed = 0;
*(_OWORD *)&termios_p.c_iflag = 0LL;
*(_OWORD *)&termios_p.c_line = 0LL;
*(_OWORD *)&termios_p.c_cc[15] = 0LL;
if ( isatty(fd) )
{
if ( tcgetattr(fd, &termios_p) < 0 )
{
diminuto_log_perror("src/diminuto_serial.c", 247LL, "diminuto_serial_raw: tcgetattr");
result = 0xFFFFFFFFLL;
}
else
{
termios_p.c_lflag &= 0xFFFF7FB4;
*(_QWORD *)&termios_p.c_iflag &= 0xFFFFFFFEFFFFFA14LL;
termios_p.c_cflag = termios_p.c_cflag & 0xFFFFFECF | 0x8B0;
*(_WORD *)&termios_p.c_cc[5] = 256;
if ( tcsetattr(fd, 0, &termios_p) < 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:
int __fastcall diminuto_i2c_open(unsigned int a1)
{
int result; // eax
int v2; // [rsp+Ch] [rbp-1Ch]
char s[8]; // [rsp+14h] [rbp-14h] BYREF
int v4; // [rsp+1Ch] [rbp-Ch]

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

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
int result; // eax
int v2; // [rsp+Ch] [rbp-1Ch]
char s[8]; // [rsp+14h] [rbp-14h] BYREF
int v4; // [rsp+1Ch] [rbp-Ch]

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

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:
int __fastcall diminuto_i2c_use(int a1, unsigned __int8 a2)
{
int result; // eax
int v3; // [rsp+Ch] [rbp-Ch]

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

canonical_decompiled_code:
int __fastcall func1(int a1, unsigned __int8 a2)
{
int result; // eax
int v3; // [rsp+Ch] [rbp-Ch]

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

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:
ssize_t __fastcall diminuto_i2c_read(int a1, void *a2, size_t a3)
{
ssize_t result; // rax
ssize_t v5; // [rsp+8h] [rbp-10h]

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

canonical_decompiled_code:
ssize_t __fastcall func2(int a1, void *a2, size_t a3)
{
ssize_t result; // rax
ssize_t v5; // [rsp+8h] [rbp-10h]

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

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:
ssize_t __fastcall diminuto_i2c_write(int a1, const void *a2, size_t a3)
{
ssize_t result; // rax
ssize_t v5; // [rsp+8h] [rbp-10h]

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

canonical_decompiled_code:
ssize_t __fastcall func3(int a1, const void *a2, size_t a3)
{
ssize_t result; // rax
ssize_t v5; // [rsp+8h] [rbp-10h]

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

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; // er12
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; // er12
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; // er12
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; // er12
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; // er12
__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; // er12
__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 ( 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 ( 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 ( 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 ( 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