#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 scalar_t__ uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ die(char *, char const *, ...);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fread(int *, int, int, int /*<<< orphan*/ *);
int load_ppm(const char *filename, uint32_t *pixels, uint8_t alpha) {
  FILE *f;
  int y, x;
  uint32_t buf;
  f = fopen(filename, "rb");
  if (f == NULL)
    die("Can't open '%s'", filename);
  buf = (uint32_t)alpha << 24;
  for (y = 0; y < 480; y++) {
    for (x = 0; x < 640; x++) {
      if (fread(&buf, 3, 1, f) == 0) {
        die("Can't read '%s'.  Has PPM got size %d x %d?", filename, 640, 480);
        fclose(f);
        return 0;
      } else
        *pixels++ = buf;
    }
  }
  fclose(f);
  return 1;
}


x86 assembly (clang, -O0):
<load_ppm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1185 <load_ppm+0x45>
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1060 <die@plt>
mov    -0x20(%rbp),%rax
shl    $0x18,%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1e0,-0x2c(%rbp)
jge    1243 <load_ppm+0x103>
movl   $0x0,-0x30(%rbp)
cmpl   $0x280,-0x30(%rbp)
jge    1230 <load_ppm+0xf0>
mov    -0x28(%rbp),%rcx
lea    -0x34(%rbp),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    1209 <load_ppm+0xc9>
mov    -0x10(%rbp),%rsi
lea    0xe30(%rip),%rdi
mov    $0x280,%edx
mov    $0x1e0,%ecx
mov    $0x0,%al
call   1060 <die@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1253 <load_ppm+0x113>
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
jmp    1222 <load_ppm+0xe2>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11aa <load_ppm+0x6a>
jmp    1235 <load_ppm+0xf5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1196 <load_ppm+0x56>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_ppm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1179 <load_ppm+0x39>
lea    0xe94(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <die@plt>
shl    $0x18,%r12d
mov    %r12d,0x4(%rsp)
xor    %r13d,%r13d
lea    0x4(%rsp),%r12
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11d4 <load_ppm+0x94>
mov    0x4(%rsp),%eax
mov    %eax,(%rbx,%rbp,1)
add    $0x4,%rbp
cmp    $0xa00,%ebp
jne    1190 <load_ppm+0x50>
add    $0x1,%r13d
add    %rbp,%rbx
cmp    $0x1e0,%r13d
jne    118a <load_ppm+0x4a>
mov    $0x1,%ebx
jmp    11f1 <load_ppm+0xb1>
lea    0xe38(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
mov    $0x280,%edx
mov    $0x1e0,%ecx
xor    %eax,%eax
call   1060 <die@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [16 x i8] c"Can't open '%s'\00"
@.str.2 = [44 x i8] c"Can't read '%s'. Has PPM got size %d x %d?\00"
define i32 @load_ppm(i8* %0, i32* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = load i32*, i32** %8
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %3
%20 = load i64, i64* %7
%21 = trunc i64 %20 to i32
%22 = shl i32 %21, 24
store i32 %22, i32* %11
store i32 0, i32* %9
br label %23
23: ; preds = %48, %19
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 480
br i1 %25, label %26, label %51
26: ; preds = %23
store i32 0, i32* %10
br label %27
27: ; preds = %44, %26
%28 = load i32, i32* %10
%29 = icmp slt i32 %28, 640
br i1 %29, label %30, label %47
30: ; preds = %27
%31 = load i32*, i32** %8
%32 = call i64 @fread(i32* %11, i32 3, i32 1, i32* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i8*, i8** %5
%36 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %35, i32 640, i32 480)
%37 = load i32*, i32** %8
%38 = call i32 @fclose(i32* %37)
store i32 0, i32* %4
br label %54
39: ; preds = %30
%40 = load i32, i32* %11
%41 = load i32*, i32** %6
%42 = getelementptr inbounds i32, i32* %41, i32 1
store i32* %42, i32** %6
store i32 %40, i32* %41
br label %43
43: ; preds = %39
br label %44
44: ; preds = %43
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %27
47: ; preds = %27
br label %48
48: ; preds = %47
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %23
51: ; preds = %23
%52 = load i32*, i32** %8
%53 = call i32 @fclose(i32* %52)
store i32 1, i32* %4
br label %54
54: ; preds = %51, %34
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [16 x i8] c"Can't open '%s'\00"
@.str.2 = [44 x i8] c"Can't read '%s'. Has PPM got size %d x %d?\00"
define i32 @load_ppm(i8* %0, i32* nocapture writeonly %1, i64 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %8, %3
%11 = trunc i64 %2 to i32
%12 = shl i32 %11, 24
store i32 %12, i32* %4
br label %13
13: ; preds = %10, %28
%14 = phi i32 [ 0, %10 ], [ %29, %28 ]
%15 = phi i32* [ %1, %10 ], [ %25, %28 ]
br label %16
16: ; preds = %13, %23
%17 = phi i32 [ 0, %13 ], [ %26, %23 ]
%18 = phi i32* [ %15, %13 ], [ %25, %23 ]
%19 = call i64 @fread(i32* %4, i32 3, i32 1, i32* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 640, i32 480)
br label %31
23: ; preds = %16
%24 = load i32, i32* %4
%25 = getelementptr inbounds i32, i32* %18, i64 1
store i32 %24, i32* %18
%26 = add nuw nsw i32 %17, 1
%27 = icmp eq i32 %26, 640
br i1 %27, label %28, label %16
28: ; preds = %23
%29 = add nuw nsw i32 %14, 1
%30 = icmp eq i32 %29, 480
br i1 %30, label %31, label %13
31: ; preds = %28, %21
%32 = phi i32 [ 0, %21 ], [ 1, %28 ]
%33 = tail call i32 @fclose(i32* %6)
ret i32 %32
}