testnm

decompiled_code:
void __fastcall testnm(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4)
{
__int64 v4; // r15
size_t v5; // r15
__int64 v6; // rbx
int i; // er13
char *v8; // rax
_QWORD *v9; // r14
__int64 v10; // rdx
__int64 v11; // rax
char *v12; // r14
__int64 v13; // r13
unsigned int j; // ebx
char *v15; // r13
__int64 v16; // rbx
__int64 v17; // rbx
__int64 v18; // rax
__int64 k; // rbx
__int64 l; // r13
__int64 v21; // r14
__int64 v22; // rax
char *v23; // rbx
char *v24; // r13
unsigned int m; // ebx
__int64 v26; // r12
char *ptr; // [rsp+10h] [rbp-68h]
char *v30; // [rsp+18h] [rbp-60h]
struct timespec tp; // [rsp+20h] [rbp-58h] BYREF
struct timespec v32; // [rsp+30h] [rbp-48h] BYREF

v4 = a3;
ptr = (char *)malloc(40LL * a1);
v30 = (char *)malloc(40LL * a2);
producerData = malloc(56LL * a1);
consumerData = malloc(8LL * a2);
started = 0;
if ( a1 )
{
v5 = 8 * v4;
v6 = 0LL;
for ( i = 0; i != a1; ++i )
{
v8 = (char *)producerData + v6;
*((_QWORD *)v8 + 2) = a3;
*(_DWORD *)v8 = i;
v9 = (char *)producerData + v6;
v9[3] = malloc(v5);
v9[4] = malloc(v5);
v9[5] = us_to_timespec(a4);
v9[6] = v10;
*(_QWORD *)((char *)producerData + v6 + 8) = 0LL;
v6 += 56LL;
}
if ( !a2 )
goto LABEL_8;
}
else if ( !a2 )
{
goto LABEL_13;
}
v11 = 0LL;
do
{
*(_QWORD *)((char *)consumerData + v11) = 0LL;
v11 += 8LL;
}
while ( v11 != 8LL * a2 );
if ( !a1 )
goto LABEL_11;
LABEL_8:
v12 = ptr;
v13 = 0LL;
for ( j = 0; j < a1; ++j )
{
initializeSender(v12, &queue, producer, (char *)producerData + v13);
v13 += 56LL;
v12 += 40;
}
if ( a2 )
{
LABEL_11:
v15 = v30;
v16 = 0LL;
do
{
initializeReceiver(v15, &queue, consumer, (char *)consumerData + 8 * v16++);
v15 += 40;
}
while ( a2 > (unsigned int)v16 );
}
LABEL_13:
started = 1;
clock_gettime(1, &tp);
do
sched_yield();
while ( getTotalConsumed(a2) < a3 * a1 );
clock_gettime(1, &v32);
v17 = timespec_to_us(v32.tv_sec, v32.tv_nsec);
v18 = timespec_to_us(tp.tv_sec, tp.tv_nsec);
printf(format, v17 - v18);
started = 0;
puts("Distribution of messages among receiver threads:");
if ( a2 )
{
for ( k = 0LL; k != a2; ++k )
printf("Receiver-Thread %i received %lu messages.\n", (unsigned int)k, *((_QWORD *)consumerData + k));
if ( !a1 )
goto LABEL_24;
}
else if ( !a1 )
{
goto LABEL_29;
}
for ( l = 0LL; l != a1; printf(aMessageSendTim, (unsigned int)l++, v21, v22) )
{
v21 = mu_mean(*((_QWORD *)producerData + 7 * l + 4), *((_QWORD *)producerData + 7 * l + 2));
v22 = mu_deviation(*((_QWORD *)producerData + 7 * l + 4), *((_QWORD *)producerData + 7 * l + 2));
}
v23 = ptr;
do
{
finalizeSender(v23);
v23 += 40;
}
while ( v23 != &ptr[40 * a1] );
if ( !a2 )
goto LABEL_27;
LABEL_24:
v24 = v30;
for ( m = 0; m < a2; ++m )
{
finalizeReceiver(v24);
v24 += 40;
}
if ( a1 )
{
LABEL_27:
v26 = 0LL;
do
{
free(*((void **)producerData + 7 * v26 + 3));
free(*((void **)producerData + 7 * v26++ + 4));
}
while ( a1 > (unsigned int)v26 );
}
LABEL_29:
free(consumerData);
consumerData = 0LL;
free(producerData);
producerData = 0LL;
free(ptr);
free(v30);
}

canonical_decompiled_code:
void __fastcall func3(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4)
{
__int64 v4; // r15
size_t v5; // r15
__int64 v6; // rbx
int i; // er13
char *v8; // rax
_QWORD *v9; // r14
__int64 v10; // rdx
__int64 v11; // rax
char *v12; // r14
__int64 v13; // r13
unsigned int j; // ebx
char *v15; // r13
__int64 v16; // rbx
__int64 v17; // rbx
__int64 v18; // rax
__int64 k; // rbx
__int64 l; // r13
__int64 v21; // r14
__int64 v22; // rax
char *v23; // rbx
char *v24; // r13
unsigned int m; // ebx
__int64 v26; // r12
char *ptr; // [rsp+10h] [rbp-68h]
char *v30; // [rsp+18h] [rbp-60h]
struct timespec tp; // [rsp+20h] [rbp-58h] BYREF
struct timespec v32; // [rsp+30h] [rbp-48h] BYREF

v4 = a3;
ptr = (char *)malloc(40LL * a1);
v30 = (char *)malloc(40LL * a2);
producerData = malloc(56LL * a1);
consumerData = malloc(8LL * a2);
started = 0;
if ( a1 )
{
v5 = 8 * v4;
v6 = 0LL;
for ( i = 0; i != a1; ++i )
{
v8 = (char *)producerData + v6;
*((_QWORD *)v8 + 2) = a3;
*(_DWORD *)v8 = i;
v9 = (char *)producerData + v6;
v9[3] = malloc(v5);
v9[4] = malloc(v5);
v9[5] = us_to_timespec(a4);
v9[6] = v10;
*(_QWORD *)((char *)producerData + v6 + 8) = 0LL;
v6 += 56LL;
}
if ( !a2 )
goto LABEL_8;
}
else if ( !a2 )
{
goto LABEL_13;
}
v11 = 0LL;
do
{
*(_QWORD *)((char *)consumerData + v11) = 0LL;
v11 += 8LL;
}
while ( v11 != 8LL * a2 );
if ( !a1 )
goto LABEL_11;
LABEL_8:
v12 = ptr;
v13 = 0LL;
for ( j = 0; j < a1; ++j )
{
initializeSender(v12, &queue, producer, (char *)producerData + v13);
v13 += 56LL;
v12 += 40;
}
if ( a2 )
{
LABEL_11:
v15 = v30;
v16 = 0LL;
do
{
initializeReceiver(v15, &queue, consumer, (char *)consumerData + 8 * v16++);
v15 += 40;
}
while ( a2 > (unsigned int)v16 );
}
LABEL_13:
started = 1;
clock_gettime(1, &tp);
do
sched_yield();
while ( func2(a2) < a3 * a1 );
clock_gettime(1, &v32);
v17 = timespec_to_us(v32.tv_sec, v32.tv_nsec);
v18 = timespec_to_us(tp.tv_sec, tp.tv_nsec);
printf(format, v17 - v18);
started = 0;
puts("Distribution of messages among receiver threads:");
if ( a2 )
{
for ( k = 0LL; k != a2; ++k )
printf("Receiver-Thread %i received %lu messages.\n", (unsigned int)k, *((_QWORD *)consumerData + k));
if ( !a1 )
goto LABEL_24;
}
else if ( !a1 )
{
goto LABEL_29;
}
for ( l = 0LL; l != a1; printf(aMessageSendTim, (unsigned int)l++, v21, v22) )
{
v21 = mu_mean(*((_QWORD *)producerData + 7 * l + 4), *((_QWORD *)producerData + 7 * l + 2));
v22 = mu_deviation(*((_QWORD *)producerData + 7 * l + 4), *((_QWORD *)producerData + 7 * l + 2));
}
v23 = ptr;
do
{
finalizeSender(v23);
v23 += 40;
}
while ( v23 != &ptr[40 * a1] );
if ( !a2 )
goto LABEL_27;
LABEL_24:
v24 = v30;
for ( m = 0; m < a2; ++m )
{
finalizeReceiver(v24);
v24 += 40;
}
if ( a1 )
{
LABEL_27:
v26 = 0LL;
do
{
free(*((void **)producerData + 7 * v26 + 3));
free(*((void **)producerData + 7 * v26++ + 4));
}
while ( a1 > (unsigned int)v26 );
}
LABEL_29:
free(consumerData);
consumerData = 0LL;
free(producerData);
producerData = 0LL;
free(ptr);
free(v30);
}

original_code:
void testnm(unsigned int n,
            unsigned int m,
            long count)
{
    int i;
    senderthread_t* senders = (senderthread_t*)malloc(n*sizeof(senderthread_t));
    receiverthread_t* receivers = (receiverthread_t*)malloc(m*sizeof(receiverthread_t));
    producerData = (producerdata_t*)malloc(n*sizeof(producerdata_t));
    consumerData = (consumerdata_t*)malloc(m*sizeof(consumerdata_t));
    started = 0;
    for( i=0 ; i<n ; ++i )
    {
        producerData[i].count = count;
        producerData[i].source = i;
        producerData[i].arrived = (int*)malloc(count*sizeof(int));
        memset(producerData[i].arrived, 0, count*sizeof(int));
        pthread_mutex_init(&producerData[i].arrivedMutex, ((void *)0));
    }
    for( i=0; i<m ; ++i )
    {
        consumerData[i].count = 0;
    }
    for( i=0 ; i<n ; ++i )
    {
        initializeSender(&senders[i], &queue, producer, &producerData[i]);
    }
    for( i=0 ; i<m ; ++i )
    {
        initializeReceiver(&receivers[i], &queue, consumer, &consumerData[i]);
    }
    started = 1;
    {
        struct timespec starttime;
        struct timespec stoptime;
        int64_t delta;
        clock_gettime( 1, &starttime );
        do
        {
            sched_yield();
        } while(getTotalConsumed(m)<n*count);
        clock_gettime( 1, &stoptime );
        delta = timespec_to_us( stoptime )-timespec_to_us( starttime );
        printf("Total time consumed %li µs\n", (long int)delta);
    }
    started = 0;
    for( i=0 ; i<n ; ++i )
    {
        int j;
        for(j=0; j<count;++j)
        {
            if(producerData[i].arrived[j]!=1)
            {
                printf("Invalid arrival count for source %i, message %i : %i\n",i,j,producerData[i].arrived[j]);
            }
        }
    }
    printf("Processing distribution among receiver threads:\n");
    for( i=0 ; i<m ; ++i )
    {
        printf("Receiver-Thread %i  received %lu\n", i, consumerData[i].count);
    }
    for( i=0 ; i<n ; ++i )
    {
        finalizeSender( &senders[i] );
    }
    for( i=0 ; i<m ; ++i )
    {
        finalizeReceiver( &receivers[i] );
    }
    for( i=0 ; i<n ; ++i )
    {
        free(producerData[i].arrived);
        pthread_mutex_destroy(&producerData[i].arrivedMutex);
    }
    free(consumerData);
    consumerData=((void *)0);
    free(producerData);
    producerData=((void *)0);
    free(senders);
    free(receivers);
}

