// File: /workspace/github_cpp_makefile_star2_O2/wcochran[P]pano_to_cube/PPM.cpp
// Function: PPM::PPM(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
PPM::PPM(const std::string& fname) {
  FILE *f = fopen(fname.c_str(), "rb");
  if (f == nullptr) {
    std::stringstream ss;
    ss << fname << ":" << strerror(errno);
    throw BogusPPM(ss.str());
  }
  static char buf[200];
  if (fgets(buf, sizeof(buf), f) == 0 || strncmp("P6",buf,2) != 0) {
    std::stringstream ss;
    ss << fname << ": not a raw PPM image!";
    fclose(f);
    throw BogusPPM(ss.str());
  }
  while (fgets(buf, sizeof(buf), f) != 0 && buf[0] == '#')
    ;
  if (sscanf(buf, "%d %d", &W, &H) != 2 || W <= 0 || H <= 0) {
    std::stringstream ss;
    ss << fname << ": has a bogus size!";
    fclose(f);
    throw BogusPPM(ss.str());
  }
  int maxval;
  while (fgets(buf, sizeof(buf), f) != 0 && buf[0] == '#')
    ;
  if (sscanf(buf, "%d", &maxval) != 1 || maxval != 255) {
    std::stringstream ss;
    ss << fname << ": max pixel value != 255!";
    fclose(f);
    throw BogusPPM(ss.str());
  }
  const unsigned numPixels = W*H;
  pixels.resize(3*numPixels);
  if (fread(&pixels[0], 3, numPixels, f) != numPixels) {
    std::stringstream ss;
    if (ferror(f))
      ss << fname << ":" << strerror(errno);
    else if (feof(f))
      ss << fname << ": unexpected EOF!";
    else
      ss << fname << ": unable to read pixels";
    fclose(f);
    throw BogusPPM(ss.str());
  }
  fclose(f);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rsi, %r15
movq %rdi, %r12
leaq 0x8(%rdi), %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
andq $0x0, 0x18(%rdi)
movq (%rsi), %rdi
leaq 0x16bb(%rip), %rsi      # 0x40c8
callq 0x21c0
testq %rax, %rax
je 0x2b50
movq %rax, %r14
leaq 0x377b(%rip), %rdi      # 0x61a0
movl $0xc8, %esi
movq %rax, %rdx
callq 0x2220
testq %rax, %rax
je 0x2bd7
cmpw $0x3650, 0x375c(%rip)   # imm = 0x3650
jne 0x2bd7
leaq 0x374f(%rip), %r13      # 0x61a0
movq %r13, %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x2220
testq %rax, %rax
je 0x2a6f
cmpb $0x23, 0x3733(%rip)     # 0x61a0
je 0x2a51
leaq 0x4(%r12), %rcx
leaq 0x3725(%rip), %rdi      # 0x61a0
leaq 0x1662(%rip), %rsi      # 0x40e4
movq %r12, %rdx
xorl %eax, %eax
callq 0x2170
cmpl $0x2, %eax
jne 0x2c4c
cmpl $0x0, (%r12)
jle 0x2c4c
cmpl $0x0, 0x4(%r12)
jle 0x2c4c
leaq 0x36ed(%rip), %r13      # 0x61a0
movq %r13, %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x2220
testq %rax, %rax
je 0x2ad1
cmpb $0x23, 0x36d1(%rip)     # 0x61a0
je 0x2ab3
leaq 0x36c8(%rip), %rdi      # 0x61a0
leaq 0x1608(%rip), %rsi      # 0x40e7
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x2170
cmpl $0x1, %eax
jne 0x2cc1
cmpl $0xff, 0xc(%rsp)
jne 0x2cc1
movl 0x4(%r12), %r13d
imull (%r12), %r13d
leal (%r13,%r13,2), %esi
movq %rbx, %rdi
callq 0x321c
movq (%rbx), %rdi
movl %r13d, %r12d
pushq $0x3
popq %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x21f0
cmpq %r12, %rax
jne 0x2d36
movq %r14, %rdi
callq 0x2190
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30(%rsp), %rdi
callq 0x2100
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x2160
leaq 0x155d(%rip), %rsi      # 0x40cb
movq %rax, %rdi
callq 0x2180
movq %rax, %r14
callq 0x2030
movl (%rax), %edi
callq 0x2060
movq %r14, %rdi
movq %rax, %rsi
callq 0x2180
pushq $0x10
popq %rdi
callq 0x20d0
movq %rax, %r15
leaq 0x48(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x2230
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x3206
xorl %ebp, %ebp
leaq 0x31ad(%rip), %rsi      # 0x5d70
movq 0x340e(%rip), %rdx      # 0x5fd8
movq %r15, %rdi
callq 0x2260
jmp 0x2e07
leaq 0x30(%rsp), %rdi
callq 0x2100
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x2160
leaq 0x14d8(%rip), %rsi      # 0x40cd
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
callq 0x2190
pushq $0x10
popq %rdi
callq 0x20d0
movq %rax, %r15
leaq 0x48(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x2230
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x3206
xorl %ebp, %ebp
leaq 0x3138(%rip), %rsi      # 0x5d70
movq 0x3399(%rip), %rdx      # 0x5fd8
movq %r15, %rdi
callq 0x2260
jmp 0x2e07
leaq 0x30(%rsp), %rdi
callq 0x2100
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x2160
leaq 0x1480(%rip), %rsi      # 0x40ea
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
callq 0x2190
pushq $0x10
popq %rdi
callq 0x20d0
movq %rax, %r15
leaq 0x48(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x2230
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x3206
xorl %ebp, %ebp
leaq 0x30c3(%rip), %rsi      # 0x5d70
movq 0x3324(%rip), %rdx      # 0x5fd8
movq %r15, %rdi
callq 0x2260
jmp 0x2e07
leaq 0x30(%rsp), %rdi
callq 0x2100
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x2160
leaq 0x141f(%rip), %rsi      # 0x40fe
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
callq 0x2190
pushq $0x10
popq %rdi
callq 0x20d0
movq %rax, %r15
leaq 0x48(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x2230
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x3206
xorl %ebp, %ebp
leaq 0x304e(%rip), %rsi      # 0x5d70
movq 0x32af(%rip), %rdx      # 0x5fd8
movq %r15, %rdi
callq 0x2260
jmp 0x2e07
leaq 0x30(%rsp), %rdi
callq 0x2100
movq %r14, %rdi
callq 0x2290
testl %eax, %eax
jne 0x2d6e
movq %r14, %rdi
callq 0x2210
leaq 0x40(%rsp), %rdi
testl %eax, %eax
jne 0x2da6
movq %r15, %rsi
callq 0x2160
leaq 0x13be(%rip), %rsi      # 0x412a
jmp 0x2db5
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x2160
leaq 0x1349(%rip), %rsi      # 0x40cb
movq %rax, %rdi
callq 0x2180
movq %rax, %r15
callq 0x2030
movl (%rax), %edi
callq 0x2060
movq %r15, %rdi
movq %rax, %rsi
callq 0x2180
jmp 0x2dbd
movq %r15, %rsi
callq 0x2160
leaq 0x1363(%rip), %rsi      # 0x4118
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
callq 0x2190
pushq $0x10
popq %rdi
callq 0x20d0
movq %rax, %r15
leaq 0x48(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x2230
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x3206
xorl %ebp, %ebp
leaq 0x2f78(%rip), %rsi      # 0x5d70
movq 0x31d9(%rip), %rdx      # 0x5fd8
movq %r15, %rdi
callq 0x2260
jmp 0x2e17
jmp 0x2e2b
jmp 0x2e17
jmp 0x2e2b
jmp 0x2e17
jmp 0x2e2b
jmp 0x2e17
jmp 0x2e2b
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x20b0
testb %bpl, %bpl
jne 0x2e2e
jmp 0x2e43
movq %rax, %r14
movq %r15, %rdi
callq 0x2120
jmp 0x2e43
jmp 0x2e40
jmp 0x2e40
jmp 0x2e40
jmp 0x2e40
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x2130
jmp 0x2e5c
jmp 0x2e59
jmp 0x2e59
jmp 0x2e59
jmp 0x2e59
jmp 0x2e59
movq %rax, %r14
movq %rbx, %rdi
callq 0x28cc
movq %r14, %rdi
callq 0x2270