// File: 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:
subq $0x68, %rsp
movq %rsi, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movss %xmm0, 0x3c(%rsp)
movl 0x5c(%rsp), %eax
subl 0x64(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0x58(%rsp), %eax
subl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
cvtsi2ssl 0x34(%rsp), %xmm0
mulss 0x3c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x3420
cvttsd2si %xmm0, %eax
movl %eax, 0x30(%rsp)
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x38(%rsp), %eax
jge 0x4ce6
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x30(%rsp), %eax
jge 0x4cd4
cvtsi2ssl 0x1c(%rsp), %xmm0
divss 0x3c(%rsp), %xmm0
movss %xmm0, 0x2c(%rsp)
movss 0x2c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x3420
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x28(%rsp)
movss 0x2c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x3070
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
movss 0x28(%rsp), %xmm0
ucomiss 0x24(%rsp), %xmm0
jne 0x4b9e
jp 0x4b9e
movss 0x9476(%rip), %xmm0     # 0xe008
addss 0x24(%rsp), %xmm0
movss %xmm0, 0x24(%rsp)
movss 0x24(%rsp), %xmm0
cvtsi2ssl 0x34(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jne 0x4bc2
jp 0x4bc2
movl 0x34(%rsp), %eax
subl $0x1, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x24(%rsp)
movss 0x28(%rsp), %xmm0
ucomiss 0x24(%rsp), %xmm0
jne 0x4be9
jp 0x4be9
movss 0x28(%rsp), %xmm0
movss 0x9429(%rip), %xmm1     # 0xe008
subss %xmm1, %xmm0
movss %xmm0, 0x28(%rsp)
movq 0x48(%rsp), %rdi
cvtsi2ssl 0x60(%rsp), %xmm0
movss 0x28(%rsp), %xmm1
addss %xmm1, %xmm0
cvttss2si %xmm0, %rax
movl %eax, %esi
movl 0x64(%rsp), %edx
movl 0x20(%rsp), %eax
addl %eax, %edx
callq 0x7170
movl (%rax), %eax
movl %eax, 0x10(%rsp)
movss 0x24(%rsp), %xmm0
movss 0x2c(%rsp), %xmm1
subss %xmm1, %xmm0
movss %xmm0, 0xc(%rsp)
movl 0x10(%rsp), %edi
leaq 0xc(%rsp), %rsi
callq 0x7790
movl %eax, 0x14(%rsp)
movq 0x48(%rsp), %rdi
cvtsi2ssl 0x60(%rsp), %xmm0
movss 0x24(%rsp), %xmm1
addss %xmm1, %xmm0
cvttss2si %xmm0, %rax
movl %eax, %esi
movl 0x64(%rsp), %edx
addl 0x20(%rsp), %edx
callq 0x7170
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movss 0x2c(%rsp), %xmm0
subss 0x28(%rsp), %xmm0
movss %xmm0, (%rsp)
movl 0x4(%rsp), %edi
movq %rsp, %rsi
callq 0x7790
movl %eax, 0x8(%rsp)
movl 0x14(%rsp), %edi
leaq 0x8(%rsp), %rsi
callq 0x7760
movl %eax, 0x18(%rsp)
movq 0x40(%rsp), %rdi
movl 0x50(%rsp), %esi
addl 0x1c(%rsp), %esi
movl 0x54(%rsp), %edx
addl 0x20(%rsp), %edx
callq 0x77c0
movl 0x18(%rsp), %ecx
movl %ecx, (%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x4b29
jmp 0x4cd6
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x4b13
addq $0x68, %rsp
retq
nopl (%rax,%rax)