#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *, char *, char *, int *,
                  int *, char *, int *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *, char *, int *, char *, int *,
                          char *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (argc < 6) {
    fprintf(stderr, "usage: {input trec} {output pgm} {width} {height} {max "
                    "hd, -1 for plot hd}\n");
    return 0;
  }
  int w = atoi(argv[3]);
  int h = atoi(argv[4]);
  int mhd = atoi(argv[5]);
  FILE *fi;
  if ((fi = fopen(argv[1], "r"))) {
    FILE *fo;
    if ((fo = fopen(argv[2], "w"))) {
      char *pixbuf = malloc(w * h);
      memset(pixbuf, 0, w * h);
      for (;;) {
        int topic_id, rank, score, hd;
        char q0[16], docname[256], runtitle[256];
        if (fscanf(fi, "%d %s %s %d %d %s %d\n", &topic_id, q0, docname, &rank,
                   &score, runtitle, &hd) <= 0)
          break;
        printf("READ [%s]\n", docname);
        if (strcmp(docname, "query") != 0) {
          int imgnum, x, y, t;
          char dummy;
          sscanf(docname, "%d%c%d%c%d%c%d", &imgnum, &dummy, &x, &dummy, &y,
                 &dummy, &t);
          if (mhd == -1) {
            printf("Plotting %d to %d,%d [%s]\n", hd, x, y, docname);
            pixbuf[y * w + x] = hd;
          } else {
            if (hd <= mhd) {
              pixbuf[y * w + x] = 255;
            }
          }
        }
      }
      fprintf(fo, "P2 %d %d\n%d\n", w, h, 255);
      for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
          fprintf(fo, "%d ", pixbuf[y * w + x]);
        }
      }
      fclose(fo);
    } else {
      fprintf(stderr, "Unable to open output file\n");
    }
    fclose(fi);
  } else {
    fprintf(stderr, "Unable to open input file\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x6,-0x8(%rbp)
jge    11e6 <main+0x46>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14ce <main+0x32e>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe27(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     14b0 <main+0x310>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe07(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     148b <main+0x2eb>
mov    -0x14(%rbp),%edi
imul   -0x18(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%edx
imul   -0x18(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
lea    -0x60(%rbp),%rcx
lea    -0x160(%rbp),%r8
lea    -0x260(%rbp),%r10
lea    0xdb7(%rip),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%r9
lea    -0x44(%rbp),%r11
lea    -0x48(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <fscanf@plt>
cmp    $0x0,%rax
jg     12cb <main+0x12b>
jmp    13cf <main+0x22f>
lea    -0x160(%rbp),%rsi
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x160(%rbp),%rdi
lea    0xd83(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     13ca <main+0x22a>
lea    -0x160(%rbp),%rdi
lea    0xd6c(%rip),%rsi
lea    -0x264(%rbp),%rdx
lea    -0x271(%rbp),%r10
lea    -0x268(%rbp),%r8
lea    -0x26c(%rbp),%r11
lea    -0x270(%rbp),%rax
mov    %r10,%rcx
mov    %r10,%r9
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   10a0 <sscanf@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1399 <main+0x1f9>
mov    -0x48(%rbp),%esi
mov    -0x268(%rbp),%edx
mov    -0x26c(%rbp),%ecx
lea    -0x160(%rbp),%r8
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%eax
mov    %al,%dl
mov    -0x38(%rbp),%rax
mov    -0x26c(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x268(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    13c5 <main+0x225>
mov    -0x48(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     13c0 <main+0x220>
mov    -0x38(%rbp),%rax
mov    -0x26c(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x268(%rbp),%ecx
movslq %ecx,%rcx
movb   $0xff,(%rax,%rcx,1)
jmp    13c5 <main+0x225>
jmp    13ca <main+0x22a>
jmp    127c <main+0xdc>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xcbf(%rip),%rsi
mov    $0xff,%r8d
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x278(%rbp)
mov    -0x278(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    147d <main+0x2dd>
movl   $0x0,-0x27c(%rbp)
mov    -0x27c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1464 <main+0x2c4>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
mov    -0x38(%rbp),%rax
mov    -0x278(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x27c(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xc65(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x27c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x27c(%rbp)
jmp    1412 <main+0x272>
jmp    1469 <main+0x2c9>
mov    -0x278(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x278(%rbp)
jmp    13f9 <main+0x259>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
jmp    14a2 <main+0x302>
mov    0x2b4e(%rip),%rax
mov    (%rax),%edi
lea    0xc17(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
jmp    14c7 <main+0x327>
mov    0x2b29(%rip),%rax
mov    (%rax),%edi
lea    0xc0e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x268,%rsp
cmp    $0x5,%edi
jg     11cb <main+0x2b>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
jmp    145d <main+0x2bd>
mov    %rsi,%rbp
mov    0x18(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,0xc(%rsp)
mov    0x20(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
mov    0x28(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
mov    0x8(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     144d <main+0x2ad>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1466 <main+0x2c6>
mov    %rax,%r13
mov    %r14d,0x20(%rsp)
imul   0xc(%rsp),%r14d
mov    %r14d,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
sub    $0x8,%rsp
lea    0x20(%rsp),%rax
lea    0x68(%rsp),%r10
lea    0x34(%rsp),%r11
lea    0xde8(%rip),%rsi
lea    0x3c(%rsp),%rdx
lea    0x58(%rsp),%rcx
lea    0x168(%rsp),%r8
lea    0x38(%rsp),%r9
mov    %rbx,%rdi
push   %rax
push   %r10
push   %r11
call   1060 <fscanf@plt>
add    $0x20,%rsp
test   %rax,%rax
jle    13ad <main+0x20d>
lea    0x160(%rsp),%r12
lea    0x1f(%rsp),%r14
jmp    1325 <main+0x185>
nopl   0x0(%rax,%rax,1)
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
lea    0xdc7(%rip),%rdi
mov    %r12,%r8
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x18(%rsp),%ecx
mov    0x10(%rsp),%eax
imul   0xc(%rsp),%eax
add    0x14(%rsp),%eax
cltq
mov    %cl,0x0(%rbp,%rax,1)
sub    $0x8,%rsp
mov    %rbx,%rdi
lea    0xd61(%rip),%rsi
lea    0x3c(%rsp),%rdx
lea    0x58(%rsp),%rcx
mov    %r12,%r8
lea    0x38(%rsp),%r9
lea    0x20(%rsp),%rax
push   %rax
lea    0x70(%rsp),%rax
push   %rax
lea    0x44(%rsp),%rax
push   %rax
call   1060 <fscanf@plt>
add    $0x20,%rsp
test   %rax,%rax
jle    13ad <main+0x20d>
lea    0xd3a(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
lea    0xd31(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12e1 <main+0x141>
sub    $0x8,%rsp
mov    %r12,%rdi
lea    0xd1f(%rip),%rsi
lea    0x54(%rsp),%rdx
mov    %r14,%rcx
lea    0x1c(%rsp),%r8
mov    %r14,%r9
lea    0x50(%rsp),%rax
push   %rax
push   %r14
lea    0x28(%rsp),%rax
push   %rax
call   10a0 <sscanf@plt>
add    $0x20,%rsp
mov    0x18(%rsp),%esi
cmp    $0xffffffff,%r15d
je     12b0 <main+0x110>
mov    %r15d,%eax
cmp    %r15d,%esi
jg     12e1 <main+0x141>
mov    0x10(%rsp),%eax
imul   0xc(%rsp),%eax
add    0x14(%rsp),%eax
mov    $0xff,%cl
jmp    12db <main+0x13b>
mov    %rbx,0x38(%rsp)
lea    0xce8(%rip),%rsi
mov    %r13d,%edi
mov    0xc(%rsp),%edx
mov    0x20(%rsp),%ebx
mov    %ebx,%ecx
mov    $0xff,%r8d
xor    %eax,%eax
call   1080 <fprintf@plt>
test   %ebx,%ebx
jle    143e <main+0x29e>
mov    0xc(%rsp),%eax
movslq %eax,%rcx
mov    %rcx,0x40(%rsp)
mov    %ebx,%ecx
mov    %rcx,0x20(%rsp)
mov    %eax,%r15d
lea    0xcba(%rip),%rbx
xor    %r14d,%r14d
jmp    1410 <main+0x270>
nopl   0x0(%rax)
add    $0x1,%r14
add    0x40(%rsp),%rbp
cmp    0x20(%rsp),%r14
je     143e <main+0x29e>
cmpl   $0x0,0xc(%rsp)
jle    1400 <main+0x260>
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movsbl 0x0(%rbp,%r12,1),%edx
mov    %r13d,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r15
jne    1420 <main+0x280>
jmp    1400 <main+0x260>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    0x38(%rsp),%rbx
jmp    147d <main+0x2dd>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
lea    0xc71(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1485 <main+0x2e5>
mov    0x2b73(%rip),%rax
mov    (%rax),%edi
lea    0xc3c(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x268,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [76 x i8] c"usage: {input trec} {output pgm} {width} {height} {max hd, -1 for plot hd}\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [22 x i8] c"%d %s %s %d %d %s %d\0A\00"
@.str.4 = [11 x i8] c"READ [%s]\0A\00"
@.str.5 = [6 x i8] c"query\00"
@.str.6 = [15 x i8] c"%d%c%d%c%d%c%d\00"
@.str.7 = [27 x i8] c"Plotting %d to %d,%d [%s]\0A\00"
@.str.8 = [13 x i8] c"P2 %d %d\0A%d\0A\00"
@.str.9 = [4 x i8] c"%d \00"
@.str.10 = [28 x i8] c"Unable to open output file\0A\00"
@.str.11 = [27 x i8] c"Unable to open input file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [16 x i8]
%17 = alloca [256 x i8]
%18 = alloca [256 x i8]
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i8
%24 = alloca i32
%25 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 6
br i1 %27, label %28, label %31
28: ; preds = %2
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %165
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %6
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 4
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %7
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 5
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %8
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %47, i32** %9
%48 = icmp ne i32* %47, null
br i1 %48, label %49, label %161
49: ; preds = %31
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32* @fopen(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %53, i32** %10
%54 = icmp ne i32* %53, null
br i1 %54, label %55, label %155
55: ; preds = %49
%56 = load i32, i32* %6
%57 = load i32, i32* %7
%58 = mul nsw i32 %56, %57
%59 = call i8* @malloc(i32 %58)
store i8* %59, i8** %11
%60 = load i8*, i8** %11
%61 = load i32, i32* %6
%62 = load i32, i32* %7
%63 = mul nsw i32 %61, %62
%64 = call i32 @memset(i8* %60, i32 0, i32 %63)
br label %65
65: ; preds = %115, %55
%66 = load i32*, i32** %9
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 0
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%70 = call i64 @fscanf(i32* %66, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32* %12, i8* %67, i8* %68, i32* %13, i32* %14, i8* %69, i32* %15)
%71 = icmp sle i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %65
br label %116
73: ; preds = %65
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %74)
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%77 = call i64 @strcmp(i8* %76, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %115
79: ; preds = %73
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%81 = call i32 @sscanf(i8* %80, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32* %19, i8* %23, i32* %20, i8* %23, i32* %21, i8* %23, i32* %22)
%82 = load i32, i32* %8
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %100
84: ; preds = %79
%85 = load i32, i32* %15
%86 = load i32, i32* %20
%87 = load i32, i32* %21
%88 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %85, i32 %86, i32 %87, i8* %88)
%90 = load i32, i32* %15
%91 = trunc i32 %90 to i8
%92 = load i8*, i8** %11
%93 = load i32, i32* %21
%94 = load i32, i32* %6
%95 = mul nsw i32 %93, %94
%96 = load i32, i32* %20
%97 = add nsw i32 %95, %96
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %92, i64 %98
store i8 %91, i8* %99
br label %114
100: ; preds = %79
%101 = load i32, i32* %15
%102 = load i32, i32* %8
%103 = icmp sle i32 %101, %102
br i1 %103, label %104, label %113
104: ; preds = %100
%105 = load i8*, i8** %11
%106 = load i32, i32* %21
%107 = load i32, i32* %6
%108 = mul nsw i32 %106, %107
%109 = load i32, i32* %20
%110 = add nsw i32 %108, %109
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %105, i64 %111
store i8 -1, i8* %112
br label %113
113: ; preds = %104, %100
br label %114
114: ; preds = %113, %84
br label %115
115: ; preds = %114, %73
br label %65
116: ; preds = %72
%117 = load i32*, i32** %10
%118 = ptrtoint i32* %117 to i32
%119 = load i32, i32* %6
%120 = load i32, i32* %7
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %119, i32 %120, i32 255)
store i32 0, i32* %24
br label %122
122: ; preds = %149, %116
%123 = load i32, i32* %24
%124 = load i32, i32* %7
%125 = icmp slt i32 %123, %124
br i1 %125, label %126, label %152
126: ; preds = %122
store i32 0, i32* %25
br label %127
127: ; preds = %145, %126
%128 = load i32, i32* %25
%129 = load i32, i32* %6
%130 = icmp slt i32 %128, %129
br i1 %130, label %131, label %148
131: ; preds = %127
%132 = load i32*, i32** %10
%133 = ptrtoint i32* %132 to i32
%134 = load i8*, i8** %11
%135 = load i32, i32* %24
%136 = load i32, i32* %6
%137 = mul nsw i32 %135, %136
%138 = load i32, i32* %25
%139 = add nsw i32 %137, %138
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i8, i8* %134, i64 %140
%142 = load i8, i8* %141
%143 = sext i8 %142 to i32
%144 = call i32 (i32, i8*, ...) @fprintf(i32 %133, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %143)
br label %145
145: ; preds = %131
%146 = load i32, i32* %25
%147 = add nsw i32 %146, 1
store i32 %147, i32* %25
br label %127
148: ; preds = %127
br label %149
149: ; preds = %148
%150 = load i32, i32* %24
%151 = add nsw i32 %150, 1
store i32 %151, i32* %24
br label %122
152: ; preds = %122
%153 = load i32*, i32** %10
%154 = call i32 @fclose(i32* %153)
br label %158
155: ; preds = %49
%156 = load i32, i32* @stderr
%157 = call i32 (i32, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %158
158: ; preds = %155, %152
%159 = load i32*, i32** %9
%160 = call i32 @fclose(i32* %159)
br label %164
161: ; preds = %31
%162 = load i32, i32* @stderr
%163 = call i32 (i32, i8*, ...) @fprintf(i32 %162, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
br label %164
164: ; preds = %161, %158
store i32 0, i32* %3
br label %165
165: ; preds = %164, %28
%166 = load i32, i32* %3
ret i32 %166
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [76 x i8] c"usage: {input trec} {output pgm} {width} {height} {max hd, -1 for plot hd}\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [22 x i8] c"%d %s %s %d %d %s %d\0A\00"
@.str.4 = [11 x i8] c"READ [%s]\0A\00"
@.str.5 = [6 x i8] c"query\00"
@.str.6 = [15 x i8] c"%d%c%d%c%d%c%d\00"
@.str.7 = [27 x i8] c"Plotting %d to %d,%d [%s]\0A\00"
@.str.8 = [13 x i8] c"P2 %d %d\0A%d\0A\00"
@.str.9 = [4 x i8] c"%d \00"
@.str.10 = [28 x i8] c"Unable to open output file\0A\00"
@.str.11 = [27 x i8] c"Unable to open input file\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [16 x i8]
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = icmp slt i32 %0, 6
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 ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
br label %126
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 4
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = getelementptr inbounds i8*, i8** %1, i64 5
%27 = load i8*, i8** %26
%28 = tail call i32 @atoi(i8* %27)
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %123, label %33
33: ; preds = %19
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = tail call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %118, label %38
38: ; preds = %33
%39 = mul nsw i32 %25, %22
%40 = tail call i8* @malloc(i32 %39)
%41 = tail call i32 @memset(i8* %40, i32 0, i32 %39)
%42 = bitcast i32* %3 to i8*
%43 = bitcast i32* %4 to i8*
%44 = bitcast i32* %5 to i8*
%45 = bitcast i32* %6 to i8*
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%49 = call i64 @fscanf(i32* %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32* %3, i8* %46, i8* %47, i32* %4, i32* %5, i8* %48, i32* %6)
%50 = icmp slt i64 %49, 1
br i1 %50, label %90, label %51
51: ; preds = %38
%52 = bitcast i32* %10 to i8*
%53 = bitcast i32* %11 to i8*
%54 = bitcast i32* %12 to i8*
%55 = bitcast i32* %13 to i8*
%56 = icmp eq i32 %28, -1
br label %57
57: ; preds = %51, %87
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%59 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %87, label %61
61: ; preds = %57
%62 = call i32 @sscanf(i8* %47, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32* %10, i8* %14, i32* %11, i8* %14, i32* %12, i8* %14, i32* %13)
%63 = load i32, i32* %6
br i1 %56, label %64, label %74
64: ; preds = %61
%65 = load i32, i32* %11
%66 = load i32, i32* %12
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %63, i32 %65, i32 %66, i8* %47)
%68 = load i32, i32* %6
%69 = trunc i32 %68 to i8
%70 = load i32, i32* %12
%71 = mul nsw i32 %70, %22
%72 = load i32, i32* %11
%73 = add nsw i32 %71, %72
br label %81
74: ; preds = %61
%75 = icmp sgt i32 %63, %28
br i1 %75, label %86, label %76
76: ; preds = %74
%77 = load i32, i32* %12
%78 = mul nsw i32 %77, %22
%79 = load i32, i32* %11
%80 = add nsw i32 %78, %79
br label %81
81: ; preds = %64, %76
%82 = phi i32 [ %80, %76 ], [ %73, %64 ]
%83 = phi i8 [ -1, %76 ], [ %69, %64 ]
%84 = sext i32 %82 to i64
%85 = getelementptr inbounds i8, i8* %40, i64 %84
store i8 %83, i8* %85
br label %86
86: ; preds = %81, %74
br label %87
87: ; preds = %57, %86
%88 = call i64 @fscanf(i32* %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32* %3, i8* %46, i8* %47, i32* %4, i32* %5, i8* %48, i32* %6)
%89 = icmp slt i64 %88, 1
br i1 %89, label %90, label %57
90: ; preds = %87, %38
%91 = ptrtoint i32* %36 to i64
%92 = trunc i64 %91 to i32
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %22, i32 %25, i32 255)
%94 = icmp sgt i32 %25, 0
br i1 %94, label %95, label %104
95: ; preds = %90
%96 = icmp sgt i32 %22, 0
%97 = sext i32 %22 to i64
%98 = zext i32 %25 to i64
%99 = zext i32 %22 to i64
br label %100
100: ; preds = %95, %106
%101 = phi i64 [ 0, %95 ], [ %107, %106 ]
br i1 %96, label %102, label %106
102: ; preds = %100
%103 = mul nsw i64 %101, %97
br label %109
104: ; preds = %106, %90
%105 = call i32 @fclose(i32* %36)
br label %121
106: ; preds = %109, %100
%107 = add nuw nsw i64 %101, 1
%108 = icmp eq i64 %107, %98
br i1 %108, label %104, label %100
109: ; preds = %102, %109
%110 = phi i64 [ 0, %102 ], [ %116, %109 ]
%111 = add nsw i64 %110, %103
%112 = getelementptr inbounds i8, i8* %40, i64 %111
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %114)
%116 = add nuw nsw i64 %110, 1
%117 = icmp eq i64 %116, %99
br i1 %117, label %106, label %109
118: ; preds = %33
%119 = load i32, i32* @stderr
%120 = tail call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %121
121: ; preds = %118, %104
%122 = call i32 @fclose(i32* %31)
br label %126
123: ; preds = %19
%124 = load i32, i32* @stderr
%125 = tail call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
br label %126
126: ; preds = %121, %123, %16
ret i32 0
}