decompiled_code:
int __fastcall init_rand(__int64 a1)
{
unsigned __int16 v1; // ax

v1 = a1;
if ( !a1 )
v1 = time(0LL);
X[1] = v1;
return fprintf(stderr, "init_rand: seed = %d\n", v1);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
unsigned __int16 v1; // ax

v1 = a1;
if ( !a1 )
v1 = time(0LL);
X[1] = v1;
return fprintf(stderr, "init_rand: seed = %d\n", v1);
}

original_code:
void init_rand(long seed) {
 fprintf(stderr, "init_rand: seed = %d\n",
            X[1]=(seed==0) ? time(0) : seed);
}

variable_types: seed long


original_code:
void dir_and_dist(double a[3], double b[3], double dir[3], double* dist) {
    int k;
    for (k=0; k<3; k++) dir[k] = b[k] - a[k];
    *dist = sqrt( ((dir[0])*(dir[0]))+((dir[1])*(dir[1]))+((dir[2])*(dir[2])));
    for (k=0; k<3; k++) dir[k] = dir[k] / (*dist);
}

canonical_original_code:
void dir_and_dist(double a[3], double b[3], double dir[3], double *dist) {
    int k;
    for (k=0; k<3; k++) dir[k] = b[k] - a[k];
    *dist = sqrt( ((dir[0])*(dir[0]))+((dir[1])*(dir[1]))+((dir[2])*(dir[2])));
    for (k=0; k<3; k++) dir[k] = dir[k] / (*dist);
}

variable_types:
a
double [3]

variable_types:
b
double [3]

variable_types:
dir
double [3]

variable_types:
dist
double *

variable_types: k int

return_type: void


crossabc

variable_types:
c
double [3]

variable_types:
n
double [3]

variable_types: t double


dotabac

return_type: double


decompiled_code:
int __fastcall init_heap(int a1)
{
heap_A = (__int64)calloc(a1, 0x10uLL);
heap_size = 0;
heap_length = a1;
return fprintf(DFILE, "heap %d initialized\n", (unsigned int)a1);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
heap_A = (__int64)calloc(a1, 0x10uLL);
heap_size = 0;
heap_length = a1;
return fprintf(DFILE, "heap %d initialized\n", (unsigned int)a1);
}

original_code:
void init_heap(int num)
{
    heap_A = (struct heap_array *)calloc(num, sizeof(struct heap_array));
    heap_size = 0;
    heap_length = num;
    fprintf(DFILE,"heap %d initialized\n", num);
}

variable_types: num int

user_defined_types: struct heap_array { int pid; double pri; }


heapify

