// File: /workspace/github_cpp_makefile_star2_O3/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
movl %edx, %r12d
movq %rsi, -0x50(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
movq %r12, -0x40(%rbp)
movq 0x4437(%rip), %r13      # 0x7fd0
jle 0x3c2f
leaq 0x1950(%rip), %rsi      # 0x54f6
movl $0x34, %edx
movq %r13, %rdi
callq 0x2130
movl (%rbx), %esi
movq %r13, %rdi
callq 0x2210
leaq 0x1967(%rip), %rsi      # 0x552b
movl $0xa, %edx
movq %rax, %rdi
movq 0x10(%rbp), %r13
movq %rax, %r12
callq 0x2130
movl (%r13), %esi
movq %r12, %rdi
callq 0x2210
leaq 0x1a13(%rip), %rsi      # 0x55fe
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
xorps %xmm0, %xmm0
cvtsi2sdl -0x40(%rbp), %xmm0
cvtsi2sdl (%rbx), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%r13), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
jmp 0x3ce8
leaq 0x187e(%rip), %rsi      # 0x54b4
movl $0x1e, %edx
movq %r13, %rdi
movss %xmm0, -0x38(%rbp)
callq 0x2130
xorps %xmm0, %xmm0
cvtss2sd -0x38(%rbp), %xmm0
movq %r13, %rdi
callq 0x21d0
leaq 0x199f(%rip), %rsi      # 0x55fe
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
xorps %xmm1, %xmm1
xorps %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
movss -0x38(%rbp), %xmm0
ucomiss %xmm1, %xmm0
movss -0x38(%rbp), %xmm1
jbe 0x3f9d
xorps %xmm0, %xmm0
cvtsi2ss %r12d, %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 %r12d, %xmm1
movq 0x10(%rbp), %r13
movl %eax, (%r13)
cvtsi2sdl (%rbx), %xmm2
divsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, -0x30(%rbp)
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
cvttps2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, -0x2c(%rbp)
movq 0x42dc(%rip), %r12      # 0x7fd0
leaq 0x181e(%rip), %rsi      # 0x5519
movl $0x11, %edx
movq %r12, %rdi
callq 0x2130
movl (%rbx), %esi
movq %r12, %rdi
callq 0x2210
movq %rax, %r12
leaq 0x181a(%rip), %rsi      # 0x5536
movl $0xb, %edx
movq %rax, %rdi
callq 0x2130
movl (%r13), %esi
movq %r12, %rdi
callq 0x2210
leaq 0x18c2(%rip), %rsi      # 0x55fe
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
movslq (%rbx), %r12
movslq (%r13), %rax
imulq %r12, %rax
leaq (%rax,%rax,2), %rdi
callq 0x2030
movq %rax, (%r14)
decl %r15d
movq -0x40(%rbp), %rax
leal -0x1(%rax), %r13d
xorl %edi, %edi
testl %r12d, %r12d
jle 0x3f96
xorps %xmm1, %xmm1
cvtsi2ss %edi, %xmm1
mulss -0x2c(%rbp), %xmm1
cvttss2si %xmm1, %edx
movl %edx, %ecx
movq -0x40(%rbp), %rax
imull %eax, %ecx
movq %rcx, -0x38(%rbp)
leal 0x1(%rdx), %r8d
movl %r8d, %ecx
imull %eax, %ecx
movq %rcx, -0x58(%rbp)
cmpl %edx, %r15d
cmovlel %edx, %r8d
xorps %xmm0, %xmm0
cvtsi2ss %r8d, %xmm0
subss %xmm1, %xmm0
movss %xmm0, -0x44(%rbp)
cvttps2dq %xmm1, %xmm2
cvtdq2ps %xmm2, %xmm2
subss %xmm2, %xmm1
movaps %xmm1, -0x70(%rbp)
xorl %r8d, %r8d
movq -0x50(%rbp), %rcx
xorps %xmm2, %xmm2
cvtsi2ss %r8d, %xmm2
mulss -0x30(%rbp), %xmm2
cvttss2si %xmm2, %r9d
movq -0x38(%rbp), %rax
leal (%rax,%r9), %r11d
cmpl %edx, %r15d
movq -0x58(%rbp), %rax
leal (%rax,%r9), %r10d
cmovlel %r11d, %r10d
movl %r15d, %eax
movq %rbx, %r15
xorl %ebx, %ebx
cmpl %r9d, %r13d
setle %bl
movl %r13d, %esi
movl %r9d, %r13d
subl %ebx, %r13d
negl %ebx
addl %ebx, %r9d
incl %r9d
xorps %xmm3, %xmm3
cvtsi2ss %r9d, %xmm3
movq (%rcx), %r9
movslq %r11d, %r11
xorps %xmm0, %xmm0
cvtsi2ss %r13d, %xmm0
movl %esi, %r13d
leaq (%r11,%r11,2), %r11
movzbl (%r9,%r11), %ebx
cvtsi2ss %ebx, %xmm4
movzbl 0x3(%r9,%r11), %ebx
cvtsi2ss %ebx, %xmm7
movzbl 0x1(%r9,%r11), %ebx
cvtsi2ss %ebx, %xmm5
movzbl 0x4(%r9,%r11), %ebx
cvtsi2ss %ebx, %xmm12
movzbl 0x2(%r9,%r11), %ebx
xorps %xmm8, %xmm8
cvtsi2ss %ebx, %xmm8
movq %r15, %rbx
movl %eax, %r15d
movslq %r10d, %r10
leaq (%r10,%r10,2), %r10
movzbl 0x5(%r9,%r11), %r11d
cvtsi2ss %r11d, %xmm14
movzbl (%r9,%r10), %r11d
cvtsi2ss %r11d, %xmm15
movzbl 0x3(%r9,%r10), %r11d
cvtsi2ss %r11d, %xmm11
movzbl 0x1(%r9,%r10), %r11d
cvtsi2ss %r11d, %xmm10
movzbl 0x4(%r9,%r10), %r11d
cvtsi2ss %r11d, %xmm9
movzbl 0x2(%r9,%r10), %r11d
xorps %xmm13, %xmm13
cvtsi2ss %r11d, %xmm13
subss %xmm2, %xmm3
movss -0x44(%rbp), %xmm6
movaps %xmm6, %xmm1
subss %xmm0, %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), %xmm0
mulss %xmm0, %xmm3
mulss %xmm3, %xmm15
addss %xmm4, %xmm15
mulss %xmm1, %xmm8
mulss %xmm0, %xmm2
mulss %xmm2, %xmm11
addss %xmm15, %xmm11
mulss %xmm3, %xmm10
mulss %xmm2, %xmm9
movzbl 0x5(%r9,%r10), %r9d
mulss %xmm3, %xmm13
xorps %xmm1, %xmm1
cvtsi2ss %r9d, %xmm1
addss %xmm14, %xmm8
mulss %xmm2, %xmm1
imull %edi, %r12d
addl %r8d, %r12d
addss %xmm5, %xmm10
cvttss2si %xmm11, %r9d
movq (%r14), %r10
addss %xmm10, %xmm9
movslq %r12d, %r11
leaq (%r11,%r11,2), %r11
movb %r9b, (%r10,%r11)
addss %xmm8, %xmm13
cvttss2si %xmm9, %r9d
movq (%r14), %r10
addss %xmm13, %xmm1
movb %r9b, 0x1(%r10,%r11)
cvttss2si %xmm1, %r9d
movq (%r14), %r10
movb %r9b, 0x2(%r10,%r11)
incl %r8d
movl (%rbx), %r12d
cmpl %r12d, %r8d
jl 0x3dcf
incl %edi
jmp 0x3d6d
movq 0x402c(%rip), %rdi      # 0x7fd0
leaq 0x1528(%rip), %rsi      # 0x54d3
movl $0x22, %edx
callq 0x2130
xorps %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movq 0x10(%rbp), %r13
jmp 0x3ced
nop