// File: /workspace/github_cpp_makefile_star2_O1/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 $0xa8, %rsp
movaps %xmm0, %xmm1
movq %r8, 0x38(%rsp)
movq %rcx, 0x88(%rsp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, 0x78(%rsp)
movq %rsi, %rbx
movq %rdx, %r14
subl %r12d, %r13d
leal 0x1(%r13), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
shrq $0x20, %rbx
shrq $0x20, %r14
movss %xmm0, 0x28(%rsp)
movss %xmm1, 0x8(%rsp)
mulss %xmm1, %xmm0
callq 0x20c0
movq %rbx, 0x70(%rsp)
subl %ebx, %r14d
movq %r14, 0x80(%rsp)
jle 0x3a27
movq 0x38(%rsp), %rax
xorps %xmm1, %xmm1
cvtsi2ss %r13d, %xmm1
movaps %xmm1, 0x90(%rsp)
shrq $0x20, %rax
movq %rax, 0x68(%rsp)
xorps %xmm1, %xmm1
cvtsi2ss %r12d, %xmm1
movss %xmm1, 0xc(%rsp)
cvttss2si %xmm0, %edx
movq $0x0, 0x18(%rsp)
leaq 0x34(%rsp), %r12
leaq 0x14(%rsp), %rbp
movl %edx, 0x24(%rsp)
movq 0x78(%rsp), %r15
testl %edx, %edx
movss 0x8(%rsp), %xmm1
jle 0x3a0e
movq 0x70(%rsp), %rax
movq 0x18(%rsp), %rcx
addl %ecx, %eax
movl %eax, 0x2c(%rsp)
movq 0x68(%rsp), %rax
addl %ecx, %eax
movl %eax, 0x30(%rsp)
xorl %ebx, %ebx
xorps %xmm0, %xmm0
cvtsi2ss %ebx, %xmm0
divss %xmm1, %xmm0
movss %xmm0, 0x10(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
callq 0x2340
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x2060
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, %xmm1
addss 0x3765(%rip), %xmm1     # 0x7008
movaps 0x50(%rsp), %xmm3
movaps %xmm3, %xmm2
cmpeqss %xmm0, %xmm2
andps %xmm2, %xmm1
andnps %xmm0, %xmm2
orps %xmm1, %xmm2
movaps %xmm2, %xmm1
cmpeqss 0x28(%rsp), %xmm1
movaps %xmm1, %xmm0
andnps %xmm2, %xmm0
andps 0x90(%rsp), %xmm1
orps %xmm0, %xmm1
movaps %xmm1, 0x40(%rsp)
movaps %xmm3, %xmm0
addss 0x3728(%rip), %xmm0     # 0x700c
cmpeqss %xmm3, %xmm1
andps %xmm1, %xmm0
andnps %xmm3, %xmm1
orps %xmm0, %xmm1
movaps %xmm1, 0x50(%rsp)
movaps %xmm1, %xmm0
addss 0xc(%rsp), %xmm0
cvttss2si %xmm0, %rsi
movq %r15, %rdi
movl 0x2c(%rsp), %r14d
movl %r14d, %edx
callq 0x4f20
movl (%rax), %edi
movaps 0x40(%rsp), %xmm0
subss 0x10(%rsp), %xmm0
movss %xmm0, 0x34(%rsp)
movq %r12, %rsi
callq 0x536c
movl %eax, %r13d
movaps 0x40(%rsp), %xmm0
addss 0xc(%rsp), %xmm0
cvttss2si %xmm0, %rsi
movq %r15, %rdi
movl %r14d, %edx
callq 0x4f20
movl (%rax), %edi
movss 0x10(%rsp), %xmm0
subss 0x50(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movq %rbp, %rsi
callq 0x536c
movq %r12, %rbp
movl %eax, %r12d
shrl $0x8, %r12d
movl %eax, %ecx
shrl $0x10, %ecx
movl %r13d, %esi
shrl $0x8, %esi
movl %r13d, %edi
shrl $0x10, %edi
movl %r13d, %edx
andl $0xff000000, %edx       # imm = 0xFF000000
movl $0xff, %r8d
andl %r8d, %r13d
andl %r8d, %eax
addl %r13d, %eax
movq 0x38(%rsp), %r13
movq 0x88(%rsp), %r14
cmpl %r8d, %eax
cmovael %r8d, %eax
andl %r8d, %esi
andl %r8d, %r12d
addl %esi, %r12d
cmpl %r8d, %r12d
cmovael %r8d, %r12d
andl %r8d, %edi
andl %r8d, %ecx
addl %edi, %ecx
cmpl %r8d, %ecx
cmovael %r8d, %ecx
shll $0x10, %ecx
orl %edx, %ecx
shll $0x8, %r12d
orl %eax, %r12d
orl %ecx, %r12d
leal (%rbx,%r13), %esi
movq %r14, %rdi
movl 0x30(%rsp), %edx
callq 0x53f2
movss 0x8(%rsp), %xmm1
movl 0x24(%rsp), %edx
movl %r12d, (%rax)
movq %rbp, %r12
leaq 0x14(%rsp), %rbp
incl %ebx
cmpl %ebx, %edx
jne 0x3860
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
cmpl 0x80(%rsp), %eax
jne 0x3835
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq