// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %rbx
movq %r8, %r14
movl %ecx, %r15d
movq %rdx, -0x48(%rbp)
movq %rsi, %r13
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x3dbf
movq 0x42a3(%rip), %r12      # 0x7fd0
leaq 0x17c2(%rip), %rsi      # 0x54f6
movl $0x34, %edx
movq %r12, %rdi
callq 0x2130
movl (%rbx), %esi
movq %r12, %rdi
callq 0x2210
movq %rax, -0x30(%rbp)
leaq 0x17d5(%rip), %rsi      # 0x552b
movl $0xa, %edx
movq %rax, %rdi
callq 0x2130
movq 0x10(%rbp), %r12
movl (%r12), %esi
movq -0x30(%rbp), %rdi
callq 0x2210
leaq 0x1883(%rip), %rsi      # 0x55fe
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
xorps %xmm0, %xmm0
cvtsi2sdl -0x48(%rbp), %xmm0
cvtsi2sdl (%rbx), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%r12), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
jmp 0x3e7f
movq 0x420a(%rip), %r12      # 0x7fd0
leaq 0x16e7(%rip), %rsi      # 0x54b4
movl $0x1e, %edx
movq %r12, %rdi
movss %xmm0, -0x30(%rbp)
callq 0x2130
xorps %xmm0, %xmm0
cvtss2sd -0x30(%rbp), %xmm0
movq %r12, %rdi
callq 0x21d0
leaq 0x1808(%rip), %rsi      # 0x55fe
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
xorps %xmm1, %xmm1
xorps %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
movss -0x30(%rbp), %xmm1
jbe 0x4153
movq -0x48(%rbp), %rcx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, (%rbx)
xorps %xmm0, %xmm0
cvtsi2ss %r15d, %xmm0
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
movq 0x10(%rbp), %rcx
movl %eax, (%rcx)
cvtsi2sdl (%rbx), %xmm2
divsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, -0x38(%rbp)
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
cvttps2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, -0x34(%rbp)
movq 0x4145(%rip), %r12      # 0x7fd0
leaq 0x1687(%rip), %rsi      # 0x5519
movl $0x11, %edx
movq %r12, %rdi
callq 0x2130
movl (%rbx), %esi
movq %r12, %rdi
callq 0x2210
movq %rax, -0x30(%rbp)
leaq 0x1682(%rip), %rsi      # 0x5536
movl $0xb, %edx
movq %rax, %rdi
callq 0x2130
movq 0x10(%rbp), %r12
movl (%r12), %esi
movq -0x30(%rbp), %rdi
callq 0x2210
leaq 0x1725(%rip), %rsi      # 0x55fe
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
movslq (%rbx), %rax
movslq (%r12), %rcx
imulq %rax, %rcx
leaq (%rcx,%rcx,2), %rdi
callq 0x2030
movq %rax, (%r14)
decl %r15d
movq -0x48(%rbp), %rax
decl %eax
xorl %ecx, %ecx
movl %eax, -0x3c(%rbp)
movl (%rbx), %r8d
testl %r8d, %r8d
movss -0x38(%rbp), %xmm1
jle 0x414c
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
mulss -0x34(%rbp), %xmm0
cvttss2si %xmm0, %edx
movl %edx, %esi
movq -0x48(%rbp), %rax
imull %eax, %esi
movq %rsi, -0x58(%rbp)
leal 0x1(%rdx), %r9d
movl %r9d, %edi
imull %eax, %edi
movl -0x3c(%rbp), %eax
cmpl %edx, %r15d
cmovlel %edx, %r9d
xorps %xmm2, %xmm2
cvtsi2ss %r9d, %xmm2
subss %xmm0, %xmm2
movss %xmm2, -0x4c(%rbp)
cvttps2dq %xmm0, %xmm2
cvtdq2ps %xmm2, %xmm2
subss %xmm2, %xmm0
movaps %xmm0, -0x70(%rbp)
xorl %r9d, %r9d
xorps %xmm2, %xmm2
cvtsi2ss %r9d, %xmm2
mulss %xmm1, %xmm2
cvttss2si %xmm2, %r10d
movq -0x58(%rbp), %rsi
leal (%rsi,%r10), %r12d
cmpl %edx, %r15d
leal (%rdi,%r10), %r11d
cmovlel %r12d, %r11d
movl %ecx, %esi
movq %r13, %rcx
xorl %r13d, %r13d
cmpl %r10d, %eax
setle %r13b
movq %rbx, %rax
movl %r15d, %ebx
movl %r10d, %r15d
subl %r13d, %r15d
negl %r13d
addl %r13d, %r10d
incl %r10d
movq %rcx, %r13
movl %esi, %ecx
xorps %xmm3, %xmm3
cvtsi2ss %r10d, %xmm3
movq (%r13), %r10
movslq %r12d, %r12
xorps %xmm0, %xmm0
cvtsi2ss %r15d, %xmm0
movss %xmm0, -0x30(%rbp)
leaq (%r12,%r12,2), %r12
movzbl (%r10,%r12), %r15d
cvtsi2ss %r15d, %xmm4
movzbl 0x3(%r10,%r12), %r15d
cvtsi2ss %r15d, %xmm7
movzbl 0x1(%r10,%r12), %r15d
cvtsi2ss %r15d, %xmm5
movzbl 0x4(%r10,%r12), %r15d
cvtsi2ss %r15d, %xmm12
movzbl 0x2(%r10,%r12), %r15d
xorps %xmm8, %xmm8
cvtsi2ss %r15d, %xmm8
movslq %r11d, %r11
leaq (%r11,%r11,2), %r11
movzbl 0x5(%r10,%r12), %r15d
cvtsi2ss %r15d, %xmm14
movzbl (%r10,%r11), %r15d
cvtsi2ss %r15d, %xmm15
movzbl 0x3(%r10,%r11), %r15d
cvtsi2ss %r15d, %xmm11
movzbl 0x1(%r10,%r11), %r15d
cvtsi2ss %r15d, %xmm10
movzbl 0x4(%r10,%r11), %r15d
cvtsi2ss %r15d, %xmm9
movzbl 0x2(%r10,%r11), %r15d
xorps %xmm13, %xmm13
cvtsi2ss %r15d, %xmm13
movl %ebx, %r15d
movq %rax, %rbx
movl -0x3c(%rbp), %eax
subss %xmm2, %xmm3
movaps %xmm1, %xmm0
movss -0x4c(%rbp), %xmm6
movaps %xmm6, %xmm1
subss -0x30(%rbp), %xmm2
mulss %xmm3, %xmm1
mulss %xmm2, %xmm6
mulss %xmm6, %xmm7
mulss %xmm1, %xmm4
addss %xmm7, %xmm4
mulss %xmm6, %xmm12
mulss %xmm1, %xmm5
addss %xmm12, %xmm5
mulss %xmm6, %xmm14
movaps -0x70(%rbp), %xmm6
mulss %xmm6, %xmm3
mulss %xmm3, %xmm15
addss %xmm4, %xmm15
mulss %xmm1, %xmm8
mulss %xmm6, %xmm2
mulss %xmm2, %xmm11
addss %xmm15, %xmm11
mulss %xmm3, %xmm10
mulss %xmm2, %xmm9
movzbl 0x5(%r10,%r11), %r10d
mulss %xmm3, %xmm13
xorps %xmm1, %xmm1
cvtsi2ss %r10d, %xmm1
addss %xmm14, %xmm8
mulss %xmm2, %xmm1
imull %esi, %r8d
addl %r9d, %r8d
addss %xmm5, %xmm10
cvttss2si %xmm11, %r10d
movq (%r14), %r11
addss %xmm10, %xmm9
movslq %r8d, %r8
leaq (%r8,%r8,2), %r8
movb %r10b, (%r11,%r8)
addss %xmm8, %xmm13
cvttss2si %xmm9, %r10d
movq (%r14), %r11
addss %xmm13, %xmm1
movb %r10b, 0x1(%r11,%r8)
cvttss2si %xmm1, %r10d
movaps %xmm0, %xmm1
movq (%r14), %r11
movb %r10b, 0x2(%r11,%r8)
incl %r9d
movl (%rbx), %r8d
cmpl %r8d, %r9d
jl 0x3f70
incl %ecx
jmp 0x3f0b
movq 0x3e76(%rip), %rdi      # 0x7fd0
leaq 0x1372(%rip), %rsi      # 0x54d3
movl $0x22, %edx
callq 0x2130
xorps %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
jmp 0x3e84