// File: /workspace/github_cpp_makefile_star2_O2/srajangarg[P]image-morph/src/morph.cpp
// Function: morphDriver(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, double, double, double)
bool
morphDriver(std::string const & img1_path, std::string const & img2_path, std::string const & seg_path, double t,
            std::string const & out_path, double a, double b, double p)
{
  // Load images, forcing both to 4-channel RGBA for compatibility
  Image img1, img2;
  if (!img1.load(img1_path, 4) || !img2.load(img2_path, 4))
    return false;

  if (!img1.hasSameDimsAs(img2))
  {
    std::cerr << "Both input images must be the same dimensions" << std::endl;
    return false;
  }

  std::cout << "Loaded two " << img1.width() << 'x' << img1.height() << ' ' << img1.numChannels() << "-channel images"
            << std::endl;

  // Load segments
  std::vector<LineSegment> seg1, seg2;
  if (!loadSegments(seg_path, seg1, seg2))
    return false;

  std::cout << "Read " << seg1.size() << " segments" << std::endl;

  Image morphed = morphImages(img1, img2, seg1, seg2, t, a, b, p);
  if (!morphed.save(out_path))
    return false;

  return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0xa0, %rsp
movsd %xmm3, 0x68(%rsp)
movsd %xmm2, 0x60(%rsp)
movsd %xmm1, 0x58(%rsp)
leaq 0x18(%rsp), %rax
andq $0x0, (%rax)
movq %rcx, %rbx
andl $0x0, 0x8(%rax)
movsd %xmm0, 0x50(%rsp)
andq $0x0, 0x10(%rax)
movq %rdx, %r14
andq $0x0, (%rsp)
movq %rsi, %r15
andl $0x0, 0x8(%rsp)
movq %rdi, %rsi
andq $0x0, 0x10(%rsp)
pushq $0x4
popq %rdx
movq %rax, %rdi
callq 0x26e0
testb %al, %al
je 0x36fd
movq %rsp, %rdi
pushq $0x4
popq %rdx
movq %r15, %rsi
callq 0x26e0
testb %al, %al
je 0x36fd
leaq 0x18(%rsp), %rdi
movq %rsp, %rsi
callq 0x290c
testb %al, %al
je 0x36e2
movq 0x11a10(%rip), %rdi     # 0x14fd0
leaq 0xbdc7(%rip), %rsi      # 0xf38e
callq 0x21f0
movl 0x18(%rsp), %esi
movq %rax, %rdi
callq 0x23d0
pushq $0x78
popq %rsi
movq %rax, %rdi
callq 0x2270
movl 0x1c(%rsp), %esi
movq %rax, %rdi
callq 0x23d0
pushq $0x20
popq %rsi
movq %rax, %rdi
callq 0x2270
movl 0x20(%rsp), %esi
movq %rax, %rdi
callq 0x23d0
leaq 0xbd8d(%rip), %rsi      # 0xf39a
movq %rax, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2110
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rsi
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
leaq 0x70(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
movq %r14, %rdi
callq 0x31fd
testb %al, %al
je 0x3720
movq 0x1197f(%rip), %rdi     # 0x14fd0
leaq 0xbd52(%rip), %rsi      # 0xf3aa
callq 0x21f0
movq 0x38(%rsp), %rsi
subq 0x30(%rsp), %rsi
sarq $0x5, %rsi
movq %rax, %rdi
callq 0x2170
leaq 0xbc45(%rip), %rsi      # 0xf2bf
movq %rax, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2110
leaq 0x88(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %rsp, %rdx
leaq 0x30(%rsp), %rcx
leaq 0x70(%rsp), %r8
movsd 0x50(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
movsd 0x68(%rsp), %xmm3
callq 0x30d7
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
callq 0x27be
movl %eax, %ebx
leaq 0x88(%rsp), %rdi
callq 0x27b4
jmp 0x3722
movq 0x11907(%rip), %rdi     # 0x14ff0
leaq 0xbc70(%rip), %rsi      # 0xf360
callq 0x21f0
movq %rax, %rdi
callq 0x2110
xorl %ebx, %ebx
movq %rsp, %rdi
callq 0x27b4
leaq 0x18(%rsp), %rdi
callq 0x27b4
movl %ebx, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %r15
retq
xorl %ebx, %ebx
leaq 0x70(%rsp), %rdi
callq 0x3f6c
leaq 0x30(%rsp), %rdi
callq 0x3f6c
jmp 0x36ff
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x27b4
jmp 0x374f
jmp 0x374c
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x3f6c
leaq 0x30(%rsp), %rdi
callq 0x3f6c
jmp 0x3768
movq %rax, %rbx
movq %rsp, %rdi
callq 0x27b4
leaq 0x18(%rsp), %rdi
callq 0x27b4
movq %rbx, %rdi
callq 0x23f0