decompiled_code:
__int64 __fastcall heapify(unsigned int a1)
{
__int64 result; // rax
int v2; // edi
__int64 v3; // rcx
int v4; // er9
__int64 v5; // rdx
__int64 v6; // r8
int *v7; // rax
__int64 v8; // rcx
__int64 v9; // xmm0_8

result = a1;
v2 = 2 * a1;
if ( v2 <= heap_size && *(double *)(heap_A + 16LL * v2 + 8) > *(double *)(heap_A + 16LL * (int)result + 8) )
{
if ( v2 >= heap_size || *(double *)(16LL * v2 + heap_A + 24) <= *(double *)(heap_A + 16LL * v2 + 8) )
goto LABEL_9;
goto LABEL_8;
}
if ( v2 < heap_size && *(double *)(16LL * v2 + heap_A + 24) > *(double *)(heap_A + 16LL * (int)result + 8) )
{
LABEL_8:
++v2;
LABEL_9:
if ( v2 != (_DWORD)result )
{
v3 = 16LL * (int)result;
v4 = *(_DWORD *)(heap_A + v3);
v5 = 16LL * v2;
*(_DWORD *)(heap_A + v3) = *(_DWORD *)(heap_A + v5);
v6 = heap_A;
*(_DWORD *)(adjlist + 72LL * *(int *)(heap_A + v3) + 32) = result;
*(_DWORD *)(v6 + v5) = v4;
v7 = (int *)(heap_A + v5);
*(_DWORD *)(adjlist + 72LL * *v7 + 32) = v2;
v8 = heap_A + v3;
v9 = *(_QWORD *)(v8 + 8);
*(_QWORD *)(v8 + 8) = *((_QWORD *)v7 + 1);
*((_QWORD *)v7 + 1) = v9;
result = heapify();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax
int v2; // edi
__int64 v3; // rcx
int v4; // er9
__int64 v5; // rdx
__int64 v6; // r8
int *v7; // rax
__int64 v8; // rcx
__int64 v9; // xmm0_8

result = a1;
v2 = 2 * a1;
if ( v2 <= heap_size && *(double *)(heap_A + 16LL * v2 + 8) > *(double *)(heap_A + 16LL * (int)result + 8) )
{
if ( v2 >= heap_size || *(double *)(16LL * v2 + heap_A + 24) <= *(double *)(heap_A + 16LL * v2 + 8) )
goto LABEL_9;
goto LABEL_8;
}
if ( v2 < heap_size && *(double *)(16LL * v2 + heap_A + 24) > *(double *)(heap_A + 16LL * (int)result + 8) )
{
LABEL_8:
++v2;
LABEL_9:
if ( v2 != (_DWORD)result )
{
v3 = 16LL * (int)result;
v4 = *(_DWORD *)(heap_A + v3);
v5 = 16LL * v2;
*(_DWORD *)(heap_A + v3) = *(_DWORD *)(heap_A + v5);
v6 = heap_A;
*(_DWORD *)(adjlist + 72LL * *(int *)(heap_A + v3) + 32) = result;
*(_DWORD *)(v6 + v5) = v4;
v7 = (int *)(heap_A + v5);
*(_DWORD *)(adjlist + 72LL * *v7 + 32) = v2;
v8 = heap_A + v3;
v9 = *(_QWORD *)(v8 + 8);
*(_QWORD *)(v8 + 8) = *((_QWORD *)v7 + 1);
*((_QWORD *)v7 + 1) = v9;
result = func1();
}
}
return result;
}

original_code:
void heapify(int hi)
{
    int largest;
    int temp;
    double td;
    if ((((hi)*2) <= heap_size) && (heap_A[((hi)*2)].pri > heap_A[hi].pri))
        largest = ((hi)*2);
    else largest = hi;
    if ((((hi)*2+1) <= heap_size) && (heap_A[((hi)*2+1)].pri > heap_A[largest].pri))
        largest = ((hi)*2+1);
    if (largest != hi) {
        temp = heap_A[hi].pid;
        heap_A[hi].pid = heap_A[largest].pid;
        adjlist[heap_A[hi].pid].hid = hi;
        heap_A[largest].pid = temp;
        adjlist[heap_A[largest].pid].hid = largest;
        td = heap_A[hi].pri;
        heap_A[hi].pri = heap_A[largest].pri;
        heap_A[largest].pri = td;
        heapify(largest);
    }
}

variable_types: hi int

variable_types: largest int

variable_types: temp int

variable_types: td double


decompiled_code:
__int64 extract_max()
{
int v0; // edx
__int64 v1; // rsi
unsigned int v2; // ebx
__int64 v3; // rax
int v4; // ecx

v0 = heap_size;
if ( heap_size <= 0 )
return (unsigned int)-1;
v1 = heap_A;
v2 = *(_DWORD *)(heap_A + 16);
v3 = heap_A + 16LL * heap_size;
v4 = *(_DWORD *)v3;
*(_DWORD *)(heap_A + 16) = *(_DWORD *)v3;
*(_QWORD *)(v1 + 24) = *(_QWORD *)(v3 + 8);
*(_DWORD *)(adjlist + 72LL * v4 + 32) = 1;
heap_size = v0 - 1;
heapify(1u);
return v2;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // edx
__int64 v1; // rsi
unsigned int v2; // ebx
__int64 v3; // rax
int v4; // ecx

v0 = heap_size;
if ( heap_size <= 0 )
return (unsigned int)-1;
v1 = heap_A;
v2 = *(_DWORD *)(heap_A + 16);
v3 = heap_A + 16LL * heap_size;
v4 = *(_DWORD *)v3;
*(_DWORD *)(heap_A + 16) = *(_DWORD *)v3;
*(_QWORD *)(v1 + 24) = *(_QWORD *)(v3 + 8);
*(_DWORD *)(adjlist + 72LL * v4 + 32) = 1;
heap_size = v0 - 1;
func1(1u);
return v2;
}

original_code:
int extract_max()
{
    int max;
    if (heap_size < 1) return -1;
    max = heap_A[1].pid;
    heap_A[1].pid = heap_A[heap_size].pid;
    heap_A[1].pri = heap_A[heap_size].pri;
    adjlist[heap_A[1].pid].hid = 1;
    heap_size--;
    heapify(1);
    return max;
}

variable_types: max int

return_type: int


decompiled_code:
__int64 __fastcall insert_heap(int a1, double a2)
{
int v2; // ecx
int v3; // esi
__int64 v4; // rax
__int64 v5; // rdx
int *v6; // rdx
__int64 v7; // rax

v2 = heap_size + 1;
heap_size = v2;
v3 = v2;
if ( v2 > 1 )
{
while ( 1 )
{
v3 = v2;
v2 /= 2;
v4 = 16LL * v2;
if ( a2 <= *(double *)(heap_A + v4 + 8) )
break;
v5 = 16LL * v3;
*(_DWORD *)(heap_A + v5) = *(_DWORD *)(heap_A + 16LL * v2);
v6 = (int *)(heap_A + v5);
*((_QWORD *)v6 + 1) = *(_QWORD *)(heap_A + v4 + 8);
*(_DWORD *)(adjlist + 72LL * *v6 + 32) = v3;
if ( v3 <= 3 )
{
v3 = v2;
break;
}
}
}
v7 = heap_A + 16LL * v3;
*(double *)(v7 + 8) = a2;
*(_DWORD *)v7 = a1;
*(_DWORD *)(adjlist + 72LL * a1 + 32) = v3;
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, double a2)
{
int v2; // ecx
int v3; // esi
__int64 v4; // rax
__int64 v5; // rdx
int *v6; // rdx
__int64 v7; // rax

v2 = heap_size + 1;
heap_size = v2;
v3 = v2;
if ( v2 > 1 )
{
while ( 1 )
{
v3 = v2;
v2 /= 2;
v4 = 16LL * v2;
if ( a2 <= *(double *)(heap_A + v4 + 8) )
break;
v5 = 16LL * v3;
*(_DWORD *)(heap_A + v5) = *(_DWORD *)(heap_A + 16LL * v2);
v6 = (int *)(heap_A + v5);
*((_QWORD *)v6 + 1) = *(_QWORD *)(heap_A + v4 + 8);
*(_DWORD *)(adjlist + 72LL * *v6 + 32) = v3;
if ( v3 <= 3 )
{
v3 = v2;
break;
}
}
}
v7 = heap_A + 16LL * v3;
*(double *)(v7 + 8) = a2;
*(_DWORD *)v7 = a1;
*(_DWORD *)(adjlist + 72LL * a1 + 32) = v3;
return (unsigned int)v3;
}

original_code:
int insert_heap(int pi, double pr)
{
    int i;
    heap_size++;
    i = heap_size;
    while ((i>1)&&(heap_A[((i)/2)].pri < pr)) {
        heap_A[i].pid = heap_A[((i)/2)].pid;
        heap_A[i].pri = heap_A[((i)/2)].pri;
        adjlist[heap_A[i].pid].hid = i;
        i = ((i)/2);
    };
    heap_A[i].pri = pr;
    heap_A[i].pid = pi;
    adjlist[pi].hid = i;
    return i;
}

variable_types: pi int

variable_types: pr double

variable_types: i int


update

original_code:
void update(int hi, double pr)
{
    int pi,i;
    heap_A[hi].pri = pr;
    pi = heap_A[hi].pid;
    if (pr > heap_A[((hi)/2)].pri) {
        i = hi;
        while ((i>1)&&(heap_A[((i)/2)].pri < pr)) {
            heap_A[i].pid = heap_A[((i)/2)].pid;
            heap_A[i].pri = heap_A[((i)/2)].pri;
            adjlist[heap_A[i].pid].hid = i;
            i = ((i)/2);
        };
        heap_A[i].pri = pr;
        heap_A[i].pid = pi;
        adjlist[pi].hid = i;
    }
    else heapify(hi);
}

canonical_original_code:
void update(int hi, double pr)
{
    int pi; int i;
    heap_A[hi].pri = pr;
    pi = heap_A[hi].pid;
    if (pr > heap_A[((hi)/2)].pri) {
        i = hi;
        while ((i>1)&&(heap_A[((i)/2)].pri < pr)) {
            heap_A[i].pid = heap_A[((i)/2)].pid;
            heap_A[i].pri = heap_A[((i)/2)].pri;
            adjlist[heap_A[i].pid].hid = i;
            i = ((i)/2);
        };
        heap_A[i].pri = pr;
        heap_A[i].pid = pi;
        adjlist[pi].hid = i;
    }
    else heapify(hi);
}


decompiled_code:
__int64 __fastcall is_bound(__int64 a1)
{
double **v1; // rax
double **v2; // rdi
double *v3; // rdx
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8

v1 = (double **)(a1 + 104);
v2 = (double **)(a1 + 200);
while ( 1 )
{
v3 = *v1;
v4 = **v1;
if ( v4 > omaxs[0] )
return 1LL;
if ( omins[0] > v4 )
return 1LL;
v5 = v3[1];
if ( v5 > omaxs[1] )
return 1LL;
if ( omins[1] > v5 )
return 1LL;
v6 = v3[2];
if ( v6 > omaxs[2] )
return 1LL;
if ( omins[2] > v6 )
break;
v1 += 3;
if ( v1 == v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
double **v1; // rax
double **v2; // rdi
double *v3; // rdx
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8

v1 = (double **)(a1 + 104);
v2 = (double **)(a1 + 200);
while ( 1 )
{
v3 = *v1;
v4 = **v1;
if ( v4 > omaxs[0] )
return 1LL;
if ( omins[0] > v4 )
return 1LL;
v5 = v3[1];
if ( v5 > omaxs[1] )
return 1LL;
if ( omins[1] > v5 )
return 1LL;
v6 = v3[2];
if ( v6 > omaxs[2] )
return 1LL;
if ( omins[2] > v6 )
break;
v1 += 3;
if ( v1 == v2 )
return 0LL;
}
return 1LL;
}

original_code:
short is_bound(simplex *s) {
    int i;
    for (i=0;i<4;i++)
        if ((s->neigh[i].vert[0] > omaxs[0]) || (s->neigh[i].vert[0] < omins[0])
            ||(s->neigh[i].vert[1] > omaxs[1]) || (s->neigh[i].vert[1] < omins[1])
            ||(s->neigh[i].vert[2] > omaxs[2]) || (s->neigh[i].vert[2] < omins[2]))
            return 1;
    return 0;
}

canonical_original_code:
short is_bound(struct simplex *s) {
    int i;
    for (i=0;i<4;i++)
        if ((s->neigh[i].vert[0] > omaxs[0]) || (s->neigh[i].vert[0] < omins[0])
            ||(s->neigh[i].vert[1] > omaxs[1]) || (s->neigh[i].vert[1] < omins[1])
            ||(s->neigh[i].vert[2] > omaxs[2]) || (s->neigh[i].vert[2] < omins[2]))
            return 1;
    return 0;
}

variable_types: struct simplex { struct simplex *next; short mark; double *vv; double sqradius; short status; long poleindex; short edgestatus[6]; long visit; struct basis_s { struct basis_s *next; int ref_count; int lscale; double sqa; double vecs[1]; } *normal; struct neighbor { double *vert; struct simplex *simp; struct basis_s *basis; } peak; struct neighbor neigh[1]; } *

return_type: short

user_defined_types: struct simplex { struct simplex *next; short mark; double *vv; double sqradius; short status; long poleindex; short edgestatus[6]; long visit; struct basis_s *normal; struct neighbor peak; struct neighbor neigh[1]; }


decompiled_code:
_BOOL8 __fastcall close_pole(__int64 a1, __int64 a2, double a3)
{
return a3 * a3 > sqdist(a1, a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, __int64 a2, double a3)
{
return a3 * a3 > sqdist(a1, a2);
}

original_code:
int close_pole(double* v, double* p, double lfs_lb) {
    return (sqdist(v,p) < lfs_lb * lfs_lb);
}

canonical_original_code:
int close_pole(double *v, double *p, double lfs_lb) {
    return (sqdist(v,p) < lfs_lb * lfs_lb);
}

variable_types:
v
double *

variable_types:
p
double *


antiLabel

decompiled_code:
__int64 __fastcall antiLabel(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( a1 == 2 )
return 1LL;
if ( a1 == 1 )
result = 2LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( a1 == 2 )
return 1LL;
if ( a1 == 1 )
result = 2LL;
return result;
}

original_code:
int antiLabel(int label) {
    if (label == 2) return(1);
    if (label == 1) return(2);
    return(label);
}

variable_types: label int


labelPole

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

result = adjlist + 72LL * a1;
*(_WORD *)(result + 10) = a2;
if ( loopStart == a1 )
loopStart = -1;
return result;
}

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

result = adjlist + 72LL * a1;
*(_WORD *)(result + 10) = a2;
if ( loopStart == a1 )
loopStart = -1;
return result;
}

original_code:
void labelPole(int pid,int label) {
    adjlist[pid].label = label;
    if (pid == loopStart) {
        loopStart = -1;
    }
}

canonical_original_code:
void labelPole(int pid, int label) {
    adjlist[pid].label = label;
    if (pid == loopStart) {
        loopStart = -1;
    }
}

variable_types: pid int


cantLabelAnything

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

if ( loopStart == -1 )
{
loopStart = a1;
count = 0;
lastCount = 0;
result = (unsigned int)FALSE;
}
else
{
if ( loopStart != a1 )
{
++count;
return (unsigned int)FALSE;
}
if ( count != lastCount )
{
lastCount = count;
count = 0;
return (unsigned int)FALSE;
}
fwrite("Can't label any more! \n", 1uLL, 0x17uLL, DFILE);
result = (unsigned int)TRUE;
}
return result;
}

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

if ( loopStart == -1 )
{
loopStart = a1;
count = 0;
lastCount = 0;
result = (unsigned int)FALSE;
}
else
{
if ( loopStart != a1 )
{
++count;
return (unsigned int)FALSE;
}
if ( count != lastCount )
{
lastCount = count;
count = 0;
return (unsigned int)FALSE;
}
fwrite("Can't label any more! \n", 1uLL, 0x17uLL, DFILE);
result = (unsigned int)TRUE;
}
return result;
}

original_code:
int cantLabelAnything(int pid) {
    if (loopStart == -1) {
        loopStart = pid;
        count = 0;
        lastCount = 0;
        return(FALSE);
    }
    if (pid == loopStart) {
        if (count == lastCount) {
            fprintf(DFILE,"Can't label any more! \n");
            return(TRUE);
        } else {
            lastCount = count;
            count = 0;
        }
    } else {
        count++;
    }
    return(FALSE);
}


newOpposite

decompiled_code:
__int64 __fastcall newOpposite(int a1, int a2, double a3)
{
double *v3; // rax
double **v4; // rcx
__int64 result; // rax
__int64 v6; // rdx
double v7; // xmm0_8

v3 = (double *)malloc(0x18uLL);
*(_QWORD *)v3 = a2;
v3[1] = a3;
v4 = (double **)(opplist + 8LL * a1);
*((_QWORD *)v3 + 2) = *v4;
*v4 = v3;
result = adjlist;
v6 = adjlist + 72LL * a1;
v7 = *(double *)(adjlist + 72LL * a2 + 40);
if ( *(double *)(v6 + 48) > v7 )
{
if ( v7 <= 0.0 )
_assert_fail("adjlist[p2index].sqradius > 0.0", "crust.c", 0x167u, "newOpposite");
*(double *)(v6 + 48) = v7;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, double a3)
{
double *v3; // rax
double **v4; // rcx
__int64 result; // rax
__int64 v6; // rdx
double v7; // xmm0_8

v3 = (double *)malloc(0x18uLL);
*(_QWORD *)v3 = a2;
v3[1] = a3;
v4 = (double **)(opplist + 8LL * a1);
*((_QWORD *)v3 + 2) = *v4;
*v4 = v3;
result = adjlist;
v6 = adjlist + 72LL * a1;
v7 = *(double *)(adjlist + 72LL * a2 + 40);
if ( *(double *)(v6 + 48) > v7 )
{
if ( v7 <= 0.0 )
_assert_fail("adjlist[p2index].sqradius > 0.0", "crust.c", 0x167u, "newOpposite");
*(double *)(v6 + 48) = v7;
}
return result;
}

original_code:
void newOpposite(int p1index, int p2index, double pole_angle) {
    plist *newplist;
    newplist = (struct plist *) malloc(sizeof(struct plist));
    newplist->pid = p2index;
    newplist->angle = pole_angle;
    newplist->next = opplist[p1index];
    opplist[p1index] = newplist;
    if (adjlist[p1index].oppradius > adjlist[p2index].sqradius) {
        ((void) sizeof ((adjlist[p2index].sqradius > 0.0) ? 1 : 0), __extension__ ({ if (adjlist[p2index].sqradius > 0.0) ; else __assert_fail ("adjlist[p2index].sqradius > 0.0", "crust.c", 359, __extension__ __PRETTY_FUNCTION__); }));
        adjlist[p1index].oppradius = adjlist[p2index].sqradius;
    }
}

canonical_original_code:
void newOpposite(int p1index, int p2index, double pole_angle) {
    struct plist *newplist;
    newplist = (struct plist *) malloc(sizeof(struct plist));
    newplist->pid = p2index;
    newplist->angle = pole_angle;
    newplist->next = opplist[p1index];
    opplist[p1index] = newplist;
    if (adjlist[p1index].oppradius > adjlist[p2index].sqradius) {
        ((void) sizeof ((adjlist[p2index].sqradius > 0.0) ? 1 : 0), __extension__ ({ if (adjlist[p2index].sqradius > 0.0) ; else __assert_fail ("adjlist[p2index].sqradius > 0.0", "crust.c", 359, __extension__ __PRETTY_FUNCTION__); }));
        adjlist[p1index].oppradius = adjlist[p2index].sqradius;
    }
}

variable_types: struct plist { long pid; double angle; struct plist *next; } *


scale

decompiled_code:
__int64 __fastcall scale(int a1, __int64 a2)
{
double *v2; // rdx
__int64 v3; // rcx
double *v4; // rax
double v5; // xmm1_8
double v6; // xmm0_8
__int64 result; // rax

if ( a1 <= 0 )
goto LABEL_6;
v2 = (double *)a2;
v3 = a2 + 8LL * (unsigned int)(a1 - 1) + 8;
v4 = (double *)a2;
v5 = 0.0;
do
{
v6 = *v4;
if ( *v4 <= 0.0 )
*(_QWORD *)&v6 ^= LC4;
v5 = fmax(v6, v5);
++v4;
}
while ( v4 != (double *)v3 );
if ( v5 < 2.220446049250313e-14 )
{
LABEL_6:
fwrite("fails to scale: ", 1uLL, 0x10uLL, stderr);
print_point(stderr, a1, a2);
fflush(stderr);
fputc(10, stderr);
result = 1LL;
}
else
{
do
{
*v2 = *v2 / v5;
++v2;
}
while ( v2 != (double *)v3 );
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
double *v2; // rdx
__int64 v3; // rcx
double *v4; // rax
double v5; // xmm1_8
double v6; // xmm0_8
__int64 result; // rax

if ( a1 <= 0 )
goto LABEL_6;
v2 = (double *)a2;
v3 = a2 + 8LL * (unsigned int)(a1 - 1) + 8;
v4 = (double *)a2;
v5 = 0.0;
do
{
v6 = *v4;
if ( *v4 <= 0.0 )
*(_QWORD *)&v6 ^= LC4;
v5 = fmax(v6, v5);
++v4;
}
while ( v4 != (double *)v3 );
if ( v5 < 2.220446049250313e-14 )
{
LABEL_6:
fwrite("fails to scale: ", 1uLL, 0x10uLL, stderr);
func0(stderr, a1, a2);
fflush(stderr);
fputc(10, stderr);
result = 1LL;
}
else
{
do
{
*v2 = *v2 / v5;
++v2;
}
while ( v2 != (double *)v3 );
result = 0LL;
}
return result;
}

original_code:
int scale(int dim, point p) {
 Coord max = 0;
 int i;
 Coord abs,val;
 for (i=0;i<dim;i++) {
  val = p[i];
  abs = (val > 0) ? val: -val;
  max = (abs > max) ? abs : max;
 }
 if (max< 100*((double)2.22044604925031308084726333618164062e-16L)) {
  fprintf(stderr, "fails to scale: ");
  print_point(stderr, dim,p);fflush(stderr);
  fprintf(stderr, "\n");
  return 1;
 }
 for (i=0;i<dim;i++) p[i] /= max;
 return 0;
}

canonical_original_code:
int scale(int dim, double *p) {
 double max = 0;
 int i;
 double abs; double val;
 for (i=0;i<dim;i++) {
  val = p[i];
  abs = (val > 0) ? val: -val;
  max = (abs > max) ? abs : max;
 }
 if (max< 100*((double)2.22044604925031308084726333618164062e-16L)) {
  fprintf(stderr, "fails to scale: ");
  print_point(stderr, dim,p);fflush(stderr);
  fprintf(stderr, "\n");
  return 1;
 }
 for (i=0;i<dim;i++) p[i] /= max;
 return 0;
}

variable_types: dim int

variable_types: max double

variable_types: abs double

variable_types: val double


repo: rhs/amp

decompiled_code:
void __fastcall amp_free_binary(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
free(a1);
}

original_code:
void amp_free_binary(amp_binary_t *b)
{
  free(b);
}

canonical_original_code:
void amp_free_binary(struct amp_binary_st *b)
{
  free(b);
}

variable_types: struct amp_binary_st { unsigned long size; char bytes[]; } *


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

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

original_code:
size_t amp_binary_size(amp_binary_t *b)
{
  return b->size;
}

canonical_original_code:
unsigned long amp_binary_size(struct amp_binary_st *b)
{
  return b->size;
}

return_type: unsigned long

user_defined_types: struct amp_binary_st { unsigned long size; char bytes[]; }


decompiled_code:
__int64 __fastcall amp_binary_bytes(__int64 a1)
{
return a1 + 8;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return a1 + 8;
}

original_code:
char *amp_binary_bytes(amp_binary_t *b)
{
  return b->bytes;
}

canonical_original_code:
char *amp_binary_bytes(struct amp_binary_st *b)
{
  return b->bytes;
}

return_type: char *


decompiled_code:
__int64 __fastcall amp_hash_binary(_QWORD *a1)
{
__int64 result; // rax
char *v2; // rdx
__int64 v3; // rsi

result = *a1;
if ( *a1 )
{
v2 = (char *)(a1 + 1);
v3 = (__int64)a1 + result + 8;
result = 0LL;
do
result = 31 * result + *v2++;
while ( v2 != (char *)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 result; // rax
char *v2; // rdx
__int64 v3; // rsi

result = *a1;
if ( *a1 )
{
v2 = (char *)(a1 + 1);
v3 = (__int64)a1 + result + 8;
result = 0LL;
do
result = 31 * result + *v2++;
while ( v2 != (char *)v3 );
}
return result;
}

original_code:
uintptr_t amp_hash_binary(amp_binary_t *b)
{
  uintptr_t hash = 0;
  for (int i = 0; i < b->size; i++)
  {
    hash = 31*hash + b->bytes[i];
  }
  return hash;
}

canonical_original_code:
unsigned long amp_hash_binary(struct amp_binary_st *b)
{
  unsigned long hash = 0;
  for (int i = 0; i < b->size; i++)
  {
    hash = 31*hash + b->bytes[i];
  }
  return hash;
}

variable_types:
hash
unsigned long


decompiled_code:
int __fastcall amp_compare_binary(size_t *a1, _QWORD *a2)
{
int result; // eax

result = *a2 - *a1;
if ( *a1 == *a2 )
result = memcmp(a1 + 1, a2 + 1, *a1);
return result;
}

canonical_decompiled_code:
int __fastcall func4(size_t *a1, _QWORD *a2)
{
int result; // eax

result = *a2 - *a1;
if ( *a1 == *a2 )
result = memcmp(a1 + 1, a2 + 1, *a1);
return result;
}

original_code:
int amp_compare_binary(amp_binary_t *a, amp_binary_t *b)
{
  if (a->size == b->size)
    return memcmp(a->bytes, b->bytes, a->size);
  else
    return b->size - a->size;
}

canonical_original_code:
int amp_compare_binary(struct amp_binary_st *a, struct amp_binary_st *b)
{
  if (a->size == b->size)
    return memcmp(a->bytes, b->bytes, a->size);
  else
    return b->size - a->size;
}

variable_types:
b
struct amp_binary_st *


decompiled_code:
__int64 __fastcall amp_format_binary(char **a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 result; // rax
const unsigned __int16 **v5; // r14
__int64 v6; // rbx
unsigned __int8 v7; // dl

if ( !a3 )
return amp_fmt(a1, a2, "(null)");
result = 0LL;
if ( *a3 )
{
v5 = _ctype_b_loc();
v6 = 0LL;
while ( 1 )
{
v7 = *((_BYTE *)a3 + v6 + 8);
if ( ((*v5)[v7] & 0x4000) != 0 )
{
if ( (unsigned __int64)*a1 >= a2 )
return 0xFFFFFFFFLL;
*(*a1)++ = v7;
}
else
{
if ( (__int64)(a2 - (_QWORD)*a1) <= 4 )
return 0xFFFFFFFFLL;
sprintf(*a1, "\\x%.2x", v7);
*a1 += 4;
}
if ( *a3 <= (unsigned __int64)++v6 )
return 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char **a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 result; // rax
const unsigned __int16 **v5; // r14
__int64 v6; // rbx
unsigned __int8 v7; // dl

if ( !a3 )
return amp_fmt(a1, a2, "(null)");
result = 0LL;
if ( *a3 )
{
v5 = _ctype_b_loc();
v6 = 0LL;
while ( 1 )
{
v7 = *((_BYTE *)a3 + v6 + 8);
if ( ((*v5)[v7] & 0x4000) != 0 )
{
if ( (unsigned __int64)*a1 >= a2 )
return 0xFFFFFFFFLL;
*(*a1)++ = v7;
}
else
{
if ( (__int64)(a2 - (_QWORD)*a1) <= 4 )
return 0xFFFFFFFFLL;
sprintf(*a1, "\\x%.2x", v7);
*a1 += 4;
}
if ( *a3 <= (unsigned __int64)++v6 )
return 0LL;
}
}
return result;
}

original_code:
int amp_format_binary(char **pos, char *limit, amp_binary_t *binary)
{
  if (!binary) return amp_fmt(pos, limit, "(null)");
  for (int i = 0; i < binary->size; i++)
  {
    uint8_t b = binary->bytes[i];
    if (((*__ctype_b_loc ())[(int) ((b))] & (unsigned short int) _ISprint)) {
      if (*pos < limit) {
        **pos = b;
        *pos += 1;
      } else {
        return -1;
      }
    } else {
      if (limit - *pos > 4)
      {
        sprintf(*pos, "\\x%.2x", b);
        *pos += 4;
      } else {
        return -1;
      }
    }
  }
  return 0;
}

canonical_original_code:
int amp_format_binary(char **pos, char *limit, struct amp_binary_st *binary)
{
  if (!binary) return amp_fmt(pos, limit, "(null)");
  for (int i = 0; i < binary->size; i++)
  {
    unsigned char b = binary->bytes[i];
    if (((*__ctype_b_loc ())[(int) ((b))] & (unsigned short) _ISprint)) {
      if (*pos < limit) {
        **pos = b;
        *pos += 1;
      } else {
        return -1;
      }
    } else {
      if (limit - *pos > 4)
      {
        sprintf(*pos, "\\x%.2x", b);
        *pos += 4;
      } else {
        return -1;
      }
    }
  }
  return 0;
}

variable_types:
pos
char **

variable_types:
limit
char *

variable_types:
b
unsigned char


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

switch ( a1 )
{
case 64:
result = 0LL;
break;
case 67:
case 112:
result = 4LL;
break;
case 68:
case -128:
result = 5LL;
break;
case 69:
case -64:
case -48:
result = 16LL;
break;
case 80:
result = 2LL;
break;
case 81:
result = 6LL;
break;
case 96:
result = 3LL;
break;
case 97:
result = 7LL;
break;
case 113:
result = 8LL;
break;
case 114:
result = 10LL;
break;
case -127:
result = 9LL;
break;
case -126:
result = 11LL;
break;
case -96:
case -80:
result = 14LL;
break;
case -95:
case -79:
result = 13LL;
break;
case -63:
case -47:
result = 17LL;
break;
case -32:
case -16:
result = 15LL;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

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

switch ( a1 )
{
case 64:
result = 0LL;
break;
case 67:
case 112:
result = 4LL;
break;
case 68:
case -128:
result = 5LL;
break;
case 69:
case -64:
case -48:
result = 16LL;
break;
case 80:
result = 2LL;
break;
case 81:
result = 6LL;
break;
case 96:
result = 3LL;
break;
case 97:
result = 7LL;
break;
case 113:
result = 8LL;
break;
case 114:
result = 10LL;
break;
case -127:
result = 9LL;
break;
case -126:
result = 11LL;
break;
case -96:
case -80:
result = 14LL;
break;
case -95:
case -79:
result = 13LL;
break;
case -63:
case -47:
result = 17LL;
break;
case -32:
case -16:
result = 15LL;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
static enum TYPE amqp_code_to_type(uint8_t code)
{
  switch (code)
  {
  case (0x40): return EMPTY;
  case (0x50): return UBYTE;
  case (0x51): return BYTE;
  case (0x60): return USHORT;
  case (0x61): return SHORT;
  case (0x70):
  case (0x43): return UINT;
  case (0x71): return INT;
  case (0x72): return FLOAT;
  case (0x44):
  case (0x80): return ULONG;
  case (0x81): return LONG;
  case (0x82): return DOUBLE;
  case (0xa0):
  case (0xb0): return BINARY;
  case (0xa1):
  case (0xb1): return STRING;
  case (0x45):
  case (0xc0):
  case (0xd0): return LIST;
  case (0xe0):
  case (0xf0): return ARRAY;
  case (0xc1):
  case (0xd1): return MAP;
  }
  return -1;
}

canonical_original_code:
static enum TYPE amqp_code_to_type(unsigned char code)
{
  switch (code)
  {
  case (0x40): return EMPTY;
  case (0x50): return UBYTE;
  case (0x51): return BYTE;
  case (0x60): return USHORT;
  case (0x61): return SHORT;
  case (0x70):
  case (0x43): return UINT;
  case (0x71): return INT;
  case (0x72): return FLOAT;
  case (0x44):
  case (0x80): return ULONG;
  case (0x81): return LONG;
  case (0x82): return DOUBLE;
  case (0xa0):
  case (0xb0): return BINARY;
  case (0xa1):
  case (0xb1): return STRING;
  case (0x45):
  case (0xc0):
  case (0xd0): return LIST;
  case (0xe0):
  case (0xf0): return ARRAY;
  case (0xc1):
  case (0xd1): return MAP;
  }
  return -1;
}

variable_types:
code
unsigned char

return_type: enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 }


frame

decompiled_code:
__int64 __fastcall frame(_QWORD *a1)
{
return (__int64)&a1[3 * *a1 - 2];
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
return (__int64)&a1[3 * *a1 - 2];
}

original_code:
static struct amp_decode_context_frame_st *frame(void *ptr)
{
  struct amp_decode_context_st *ctx = ((struct amp_decode_context_st *) (ptr));
  return &ctx->frames[ctx->depth-1];
}

variable_types:
ptr
void *

variable_types: struct amp_decode_context_st { unsigned long depth; struct amp_decode_context_frame_st { unsigned long count; unsigned long limit; struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_list; struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; } *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; } *values; } frames[1024]; } *

return_type: struct amp_decode_context_frame_st { unsigned long count; unsigned long limit; struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_list; struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; } *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; } *values; } *

user_defined_types: struct amp_decode_context_st { unsigned long depth; struct amp_decode_context_frame_st frames[1024]; }

user_defined_types: struct amp_decode_context_frame_st { unsigned long count; unsigned long limit; struct amp_value_st *values; }

user_defined_types: struct amp_value_st { enum TYPE type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st *as_string; struct amp_binary_st *as_binary; struct amp_array_st *as_array; struct amp_list_st *as_list; struct amp_map_st *as_map; struct amp_tag_st *as_tag; void *as_ref; } u; }

user_defined_types: struct amp_array_st { enum TYPE type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; }


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

autopop(a1);
v1 = (_QWORD *)frame(a1);
v2 = (*v1)++;
return v1[2] + 16 * v2;
}

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

autopop(a1);
v1 = (_QWORD *)func2(a1);
v2 = (*v1)++;
return v1[2] + 16 * v2;
}

original_code:
static amp_value_t *next_value(void *ptr)
{
  autopop(ptr);
  struct amp_decode_context_frame_st *frm = frame(ptr);
  amp_value_t *result = &frm->values[frm->count++];
  return result;
}

canonical_original_code:
static struct amp_value_st *next_value(void *ptr)
{
  autopop(ptr);
  struct amp_decode_context_frame_st *frm = frame(ptr);
  struct amp_value_st *result = &frm->values[frm->count++];
  return result;
}

variable_types: struct amp_decode_context_frame_st { unsigned long count; unsigned long limit; struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_list; struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; } *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; } *values; } *


