#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*/ GL_BACK_LEFT;
int /*<<< orphan*/ GL_BACK_RIGHT;
int /*<<< orphan*/ GL_RGB;
int /*<<< orphan*/ GL_UNSIGNED_BYTE;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ glReadBuffer(int /*<<< orphan*/);
int /*<<< orphan*/ glReadPixels(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                int, int /*<<< orphan*/, int /*<<< orphan*/,
                                unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int WindowDump(int width, int height, int stereo) {
  int i, j;
  FILE *fptr;
  static int counter = 0;
  char fname[32];
  unsigned char *image;
  if ((image = (unsigned char *)malloc(3 * width * height * sizeof(char))) ==
      NULL) {
    fprintf(stderr, "WindowDump - Failed to allocate memory for image\n");
    return (0);
  }
  sprintf(fname, "L_%04d.ppm", counter);
  if ((fptr = fopen(fname, "w")) == NULL) {
    fprintf(stderr, "WindowDump - Failed to open file for window dump\n");
    return (0);
  }
  glReadBuffer(GL_BACK_LEFT);
  glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, image);
  fprintf(fptr, "P3\n%d %d\n255\n", width, height);
  for (j = height - 1; j >= 0; j--) {
    for (i = 0; i < width; i++) {
      fputc(image[3 * j * width + 3 * i + 0], fptr);
      fputc(image[3 * j * width + 3 * i + 1], fptr);
      fputc(image[3 * j * width + 3 * i + 2], fptr);
    }
  }
  fclose(fptr);
  if (stereo) {
    sprintf(fname, "R_%04d.ppm", counter);
    if ((fptr = fopen(fname, "w")) == NULL) {
      fprintf(stderr, "WindowDump - Failed to open file for window dump\n");
      return (0);
    }
    glReadBuffer(GL_BACK_RIGHT);
    glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, image);
    fprintf(fptr, "P3\n%d %d\n255\n", width, height);
    for (j = height - 1; j >= 0; j--) {
      for (i = 0; i < width; i++) {
        fputc(image[3 * j * width + 3 * i + 0], fptr);
        fputc(image[3 * j * width + 3 * i + 1], fptr);
        fputc(image[3 * j * width + 3 * i + 2], fptr);
      }
    }
    fclose(fptr);
  }
  free(image);
  counter++;
  return (1);
}