canonical_original_code:
void testnm(unsigned int n, unsigned int m, long count)
{
    int i;
    struct senderthread_t *senders = (senderthread_t*)malloc(n*sizeof(senderthread_t));
    struct receiverthread_t *receivers = (receiverthread_t*)malloc(m*sizeof(receiverthread_t));
    producerData = (struct producerdata_t *)malloc(n*sizeof(producerdata_t));
    consumerData = (struct consumerdata_t *)malloc(m*sizeof(consumerdata_t));
    started = 0;
    for( i=0 ; i<n ; ++i )
    {
        producerData[i].count = count;
        producerData[i].source = i;
        producerData[i].arrived = (int *)malloc(count*sizeof(int));
        memset(producerData[i].arrived, 0, count*sizeof(int));
        pthread_mutex_init(&producerData[i].arrivedMutex, ((void *)0));
    }
    for( i=0; i<m ; ++i )
    {
        consumerData[i].count = 0;
    }
    for( i=0 ; i<n ; ++i )
    {
        initializeSender(&senders[i], &queue, producer, &producerData[i]);
    }
    for( i=0 ; i<m ; ++i )
    {
        initializeReceiver(&receivers[i], &queue, consumer, &consumerData[i]);
    }
    started = 1;
    {
        struct timespec starttime;
        struct timespec stoptime;
        long delta;
        clock_gettime( 1, &starttime );
        do
        {
            sched_yield();
        } while(getTotalConsumed(m)<n*count);
        clock_gettime( 1, &stoptime );
        delta = timespec_to_us( stoptime )-timespec_to_us( starttime );
        printf("Total time consumed %li µs\n", (long)delta);
    }
    started = 0;
    for( i=0 ; i<n ; ++i )
    {
        int j;
        for(j=0; j<count;++j)
        {
            if(producerData[i].arrived[j]!=1)
            {
                printf("Invalid arrival count for source %i, message %i : %i\n",i,j,producerData[i].arrived[j]);
            }
        }
    }
    printf("Processing distribution among receiver threads:\n");
    for( i=0 ; i<m ; ++i )
    {
        printf("Receiver-Thread %i  received %lu\n", i, consumerData[i].count);
    }
    for( i=0 ; i<n ; ++i )
    {
        finalizeSender( &senders[i] );
    }
    for( i=0 ; i<m ; ++i )
    {
        finalizeReceiver( &receivers[i] );
    }
    for( i=0 ; i<n ; ++i )
    {
        free(producerData[i].arrived);
        pthread_mutex_destroy(&producerData[i].arrivedMutex);
    }
    free(consumerData);
    consumerData=((void *)0);
    free(producerData);
    producerData=((void *)0);
    free(senders);
    free(receivers);
}

variable_types:
n
unsigned int

variable_types:
m
unsigned int

variable_types: count long

variable_types: i int

variable_types: struct receiverthread_t { unsigned long thread; void (*receiverDest)(int, void *, unsigned long, void *); void *receiverDestParam; struct nmqueue_t { unsigned long readPosition; unsigned long writePosition; unsigned long length; void *abort; struct nmqueue_message_s { void *data; unsigned long dataSize; int source; } *queue; 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; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } writtenCond; union pthread_cond_t readCond; } *queue; int terminated; } *

variable_types: delta long

variable_types: j int

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }

user_defined_types: struct producerdata_t { int source; long count; union pthread_mutex_t arrivedMutex; int *arrived; }


producer

decompiled_code:
__int64 __fastcall producer(_DWORD *a1, _QWORD *a2, _QWORD *a3, __int64 a4)
{
__int64 result; // rax
struct timespec v7; // [rsp+0h] [rbp-38h] BYREF

if ( *(_QWORD *)(a4 + 8) == *(_QWORD *)(a4 + 16) )
{
sched_yield();
result = 1LL;
}
else
{
while ( !started )
sched_yield();
v7 = (struct timespec)_mm_loadu_si128((const __m128i *)(a4 + 40));
while ( v7 != 0uLL && nanosleep(&v7, &v7) )
;
*a1 = *(_DWORD *)a4;
*a2 = 0LL;
*a3 = *(_QWORD *)(a4 + 8);
clock_gettime(1, &v7);
*(_QWORD *)(*(_QWORD *)(a4 + 24) + 8LL * (*(_QWORD *)(a4 + 8))++) = timespec_to_us(v7.tv_sec, v7.tv_nsec);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _QWORD *a2, _QWORD *a3, __int64 a4)
{
__int64 result; // rax
struct timespec v7; // [rsp+0h] [rbp-38h] BYREF

if ( *(_QWORD *)(a4 + 8) == *(_QWORD *)(a4 + 16) )
{
sched_yield();
result = 1LL;
}
else
{
while ( !started )
sched_yield();
v7 = (struct timespec)_mm_loadu_si128((const __m128i *)(a4 + 40));
while ( v7 != 0uLL && nanosleep(&v7, &v7) )
;
*a1 = *(_DWORD *)a4;
*a2 = 0LL;
*a3 = *(_QWORD *)(a4 + 8);
clock_gettime(1, &v7);
*(_QWORD *)(*(_QWORD *)(a4 + 24) + 8LL * (*(_QWORD *)(a4 + 8))++) = timespec_to_us(v7.tv_sec, v7.tv_nsec);
result = 0LL;
}
return result;
}

original_code:
int producer(source_t* source,
             void** data,
             size_t* dataSize,
             void* param)
{
    producerdata_t* pdata = (producerdata_t*)param;
    if( pdata->count != 0 )
    {
        while(!started)
        {
            sched_yield();
        }
        pdata->count--;
        *source = pdata->source;
        *data = ((void *)0);
        *dataSize = pdata->count;
        return 0;
    }
    else
    {
        sched_yield();
    }
    return 1;
}

canonical_original_code:
int producer(int *source, void **data, unsigned long *dataSize, void *param)
{
    struct producerdata_t *pdata = (producerdata_t*)param;
    if( pdata->count != 0 )
    {
        while(!started)
        {
            sched_yield();
        }
        pdata->count--;
        *source = pdata->source;
        *data = ((void *)0);
        *dataSize = pdata->count;
        return 0;
    }
    else
    {
        sched_yield();
    }
    return 1;
}

variable_types:
source
int *

variable_types:
data
void **

variable_types:
dataSize
unsigned long *

variable_types:
param
void *

variable_types: struct producerdata_t { int source; long count; 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; } arrivedMutex; int *arrived; } *

return_type: int

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


getTotalConsumed

decompiled_code:
__int64 __fastcall getTotalConsumed(int a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx

if ( !a1 )
return 0LL;
v1 = consumerData;
v2 = 0LL;
do
v2 += *v1++;
while ( v1 != (_QWORD *)((char *)consumerData + 8 * (unsigned int)(a1 - 1) + 8) );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx

if ( !a1 )
return 0LL;
v1 = consumerData;
v2 = 0LL;
do
v2 += *v1++;
while ( v1 != (_QWORD *)((char *)consumerData + 8 * (unsigned int)(a1 - 1) + 8) );
return v2;
}

original_code:
long getTotalConsumed(unsigned int consumers)
{
    int i;
    long count = 0;
    for( i=0 ; i<consumers ; ++i )
    {
        count+=consumerData[i].count;
    }
    return count;
}

variable_types:
consumers
unsigned int

return_type: long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v5; // rax

v3 = nmqueue_initialize(&queue, 1024LL, envp);
if ( v3 )
{
v5 = (const char *)nmqueue_error_to_string(v3);
printf("Failed to initialize nmqueue: %s\n", v5);
}
testnm(1u, 1u, 1000000LL, 0LL);
testnm(2u, 2u, 1000000LL, 0LL);
nmqueue_finalize(&queue);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v5; // rax

v3 = nmqueue_initialize(&queue, 1024LL, envp);
if ( v3 )
{
v5 = (const char *)nmqueue_error_to_string(v3);
printf("Failed to initialize nmqueue: %s\n", v5);
}
func3(1u, 1u, 1000000LL, 0LL);
func3(2u, 2u, 1000000LL, 0LL);
nmqueue_finalize(&queue);
return 0;
}

original_code:
int main()
{
    {
        int err;
        if( (err=nmqueue_initialize(&queue,1024)) != 0)
        {
            printf("Failed to initialize nmqueue: %s\n",nmqueue_error_to_string(err));
        }
    }
    testnm(20, 20, 1000000);
    nmqueue_finalize(&queue);
    return 0;
}