decompiled_code:
__int64 __fastcall curr_value(_QWORD *a1)
{
return a1[3 * *a1] + 16LL * a1[3 * *a1 - 2] - 16;
}

original_code:
static amp_value_t *curr_value(void *ptr)
{
  struct amp_decode_context_st *ctx = ((struct amp_decode_context_st *) (ptr));
  struct amp_decode_context_frame_st *frm = &ctx->frames[ctx->depth-1];
  return &frm->values[frm->count - 1];
}

canonical_original_code:
static struct amp_value_st *curr_value(void *ptr)
{
  struct amp_decode_context_st *ctx = ((struct amp_decode_context_st *) (ptr));
  struct amp_decode_context_frame_st *frm = &ctx->frames[ctx->depth-1];
  return &frm->values[frm->count - 1];
}

return_type: struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_list; struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; } *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; } *


decompiled_code:
__int64 __fastcall amp_decode_bool(_QWORD *a1, char a2)
{
__int64 result; // rax

result = next_value(a1);
*(_DWORD *)result = 1;
*(_BYTE *)(result + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, char a2)
{
__int64 result; // rax

result = func3(a1);
*(_DWORD *)result = 1;
*(_BYTE *)(result + 8) = a2;
return result;
}

original_code:
void amp_decode_bool(void *ctx, _Bool v) {
  amp_value_t *value = next_value(ctx);
  value->type = BOOLEAN;
  value->u.as_boolean = v;
}

canonical_original_code:
void amp_decode_bool(void *ctx, _Bool v) {
  struct amp_value_st *value = next_value(ctx);
  value->type = BOOLEAN;
  value->u.as_boolean = v;
}

variable_types:
ctx
void *

variable_types: struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_list; struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; } *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; } *