x86 assembly (clang, -O0):
<WindowDump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
imul   $0x3,-0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    11e8 <WindowDump+0x58>
mov    0x2dfd(%rip),%rax
movslq (%rax),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14ed <WindowDump+0x35d>
lea    -0x40(%rbp),%rdi
mov    0x2e7a(%rip),%edx
lea    0xe39(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1240 <WindowDump+0xb0>
mov    0x2da5(%rip),%rax
movslq (%rax),%rdi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14ed <WindowDump+0x35d>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   1040 <glReadBuffer@plt>
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    0x2d95(%rip),%rax
mov    (%rax),%r8d
mov    0x2d5b(%rip),%rax
mov    (%rax),%r9d
mov    -0x48(%rbp),%rax
xor    %esi,%esi
mov    %esi,%edi
mov    %rax,(%rsp)
call   1080 <glReadPixels@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     134d <WindowDump+0x1bd>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    133a <WindowDump+0x1aa>
mov    -0x48(%rbp),%rax
imul   $0x3,-0x18(%rbp),%ecx
imul   -0x8(%rbp),%ecx
imul   $0x3,-0x14(%rbp),%edx
add    %edx,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1060 <fputc@plt>
mov    -0x48(%rbp),%rax
imul   $0x3,-0x18(%rbp),%ecx
imul   -0x8(%rbp),%ecx
imul   $0x3,-0x14(%rbp),%edx
add    %edx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1060 <fputc@plt>
mov    -0x48(%rbp),%rax
imul   $0x3,-0x18(%rbp),%ecx
imul   -0x8(%rbp),%ecx
imul   $0x3,-0x14(%rbp),%edx
add    %edx,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1060 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12ab <WindowDump+0x11b>
jmp    133f <WindowDump+0x1af>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    129a <WindowDump+0x10a>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x10(%rbp)
je     14ce <WindowDump+0x33e>
lea    -0x40(%rbp),%rdi
mov    0x2d02(%rip),%edx
lea    0xd0e(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x40(%rbp),%rdi
lea    0xcbc(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    13b8 <WindowDump+0x228>
mov    0x2c2d(%rip),%rax
movslq (%rax),%rdi
lea    0xc9a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14ed <WindowDump+0x35d>
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
call   1040 <glReadBuffer@plt>
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    0x2c1d(%rip),%rax
mov    (%rax),%r8d
mov    0x2be3(%rip),%rax
mov    (%rax),%r9d
mov    -0x48(%rbp),%rax
xor    %esi,%esi
mov    %esi,%edi
mov    %rax,(%rsp)
call   1080 <glReadPixels@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xc6f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     14c5 <WindowDump+0x335>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    14b2 <WindowDump+0x322>
mov    -0x48(%rbp),%rax
imul   $0x3,-0x18(%rbp),%ecx
imul   -0x8(%rbp),%ecx
imul   $0x3,-0x14(%rbp),%edx
add    %edx,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1060 <fputc@plt>
mov    -0x48(%rbp),%rax
imul   $0x3,-0x18(%rbp),%ecx
imul   -0x8(%rbp),%ecx
imul   $0x3,-0x14(%rbp),%edx
add    %edx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1060 <fputc@plt>
mov    -0x48(%rbp),%rax
imul   $0x3,-0x18(%rbp),%ecx
imul   -0x8(%rbp),%ecx
imul   $0x3,-0x14(%rbp),%edx
add    %edx,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1060 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1423 <WindowDump+0x293>
jmp    14b7 <WindowDump+0x327>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1412 <WindowDump+0x282>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b8f(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2b86(%rip)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WindowDump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rax
mov    %rdi,0x10(%rsp)
imul   %esi,%eax
lea    (%rax,%rax,2),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1440 <WindowDump+0x2a0>
mov    %rax,%rbx
mov    0x2e9b(%rip),%edx
lea    0xe52(%rip),%rsi
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
call   10b0 <sprintf@plt>
lea    0xe49(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1453 <WindowDump+0x2b3>
mov    %rax,%rbp
mov    %r14d,0x2c(%rsp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1040 <glReadBuffer@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%r8d
mov    0x2d94(%rip),%rax
mov    (%rax),%r9d
mov    %rbx,(%rsp)
xor    %edi,%edi
xor    %esi,%esi
mov    0x10(%rsp),%r14
mov    %r14d,%edx
mov    %r15d,%ecx
call   1080 <glReadPixels@plt>
lea    0xe23(%rip),%rsi
mov    %rbp,%rdi
mov    %r14d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    -0x1(%r15),%eax
mov    %rax,0x18(%rsp)
mov    %r15,0x30(%rsp)
test   %r15d,%r15d
jle    1300 <WindowDump+0x160>
mov    0x10(%rsp),%rcx
mov    %ecx,%eax
mov    %rax,0x38(%rsp)
mov    %ecx,%eax
mov    0x18(%rsp),%r13
imul   %r13d,%eax
lea    (%rax,%rax,2),%r15d
lea    (%rcx,%rcx,2),%eax
mov    %eax,0x20(%rsp)
jmp    12b1 <WindowDump+0x111>
nopl   0x0(%rax)
lea    -0x1(%r13),%eax
sub    0x20(%rsp),%r15d
test   %r13d,%r13d
mov    %eax,%r13d
jle    1300 <WindowDump+0x160>
cmpl   $0x0,0x10(%rsp)
jle    12a0 <WindowDump+0x100>
mov    0x38(%rsp),%r12
mov    %r15d,%r14d
movslq %r14d,%r14
movzbl (%rbx,%r14,1),%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
lea    0x1(%r14),%eax
cltq
movzbl (%rbx,%rax,1),%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
lea    0x2(%r14),%eax
cltq
movzbl (%rbx,%rax,1),%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
add    $0x3,%r14d
add    $0xffffffffffffffff,%r12
jne    12c0 <WindowDump+0x120>
jmp    12a0 <WindowDump+0x100>
mov    %rbp,%rdi
call   1050 <fclose@plt>
cmpl   $0x0,0x2c(%rsp)
je     147f <WindowDump+0x2df>
mov    0x2d5b(%rip),%edx
lea    0xd5f(%rip),%rsi
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
call   10b0 <sprintf@plt>
lea    0xd09(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1453 <WindowDump+0x2b3>
mov    %rax,%r13
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
call   1040 <glReadBuffer@plt>
mov    0x2c93(%rip),%rax
mov    (%rax),%r8d
mov    0x2c59(%rip),%rax
mov    (%rax),%r9d
mov    %rbx,(%rsp)
xor    %edi,%edi
xor    %esi,%esi
mov    0x10(%rsp),%r14
mov    %r14d,%edx
mov    0x30(%rsp),%rbp
mov    %ebp,%ecx
call   1080 <glReadPixels@plt>
lea    0xce4(%rip),%rsi
mov    %r13,%rdi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %ebp,%ebp
jle    1477 <WindowDump+0x2d7>
mov    0x10(%rsp),%rcx
mov    %ecx,%eax
mov    %rax,0x20(%rsp)
mov    %ecx,%eax
imul   0x18(%rsp),%eax
lea    (%rax,%rax,2),%r12d
lea    (%rcx,%rcx,2),%r14d
jmp    13e8 <WindowDump+0x248>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rcx
lea    -0x1(%rcx),%eax
sub    %r14d,%r12d
test   %ecx,%ecx
mov    %rax,0x18(%rsp)
jle    1477 <WindowDump+0x2d7>
cmpl   $0x0,0x10(%rsp)
jle    13d0 <WindowDump+0x230>
mov    0x20(%rsp),%rbp
mov    %r12d,%r15d
nopw   0x0(%rax,%rax,1)
movslq %r15d,%r15
movzbl (%rbx,%r15,1),%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
lea    0x1(%r15),%eax
cltq
movzbl (%rbx,%rax,1),%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
lea    0x2(%r15),%eax
cltq
movzbl (%rbx,%rax,1),%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
add    $0x3,%r15d
add    $0xffffffffffffffff,%rbp
jne    1400 <WindowDump+0x260>
jmp    13d0 <WindowDump+0x230>
mov    0x2b81(%rip),%rax
movslq (%rax),%rcx
lea    0xbaf(%rip),%rdi
jmp    1464 <WindowDump+0x2c4>
mov    0x2b6e(%rip),%rax
movslq (%rax),%rcx
lea    0xbdb(%rip),%rdi
mov    $0x31,%esi
mov    $0x1,%edx
call   10c0 <fwrite@plt>
xor    %eax,%eax
jmp    1493 <WindowDump+0x2f3>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
addl   $0x1,0x2be6(%rip)
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@WindowDump.counter = internal global i32 0
@stderr = global i32 0
@.str = [50 x i8] c"WindowDump - Failed to allocate memory for image\0A\00"
@.str.1 = [11 x i8] c"L_%04d.ppm\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [50 x i8] c"WindowDump - Failed to open file for window dump\0A\00"
@GL_BACK_LEFT = global i32 0
@GL_RGB = global i32 0
@GL_UNSIGNED_BYTE = global i32 0
@.str.4 = [14 x i8] c"P3\0A%d %d\0A255\0A\00"
@.str.5 = [11 x i8] c"R_%04d.ppm\00"
@GL_BACK_RIGHT = global i32 0
define i32 @WindowDump(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca [32 x i8]
%12 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%13 = load i32, i32* %5
%14 = mul nsw i32 3, %13
%15 = load i32, i32* %6
%16 = mul nsw i32 %14, %15
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %12
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %28
23: ; preds = %3
%24 = load i32, i32* @stderr
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i32*
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %211
28: ; preds = %3
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%30 = load i32, i32* @WindowDump.counter
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %10
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %40
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i32*
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %211
40: ; preds = %28
%41 = load i32, i32* @GL_BACK_LEFT
%42 = call i32 @glReadBuffer(i32 %41)
%43 = load i32, i32* %5
%44 = load i32, i32* %6
%45 = load i32, i32* @GL_RGB
%46 = load i32, i32* @GL_UNSIGNED_BYTE
%47 = load i8*, i8** %12
%48 = call i32 @glReadPixels(i32 0, i32 0, i32 %43, i32 %44, i32 %45, i32 %46, i8* %47)
%49 = load i32*, i32** %10
%50 = load i32, i32* %5
%51 = load i32, i32* %6
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %50, i32 %51)
%53 = load i32, i32* %6
%54 = sub nsw i32 %53, 1
store i32 %54, i32* %9
br label %55
55: ; preds = %110, %40
%56 = load i32, i32* %9
%57 = icmp sge i32 %56, 0
br i1 %57, label %58, label %113
58: ; preds = %55
store i32 0, i32* %8
br label %59
59: ; preds = %106, %58
%60 = load i32, i32* %8
%61 = load i32, i32* %5
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %109
63: ; preds = %59
%64 = load i8*, i8** %12
%65 = load i32, i32* %9
%66 = mul nsw i32 3, %65
%67 = load i32, i32* %5
%68 = mul nsw i32 %66, %67
%69 = load i32, i32* %8
%70 = mul nsw i32 3, %69
%71 = add nsw i32 %68, %70
%72 = add nsw i32 %71, 0
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %64, i64 %73
%75 = load i8, i8* %74
%76 = load i32*, i32** %10
%77 = call i32 @fputc(i8 zeroext %75, i32* %76)
%78 = load i8*, i8** %12
%79 = load i32, i32* %9
%80 = mul nsw i32 3, %79
%81 = load i32, i32* %5
%82 = mul nsw i32 %80, %81
%83 = load i32, i32* %8
%84 = mul nsw i32 3, %83
%85 = add nsw i32 %82, %84
%86 = add nsw i32 %85, 1
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %78, i64 %87
%89 = load i8, i8* %88
%90 = load i32*, i32** %10
%91 = call i32 @fputc(i8 zeroext %89, i32* %90)
%92 = load i8*, i8** %12
%93 = load i32, i32* %9
%94 = mul nsw i32 3, %93
%95 = load i32, i32* %5
%96 = mul nsw i32 %94, %95
%97 = load i32, i32* %8
%98 = mul nsw i32 3, %97
%99 = add nsw i32 %96, %98
%100 = add nsw i32 %99, 2
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %92, i64 %101
%103 = load i8, i8* %102
%104 = load i32*, i32** %10
%105 = call i32 @fputc(i8 zeroext %103, i32* %104)
br label %106
106: ; preds = %63
%107 = load i32, i32* %8
%108 = add nsw i32 %107, 1
store i32 %108, i32* %8
br label %59
109: ; preds = %59
br label %110
110: ; preds = %109
%111 = load i32, i32* %9
%112 = add nsw i32 %111, -1
store i32 %112, i32* %9
br label %55
113: ; preds = %55
%114 = load i32*, i32** %10
%115 = call i32 @fclose(i32* %114)
%116 = load i32, i32* %7
%117 = icmp ne i32 %116, 0
br i1 %117, label %118, label %206
118: ; preds = %113
%119 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%120 = load i32, i32* @WindowDump.counter
%121 = call i32 @sprintf(i8* %119, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %120)
%122 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%123 = call i32* @fopen(i8* %122, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %123, i32** %10
%124 = icmp eq i32* %123, null
br i1 %124, label %125, label %130
125: ; preds = %118
%126 = load i32, i32* @stderr
%127 = sext i32 %126 to i64
%128 = inttoptr i64 %127 to i32*
%129 = call i32 (i32*, i8*, ...) @fprintf(i32* %128, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %211
130: ; preds = %118
%131 = load i32, i32* @GL_BACK_RIGHT
%132 = call i32 @glReadBuffer(i32 %131)
%133 = load i32, i32* %5
%134 = load i32, i32* %6
%135 = load i32, i32* @GL_RGB
%136 = load i32, i32* @GL_UNSIGNED_BYTE
%137 = load i8*, i8** %12
%138 = call i32 @glReadPixels(i32 0, i32 0, i32 %133, i32 %134, i32 %135, i32 %136, i8* %137)
%139 = load i32*, i32** %10
%140 = load i32, i32* %5
%141 = load i32, i32* %6
%142 = call i32 (i32*, i8*, ...) @fprintf(i32* %139, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %140, i32 %141)
%143 = load i32, i32* %6
%144 = sub nsw i32 %143, 1
store i32 %144, i32* %9
br label %145
145: ; preds = %200, %130
%146 = load i32, i32* %9
%147 = icmp sge i32 %146, 0
br i1 %147, label %148, label %203
148: ; preds = %145
store i32 0, i32* %8
br label %149
149: ; preds = %196, %148
%150 = load i32, i32* %8
%151 = load i32, i32* %5
%152 = icmp slt i32 %150, %151
br i1 %152, label %153, label %199
153: ; preds = %149
%154 = load i8*, i8** %12
%155 = load i32, i32* %9
%156 = mul nsw i32 3, %155
%157 = load i32, i32* %5
%158 = mul nsw i32 %156, %157
%159 = load i32, i32* %8
%160 = mul nsw i32 3, %159
%161 = add nsw i32 %158, %160
%162 = add nsw i32 %161, 0
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds i8, i8* %154, i64 %163
%165 = load i8, i8* %164
%166 = load i32*, i32** %10
%167 = call i32 @fputc(i8 zeroext %165, i32* %166)
%168 = load i8*, i8** %12
%169 = load i32, i32* %9
%170 = mul nsw i32 3, %169
%171 = load i32, i32* %5
%172 = mul nsw i32 %170, %171
%173 = load i32, i32* %8
%174 = mul nsw i32 3, %173
%175 = add nsw i32 %172, %174
%176 = add nsw i32 %175, 1
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds i8, i8* %168, i64 %177
%179 = load i8, i8* %178
%180 = load i32*, i32** %10
%181 = call i32 @fputc(i8 zeroext %179, i32* %180)
%182 = load i8*, i8** %12
%183 = load i32, i32* %9
%184 = mul nsw i32 3, %183
%185 = load i32, i32* %5
%186 = mul nsw i32 %184, %185
%187 = load i32, i32* %8
%188 = mul nsw i32 3, %187
%189 = add nsw i32 %186, %188
%190 = add nsw i32 %189, 2
%191 = sext i32 %190 to i64
%192 = getelementptr inbounds i8, i8* %182, i64 %191
%193 = load i8, i8* %192
%194 = load i32*, i32** %10
%195 = call i32 @fputc(i8 zeroext %193, i32* %194)
br label %196
196: ; preds = %153
%197 = load i32, i32* %8
%198 = add nsw i32 %197, 1
store i32 %198, i32* %8
br label %149
199: ; preds = %149
br label %200
200: ; preds = %199
%201 = load i32, i32* %9
%202 = add nsw i32 %201, -1
store i32 %202, i32* %9
br label %145
203: ; preds = %145
%204 = load i32*, i32** %10
%205 = call i32 @fclose(i32* %204)
br label %206
206: ; preds = %203, %113
%207 = load i8*, i8** %12
%208 = call i32 @free(i8* %207)
%209 = load i32, i32* @WindowDump.counter
%210 = add nsw i32 %209, 1
store i32 %210, i32* @WindowDump.counter
store i32 1, i32* %4
br label %211
211: ; preds = %206, %125, %35, %23
%212 = load i32, i32* %4
ret i32 %212
}

LLVM IR (-O2):
@WindowDump.counter = internal unnamed_addr global i32 0
@stderr = global i32 0
@.str = [50 x i8] c"WindowDump - Failed to allocate memory for image\0A\00"
@.str.1 = [11 x i8] c"L_%04d.ppm\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [50 x i8] c"WindowDump - Failed to open file for window dump\0A\00"
@GL_BACK_LEFT = global i32 0
@GL_RGB = global i32 0
@GL_UNSIGNED_BYTE = global i32 0
@.str.4 = [14 x i8] c"P3\0A%d %d\0A255\0A\00"
@.str.5 = [11 x i8] c"R_%04d.ppm\00"
@GL_BACK_RIGHT = global i32 0
define i32 @WindowDump(i32 %0, i32 %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = mul nsw i32 %0, 3
%7 = mul nsw i32 %6, %1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i32*
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 49, i64 1, i32* %14)
br label %123
16: ; preds = %3
%17 = load i32, i32* @WindowDump.counter
%18 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i64 49, i64 1, i32* %24)
br label %123
26: ; preds = %16
%27 = load i32, i32* @GL_BACK_LEFT
%28 = tail call i32 @glReadBuffer(i32 %27)
%29 = load i32, i32* @GL_RGB
%30 = load i32, i32* @GL_UNSIGNED_BYTE
%31 = tail call i32 @glReadPixels(i32 0, i32 0, i32 %0, i32 %1, i32 %29, i32 %30, i8* %9)
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %0, i32 %1)
%33 = add nsw i32 %1, -1
%34 = icmp sgt i32 %1, 0
br i1 %34, label %35, label %66
35: ; preds = %26
%36 = icmp sgt i32 %0, 0
%37 = zext i32 %0 to i64
br label %38
38: ; preds = %35, %63
%39 = phi i32 [ %33, %35 ], [ %64, %63 ]
br i1 %36, label %40, label %63
40: ; preds = %38
%41 = mul i32 %39, %0
br label %42
42: ; preds = %40, %42
%43 = phi i64 [ 0, %40 ], [ %61, %42 ]
%44 = trunc i64 %43 to i32
%45 = add i32 %41, %44
%46 = mul i32 %45, 3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %9, i64 %47
%49 = load i8, i8* %48
%50 = tail call i32 @fputc(i8 zeroext %49, i32* %19)
%51 = add nsw i32 %46, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %9, i64 %52
%54 = load i8, i8* %53
%55 = tail call i32 @fputc(i8 zeroext %54, i32* %19)
%56 = add nsw i32 %46, 2
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %9, i64 %57
%59 = load i8, i8* %58
%60 = tail call i32 @fputc(i8 zeroext %59, i32* %19)
%61 = add nuw nsw i64 %43, 1
%62 = icmp eq i64 %61, %37
br i1 %62, label %63, label %42
63: ; preds = %42, %38
%64 = add nsw i32 %39, -1
%65 = icmp sgt i32 %39, 0
br i1 %65, label %38, label %66
66: ; preds = %63, %26
%67 = tail call i32 @fclose(i32* %19)
%68 = icmp eq i32 %2, 0
br i1 %68, label %119, label %69
69: ; preds = %66
%70 = load i32, i32* @WindowDump.counter
%71 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %70)
%72 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%73 = icmp eq i32* %72, null
br i1 %73, label %74, label %79
74: ; preds = %69
%75 = load i32, i32* @stderr
%76 = sext i32 %75 to i64
%77 = inttoptr i64 %76 to i32*
%78 = tail call i64 @fwrite(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i64 49, i64 1, i32* %77)
br label %123
79: ; preds = %69
%80 = load i32, i32* @GL_BACK_RIGHT
%81 = tail call i32 @glReadBuffer(i32 %80)
%82 = load i32, i32* @GL_RGB
%83 = load i32, i32* @GL_UNSIGNED_BYTE
%84 = tail call i32 @glReadPixels(i32 0, i32 0, i32 %0, i32 %1, i32 %82, i32 %83, i8* %9)
%85 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %0, i32 %1)
br i1 %34, label %86, label %117
86: ; preds = %79
%87 = icmp sgt i32 %0, 0
%88 = zext i32 %0 to i64
br label %89
89: ; preds = %86, %114
%90 = phi i32 [ %33, %86 ], [ %115, %114 ]
br i1 %87, label %91, label %114
91: ; preds = %89
%92 = mul i32 %90, %0
br label %93
93: ; preds = %91, %93
%94 = phi i64 [ 0, %91 ], [ %112, %93 ]
%95 = trunc i64 %94 to i32
%96 = add i32 %92, %95
%97 = mul i32 %96, 3
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %9, i64 %98
%100 = load i8, i8* %99
%101 = tail call i32 @fputc(i8 zeroext %100, i32* %72)
%102 = add nsw i32 %97, 1
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %9, i64 %103
%105 = load i8, i8* %104
%106 = tail call i32 @fputc(i8 zeroext %105, i32* %72)
%107 = add nsw i32 %97, 2
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %9, i64 %108
%110 = load i8, i8* %109
%111 = tail call i32 @fputc(i8 zeroext %110, i32* %72)
%112 = add nuw nsw i64 %94, 1
%113 = icmp eq i64 %112, %88
br i1 %113, label %114, label %93
114: ; preds = %93, %89
%115 = add nsw i32 %90, -1
%116 = icmp sgt i32 %90, 0
br i1 %116, label %89, label %117
117: ; preds = %114, %79
%118 = tail call i32 @fclose(i32* %72)
br label %119
119: ; preds = %117, %66
%120 = tail call i32 @free(i8* %9)
%121 = load i32, i32* @WindowDump.counter
%122 = add nsw i32 %121, 1
store i32 %122, i32* @WindowDump.counter
br label %123
123: ; preds = %119, %74, %21, %11
%124 = phi i32 [ 0, %11 ], [ 0, %21 ], [ 0, %74 ], [ 1, %119 ]
ret i32 %124
}