// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movq $0x0, 0x18(%rdi)
movq (%rsi), %rdi
leaq 0x168c(%rip), %rsi      # 0x40c8
callq 0x21c0
testq %rax, %rax
je 0x2b7d
movq %rax, %r15
leaq 0x374c(%rip), %rdi      # 0x61a0
movl $0xc8, %esi
movq %rax, %rdx
callq 0x2220
testq %rax, %rax
je 0x2c1c
movzwl 0x372f(%rip), %eax      # 0x61a0
cmpl $0x3650, %eax           # imm = 0x3650
jne 0x2c1c
leaq 0x371d(%rip), %r13      # 0x61a0
movq %r13, %rdi
movl $0xc8, %esi
movq %r15, %rdx
callq 0x2220
testq %rax, %rax
je 0x2aa1
cmpb $0x23, 0x3701(%rip)     # 0x61a0
je 0x2a83
leaq 0x4(%rbx), %rcx
leaq 0x36f4(%rip), %rdi      # 0x61a0
leaq 0x1631(%rip), %rsi      # 0x40e4
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2160
cmpl $0x2, %eax
jne 0x2ca9
cmpl $0x0, (%rbx)
jle 0x2ca9
cmpl $0x0, 0x4(%rbx)
jle 0x2ca9
leaq 0x36c0(%rip), %r13      # 0x61a0
movq %r13, %rdi
movl $0xc8, %esi
movq %r15, %rdx
callq 0x2220
testq %rax, %rax
je 0x2afe
cmpb $0x23, 0x36a4(%rip)     # 0x61a0
je 0x2ae0
leaq 0x369b(%rip), %rdi      # 0x61a0
leaq 0x15db(%rip), %rsi      # 0x40e7
leaq 0x2c(%rsp), %rdx
xorl %eax, %eax
callq 0x2160
cmpl $0x1, %eax
jne 0x2d36
cmpl $0xff, 0x2c(%rsp)
jne 0x2d36
movl 0x4(%rbx), %r13d
imull (%rbx), %r13d
leal (%r13,%r13,2), %esi
movq %r14, %rdi
callq 0x3360
movq (%r14), %rdi
movl %r13d, %r13d
movl $0x3, %esi
movq %r13, %rdx
movq %r15, %rcx
callq 0x21f0
cmpq %r13, %rax
jne 0x2dc3
movq %r15, %rdi
callq 0x2180
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 (%r12), %rsi
movq 0x8(%r12), %rdx
callq 0x21b0
movq %rax, %r15
leaq 0x1527(%rip), %rsi      # 0x40cb
movl $0x1, %edx
movq %rax, %rdi
callq 0x21b0
callq 0x2030
movl (%rax), %edi
callq 0x2070
movq %r15, %rdi
movq %rax, %rsi
callq 0x2170
movl $0x10, %edi
callq 0x20d0
movq %rax, %r12
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x2230
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x22b0
leaq 0x3195(%rip), %rax      # 0x5d90
movq %rax, (%r12)
xorl %ebp, %ebp
leaq 0x3160(%rip), %rsi      # 0x5d68
movq 0x33c9(%rip), %rdx      # 0x5fd8
movq %r12, %rdi
callq 0x2260
jmp 0x2eb9
leaq 0x30(%rsp), %rdi
callq 0x2100
leaq 0x40(%rsp), %rdi
movq (%r12), %rsi
movq 0x8(%r12), %rdx
callq 0x21b0
leaq 0x148d(%rip), %rsi      # 0x40cd
movl $0x16, %edx
movq %rax, %rdi
callq 0x21b0
movq %r15, %rdi
callq 0x2180
movl $0x10, %edi
callq 0x20d0
movq %rax, %r12
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x2230
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x22b0
leaq 0x3108(%rip), %rax      # 0x5d90
movq %rax, (%r12)
xorl %ebp, %ebp
leaq 0x30d3(%rip), %rsi      # 0x5d68
movq 0x333c(%rip), %rdx      # 0x5fd8
movq %r12, %rdi
callq 0x2260
jmp 0x2eb9
leaq 0x30(%rsp), %rdi
callq 0x2100
leaq 0x40(%rsp), %rdi
movq (%r12), %rsi
movq 0x8(%r12), %rdx
callq 0x21b0
leaq 0x141d(%rip), %rsi      # 0x40ea
movl $0x13, %edx
movq %rax, %rdi
callq 0x21b0
movq %r15, %rdi
callq 0x2180
movl $0x10, %edi
callq 0x20d0
movq %rax, %r12
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x2230
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x22b0
leaq 0x307b(%rip), %rax      # 0x5d90
movq %rax, (%r12)
xorl %ebp, %ebp
leaq 0x3046(%rip), %rsi      # 0x5d68
movq 0x32af(%rip), %rdx      # 0x5fd8
movq %r12, %rdi
callq 0x2260
jmp 0x2eb9
leaq 0x30(%rsp), %rdi
callq 0x2100
leaq 0x40(%rsp), %rdi
movq (%r12), %rsi
movq 0x8(%r12), %rdx
callq 0x21b0
leaq 0x13a4(%rip), %rsi      # 0x40fe
movl $0x19, %edx
movq %rax, %rdi
callq 0x21b0
movq %r15, %rdi
callq 0x2180
movl $0x10, %edi
callq 0x20d0
movq %rax, %r12
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x2230
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x22b0
leaq 0x2fee(%rip), %rax      # 0x5d90
movq %rax, (%r12)
xorl %ebp, %ebp
leaq 0x2fb9(%rip), %rsi      # 0x5d68
movq 0x3222(%rip), %rdx      # 0x5fd8
movq %r12, %rdi
callq 0x2260
jmp 0x2eb9
leaq 0x30(%rsp), %rdi
callq 0x2100
movq %r15, %rdi
callq 0x2290
testl %eax, %eax
jne 0x2e06
movq %r15, %rdi
callq 0x2210
leaq 0x40(%rsp), %rdi
movq (%r12), %rsi
movq 0x8(%r12), %rdx
testl %eax, %eax
jne 0x2e49
callq 0x21b0
movl $0x17, %edx
leaq 0x1326(%rip), %rsi      # 0x412a
jmp 0x2e5a
leaq 0x40(%rsp), %rdi
movq (%r12), %rsi
movq 0x8(%r12), %rdx
callq 0x21b0
movq %rax, %r12
leaq 0x12a8(%rip), %rsi      # 0x40cb
movl $0x1, %edx
movq %rax, %rdi
callq 0x21b0
callq 0x2030
movl (%rax), %edi
callq 0x2070
movq %r12, %rdi
movq %rax, %rsi
callq 0x2170
jmp 0x2e62
callq 0x21b0
movl $0x11, %edx
leaq 0x12be(%rip), %rsi      # 0x4118
movq %rax, %rdi
callq 0x21b0
movq %r15, %rdi
callq 0x2180
movl $0x10, %edi
callq 0x20d0
movq %rax, %r12
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x2230
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x22b0
leaq 0x2ef3(%rip), %rax      # 0x5d90
movq %rax, (%r12)
xorl %ebp, %ebp
leaq 0x2ebe(%rip), %rsi      # 0x5d68
movq 0x3127(%rip), %rdx      # 0x5fd8
movq %r12, %rdi
callq 0x2260
jmp 0x2ec9
jmp 0x2eee
jmp 0x2ec9
jmp 0x2eee
jmp 0x2ec9
jmp 0x2eee
jmp 0x2ec9
jmp 0x2eee
movq %rax, %r15
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ee7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21a0
testb %bpl, %bpl
jne 0x2ef1
jmp 0x2f06
movq %rax, %r15
movq %r12, %rdi
callq 0x2120
jmp 0x2f06
jmp 0x2f03
jmp 0x2f03
jmp 0x2f03
jmp 0x2f03
movq %rax, %r15
movq 0x30ab(%rip), %rsi      # 0x5fb8
leaq 0x30(%rsp), %rdi
callq 0x2130
leaq 0xb0(%rsp), %rdi
callq 0x2060
jmp 0x2f33
jmp 0x2f30
jmp 0x2f30
jmp 0x2f30
jmp 0x2f30
jmp 0x2f30
movq %rax, %r15
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2f47
movq 0x18(%rbx), %rsi
subq %rdi, %rsi
callq 0x21a0
movq %r15, %rdi
callq 0x2270
nop