// File: 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 %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movsd %xmm1, -0x38(%rbp)
movsd %xmm2, -0x40(%rbp)
movsd %xmm3, -0x48(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x6940
leaq -0x78(%rbp), %rdi
callq 0x6940
jmp 0x55e3
movq -0x10(%rbp), %rsi
leaq -0x60(%rbp), %rdi
movl $0x4, %edx
callq 0x39e0
movb %al, -0xd1(%rbp)
jmp 0x55fd
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x5609
jmp 0x562f
movq -0x18(%rbp), %rsi
leaq -0x78(%rbp), %rdi
movl $0x4, %edx
callq 0x39e0
movb %al, -0xd2(%rbp)
jmp 0x5623
movb -0xd2(%rbp), %al
testb $0x1, %al
jne 0x566a
jmp 0x562f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x5994
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x59bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x59b4
leaq -0x60(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3dc0
movb %al, -0xd3(%rbp)
jmp 0x567f
movb -0xd3(%rbp), %al
testb $0x1, %al
jne 0x56cf
jmp 0x568b
movq 0x1c95e(%rip), %rdi     # 0x21ff0
leaq 0x16ca7(%rip), %rsi     # 0x1c340
callq 0x32c0
movq %rax, -0xe0(%rbp)
jmp 0x56a7
movq -0xe0(%rbp), %rdi
movq 0x1c8fb(%rip), %rsi     # 0x21fb0
callq 0x3310
jmp 0x56bc
movb $0x0, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x5994
movq 0x1c8f2(%rip), %rdi     # 0x21fc8
leaq 0x16c91(%rip), %rsi     # 0x1c36e
callq 0x32c0
movq %rax, -0xe8(%rbp)
jmp 0x56eb
leaq -0x60(%rbp), %rdi
callq 0x5f80
movl %eax, -0xec(%rbp)
jmp 0x56fc
movl -0xec(%rbp), %esi
movq -0xe8(%rbp), %rdi
callq 0x3500
movq %rax, -0xf8(%rbp)
jmp 0x5717
movq -0xf8(%rbp), %rdi
movl $0x78, %esi
callq 0x3370
movq %rax, -0x100(%rbp)
jmp 0x5731
leaq -0x60(%rbp), %rdi
callq 0x5f90
movl %eax, -0x104(%rbp)
jmp 0x5742
movl -0x104(%rbp), %esi
movq -0x100(%rbp), %rdi
callq 0x3500
movq %rax, -0x110(%rbp)
jmp 0x575d
movq -0x110(%rbp), %rdi
movl $0x20, %esi
callq 0x3370
movq %rax, -0x118(%rbp)
jmp 0x5777
leaq -0x60(%rbp), %rdi
callq 0x5fb0
movl %eax, -0x11c(%rbp)
jmp 0x5788
movl -0x11c(%rbp), %esi
movq -0x118(%rbp), %rdi
callq 0x3500
movq %rax, -0x128(%rbp)
jmp 0x57a3
movq -0x128(%rbp), %rdi
leaq 0x16bc9(%rip), %rsi     # 0x1c37a
callq 0x32c0
movq %rax, -0x130(%rbp)
jmp 0x57bf
movq -0x130(%rbp), %rdi
movq 0x1c7e3(%rip), %rsi     # 0x21fb0
callq 0x3310
jmp 0x57d4
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x6970
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x6970
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rdx
movq -0x20(%rbp), %rdi
callq 0x5010
movb %al, -0x131(%rbp)
jmp 0x5819
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x584c
jmp 0x5825
movb $0x0, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x5960
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x597a
movq 0x1c775(%rip), %rdi     # 0x21fc8
leaq 0x16b30(%rip), %rsi     # 0x1c38a
callq 0x32c0
movq %rax, -0x150(%rbp)
jmp 0x5868
leaq -0xa0(%rbp), %rdi
callq 0x60c0
movq -0x150(%rbp), %rdi
movq %rax, %rsi
callq 0x3090
movq %rax, -0x158(%rbp)
jmp 0x588c
movq -0x158(%rbp), %rdi
leaq 0x16a05(%rip), %rsi     # 0x1c29f
callq 0x32c0
movq %rax, -0x160(%rbp)
jmp 0x58a8
movq -0x160(%rbp), %rdi
movq 0x1c6fa(%rip), %rsi     # 0x21fb0
callq 0x3310
jmp 0x58bd
movsd -0x28(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
movsd -0x48(%rbp), %xmm3
leaq -0xd0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x78(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
leaq -0xb8(%rbp), %r8
callq 0x4e80
jmp 0x58f5
movq -0x30(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x3b50
movb %al, -0x161(%rbp)
jmp 0x590d
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x5946
jmp 0x5919
movb $0x0, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x5954
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3b30
jmp 0x597a
movb $0x1, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3b30
leaq -0xb8(%rbp), %rdi
callq 0x6990
leaq -0xa0(%rbp), %rdi
callq 0x6990
jmp 0x5994
leaq -0xb8(%rbp), %rdi
callq 0x6990
leaq -0xa0(%rbp), %rdi
callq 0x6990
jmp 0x59b4
leaq -0x78(%rbp), %rdi
callq 0x3b30
leaq -0x60(%rbp), %rdi
callq 0x3b30
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0x3b30
leaq -0x60(%rbp), %rdi
callq 0x3b30
movq -0x80(%rbp), %rdi
callq 0x3520
nop