// File: /workspace/github_cpp_makefile_star2_O1/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 0x2710
testb %al, %al
je 0x3da7
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movl $0x4, %edx
callq 0x2710
testb %al, %al
je 0x3da7
leaq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2a56
testb %al, %al
je 0x3d61
movq 0x18401(%rip), %rdi     # 0x1bfd0
leaq 0x127d8(%rip), %rsi     # 0x163ae
movl $0xb, %edx
callq 0x2240
movl 0x38(%rsp), %esi
movq 0x183e5(%rip), %rdi     # 0x1bfd0
callq 0x2390
movq %rsp, %rsi
movb $0x78, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x2240
movl 0x3c(%rsp), %esi
movq %rax, %rdi
callq 0x2390
movq %rsp, %rsi
movb $0x20, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x2240
movl 0x40(%rsp), %esi
movq %rax, %rdi
callq 0x2390
movq %rax, %r15
leaq 0x12782(%rip), %rsi     # 0x163ba
movl $0xf, %edx
movq %rax, %rdi
callq 0x2240
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
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 0x372c
testb %al, %al
je 0x3dcc
movq 0x18332(%rip), %rdi     # 0x1bfd0
leaq 0x12725(%rip), %rsi     # 0x163ca
movl $0x5, %edx
callq 0x2240
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x5, %rsi
movq 0x1830d(%rip), %rdi     # 0x1bfd0
callq 0x2140
movq %rax, %r14
leaq 0x1260d(%rip), %rsi     # 0x162df
movl $0x9, %edx
movq %rax, %rdi
callq 0x2240
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
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 0x3606
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
callq 0x2858
movl %eax, %ebx
leaq 0x88(%rsp), %rdi
callq 0x284e
jmp 0x3dce
movq 0x18288(%rip), %rbx     # 0x1bff0
leaq 0x12611(%rip), %rsi     # 0x16380
movl $0x2d, %edx
movq %rbx, %rdi
callq 0x2240
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x18256(%rip), %rdi     # 0x1bff0
callq 0x2040
movq %rax, %rdi
callq 0x2150
xorl %ebx, %ebx
leaq 0x20(%rsp), %rdi
callq 0x284e
leaq 0x38(%rsp), %rdi
callq 0x284e
movl %ebx, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %r15
retq
xorl %ebx, %ebx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3de5
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3da9
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
jmp 0x3da9
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x284e
jmp 0x3e14
jmp 0x3e11
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3e2b
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3e46
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
jmp 0x3e46
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x284e
leaq 0x38(%rsp), %rdi
callq 0x284e
movq %rbx, %rdi
callq 0x23b0