// File: /workspace/github_cpp_makefile_star2_O2/iibrahimli[P]adsa_project/src/../include/util.hpp
// Function: x_enlarge_region(BMP_image const&, std::pair<int, int>, std::pair<int, int>, BMP_image&, std::pair<int, int>, float)
void x_enlarge_region(const BMP_image& a, std::pair<int, int> a_start, std::pair<int, int> a_end,
                            BMP_image& b, std::pair<int, int> b_start, float scale)
{
    int height = a_end.second - a_start.second;
    int width = (a_end.first - a_start.first) + 1;
    int new_w = floor(width * scale);
    float x, x_0, x_1;  // source pixel and its neighbors

    // outer loop with j for cache efficiency
    for(int j=0; j<height; ++j){
        for(int i=0; i<new_w; ++i){
            x = i / scale;
            x_0 = floor(x);
            x_1 = ceil(x);
            
            if(x_0 == x_1) x_1 += 1.0f;         // x is an integer
            if(x_1 == width) x_1 = width-1;     // out of bounds : replicate edge pixel
            if(x_0 == x_1) x_0 -= 1.0f;
            
            // linear interpolation between neighbor pixels
            b(b_start.first+i, b_start.second+j) = a.ploc(a_start.first+x_0, a_start.second+j)*(x_1 - x) +
                                                   a.ploc(a_start.first+x_1, a_start.second+j)*(x - x_0);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movaps %xmm0, %xmm1
movq %rcx, 0x60(%rsp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r15
movq %rsi, %rcx
shrq $0x20, %rcx
movq %rdx, %r14
shrq $0x20, %r14
movq %r8, 0x68(%rsp)
subl %r12d, %r13d
leal 0x1(%r13), %eax
cvtsi2ss %eax, %xmm0
shrq $0x20, %r8
movq %r8, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
subl %ecx, %r14d
movss %xmm0, 0xc(%rsp)
movss %xmm1, 0x10(%rsp)
mulss %xmm1, %xmm0
callq 0x20a0
cvttss2si %xmm0, %ebx
cvtsi2ss %r13d, %xmm0
movaps %xmm0, 0x70(%rsp)
cvtsi2ss %r12d, %xmm0
movss %xmm0, 0x4(%rsp)
xorl %ecx, %ecx
testl %ebx, %ebx
cmovlel %ecx, %ebx
testl %r14d, %r14d
cmovlel %ecx, %r14d
movq %r14, 0x50(%rsp)
cmpl 0x50(%rsp), %ecx
je 0x32e0
movq 0x48(%rsp), %rax
leal (%rcx,%rax), %r12d
movq 0x40(%rsp), %rax
movq %rcx, 0x58(%rsp)
leal (%rcx,%rax), %r13d
xorl %r14d, %r14d
cmpl %r14d, %ebx
je 0x32d4
cvtsi2ss %r14d, %xmm0
divss 0x10(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x2330
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x2050
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, %xmm1
addss 0x2e28(%rip), %xmm1     # 0x6008
movaps 0x30(%rsp), %xmm3
movaps %xmm3, %xmm2
cmpeqss %xmm0, %xmm2
andps %xmm2, %xmm1
andnps %xmm0, %xmm2
orps %xmm1, %xmm2
movaps %xmm2, %xmm1
cmpeqss 0xc(%rsp), %xmm1
movaps %xmm1, %xmm0
andnps %xmm2, %xmm0
andps 0x70(%rsp), %xmm1
orps %xmm0, %xmm1
movaps %xmm1, 0x20(%rsp)
movaps %xmm3, %xmm0
addss 0x2dee(%rip), %xmm0     # 0x600c
cmpeqss %xmm3, %xmm1
andps %xmm1, %xmm0
andnps %xmm3, %xmm1
orps %xmm0, %xmm1
movaps %xmm1, 0x30(%rsp)
movaps %xmm1, %xmm0
addss 0x4(%rsp), %xmm0
cvttss2si %xmm0, %rsi
movq %r15, %rdi
movl %r12d, %edx
callq 0x42be
movl (%rax), %edi
movaps 0x20(%rsp), %xmm0
subss 0x8(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
leaq 0x1c(%rsp), %rsi
callq 0x45e5
movl %eax, %ebp
movaps 0x20(%rsp), %xmm0
addss 0x4(%rsp), %xmm0
cvttss2si %xmm0, %rsi
movq %r15, %rdi
movl %r12d, %edx
callq 0x42be
movl (%rax), %edi
movss 0x8(%rsp), %xmm0
subss 0x30(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
leaq 0x14(%rsp), %rsi
callq 0x45e5
movl %eax, 0x18(%rsp)
movl %ebp, %edi
leaq 0x18(%rsp), %rsi
callq 0x45c9
movl %eax, %ebp
movq 0x68(%rsp), %rax
leal (%rax,%r14), %esi
movq 0x60(%rsp), %rdi
movl %r13d, %edx
callq 0x4602
movl %ebp, (%rax)
incl %r14d
jmp 0x3194
movq 0x58(%rsp), %rcx
incl %ecx
jmp 0x3170
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq