// File: /workspace/github_cpp_makefile_star2_O3/wcochran[P]pano_to_cube/PPM.cpp
// Function: PPM::write(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void PPM::write(const std::string& fname) { // throws BogusPPM
  FILE *f = fopen(fname.c_str(), "wb");
  if (f == nullptr) {
    std::stringstream ss;
    ss << fname << ":" << strerror(errno);
    throw BogusPPM(ss.str());
  }
  fprintf(f, "P6\n%d %d\n255\n", W, H);
  if (fwrite(&pixels[0], 3, W*H, f) != W*H) {
    std::stringstream ss;
    if (ferror(f))
      ss << fname << ":" << strerror(errno);
    else if (feof(f))
      ss << fname << ": unexpected EOF!";
    else
      ss << fname << ": unable to write pixels";
    fclose(f);
    throw BogusPPM(ss.str());
  }
  fclose(f);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rsi, %r14
movq %rdi, %r15
movq (%rsi), %rdi
leaq 0x11d5(%rip), %rsi      # 0x4142
callq 0x21c0
testq %rax, %rax
je 0x2fd7
movq %rax, %rbx
movl (%r15), %edx
movl 0x4(%r15), %ecx
leaq 0x11bd(%rip), %rsi      # 0x4145
movq %rax, %rdi
xorl %eax, %eax
callq 0x21e0
movq 0x8(%r15), %rdi
movslq (%r15), %rax
movslq 0x4(%r15), %rdx
imulq %rax, %rdx
movl $0x3, %esi
movq %rbx, %rcx
callq 0x22a0
movslq (%r15), %rcx
movslq 0x4(%r15), %rdx
imulq %rcx, %rdx
cmpq %rdx, %rax
jne 0x306f
movq %rbx, %rdi
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2180
leaq 0x20(%rsp), %rdi
callq 0x2100
leaq 0x30(%rsp), %rdi
movq (%r14), %rsi
movq 0x8(%r14), %rdx
callq 0x21b0
movq %rax, %rbx
leaq 0x10cf(%rip), %rsi      # 0x40cb
movl $0x1, %edx
movq %rax, %rdi
callq 0x21b0
callq 0x2030
movl (%rax), %edi
callq 0x2070
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2170
movl $0x10, %edi
callq 0x20d0
movq %rax, %r14
leaq 0x38(%rsp), %rsi
movq %rsp, %rdi
callq 0x2230
movb $0x1, %bpl
movq %rsp, %rsi
movq %r14, %rdi
callq 0x22b0
leaq 0x2d41(%rip), %rax      # 0x5d90
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x2d0d(%rip), %rsi      # 0x5d68
movq 0x2f76(%rip), %rdx      # 0x5fd8
movq %r14, %rdi
callq 0x2260
jmp 0x315c
leaq 0x20(%rsp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x2290
testl %eax, %eax
jne 0x30b0
movq %rbx, %rdi
callq 0x2210
leaq 0x30(%rsp), %rdi
movq (%r14), %rsi
movq 0x8(%r14), %rdx
testl %eax, %eax
jne 0x30f1
callq 0x21b0
movl $0x18, %edx
leaq 0x10a5(%rip), %rsi      # 0x4153
jmp 0x3102
leaq 0x30(%rsp), %rdi
movq (%r14), %rsi
movq 0x8(%r14), %rdx
callq 0x21b0
movq %rax, %r14
leaq 0x1000(%rip), %rsi      # 0x40cb
movl $0x1, %edx
movq %rax, %rdi
callq 0x21b0
callq 0x2030
movl (%rax), %edi
callq 0x2070
movq %r14, %rdi
movq %rax, %rsi
callq 0x2170
jmp 0x310a
callq 0x21b0
movl $0x11, %edx
leaq 0x1016(%rip), %rsi      # 0x4118
movq %rax, %rdi
callq 0x21b0
movq %rbx, %rdi
callq 0x2180
movl $0x10, %edi
callq 0x20d0
movq %rax, %r14
leaq 0x38(%rsp), %rsi
movq %rsp, %rdi
callq 0x2230
movb $0x1, %bpl
movq %rsp, %rsi
movq %r14, %rdi
callq 0x22b0
leaq 0x2c4f(%rip), %rax      # 0x5d90
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x2c1b(%rip), %rsi      # 0x5d68
movq 0x2e84(%rip), %rdx      # 0x5fd8
movq %r14, %rdi
callq 0x2260
jmp 0x3160
jmp 0x3185
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x317e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
testb %bpl, %bpl
jne 0x3188
jmp 0x3197
movq %rax, %rbx
movq %r14, %rdi
callq 0x2120
jmp 0x3197
jmp 0x3194
movq %rax, %rbx
movq 0x2e1a(%rip), %rsi      # 0x5fb8
leaq 0x20(%rsp), %rdi
callq 0x2130
leaq 0xa0(%rsp), %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2270
nop