variable_types: err int


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return printf(
"Usage: %s [OPTION]... [FILE]...\n"
"Check whether input files are valid UTF-8.\n"
"\n"
" -h, --help display this help text and exit\n"
" -q, --quiet suppress all normal output\n"
" -l, --list print only names of FILEs containing invalid UTF-8\n"
" -i, --invert list valid UTF-8 files instead of invalid ones\n"
" -v, --verbose print detailed error (multiple lines)\n"
"\n"
"This is version %s.\n",
a1,
"1.2");
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf(
"Usage: %s [OPTION]... [FILE]...\n"
"Check whether input files are valid UTF-8.\n"
"\n"
" -h, --help display this help text and exit\n"
" -q, --quiet suppress all normal output\n"
" -l, --list print only names of FILEs containing invalid UTF-8\n"
" -i, --invert list valid UTF-8 files instead of invalid ones\n"
" -v, --verbose print detailed error (multiple lines)\n"
"\n"
"This is version %s.\n",
a1,
"1.2");
}

original_code:
static void usage(const char *program_name) {
    printf("Usage: %s [OPTION]... [FILE]...\n"
           "Check whether input files are valid UTF-8.\n"
           "\n"
           "  -h, --help       display this help text and exit\n"
           "  -q, --quiet      suppress all normal output\n"
           "  -l, --list       print only names of FILEs containing invalid UTF-8\n"
           "  -i, --invert     list valid UTF-8 files instead of invalid ones\n"
           "  -v, --verbose    print detailed error (multiple lines)\n"
           "\n"
           "This is version %s.\n",
           program_name, "1.2");
}

canonical_original_code:
static void usage(char *program_name) {
    printf("Usage: %s [OPTION]... [FILE]...\n"
           "Check whether input files are valid UTF-8.\n"
           "\n"
           "  -h, --help       display this help text and exit\n"
           "  -q, --quiet      suppress all normal output\n"
           "  -l, --list       print only names of FILEs containing invalid UTF-8\n"
           "  -i, --invert     list valid UTF-8 files instead of invalid ones\n"
           "  -v, --verbose    print detailed error (multiple lines)\n"
           "\n"
           "This is version %s.\n",
           program_name, "1.2");
}

return_type: void


