// File: OpenFirework[P]MyJPEG_Decoder/./bmp/bmp_code.cpp
// Function: MyBMP::BMP::resize(unsigned char*&, int, int, unsigned char*&, int&, int&, float)
int MyBMP::BMP::resize(byte *&inputdata, int inwidth, int inheight, byte *&outdata, int &outwidth, int &outheight, float scale) {

    float xscale = 0.0;
    float yscale = 0.0;
    if((outheight <= 0) || (outheight <= 0)) {
        std::cout<<"resize use scale and scale is "<<scale<<"\n";
        if(scale > 0) {
            outwidth = inwidth*scale;
            outheight = inheight*scale;
            xscale = inwidth*1.0/outwidth;
            yscale = inheight*1.0/outheight;
        } else {
            std::cout<<"scale value is wrong(less than 0)\n";
        }
       
    } else {
        std::cout<<"resize use outwidth and outheight, resized width is "<<outwidth<<" heigt is "<<outheight<<"\n";
        xscale = inwidth*1.0/outwidth;
        yscale = inheight*1.0/outheight;

    }
    std::cout<<"resized width is "<<outwidth<<" height is "<<outheight<<"\n";

    outdata = new byte[3*outwidth*outheight];

    for(int h=0; h<outheight; h++) {
        for(int w=0; w<outwidth; w++) {
            float srcx = w*xscale;
            float srcy = h*yscale;
            int topx = srcx;
            int topy = srcy;
            int reflect = topy*inwidth+topx;
            int reflect2 = 0;
            int topy2 = 0;
            int topx2 = 0;
            if(topy+1 > (inheight-1)){
                reflect2 = topy*inwidth+topx;
                topy2 = topy;
            } else {
                reflect2 = (topy+1)*inwidth+topx;
                topy2 = topy+1;
            }
            if(topx +1 > (inwidth-1)) {
                topx = topx - 1;
            }
            float fr = (topy2-srcy)*(topx+1-srcx)*inputdata[reflect*3] +
                       (topy2-srcy)*(srcx - topx)*inputdata[reflect*3+3] +
                        (srcy-topy)*(topx+1-srcx)*inputdata[reflect2*3] +
                        (srcy-topy)*(srcx-topx)*inputdata[reflect2*3+3];
            
            float fg = (topy2-srcy)*(topx+1-srcx)*inputdata[reflect*3+1] +
                       (topy2-srcy)*(srcx - topx)*inputdata[reflect*3+3+1] +
                        (srcy-topy)*(topx+1-srcx)*inputdata[reflect2*3+1] +
                        (srcy-topy)*(srcx-topx)*inputdata[reflect2*3+3+1];


            float fb = (topy2-srcy)*(topx+1-srcx)*inputdata[reflect*3+2] +
                       (topy2-srcy)*(srcx - topx)*inputdata[reflect*3+3+2] +
                        (srcy-topy)*(topx+1-srcx)*inputdata[reflect2*3+2] +
                        (srcy-topy)*(srcx-topx)*inputdata[reflect2*3+3+2];

            int offset = h*outwidth + w;
            outdata[offset*3] = fr;
            outdata[offset*3+1] = fg;
            outdata[offset*3+2] = fb;
        }
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movss %xmm0, -0x2c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x6c3d
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
jg 0x6d07
movq 0x438c(%rip), %rdi      # 0xafd0
leaq 0x1c2b(%rip), %rsi      # 0x8876
callq 0x2130
movq %rax, %rdi
movss -0x2c(%rbp), %xmm0
callq 0x20e0
movq %rax, %rdi
leaq 0x1d43(%rip), %rsi      # 0x89aa
callq 0x2130
movss -0x2c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x6cef
cvtsi2ssl -0x14(%rbp), %xmm0
mulss -0x2c(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
cvtsi2ssl -0x18(%rbp), %xmm0
mulss -0x2c(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
cvtsi2sdl -0x14(%rbp), %xmm0
movsd 0x19fa(%rip), %xmm1     # 0x86a8
mulsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
cvtsi2sdl -0x18(%rbp), %xmm0
movsd 0x19d4(%rip), %xmm1     # 0x86a8
mulsd %xmm1, %xmm0
movq 0x10(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
jmp 0x6d02
movq 0x42da(%rip), %rdi      # 0xafd0
leaq 0x1b98(%rip), %rsi      # 0x8895
callq 0x2130
jmp 0x6da0
movq 0x42c2(%rip), %rdi      # 0xafd0
leaq 0x1ba3(%rip), %rsi      # 0x88b8
callq 0x2130
movq %rax, %rdi
movq -0x28(%rbp), %rax
movl (%rax), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x1bbb(%rip), %rsi      # 0x88ed
callq 0x2130
movq %rax, %rdi
movq 0x10(%rbp), %rax
movl (%rax), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x1c5b(%rip), %rsi      # 0x89aa
callq 0x2130
cvtsi2sdl -0x14(%rbp), %xmm0
movsd 0x1947(%rip), %xmm1     # 0x86a8
mulsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
cvtsi2sdl -0x18(%rbp), %xmm0
movsd 0x1921(%rip), %xmm1     # 0x86a8
mulsd %xmm1, %xmm0
movq 0x10(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
movq 0x4229(%rip), %rdi      # 0xafd0
leaq 0x1b2d(%rip), %rsi      # 0x88db
callq 0x2130
movq %rax, %rdi
movq -0x28(%rbp), %rax
movl (%rax), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x1b2d(%rip), %rsi      # 0x88f8
callq 0x2130
movq %rax, %rdi
movq 0x10(%rbp), %rax
movl (%rax), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x1bc2(%rip), %rsi      # 0x89aa
callq 0x2130
movq -0x28(%rbp), %rax
imull $0x3, (%rax), %eax
movq 0x10(%rbp), %rcx
imull (%rcx), %eax
movslq %eax, %rdi
callq 0x2030
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x7160
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x7150
cvtsi2ssl -0x3c(%rbp), %xmm0
mulss -0x30(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
cvtsi2ssl -0x38(%rbp), %xmm0
mulss -0x34(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
cvttss2si -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
cvttss2si -0x44(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
imull -0x14(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x6eae
movl -0x4c(%rbp), %eax
imull -0x14(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x6ec7
movl -0x4c(%rbp), %eax
addl $0x1, %eax
imull -0x14(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x6ee0
movl -0x48(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
cvtsi2ssl -0x58(%rbp), %xmm1
movss -0x44(%rbp), %xmm0
subss %xmm0, %xmm1
movl -0x48(%rbp), %edx
movl %edx, %eax
incl %eax
cvtsi2ss %eax, %xmm4
movss -0x40(%rbp), %xmm2
subss %xmm2, %xmm4
movaps %xmm1, %xmm3
mulss %xmm4, %xmm3
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x50(%rbp), %esi
movl %esi, %ecx
leal (%rcx,%rcx,2), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %esi
cvtsi2ss %esi, %xmm5
cvtsi2ss %edx, %xmm6
subss %xmm6, %xmm2
mulss %xmm2, %xmm1
movzbl 0x3(%rax,%rcx), %ecx
cvtsi2ss %ecx, %xmm6
mulss %xmm6, %xmm1
mulss %xmm5, %xmm3
addss %xmm1, %xmm3
cvtsi2ssl -0x4c(%rbp), %xmm1
subss %xmm1, %xmm0
movaps %xmm0, %xmm1
mulss %xmm4, %xmm1
movl -0x54(%rbp), %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
cvtsi2ss %edx, %xmm4
mulss %xmm4, %xmm1
addss %xmm3, %xmm1
mulss %xmm2, %xmm0
movzbl 0x3(%rax,%rcx), %eax
cvtsi2ss %eax, %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x60(%rbp)
cvtsi2ssl -0x58(%rbp), %xmm1
movss -0x44(%rbp), %xmm0
subss %xmm0, %xmm1
movl -0x48(%rbp), %edx
movl %edx, %eax
incl %eax
cvtsi2ss %eax, %xmm4
movss -0x40(%rbp), %xmm2
subss %xmm2, %xmm4
movaps %xmm1, %xmm3
mulss %xmm4, %xmm3
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl -0x50(%rbp), %esi
movl %esi, %eax
leal (%rax,%rax,2), %eax
cltq
movzbl 0x1(%rax,%rcx), %esi
cvtsi2ss %esi, %xmm5
cvtsi2ss %edx, %xmm6
subss %xmm6, %xmm2
mulss %xmm2, %xmm1
movzbl 0x4(%rax,%rcx), %eax
cvtsi2ss %eax, %xmm6
mulss %xmm6, %xmm1
mulss %xmm5, %xmm3
addss %xmm1, %xmm3
cvtsi2ssl -0x4c(%rbp), %xmm1
subss %xmm1, %xmm0
movaps %xmm0, %xmm1
mulss %xmm4, %xmm1
movl -0x54(%rbp), %edx
movl %edx, %eax
leal (%rax,%rax,2), %eax
cltq
movzbl 0x1(%rax,%rcx), %edx
cvtsi2ss %edx, %xmm4
mulss %xmm4, %xmm1
addss %xmm3, %xmm1
mulss %xmm2, %xmm0
movzbl 0x4(%rax,%rcx), %eax
cvtsi2ss %eax, %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x64(%rbp)
cvtsi2ssl -0x58(%rbp), %xmm1
movss -0x44(%rbp), %xmm0
subss %xmm0, %xmm1
movl -0x48(%rbp), %edx
movl %edx, %eax
incl %eax
cvtsi2ss %eax, %xmm4
movss -0x40(%rbp), %xmm2
subss %xmm2, %xmm4
movaps %xmm1, %xmm3
mulss %xmm4, %xmm3
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl -0x50(%rbp), %esi
movl %esi, %eax
leal (%rax,%rax,2), %eax
cltq
movzbl 0x2(%rax,%rcx), %esi
cvtsi2ss %esi, %xmm5
cvtsi2ss %edx, %xmm6
subss %xmm6, %xmm2
mulss %xmm2, %xmm1
movzbl 0x5(%rax,%rcx), %eax
cvtsi2ss %eax, %xmm6
mulss %xmm6, %xmm1
mulss %xmm5, %xmm3
addss %xmm1, %xmm3
cvtsi2ssl -0x4c(%rbp), %xmm1
subss %xmm1, %xmm0
movaps %xmm0, %xmm1
mulss %xmm4, %xmm1
movl -0x54(%rbp), %edx
movl %edx, %eax
leal (%rax,%rax,2), %eax
cltq
movzbl 0x2(%rax,%rcx), %edx
cvtsi2ss %edx, %xmm4
mulss %xmm4, %xmm1
addss %xmm3, %xmm1
mulss %xmm2, %xmm0
movzbl 0x5(%rax,%rcx), %eax
cvtsi2ss %eax, %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x68(%rbp)
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
imull %ecx, %eax
movl -0x3c(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x6c(%rbp)
cvttss2si -0x60(%rbp), %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0x6c(%rbp), %esi
movl %esi, %ecx
leal (%rcx,%rcx,2), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
cvttss2si -0x64(%rbp), %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movl -0x6c(%rbp), %esi
movl %esi, %eax
leal (%rax,%rax,2), %eax
cltq
movb %dl, 0x1(%rax,%rcx)
cvttss2si -0x68(%rbp), %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movq (%rax), %rax
imull $0x3, -0x6c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6e2a
jmp 0x7152
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x6e14
ud2
nopw %cs:(%rax,%rax)
nopl (%rax)