decompiled_code:
__int64 __fastcall amp_decode_ubyte(_QWORD *a1, char a2)
{
__int64 result; // rax

result = next_value(a1);
*(_DWORD *)result = 2;
*(_BYTE *)(result + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, char a2)
{
__int64 result; // rax

result = func3(a1);
*(_DWORD *)result = 2;
*(_BYTE *)(result + 8) = a2;
return result;
}

original_code:
void amp_decode_ubyte(void *ctx, uint8_t v) {
  amp_value_t *value = next_value(ctx);
  value->type = UBYTE;
  value->u.as_ubyte = v;
}

canonical_original_code:
void amp_decode_ubyte(void *ctx, unsigned char v) {
  struct amp_value_st *value = next_value(ctx);
  value->type = UBYTE;
  value->u.as_ubyte = v;
}

variable_types:
v
unsigned char

user_defined_types: enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 }

user_defined_types: struct amp_string_st { unsigned long size; int wcs[]; }

user_defined_types: struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; }

user_defined_types: struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; }

user_defined_types: struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; }


decompiled_code:
__int64 __fastcall amp_decode_byte(_QWORD *a1, char a2)
{
__int64 result; // rax

result = next_value(a1);
*(_DWORD *)result = 6;
*(_BYTE *)(result + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, char a2)
{
__int64 result; // rax

result = func3(a1);
*(_DWORD *)result = 6;
*(_BYTE *)(result + 8) = a2;
return result;
}

original_code:
void amp_decode_byte(void *ctx, int8_t v) {
  amp_value_t *value = next_value(ctx);
  value->type = BYTE;
  value->u.as_byte = v;
}

canonical_original_code:
void amp_decode_byte(void *ctx, char v) {
  struct amp_value_st *value = next_value(ctx);
  value->type = BYTE;
  value->u.as_byte = v;
}

variable_types: v char


decompiled_code:
__int64 __fastcall amp_decode_ushort(_QWORD *a1, __int16 a2)
{
__int64 result; // rax

result = next_value(a1);
*(_DWORD *)result = 3;
*(_WORD *)(result + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int16 a2)
{
__int64 result; // rax

result = func3(a1);
*(_DWORD *)result = 3;
*(_WORD *)(result + 8) = a2;
return result;
}

original_code:
void amp_decode_ushort(void *ctx, uint16_t v) {
  amp_value_t *value = next_value(ctx);
  value->type = USHORT;
  value->u.as_ushort = v;
}

canonical_original_code:
void amp_decode_ushort(void *ctx, unsigned short v) {
  struct amp_value_st *value = next_value(ctx);
  value->type = USHORT;
  value->u.as_ushort = v;
}

variable_types:
v
unsigned short


decompiled_code:
__int64 __fastcall amp_decode_short(_QWORD *a1, __int16 a2)
{
__int64 result; // rax

result = next_value(a1);
*(_DWORD *)result = 7;
*(_WORD *)(result + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int16 a2)
{
__int64 result; // rax

result = func3(a1);
*(_DWORD *)result = 7;
*(_WORD *)(result + 8) = a2;
return result;
}

original_code:
void amp_decode_short(void *ctx, int16_t v) {
  amp_value_t *value = next_value(ctx);
  value->type = SHORT;
  value->u.as_short = v;
}

canonical_original_code:
void amp_decode_short(void *ctx, short v) {
  struct amp_value_st *value = next_value(ctx);
  value->type = SHORT;
  value->u.as_short = v;
}

variable_types: v short


decompiled_code:
__int64 __fastcall amp_decode_ulong(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = next_value(a1);
*(_DWORD *)result = 5;
*(_QWORD *)(result + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = func3(a1);
*(_DWORD *)result = 5;
*(_QWORD *)(result + 8) = a2;
return result;
}

original_code:
void amp_decode_ulong(void *ctx, uint64_t v) {
  amp_value_t *value = next_value(ctx);
  value->type = ULONG;
  value->u.as_ulong = v;
}

canonical_original_code:
void amp_decode_ulong(void *ctx, unsigned long v) {
  struct amp_value_st *value = next_value(ctx);
  value->type = ULONG;
  value->u.as_ulong = v;
}

variable_types:
v
unsigned long


decompiled_code:
__int64 __fastcall amp_decode_long(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = next_value(a1);
*(_DWORD *)result = 9;
*(_QWORD *)(result + 8) = a2;
return result;
}

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

result = func3(a1);
*(_DWORD *)result = 9;
*(_QWORD *)(result + 8) = a2;
return result;
}

original_code:
void amp_decode_long(void *ctx, int64_t v) {
  amp_value_t *value = next_value(ctx);
  value->type = LONG;
  value->u.as_long = v;
}

canonical_original_code:
void amp_decode_long(void *ctx, long v) {
  struct amp_value_st *value = next_value(ctx);
  value->type = LONG;
  value->u.as_long = v;
}

variable_types: v long


decompiled_code:
__int64 __fastcall amp_decode_double(_QWORD *a1, double a2)
{
__int64 result; // rax

result = next_value(a1);
*(_DWORD *)result = 11;
*(double *)(result + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1, double a2)
{
__int64 result; // rax

result = func3(a1);
*(_DWORD *)result = 11;
*(double *)(result + 8) = a2;
return result;
}

original_code:
void amp_decode_double(void *ctx, double v) {
  amp_value_t *value = next_value(ctx);
  value->type = DOUBLE;
  value->u.as_double = v;
}

canonical_original_code:
void amp_decode_double(void *ctx, double v) {
  struct amp_value_st *value = next_value(ctx);
  value->type = DOUBLE;
  value->u.as_double = v;
}

variable_types: v double


decompiled_code:
void amp_decode_symbol()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void amp_decode_symbol(void *ctx, size_t size, char *bytes) {
}

canonical_original_code:
void amp_decode_symbol(void *ctx, unsigned long size, char *bytes) {
}

variable_types:
size
unsigned long

variable_types:
bytes
char *


decompiled_code:
__int64 __fastcall amp_decode_stop_array(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

pop_frame(a1);
result = *(_QWORD *)(curr_value(a1) + 8);
*(_QWORD *)(result + 8) = a2;
return result;
}

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

pop_frame(a1);
result = *(_QWORD *)(func4(a1) + 8);
*(_QWORD *)(result + 8) = a2;
return result;
}

original_code:
void amp_decode_stop_array(void *ctx, size_t count, uint8_t code) {
  pop_frame(ctx);
  amp_value_t *value = curr_value(ctx);
  value->u.as_array->size = count;
}

canonical_original_code:
void amp_decode_stop_array(void *ctx, unsigned long count, unsigned char code) {
  pop_frame(ctx);
  struct amp_value_st *value = curr_value(ctx);
  value->u.as_array->size = count;
}

variable_types:
count
unsigned long


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

pop_frame(a1);
result = *(unsigned __int64 **)(curr_value(a1) + 8);
*result = a2 >> 1;
return result;
}

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

pop_frame(a1);
result = *(unsigned __int64 **)(func4(a1) + 8);
*result = a2 >> 1;
return result;
}

original_code:
void amp_decode_stop_map(void *ctx, size_t count) {
  pop_frame(ctx);
  amp_value_t *value = curr_value(ctx);
  value->u.as_map->size = count/2;
}

canonical_original_code:
void amp_decode_stop_map(void *ctx, unsigned long count) {
  pop_frame(ctx);
  struct amp_value_st *value = curr_value(ctx);
  value->u.as_map->size = count/2;
}


decompiled_code:
__int64 __fastcall amp_decode_binary(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
__int64 result; // rax

v4 = next_value(a1);
*(_DWORD *)v4 = 14;
result = amp_binary(a3, a2);
*(_QWORD *)(v4 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
__int64 result; // rax

v4 = func3(a1);
*(_DWORD *)v4 = 14;
result = amp_binary(a3, a2);
*(_QWORD *)(v4 + 8) = result;
return result;
}

original_code:
void amp_decode_binary(void *ctx, size_t size, char *bytes) {
  amp_value_t *value = next_value(ctx);
  value->type = BINARY;
  value->u.as_binary = amp_binary(bytes, size);
}

canonical_original_code:
void amp_decode_binary(void *ctx, unsigned long size, char *bytes) {
  struct amp_value_st *value = next_value(ctx);
  value->type = BINARY;
  value->u.as_binary = amp_binary(bytes, size);
}


decompiled_code:
__int64 __fastcall amp_decode_utf8(_QWORD *a1, size_t a2, char *a3)
{
__int64 v3; // rbx
void *v4; // rsp
iconv_t v5; // r12
__int64 result; // rax
char *inbuf; // [rsp+0h] [rbp-40h] BYREF
size_t inbytesleft; // [rsp+8h] [rbp-38h] BYREF
char *outbuf; // [rsp+10h] [rbp-30h] BYREF
size_t outbytesleft[5]; // [rsp+18h] [rbp-28h] BYREF

inbytesleft = a2;
inbuf = a3;
v3 = next_value(a1);
*(_DWORD *)v3 = 13;
outbytesleft[0] = 4 * inbytesleft + 4;
v4 = alloca(outbytesleft[0]);
v5 = iconv_open("WCHAR_T", "UTF-8");
outbuf = (char *)&inbuf;
if ( iconv(v5, &inbuf, &inbytesleft, &outbuf, outbytesleft) == -1LL )
perror("amp_decode_utf8");
*(_DWORD *)outbuf = 0;
iconv_close(v5);
result = amp_string(&inbuf);
*(_QWORD *)(v3 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1, size_t a2, char *a3)
{
__int64 v3; // rbx
void *v4; // rsp
iconv_t v5; // r12
__int64 result; // rax
char *inbuf; // [rsp+0h] [rbp-40h] BYREF
size_t inbytesleft; // [rsp+8h] [rbp-38h] BYREF
char *outbuf; // [rsp+10h] [rbp-30h] BYREF
size_t outbytesleft[5]; // [rsp+18h] [rbp-28h] BYREF

inbytesleft = a2;
inbuf = a3;
v3 = func3(a1);
*(_DWORD *)v3 = 13;
outbytesleft[0] = 4 * inbytesleft + 4;
v4 = alloca(outbytesleft[0]);
v5 = iconv_open("WCHAR_T", "UTF-8");
outbuf = (char *)&inbuf;
if ( iconv(v5, &inbuf, &inbytesleft, &outbuf, outbytesleft) == -1LL )
perror("amp_decode_utf8");
*(_DWORD *)outbuf = 0;
iconv_close(v5);
result = amp_string(&inbuf);
*(_QWORD *)(v3 + 8) = result;
return result;
}

original_code:
void amp_decode_utf8(void *ctx, size_t size, char *bytes) {
  amp_value_t *value = next_value(ctx);
  value->type = STRING;
  size_t remaining = (size+1)*sizeof(wchar_t);
  wchar_t buf[size+1];
  iconv_t cd = iconv_open("WCHAR_T", "UTF-8");
  wchar_t *out = buf;
  size_t n = iconv(cd, &bytes, &size, (char **)&out, &remaining);
  if (n == -1)
  {
    perror("amp_decode_utf8");
  }
  *out = L'\0';
  iconv_close(cd);
  value->u.as_string = amp_string(buf);
}

canonical_original_code:
void amp_decode_utf8(void *ctx, unsigned long size, char *bytes) {
  struct amp_value_st *value = next_value(ctx);
  value->type = STRING;
  unsigned long remaining = (size+1)*sizeof(wchar_t);
  int buf[-1];
  void *cd = iconv_open("WCHAR_T", "UTF-8");
  int *out = buf;
  unsigned long n = iconv(cd, &bytes, &size, (char **)&out, &remaining);
  if (n == -1)
  {
    perror("amp_decode_utf8");
  }
  *out = L'\0';
  iconv_close(cd);
  value->u.as_string = amp_string(buf);
}

variable_types:
remaining
unsigned long

variable_types:
buf
int [-1]

variable_types:
cd
void *

variable_types:
out
int *

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall amp_decode(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD v5[3079]; // [rsp+0h] [rbp-6038h] BYREF

memset(v5, 0, 0x6008uLL);
push_frame(v5, a1, 0LL);
return amp_read_datum(a2, a3, amp_decoder[0], v5);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD v5[3079]; // [rsp+0h] [rbp-6038h] BYREF

memset(v5, 0, 0x6008uLL);
func1(v5, a1, 0LL);
return amp_read_datum(a2, a3, amp_decoder[0], v5);
}

original_code:
ssize_t amp_decode(amp_value_t *v, char *bytes, size_t n)
{
  struct amp_decode_context_st ctx = {.depth = 0};
  push_frame(&ctx, v, 0);
  ssize_t read = amp_read_datum(bytes, n, amp_decoder, &ctx);
  return read;
}

canonical_original_code:
long amp_decode(struct amp_value_st *v, char *bytes, unsigned long n)
{
  struct amp_decode_context_st ctx = {.depth = 0};
  push_frame(&ctx, v, 0);
  long read = amp_read_datum(bytes, n, amp_decoder, &ctx);
  return read;
}

variable_types: struct amp_decode_context_st { unsigned long depth; struct amp_decode_context_frame_st { unsigned long count; unsigned long limit; struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_list; struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; } *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; } *values; } frames[1024]; }

variable_types: read long

return_type: long


decompiled_code:
void __fastcall amp_free_map(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
free(a1);
}

original_code:
void amp_free_map(amp_map_t *m)
{
  free(m);
}

canonical_original_code:
void amp_free_map(struct amp_map_st *m)
{
  free(m);
}

variable_types: struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_list; struct amp_map_st *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; } pairs[]; } *


