// File: 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
movq %rsp, %rbp
subq $0x950, %rsp            # imm = 0x950
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x8b0(%rbp)
addq $0x8, %rdi
movq %rdi, -0x8a8(%rbp)
callq 0x4910
movq -0x10(%rbp), %rdi
callq 0x20b0
movq %rax, %rdi
leaq 0x2657(%rip), %rsi      # 0x60c8
callq 0x2270
movq %rax, -0x8a0(%rbp)
jmp 0x3a7f
movq -0x8a0(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3bcc
leaq -0x1b0(%rbp), %rdi
callq 0x2130
jmp 0x3aa3
leaq -0x1a0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x8b8(%rbp)
jmp 0x3abc
movq -0x8b8(%rbp), %rdi
leaq 0x2601(%rip), %rsi      # 0x60cb
callq 0x21e0
movq %rax, -0x8c0(%rbp)
jmp 0x3ad8
callq 0x2030
movl (%rax), %edi
callq 0x2070
movq -0x8c0(%rbp), %rdi
movq %rax, %rsi
callq 0x21e0
jmp 0x3af5
movb $0x1, -0x1d1(%rbp)
movl $0x10, %edi
callq 0x20e0
movq %rax, -0x8c8(%rbp)
leaq -0x1d0(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x21d0
jmp 0x3b22
movq -0x8c8(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x4930
jmp 0x3b37
movq -0x8c8(%rbp), %rdi
movb $0x0, -0x1d1(%rbp)
leaq 0x5224(%rip), %rsi      # 0x8d70
leaq 0xe1d(%rip), %rdx       # 0x4970
callq 0x2320
jmp 0x42b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x429f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x3bbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x3ba2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x2110
testb $0x1, -0x1d1(%rbp)
jne 0x3bad
jmp 0x3bb9
movq -0x8c8(%rbp), %rdi
callq 0x2150
jmp 0x3bbb
leaq -0x1b0(%rbp), %rdi
callq 0x2160
jmp 0x429f
movq -0x18(%rbp), %rdx
leaq 0x5649(%rip), %rdi      # 0x9220
movl $0xc8, %esi
callq 0x22f0
movq %rax, -0x8d0(%rbp)
jmp 0x3bea
movq -0x8d0(%rbp), %rax
cmpq $0x0, %rax
je 0x3c18
leaq 0x24cf(%rip), %rdi      # 0x60cd
leaq 0x561b(%rip), %rsi      # 0x9220
movl $0x2, %edx
callq 0x20d0
cmpl $0x0, %eax
je 0x3d25
leaq -0x360(%rbp), %rdi
callq 0x2130
jmp 0x3c26
leaq -0x350(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x8d8(%rbp)
jmp 0x3c3f
movq -0x8d8(%rbp), %rdi
leaq 0x2483(%rip), %rsi      # 0x60d0
callq 0x21e0
jmp 0x3c54
movq -0x18(%rbp), %rdi
callq 0x21f0
jmp 0x3c5f
movb $0x1, -0x381(%rbp)
movl $0x10, %edi
callq 0x20e0
movq %rax, -0x8e0(%rbp)
leaq -0x380(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0x21d0
jmp 0x3c8c
movq -0x8e0(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0x4930
jmp 0x3ca1
movq -0x8e0(%rbp), %rdi
movb $0x0, -0x381(%rbp)
leaq 0x50ba(%rip), %rsi      # 0x8d70
leaq 0xcb3(%rip), %rdx       # 0x4970
callq 0x2320
jmp 0x42b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x3d14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x3cfb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x380(%rbp), %rdi
callq 0x2110
testb $0x1, -0x381(%rbp)
jne 0x3d06
jmp 0x3d12
movq -0x8e0(%rbp), %rdi
callq 0x2150
jmp 0x3d14
leaq -0x360(%rbp), %rdi
callq 0x2160
jmp 0x429f
jmp 0x3d27
movq -0x18(%rbp), %rdx
leaq 0x54ee(%rip), %rdi      # 0x9220
movl $0xc8, %esi
callq 0x22f0
movq %rax, -0x8e8(%rbp)
jmp 0x3d45
movq -0x8e8(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x8e9(%rbp)
je 0x3d6d
movsbl 0x54bf(%rip), %eax      # 0x9220
cmpl $0x23, %eax
sete %al
movb %al, -0x8e9(%rbp)
movb -0x8e9(%rbp), %al
testb $0x1, %al
jne 0x3d79
jmp 0x3d7b
jmp 0x3d27
movq -0x8b0(%rbp), %rdx
movq %rdx, %rcx
addq $0x4, %rcx
leaq 0x5490(%rip), %rdi      # 0x9220
leaq 0x2350(%rip), %rsi      # 0x60e7
movb $0x0, %al
callq 0x21c0
cmpl $0x2, %eax
jne 0x3dc0
movq -0x8b0(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x3dc0
movq -0x8b0(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jg 0x3ecd
leaq -0x510(%rbp), %rdi
callq 0x2130
jmp 0x3dce
leaq -0x500(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x8f8(%rbp)
jmp 0x3de7
movq -0x8f8(%rbp), %rdi
leaq 0x22f8(%rip), %rsi      # 0x60ed
callq 0x21e0
jmp 0x3dfc
movq -0x18(%rbp), %rdi
callq 0x21f0
jmp 0x3e07
movb $0x1, -0x531(%rbp)
movl $0x10, %edi
callq 0x20e0
movq %rax, -0x900(%rbp)
leaq -0x530(%rbp), %rdi
leaq -0x510(%rbp), %rsi
callq 0x21d0
jmp 0x3e34
movq -0x900(%rbp), %rdi
leaq -0x530(%rbp), %rsi
callq 0x4930
jmp 0x3e49
movq -0x900(%rbp), %rdi
movb $0x0, -0x531(%rbp)
leaq 0x4f12(%rip), %rsi      # 0x8d70
leaq 0xb0b(%rip), %rdx       # 0x4970
callq 0x2320
jmp 0x42b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x3ebc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x3ea3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x530(%rbp), %rdi
callq 0x2110
testb $0x1, -0x531(%rbp)
jne 0x3eae
jmp 0x3eba
movq -0x900(%rbp), %rdi
callq 0x2150
jmp 0x3ebc
leaq -0x510(%rbp), %rdi
callq 0x2160
jmp 0x429f
jmp 0x3ecf
movq -0x18(%rbp), %rdx
leaq 0x5346(%rip), %rdi      # 0x9220
movl $0xc8, %esi
callq 0x22f0
movq %rax, -0x908(%rbp)
jmp 0x3eed
movq -0x908(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x909(%rbp)
je 0x3f15
movsbl 0x5317(%rip), %eax      # 0x9220
cmpl $0x23, %eax
sete %al
movb %al, -0x909(%rbp)
movb -0x909(%rbp), %al
testb $0x1, %al
jne 0x3f21
jmp 0x3f23
jmp 0x3ecf
leaq 0x52f6(%rip), %rdi      # 0x9220
leaq 0x21b9(%rip), %rsi      # 0x60ea
leaq -0x538(%rbp), %rdx
movb $0x0, %al
callq 0x21c0
cmpl $0x1, %eax
jne 0x3f54
cmpl $0xff, -0x538(%rbp)
je 0x4061
leaq -0x6c0(%rbp), %rdi
callq 0x2130
jmp 0x3f62
leaq -0x6b0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x918(%rbp)
jmp 0x3f7b
movq -0x918(%rbp), %rdi
leaq 0x2178(%rip), %rsi      # 0x6101
callq 0x21e0
jmp 0x3f90
movq -0x18(%rbp), %rdi
callq 0x21f0
jmp 0x3f9b
movb $0x1, -0x6e1(%rbp)
movl $0x10, %edi
callq 0x20e0
movq %rax, -0x920(%rbp)
leaq -0x6e0(%rbp), %rdi
leaq -0x6c0(%rbp), %rsi
callq 0x21d0
jmp 0x3fc8
movq -0x920(%rbp), %rdi
leaq -0x6e0(%rbp), %rsi
callq 0x4930
jmp 0x3fdd
movq -0x920(%rbp), %rdi
movb $0x0, -0x6e1(%rbp)
leaq 0x4d7e(%rip), %rsi      # 0x8d70
leaq 0x977(%rip), %rdx       # 0x4970
callq 0x2320
jmp 0x42b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x4050
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x4037
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x6e0(%rbp), %rdi
callq 0x2110
testb $0x1, -0x6e1(%rbp)
jne 0x4042
jmp 0x404e
movq -0x920(%rbp), %rdi
callq 0x2150
jmp 0x4050
leaq -0x6c0(%rbp), %rdi
callq 0x2160
jmp 0x429f
movq -0x8b0(%rbp), %rdi
movl (%rdi), %eax
movl 0x4(%rdi), %ecx
imull %ecx, %eax
movl %eax, -0x6e8(%rbp)
addq $0x8, %rdi
movl -0x6e8(%rbp), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
movl %eax, %esi
callq 0x4990
jmp 0x408e
movq -0x8b0(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2d30
movq %rax, %rdi
movl -0x6e8(%rbp), %eax
movl %eax, %edx
movq -0x18(%rbp), %rcx
movl $0x3, %esi
callq 0x22c0
movq %rax, -0x928(%rbp)
jmp 0x40c4
movq -0x928(%rbp), %rax
movl -0x6e8(%rbp), %ecx
cmpq %rcx, %rax
je 0x428b
leaq -0x870(%rbp), %rdi
callq 0x2130
jmp 0x40e8
movq -0x18(%rbp), %rdi
callq 0x2380
cmpl $0x0, %eax
je 0x415e
leaq -0x860(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x930(%rbp)
jmp 0x410f
movq -0x930(%rbp), %rdi
leaq 0x1fae(%rip), %rsi      # 0x60cb
callq 0x21e0
movq %rax, -0x938(%rbp)
jmp 0x412b
callq 0x2030
movl (%rax), %edi
callq 0x2070
movq -0x938(%rbp), %rdi
movq %rax, %rsi
callq 0x21e0
jmp 0x4148
jmp 0x41ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x427d
movq -0x18(%rbp), %rdi
callq 0x22e0
cmpl $0x0, %eax
je 0x419c
leaq -0x860(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x940(%rbp)
jmp 0x4185
movq -0x940(%rbp), %rdi
leaq 0x1f88(%rip), %rsi      # 0x611b
callq 0x21e0
jmp 0x419a
jmp 0x41cc
leaq -0x860(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21b0
movq %rax, -0x948(%rbp)
jmp 0x41b5
movq -0x948(%rbp), %rdi
leaq 0x1f6a(%rip), %rsi      # 0x612d
callq 0x21e0
jmp 0x41ca
jmp 0x41cc
jmp 0x41ce
movq -0x18(%rbp), %rdi
callq 0x21f0
jmp 0x41d9
movb $0x1, -0x891(%rbp)
movl $0x10, %edi
callq 0x20e0
movq %rax, -0x950(%rbp)
leaq -0x890(%rbp), %rdi
leaq -0x870(%rbp), %rsi
callq 0x21d0
jmp 0x4206
movq -0x950(%rbp), %rdi
leaq -0x890(%rbp), %rsi
callq 0x4930
jmp 0x421b
movq -0x950(%rbp), %rdi
movb $0x0, -0x891(%rbp)
leaq 0x4b40(%rip), %rsi      # 0x8d70
leaq 0x739(%rip), %rdx       # 0x4970
callq 0x2320
jmp 0x42b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x4264
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x890(%rbp), %rdi
callq 0x2110
testb $0x1, -0x891(%rbp)
jne 0x426f
jmp 0x427b
movq -0x950(%rbp), %rdi
callq 0x2150
jmp 0x427d
leaq -0x870(%rbp), %rdi
callq 0x2160
jmp 0x429f
movq -0x18(%rbp), %rdi
callq 0x21f0
jmp 0x4296
addq $0x950, %rsp            # imm = 0x950
popq %rbp
retq
movq -0x8a8(%rbp), %rdi
callq 0x2ea0
movq -0x20(%rbp), %rdi
callq 0x2330
nopw %cs:(%rax,%rax)