decompiled_code:
__int64 __fastcall show_hex_str(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
unsigned int v3; // ebp

if ( !a2 )
return 0;
v2 = a1;
v3 = 0;
do
v3 += printf("%.2X ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
unsigned int v3; // ebp

if ( !a2 )
return 0;
v2 = a1;
v3 = 0;
do
v3 += printf("%.2X ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
return v3;
}

original_code:
static int show_hex_str(const char *str, unsigned int max_length)
{
    int printed = 0;
    while (max_length-- > 0)
        printed += printf("%.2X ", (unsigned char)*str++);
    return printed;
}

canonical_original_code:
static int show_hex_str(char *str, unsigned int max_length)
{
    int printed = 0;
    while (max_length-- > 0)
        printed += printf("%.2X ", (unsigned char)*str++);
    return printed;
}

variable_types:
str
char *

variable_types: printed int


original_code:
static void show_context(char *str, int str_length, int err_pos_in_str, int faulty_bytes)
{
    int chars_before_error = (((err_pos_in_str) < (8)) ? (err_pos_in_str) : (8));
    int chars_after_error = (((str_length - err_pos_in_str) < (8)) ? (str_length - err_pos_in_str) : (8));
    int printed = 0;
    printed = show_hex_str(str + err_pos_in_str - chars_before_error, chars_before_error + chars_after_error);
    printf("%*s | ", 3 * 16 - printed, "");
    show_str(str + err_pos_in_str - chars_before_error, chars_before_error + chars_after_error);
    printf("\n");
    printed = printf("%*s", (3 * chars_before_error), "");
    printed += printf("%.*s", faulty_bytes * 2 + faulty_bytes - 1, "^^^^^^^^^^^^^^^^");
    printf("%*s | ", 3 * 16 - printed, "");
    printf("%*s", (chars_before_error), "");
    printf("%.*s", faulty_bytes, "^^^^");
    printf("\n\n");
}


decompiled_code:
int __fastcall print_utf8_error(const char *a1, unsigned int a2, unsigned int a3, unsigned int a4, __int64 a5, int a6, int a7, const char *a8, int a9, int a10, int a11, int a12, int a13)
{
int result; // eax

if ( !a10 )
{
if ( a8 && !a13 )
{
if ( !a12 )
{
result = printf("%s: line %d, char %d, byte %d: %s\n", a1, a2, a3, a4, a8);
if ( a11 )
result = show_context(a5, a6, a7, a9);
return result;
}
return puts(a1);
}
if ( !a8 && a13 )
return puts(a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, unsigned int a2, unsigned int a3, unsigned int a4, __int64 a5, int a6, int a7, const char *a8, int a9, int a10, int a11, int a12, int a13)
{
int result; // eax

if ( !a10 )
{
if ( a8 && !a13 )
{
if ( !a12 )
{
result = printf("%s: line %d, char %d, byte %d: %s\n", a1, a2, a3, a4, a8);
if ( a11 )
result = func4(a5, a6, a7, a9);
return result;
}
return puts(a1);
}
if ( !a8 && a13 )
return puts(a1);
}
return result;
}

original_code:
static void print_utf8_error(
    const char* file_path,
    int error_line, int error_column, int byte_no,
    char *str, int str_length, int err_pos_in_str,
    const char *message, int faulty_bytes,
    int quiet, int verbose,
    int list_only, int invert)
{
    if (quiet)
        return;
    if (message && !invert)
    {
        if (list_only)
            printf("%s\n", file_path);
        else
            printf("%s: line %d, char %d, byte %d: %s\n",
                   file_path, error_line, error_column, byte_no,
                   message);
        if (verbose && !list_only)
        {
            show_context(str, str_length, err_pos_in_str, faulty_bytes);
        }
    }
    if (!message && invert)
    {
        printf("%s\n", file_path);
    }
}

canonical_original_code:
static void print_utf8_error(char *file_path, int error_line, int error_column, int byte_no, char *str, int str_length, int err_pos_in_str, char *message, int faulty_bytes, int quiet, int verbose, int list_only, int invert)
{
    if (quiet)
        return;
    if (message && !invert)
    {
        if (list_only)
            printf("%s\n", file_path);
        else
            printf("%s: line %d, char %d, byte %d: %s\n",
                   file_path, error_line, error_column, byte_no,
                   message);
        if (verbose && !list_only)
        {
            show_context(str, str_length, err_pos_in_str, faulty_bytes);
        }
    }
    if (!message && invert)
    {
        printf("%s\n", file_path);
    }
}

variable_types:
message
char *

variable_types: quiet int

variable_types: verbose int

variable_types: invert int


decompiled_code:
_BOOL8 __fastcall is_utf8_mmap(char *filename, int a2, int a3, int a4, int a5)
{
int v7; // eax
int v8; // ebx
void *v9; // rax
void *v10; // r12
int v11; // eax
unsigned int v12; // er15
_BOOL4 v13; // ebp
FILE *v15; // rax
int v17; // [rsp+1Ch] [rbp-DCh] BYREF
unsigned int v18; // [rsp+20h] [rbp-D8h] BYREF
unsigned int v19; // [rsp+24h] [rbp-D4h] BYREF
const char *v20; // [rsp+28h] [rbp-D0h] BYREF
struct stat buf; // [rsp+30h] [rbp-C8h] BYREF

v19 = 1;
v18 = 0;
v17 = 0;
v7 = open(filename, 0);
if ( v7 == -1 )
{
perror("open");
v13 = 1;
}
else
{
v8 = v7;
if ( fstat(v7, &buf) == -1 )
{
perror("fstat");
v13 = 1;
}
else
{
v9 = mmap(0LL, buf.st_size, 1, 2, v8, 0LL);
v10 = v9;
if ( v9 == (void *)-1LL )
{
close(v8);
v15 = fopen(filename, "r");
return is_utf8_readline(v15, filename, a2, a3, a4, a5);
}
v11 = is_utf8(v9, buf.st_size, &v20, &v17);
v12 = v11;
if ( v20 )
count_lines((__int64)v10, buf.st_size, v11, &v18, &v19);
print_utf8_error(filename, v18, v19, v12, (__int64)v10, buf.st_size, v12, v20, v17, a2, a3, a4, a5);
v13 = v20 != 0LL;
munmap(v10, buf.st_size);
}
close(v8);
}
return v13;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(char *filename, int a2, int a3, int a4, int a5)
{
int v7; // eax
int v8; // ebx
void *v9; // rax
void *v10; // r12
int v11; // eax
unsigned int v12; // er15
_BOOL4 v13; // ebp
FILE *v15; // rax
int v17; // [rsp+1Ch] [rbp-DCh] BYREF
unsigned int v18; // [rsp+20h] [rbp-D8h] BYREF
unsigned int v19; // [rsp+24h] [rbp-D4h] BYREF
const char *v20; // [rsp+28h] [rbp-D0h] BYREF
struct stat buf; // [rsp+30h] [rbp-C8h] BYREF

v19 = 1;
v18 = 0;
v17 = 0;
v7 = open(filename, 0);
if ( v7 == -1 )
{
perror("open");
v13 = 1;
}
else
{
v8 = v7;
if ( fstat(v7, &buf) == -1 )
{
perror("fstat");
v13 = 1;
}
else
{
v9 = mmap(0LL, buf.st_size, 1, 2, v8, 0LL);
v10 = v9;
if ( v9 == (void *)-1LL )
{
close(v8);
v15 = fopen(filename, "r");
return func6(v15, filename, a2, a3, a4, a5);
}
v11 = is_utf8(v9, buf.st_size, &v20, &v17);
v12 = v11;
if ( v20 )
func0((__int64)v10, buf.st_size, v11, &v18, &v19);
func5(filename, v18, v19, v12, (__int64)v10, buf.st_size, v12, v20, v17, a2, a3, a4, a5);
v13 = v20 != 0LL;
munmap(v10, buf.st_size);
}
close(v8);
}
return v13;
}

original_code:
static int is_utf8_mmap(const char *file_path, int quiet, int verbose,
                        int list_only, int invert)
{
    char *addr;
    struct stat sb;
    int fd;
    int pos = 0;
    char *message;
    int retval = 0;
    int error_column = 1;
    int error_line = 0;
    int faulty_bytes = 0;
    fd = open(file_path, 00);
    if (fd == -1)
        do {retval = 1; perror("open"); goto err_open;} while (0);
    if (fstat(fd, &sb) == -1)
        do {retval = 1; perror("fstat"); goto err_fstat;} while (0);
    addr = mmap(((void *)0), sb.st_size, 0x1, 0x02, fd, 0);
    if (addr == ((void *) -1))
    {
        close(fd);
        return is_utf8_readline(fopen(file_path, "r"), file_path,
                                quiet, verbose, list_only, invert);
    }
    pos = is_utf8((unsigned char*)addr, sb.st_size, &message, &faulty_bytes);
    if (message != ((void *)0))
        count_lines(addr, sb.st_size, pos, &error_line, &error_column);
    print_utf8_error(file_path, error_line, error_column, pos,
                     addr, sb.st_size, pos, message, faulty_bytes,
                     quiet, verbose, list_only, invert);
    if (message != ((void *)0))
        retval = 1;
    munmap(addr, sb.st_size);
err_fstat:
    close(fd);
err_open:
    return retval;
}

canonical_original_code:
static int is_utf8_mmap(char *file_path, int quiet, int verbose, int list_only, int invert)
{
    char *addr;
    struct stat sb;
    int fd;
    int pos = 0;
    char *message;
    int retval = 0;
    int error_column = 1;
    int error_line = 0;
    int faulty_bytes = 0;
    fd = open(file_path, 00);
    if (fd == -1)
        do {retval = 1; perror("open"); goto err_open;} while (0);
    if (fstat(fd, &sb) == -1)
        do {retval = 1; perror("fstat"); goto err_fstat;} while (0);
    addr = mmap(((void *)0), sb.st_size, 0x1, 0x02, fd, 0);
    if (addr == ((void *) -1))
    {
        close(fd);
        return is_utf8_readline(fopen(file_path, "r"), file_path,
                                quiet, verbose, list_only, invert);
    }
    pos = is_utf8((unsigned char *)addr, sb.st_size, &message, &faulty_bytes);
    if (message != ((void *)0))
        count_lines(addr, sb.st_size, pos, &error_line, &error_column);
    print_utf8_error(file_path, error_line, error_column, pos,
                     addr, sb.st_size, pos, message, faulty_bytes,
                     quiet, verbose, list_only, invert);
    if (message != ((void *)0))
        retval = 1;
    munmap(addr, sb.st_size);
err_fstat:
    close(fd);
err_open:
    return retval;
}

variable_types:
addr
char *

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

variable_types: fd int

variable_types: pos int

variable_types: retval int

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
__int64 v6; // r13
struct option v7; // [rsp+0h] [rbp-F8h] BYREF
const char *v8; // [rsp+20h] [rbp-D8h]
int v9; // [rsp+28h] [rbp-D0h]
int *v10; // [rsp+30h] [rbp-C8h]
int v11; // [rsp+38h] [rbp-C0h]
const char *v12; // [rsp+40h] [rbp-B8h]
int v13; // [rsp+48h] [rbp-B0h]
int *v14; // [rsp+50h] [rbp-A8h]
int v15; // [rsp+58h] [rbp-A0h]
const char *v16; // [rsp+60h] [rbp-98h]
int v17; // [rsp+68h] [rbp-90h]
int *v18; // [rsp+70h] [rbp-88h]
int v19; // [rsp+78h] [rbp-80h]
const char *v20; // [rsp+80h] [rbp-78h]
int v21; // [rsp+88h] [rbp-70h]
int *v22; // [rsp+90h] [rbp-68h]
int v23; // [rsp+98h] [rbp-60h]
__int64 v24; // [rsp+A0h] [rbp-58h]
int v25; // [rsp+A8h] [rbp-50h]
__int64 v26; // [rsp+B0h] [rbp-48h]
int v27; // [rsp+B8h] [rbp-40h]
int v28; // [rsp+C0h] [rbp-38h] BYREF
int v29; // [rsp+C4h] [rbp-34h] BYREF
int v30; // [rsp+C8h] [rbp-30h] BYREF
int v31; // [rsp+CCh] [rbp-2Ch] BYREF

v31 = 0;
v30 = 0;
v29 = 0;
v28 = 0;
v7.name = "help";
v7.has_arg = 0;
v7.flag = 0LL;
v7.val = 104;
v8 = "quiet";
v9 = 0;
v10 = &v31;
v11 = 1;
v12 = "list-only";
v13 = 0;
v14 = &v30;
v15 = 1;
v16 = "invert";
v17 = 0;
v18 = &v29;
v19 = 1;
v20 = "verbose";
v21 = 0;
v22 = &v28;
v23 = 1;
v24 = 0LL;
v25 = 0;
v26 = 0LL;
v27 = 0;
while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "hqliv", &v7, 0LL);
if ( v3 == -1 )
break;
if ( v3 > 118 )
goto LABEL_7;
if ( v3 > 103 )
{
switch ( v3 )
{
case 'h':
usage(*argv);
v4 = 0;
break;
case 'i':
v29 = 1;
continue;
case 'l':
v30 = 1;
continue;
case 'q':
v31 = 1;
continue;
case 'v':
v28 = 1;
continue;
default:
goto LABEL_7;
}
return v4;
}
if ( v3 )
{
LABEL_7:
usage(*argv);
return 1;
}
}
if ( optind == argc )
return is_utf8_readline(stdin, "(standard input)", v31, v28, v30, v29);
v6 = optind;
v4 = 0;
while ( argc > (int)v6 )
{
if ( is_utf8_mmap((char *)argv[v6], v31, v28, v30, v29) )
v4 = 1;
++v6;
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
__int64 v6; // r13
struct option v7; // [rsp+0h] [rbp-F8h] BYREF
const char *v8; // [rsp+20h] [rbp-D8h]
int v9; // [rsp+28h] [rbp-D0h]
int *v10; // [rsp+30h] [rbp-C8h]
int v11; // [rsp+38h] [rbp-C0h]
const char *v12; // [rsp+40h] [rbp-B8h]
int v13; // [rsp+48h] [rbp-B0h]
int *v14; // [rsp+50h] [rbp-A8h]
int v15; // [rsp+58h] [rbp-A0h]
const char *v16; // [rsp+60h] [rbp-98h]
int v17; // [rsp+68h] [rbp-90h]
int *v18; // [rsp+70h] [rbp-88h]
int v19; // [rsp+78h] [rbp-80h]
const char *v20; // [rsp+80h] [rbp-78h]
int v21; // [rsp+88h] [rbp-70h]
int *v22; // [rsp+90h] [rbp-68h]
int v23; // [rsp+98h] [rbp-60h]
__int64 v24; // [rsp+A0h] [rbp-58h]
int v25; // [rsp+A8h] [rbp-50h]
__int64 v26; // [rsp+B0h] [rbp-48h]
int v27; // [rsp+B8h] [rbp-40h]
int v28; // [rsp+C0h] [rbp-38h] BYREF
int v29; // [rsp+C4h] [rbp-34h] BYREF
int v30; // [rsp+C8h] [rbp-30h] BYREF
int v31; // [rsp+CCh] [rbp-2Ch] BYREF

v31 = 0;
v30 = 0;
v29 = 0;
v28 = 0;
v7.name = "help";
v7.has_arg = 0;
v7.flag = 0LL;
v7.val = 104;
v8 = "quiet";
v9 = 0;
v10 = &v31;
v11 = 1;
v12 = "list-only";
v13 = 0;
v14 = &v30;
v15 = 1;
v16 = "invert";
v17 = 0;
v18 = &v29;
v19 = 1;
v20 = "verbose";
v21 = 0;
v22 = &v28;
v23 = 1;
v24 = 0LL;
v25 = 0;
v26 = 0LL;
v27 = 0;
while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "hqliv", &v7, 0LL);
if ( v3 == -1 )
break;
if ( v3 > 118 )
goto LABEL_7;
if ( v3 > 103 )
{
switch ( v3 )
{
case 'h':
func1(*argv);
v4 = 0;
break;
case 'i':
v29 = 1;
continue;
case 'l':
v30 = 1;
continue;
case 'q':
v31 = 1;
continue;
case 'v':
v28 = 1;
continue;
default:
goto LABEL_7;
}
return v4;
}
if ( v3 )
{
LABEL_7:
func1(*argv);
return 1;
}
}
if ( optind == argc )
return func6(stdin, "(standard input)", v31, v28, v30, v29);
v6 = optind;
v4 = 0;
while ( argc > (int)v6 )
{
if ( func7((char *)argv[v6], v31, v28, v30, v29) )
v4 = 1;
++v6;
}
return v4;
}

original_code:
int main(int ac, char **av)
{
    int quiet = 0;
    int exit_value = 0;
    int i;
    int list_only = 0;
    int invert = 0;
    int verbose = 0;
    int opt;
    struct option options[] = {
        { "help", 0, ((void *)0), 'h' },
        { "quiet", 0, &quiet, 1 },
        { "list-only", 0, &list_only, 1 },
        { "invert", 0, &invert, 1 },
        { "verbose", 0, &verbose, 1 },
        { 0, 0, 0, 0 }
    };
    while ((opt = getopt_long(ac, av, "hqliv", options, ((void *)0))) != -1) {
        switch (opt) {
            case 0:
                break;
            case 'h':
                usage(av[0]);
                return 0;
            case 'q':
                quiet = 1;
                break;
            case 'l':
                list_only = 1;
                break;
            case 'i':
                invert = 1;
                break;
            case 'v':
                verbose = 1;
                break;
            case '?':
                usage(av[0]);
                return 1;
            default:
                usage(av[0]);
                return 1;
        }
    }
    if (optind == ac)
    {
        return is_utf8_readline(stdin, "(standard input)", quiet, verbose,
                                list_only, invert);
    }
    else
    {
        for (i = optind; i < ac; ++i)
        {
            if (is_utf8_mmap(av[i], quiet, verbose,
                             list_only, invert) == 1)
                exit_value = 1;
        }
        return exit_value;
    }
}

variable_types: ac int

variable_types:
av
char **

variable_types: i int

variable_types: opt int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


decompiled_code:
unsigned __int64 __fastcall is_utf8(__int64 a1, unsigned __int64 a2, _QWORD *a3, _DWORD *a4)
{
unsigned __int64 result; // rax
char v6; // dl

*a3 = 0LL;
*a4 = 0;
if ( !a2 )
return 0LL;
result = 0LL;
do
{
v6 = *(_BYTE *)(a1 + result);
if ( v6 >= 0 )
{
++result;
}
else if ( (unsigned __int8)(v6 + 62) > 0x1Du )
{
if ( v6 == -32 )
{
if ( result + 2 >= a2 )
{
*a3 = "After a first byte of E0, expecting two following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 96) > 0x1Fu )
{
*a3 = "After a first byte of E0, expecting a 2nd byte between A0 and BF.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of E0, expecting a 3nd byte between 80 and BF.";
*a4 = 3;
return result;
}
result += 3LL;
}
else if ( (unsigned __int8)(v6 + 31) > 0xBu )
{
if ( v6 == -19 )
{
if ( result + 2 >= a2 )
{
*a3 = "After a first byte of ED, expecting two following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0x1Fu )
{
*a3 = "After a first byte of ED, expecting 2nd byte between 80 and 9F.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of ED, expecting 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
result += 3LL;
}
else if ( (unsigned __int8)(v6 + 18) <= 1u )
{
if ( result + 2 >= a2 )
{
*a3 = "After a first byte between EE and EF, two following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte between EE and EF, expecting 2nd byte between 80 and BF.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte between EE and EF, expecting 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
result += 3LL;
}
else if ( v6 == -16 )
{
if ( result + 3 >= a2 )
{
*a3 = "After a first byte of F0, expecting three following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 112) > 0x2Fu )
{
*a3 = "After a first byte of F0, expecting 2nd byte between 90 and BF.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F0, expecting 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 3) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F0, expecting 4th byte between 80 and BF.";
*a4 = 4;
return result;
}
result += 4LL;
}
else if ( (unsigned __int8)(v6 + 15) > 2u )
{
if ( v6 != -12 )
{
*a3 = "Expecting bytes in the following ranges: 00..7F C2..F4.";
*a4 = 1;
return result;
}
if ( result + 3 >= a2 )
{
*a3 = "After a first byte of F4, expecting three following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0xFu )
{
*a3 = "After a first byte of F4, expecting 2nd byte between 80 and 8F.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F4, expecting 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 3) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F4, expecting 4th byte between 80 and BF.";
*a4 = 4;
return result;
}
result += 4LL;
}
else
{
if ( result + 3 >= a2 )
{
*a3 = "After a first byte of F1, F2, or F3, expecting three following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F1, F2, or F3, expecting a 2nd byte between 80 and BF.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F1, F2, or F3, expecting a 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 3) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F1, F2, or F3, expecting a 4th byte between 80 and BF.";
*a4 = 4;
return result;
}
result += 4LL;
}
}
else
{
if ( result + 2 >= a2 )
{
*a3 = "After a first byte between E1 and EC, expecting two following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte between E1 and EC, expecting the 2nd byte between 80 and BF.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte between E1 and EC, expecting the 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
result += 3LL;
}
}
else
{
if ( result + 1 >= a2 )
{
*a3 = "After a first byte between C2 and DF, expecting a 2nd byte.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte between C2 and DF, expecting a 2nd byte between 80 and BF";
*a4 = 2;
return result;
}
result += 2LL;
}
}
while ( result < a2 );
return 0LL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1, unsigned __int64 a2, _QWORD *a3, _DWORD *a4)
{
unsigned __int64 result; // rax
char v6; // dl

*a3 = 0LL;
*a4 = 0;
if ( !a2 )
return 0LL;
result = 0LL;
do
{
v6 = *(_BYTE *)(a1 + result);
if ( v6 >= 0 )
{
++result;
}
else if ( (unsigned __int8)(v6 + 62) > 0x1Du )
{
if ( v6 == -32 )
{
if ( result + 2 >= a2 )
{
*a3 = "After a first byte of E0, expecting two following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 96) > 0x1Fu )
{
*a3 = "After a first byte of E0, expecting a 2nd byte between A0 and BF.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of E0, expecting a 3nd byte between 80 and BF.";
*a4 = 3;
return result;
}
result += 3LL;
}
else if ( (unsigned __int8)(v6 + 31) > 0xBu )
{
if ( v6 == -19 )
{
if ( result + 2 >= a2 )
{
*a3 = "After a first byte of ED, expecting two following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0x1Fu )
{
*a3 = "After a first byte of ED, expecting 2nd byte between 80 and 9F.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of ED, expecting 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
result += 3LL;
}
else if ( (unsigned __int8)(v6 + 18) <= 1u )
{
if ( result + 2 >= a2 )
{
*a3 = "After a first byte between EE and EF, two following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte between EE and EF, expecting 2nd byte between 80 and BF.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte between EE and EF, expecting 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
result += 3LL;
}
else if ( v6 == -16 )
{
if ( result + 3 >= a2 )
{
*a3 = "After a first byte of F0, expecting three following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 112) > 0x2Fu )
{
*a3 = "After a first byte of F0, expecting 2nd byte between 90 and BF.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F0, expecting 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 3) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F0, expecting 4th byte between 80 and BF.";
*a4 = 4;
return result;
}
result += 4LL;
}
else if ( (unsigned __int8)(v6 + 15) > 2u )
{
if ( v6 != -12 )
{
*a3 = "Expecting bytes in the following ranges: 00..7F C2..F4.";
*a4 = 1;
return result;
}
if ( result + 3 >= a2 )
{
*a3 = "After a first byte of F4, expecting three following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0xFu )
{
*a3 = "After a first byte of F4, expecting 2nd byte between 80 and 8F.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F4, expecting 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 3) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F4, expecting 4th byte between 80 and BF.";
*a4 = 4;
return result;
}
result += 4LL;
}
else
{
if ( result + 3 >= a2 )
{
*a3 = "After a first byte of F1, F2, or F3, expecting three following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F1, F2, or F3, expecting a 2nd byte between 80 and BF.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F1, F2, or F3, expecting a 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 3) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte of F1, F2, or F3, expecting a 4th byte between 80 and BF.";
*a4 = 4;
return result;
}
result += 4LL;
}
}
else
{
if ( result + 2 >= a2 )
{
*a3 = "After a first byte between E1 and EC, expecting two following bytes.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte between E1 and EC, expecting the 2nd byte between 80 and BF.";
*a4 = 2;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 2) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte between E1 and EC, expecting the 3rd byte between 80 and BF.";
*a4 = 3;
return result;
}
result += 3LL;
}
}
else
{
if ( result + 1 >= a2 )
{
*a3 = "After a first byte between C2 and DF, expecting a 2nd byte.";
*a4 = 1;
return result;
}
if ( (unsigned __int8)(*(_BYTE *)(a1 + result + 1) + 0x80) > 0x3Fu )
{
*a3 = "After a first byte between C2 and DF, expecting a 2nd byte between 80 and BF";
*a4 = 2;
return result;
}
result += 2LL;
}
}
while ( result < a2 );
return 0LL;
}

original_code:
size_t is_utf8(unsigned char *str, size_t len, char **message, int *faulty_bytes)
{
    size_t i = 0;
    *message = ((void *)0);
    *faulty_bytes = 0;
    while (i < len)
    {
        if (str[i] <= 0x7F)
        {
            i += 1;
        }
        else if (str[i] >= 0xC2 && str[i] <= 0xDF)
        {
            if (i + 1 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte between C2 and DF, expecting a 2nd byte between 80 and BF";
                    *faulty_bytes = 2;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte between C2 and DF, expecting a 2nd byte.";
                *faulty_bytes = 1;
                return i;
            }
            i += 2;
        }
        else if (str[i] == 0xE0)
        {
            if (i + 2 < len)
            {
                if (str[i + 1] < 0xA0 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte of E0, expecting a 2nd byte between A0 and BF.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte of E0, expecting a 3nd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte of E0, expecting two following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 3;
        }
        else if (str[i] >= 0xE1 && str[i] <= 0xEC)
        {
            if (i + 2 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte between E1 and EC, expecting the 2nd byte between 80 and BF.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte between E1 and EC, expecting the 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte between E1 and EC, expecting two following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 3;
        }
        else if (str[i] == 0xED)
        {
            if (i + 2 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0x9F)
                {
                    *message = "After a first byte of ED, expecting 2nd byte between 80 and 9F.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte of ED, expecting 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte of ED, expecting two following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 3;
        }
        else if (str[i] >= 0xEE && str[i] <= 0xEF)
        {
            if (i + 2 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte between EE and EF, expecting 2nd byte between 80 and BF.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte between EE and EF, expecting 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte between EE and EF, two following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 3;
        }
        else if (str[i] == 0xF0)
        {
            if (i + 3 < len)
            {
                if (str[i + 1] < 0x90 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte of F0, expecting 2nd byte between 90 and BF.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte of F0, expecting 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
                if (str[i + 3] < 0x80 || str[i + 3] > 0xBF)
                {
                    *message = "After a first byte of F0, expecting 4th byte between 80 and BF.";
                    *faulty_bytes = 4;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte of F0, expecting three following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 4;
        }
        else if (str[i] >= 0xF1 && str[i] <= 0xF3)
        {
            if (i + 3 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte of F1, F2, or F3, expecting a 2nd byte between 80 and BF.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte of F1, F2, or F3, expecting a 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
                if (str[i + 3] < 0x80 || str[i + 3] > 0xBF)
                {
                    *message = "After a first byte of F1, F2, or F3, expecting a 4th byte between 80 and BF.";
                    *faulty_bytes = 4;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte of F1, F2, or F3, expecting three following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 4;
        }
        else if (str[i] == 0xF4)
        {
            if (i + 3 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0x8F)
                {
                    *message = "After a first byte of F4, expecting 2nd byte between 80 and 8F.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte of F4, expecting 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
                if (str[i + 3] < 0x80 || str[i + 3] > 0xBF)
                {
                    *message = "After a first byte of F4, expecting 4th byte between 80 and BF.";
                    *faulty_bytes = 4;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte of F4, expecting three following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 4;
        }
        else
        {
            *message = "Expecting bytes in the following ranges: 00..7F C2..F4.";
            *faulty_bytes = 1;
            return i;
        }
    }
    message = ((void *)0);
    return 0;
}

canonical_original_code:
unsigned long is_utf8(unsigned char *str, unsigned long len, char **message, int *faulty_bytes)
{
    unsigned long i = 0;
    *message = ((void *)0);
    *faulty_bytes = 0;
    while (i < len)
    {
        if (str[i] <= 0x7F)
        {
            i += 1;
        }
        else if (str[i] >= 0xC2 && str[i] <= 0xDF)
        {
            if (i + 1 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte between C2 and DF, expecting a 2nd byte between 80 and BF";
                    *faulty_bytes = 2;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte between C2 and DF, expecting a 2nd byte.";
                *faulty_bytes = 1;
                return i;
            }
            i += 2;
        }
        else if (str[i] == 0xE0)
        {
            if (i + 2 < len)
            {
                if (str[i + 1] < 0xA0 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte of E0, expecting a 2nd byte between A0 and BF.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte of E0, expecting a 3nd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte of E0, expecting two following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 3;
        }
        else if (str[i] >= 0xE1 && str[i] <= 0xEC)
        {
            if (i + 2 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte between E1 and EC, expecting the 2nd byte between 80 and BF.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte between E1 and EC, expecting the 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte between E1 and EC, expecting two following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 3;
        }
        else if (str[i] == 0xED)
        {
            if (i + 2 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0x9F)
                {
                    *message = "After a first byte of ED, expecting 2nd byte between 80 and 9F.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte of ED, expecting 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte of ED, expecting two following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 3;
        }
        else if (str[i] >= 0xEE && str[i] <= 0xEF)
        {
            if (i + 2 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte between EE and EF, expecting 2nd byte between 80 and BF.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte between EE and EF, expecting 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte between EE and EF, two following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 3;
        }
        else if (str[i] == 0xF0)
        {
            if (i + 3 < len)
            {
                if (str[i + 1] < 0x90 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte of F0, expecting 2nd byte between 90 and BF.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte of F0, expecting 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
                if (str[i + 3] < 0x80 || str[i + 3] > 0xBF)
                {
                    *message = "After a first byte of F0, expecting 4th byte between 80 and BF.";
                    *faulty_bytes = 4;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte of F0, expecting three following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 4;
        }
        else if (str[i] >= 0xF1 && str[i] <= 0xF3)
        {
            if (i + 3 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0xBF)
                {
                    *message = "After a first byte of F1, F2, or F3, expecting a 2nd byte between 80 and BF.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte of F1, F2, or F3, expecting a 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
                if (str[i + 3] < 0x80 || str[i + 3] > 0xBF)
                {
                    *message = "After a first byte of F1, F2, or F3, expecting a 4th byte between 80 and BF.";
                    *faulty_bytes = 4;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte of F1, F2, or F3, expecting three following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 4;
        }
        else if (str[i] == 0xF4)
        {
            if (i + 3 < len)
            {
                if (str[i + 1] < 0x80 || str[i + 1] > 0x8F)
                {
                    *message = "After a first byte of F4, expecting 2nd byte between 80 and 8F.";
                    *faulty_bytes = 2;
                    return i;
                }
                if (str[i + 2] < 0x80 || str[i + 2] > 0xBF)
                {
                    *message = "After a first byte of F4, expecting 3rd byte between 80 and BF.";
                    *faulty_bytes = 3;
                    return i;
                }
                if (str[i + 3] < 0x80 || str[i + 3] > 0xBF)
                {
                    *message = "After a first byte of F4, expecting 4th byte between 80 and BF.";
                    *faulty_bytes = 4;
                    return i;
                }
            }
            else
            {
                *message = "After a first byte of F4, expecting three following bytes.";
                *faulty_bytes = 1;
                return i;
            }
            i += 4;
        }
        else
        {
            *message = "Expecting bytes in the following ranges: 00..7F C2..F4.";
            *faulty_bytes = 1;
            return i;
        }
    }
    message = ((void *)0);
    return 0;
}

variable_types:
str
unsigned char *

variable_types:
len
unsigned long

variable_types:
message
char **

variable_types:
i
unsigned long

return_type: unsigned long


player

repo: JustB/Roulette

decompiled_code:
void __fastcall __noreturn player(void *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
int v3; // ebx
int v4; // er12
int v5; // er14
unsigned int v6; // eax
_DWORD *v7; // rbp
unsigned int v8; // eax
int *v9; // rax

v1 = pthread_mutex_lock(&puntate_mutex);
if ( v1 )
err_abort(v1, "Lock sul mutex nel player");
while ( 1 )
{
while ( estratto < 0 )
{
printf("GIOCATORE %d CONDIZIONE FALSA\n", (unsigned int)a1);
v8 = pthread_cond_wait(&puntate_cond, &puntate_mutex);
if ( v8 )
err_abort(v8, "Wait nel player");
}
v2 = pthread_mutex_unlock(&puntate_mutex);
if ( v2 )
err_abort(v2, "Unlock sul mutex nel player");
v3 = rand() % 37;
v4 = rand() % 3;
v5 = rand() % 100 + 1;
sleep(1u);
v6 = pthread_mutex_lock(&puntate_mutex);
if ( v6 )
err_abort(v6, "Lock sul mutex nel player");
v7 = malloc(0x18uLL);
if ( !v7 )
{
v9 = _errno_location();
err_abort((unsigned int)*v9, "Errore malloc!");
}
v7[2] = v3;
v7[3] = v4;
v7[4] = v5;
queue_put((unsigned int)((_DWORD)&lista_puntate + 96), v7);
printf(
"GIOCATORE %d ha aggiunto %d di tipo %d puntando %d€\n",
(unsigned int)a1,
(unsigned int)v7[2],
(unsigned int)v7[3],
(unsigned int)v7[4]);
++num_requests;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
int v3; // ebx
int v4; // er12
int v5; // er14
unsigned int v6; // eax
_DWORD *v7; // rbp
unsigned int v8; // eax
int *v9; // rax

v1 = pthread_mutex_lock(&puntate_mutex);
if ( v1 )
err_abort(v1, "Lock sul mutex nel player");
while ( 1 )
{
while ( estratto < 0 )
{
printf("GIOCATORE %d CONDIZIONE FALSA\n", (unsigned int)a1);
v8 = pthread_cond_wait(&puntate_cond, &puntate_mutex);
if ( v8 )
err_abort(v8, "Wait nel player");
}
v2 = pthread_mutex_unlock(&puntate_mutex);
if ( v2 )
err_abort(v2, "Unlock sul mutex nel player");
v3 = rand() % 37;
v4 = rand() % 3;
v5 = rand() % 100 + 1;
sleep(1u);
v6 = pthread_mutex_lock(&puntate_mutex);
if ( v6 )
err_abort(v6, "Lock sul mutex nel player");
v7 = malloc(0x18uLL);
if ( !v7 )
{
v9 = _errno_location();
err_abort((unsigned int)*v9, "Errore malloc!");
}
v7[2] = v3;
v7[3] = v4;
v7[4] = v5;
queue_put((unsigned int)((_DWORD)&lista_puntate + 96), v7);
printf(
"GIOCATORE %d ha aggiunto %d di tipo %d puntando %d€\n",
(unsigned int)a1,
(unsigned int)v7[2],
(unsigned int)v7[3],
(unsigned int)v7[4]);
++num_requests;
}
}

original_code:
void *player(void *arg) {
 int num_giocatore = (int) arg;
 int num_puntato_dal_giocatore = 0;
 bet_t tipo_puntata;
 int status;
 int somma_puntata;
 puntata_t *mybet;
 status = pthread_mutex_lock(&puntate_mutex);
 if (status != 0) {
  err_abort(status, "Lock sul mutex nel player");
 }
 while (1) {
  while (estratto < 0) {
   printf("GIOCATORE %d CONDIZIONE FALSA\n", num_giocatore);
   status = pthread_cond_wait(&puntate_cond, &puntate_mutex);
   if (status != 0) {
    err_abort(status, "Wait nel player");
   }
  }
  status = pthread_mutex_unlock(&puntate_mutex);
  if (status != 0) {
   err_abort(status, "Unlock sul mutex nel player");
  }
  num_puntato_dal_giocatore = rand() % 37;
  tipo_puntata = (bet_t)(rand() % 3);
  somma_puntata = (rand() % 100)+1;
  sleep(1);
  status = pthread_mutex_lock(&puntate_mutex);
  if (status != 0) {
   err_abort(status, "Lock sul mutex nel player");
  }
  mybet = (puntata_t *) malloc(sizeof (puntata_t));
  if (!mybet) {
   err_abort((*__errno_location ()), "Errore malloc!");
  }
  mybet->puntata = num_puntato_dal_giocatore;
  mybet->tipo = tipo_puntata;
  mybet->somma_puntata = somma_puntata;
  queue_put(&(lista_puntate.puntate), (node *) mybet);
  printf("GIOCATORE %d ha aggiunto %d di tipo %d puntando %d€\n",
   num_giocatore, mybet->puntata, mybet->tipo, mybet->somma_puntata);
  num_requests++;
 }
 pthread_exit(((void *)0));
}

canonical_original_code:
void *player(void *arg) {
 int num_giocatore = (int) arg;
 int num_puntato_dal_giocatore = 0;
 enum bet_type tipo_puntata;
 int status;
 int somma_puntata;
 struct puntate_node *mybet;
 status = pthread_mutex_lock(&puntate_mutex);
 if (status != 0) {
  err_abort(status, "Lock sul mutex nel player");
 }
 while (1) {
  while (estratto < 0) {
   printf("GIOCATORE %d CONDIZIONE FALSA\n", num_giocatore);
   status = pthread_cond_wait(&puntate_cond, &puntate_mutex);
   if (status != 0) {
    err_abort(status, "Wait nel player");
   }
  }
  status = pthread_mutex_unlock(&puntate_mutex);
  if (status != 0) {
   err_abort(status, "Unlock sul mutex nel player");
  }
  num_puntato_dal_giocatore = rand() % 37;
  tipo_puntata = (bet_t)(rand() % 3);
  somma_puntata = (rand() % 100)+1;
  sleep(1);
  status = pthread_mutex_lock(&puntate_mutex);
  if (status != 0) {
   err_abort(status, "Lock sul mutex nel player");
  }
  mybet = (struct puntate_node *) malloc(sizeof (puntata_t));
  if (!mybet) {
   err_abort((*__errno_location ()), "Errore malloc!");
  }
  mybet->puntata = num_puntato_dal_giocatore;
  mybet->tipo = tipo_puntata;
  mybet->somma_puntata = somma_puntata;
  queue_put(&(lista_puntate.puntate), (struct node *) mybet);
  printf("GIOCATORE %d ha aggiunto %d di tipo %d puntando %d€\n",
   num_giocatore, mybet->puntata, mybet->tipo, mybet->somma_puntata);
  num_requests++;
 }
 pthread_exit(((void *)0));
}

variable_types:
arg
void *

variable_types: status int

variable_types: struct puntate_node { struct node { struct node *next; } *next; int puntata; enum bet_type { NUMBER=0, EVEN=1, ODD=2 } tipo; int somma_puntata; } *

return_type: void *

user_defined_types: struct puntate_node { struct node *next; int puntata; enum bet_type tipo; int somma_puntata; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int16 v3; // bp
__int64 v4; // rbx
unsigned int v5; // eax
int v6; // ebp
char *v7; // rbx
unsigned int v8; // eax
pthread_t v9; // [rsp+0h] [rbp-28h] BYREF
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc != 3 )
{
printf("Utilizzo: %s <numero porta> <intervallo secondi>\n", *argv);
exit(1);
}
queue_init((unsigned int)((_DWORD)&lista_puntate + 96), argv, envp);
v3 = atoi(argv[1]);
v4 = (unsigned int)atoi(argv[2]);
printf(aLaGiocataDurer, v4);
v5 = pthread_create(&v9, 0LL, (void *(*)(void *))croupier, (void *)(int)v4);
if ( v5 )
err_abort(v5, "Creazione del thread croupier");
v6 = open_socket(0LL, 0LL, (unsigned int)v3);
v7 = 0LL;
while ( 1 )
{
v8 = pthread_create(newthread, 0LL, (void *(*)(void *))player, v7);
if ( v8 )
err_abort(v8, "Creazione thread");
if ( ++v7 == (_BYTE *)&loc_8 + 2 )
{
close(v6);
pthread_exit(0LL);
}
}
}

original_code:
int main(int argc, char **argv) {
 if (argc != 3) {
  printf("Utilizzo: %s <numero porta> <intervallo secondi>\n", argv[0]);
  exit(1);
 }
 int j = 0;
 int sockfd;
 short int server_port;
 int game_interval;
 struct sockaddr_in self;
 int status;
 pthread_t player_tid, croupier_tid;
 queue_init(&(lista_puntate.puntate));
 server_port = atoi(argv[1]);
 game_interval = atoi(argv[2]);
 printf("La giocata durerà %d secondi\n", game_interval);
 status = pthread_create(&croupier_tid, ((void *)0), croupier, (void *) game_interval);
 if (status != 0) {
  err_abort(status, "Creazione del thread croupier");
 }
 sockfd = open_socket(self, server_port);
 for (j = 0; j < 10; j++) {
  status = pthread_create(&player_tid, ((void *)0), player, (void *) j);
  if (status != 0) {
   err_abort(status, "Creazione thread");
  }
 }
 close(sockfd);
 pthread_exit(((void *)0));
}

canonical_original_code:
int main(int argc, char **argv) {
 if (argc != 3) {
  printf("Utilizzo: %s <numero porta> <intervallo secondi>\n", argv[0]);
  exit(1);
 }
 int j = 0;
 int sockfd;
 short server_port;
 int game_interval;
 struct sockaddr_in self;
 int status;
 unsigned long player_tid; unsigned long croupier_tid;
 queue_init(&(lista_puntate.puntate));
 server_port = atoi(argv[1]);
 game_interval = atoi(argv[2]);
 printf("La giocata durerà %d secondi\n", game_interval);
 status = pthread_create(&croupier_tid, ((void *)0), croupier, (void *) game_interval);
 if (status != 0) {
  err_abort(status, "Creazione del thread croupier");
 }
 sockfd = open_socket(self, server_port);
 for (j = 0; j < 10; j++) {
  status = pthread_create(&player_tid, ((void *)0), player, (void *) j);
  if (status != 0) {
   err_abort(status, "Creazione thread");
  }
 }
 close(sockfd);
 pthread_exit(((void *)0));
}

variable_types: argc int

variable_types:
argv
char **

variable_types: j int

variable_types: sockfd int

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

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


decompiled_code:
int __fastcall control_init(__int64 a1)
{
int v1; // edx
int result; // eax

v1 = pthread_mutex_init((pthread_mutex_t *)a1, 0LL);
result = 1;
if ( !v1 )
{
result = pthread_cond_init((pthread_cond_t *)(a1 + 40), 0LL);
if ( result )
result = 1;
else
*(_DWORD *)(a1 + 88) = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int v1; // edx
int result; // eax

v1 = pthread_mutex_init((pthread_mutex_t *)a1, 0LL);
result = 1;
if ( !v1 )
{
result = pthread_cond_init((pthread_cond_t *)(a1 + 40), 0LL);
if ( result )
result = 1;
else
*(_DWORD *)(a1 + 88) = 0;
}
return result;
}

original_code:
int control_init(data_control *mycontrol) {
 int status;
 status = pthread_mutex_init(&(mycontrol->mutex), ((void *)0));
 if(status != 0){
  return 1;
 }
 status = pthread_cond_init(&(mycontrol->cond), ((void *)0));
 if(status != 0){
  return 1;
 }
 mycontrol->active = 0;
 return 0;
}

canonical_original_code:
int control_init(struct data_control *mycontrol) {
 int status;
 status = pthread_mutex_init(&(mycontrol->mutex), ((void *)0));
 if(status != 0){
  return 1;
 }
 status = pthread_cond_init(&(mycontrol->cond), ((void *)0));
 if(status != 0){
  return 1;
 }
 mycontrol->active = 0;
 return 0;
}

variable_types: struct data_control { 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; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int active; } *

user_defined_types: struct data_control { union pthread_mutex_t mutex; union pthread_cond_t cond; int active; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


decompiled_code:
int __fastcall control_destroy(__int64 a1)
{
int v1; // edx
int result; // eax

v1 = pthread_mutex_destroy((pthread_mutex_t *)a1);
result = 1;
if ( !v1 )
{
result = pthread_cond_destroy((pthread_cond_t *)(a1 + 40));
if ( result )
result = 1;
else
*(_DWORD *)(a1 + 88) = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
int v1; // edx
int result; // eax

v1 = pthread_mutex_destroy((pthread_mutex_t *)a1);
result = 1;
if ( !v1 )
{
result = pthread_cond_destroy((pthread_cond_t *)(a1 + 40));
if ( result )
result = 1;
else
*(_DWORD *)(a1 + 88) = 0;
}
return result;
}

original_code:
int control_destroy(data_control *mycontrol) {
 int status;
 status = pthread_mutex_destroy(&(mycontrol->mutex));
 if(status != 0){
  return 1;
 }
 status = pthread_cond_destroy(&(mycontrol->cond));
 if(status != 0){
  return 1;
 }
 mycontrol->active = 0;
 return 0;
}

canonical_original_code:
int control_destroy(struct data_control *mycontrol) {
 int status;
 status = pthread_mutex_destroy(&(mycontrol->mutex));
 if(status != 0){
  return 1;
 }
 status = pthread_cond_destroy(&(mycontrol->cond));
 if(status != 0){
  return 1;
 }
 mycontrol->active = 0;
 return 0;
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

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


decompiled_code:
__int64 __fastcall control_activate(pthread_mutex_t *mutex)
{
int v1; // edx
__int64 result; // rax

v1 = pthread_mutex_lock(mutex);
result = 0LL;
if ( !v1 )
{
mutex[2].__owner = 1;
pthread_mutex_unlock(mutex);
pthread_cond_broadcast((pthread_cond_t *)&mutex[1]);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(pthread_mutex_t *mutex)
{
int v1; // edx
__int64 result; // rax

v1 = pthread_mutex_lock(mutex);
result = 0LL;
if ( !v1 )
{
mutex[2].__owner = 1;
pthread_mutex_unlock(mutex);
pthread_cond_broadcast((pthread_cond_t *)&mutex[1]);
result = 1LL;
}
return result;
}

original_code:
int control_activate(data_control *mycontrol ){
 int status;
 status = pthread_mutex_lock(&(mycontrol->mutex));
 if(status != 0) {
  return 0;
 }
 mycontrol->active = 1;
 status = pthread_mutex_unlock(&(mycontrol->mutex));
 pthread_cond_broadcast(&(mycontrol->cond));
 return 1;
}

canonical_original_code:
int control_activate(struct data_control *mycontrol){
 int status;
 status = pthread_mutex_lock(&(mycontrol->mutex));
 if(status != 0) {
  return 0;
 }
 mycontrol->active = 1;
 status = pthread_mutex_unlock(&(mycontrol->mutex));
 pthread_cond_broadcast(&(mycontrol->cond));
 return 1;
}


decompiled_code:
__int64 __fastcall control_deactivate(pthread_mutex_t *mutex)
{
int v1; // edx
__int64 result; // rax

v1 = pthread_mutex_lock(mutex);
result = 0LL;
if ( !v1 )
{
mutex[2].__owner = 0;
pthread_mutex_unlock(mutex);
pthread_cond_broadcast((pthread_cond_t *)&mutex[1]);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(pthread_mutex_t *mutex)
{
int v1; // edx
__int64 result; // rax

v1 = pthread_mutex_lock(mutex);
result = 0LL;
if ( !v1 )
{
mutex[2].__owner = 0;
pthread_mutex_unlock(mutex);
pthread_cond_broadcast((pthread_cond_t *)&mutex[1]);
result = 1LL;
}
return result;
}

original_code:
int control_deactivate(data_control *mycontrol) {
 int status;
 status = pthread_mutex_lock(&(mycontrol->mutex));
 if(status != 0) {
  return 0;
 }
 mycontrol->active = 0;
 status = pthread_mutex_unlock(&(mycontrol->mutex));
 pthread_cond_broadcast(&(mycontrol->cond));
 return 1;
}

canonical_original_code:
int control_deactivate(struct data_control *mycontrol) {
 int status;
 status = pthread_mutex_lock(&(mycontrol->mutex));
 if(status != 0) {
  return 0;
 }
 mycontrol->active = 0;
 status = pthread_mutex_unlock(&(mycontrol->mutex));
 pthread_cond_broadcast(&(mycontrol->cond));
 return 1;
}


decompiled_code:
void __fastcall __noreturn err_abort(int a1, const char *a2)
{
char *v2; // rax

v2 = strerror(a1);
fprintf(stderr, "%s at %s:%d: %s\n", a2, "common_header.c", 15LL, v2);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func2(int a1, const char *a2)
{
char *v2; // rax

v2 = strerror(a1);
fprintf(stderr, "%s at %s:%d: %s\n", a2, "common_header.c", 15LL, v2);
abort();
}

original_code:
void err_abort(int code, char *text) {
 fprintf(stderr, "%s at %s:%d: %s\n", text, "common_header.c", 15, strerror(code));
 abort();
}

variable_types: code int

variable_types:
text
char *


decompiled_code:
__int64 __fastcall open_socket(__int64 a1, __int64 a2, __int16 a3)
{
int v4; // eax
unsigned int v5; // ebx
int *v7; // rax
int *v8; // rax
int *v9; // rax
struct sockaddr v10; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&v10.sa_family = a1;
*(_QWORD *)&v10.sa_data[6] = a2;
v4 = socket(2, 1, 0);
if ( v4 < 0 )
{
v7 = _errno_location();
err_abort(*v7, "Creazione socket");
}
v5 = v4;
*(_DWORD *)&v10.sa_data[10] = 0;
v10.sa_family = 2;
*(_WORD *)v10.sa_data = _bswap_16(a3);
*(_QWORD *)&v10.sa_data[2] = (unsigned int)_bswap_32(0);
if ( bind(v5, &v10, 0x10u) )
{
v8 = _errno_location();
err_abort(*v8, "Bind socket");
}
if ( listen(v5, 5) )
{
v9 = _errno_location();
err_abort(*v9, "Error in listening to socket");
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int16 a3)
{
int v4; // eax
unsigned int v5; // ebx
int *v7; // rax
int *v8; // rax
int *v9; // rax
struct sockaddr v10; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&v10.sa_family = a1;
*(_QWORD *)&v10.sa_data[6] = a2;
v4 = socket(2, 1, 0);
if ( v4 < 0 )
{
v7 = _errno_location();
func2(*v7, "Creazione socket");
}
v5 = v4;
*(_DWORD *)&v10.sa_data[10] = 0;
v10.sa_family = 2;
*(_WORD *)v10.sa_data = func0(a3);
*(_QWORD *)&v10.sa_data[2] = (unsigned int)func1(0);
if ( bind(v5, &v10, 0x10u) )
{
v8 = _errno_location();
func2(*v8, "Bind socket");
}
if ( listen(v5, 5) )
{
v9 = _errno_location();
func2(*v9, "Error in listening to socket");
}
return v5;
}

original_code:
int open_socket(struct sockaddr_in self, short int server_port) {
 int sockfd;
 int status;
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0) {
  err_abort((*__errno_location ()), "Creazione socket");
 }
 bzero(&self, sizeof (self));
 self.sin_family = 2;
 self.sin_port = htons(server_port);
 self.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 status = bind(sockfd, (struct sockaddr *) &self, sizeof (self));
 if (status != 0) {
  err_abort((*__errno_location ()), "Bind socket");
 }
 status = listen(sockfd, 5);
 if (status != 0) {
  err_abort((*__errno_location ()), "Error in listening to socket");
 }
 return sockfd;
}

canonical_original_code:
int open_socket(struct sockaddr_in self, short server_port) {
 int sockfd;
 int status;
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0) {
  err_abort((*__errno_location ()), "Creazione socket");
 }
 bzero(&self, sizeof (self));
 self.sin_family = 2;
 self.sin_port = htons(server_port);
 self.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 status = bind(sockfd, (struct sockaddr *) &self, sizeof (self));
 if (status != 0) {
  err_abort((*__errno_location ()), "Bind socket");
 }
 status = listen(sockfd, 5);
 if (status != 0) {
  err_abort((*__errno_location ()), "Error in listening to socket");
 }
 return sockfd;
}

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


decompiled_code:
unsigned int *gestisci_puntata()
{
unsigned int *result; // rax
unsigned int *v1; // rbx

while ( 1 )
{
result = (unsigned int *)queue_get((unsigned int)((_DWORD)&lista_puntate + 96));
v1 = result;
if ( !result )
break;
fprintf(
stdout,
"CROUPIER: nella lista delle puntate numero %d di tipo %d con %d€\n",
result[2],
result[3],
result[4]);
free(v1);
--num_requests;
}
return result;
}

canonical_decompiled_code:
unsigned int *func4()
{
unsigned int *result; // rax
unsigned int *v1; // rbx

while ( 1 )
{
result = (unsigned int *)queue_get((unsigned int)((_DWORD)&lista_puntate + 96));
v1 = result;
if ( !result )
break;
fprintf(
stdout,
"CROUPIER: nella lista delle puntate numero %d di tipo %d con %d€\n",
result[2],
result[3],
result[4]);
free(v1);
--num_requests;
}
return result;
}

original_code:
void gestisci_puntata() {
 puntata_t *puntata;
 while ((puntata = (puntata_t *) queue_get(&(lista_puntate.puntate))) != ((void *)0)) {
  fprintf(stdout, "CROUPIER: nella lista delle puntate numero %d di tipo %d con %d€\n",
   puntata->puntata, puntata->tipo, puntata->somma_puntata);
  free(puntata);
  num_requests--;
 }
}

canonical_original_code:
void gestisci_puntata() {
 struct puntate_node *puntata;
 while ((puntata = (struct puntate_node *) queue_get(&(lista_puntate.puntate))) != ((void *)0)) {
  fprintf(stdout, "CROUPIER: nella lista delle puntate numero %d di tipo %d con %d€\n",
   puntata->puntata, puntata->tipo, puntata->somma_puntata);
  free(puntata);
  num_requests--;
 }
}

user_defined_types: enum bet_type { NUMBER=0, EVEN=1, ODD=2 }


decompiled_code:
time_t __fastcall calcola_intervallo(int a1)
{
return a1 + time(0LL);
}

canonical_decompiled_code:
time_t __fastcall func5(int a1)
{
return a1 + time(0LL);
}

original_code:
struct timespec calcola_intervallo(int intervallo) {
 time_t now;
 struct timespec cond_time;
 now = time(((void *)0));
 cond_time.tv_sec = now + intervallo;
 cond_time.tv_nsec = 0;
 return cond_time;
}

canonical_original_code:
struct timespec calcola_intervallo(int intervallo) {
 long now;
 struct timespec cond_time;
 now = time(((void *)0));
 cond_time.tv_sec = now + intervallo;
 cond_time.tv_nsec = 0;
 return cond_time;
}

variable_types: intervallo int

variable_types: now long

variable_types: struct timespec { long tv_sec; long tv_nsec; }


repo: Juxi/SysProg

decompiled_code:
const char *__fastcall variable_name_of_index(unsigned __int16 a1)
{
unsigned __int16 v1; // dx
__int64 v2; // rax

v1 = variables[0];
v2 = 1LL;
if ( a1 )
{
while ( a1 > v1 )
{
v1 += variables[8 * v2++];
if ( v2 == 34 )
return "unknown";
}
}
else
{
v1 = 0;
v2 = 0LL;
}
if ( (unsigned __int16)variables[8 * v2] <= 1u )
strcpy(ret_0, (&off_4054C8)[2 * v2]);
else
sprintf(ret_0, "%s[%d]", (&off_4054C8)[2 * v2], v1 - (unsigned int)a1);
return ret_0;
}

canonical_decompiled_code:
const char *__fastcall func7(unsigned __int16 a1)
{
unsigned __int16 v1; // dx
__int64 v2; // rax

v1 = variables[0];
v2 = 1LL;
if ( a1 )
{
while ( a1 > v1 )
{
v1 += variables[8 * v2++];
if ( v2 == 34 )
return "unknown";
}
}
else
{
v1 = 0;
v2 = 0LL;
}
if ( (unsigned __int16)variables[8 * v2] <= 1u )
strcpy(ret_0, (&off_4054C8)[2 * v2]);
else
sprintf(ret_0, "%s[%d]", (&off_4054C8)[2 * v2], v1 - (unsigned int)a1);
return ret_0;
}

original_code:
const char* variable_name_of_index(uint16_t idx)
{
 static char ret[256];
 size_t num = sizeof(variables)/sizeof(variable_t);
 size_t i;
 uint16_t sum = 0;
 for (i=0;i<num;i++)
 {
  if (idx<=sum)
  {
   if (variables[i].size>1)
   {
    sprintf(ret,"%s[%d]",variables[i].name,sum-idx);
   }
   else
   {
    sprintf(ret,"%s",variables[i].name);
   }
   return ret;
  }
       sum += variables[i].size;
 }
 return "unknown";
}

canonical_original_code:
char *variable_name_of_index(unsigned short idx)
{
 static char ret[256];
 unsigned long num = sizeof(variables)/sizeof(variable_t);
 unsigned long i;
 unsigned short sum = 0;
 for (i=0;i<num;i++)
 {
  if (idx<=sum)
  {
   if (variables[i].size>1)
   {
    sprintf(ret,"%s[%d]",variables[i].name,sum-idx);
   }
   else
   {
    sprintf(ret,"%s",variables[i].name);
   }
   return ret;
  }
       sum += variables[i].size;
 }
 return "unknown";
}

variable_types:
idx
unsigned short

variable_types:
ret
char [256]

variable_types:
num
unsigned long

variable_types:
sum
unsigned short

return_type: char *