// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Engine/Quantize.c
// Function: QuantizeBitmap
int QuantizeBitmap(const Bitmap *bitmap, uint8_t *output, Palette palette, const Bitmap* orig) {
    uint32_t *colourarray=calloc(256*256*256*4,1);
    uint32_t *colourarrayorig=calloc(256*256*256*4,1);
    uint32_t *colourcount=calloc(256*256*256*sizeof(int),1);
    uint32_t *colourindices=calloc(256*256*256*sizeof(int),1);
    Pixel* colourlist=(Pixel*)calloc(256*256*256*sizeof(Pixel),1);
    int numcolours=0;
    
    Pixel brightest = RGB(0, 0, 0);
    Pixel darkest = RGB(255, 255, 255);

    int palcount = 0;
    for(int y=0;y<orig->height;y++)
    for(int x=0;x<orig->width;x++)
    {
        Pixel p=ReadPixelNoClip(orig,x,y);
        int index=PixelToIndex(p);
        if(colourarrayorig[index] == 0) {
            palette[palcount] = p;
            palcount += 1;
        }
        colourarrayorig[index]++;
    }

    int palInitialSize = palcount;
    if(palcount > 150) {
        palInitialSize = 0;
    }
    for(int y=0;y<bitmap->height;y++)
    for(int x=0;x<bitmap->width;x++)
    {
        Pixel p=ReadPixelNoClip(bitmap,x,y);
        int index=PixelToIndex(p);
        colourcount[index]++;
        if(colourarray[index]==0) {
            colourlist[numcolours] = p;
            colourindices[numcolours] = index + 1;
            if(palcount > 150) {            
                if(colourarrayorig[index] != 0) {
                    // Can't be more than 256 colours in the orig image, so this is fine
                    palette[palInitialSize] = p;
                    palInitialSize++;
                }
            }
            numcolours++;
        }
        colourarray[index]++;
    }
        
    qsort(colourlist, numcolours, sizeof(Pixel), &PixelComp);
    
    int bestCountBright = 0;
    int bestCountDark = 0;
    for(int i = 0; i < numcolours / 25; i++) {
        if(colourcount[PixelToIndex(colourlist[i])] > bestCountBright) {
            bestCountBright = colourcount[PixelToIndex(colourlist[i])];
            brightest = colourlist[i];
        }

        if(colourcount[PixelToIndex(colourlist[numcolours - i - 1])] > bestCountDark) {
            bestCountDark = colourcount[PixelToIndex(colourlist[numcolours - i - 1])];
            darkest = colourlist[numcolours - i - 1];
        }
    }

    if(numcolours<=256)
    {
        int n=0;
        /*for(int i=0;i<256*256*256;i++)
        {
            if(colourarray[i])
            {
                palette[n]=IndexToPixel(i);
                colourarray[i]=n;
                n++;
            }
        }*/
        while(colourindices[n] != 0) {
            int i = colourindices[n] - 1;
            palette[n]=IndexToPixel(i);
            colourarray[i]=n;
            n++;
        }
        
        
        uint8_t *ptr=output;
        for(int y=0;y<bitmap->height;y++)
        for(int x=0;x<bitmap->width;x++)
        {
            Pixel p=ReadPixelNoClip(bitmap,x,y);
            int index=PixelToIndex(p);
            *ptr++=colourarray[index];
        }
    }
    else
    {
        palette[palInitialSize] = brightest;
        if(palInitialSize < 255) {
            palette[palInitialSize + 1] = darkest;
        }
        
        int index = palInitialSize + 2;
        float bestDiff = -1;
        
        // Terminates if index too big anyways, no need for more checks
        float* colDiffs = calloc(sizeof(float) * numcolours, 1);
        int lastIndex = 0;
        while(index < 256) {
            for(int col = 0; col < numcolours; col++) {
                Pixel p = colourlist[col];
                
                int found = 0;
                for(int i = 0; i < index; i++) {
                    if(palette[i] == p) {
                        found = 1;
                        break;
                    }
                }
                if(found == 1) {
                    continue;
                }
                
                for(int i = lastIndex; i < index; i++) {
                    colDiffs[col] += PixelDist(palette[i], p);
                }
                lastIndex = index;
                if(colDiffs[col] > bestDiff) {
                    palette[index] = p;
                    bestDiff = colDiffs[col];
                }
            }
            index += 1;
        }
        free(colDiffs);
        /*for(int i=0;i<256*256*256;i++)
        {
            if(colourarray[i])
            {
                Pixel p=IndexToPixel(i);
                float bestDiff = PixelDist(palette[0], p);
                colourarray[i] = 0;
                for(int j = 1; j < 256; j++) {
                    float dist = PixelDist(palette[j], p);
                    if(dist < bestDiff) {
                        bestDiff = dist;
                        colourarray[i] = j;
                    }
                    
                }
            }
        }*/
        
        int n = 0;
        while(colourindices[n] != 0) {
            int i = colourindices[n] - 1;
            Pixel p=IndexToPixel(i);
            float bestDiff = PixelDist(palette[0], p);
            colourarray[i] = 0;
            for(int j = 1; j < 256; j++) {
                float dist = PixelDist(palette[j], p);
                if(dist < bestDiff) {
                    bestDiff = dist;
                    colourarray[i] = j;
                }
                
            }
            n++;
        }
        
        uint8_t *ptr=output;
        for(int y=0;y<bitmap->height;y++)
        for(int x=0;x<bitmap->width;x++)
        {
            Pixel p=ReadPixelNoClip(bitmap,x,y);
            int index=PixelToIndex(p);
            *ptr++=colourarray[index];
            //*ptr++=SearchNeuquantIndex(&quant,ExtractRed(p),ExtractGreen(p),ExtractBlue(p));
        }

        numcolours=256;
        
// 		Neuquant quant;
// 		InitializeNeuquantNetwork(&quant);
// 		NeuquantLearn(&quant,bitmap,PixelLookup,bitmap->width*bitmap->height,1);
// 		UnbiasNeuquantNetwork(&quant);
// 
// 		for(int i=0;i<256;i++)
// 		{
// 			int r,g,b;
// 			GetNeuquantPaletteEntry(&quant,i,&r,&g,&b);
// 			palette[i]=RGB(r,g,b);
// 		}
// 
// 		BuildNeuquantIndex(&quant);
// 
// 		for(int i=0;i<256*256*256;i++)
// 		{
// 			if(colourarray[i])
// 			{
// 				Pixel p=IndexToPixel(i);
// 				colourarray[i]=SearchNeuquantIndex(&quant,ExtractRed(p),ExtractGreen(p),ExtractBlue(p));
// 			}
// 		}
// 
// 		uint8_t *ptr=output;
// 		for(int y=0;y<bitmap->height;y++)
// 		for(int x=0;x<bitmap->width;x++)
// 		{
// 			Pixel p=ReadPixelNoClip(bitmap,x,y);
// 			int index=PixelToIndex(p);
// 			*ptr++=colourarray[index];
// 			//*ptr++=SearchNeuquantIndex(&quant,ExtractRed(p),ExtractGreen(p),ExtractBlue(p));
// 		}
// 
// 		numcolours=256;
        
        
    }

    free(colourindices);
    free(colourlist);
    free(colourcount);
    free(colourarrayorig);
    free(colourarray);
    return 256;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq -0x130(%rsp), %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x4000000, %edi        # imm = 0x4000000
movl $0x1, %esi
callq 0x1120
movq %rax, -0x28(%rbp)
movl $0x4000000, %edi        # imm = 0x4000000
movl $0x1, %esi
callq 0x1120
movq %rax, -0x30(%rbp)
movl $0x4000000, %edi        # imm = 0x4000000
movl $0x1, %esi
callq 0x1120
movq %rax, -0x38(%rbp)
movl $0x4000000, %edi        # imm = 0x4000000
movl $0x1, %esi
callq 0x1120
movq %rax, -0x40(%rbp)
movl $0x4000000, %edi        # imm = 0x4000000
movl $0x1, %esi
callq 0x1120
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0xff, -0x50(%rbp)
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x20(%rbp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x7554
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movq -0x20(%rbp), %rcx
movswl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x7544
movq -0x20(%rbp), %rdi
movl -0x60(%rbp), %esi
movl -0x5c(%rbp), %edx
callq 0xad20
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %edi
callq 0x7d20
movl %eax, -0x68(%rbp)
movq -0x30(%rbp), %rax
movslq -0x68(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x7528
movl -0x64(%rbp), %edx
movq -0x18(%rbp), %rax
movslq -0x58(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movslq -0x68(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x74d8
jmp 0x7546
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x74be
movl -0x58(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x96, -0x58(%rbp)
jle 0x756a
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
movq -0x8(%rbp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x7660
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x8(%rbp), %rcx
movswl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x7650
movq -0x8(%rbp), %rdi
movl -0x74(%rbp), %esi
movl -0x70(%rbp), %edx
callq 0xad20
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %edi
callq 0x7d20
movl %eax, -0x7c(%rbp)
movq -0x38(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x7631
movl -0x78(%rbp), %edx
movq -0x48(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x7c(%rbp), %edx
addl $0x1, %edx
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
cmpl $0x96, -0x58(%rbp)
jle 0x7628
movq -0x30(%rbp), %rax
movslq -0x7c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x7626
movl -0x78(%rbp), %edx
movq -0x18(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x7628
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x758b
jmp 0x7652
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x7571
movq -0x48(%rbp), %rdi
movslq -0x4c(%rbp), %rsi
movl $0x4, %edx
leaq -0x434(%rip), %rcx      # 0x7240
callq 0x1060
movl $0x0, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x104(%rbp)
movl -0x4c(%rbp), %eax
movl $0x19, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x104(%rbp), %eax
cmpl %ecx, %eax
jge 0x77d5
movq -0x38(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x48(%rbp), %rax
movslq -0x88(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x7d20
movl %eax, %ecx
movq -0x110(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x80(%rbp), %eax
jbe 0x772e
movq -0x38(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x48(%rbp), %rax
movslq -0x88(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x7d20
movl %eax, %ecx
movq -0x118(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x80(%rbp)
movq -0x48(%rbp), %rax
movslq -0x88(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x48(%rbp), %rax
movl -0x4c(%rbp), %ecx
subl -0x88(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edi
callq 0x7d20
movl %eax, %ecx
movq -0x120(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x84(%rbp), %eax
jbe 0x77bf
movq -0x38(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x48(%rbp), %rax
movl -0x4c(%rbp), %ecx
subl -0x88(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edi
callq 0x7d20
movl %eax, %ecx
movq -0x128(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x84(%rbp)
movq -0x48(%rbp), %rax
movl -0x4c(%rbp), %ecx
subl -0x88(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
jmp 0x77c1
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x7694
cmpl $0x100, -0x4c(%rbp)     # imm = 0x100
jg 0x7919
movl $0x0, -0x8c(%rbp)
movq -0x40(%rbp), %rax
movslq -0x8c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x7854
movq -0x40(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %edi
callq 0x7d30
movl %eax, %edx
movq -0x18(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x8c(%rbp), %edx
movq -0x28(%rbp), %rax
movslq -0x90(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x77ec
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movq -0x8(%rbp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x7914
movl $0x0, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
movq -0x8(%rbp), %rcx
movswl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x78fe
movq -0x8(%rbp), %rdi
movl -0xa0(%rbp), %esi
movl -0x9c(%rbp), %edx
callq 0xad20
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %edi
callq 0x7d20
movl %eax, -0xa8(%rbp)
movq -0x28(%rbp), %rax
movslq -0xa8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movb %al, %cl
movq -0x98(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x98(%rbp)
movb %cl, (%rax)
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x7889
jmp 0x7900
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x7869
jmp 0x7cdd
movl -0x50(%rbp), %edx
movq -0x18(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
cmpl $0xff, -0x6c(%rbp)
jge 0x7943
movl -0x54(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x6c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x6c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xac(%rbp)
movss 0xfb99(%rip), %xmm0     # 0x174f0
movss %xmm0, -0xb0(%rbp)
movslq -0x4c(%rbp), %rdi
shlq $0x2, %rdi
movl $0x1, %esi
callq 0x1120
movq %rax, -0xb8(%rbp)
movl $0x0, -0xbc(%rbp)
cmpl $0x100, -0xac(%rbp)     # imm = 0x100
jge 0x7b01
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x7aed
movq -0x48(%rbp), %rax
movslq -0xc0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xc4(%rbp)
movl $0x0, -0xc8(%rbp)
movl $0x0, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
cmpl -0xac(%rbp), %eax
jge 0x7a16
movq -0x18(%rbp), %rax
movslq -0xcc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0xc4(%rbp), %eax
jne 0x7a03
movl $0x1, -0xc8(%rbp)
jmp 0x7a16
jmp 0x7a05
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x79d3
cmpl $0x1, -0xc8(%rbp)
jne 0x7a24
jmp 0x7ad9
movl -0xbc(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
cmpl -0xac(%rbp), %eax
jge 0x7a80
movq -0x18(%rbp), %rax
movslq -0xd0(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movl -0xc4(%rbp), %esi
callq 0x7d50
movq -0xb8(%rbp), %rax
movslq -0xc0(%rbp), %rcx
addss (%rax,%rcx,4), %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x7a30
movl -0xac(%rbp), %eax
movl %eax, -0xbc(%rbp)
movq -0xb8(%rbp), %rax
movslq -0xc0(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
ucomiss -0xb0(%rbp), %xmm0
jbe 0x7ad7
movl -0xc4(%rbp), %edx
movq -0x18(%rbp), %rax
movslq -0xac(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0xb8(%rbp), %rax
movslq -0xc0(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0xb0(%rbp)
jmp 0x7ad9
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x799c
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x7982
movq -0xb8(%rbp), %rdi
callq 0x1030
movl $0x0, -0xd4(%rbp)
movq -0x40(%rbp), %rax
movslq -0xd4(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x7c16
movq -0x40(%rbp), %rax
movslq -0xd4(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
movl %eax, -0xd8(%rbp)
movl -0xd8(%rbp), %edi
callq 0x7d30
movl %eax, -0xdc(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %edi
movl -0xdc(%rbp), %esi
callq 0x7d50
movss %xmm0, -0xe0(%rbp)
movq -0x28(%rbp), %rax
movslq -0xd8(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl $0x1, -0xe4(%rbp)
cmpl $0x100, -0xe4(%rbp)     # imm = 0x100
jge 0x7c02
movq -0x18(%rbp), %rax
movslq -0xe4(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movl -0xdc(%rbp), %esi
callq 0x7d50
movss %xmm0, -0xe8(%rbp)
movss -0xe8(%rbp), %xmm1
movss -0xe0(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x7bef
movss -0xe8(%rbp), %xmm0
movss %xmm0, -0xe0(%rbp)
movl -0xe4(%rbp), %edx
movq -0x28(%rbp), %rax
movslq -0xd8(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x7bf1
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x7b89
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x7b17
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl $0x0, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
movq -0x8(%rbp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x7cd6
movl $0x0, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
movq -0x8(%rbp), %rcx
movswl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x7cc0
movq -0x8(%rbp), %rdi
movl -0xf8(%rbp), %esi
movl -0xf4(%rbp), %edx
callq 0xad20
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %edi
callq 0x7d20
movl %eax, -0x100(%rbp)
movq -0x28(%rbp), %rax
movslq -0x100(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movb %al, %cl
movq -0xf0(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0xf0(%rbp)
movb %cl, (%rax)
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0x7c4b
jmp 0x7cc2
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x7c2b
movl $0x100, -0x4c(%rbp)     # imm = 0x100
movq -0x40(%rbp), %rdi
callq 0x1030
movq -0x48(%rbp), %rdi
callq 0x1030
movq -0x38(%rbp), %rdi
callq 0x1030
movq -0x30(%rbp), %rdi
callq 0x1030
movq -0x28(%rbp), %rdi
callq 0x1030
movl $0x100, %eax            # imm = 0x100
leaq 0x130(%rsp), %rsp
popq %rbp
retq
nopl (%rax)