decompiled_code:
__int64 __fastcall amp_map_key(__int64 a1, int a2)
{
return *(_QWORD *)(32LL * a2 + a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
return *(_QWORD *)(32LL * a2 + a1 + 16);
}

original_code:
amp_value_t amp_map_key(amp_map_t *map, int index)
{
  return map->pairs[2*index];
}

canonical_original_code:
struct amp_value_st amp_map_key(struct amp_map_st *map, int index)
{
  return map->pairs[2*index];
}

variable_types:
map
struct amp_map_st *

variable_types: index int

return_type: struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_list; struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; } *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; }


decompiled_code:
__int64 __fastcall amp_map_value(__int64 a1, int a2)
{
return *(_QWORD *)(16LL * (2 * a2 + 1) + a1 + 16);
}

original_code:
amp_value_t amp_map_value(amp_map_t *map, int index)
{
  return map->pairs[2*index+1];
}

canonical_original_code:
struct amp_value_st amp_map_value(struct amp_map_st *map, int index)
{
  return map->pairs[2*index+1];
}


decompiled_code:
__int64 __fastcall has_entry(unsigned __int64 *a1, unsigned int a2, __int64 a3, unsigned int a4, __int64 a5)
{
unsigned __int64 v8; // rbx
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11; // rax
__int64 v12; // rdx

if ( !*a1 )
return 0LL;
v8 = 0LL;
do
{
v9 = amp_map_key((__int64)a1, v8);
if ( !(unsigned int)amp_compare_value(v9, v10, a2, a3) )
{
v11 = amp_map_value((__int64)a1, v8);
if ( !(unsigned int)amp_compare_value(v11, v12, a4, a5) )
return 1LL;
}
++v8;
}
while ( *a1 > v8 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 *a1, unsigned int a2, __int64 a3, unsigned int a4, __int64 a5)
{
unsigned __int64 v8; // rbx
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11; // rax
__int64 v12; // rdx

if ( !*a1 )
return 0LL;
v8 = 0LL;
do
{
v9 = func1((__int64)a1, v8);
if ( !(unsigned int)amp_compare_value(v9, v10, a2, a3) )
{
v11 = func2((__int64)a1, v8);
if ( !(unsigned int)amp_compare_value(v11, v12, a4, a5) )
return 1LL;
}
++v8;
}
while ( *a1 > v8 );
return 0LL;
}

original_code:
static _Bool has_entry(amp_map_t *m, amp_value_t key, amp_value_t value)
{
  int i;
  for (i = 0; i < m->size; i++)
  {
    if (!amp_compare_value(amp_map_key(m, i), key) &&
        !amp_compare_value(amp_map_value(m, i), value))
      return 1;
  }
  return 0;
}

canonical_original_code:
static _Bool has_entry(struct amp_map_st *m, struct amp_value_st key, struct amp_value_st value)
{
  int i;
  for (i = 0; i < m->size; i++)
  {
    if (!amp_compare_value(amp_map_key(m, i), key) &&
        !amp_compare_value(amp_map_value(m, i), value))
      return 1;
  }
  return 0;
}

variable_types:
key
struct amp_value_st

variable_types:
value
struct amp_value_st

variable_types: i int


decompiled_code:
void __fastcall amp_visit_map(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned int v3; // eax
__int64 v4; // rdx
unsigned int v5; // eax
__int64 v6; // rdx

if ( *a1 )
{
v2 = 0LL;
do
{
v3 = amp_map_key((__int64)a1, v2);
amp_visit(v3, v4, a2);
v5 = amp_map_value((__int64)a1, v2);
amp_visit(v5, v6, a2);
++v2;
}
while ( *a1 > v2 );
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned int v3; // eax
__int64 v4; // rdx
unsigned int v5; // eax
__int64 v6; // rdx

if ( *a1 )
{
v2 = 0LL;
do
{
v3 = func1((__int64)a1, v2);
amp_visit(v3, v4, a2);
v5 = func2((__int64)a1, v2);
amp_visit(v5, v6, a2);
++v2;
}
while ( *a1 > v2 );
}
}

original_code:
void amp_visit_map(amp_map_t *m, void (*visitor)(amp_value_t))
{
  for (int i = 0; i < m->size; i++)
  {
    amp_visit(amp_map_key(m, i), visitor);
    amp_visit(amp_map_value(m, i), visitor);
  }
}

canonical_original_code:
void amp_visit_map(struct amp_map_st *m, void (*visitor)(struct amp_value_st))
{
  for (int i = 0; i < m->size; i++)
  {
    amp_visit(amp_map_key(m, i), visitor);
    amp_visit(amp_map_value(m, i), visitor);
  }
}

variable_types:
visitor
void (*)(struct amp_value_st)


decompiled_code:
__int64 __fastcall amp_format_sizeof_map(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // r15
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // r12
unsigned int v6; // er13
unsigned int v7; // eax
__int64 v8; // rdx
unsigned int v9; // ebp
__int64 v10; // r12
__int64 v12; // [rsp+8h] [rbp-40h]

if ( !*a1 )
return 2LL;
v1 = 0LL;
v2 = 2LL;
do
{
v3 = amp_map_key((__int64)a1, v1);
v5 = v4;
v6 = v3;
v7 = amp_map_value((__int64)a1, v1);
v12 = v8;
v9 = v7;
v10 = amp_format_sizeof(v6, v5);
v2 += v10 + amp_format_sizeof(v9, v12) + 4;
++v1;
}
while ( *a1 > v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // r15
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // r12
unsigned int v6; // er13
unsigned int v7; // eax
__int64 v8; // rdx
unsigned int v9; // ebp
__int64 v10; // r12
__int64 v12; // [rsp+8h] [rbp-40h]

if ( !*a1 )
return 2LL;
v1 = 0LL;
v2 = 2LL;
do
{
v3 = func1((__int64)a1, v1);
v5 = v4;
v6 = v3;
v7 = func2((__int64)a1, v1);
v12 = v8;
v9 = v7;
v10 = amp_format_sizeof(v6, v5);
v2 += v10 + amp_format_sizeof(v9, v12) + 4;
++v1;
}
while ( *a1 > v1 );
return v2;
}

original_code:
size_t amp_format_sizeof_map(amp_map_t *map)
{
  size_t result = 2;
  for (int i = 0; i < map->size; i++)
  {
    amp_value_t key = amp_map_key(map, i);
    amp_value_t value = amp_map_value(map, i);
    result += amp_format_sizeof(key) + 2 + amp_format_sizeof(value) + 2;
  }
  return result;
}

canonical_original_code:
unsigned long amp_format_sizeof_map(struct amp_map_st *map)
{
  unsigned long result = 2;
  for (int i = 0; i < map->size; i++)
  {
    struct amp_value_st key = amp_map_key(map, i);
    struct amp_value_st value = amp_map_value(map, i);
    result += amp_format_sizeof(key) + 2 + amp_format_sizeof(value) + 2;
  }
  return result;
}

variable_types:
result
unsigned long

variable_types: struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_list; struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; } *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; }


decompiled_code:
__int64 __fastcall amp_format_map(__int64 a1, __int64 a2, unsigned __int64 *a3)
{
__int64 result; // rax
__int64 v5; // rdx
__int64 v6; // rdx
unsigned __int64 v7; // rbx
__int64 v8; // rdx
__int64 v9; // rdx
int v10; // [rsp+0h] [rbp-48h] BYREF
__int64 v11; // [rsp+8h] [rbp-40h]
int v12; // [rsp+10h] [rbp-38h] BYREF
__int64 v13; // [rsp+18h] [rbp-30h]

result = amp_fmt(a1, a2, &LC0);
if ( !(_DWORD)result )
{
if ( *a3 )
{
v10 = amp_map_key((__int64)a3, 0);
v11 = v5;
v12 = amp_map_value((__int64)a3, 0);
v13 = v6;
v7 = 1LL;
do
{
result = amp_format_value(a1, a2, &v10, 1LL);
if ( (_DWORD)result )
break;
result = amp_fmt(a1, a2, &LC2);
if ( (_DWORD)result )
break;
result = amp_format_value(a1, a2, &v12, 1LL);
if ( (_DWORD)result )
break;
if ( *a3 <= v7 )
goto LABEL_10;
v10 = amp_map_key((__int64)a3, v7);
v11 = v8;
v12 = amp_map_value((__int64)a3, v7);
v13 = v9;
result = amp_fmt(a1, a2, &LC1);
++v7;
}
while ( !(_DWORD)result );
}
else
{
LABEL_10:
result = amp_fmt(a1, a2, &LC3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned __int64 *a3)
{
__int64 result; // rax
__int64 v5; // rdx
__int64 v6; // rdx
unsigned __int64 v7; // rbx
__int64 v8; // rdx
__int64 v9; // rdx
int v10; // [rsp+0h] [rbp-48h] BYREF
__int64 v11; // [rsp+8h] [rbp-40h]
int v12; // [rsp+10h] [rbp-38h] BYREF
__int64 v13; // [rsp+18h] [rbp-30h]

result = amp_fmt(a1, a2, &LC0);
if ( !(_DWORD)result )
{
if ( *a3 )
{
v10 = func1((__int64)a3, 0);
v11 = v5;
v12 = func2((__int64)a3, 0);
v13 = v6;
v7 = 1LL;
do
{
result = amp_format_value(a1, a2, &v10, 1LL);
if ( (_DWORD)result )
break;
result = amp_fmt(a1, a2, &LC2);
if ( (_DWORD)result )
break;
result = amp_format_value(a1, a2, &v12, 1LL);
if ( (_DWORD)result )
break;
if ( *a3 <= v7 )
goto LABEL_10;
v10 = func1((__int64)a3, v7);
v11 = v8;
v12 = func2((__int64)a3, v7);
v13 = v9;
result = amp_fmt(a1, a2, &LC1);
++v7;
}
while ( !(_DWORD)result );
}
else
{
LABEL_10:
result = amp_fmt(a1, a2, &LC3);
}
}
return result;
}

original_code:
int amp_format_map(char **pos, char *limit, amp_map_t *map)
{
  _Bool first = 1;
  int i, e;
  if ((e = amp_fmt(pos, limit, "{"))) return e;
  for (i = 0; i < map->size; i++)
  {
    amp_value_t key = amp_map_key(map, i);
    amp_value_t value = amp_map_value(map, i);
    if (first) first = 0;
    else if ((e = amp_fmt(pos, limit, ", "))) return e;
    if ((e = amp_format_value(pos, limit, &key, 1))) return e;
    if ((e = amp_fmt(pos, limit, ": "))) return e;
    if ((e = amp_format_value(pos, limit, &value, 1))) return e;
  }
  if ((e = amp_fmt(pos, limit, "}"))) return e;
  return 0;
}

canonical_original_code:
int amp_format_map(char **pos, char *limit, struct amp_map_st *map)
{
  _Bool first = 1;
  int i; int e;
  if ((e = amp_fmt(pos, limit, "{"))) return e;
  for (i = 0; i < map->size; i++)
  {
    struct amp_value_st key = amp_map_key(map, i);
    struct amp_value_st value = amp_map_value(map, i);
    if (first) first = 0;
    else if ((e = amp_fmt(pos, limit, ", "))) return e;
    if ((e = amp_format_value(pos, limit, &key, 1))) return e;
    if ((e = amp_fmt(pos, limit, ": "))) return e;
    if ((e = amp_format_value(pos, limit, &value, 1))) return e;
  }
  if ((e = amp_fmt(pos, limit, "}"))) return e;
  return 0;
}

variable_types:
pos
char **

variable_types:
limit
char *

variable_types: e int


decompiled_code:
unsigned __int64 __fastcall amp_hash_map(unsigned __int64 *a1)
{
unsigned __int64 v1; // r13
unsigned __int64 v2; // rbp
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // rbx
unsigned int v6; // eax
__int64 v7; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = 0LL;
v1 = 0LL;
do
{
v3 = amp_map_key((__int64)a1, v2);
v5 = amp_hash_value(v3, v4);
v6 = amp_map_value((__int64)a1, v2);
v1 += amp_hash_value(v6, v7) ^ v5;
++v2;
}
while ( *a1 > v2 );
}
return v1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(unsigned __int64 *a1)
{
unsigned __int64 v1; // r13
unsigned __int64 v2; // rbp
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // rbx
unsigned int v6; // eax
__int64 v7; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = 0LL;
v1 = 0LL;
do
{
v3 = func1((__int64)a1, v2);
v5 = amp_hash_value(v3, v4);
v6 = func2((__int64)a1, v2);
v1 += amp_hash_value(v6, v7) ^ v5;
++v2;
}
while ( *a1 > v2 );
}
return v1;
}

original_code:
uintptr_t amp_hash_map(amp_map_t *map)
{
  uintptr_t hash = 0;
  int i;
  for (i = 0; i < map->size; i++)
  {
    hash += (amp_hash_value(amp_map_key(map, i)) ^
             amp_hash_value(amp_map_value(map, i)));
  }
  return hash;
}

canonical_original_code:
unsigned long amp_hash_map(struct amp_map_st *map)
{
  unsigned long hash = 0;
  int i;
  for (i = 0; i < map->size; i++)
  {
    hash += (amp_hash_value(amp_map_key(map, i)) ^
             amp_hash_value(amp_map_value(map, i)));
  }
  return hash;
}

variable_types:
hash
unsigned long


decompiled_code:
__int64 __fastcall amp_compare_map(unsigned __int64 *a1, unsigned __int64 *a2)
{
__int64 v2; // rbx
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // r12
unsigned int v6; // er13
unsigned int v7; // eax
__int64 v8; // rdx
__int64 v9; // rbx
unsigned int v10; // eax
__int64 v11; // rdx
__int64 v12; // r12
unsigned int v13; // er13
unsigned int v14; // eax
__int64 v15; // rdx
unsigned int v16; // ecx

if ( *a1 != *a2 )
return (unsigned int)*a2 - (unsigned int)*a1;
v2 = 0LL;
if ( *a1 )
{
while ( 1 )
{
v3 = amp_map_value((__int64)a1, v2);
v5 = v4;
v6 = v3;
v7 = amp_map_key((__int64)a1, v2);
if ( !(unsigned __int8)has_entry(a2, v7, v8, v6, v5) )
break;
if ( *a1 <= ++v2 )
goto LABEL_5;
}
v16 = -1;
}
else
{
LABEL_5:
if ( *a2 )
{
v9 = 0LL;
while ( 1 )
{
v10 = amp_map_value((__int64)a2, v9);
v12 = v11;
v13 = v10;
v14 = amp_map_key((__int64)a2, v9);
if ( !(unsigned __int8)has_entry(a1, v14, v15, v13, v12) )
break;
if ( *a2 <= ++v9 )
return 0;
}
v16 = -1;
}
else
{
v16 = 0;
}
}
return v16;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 *a1, unsigned __int64 *a2)
{
__int64 v2; // rbx
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // r12
unsigned int v6; // er13
unsigned int v7; // eax
__int64 v8; // rdx
__int64 v9; // rbx
unsigned int v10; // eax
__int64 v11; // rdx
__int64 v12; // r12
unsigned int v13; // er13
unsigned int v14; // eax
__int64 v15; // rdx
unsigned int v16; // ecx

if ( *a1 != *a2 )
return (unsigned int)*a2 - (unsigned int)*a1;
v2 = 0LL;
if ( *a1 )
{
while ( 1 )
{
v3 = func2((__int64)a1, v2);
v5 = v4;
v6 = v3;
v7 = func1((__int64)a1, v2);
if ( !(unsigned __int8)func3(a2, v7, v8, v6, v5) )
break;
if ( *a1 <= ++v2 )
goto LABEL_5;
}
v16 = -1;
}
else
{
LABEL_5:
if ( *a2 )
{
v9 = 0LL;
while ( 1 )
{
v10 = func2((__int64)a2, v9);
v12 = v11;
v13 = v10;
v14 = func1((__int64)a2, v9);
if ( !(unsigned __int8)func3(a1, v14, v15, v13, v12) )
break;
if ( *a2 <= ++v9 )
return 0;
}
v16 = -1;
}
else
{
v16 = 0;
}
}
return v16;
}

original_code:
int amp_compare_map(amp_map_t *a, amp_map_t *b)
{
  int i;
  if (a->size != b->size)
    return b->size - a->size;
  for (i = 0; i < a->size; i++)
    if (!has_entry(b, amp_map_key(a, i), amp_map_value(a, i)))
      return -1;
  for (i = 0; i < b->size; i++)
    if (!has_entry(a, amp_map_key(b, i), amp_map_value(b, i)))
      return -1;
  return 0;
}

canonical_original_code:
int amp_compare_map(struct amp_map_st *a, struct amp_map_st *b)
{
  int i;
  if (a->size != b->size)
    return b->size - a->size;
  for (i = 0; i < a->size; i++)
    if (!has_entry(b, amp_map_key(a, i), amp_map_value(a, i)))
      return -1;
  for (i = 0; i < b->size; i++)
    if (!has_entry(a, amp_map_key(b, i), amp_map_value(b, i)))
      return -1;
  return 0;
}

variable_types:
b
struct amp_map_st *


decompiled_code:
__int64 __fastcall amp_map_has(_QWORD *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbx
unsigned int v5; // eax
__int64 v6; // rdx

if ( !*a1 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = amp_map_key((__int64)a1, v4);
if ( !(unsigned int)amp_compare_value(a2, a3, v5, v6) )
break;
if ( *a1 <= (unsigned __int64)++v4 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbx
unsigned int v5; // eax
__int64 v6; // rdx

if ( !*a1 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = func1((__int64)a1, v4);
if ( !(unsigned int)amp_compare_value(a2, a3, v5, v6) )
break;
if ( *a1 <= (unsigned __int64)++v4 )
return 0LL;
}
return 1LL;
}

original_code:
_Bool amp_map_has(amp_map_t *map, amp_value_t key)
{
  for (int i = 0; i < map->size; i++)
  {
    if (!amp_compare_value(key, amp_map_key(map, i)))
      return 1;
  }
  return 0;
}

canonical_original_code:
_Bool amp_map_has(struct amp_map_st *map, struct amp_value_st key)
{
  for (int i = 0; i < map->size; i++)
  {
    if (!amp_compare_value(key, amp_map_key(map, i)))
      return 1;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall amp_map_get(_QWORD *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbx
unsigned int v5; // eax
__int64 v6; // rdx

if ( !*a1 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = amp_map_key((__int64)a1, v4);
if ( !(unsigned int)amp_compare_value(a2, a3, v5, v6) )
break;
if ( *a1 <= (unsigned __int64)++v4 )
return 0LL;
}
return amp_map_value((__int64)a1, v4);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbx
unsigned int v5; // eax
__int64 v6; // rdx

if ( !*a1 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = func1((__int64)a1, v4);
if ( !(unsigned int)amp_compare_value(a2, a3, v5, v6) )
break;
if ( *a1 <= (unsigned __int64)++v4 )
return 0LL;
}
return func2((__int64)a1, v4);
}

original_code:
amp_value_t amp_map_get(amp_map_t *map, amp_value_t key)
{
  for (int i = 0; i < map->size; i++)
  {
    if (!amp_compare_value(key, amp_map_key(map, i)))
      return amp_map_value(map, i);
  }
  return ((amp_value_t) {.type = EMPTY});
}

canonical_original_code:
struct amp_value_st amp_map_get(struct amp_map_st *map, struct amp_value_st key)
{
  for (int i = 0; i < map->size; i++)
  {
    if (!amp_compare_value(key, amp_map_key(map, i)))
      return amp_map_value(map, i);
  }
  return ((struct amp_value_st) {.type = EMPTY});
}


decompiled_code:
__int64 __fastcall amp_map_set(unsigned __int64 *a1, unsigned __int64 a2, unsigned __int64 a3, unsigned __int64 a4, unsigned __int64 a5)
{
unsigned __int64 v7; // rax
__int64 v8; // rbx
unsigned int v9; // eax
__int64 v10; // rdx
__int64 result; // rax
unsigned __int64 *v12; // rdx
unsigned __int64 *v13; // rbp

v7 = *a1;
if ( *a1 )
{
v8 = 0LL;
while ( 1 )
{
v9 = amp_map_key((__int64)a1, v8);
result = amp_compare_value((unsigned int)a2, a3, v9, v10);
if ( !(_DWORD)result )
break;
v7 = *a1;
if ( *a1 <= ++v8 )
goto LABEL_5;
}
v13 = &a1[4 * (int)v8 + 4];
*v13 = a4;
v13[1] = a5;
}
else
{
LABEL_5:
if ( a1[1] <= v7 )
{
result = 0xFFFFFFFFLL;
}
else
{
v12 = &a1[4 * v7];
v12[2] = a2;
v12[3] = a3;
v12[4] = a4;
v12[5] = a5;
*a1 = v7 + 1;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int64 *a1, unsigned __int64 a2, unsigned __int64 a3, unsigned __int64 a4, unsigned __int64 a5)
{
unsigned __int64 v7; // rax
__int64 v8; // rbx
unsigned int v9; // eax
__int64 v10; // rdx
__int64 result; // rax
unsigned __int64 *v12; // rdx
unsigned __int64 *v13; // rbp

v7 = *a1;
if ( *a1 )
{
v8 = 0LL;
while ( 1 )
{
v9 = func1((__int64)a1, v8);
result = amp_compare_value((unsigned int)a2, a3, v9, v10);
if ( !(_DWORD)result )
break;
v7 = *a1;
if ( *a1 <= ++v8 )
goto LABEL_5;
}
v13 = &a1[4 * (int)v8 + 4];
*v13 = a4;
v13[1] = a5;
}
else
{
LABEL_5:
if ( a1[1] <= v7 )
{
result = 0xFFFFFFFFLL;
}
else
{
v12 = &a1[4 * v7];
v12[2] = a2;
v12[3] = a3;
v12[4] = a4;
v12[5] = a5;
*a1 = v7 + 1;
result = 0LL;
}
}
return result;
}

original_code:
int amp_map_set(amp_map_t *map, amp_value_t key, amp_value_t value)
{
  for (int i = 0; i < map->size; i++)
  {
    if (!amp_compare_value(key, amp_map_key(map, i)))
    {
      map->pairs[2*i + 1] = value;
      return 0;
    }
  }
  if (map->size < map->capacity)
  {
    map->pairs[2*map->size] = key;
    map->pairs[2*map->size+1] = value;
    map->size++;
    return 0;
  }
  else
  {
    return -1;
  }
}

canonical_original_code:
int amp_map_set(struct amp_map_st *map, struct amp_value_st key, struct amp_value_st value)
{
  for (int i = 0; i < map->size; i++)
  {
    if (!amp_compare_value(key, amp_map_key(map, i)))
    {
      map->pairs[2*i + 1] = value;
      return 0;
    }
  }
  if (map->size < map->capacity)
  {
    map->pairs[2*map->size] = key;
    map->pairs[2*map->size+1] = value;
    map->size++;
    return 0;
  }
  else
  {
    return -1;
  }
}


decompiled_code:
__int64 __fastcall amp_map_pop(_QWORD *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbx
unsigned int v5; // eax
__int64 v6; // rdx
__int64 v8; // r13

if ( !*a1 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = amp_map_key((__int64)a1, v4);
if ( !(unsigned int)amp_compare_value(a2, a3, v5, v6) )
break;
if ( *a1 <= (unsigned __int64)++v4 )
return 0LL;
}
v8 = amp_map_value((__int64)a1, v4);
memmove(&a1[4 * (int)v4 + 2], &a1[4 * (int)v4 + 6], 32 * (*a1 + ~v4));
--*a1;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbx
unsigned int v5; // eax
__int64 v6; // rdx
__int64 v8; // r13

if ( !*a1 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = func1((__int64)a1, v4);
if ( !(unsigned int)amp_compare_value(a2, a3, v5, v6) )
break;
if ( *a1 <= (unsigned __int64)++v4 )
return 0LL;
}
v8 = func2((__int64)a1, v4);
memmove(&a1[4 * (int)v4 + 2], &a1[4 * (int)v4 + 6], 32 * (*a1 + ~v4));
--*a1;
return v8;
}

original_code:
amp_value_t amp_map_pop(amp_map_t *map, amp_value_t key)
{
  for (int i = 0; i < map->size; i++)
  {
    if (!amp_compare_value(key, amp_map_key(map, i)))
    {
      amp_value_t result = amp_map_value(map, i);
      memmove(&map->pairs[2*i], &map->pairs[2*(i+1)],
              (map->size - i - 1)*2*sizeof(amp_value_t));
      map->size--;
      return result;
    }
  }
  return ((amp_value_t) {.type = EMPTY});
}

canonical_original_code:
struct amp_value_st amp_map_pop(struct amp_map_st *map, struct amp_value_st key)
{
  for (int i = 0; i < map->size; i++)
  {
    if (!amp_compare_value(key, amp_map_key(map, i)))
    {
      struct amp_value_st result = amp_map_value(map, i);
      memmove(&map->pairs[2*i], &map->pairs[2*(i+1)],
              (map->size - i - 1)*2*sizeof(amp_value_t));
      map->size--;
      return result;
    }
  }
  return ((struct amp_value_st) {.type = EMPTY});
}


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

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

original_code:
int amp_map_size(amp_map_t *map)
{
  return map->size;
}

canonical_original_code:
int amp_map_size(struct amp_map_st *map)
{
  return map->size;
}


decompiled_code:
__int64 __fastcall amp_map_capacity(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
int amp_map_capacity(amp_map_t *map)
{
  return map->capacity;
}

canonical_original_code:
int amp_map_capacity(struct amp_map_st *map)
{
  return map->capacity;
}


decompiled_code:
__int64 __fastcall amp_encode_sizeof_map(_QWORD *a1)
{
__int64 v1; // rbp
unsigned __int64 v2; // rbx

v1 = 2LL * *a1;
if ( v1 )
{
v2 = 0LL;
v1 = 0LL;
do
{
v1 += amp_encode_sizeof(LODWORD(a1[2 * (int)v2 + 2]), a1[2 * (int)v2 + 3]);
++v2;
}
while ( 2LL * *a1 > v2 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func15(_QWORD *a1)
{
__int64 v1; // rbp
unsigned __int64 v2; // rbx

v1 = 2LL * *a1;
if ( v1 )
{
v2 = 0LL;
v1 = 0LL;
do
{
v1 += amp_encode_sizeof(LODWORD(a1[2 * (int)v2 + 2]), a1[2 * (int)v2 + 3]);
++v2;
}
while ( 2LL * *a1 > v2 );
}
return v1;
}

original_code:
size_t amp_encode_sizeof_map(amp_map_t *m)
{
  size_t result = 0;
  for (int i = 0; i < 2*m->size; i++)
  {
    result += amp_encode_sizeof(m->pairs[i]);
  }
  return result;
}

canonical_original_code:
unsigned long amp_encode_sizeof_map(struct amp_map_st *m)
{
  unsigned long result = 0;
  for (int i = 0; i < 2*m->size; i++)
  {
    result += amp_encode_sizeof(m->pairs[i]);
  }
  return result;
}


original_code:
size_t amp_encode_map(amp_map_t *m, char *out)
{
  char *old = out;
  char *start;
  int count = 2*m->size;
  amp_write_start(&out, out + 1024, &start);
  for (int i = 0; i < count; i++)
  {
    out += amp_encode(m->pairs[i], out);
  }
  amp_write_map(&out, out + 1024, start, m->size);
  return out - old;
}

canonical_original_code:
unsigned long amp_encode_map(struct amp_map_st *m, char *out)
{
  char *old = out;
  char *start;
  int count = 2*m->size;
  amp_write_start(&out, out + 1024, &start);
  for (int i = 0; i < count; i++)
  {
    out += amp_encode(m->pairs[i], out);
  }
  amp_write_map(&out, out + 1024, start, m->size);
  return out - old;
}

variable_types:
out
char *

variable_types:
old
char *

variable_types:
start
char *

variable_types: count int


decompiled_code:
void __fastcall amp_free_string(void *a1)
{
free(a1);
}

original_code:
void amp_free_string(amp_string_t *str)
{
  free(str);
}

canonical_original_code:
void amp_free_string(struct amp_string_st *str)
{
  free(str);
}

variable_types: struct amp_string_st { unsigned long size; int wcs[]; } *


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

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

original_code:
size_t amp_string_size(amp_string_t *str)
{
  return str->size;
}

canonical_original_code:
unsigned long amp_string_size(struct amp_string_st *str)
{
  return str->size;
}


decompiled_code:
__int64 __fastcall amp_string_wcs(__int64 a1)
{
return a1 + 8;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return a1 + 8;
}

original_code:
wchar_t *amp_string_wcs(amp_string_t *str)
{
  return str->wcs;
}

canonical_original_code:
int *amp_string_wcs(struct amp_string_st *str)
{
  return str->wcs;
}

return_type: int *


decompiled_code:
__int64 __fastcall amp_hash_string(__int64 a1)
{
_DWORD *v1; // rsi
int v2; // eax
__int64 v3; // rcx

v1 = (_DWORD *)(a1 + 8);
v2 = *(_DWORD *)(a1 + 8);
if ( !v2 )
return 1LL;
v3 = 1LL;
do
{
v3 = v2 + 31 * v3;
v2 = *++v1;
}
while ( *v1 );
return v3;
}

original_code:
uintptr_t amp_hash_string(amp_string_t *s)
{
  wchar_t *c;
  uintptr_t hash = 1;
  for (c = s->wcs; *c; c++)
  {
    hash = 31*hash + *c;
  }
  return hash;
}

canonical_original_code:
unsigned long amp_hash_string(struct amp_string_st *s)
{
  int *c;
  unsigned long hash = 1;
  for (c = s->wcs; *c; c++)
  {
    hash = 31*hash + *c;
  }
  return hash;
}

variable_types:
c
int *


decompiled_code:
int __fastcall amp_compare_string(__int64 a1, __int64 a2)
{
int result; // eax

result = *(_QWORD *)a2 - *(_QWORD *)a1;
if ( *(_QWORD *)a1 == *(_QWORD *)a2 )
result = wmemcmp((const wchar_t *)(a1 + 8), (const wchar_t *)(a2 + 8), *(_QWORD *)a1);
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2)
{
int result; // eax

result = *(_QWORD *)a2 - *(_QWORD *)a1;
if ( *(_QWORD *)a1 == *(_QWORD *)a2 )
result = wmemcmp((const wchar_t *)(a1 + 8), (const wchar_t *)(a2 + 8), *(_QWORD *)a1);
return result;
}

original_code:
int amp_compare_string(amp_string_t *a, amp_string_t *b)
{
  if (a->size == b->size)
    return wmemcmp(a->wcs, b->wcs, a->size);
  else
    return b->size - a->size;
}

canonical_original_code:
int amp_compare_string(struct amp_string_st *a, struct amp_string_st *b)
{
  if (a->size == b->size)
    return wmemcmp(a->wcs, b->wcs, a->size);
  else
    return b->size - a->size;
}

variable_types:
b
struct amp_string_st *


min

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
static int min(int a, int b)
{
  if (a < b)
    return a;
  else
    return b;
}

variable_types: a int

variable_types: b int


decompiled_code:
void __fastcall amp_free_list(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
void amp_free_list(amp_list_t *l)
{
  free(l);
}

canonical_original_code:
void amp_free_list(struct amp_list_st *l)
{
  free(l);
}

variable_types: struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st *as_list; struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; } *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; } values[]; } *


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

if ( *a1 )
{
v2 = 0LL;
do
{
result = amp_visit(LODWORD(a1[2 * (int)v2 + 2]), a1[2 * (int)v2 + 3], a2);
++v2;
}
while ( *a1 > v2 );
}
return result;
}

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

if ( *a1 )
{
v2 = 0LL;
do
{
result = amp_visit(LODWORD(a1[2 * (int)v2 + 2]), a1[2 * (int)v2 + 3], a2);
++v2;
}
while ( *a1 > v2 );
}
return result;
}

original_code:
void amp_visit_list(amp_list_t *l, void (*visitor)(amp_value_t))
{
  for (int i = 0; i < l->size; i++)
  {
    amp_visit(l->values[i], visitor);
  }
}

canonical_original_code:
void amp_visit_list(struct amp_list_st *l, void (*visitor)(struct amp_value_st))
{
  for (int i = 0; i < l->size; i++)
  {
    amp_visit(l->values[i], visitor);
  }
}

variable_types:
visitor
void (*)(struct amp_value_st)

variable_types: i int


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

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

original_code:
int amp_list_size(amp_list_t *l)
{
  return l->size;
}

canonical_original_code:
int amp_list_size(struct amp_list_st *l)
{
  return l->size;
}


decompiled_code:
__int64 __fastcall amp_list_get(_QWORD *a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( (unsigned __int64)a2 < *a1 )
result = a1[2 * a2 + 2];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( (unsigned __int64)a2 < *a1 )
result = a1[2 * a2 + 2];
return result;
}

original_code:
amp_value_t amp_list_get(amp_list_t *l, int index)
{
  if (index < l->size)
    return l->values[index];
  else
    return ((amp_value_t) {.type = EMPTY});
}

canonical_original_code:
struct amp_value_st amp_list_get(struct amp_list_st *l, int index)
{
  if (index < l->size)
    return l->values[index];
  else
    return ((struct amp_value_st) {.type = EMPTY});
}

variable_types:
l
struct amp_list_st *

variable_types: index int


decompiled_code:
__int64 __fastcall amp_list_set(__int64 a1, int a2, unsigned int a3, __int64 a4)
{
__int64 *v4; // rsi
__int64 result; // rax

v4 = (__int64 *)(a1 + 16 * (a2 + 1LL));
result = *v4;
*v4 = a3;
v4[1] = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, unsigned int a3, __int64 a4)
{
__int64 *v4; // rsi
__int64 result; // rax

v4 = (__int64 *)(a1 + 16 * (a2 + 1LL));
result = *v4;
*v4 = a3;
v4[1] = a4;
return result;
}

original_code:
amp_value_t amp_list_set(amp_list_t *l, int index, amp_value_t v)
{
  amp_value_t r = l->values[index];
  l->values[index] = v;
  return r;
}

canonical_original_code:
struct amp_value_st amp_list_set(struct amp_list_st *l, int index, struct amp_value_st v)
{
  struct amp_value_st r = l->values[index];
  l->values[index] = v;
  return r;
}

variable_types:
v
struct amp_value_st

variable_types: struct amp_value_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; union { _Bool as_boolean; unsigned char as_ubyte; unsigned short as_ushort; unsigned int as_uint; unsigned long as_ulong; char as_byte; short as_short; int as_int; long as_long; float as_float; double as_double; int as_char; struct amp_string_st { unsigned long size; int wcs[]; } *as_string; struct amp_binary_st { unsigned long size; char bytes[]; } *as_binary; struct amp_array_st { enum TYPE { EMPTY=0, BOOLEAN=1, UBYTE=2, USHORT=3, UINT=4, ULONG=5, BYTE=6, SHORT=7, INT=8, LONG=9, FLOAT=10, DOUBLE=11, CHAR=12, STRING=13, BINARY=14, ARRAY=15, LIST=16, MAP=17, TAG=18, REF=19 } type; unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_array; struct amp_list_st { unsigned long size; unsigned long capacity; struct amp_value_st values[]; } *as_list; struct amp_map_st { unsigned long size; unsigned long capacity; struct amp_value_st pairs[]; } *as_map; struct amp_tag_st { struct amp_value_st descriptor; struct amp_value_st value; } *as_tag; void *as_ref; } u; }


original_code:
amp_value_t amp_list_pop(amp_list_t *l, int index)
{
  int i, n = l->size;
  amp_value_t v = l->values[index];
  for (i = index; i < n - 1; i++)
    l->values[i] = l->values[i+1];
  l->size--;
  return v;
}

canonical_original_code:
struct amp_value_st amp_list_pop(struct amp_list_st *l, int index)
{
  int i; int n = l->size;
  struct amp_value_st v = l->values[index];
  for (i = index; i < n - 1; i++)
    l->values[i] = l->values[i+1];
  l->size--;
  return v;
}

variable_types: n int


decompiled_code:
__int64 __fastcall amp_list_add(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
__int64 *v4; // rdi
__int64 result; // rax

if ( a1[1] <= (unsigned __int64)*a1 )
{
fwrite("wah!\n", 1uLL, 5uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v3 = *a1 + 1;
*a1 = v3;
v4 = &a1[2 * v3];
*v4 = a2;
v4[1] = a3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
__int64 *v4; // rdi
__int64 result; // rax

if ( a1[1] <= (unsigned __int64)*a1 )
{
fwrite("wah!\n", 1uLL, 5uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v3 = *a1 + 1;
*a1 = v3;
v4 = &a1[2 * v3];
*v4 = a2;
v4[1] = a3;
result = 0LL;
}
return result;
}

original_code:
int amp_list_add(amp_list_t *l, amp_value_t v)
{
  if (l->capacity <= l->size) {
    fprintf(stderr, "wah!\n");
    return -1;
  }
  l->values[l->size++] = v;
  return 0;
}

canonical_original_code:
int amp_list_add(struct amp_list_st *l, struct amp_value_st v)
{
  if (l->capacity <= l->size) {
    fprintf(stderr, "wah!\n");
    return -1;
  }
  l->values[l->size++] = v;
  return 0;
}


decompiled_code:
__int64 amp_list_extend(_QWORD *a1, __int64 a2, ...)
{
__int64 result; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
result = amp_vscan(&a1[2 * *a1 + 2], a2, va);
if ( (int)result > 0 )
*a1 += (int)result;
return result;
}

canonical_decompiled_code:
__int64 func8(_QWORD *a1, __int64 a2, ...)
{
__int64 result; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
result = amp_vscan(&a1[2 * *a1 + 2], a2, va);
if ( (int)result > 0 )
*a1 += (int)result;
return result;
}

original_code:
int amp_list_extend(amp_list_t *l, const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  int n = amp_vscan(l->values + l->size, fmt, ap);
  __builtin_va_end(ap);
  if (n > 0) l->size += n;
  return n;
}

canonical_original_code:
int amp_list_extend(struct amp_list_st *l, char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  int n = amp_vscan(l->values + l->size, fmt, ap);
  __builtin_va_end(ap);
  if (n > 0) l->size += n;
  return n;
}

variable_types:
fmt
char *


decompiled_code:
__int64 __fastcall amp_list_index(_QWORD *a1, unsigned int a2, __int64 a3)
{
int v4; // er14
int v5; // ebx

if ( (int)*a1 <= 0 )
{
v5 = -1;
}
else
{
v4 = *a1;
v5 = 0;
while ( (unsigned int)amp_compare_value(a2, a3, LODWORD(a1[2 * v5 + 2]), a1[2 * v5 + 3]) )
{
if ( v4 == ++v5 )
return (unsigned int)-1;
}
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, unsigned int a2, __int64 a3)
{
int v4; // er14
int v5; // ebx

if ( (int)*a1 <= 0 )
{
v5 = -1;
}
else
{
v4 = *a1;
v5 = 0;
while ( (unsigned int)amp_compare_value(a2, a3, LODWORD(a1[2 * v5 + 2]), a1[2 * v5 + 3]) )
{
if ( v4 == ++v5 )
return (unsigned int)-1;
}
}
return (unsigned int)v5;
}

original_code:
int amp_list_index(amp_list_t *l, amp_value_t v)
{
  int i, n = l->size;
  for (i = 0; i < n; i++)
    if (amp_compare_value(v, l->values[i]) == 0)
      return i;
  return -1;
}

canonical_original_code:
int amp_list_index(struct amp_list_st *l, struct amp_value_st v)
{
  int i; int n = l->size;
  for (i = 0; i < n; i++)
    if (amp_compare_value(v, l->values[i]) == 0)
      return i;
  return -1;
}


decompiled_code:
__int64 __fastcall amp_list_remove(__int64 *a1, unsigned int a2, __int64 a3)
{
signed int v3; // esi
__int64 result; // rax

v3 = amp_list_index(a1, a2, a3);
result = 0LL;
if ( v3 >= 0 )
{
amp_list_pop(a1, v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1, unsigned int a2, __int64 a3)
{
signed int v3; // esi
__int64 result; // rax

v3 = func9(a1, a2, a3);
result = 0LL;
if ( v3 >= 0 )
{
func6(a1, v3);
result = 1LL;
}
return result;
}

original_code:
_Bool amp_list_remove(amp_list_t *l, amp_value_t v)
{
  int i = amp_list_index(l, v);
  if (i >= 0) {
    amp_list_pop(l, i);
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
_Bool amp_list_remove(struct amp_list_st *l, struct amp_value_st v)
{
  int i = amp_list_index(l, v);
  if (i >= 0) {
    amp_list_pop(l, i);
    return 1;
  } else {
    return 0;
  }
}


decompiled_code:
__int64 __fastcall amp_list_fill(__int64 *a1, unsigned int a2, __int64 a3, int a4)
{
int i; // ebx
__int64 result; // rax

if ( a4 <= 0 )
return 0LL;
for ( i = 0; i != a4; ++i )
{
result = amp_list_add(a1, a2, a3);
if ( (_DWORD)result )
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, unsigned int a2, __int64 a3, int a4)
{
int i; // ebx
__int64 result; // rax

if ( a4 <= 0 )
return 0LL;
for ( i = 0; i != a4; ++i )
{
result = func7(a1, a2, a3);
if ( (_DWORD)result )
break;
}
return result;
}

original_code:
int amp_list_fill(amp_list_t *l, amp_value_t v, int n)
{
  int i, e;
  for (i = 0; i < n; i++)
    if ((e = amp_list_add(l, v))) return e;
  return 0;
}

canonical_original_code:
int amp_list_fill(struct amp_list_st *l, struct amp_value_st v, int n)
{
  int i; int e;
  for (i = 0; i < n; i++)
    if ((e = amp_list_add(l, v))) return e;
  return 0;
}

variable_types: e int


decompiled_code:
__int64 __fastcall amp_format_sizeof_list(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // r12

if ( !*a1 )
return 2LL;
v1 = 0LL;
v2 = 2LL;
do
{
v2 += amp_format_sizeof(LODWORD(a1[2 * (int)v1 + 2]), a1[2 * (int)v1 + 3]) + 2;
++v1;
}
while ( *a1 > v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // r12

if ( !*a1 )
return 2LL;
v1 = 0LL;
v2 = 2LL;
do
{
v2 += amp_format_sizeof(LODWORD(a1[2 * (int)v1 + 2]), a1[2 * (int)v1 + 3]) + 2;
++v1;
}
while ( *a1 > v1 );
return v2;
}

original_code:
size_t amp_format_sizeof_list(amp_list_t *list)
{
  size_t result = 2;
  for (int i = 0; i < list->size; i++) {
    result += amp_format_sizeof(list->values[i]) + 2;
  }
  return result;
}

canonical_original_code:
unsigned long amp_format_sizeof_list(struct amp_list_st *list)
{
  unsigned long result = 2;
  for (int i = 0; i < list->size; i++) {
    result += amp_format_sizeof(list->values[i]) + 2;
  }
  return result;
}

variable_types:
result
unsigned long


decompiled_code:
__int64 __fastcall amp_format_list(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax

result = amp_fmt(a1, a2, "[");
if ( !(_DWORD)result )
{
result = amp_format_value(a1, a2, a3 + 2, *a3);
if ( !(_DWORD)result )
result = amp_fmt(a1, a2, "]");
}
return result;
}

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

result = amp_fmt(a1, a2, "[");
if ( !(_DWORD)result )
{
result = amp_format_value(a1, a2, a3 + 2, *a3);
if ( !(_DWORD)result )
result = amp_fmt(a1, a2, "]");
}
return result;
}

original_code:
int amp_format_list(char **pos, char *limit, amp_list_t *list)
{
  int e;
  if ((e = amp_fmt(pos, limit, "["))) return e;
  if ((e = amp_format_value(pos, limit, list->values, list->size))) return e;
  if ((e = amp_fmt(pos, limit, "]"))) return e;
  return 0;
}

canonical_original_code:
int amp_format_list(char **pos, char *limit, struct amp_list_st *list)
{
  int e;
  if ((e = amp_fmt(pos, limit, "["))) return e;
  if ((e = amp_format_value(pos, limit, list->values, list->size))) return e;
  if ((e = amp_fmt(pos, limit, "]"))) return e;
  return 0;
}

variable_types:
pos
char **

variable_types:
limit
char *


decompiled_code:
__int64 __fastcall amp_hash_list(_QWORD *a1)
{
int v1; // er13
__int64 result; // rax
int v3; // ebx
__int64 v4; // rbp
unsigned int v5; // eax
__int64 v6; // rdx

if ( (int)*a1 <= 0 )
return 1LL;
v1 = *a1;
result = 1LL;
v3 = 0;
do
{
v4 = 31 * result;
v5 = amp_list_get(a1, v3);
result = v4 + amp_hash_value(v5, v6);
++v3;
}
while ( v1 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(_QWORD *a1)
{
int v1; // er13
__int64 result; // rax
int v3; // ebx
__int64 v4; // rbp
unsigned int v5; // eax
__int64 v6; // rdx

if ( (int)*a1 <= 0 )
return 1LL;
v1 = *a1;
result = 1LL;
v3 = 0;
do
{
v4 = 31 * result;
v5 = func4(a1, v3);
result = v4 + amp_hash_value(v5, v6);
++v3;
}
while ( v1 != v3 );
return result;
}

original_code:
uintptr_t amp_hash_list(amp_list_t *list)
{
  int i, n = list->size;
  uintptr_t hash = 1;
  for (i = 0; i < n; i++)
  {
    hash = 31*hash + amp_hash_value(amp_list_get(list, i));
  }
  return hash;
}

canonical_original_code:
unsigned long amp_hash_list(struct amp_list_st *list)
{
  int i; int n = list->size;
  unsigned long hash = 1;
  for (i = 0; i < n; i++)
  {
    hash = 31*hash + amp_hash_value(amp_list_get(list, i));
  }
  return hash;
}

variable_types:
hash
unsigned long


decompiled_code:
__int64 __fastcall amp_compare_list(unsigned int *a1, unsigned int *a2)
{
int v2; // eax
int v3; // er15
int i; // ebx
unsigned int v5; // eax
__int64 v6; // rdx
__int64 v7; // rbp
unsigned int v8; // er12
__int64 v9; // rax
__int64 v10; // rdx

v2 = min(*a1, *a2);
if ( v2 > 0 )
{
v3 = v2;
for ( i = 0; i != v3; ++i )
{
v5 = amp_list_get(a2, i);
v7 = v6;
v8 = v5;
v9 = amp_list_get(a1, i);
if ( !(unsigned int)amp_compare_value(v9, v10, v8, v7) )
break;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int *a1, unsigned int *a2)
{
int v2; // eax
int v3; // er15
int i; // ebx
unsigned int v5; // eax
__int64 v6; // rdx
__int64 v7; // rbp
unsigned int v8; // er12
__int64 v9; // rax
__int64 v10; // rdx

v2 = func0(*a1, *a2);
if ( v2 > 0 )
{
v3 = v2;
for ( i = 0; i != v3; ++i )
{
v5 = func4(a2, i);
v7 = v6;
v8 = v5;
v9 = func4(a1, i);
if ( !(unsigned int)amp_compare_value(v9, v10, v8, v7) )
break;
}
}
return 0LL;
}

original_code:
int amp_compare_list(amp_list_t *a, amp_list_t *b)
{
  int i, n = min(a->size, b->size);
  int c;
  for (i = 0; i < n; i++)
  {
    c = amp_compare_value(amp_list_get(a, i), amp_list_get(b, i));
    if (!c)
      return c;
  }
  return 0;
}

canonical_original_code:
int amp_compare_list(struct amp_list_st *a, struct amp_list_st *b)
{
  int i; int n = min(a->size, b->size);
  int c;
  for (i = 0; i < n; i++)
  {
    c = amp_compare_value(amp_list_get(a, i), amp_list_get(b, i));
    if (!c)
      return c;
  }
  return 0;
}

variable_types:
b
struct amp_list_st *

variable_types: c int