// File: srajangarg[P]raytracer/src/core/Image.cpp
// Function: Image::save(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
bool
Image::save(std::string const & path) const
{
  if (path.length() >= 4)
  {
    std::string ext = toLower(path.substr(path.length() - 4, 4));
    bool ok = true;
    if (ext == ".png")
    {
      ok = (bool)stbi_write_png(path.c_str(), w, h, nc, buf, w * nc);
      if (ok) return true;
    }
    else if (ext == ".bmp")
    {
      ok = (bool)stbi_write_bmp(path.c_str(), w, h, nc, buf);
      if (ok) return true;
    }

    if (!ok)
    {
      std::cerr << "Error load image: " << path << std::endl;
      return false;
    }
  }

  std::cerr << "Unsupported output image format: " << path << std::endl;
  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
callq 0x55f0
cmpq $0x4, %rax
jb 0x62ad
movq -0x18(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x55f0
movq -0x88(%rbp), %rsi
movq %rax, %rdx
addq $-0x4, %rdx
leaq -0x58(%rbp), %rdi
movq %rdi, -0x80(%rbp)
movl $0x4, %ecx
callq 0x5420
movq -0x80(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x5c60
jmp 0x60fd
leaq -0x58(%rbp), %rdi
callq 0x5290
movb $0x1, -0x65(%rbp)
leaq 0x40f0e(%rip), %rsi     # 0x4701f
leaq -0x38(%rbp), %rdi
callq 0x64f0
movb %al, -0x89(%rbp)
jmp 0x6122
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x6131
jmp 0x61be
movq -0x18(%rbp), %rdi
callq 0x51a0
movq %rax, %rdi
movq -0x78(%rbp), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
movl 0x8(%rax), %ecx
movq 0x10(%rax), %r8
movl %esi, %r9d
imull %ecx, %r9d
callq 0x3a280
movl %eax, -0x90(%rbp)
jmp 0x6161
movl -0x90(%rbp), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x65(%rbp)
testb $0x1, -0x65(%rbp)
je 0x61bc
movb $0x1, -0x1(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x6297
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5290
jmp 0x62ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5290
jmp 0x62ed
jmp 0x6233
leaq 0x40e5f(%rip), %rsi     # 0x47024
leaq -0x38(%rbp), %rdi
callq 0x64f0
movb %al, -0x91(%rbp)
jmp 0x61d6
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x61e2
jmp 0x6231
movq -0x18(%rbp), %rdi
callq 0x51a0
movq %rax, %rdi
movq -0x78(%rbp), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
movl 0x8(%rax), %ecx
movq 0x10(%rax), %r8
callq 0x378e0
movl %eax, -0x98(%rbp)
jmp 0x620b
movl -0x98(%rbp), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x65(%rbp)
testb $0x1, -0x65(%rbp)
je 0x622f
movb $0x1, -0x1(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x6297
jmp 0x6231
jmp 0x6233
testb $0x1, -0x65(%rbp)
jne 0x6290
movq 0x55db0(%rip), %rdi     # 0x5bff0
leaq 0x40de2(%rip), %rsi     # 0x47029
callq 0x53e0
movq %rax, -0xa0(%rbp)
jmp 0x6255
movq -0xa0(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x53c0
movq %rax, -0xa8(%rbp)
jmp 0x626e
movq -0xa8(%rbp), %rdi
movq 0x55d34(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0x6283
movb $0x0, -0x1(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x6297
movl $0x0, -0x6c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5290
movl -0x6c(%rbp), %eax
testl %eax, %eax
je 0x62ab
jmp 0x62a9
jmp 0x62df
jmp 0x62ad
movq 0x55d3c(%rip), %rdi     # 0x5bff0
leaq 0x40d81(%rip), %rsi     # 0x4703c
callq 0x53e0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53c0
movq %rax, %rdi
movq 0x55cda(%rip), %rsi     # 0x5bfb0
callq 0x5440
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xb0, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x5720
nopw %cs:(%rax,%rax)