// File: 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
movq %rsp, %rbp
subq $0x3d0, %rsp            # imm = 0x3D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x390(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20b0
movq %rax, %rdi
leaq 0x1e54(%rip), %rsi      # 0x6145
callq 0x2270
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x443b
leaq -0x1a0(%rbp), %rdi
callq 0x2130
leaq -0x190(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x398(%rbp)
jmp 0x432a
movq -0x398(%rbp), %rdi
leaq 0x1d93(%rip), %rsi      # 0x60cb
callq 0x21e0
movq %rax, -0x3a0(%rbp)
jmp 0x4346
callq 0x2030
movl (%rax), %edi
callq 0x2070
movq -0x3a0(%rbp), %rdi
movq %rax, %rsi
callq 0x21e0
jmp 0x4363
movb $0x1, -0x1d1(%rbp)
movl $0x10, %edi
callq 0x20e0
movq %rax, -0x3a8(%rbp)
leaq -0x1d0(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x21d0
jmp 0x4390
movq -0x3a8(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x4930
jmp 0x43a5
movq -0x3a8(%rbp), %rdi
movb $0x0, -0x1d1(%rbp)
leaq 0x49b6(%rip), %rsi      # 0x8d70
leaq 0x5af(%rip), %rdx       # 0x4970
callq 0x2320
jmp 0x4686
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x442a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x4411
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x2110
testb $0x1, -0x1d1(%rbp)
jne 0x441c
jmp 0x4428
movq -0x3a8(%rbp), %rdi
callq 0x2150
jmp 0x442a
leaq -0x1a0(%rbp), %rdi
callq 0x2160
jmp 0x467a
movq -0x390(%rbp), %rax
movq -0x18(%rbp), %rdi
movl (%rax), %edx
movl 0x4(%rax), %ecx
leaq 0x1cf6(%rip), %rsi      # 0x6148
movb $0x0, %al
callq 0x22a0
movq -0x390(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2d30
movq -0x390(%rbp), %rcx
movq %rax, %rdi
movl (%rcx), %eax
imull 0x4(%rcx), %eax
movslq %eax, %rdx
movq -0x18(%rbp), %rcx
movl $0x3, %esi
callq 0x2390
movq -0x390(%rbp), %rdx
movl (%rdx), %ecx
imull 0x4(%rdx), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0x4668
leaq -0x360(%rbp), %rdi
callq 0x2130
movq -0x18(%rbp), %rdi
callq 0x2380
cmpl $0x0, %eax
je 0x452f
leaq -0x350(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x3b0(%rbp)
jmp 0x44da
movq -0x3b0(%rbp), %rdi
leaq 0x1be3(%rip), %rsi      # 0x60cb
callq 0x21e0
movq %rax, -0x3b8(%rbp)
jmp 0x44f6
callq 0x2030
movl (%rax), %edi
callq 0x2070
movq -0x3b8(%rbp), %rdi
movq %rax, %rsi
callq 0x21e0
jmp 0x4513
jmp 0x459f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x465a
movq -0x18(%rbp), %rdi
callq 0x22e0
cmpl $0x0, %eax
je 0x456d
leaq -0x350(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x3c0(%rbp)
jmp 0x4556
movq -0x3c0(%rbp), %rdi
leaq 0x1bb7(%rip), %rsi      # 0x611b
callq 0x21e0
jmp 0x456b
jmp 0x459d
leaq -0x350(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x3c8(%rbp)
jmp 0x4586
movq -0x3c8(%rbp), %rdi
leaq 0x1bc2(%rip), %rsi      # 0x6156
callq 0x21e0
jmp 0x459b
jmp 0x459d
jmp 0x459f
movq -0x18(%rbp), %rdi
callq 0x21f0
jmp 0x45aa
movb $0x1, -0x381(%rbp)
movl $0x10, %edi
callq 0x20e0
movq %rax, -0x3d0(%rbp)
leaq -0x380(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0x21d0
jmp 0x45d7
movq -0x3d0(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0x4930
jmp 0x45ec
movq -0x3d0(%rbp), %rdi
movb $0x0, -0x381(%rbp)
leaq 0x476f(%rip), %rsi      # 0x8d70
leaq 0x368(%rip), %rdx       # 0x4970
callq 0x2320
jmp 0x4686
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x4641
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x380(%rbp), %rdi
callq 0x2110
testb $0x1, -0x381(%rbp)
jne 0x464c
jmp 0x4658
movq -0x3d0(%rbp), %rdi
callq 0x2150
jmp 0x465a
leaq -0x360(%rbp), %rdi
callq 0x2160
jmp 0x467a
movq -0x18(%rbp), %rdi
callq 0x21f0
addq $0x3d0, %rsp            # imm = 0x3D0
popq %rbp
retq
movq -0x1a8(%rbp), %rdi
callq 0x2330
nopw %cs:(%rax,%rax)