// File: iibrahimli[P]adsa_project/src/../include/util.hpp
// Function: merge(std::vector<BMP_image const*, std::allocator<BMP_image const*>>)
BMP_image merge(std::vector<const BMP_image *> imgs){
    // calculate total width
    unsigned int res_width = 0;
    for(auto i : imgs) res_width += i->info_h.width;

    BMP_image res(res_width, imgs[0]->info_h.height);

    int c_width = 0;

    for(int n=0; n<imgs.size(); ++n){
        for(int j=0; j<res.info_h.height; ++j){
            for(int i=0; i<imgs[n]->info_h.width; ++i){
                res(c_width+i, j) = imgs[n]->ploc(i, j);
            }
        }
        c_width += imgs[n]->info_h.width;
    }

    // interpolate touching regions to smooth out stitches
    c_width = imgs[0]->info_h.width;
    for(int n=1; n<imgs.size(); ++n){
        for(int j=0; j<res.info_h.height; ++j){
            res(c_width, j)   = res(c_width-4, j)*0.5       + res(c_width+4, j)*0.5;
            res(c_width-1, j) = res(c_width-4, j)*(5.0/8.0) + res(c_width+4, j)*(3.0/8.0);
            res(c_width+1, j) = res(c_width-4, j)*(3.0/8.0) + res(c_width+4, j)*(5.0/8.0);
            res(c_width-2, j) = res(c_width-4, j)*(6.0/8.0) + res(c_width+4, j)*(2.0/8.0);
            res(c_width+2, j) = res(c_width-4, j)*(2.0/8.0) + res(c_width+4, j)*(6.0/8.0);
            res(c_width-3, j) = res(c_width-4, j)*(7.0/8.0) + res(c_width+4, j)*(1.0/8.0);
            res(c_width+3, j) = res(c_width-4, j)*(1.0/8.0) + res(c_width+4, j)*(7.0/8.0);
            // res(c_width-4, j) = res(c_width-6, j)*(10.0/12.0) + res(c_width+6, j)*(2.0 /12.0);
            // res(c_width+4, j) = res(c_width-6, j)*(2.0 /12.0) + res(c_width+6, j)*(10.0/12.0);
            // res(c_width-5, j) = res(c_width-6, j)*(11.0/12.0) + res(c_width+6, j)*(1.0 /12.0);
            // res(c_width+5, j) = res(c_width-6, j)*(1.0 /12.0) + res(c_width+6, j)*(11.0/12.0);
        }
        c_width += imgs[n]->info_h.width;
    }

    return res;
}

