#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *next(int /*<<< orphan*/ *, char *, int);
int numread(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int sscanf(char const *, char *, int *, ...);
int /*<<< orphan*/ stderr;
char *strrchr(char const *, char);
int main(int argc, char *argv[]) {
  int ret = -1;
  const char *filename;
  const char *pos;
  char imgname_l[256];
  char imgname_u[256];
  char line_buf[256];
  int i, width, height, maxv, ppmascii = 0;
  FILE *fp = NULL;
  if (argc < 2) {
    fprintf(stderr, "Specify ppm file\n");
    return (0);
  }
  filename = argv[1];
  pos = strrchr(filename, '/');
  if (pos)
    snprintf(imgname_l, 256, "%s", pos + 1);
  else
    snprintf(imgname_l, 256, "%s", filename);
  for (i = 0; imgname_l[i] != '\0'; i++) {
    int valid = 0;
    int ch = ((unsigned char *)imgname_l)[i];
    if ('0' <= ch && ch <= '9')
      valid = 1;
    else if ('A' <= ch && ch <= 'Z')
      valid = 1;
    else if ('a' <= ch && ch <= 'z')
      valid = 1;
    else if (ch == '_')
      valid = 1;
    else if (ch == '.')
      break;
    if (valid == 0)
      imgname_l[i] = '_';
  }
  imgname_l[i] = '\0';
  for (i = 0; imgname_l[i] != '\0'; i++) {
    int ch = ((unsigned char *)imgname_l)[i];
    if ('a' <= ch && ch <= 'z')
      imgname_u[i] = ch - 0x0020;
    else
      imgname_u[i] = ch;
  }
  imgname_u[i] = '\0';
  fp = fopen(filename, "rb");
  if (fp == NULL) {
    fprintf(stderr, "Cannot open file: %s\n", filename);
    goto quit;
  }
  pos = next(fp, line_buf, 256);
  if (pos == NULL || pos[0] != 'P') {
    fprintf(stderr, "ERROR: Invalid stream (1)\n");
    goto quit;
  }
  if (pos[1] != '6' && pos[1] != '3') {
    fprintf(stderr, "ERROR: Invalid stream (2)\n");
    goto quit;
  }
  if (pos[1] == '3')
    ppmascii = 1;
  pos = next(fp, line_buf, 256);
  if (pos == NULL) {
    fprintf(stderr, "ERROR: Invalid stream (3)\n");
    goto quit;
  }
  i = sscanf(pos, "%d %d\n", &width, &height);
  if (i != 2) {
    fprintf(stderr, "ERROR: Invalid stream (4)\n");
    goto quit;
  }
  pos = next(fp, line_buf, 256);
  if (pos == NULL) {
    fprintf(stderr, "ERROR: Invalid stream (5)\n");
    goto quit;
  }
  i = sscanf(pos, "%d\n", &maxv);
  if (i != 1) {
    fprintf(stderr, "ERROR: Invalid stream (6)\n");
    goto quit;
  }
  printf("#define PPM_WIDTH_%s %d\n", imgname_u, width);
  printf("#define PPM_HEIGHT_%s %d\n", imgname_u, height);
  printf("unsigned char Ppm_image_%s[] = { \n", imgname_l);
  if (ppmascii) {
    for (i = 0; i < width * height * 3; i++) {
      if ((i % 3) == 0)
        printf("0xff,");
      printf("0x%02x", 255 * numread(fp) / maxv);
      if (i != (width * height * 3 - 1))
        printf(",");
      if (((i + 1) % 12) == 0)
        printf("\n");
    }
  } else {
    int vl;
    int nbytes = (maxv < 256) ? 1 : 2;
    for (i = 0; i < width * height * 3; i++) {
      if ((i % 3) == 0)
        printf("0xff,");
      vl = fgetc(fp);
      if (1 < nbytes) {
        vl <<= 8;
        vl |= fgetc(fp);
      }
      printf("0x%02x", 255 * vl / maxv);
      if (i != (width * height * 3 - 1))
        printf(",");
      if (((i + 1) % 12) == 0)
        printf("\n");
    }
  }
  printf("} ;\n");
  fclose(fp);
  fp = NULL;
  ret = 0;
quit:
  if (fp != NULL)
    fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x370,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x344(%rbp)
movq   $0x0,-0x350(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1202 <main+0x62>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1954 <main+0x7b4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1250 <main+0xb0>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
mov    $0x100,%esi
lea    0xdcc(%rip),%rdx
call   1060 <snprintf@plt>
jmp    126c <main+0xcc>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x100,%esi
lea    0xdab(%rip),%rdx
call   1060 <snprintf@plt>
movl   $0x0,-0x334(%rbp)
movslq -0x334(%rbp),%rax
movsbl -0x130(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     13ab <main+0x20b>
movl   $0x0,-0x354(%rbp)
movslq -0x334(%rbp),%rax
movzbl -0x130(%rbp,%rax,1),%eax
ff
mov    %eax,-0x358(%rbp)
mov    $0x30,%eax
cmp    -0x358(%rbp),%eax
jg     12da <main+0x13a>
cmpl   $0x39,-0x358(%rbp)
jg     12da <main+0x13a>
movl   $0x1,-0x354(%rbp)
jmp    1376 <main+0x1d6>
mov    $0x41,%eax
cmp    -0x358(%rbp),%eax
jg     1307 <main+0x167>
cmpl   $0x5a,-0x358(%rbp)
jg     1307 <main+0x167>
movl   $0x1,-0x354(%rbp)
jmp    1371 <main+0x1d1>
mov    $0x61,%eax
cmp    -0x358(%rbp),%eax
jg     1334 <main+0x194>
cmpl   $0x7a,-0x358(%rbp)
jg     1334 <main+0x194>
movl   $0x1,-0x354(%rbp)
jmp    136c <main+0x1cc>
cmpl   $0x5f,-0x358(%rbp)
jne    1350 <main+0x1b0>
movl   $0x1,-0x354(%rbp)
jmp    1367 <main+0x1c7>
cmpl   $0x2e,-0x358(%rbp)
jne    1362 <main+0x1c2>
jmp    13ab <main+0x20b>
jmp    1367 <main+0x1c7>
jmp    136c <main+0x1cc>
jmp    1371 <main+0x1d1>
jmp    1376 <main+0x1d6>
cmpl   $0x0,-0x354(%rbp)
jne    1392 <main+0x1f2>
movslq -0x334(%rbp),%rax
movb   $0x5f,-0x130(%rbp,%rax,1)
5f
jmp    1397 <main+0x1f7>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    1276 <main+0xd6>
movslq -0x334(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
movl   $0x0,-0x334(%rbp)
movslq -0x334(%rbp),%rax
movsbl -0x130(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     145c <main+0x2bc>
movslq -0x334(%rbp),%rax
movzbl -0x130(%rbp,%rax,1),%eax
ff
mov    %eax,-0x35c(%rbp)
mov    $0x61,%eax
cmp    -0x35c(%rbp),%eax
jg     142d <main+0x28d>
cmpl   $0x7a,-0x35c(%rbp)
jg     142d <main+0x28d>
mov    -0x35c(%rbp),%eax
sub    $0x20,%eax
mov    %al,%cl
movslq -0x334(%rbp),%rax
mov    %cl,-0x230(%rbp,%rax,1)
jmp    1443 <main+0x2a3>
mov    -0x35c(%rbp),%eax
mov    %al,%cl
movslq -0x334(%rbp),%rax
mov    %cl,-0x230(%rbp,%rax,1)
jmp    1448 <main+0x2a8>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    13c4 <main+0x224>
movslq -0x334(%rbp),%rax
movb   $0x0,-0x230(%rbp,%rax,1)
mov    -0x20(%rbp),%rdi
lea    0xb9f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x350(%rbp)
cmpq   $0x0,-0x350(%rbp)
jne    14b0 <main+0x310>
mov    0x2b49(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xb74(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1934 <main+0x794>
mov    -0x350(%rbp),%rdi
lea    -0x330(%rbp),%rsi
mov    $0x100,%edx
call   1090 <next@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     14e7 <main+0x347>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x50,%eax
je     1503 <main+0x363>
mov    0x2af2(%rip),%rax
mov    (%rax),%edi
lea    0xb37(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1934 <main+0x794>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x36,%eax
je     1541 <main+0x3a1>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x33,%eax
je     1541 <main+0x3a1>
mov    0x2ab4(%rip),%rax
mov    (%rax),%edi
lea    0xb14(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1934 <main+0x794>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x33,%eax
jne    155c <main+0x3bc>
movl   $0x1,-0x344(%rbp)
mov    -0x350(%rbp),%rdi
lea    -0x330(%rbp),%rsi
mov    $0x100,%edx
call   1090 <next@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    159f <main+0x3ff>
mov    0x2a56(%rip),%rax
mov    (%rax),%edi
lea    0xad1(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1934 <main+0x794>
mov    -0x28(%rbp),%rdi
lea    0xad5(%rip),%rsi
lea    -0x338(%rbp),%rdx
lea    -0x33c(%rbp),%rcx
mov    $0x0,%al
call   10b0 <sscanf@plt>
mov    %eax,-0x334(%rbp)
cmpl   $0x2,-0x334(%rbp)
je     15ee <main+0x44e>
mov    0x2a07(%rip),%rax
mov    (%rax),%edi
lea    0xaa4(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1934 <main+0x794>
mov    -0x350(%rbp),%rdi
lea    -0x330(%rbp),%rsi
mov    $0x100,%edx
call   1090 <next@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1631 <main+0x491>
mov    0x29c4(%rip),%rax
mov    (%rax),%edi
lea    0xa7c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1934 <main+0x794>
mov    -0x28(%rbp),%rdi
lea    0xa46(%rip),%rsi
lea    -0x340(%rbp),%rdx
mov    $0x0,%al
call   10b0 <sscanf@plt>
mov    %eax,-0x334(%rbp)
cmpl   $0x1,-0x334(%rbp)
je     1679 <main+0x4d9>
mov    0x297c(%rip),%rax
mov    (%rax),%edi
lea    0xa4f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1934 <main+0x794>
lea    -0x230(%rbp),%rsi
mov    -0x338(%rbp),%edx
lea    0xa4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x230(%rbp),%rsi
mov    -0x33c(%rbp),%edx
lea    0xa48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x130(%rbp),%rsi
lea    0xa4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x344(%rbp)
je     17bc <main+0x61c>
movl   $0x0,-0x334(%rbp)
mov    -0x334(%rbp),%eax
mov    -0x338(%rbp),%ecx
imul   -0x33c(%rbp),%ecx
imul   $0x3,%ecx,%ecx
cmp    %ecx,%eax
jge    17b7 <main+0x617>
mov    -0x334(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    171e <main+0x57e>
lea    0xa16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x350(%rbp),%rdi
call   1030 <numread@plt>
imul   $0xff,%eax,%eax
cltd
idivl  -0x340(%rbp)
mov    %eax,%esi
lea    0x9f3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x334(%rbp),%eax
mov    -0x338(%rbp),%ecx
imul   -0x33c(%rbp),%ecx
imul   $0x3,%ecx,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1776 <main+0x5d6>
lea    0x9c2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    179e <main+0x5fe>
lea    0x994(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    17a3 <main+0x603>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    16db <main+0x53b>
jmp    1908 <main+0x768>
mov    -0x340(%rbp),%edx
mov    $0x2,%eax
mov    $0x1,%ecx
cmp    $0x100,%edx
cmovl  %ecx,%eax
mov    %eax,-0x364(%rbp)
movl   $0x0,-0x334(%rbp)
mov    -0x334(%rbp),%eax
mov    -0x338(%rbp),%ecx
imul   -0x33c(%rbp),%ecx
imul   $0x3,%ecx,%ecx
cmp    %ecx,%eax
jge    1903 <main+0x763>
mov    -0x334(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1828 <main+0x688>
lea    0x90c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x350(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x360(%rbp)
mov    $0x1,%eax
cmp    -0x364(%rbp),%eax
jge    1872 <main+0x6d2>
mov    -0x360(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x360(%rbp)
mov    -0x350(%rbp),%rdi
call   1080 <fgetc@plt>
or     -0x360(%rbp),%eax
mov    %eax,-0x360(%rbp)
imul   $0xff,-0x360(%rbp),%eax
cltd
idivl  -0x340(%rbp)
mov    %eax,%esi
lea    0x8a7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x334(%rbp),%eax
mov    -0x338(%rbp),%ecx
imul   -0x33c(%rbp),%ecx
imul   $0x3,%ecx,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     18c2 <main+0x722>
lea    0x876(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    18ea <main+0x74a>
lea    0x848(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18ef <main+0x74f>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    17e5 <main+0x645>
jmp    1908 <main+0x768>
lea    0x82b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x350(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x350(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x350(%rbp)
je     194e <main+0x7ae>
mov    -0x350(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x370,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x318,%rsp
cmp    $0x1,%edi
jg     11f4 <main+0x34>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    1519 <main+0x359>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
test   %rax,%rax
je     1224 <main+0x64>
add    $0x1,%rax
lea    0xdfd(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rcx
jmp    1238 <main+0x78>
lea    0xde7(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
call   1080 <snprintf@plt>
mov    0x10(%rsp),%cl
lea    0x10(%rsp),%rax
jmp    125b <main+0x9b>
nopl   0x0(%rax,%rax,1)
movb   $0x5f,(%rax)
movzbl 0x1(%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
je     1281 <main+0xc1>
lea    -0x30(%rcx),%edx
cmp    $0xa,%dl
jb     1253 <main+0x93>
lea    -0x41(%rcx),%edx
cmp    $0x1a,%dl
jb     1253 <main+0x93>
lea    -0x61(%rcx),%edx
cmp    $0x1a,%dl
jb     1253 <main+0x93>
cmp    $0x5f,%cl
je     1253 <main+0x93>
cmp    $0x2e,%cl
jne    1250 <main+0x90>
movb   $0x0,(%rax)
mov    0x10(%rsp),%cl
xor    %eax,%eax
test   %cl,%cl
je     12b9 <main+0xf9>
xchg   %ax,%ax
lea    -0x61(%rcx),%edx
lea    -0x20(%rcx),%esi
cmp    $0x1a,%dl
movzbl %cl,%ecx
movzbl %sil,%edx
cmovae %ecx,%edx
mov    %dl,0x210(%rsp,%rax,1)
movzbl 0x11(%rsp,%rax,1),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1290 <main+0xd0>
mov    %eax,%eax
movb   $0x0,0x210(%rsp,%rax,1)
lea    0xd4d(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1408 <main+0x248>
mov    %rax,%r14
lea    0x110(%rsp),%rsi
mov    %rax,%rdi
mov    $0x100,%edx
call   10b0 <next@plt>
lea    0xd36(%rip),%rsi
test   %rax,%rax
je     14fc <main+0x33c>
cmpb   $0x50,(%rax)
jne    14fc <main+0x33c>
mov    0x1(%rax),%bl
cmp    $0x36,%bl
je     131b <main+0x15b>
cmp    $0x33,%bl
jne    14d1 <main+0x311>
lea    0x110(%rsp),%rsi
mov    %r14,%rdi
mov    $0x100,%edx
call   10b0 <next@plt>
test   %rax,%rax
je     14da <main+0x31a>
lea    0xd3f(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %rax,%rdi
xor    %eax,%eax
call   10d0 <sscanf@plt>
cmp    $0x2,%eax
jne    14e3 <main+0x323>
lea    0x110(%rsp),%rsi
mov    %r14,%rdi
mov    $0x100,%edx
call   10b0 <next@plt>
test   %rax,%rax
je     14ec <main+0x32c>
lea    0xd02(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   10d0 <sscanf@plt>
cmp    $0x1,%eax
jne    14f5 <main+0x335>
mov    0x4(%rsp),%edx
lea    0xd34(%rip),%rdi
lea    0x210(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rsp),%edx
lea    0xd31(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd3a(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x33,%bl
jne    152d <main+0x36d>
mov    0x4(%rsp),%eax
imul   (%rsp),%eax
lea    (%rax,%rax,2),%eax
test   %eax,%eax
jle    1620 <main+0x460>
mov    $0x1,%r12d
mov    $0xaaaaaaab,%r13d
xor    %ebx,%ebx
jmp    1440 <main+0x280>
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
lea    0xc00(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    1514 <main+0x354>
mov    0x4(%rsp),%eax
imul   (%rsp),%eax
lea    (%rax,%rax,2),%eax
add    $0x1,%r12d
mov    %ebp,%ebx
cmp    %eax,%ebp
jge    1620 <main+0x460>
mov    %r12d,%r15d
imul   %r13,%r15
mov    %ebx,%eax
imul   %r13,%rax
shr    $0x21,%rax
lea    (%rax,%rax,2),%eax
cmp    %ebx,%eax
jne    1466 <main+0x2a6>
lea    0xcce(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
shr    $0x23,%r15
mov    %r14,%rdi
call   1050 <numread@plt>
mov    %eax,%ecx
shl    $0x8,%ecx
sub    %eax,%ecx
mov    %ecx,%eax
cltd
idivl  0x8(%rsp)
lea    0xcac(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%rsp),%eax
imul   (%rsp),%eax
lea    (%rax,%rax,2),%eax
add    $0xffffffff,%eax
cmp    %eax,%ebx
je     14ac <main+0x2ec>
mov    $0x2c,%edi
call   1030 <putchar@plt>
lea    (%r15,%r15,2),%eax
lea    -0x1(,%rax,4),%eax
lea    0x1(%rbx),%ebp
cmp    %ebx,%eax
jne    1427 <main+0x267>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1427 <main+0x267>
lea    0xb71(%rip),%rsi
jmp    14fc <main+0x33c>
lea    0xb83(%rip),%rsi
jmp    14fc <main+0x33c>
lea    0xb9c(%rip),%rsi
jmp    14fc <main+0x33c>
lea    0xbae(%rip),%rsi
jmp    14fc <main+0x33c>
lea    0xbc0(%rip),%rsi
mov    0x2add(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x318,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x4(%rsp),%eax
imul   (%rsp),%eax
lea    (%rax,%rax,2),%eax
test   %eax,%eax
jle    1620 <main+0x460>
mov    0x8(%rsp),%eax
mov    %eax,0xc(%rsp)
mov    $0x1,%ebx
mov    $0xaaaaaaab,%r15d
xor    %r12d,%r12d
jmp    1571 <main+0x3b1>
mov    0x4(%rsp),%eax
imul   (%rsp),%eax
lea    (%rax,%rax,2),%eax
add    $0x1,%ebx
mov    %ebp,%r12d
cmp    %eax,%ebp
jge    1620 <main+0x460>
mov    %r12d,%eax
imul   %r15,%rax
shr    $0x21,%rax
lea    (%rax,%rax,2),%eax
cmp    %r12d,%eax
jne    1592 <main+0x3d2>
lea    0xba2(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%r13d
imul   %r15,%r13
mov    %r14,%rdi
call   10a0 <fgetc@plt>
mov    %eax,%ebp
cmpl   $0x100,0xc(%rsp)
jl     15ba <main+0x3fa>
shl    $0x8,%ebp
mov    %r14,%rdi
call   10a0 <fgetc@plt>
or     %eax,%ebp
shr    $0x23,%r13
mov    %ebp,%eax
shl    $0x8,%eax
sub    %ebp,%eax
cltd
idivl  0x8(%rsp)
lea    0xb62(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%rsp),%eax
imul   (%rsp),%eax
lea    (%rax,%rax,2),%eax
add    $0xffffffff,%eax
cmp    %eax,%r12d
je     15f7 <main+0x437>
mov    $0x2c,%edi
call   1030 <putchar@plt>
lea    0x0(%r13,%r13,2),%eax
lea    -0x1(,%rax,4),%eax
lea    0x1(%r12),%ebp
cmp    %r12d,%eax
jne    1558 <main+0x398>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1558 <main+0x398>
lea    0xb13(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %ebx,%ebx
jmp    1519 <main+0x359>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Specify ppm file\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [22 x i8] c"Cannot open file: %s\0A\00"
@.str.4 = [27 x i8] c"ERROR: Invalid stream (1)\0A\00"
@.str.5 = [27 x i8] c"ERROR: Invalid stream (2)\0A\00"
@.str.6 = [27 x i8] c"ERROR: Invalid stream (3)\0A\00"
@.str.7 = [7 x i8] c"%d %d\0A\00"
@.str.8 = [27 x i8] c"ERROR: Invalid stream (4)\0A\00"
@.str.9 = [27 x i8] c"ERROR: Invalid stream (5)\0A\00"
@.str.10 = [4 x i8] c"%d\0A\00"
@.str.11 = [27 x i8] c"ERROR: Invalid stream (6)\0A\00"
@.str.12 = [25 x i8] c"#define PPM_WIDTH_%s %d\0A\00"
@.str.13 = [26 x i8] c"#define PPM_HEIGHT_%s %d\0A\00"
@.str.14 = [35 x i8] c"unsigned char Ppm_image_%s[] = { \0A\00"
@.str.15 = [6 x i8] c"0xff,\00"
@.str.16 = [7 x i8] c"0x%02x\00"
@.str.17 = [2 x i8] c",\00"
@.str.18 = [2 x i8] c"\0A\00"
@.str.19 = [5 x i8] c"} ;\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
%11 = alloca [256 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 0, i32* %16
store i32* null, i32** %17
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %348
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = call i8* @strrchr(i8* %32, i8 signext 47)
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %41
36: ; preds = %28
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%38 = load i8*, i8** %8
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = call i32 @snprintf(i8* %37, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %39)
br label %45
41: ; preds = %28
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%43 = load i8*, i8** %7
%44 = call i32 @snprintf(i8* %42, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %41, %36
store i32 0, i32* %12
br label %46
46: ; preds = %100, %45
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %103
53: ; preds = %46
store i32 0, i32* %18
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%55 = load i32, i32* %12
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
store i32 %59, i32* %19
%60 = load i32, i32* %19
%61 = icmp sle i32 48, %60
br i1 %61, label %62, label %66
62: ; preds = %53
%63 = load i32, i32* %19
%64 = icmp sle i32 %63, 57
br i1 %64, label %65, label %66
65: ; preds = %62
store i32 1, i32* %18
br label %92
66: ; preds = %62, %53
%67 = load i32, i32* %19
%68 = icmp sle i32 65, %67
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = load i32, i32* %19
%71 = icmp sle i32 %70, 90
br i1 %71, label %72, label %73
72: ; preds = %69
store i32 1, i32* %18
br label %91
73: ; preds = %69, %66
%74 = load i32, i32* %19
%75 = icmp sle i32 97, %74
br i1 %75, label %76, label %80
76: ; preds = %73
%77 = load i32, i32* %19
%78 = icmp sle i32 %77, 122
br i1 %78, label %79, label %80
79: ; preds = %76
store i32 1, i32* %18
br label %90
80: ; preds = %76, %73
%81 = load i32, i32* %19
%82 = icmp eq i32 %81, 95
br i1 %82, label %83, label %84
83: ; preds = %80
store i32 1, i32* %18
br label %89
84: ; preds = %80
%85 = load i32, i32* %19
%86 = icmp eq i32 %85, 46
br i1 %86, label %87, label %88
87: ; preds = %84
br label %103
88: ; preds = %84
br label %89
89: ; preds = %88, %83
br label %90
90: ; preds = %89, %79
br label %91
91: ; preds = %90, %72
br label %92
92: ; preds = %91, %65
%93 = load i32, i32* %18
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %99
95: ; preds = %92
%96 = load i32, i32* %12
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %97
store i8 95, i8* %98
br label %99
99: ; preds = %95, %92
br label %100
100: ; preds = %99
%101 = load i32, i32* %12
%102 = add nsw i32 %101, 1
store i32 %102, i32* %12
br label %46
103: ; preds = %87, %46
%104 = load i32, i32* %12
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %105
store i8 0, i8* %106
store i32 0, i32* %12
br label %107
107: ; preds = %140, %103
%108 = load i32, i32* %12
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %109
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %143
114: ; preds = %107
%115 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%116 = load i32, i32* %12
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds i8, i8* %115, i64 %117
%119 = load i8, i8* %118
%120 = zext i8 %119 to i32
store i32 %120, i32* %20
%121 = load i32, i32* %20
%122 = icmp sle i32 97, %121
br i1 %122, label %123, label %133
123: ; preds = %114
%124 = load i32, i32* %20
%125 = icmp sle i32 %124, 122
br i1 %125, label %126, label %133
126: ; preds = %123
%127 = load i32, i32* %20
%128 = sub nsw i32 %127, 32
%129 = trunc i32 %128 to i8
%130 = load i32, i32* %12
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %131
store i8 %129, i8* %132
br label %139
133: ; preds = %123, %114
%134 = load i32, i32* %20
%135 = trunc i32 %134 to i8
%136 = load i32, i32* %12
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %137
store i8 %135, i8* %138
br label %139
139: ; preds = %133, %126
br label %140
140: ; preds = %139
%141 = load i32, i32* %12
%142 = add nsw i32 %141, 1
store i32 %142, i32* %12
br label %107
143: ; preds = %107
%144 = load i32, i32* %12
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %145
store i8 0, i8* %146
%147 = load i8*, i8** %7
%148 = call i32* @fopen(i8* %147, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %148, i32** %17
%149 = load i32*, i32** %17
%150 = icmp eq i32* %149, null
br i1 %150, label %151, label %155
151: ; preds = %143
%152 = load i32, i32* @stderr
%153 = load i8*, i8** %7
%154 = call i32 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %153)
br label %340
155: ; preds = %143
%156 = load i32*, i32** %17
%157 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%158 = call i8* @next(i32* %156, i8* %157, i32 256)
store i8* %158, i8** %8
%159 = load i8*, i8** %8
%160 = icmp eq i8* %159, null
br i1 %160, label %167, label %161
161: ; preds = %155
%162 = load i8*, i8** %8
%163 = getelementptr inbounds i8, i8* %162, i64 0
%164 = load i8, i8* %163
%165 = sext i8 %164 to i32
%166 = icmp ne i32 %165, 80
br i1 %166, label %167, label %170
167: ; preds = %161, %155
%168 = load i32, i32* @stderr
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %168, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %340
170: ; preds = %161
%171 = load i8*, i8** %8
%172 = getelementptr inbounds i8, i8* %171, i64 1
%173 = load i8, i8* %172
%174 = sext i8 %173 to i32
%175 = icmp ne i32 %174, 54
br i1 %175, label %176, label %185
176: ; preds = %170
%177 = load i8*, i8** %8
%178 = getelementptr inbounds i8, i8* %177, i64 1
%179 = load i8, i8* %178
%180 = sext i8 %179 to i32
%181 = icmp ne i32 %180, 51
br i1 %181, label %182, label %185
182: ; preds = %176
%183 = load i32, i32* @stderr
%184 = call i32 (i32, i8*, ...) @fprintf(i32 %183, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %340
185: ; preds = %176, %170
%186 = load i8*, i8** %8
%187 = getelementptr inbounds i8, i8* %186, i64 1
%188 = load i8, i8* %187
%189 = sext i8 %188 to i32
%190 = icmp eq i32 %189, 51
br i1 %190, label %191, label %192
191: ; preds = %185
store i32 1, i32* %16
br label %192
192: ; preds = %191, %185
%193 = load i32*, i32** %17
%194 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%195 = call i8* @next(i32* %193, i8* %194, i32 256)
store i8* %195, i8** %8
%196 = load i8*, i8** %8
%197 = icmp eq i8* %196, null
br i1 %197, label %198, label %201
198: ; preds = %192
%199 = load i32, i32* @stderr
%200 = call i32 (i32, i8*, ...) @fprintf(i32 %199, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %340
201: ; preds = %192
%202 = load i8*, i8** %8
%203 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %202, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32* %13, i32* %14)
store i32 %203, i32* %12
%204 = load i32, i32* %12
%205 = icmp ne i32 %204, 2
br i1 %205, label %206, label %209
206: ; preds = %201
%207 = load i32, i32* @stderr
%208 = call i32 (i32, i8*, ...) @fprintf(i32 %207, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
br label %340
209: ; preds = %201
%210 = load i32*, i32** %17
%211 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%212 = call i8* @next(i32* %210, i8* %211, i32 256)
store i8* %212, i8** %8
%213 = load i8*, i8** %8
%214 = icmp eq i8* %213, null
br i1 %214, label %215, label %218
215: ; preds = %209
%216 = load i32, i32* @stderr
%217 = call i32 (i32, i8*, ...) @fprintf(i32 %216, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
br label %340
218: ; preds = %209
%219 = load i8*, i8** %8
%220 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %219, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32* %15)
store i32 %220, i32* %12
%221 = load i32, i32* %12
%222 = icmp ne i32 %221, 1
br i1 %222, label %223, label %226
223: ; preds = %218
%224 = load i32, i32* @stderr
%225 = call i32 (i32, i8*, ...) @fprintf(i32 %224, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
br label %340
226: ; preds = %218
%227 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%228 = load i32, i32* %13
%229 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i8* %227, i32 %228)
%230 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%231 = load i32, i32* %14
%232 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i8* %230, i32 %231)
%233 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%234 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0), i8* %233)
%235 = load i32, i32* %16
%236 = icmp ne i32 %235, 0
br i1 %236, label %237, label %279
237: ; preds = %226
store i32 0, i32* %12
br label %238
238: ; preds = %275, %237
%239 = load i32, i32* %12
%240 = load i32, i32* %13
%241 = load i32, i32* %14
%242 = mul nsw i32 %240, %241
%243 = mul nsw i32 %242, 3
%244 = icmp slt i32 %239, %243
br i1 %244, label %245, label %278
245: ; preds = %238
%246 = load i32, i32* %12
%247 = srem i32 %246, 3
%248 = icmp eq i32 %247, 0
br i1 %248, label %249, label %251
249: ; preds = %245
%250 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0))
br label %251
251: ; preds = %249, %245
%252 = load i32*, i32** %17
%253 = call i32 @numread(i32* %252)
%254 = mul nsw i32 255, %253
%255 = load i32, i32* %15
%256 = sdiv i32 %254, %255
%257 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0), i32 %256)
%258 = load i32, i32* %12
%259 = load i32, i32* %13
%260 = load i32, i32* %14
%261 = mul nsw i32 %259, %260
%262 = mul nsw i32 %261, 3
%263 = sub nsw i32 %262, 1
%264 = icmp ne i32 %258, %263
br i1 %264, label %265, label %267
265: ; preds = %251
%266 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
br label %267
267: ; preds = %265, %251
%268 = load i32, i32* %12
%269 = add nsw i32 %268, 1
%270 = srem i32 %269, 12
%271 = icmp eq i32 %270, 0
br i1 %271, label %272, label %274
272: ; preds = %267
%273 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
br label %274
274: ; preds = %272, %267
br label %275
275: ; preds = %274
%276 = load i32, i32* %12
%277 = add nsw i32 %276, 1
store i32 %277, i32* %12
br label %238
278: ; preds = %238
br label %336
279: ; preds = %226
%280 = load i32, i32* %15
%281 = icmp slt i32 %280, 256
%282 = zext i1 %281 to i64
%283 = select i1 %281, i32 1, i32 2
store i32 %283, i32* %22
store i32 0, i32* %12
br label %284
284: ; preds = %332, %279
%285 = load i32, i32* %12
%286 = load i32, i32* %13
%287 = load i32, i32* %14
%288 = mul nsw i32 %286, %287
%289 = mul nsw i32 %288, 3
%290 = icmp slt i32 %285, %289
br i1 %290, label %291, label %335
291: ; preds = %284
%292 = load i32, i32* %12
%293 = srem i32 %292, 3
%294 = icmp eq i32 %293, 0
br i1 %294, label %295, label %297
295: ; preds = %291
%296 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0))
br label %297
297: ; preds = %295, %291
%298 = load i32*, i32** %17
%299 = call i32 @fgetc(i32* %298)
store i32 %299, i32* %21
%300 = load i32, i32* %22
%301 = icmp slt i32 1, %300
br i1 %301, label %302, label %309
302: ; preds = %297
%303 = load i32, i32* %21
%304 = shl i32 %303, 8
store i32 %304, i32* %21
%305 = load i32*, i32** %17
%306 = call i32 @fgetc(i32* %305)
%307 = load i32, i32* %21
%308 = or i32 %307, %306
store i32 %308, i32* %21
br label %309
309: ; preds = %302, %297
%310 = load i32, i32* %21
%311 = mul nsw i32 255, %310
%312 = load i32, i32* %15
%313 = sdiv i32 %311, %312
%314 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0), i32 %313)
%315 = load i32, i32* %12
%316 = load i32, i32* %13
%317 = load i32, i32* %14
%318 = mul nsw i32 %316, %317
%319 = mul nsw i32 %318, 3
%320 = sub nsw i32 %319, 1
%321 = icmp ne i32 %315, %320
br i1 %321, label %322, label %324
322: ; preds = %309
%323 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
br label %324
324: ; preds = %322, %309
%325 = load i32, i32* %12
%326 = add nsw i32 %325, 1
%327 = srem i32 %326, 12
%328 = icmp eq i32 %327, 0
br i1 %328, label %329, label %331
329: ; preds = %324
%330 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
br label %331
331: ; preds = %329, %324
br label %332
332: ; preds = %331
%333 = load i32, i32* %12
%334 = add nsw i32 %333, 1
store i32 %334, i32* %12
br label %284
335: ; preds = %284
br label %336
336: ; preds = %335, %278
%337 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.19, i64 0, i64 0))
%338 = load i32*, i32** %17
%339 = call i32 @fclose(i32* %338)
store i32* null, i32** %17
store i32 0, i32* %6
br label %340
340: ; preds = %336, %223, %215, %206, %198, %182, %167, %151
%341 = load i32*, i32** %17
%342 = icmp ne i32* %341, null
br i1 %342, label %343, label %346
343: ; preds = %340
%344 = load i32*, i32** %17
%345 = call i32 @fclose(i32* %344)
br label %346
346: ; preds = %343, %340
%347 = load i32, i32* %6
store i32 %347, i32* %3
br label %348
348: ; preds = %346, %25
%349 = load i32, i32* %3
ret i32 %349
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Specify ppm file\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [22 x i8] c"Cannot open file: %s\0A\00"
@.str.4 = [27 x i8] c"ERROR: Invalid stream (1)\0A\00"
@.str.5 = [27 x i8] c"ERROR: Invalid stream (2)\0A\00"
@.str.6 = [27 x i8] c"ERROR: Invalid stream (3)\0A\00"
@.str.7 = [7 x i8] c"%d %d\0A\00"
@.str.8 = [27 x i8] c"ERROR: Invalid stream (4)\0A\00"
@.str.9 = [27 x i8] c"ERROR: Invalid stream (5)\0A\00"
@.str.10 = [4 x i8] c"%d\0A\00"
@.str.11 = [27 x i8] c"ERROR: Invalid stream (6)\0A\00"
@.str.12 = [25 x i8] c"#define PPM_WIDTH_%s %d\0A\00"
@.str.13 = [26 x i8] c"#define PPM_HEIGHT_%s %d\0A\00"
@.str.14 = [35 x i8] c"unsigned char Ppm_image_%s[] = { \0A\00"
@.str.15 = [6 x i8] c"0xff,\00"
@.str.16 = [7 x i8] c"0x%02x\00"
@str = [4 x i8] c"} ;\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast i32* %8 to i8*
%15 = icmp slt i32 %0, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %197
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i8* @strrchr(i8* dereferenceable(1) %21, i8 signext 47)
%23 = icmp eq i8* %22, null
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = getelementptr inbounds i8, i8* %22, i64 1
%26 = call i32 @snprintf(i8* %9, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %29
27: ; preds = %19
%28 = call i32 @snprintf(i8* %9, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %29
29: ; preds = %27, %24
%30 = load i8, i8* %9
%31 = icmp eq i8 %30, 0
br i1 %31, label %51, label %32
32: ; preds = %29, %46
%33 = phi i64 [ %47, %46 ], [ 0, %29 ]
%34 = phi i8 [ %49, %46 ], [ %30, %29 ]
%35 = phi i8* [ %48, %46 ], [ %9, %29 ]
%36 = add i8 %34, -48
%37 = icmp ult i8 %36, 10
%38 = add i8 %34, -65
%39 = icmp ult i8 %38, 26
%40 = or i1 %37, %39
%41 = add i8 %34, -97
%42 = icmp ult i8 %41, 26
%43 = select i1 %40, i1 true, i1 %42
br i1 %43, label %46, label %44
44: ; preds = %32
switch i8 %34, label %45 [
i8 95, label %46
i8 46, label %51
]
45: ; preds = %44
store i8 95, i8* %35
br label %46
46: ; preds = %45, %32, %44
%47 = add nuw i64 %33, 1
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 0
br i1 %50, label %51, label %32
51: ; preds = %46, %44, %29
%52 = phi i8* [ %9, %29 ], [ %35, %44 ], [ %48, %46 ]
store i8 0, i8* %52
%53 = load i8, i8* %9
%54 = icmp eq i8 %53, 0
br i1 %54, label %69, label %55
55: ; preds = %51, %55
%56 = phi i64 [ %63, %55 ], [ 0, %51 ]
%57 = phi i8 [ %65, %55 ], [ %53, %51 ]
%58 = add i8 %57, -97
%59 = icmp ult i8 %58, 26
%60 = add nsw i8 %57, -32
%61 = select i1 %59, i8 %60, i8 %57
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %56
store i8 %61, i8* %62
%63 = add nuw i64 %56, 1
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %63
%65 = load i8, i8* %64
%66 = icmp eq i8 %65, 0
br i1 %66, label %67, label %55
67: ; preds = %55
%68 = and i64 %63, 4294967295
br label %69
69: ; preds = %67, %51
%70 = phi i64 [ 0, %51 ], [ %68, %67 ]
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %70
store i8 0, i8* %71
%72 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%73 = icmp eq i32* %72, null
br i1 %73, label %74, label %77
74: ; preds = %69
%75 = load i32, i32* @stderr
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %197
77: ; preds = %69
%78 = call i8* @next(i32* %72, i8* %11, i32 256)
%79 = icmp eq i8* %78, null
br i1 %79, label %192, label %80
80: ; preds = %77
%81 = load i8, i8* %78
%82 = icmp eq i8 %81, 80
br i1 %82, label %83, label %192
83: ; preds = %80
%84 = getelementptr inbounds i8, i8* %78, i64 1
%85 = load i8, i8* %84
switch i8 %85, label %192 [
i8 54, label %86
i8 51, label %86
]
86: ; preds = %83, %83
%87 = icmp eq i8 %85, 51
%88 = call i8* @next(i32* %72, i8* %11, i32 256)
%89 = icmp eq i8* %88, null
br i1 %89, label %192, label %90
90: ; preds = %86
%91 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %88, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32* %6, i32* %7)
%92 = icmp eq i32 %91, 2
br i1 %92, label %93, label %192
93: ; preds = %90
%94 = call i8* @next(i32* %72, i8* %11, i32 256)
%95 = icmp eq i8* %94, null
br i1 %95, label %192, label %96
96: ; preds = %93
%97 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %94, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32* %8)
%98 = icmp eq i32 %97, 1
br i1 %98, label %99, label %192
99: ; preds = %96
%100 = load i32, i32* %6
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i8* %10, i32 %100)
%102 = load i32, i32* %7
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i8* %10, i32 %102)
%104 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0), i8* %9)
br i1 %87, label %105, label %143
105: ; preds = %99
%106 = load i32, i32* %6
%107 = load i32, i32* %7
%108 = mul i32 %106, 3
%109 = mul i32 %108, %107
%110 = icmp sgt i32 %109, 0
br i1 %110, label %111, label %189
111: ; preds = %105, %137
%112 = phi i32 [ %132, %137 ], [ 0, %105 ]
%113 = urem i32 %112, 3
%114 = icmp eq i32 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %111
%116 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0))
br label %117
117: ; preds = %115, %111
%118 = call i32 @numread(i32* %72)
%119 = mul nsw i32 %118, 255
%120 = load i32, i32* %8
%121 = sdiv i32 %119, %120
%122 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0), i32 %121)
%123 = load i32, i32* %6
%124 = load i32, i32* %7
%125 = mul i32 %123, 3
%126 = mul i32 %125, %124
%127 = add nsw i32 %126, -1
%128 = icmp eq i32 %112, %127
br i1 %128, label %131, label %129
129: ; preds = %117
%130 = call i32 @putchar(i32 44)
br label %131
131: ; preds = %129, %117
%132 = add nuw nsw i32 %112, 1
%133 = urem i32 %132, 12
%134 = icmp eq i32 %133, 0
br i1 %134, label %135, label %137
135: ; preds = %131
%136 = call i32 @putchar(i32 10)
br label %137
137: ; preds = %131, %135
%138 = load i32, i32* %6
%139 = load i32, i32* %7
%140 = mul i32 %138, 3
%141 = mul i32 %140, %139
%142 = icmp slt i32 %132, %141
br i1 %142, label %111, label %189
143: ; preds = %99
%144 = load i32, i32* %8
%145 = icmp sgt i32 %144, 255
%146 = load i32, i32* %6
%147 = load i32, i32* %7
%148 = mul i32 %146, 3
%149 = mul i32 %148, %147
%150 = icmp sgt i32 %149, 0
br i1 %150, label %151, label %189
151: ; preds = %143, %183
%152 = phi i32 [ %178, %183 ], [ 0, %143 ]
%153 = urem i32 %152, 3
%154 = icmp eq i32 %153, 0
br i1 %154, label %155, label %157
155: ; preds = %151
%156 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0))
br label %157
157: ; preds = %155, %151
%158 = call i32 @fgetc(i32* %72)
br i1 %145, label %159, label %163
159: ; preds = %157
%160 = shl i32 %158, 8
%161 = call i32 @fgetc(i32* %72)
%162 = or i32 %161, %160
br label %163
163: ; preds = %159, %157
%164 = phi i32 [ %162, %159 ], [ %158, %157 ]
%165 = mul nsw i32 %164, 255
%166 = load i32, i32* %8
%167 = sdiv i32 %165, %166
%168 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0), i32 %167)
%169 = load i32, i32* %6
%170 = load i32, i32* %7
%171 = mul i32 %169, 3
%172 = mul i32 %171, %170
%173 = add nsw i32 %172, -1
%174 = icmp eq i32 %152, %173
br i1 %174, label %177, label %175
175: ; preds = %163
%176 = call i32 @putchar(i32 44)
br label %177
177: ; preds = %175, %163
%178 = add nuw nsw i32 %152, 1
%179 = urem i32 %178, 12
%180 = icmp eq i32 %179, 0
br i1 %180, label %181, label %183
181: ; preds = %177
%182 = call i32 @putchar(i32 10)
br label %183
183: ; preds = %177, %181
%184 = load i32, i32* %6
%185 = load i32, i32* %7
%186 = mul i32 %184, 3
%187 = mul i32 %186, %185
%188 = icmp slt i32 %178, %187
br i1 %188, label %151, label %189
189: ; preds = %183, %137, %143, %105
%190 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%191 = call i32 @fclose(i32* %72)
br label %197
192: ; preds = %96, %93, %90, %86, %83, %77, %80
%193 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), %80 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), %77 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), %83 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), %86 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), %90 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), %93 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), %96 ]
%194 = load i32, i32* @stderr
%195 = call i32 (i32, i8*, ...) @fprintf(i32 %194, i8* %193)
%196 = call i32 @fclose(i32* %72)
br label %197
197: ; preds = %74, %189, %192, %16
%198 = phi i32 [ 0, %16 ], [ -1, %192 ], [ -1, %74 ], [ 0, %189 ]
ret i32 %198
}