#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ readheader(int /*<<< orphan*/ *, int *, int *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ writeoutput(char const *, int /*<<< orphan*/ *, int, int,
                               int);
int main(int argc, char *argv[]) {
  const char *fn;
  FILE *ppm = NULL;
  int X, Y, bpp;
  int ok = 0;
  if (argc < 2) {
    fprintf(stderr, "%s input.ppm\n", argv[0]);
    goto cleanup;
  }
  fn = argv[1];
  ppm = fopen(fn, "rb");
  if (!readheader(ppm, &X, &Y, &bpp))
    goto cleanup;
  if (!writeoutput(fn, ppm, X, Y, bpp))
    goto cleanup;
  ok = 1;
cleanup:
  if (ppm)
    fclose(ppm);
  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a0 <main+0x50>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe6a(%rip),%rsi
call   1050 <fprintf@plt>
jmp    120f <main+0xbf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1040 <readheader@plt>
cmp    $0x0,%eax
jne    11e3 <main+0x93>
jmp    120f <main+0xbf>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
call   1060 <writeoutput@plt>
cmp    $0x0,%eax
jne    1208 <main+0xb8>
jmp    120f <main+0xbf>
movl   $0x1,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1223 <main+0xd3>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x30(%rbp)
je     123e <main+0xee>
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    124a <main+0xfa>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jg     1177 <main+0x27>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe90(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11e9 <main+0x99>
mov    0x8(%rsi),%r14
lea    0xe8c(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
call   1040 <readheader@plt>
test   %eax,%eax
je     11dc <main+0x8c>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%r8d
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <writeoutput@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     11cf <main+0x7f>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %ebp,%ebp
je     11e9 <main+0x99>
mov    0x2df6(%rip),%rax
jmp    11f0 <main+0xa0>
test   %rbx,%rbx
je     11e9 <main+0x99>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"%s input.ppm\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %7
store i32 0, i32* %11
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %40
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %7
%26 = load i32*, i32** %7
%27 = call i32 @readheader(i32* %26, i32* %8, i32* %9, i32* %10)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %20
br label %40
30: ; preds = %20
%31 = load i8*, i8** %6
%32 = load i32*, i32** %7
%33 = load i32, i32* %8
%34 = load i32, i32* %9
%35 = load i32, i32* %10
%36 = call i32 @writeoutput(i8* %31, i32* %32, i32 %33, i32 %34, i32 %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %30
br label %40
39: ; preds = %30
store i32 1, i32* %11
br label %40
40: ; preds = %39, %38, %29, %14
%41 = load i32*, i32** %7
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
br label %46
46: ; preds = %43, %40
%47 = load i32, i32* %11
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = load i32, i32* @EXIT_SUCCESS
br label %53
51: ; preds = %46
%52 = load i32, i32* @EXIT_FAILURE
br label %53
53: ; preds = %51, %49
%54 = phi i32 [ %50, %49 ], [ %52, %51 ]
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"%s input.ppm\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %34
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @readheader(i32* %17, i32* %3, i32* %4, i32* %5)
%19 = icmp eq i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %14
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @writeoutput(i8* %16, i32* %17, i32 %21, i32 %22, i32 %23)
%25 = icmp eq i32 %24, 0
%26 = icmp eq i32* %17, null
br i1 %26, label %33, label %31
27: ; preds = %14
%28 = icmp eq i32* %17, null
br i1 %28, label %34, label %29
29: ; preds = %27
%30 = call i32 @fclose(i32* %17)
br label %34
31: ; preds = %20
%32 = call i32 @fclose(i32* %17)
br i1 %25, label %34, label %35
33: ; preds = %20
br i1 %25, label %34, label %35
34: ; preds = %27, %29, %31, %10, %33
br label %35
35: ; preds = %31, %33, %34
%36 = phi i32* [ @EXIT_FAILURE, %34 ], [ @EXIT_SUCCESS, %33 ], [ @EXIT_SUCCESS, %31 ]
%37 = load i32, i32* %36
ret i32 %37
}