// Assembly:
subq $0x288, %rsp            # imm = 0x288
movq %rsi, 0x148(%rsp)
movq %rdi, 0x150(%rsp)
movq %rdi, %rax
movq %rax, 0x158(%rsp)
movq %rdi, 0x280(%rsp)
movq %rsi, 0x278(%rsp)
movl $0x0, 0x274(%rsp)
movq %rsi, 0x268(%rsp)
movq 0x268(%rsp), %rdi
callq 0x8350
movq %rax, 0x260(%rsp)
movq 0x268(%rsp), %rdi
callq 0x8380
movq %rax, 0x258(%rsp)
leaq 0x260(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x83b0
testb $0x1, %al
jne 0x579a
jmp 0x57da
leaq 0x260(%rsp), %rdi
callq 0x83f0
movq (%rax), %rax
movq %rax, 0x250(%rsp)
movq 0x250(%rsp), %rax
movl 0x12(%rax), %eax
addl 0x274(%rsp), %eax
movl %eax, 0x274(%rsp)
leaq 0x260(%rsp), %rdi
callq 0x8400
jmp 0x577f
movq 0x148(%rsp), %rdi
movb $0x0, 0x24f(%rsp)
movl 0x274(%rsp), %eax
movl %eax, 0x140(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x8420
movq (%rax), %rax
movl 0x16(%rax), %eax
movl %eax, 0x144(%rsp)
leaq 0x24b(%rsp), %rdi
movl $0xff, %r8d
movl %r8d, %esi
movl %r8d, %edx
movl %r8d, %ecx
callq 0x8070
movq 0x150(%rsp), %rdi
movl 0x140(%rsp), %esi
movl 0x144(%rsp), %edx
movl 0x24b(%rsp), %ecx
movl $0x1, %r8d
callq 0x80b0
movl $0x0, 0x244(%rsp)
movl $0x0, 0x240(%rsp)
movq 0x148(%rsp), %rdi
movslq 0x240(%rsp), %rax
movq %rax, 0x138(%rsp)
callq 0x8440
movq %rax, %rcx
movq 0x138(%rsp), %rax
cmpq %rcx, %rax
jae 0x5a0a
movl $0x0, 0x23c(%rsp)
movq 0x150(%rsp), %rcx
movl 0x23c(%rsp), %eax
cmpl 0x16(%rcx), %eax
jge 0x59cb
movl $0x0, 0x238(%rsp)
movq 0x148(%rsp), %rdi
movl 0x238(%rsp), %eax
movl %eax, 0x134(%rsp)
movslq 0x240(%rsp), %rsi
callq 0x8420
movq %rax, %rcx
movl 0x134(%rsp), %eax
movq (%rcx), %rcx
cmpl 0x12(%rcx), %eax
jge 0x59b3
movq 0x148(%rsp), %rdi
movslq 0x240(%rsp), %rsi
callq 0x8420
movq (%rax), %rdi
movl 0x238(%rsp), %esi
movl 0x23c(%rsp), %edx
callq 0x7170
movq %rax, 0x128(%rsp)
jmp 0x5935
movq 0x150(%rsp), %rdi
movl 0x244(%rsp), %esi
movl 0x238(%rsp), %eax
addl %eax, %esi
movl 0x23c(%rsp), %edx
callq 0x77c0
movq %rax, 0x120(%rsp)
jmp 0x5963
movq 0x120(%rsp), %rax
movq 0x128(%rsp), %rcx
movl (%rcx), %ecx
movl %ecx, (%rax)
movl 0x238(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x238(%rsp)
jmp 0x58c7
movq 0x150(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
callq 0x8310
jmp 0x6360
jmp 0x59b5
movl 0x23c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x23c(%rsp)
jmp 0x58a4
movq 0x148(%rsp), %rdi
movslq 0x240(%rsp), %rsi
callq 0x8420
movq (%rax), %rax
movl 0x12(%rax), %eax
addl 0x244(%rsp), %eax
movl %eax, 0x244(%rsp)
movl 0x240(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x240(%rsp)
jmp 0x5868
movq 0x148(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8420
movq (%rax), %rax
movl 0x12(%rax), %eax
movl %eax, 0x244(%rsp)
movl $0x1, 0x228(%rsp)
movq 0x148(%rsp), %rdi
movslq 0x228(%rsp), %rax
movq %rax, 0x118(%rsp)
callq 0x8440
movq %rax, %rcx
movq 0x118(%rsp), %rax
cmpq %rcx, %rax
jae 0x6331
movl $0x0, 0x224(%rsp)
movq 0x150(%rsp), %rcx
movl 0x224(%rsp), %eax
cmpl 0x16(%rcx), %eax
jge 0x62f2
movq 0x150(%rsp), %rdi
movl 0x244(%rsp), %esi
addl $-0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x110(%rsp)
jmp 0x5aaf
movq 0x110(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x218(%rsp)
movl $0x3f000000, 0x214(%rsp) # imm = 0x3F000000
movl 0x218(%rsp), %edi
leaq 0x214(%rsp), %rsi
callq 0x7790
movl %eax, 0x10c(%rsp)
jmp 0x5ae8
movq 0x150(%rsp), %rdi
movl 0x10c(%rsp), %eax
movl %eax, 0x21c(%rsp)
movl 0x244(%rsp), %esi
addl $0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x100(%rsp)
jmp 0x5b1e
movq 0x100(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x20c(%rsp)
movl $0x3f000000, 0x208(%rsp) # imm = 0x3F000000
movl 0x20c(%rsp), %edi
leaq 0x208(%rsp), %rsi
callq 0x7790
movl %eax, 0xfc(%rsp)
jmp 0x5b57
movl 0xfc(%rsp), %eax
movl %eax, 0x210(%rsp)
movl 0x21c(%rsp), %edi
leaq 0x210(%rsp), %rsi
callq 0x7760
movl %eax, 0xf8(%rsp)
jmp 0x5b82
movq 0x150(%rsp), %rdi
movl 0xf8(%rsp), %eax
movl %eax, 0x220(%rsp)
movl 0x244(%rsp), %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0xf0(%rsp)
jmp 0x5bb5
movq 0x150(%rsp), %rdi
movq 0xf0(%rsp), %rax
movl 0x220(%rsp), %ecx
movl %ecx, (%rax)
movl 0x244(%rsp), %esi
addl $-0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0xe8(%rsp)
jmp 0x5bee
movq 0xe8(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x1fc(%rsp)
movl $0x3f200000, 0x1f8(%rsp) # imm = 0x3F200000
movl 0x1fc(%rsp), %edi
leaq 0x1f8(%rsp), %rsi
callq 0x7790
movl %eax, 0xe4(%rsp)
jmp 0x5c27
movq 0x150(%rsp), %rdi
movl 0xe4(%rsp), %eax
movl %eax, 0x200(%rsp)
movl 0x244(%rsp), %esi
addl $0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0xd8(%rsp)
jmp 0x5c5d
movq 0xd8(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x1f0(%rsp)
movl $0x3ec00000, 0x1ec(%rsp) # imm = 0x3EC00000
movl 0x1f0(%rsp), %edi
leaq 0x1ec(%rsp), %rsi
callq 0x7790
movl %eax, 0xd4(%rsp)
jmp 0x5c96
movl 0xd4(%rsp), %eax
movl %eax, 0x1f4(%rsp)
movl 0x200(%rsp), %edi
leaq 0x1f4(%rsp), %rsi
callq 0x7760
movl %eax, 0xd0(%rsp)
jmp 0x5cc1
movq 0x150(%rsp), %rdi
movl 0xd0(%rsp), %eax
movl %eax, 0x204(%rsp)
movl 0x244(%rsp), %esi
decl %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0xc8(%rsp)
jmp 0x5cf6
movq 0x150(%rsp), %rdi
movq 0xc8(%rsp), %rax
movl 0x204(%rsp), %ecx
movl %ecx, (%rax)
movl 0x244(%rsp), %esi
addl $-0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0xc0(%rsp)
jmp 0x5d2f
movq 0xc0(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x1e0(%rsp)
movl $0x3ec00000, 0x1dc(%rsp) # imm = 0x3EC00000
movl 0x1e0(%rsp), %edi
leaq 0x1dc(%rsp), %rsi
callq 0x7790
movl %eax, 0xbc(%rsp)
jmp 0x5d68
movq 0x150(%rsp), %rdi
movl 0xbc(%rsp), %eax
movl %eax, 0x1e4(%rsp)
movl 0x244(%rsp), %esi
addl $0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0xb0(%rsp)
jmp 0x5d9e
movq 0xb0(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x1d4(%rsp)
movl $0x3f200000, 0x1d0(%rsp) # imm = 0x3F200000
movl 0x1d4(%rsp), %edi
leaq 0x1d0(%rsp), %rsi
callq 0x7790
movl %eax, 0xac(%rsp)
jmp 0x5dd7
movl 0xac(%rsp), %eax
movl %eax, 0x1d8(%rsp)
movl 0x1e4(%rsp), %edi
leaq 0x1d8(%rsp), %rsi
callq 0x7760
movl %eax, 0xa8(%rsp)
jmp 0x5e02
movq 0x150(%rsp), %rdi
movl 0xa8(%rsp), %eax
movl %eax, 0x1e8(%rsp)
movl 0x244(%rsp), %esi
incl %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0xa0(%rsp)
jmp 0x5e37
movq 0x150(%rsp), %rdi
movq 0xa0(%rsp), %rax
movl 0x1e8(%rsp), %ecx
movl %ecx, (%rax)
movl 0x244(%rsp), %esi
addl $-0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x98(%rsp)
jmp 0x5e70
movq 0x98(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x1c4(%rsp)
movl $0x3f400000, 0x1c0(%rsp) # imm = 0x3F400000
movl 0x1c4(%rsp), %edi
leaq 0x1c0(%rsp), %rsi
callq 0x7790
movl %eax, 0x94(%rsp)
jmp 0x5ea9
movq 0x150(%rsp), %rdi
movl 0x94(%rsp), %eax
movl %eax, 0x1c8(%rsp)
movl 0x244(%rsp), %esi
addl $0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x88(%rsp)
jmp 0x5edf
movq 0x88(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x1b8(%rsp)
movl $0x3e800000, 0x1b4(%rsp) # imm = 0x3E800000
movl 0x1b8(%rsp), %edi
leaq 0x1b4(%rsp), %rsi
callq 0x7790
movl %eax, 0x84(%rsp)
jmp 0x5f18
movl 0x84(%rsp), %eax
movl %eax, 0x1bc(%rsp)
movl 0x1c8(%rsp), %edi
leaq 0x1bc(%rsp), %rsi
callq 0x7760
movl %eax, 0x80(%rsp)
jmp 0x5f43
movq 0x150(%rsp), %rdi
movl 0x80(%rsp), %eax
movl %eax, 0x1cc(%rsp)
movl 0x244(%rsp), %esi
addl $-0x2, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x78(%rsp)
jmp 0x5f76
movq 0x150(%rsp), %rdi
movq 0x78(%rsp), %rax
movl 0x1cc(%rsp), %ecx
movl %ecx, (%rax)
movl 0x244(%rsp), %esi
addl $-0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x70(%rsp)
jmp 0x5fa9
movq 0x70(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x1a8(%rsp)
movl $0x3e800000, 0x1a4(%rsp) # imm = 0x3E800000
movl 0x1a8(%rsp), %edi
leaq 0x1a4(%rsp), %rsi
callq 0x7790
movl %eax, 0x6c(%rsp)
jmp 0x5fdc
movq 0x150(%rsp), %rdi
movl 0x6c(%rsp), %eax
movl %eax, 0x1ac(%rsp)
movl 0x244(%rsp), %esi
addl $0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x60(%rsp)
jmp 0x600c
movq 0x60(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x19c(%rsp)
movl $0x3f400000, 0x198(%rsp) # imm = 0x3F400000
movl 0x19c(%rsp), %edi
leaq 0x198(%rsp), %rsi
callq 0x7790
movl %eax, 0x5c(%rsp)
jmp 0x603f
movl 0x5c(%rsp), %eax
movl %eax, 0x1a0(%rsp)
movl 0x1ac(%rsp), %edi
leaq 0x1a0(%rsp), %rsi
callq 0x7760
movl %eax, 0x58(%rsp)
jmp 0x6064
movq 0x150(%rsp), %rdi
movl 0x58(%rsp), %eax
movl %eax, 0x1b0(%rsp)
movl 0x244(%rsp), %esi
addl $0x2, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x50(%rsp)
jmp 0x6094
movq 0x150(%rsp), %rdi
movq 0x50(%rsp), %rax
movl 0x1b0(%rsp), %ecx
movl %ecx, (%rax)
movl 0x244(%rsp), %esi
addl $-0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x48(%rsp)
jmp 0x60c7
movq 0x48(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x18c(%rsp)
movl $0x3f600000, 0x188(%rsp) # imm = 0x3F600000
movl 0x18c(%rsp), %edi
leaq 0x188(%rsp), %rsi
callq 0x7790
movl %eax, 0x44(%rsp)
jmp 0x60fa
movq 0x150(%rsp), %rdi
movl 0x44(%rsp), %eax
movl %eax, 0x190(%rsp)
movl 0x244(%rsp), %esi
addl $0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x38(%rsp)
jmp 0x612a
movq 0x38(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x180(%rsp)
movl $0x3e000000, 0x17c(%rsp) # imm = 0x3E000000
movl 0x180(%rsp), %edi
leaq 0x17c(%rsp), %rsi
callq 0x7790
movl %eax, 0x34(%rsp)
jmp 0x615d
movl 0x34(%rsp), %eax
movl %eax, 0x184(%rsp)
movl 0x190(%rsp), %edi
leaq 0x184(%rsp), %rsi
callq 0x7760
movl %eax, 0x30(%rsp)
jmp 0x6182
movq 0x150(%rsp), %rdi
movl 0x30(%rsp), %eax
movl %eax, 0x194(%rsp)
movl 0x244(%rsp), %esi
addl $-0x3, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x28(%rsp)
jmp 0x61b2
movq 0x150(%rsp), %rdi
movq 0x28(%rsp), %rax
movl 0x194(%rsp), %ecx
movl %ecx, (%rax)
movl 0x244(%rsp), %esi
addl $-0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x20(%rsp)
jmp 0x61e5
movq 0x20(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x170(%rsp)
movl $0x3e000000, 0x16c(%rsp) # imm = 0x3E000000
movl 0x170(%rsp), %edi
leaq 0x16c(%rsp), %rsi
callq 0x7790
movl %eax, 0x1c(%rsp)
jmp 0x6218
movq 0x150(%rsp), %rdi
movl 0x1c(%rsp), %eax
movl %eax, 0x174(%rsp)
movl 0x244(%rsp), %esi
addl $0x4, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, 0x10(%rsp)
jmp 0x6248
movq 0x10(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x164(%rsp)
movl $0x3f600000, 0x160(%rsp) # imm = 0x3F600000
movl 0x164(%rsp), %edi
leaq 0x160(%rsp), %rsi
callq 0x7790
movl %eax, 0xc(%rsp)
jmp 0x627b
movl 0xc(%rsp), %eax
movl %eax, 0x168(%rsp)
movl 0x174(%rsp), %edi
leaq 0x168(%rsp), %rsi
callq 0x7760
movl %eax, 0x8(%rsp)
jmp 0x62a0
movq 0x150(%rsp), %rdi
movl 0x8(%rsp), %eax
movl %eax, 0x178(%rsp)
movl 0x244(%rsp), %esi
addl $0x3, %esi
movl 0x224(%rsp), %edx
callq 0x77c0
movq %rax, (%rsp)
jmp 0x62cf
movq (%rsp), %rax
movl 0x178(%rsp), %ecx
movl %ecx, (%rax)
movl 0x224(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x224(%rsp)
jmp 0x5a6f
movq 0x148(%rsp), %rdi
movslq 0x228(%rsp), %rsi
callq 0x8420
movq (%rax), %rax
movl 0x12(%rax), %eax
addl 0x244(%rsp), %eax
movl %eax, 0x244(%rsp)
movl 0x228(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x228(%rsp)
jmp 0x5a33
movb $0x1, 0x24f(%rsp)
testb $0x1, 0x24f(%rsp)
jne 0x6350
movq 0x150(%rsp), %rdi
callq 0x8310
movq 0x158(%rsp), %rax
addq $0x288, %rsp            # imm = 0x288
retq
movq 0x230(%rsp), %rdi
callq 0x3460
nopl (%rax)