// File: /workspace/github_cpp_makefile_star2_O3/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, 0x80(%rsp)
movsd %xmm2, 0x78(%rsp)
movsd %xmm1, 0x70(%rsp)
movq %rcx, %rbx
movsd %xmm0, 0x68(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rsi
xorl %eax, %eax
leaq 0x38(%rsp), %rdi
movq %rax, (%rdi)
movl %eax, 0x8(%rdi)
movq %rax, 0x10(%rdi)
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl $0x4, %edx
callq 0x26e8
testb %al, %al
je 0x3b97
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movl $0x4, %edx
callq 0x26e8
testb %al, %al
je 0x3b97
leaq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2a20
testb %al, %al
je 0x3b51
movq 0x18611(%rip), %rdi     # 0x1bfd0
leaq 0x129e8(%rip), %rsi     # 0x163ae
movl $0xb, %edx
callq 0x2220
movl 0x38(%rsp), %esi
movq 0x185f5(%rip), %rdi     # 0x1bfd0
callq 0x2370
movq %rsp, %rsi
movb $0x78, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
movl 0x3c(%rsp), %esi
movq %rax, %rdi
callq 0x2370
movq %rsp, %rsi
movb $0x20, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
movl 0x40(%rsp), %esi
movq %rax, %rdi
callq 0x2370
movq %rax, %r15
leaq 0x12992(%rip), %rsi     # 0x163ba
movl $0xf, %edx
movq %rax, %rdi
callq 0x2220
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
xorl %eax, %eax
movq %rax, 0x10(%rsi)
leaq 0x50(%rsp), %rdx
movq %rax, 0x10(%rdx)
movaps %xmm0, (%rdx)
movq %r14, %rdi
callq 0x354d
testb %al, %al
je 0x3bbc
movq 0x18542(%rip), %rdi     # 0x1bfd0
leaq 0x12935(%rip), %rsi     # 0x163ca
movl $0x5, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x5, %rsi
movq 0x1851d(%rip), %rdi     # 0x1bfd0
callq 0x2130
movq %rax, %r14
leaq 0x1281d(%rip), %rsi     # 0x162df
movl $0x9, %edx
movq %rax, %rdi
callq 0x2220
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq 0x88(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %rsp, %rcx
leaq 0x50(%rsp), %r8
movsd 0x68(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
movsd 0x78(%rsp), %xmm2
movsd 0x80(%rsp), %xmm3
callq 0x3427
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
callq 0x2830
movl %eax, %ebx
leaq 0x88(%rsp), %rdi
callq 0x2826
jmp 0x3bbe
movq 0x18498(%rip), %rbx     # 0x1bff0
leaq 0x12821(%rip), %rsi     # 0x16380
movl $0x2d, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq 0x18466(%rip), %rdi     # 0x1bff0
callq 0x2040
movq %rax, %rdi
callq 0x2140
xorl %ebx, %ebx
leaq 0x20(%rsp), %rdi
callq 0x2826
leaq 0x38(%rsp), %rdi
callq 0x2826
movl %ebx, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %r15
retq
xorl %ebx, %ebx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3bd5
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3b99
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
jmp 0x3b99
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x2826
jmp 0x3c04
jmp 0x3c01
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3c1b
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3c36
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
jmp 0x3c36
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2826
leaq 0x38(%rsp), %rdi
callq 0x2826
movq %rbx, %rdi
callq 0x2390