#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int cutint(int);
char *malloc(int);
char nextchar(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
char *ppm_load(char *path, int *h, int *w) {
  char *d;
  int fd = open(path, O_RDONLY);
  if (fd < 0 || nextchar(fd) != 'P' || nextchar(fd) != '6')
    return NULL;
  *w = cutint(fd);
  *h = cutint(fd);
  cutint(fd);
  d = malloc(*h * *w * 3);
  read(fd, d, *h * *w * 3);
  close(fd);
  return d;
}


x86 assembly (clang, -O0):
<ppm_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     11bb <ppm_load+0x5b>
mov    -0x2c(%rbp),%edi
call   1070 <nextchar@plt>
movsbl %al,%eax
cmp    $0x50,%eax
jne    11bb <ppm_load+0x5b>
mov    -0x2c(%rbp),%edi
call   1070 <nextchar@plt>
movsbl %al,%eax
cmp    $0x36,%eax
je     11c8 <ppm_load+0x68>
movq   $0x0,-0x8(%rbp)
jmp    1235 <ppm_load+0xd5>
mov    -0x2c(%rbp),%edi
call   1030 <cutint@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%edi
call   1030 <cutint@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%edi
call   1030 <cutint@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%eax
imul   $0x3,%eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%eax
imul   $0x3,%eax,%edx
call   1050 <read@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ppm_load>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     11db <ppm_load+0x7b>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <nextchar@plt>
cmp    $0x50,%al
jne    11db <ppm_load+0x7b>
mov    %ebx,%edi
call   1070 <nextchar@plt>
cmp    $0x36,%al
jne    11db <ppm_load+0x7b>
mov    %ebx,%edi
call   1030 <cutint@plt>
mov    %eax,(%r14)
mov    %ebx,%edi
call   1030 <cutint@plt>
mov    %eax,(%r15)
mov    %ebx,%edi
call   1030 <cutint@plt>
mov    (%r15),%eax
imul   (%r14),%eax
lea    (%rax,%rax,2),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    %rax,%rsi
mov    %ebp,%edx
call   1050 <read@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11de <ppm_load+0x7e>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i8* @ppm_load(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %3
%16 = load i32, i32* %9
%17 = call signext i8 @nextchar(i32 %16)
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 80
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = load i32, i32* %9
%22 = call signext i8 @nextchar(i32 %21)
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 54
br i1 %24, label %25, label %26
25: ; preds = %20, %15, %3
store i8* null, i8** %4
br label %54
26: ; preds = %20
%27 = load i32, i32* %9
%28 = call i32 @cutint(i32 %27)
%29 = load i32*, i32** %7
store i32 %28, i32* %29
%30 = load i32, i32* %9
%31 = call i32 @cutint(i32 %30)
%32 = load i32*, i32** %6
store i32 %31, i32* %32
%33 = load i32, i32* %9
%34 = call i32 @cutint(i32 %33)
%35 = load i32*, i32** %6
%36 = load i32, i32* %35
%37 = load i32*, i32** %7
%38 = load i32, i32* %37
%39 = mul nsw i32 %36, %38
%40 = mul nsw i32 %39, 3
%41 = call i8* @malloc(i32 %40)
store i8* %41, i8** %8
%42 = load i32, i32* %9
%43 = load i8*, i8** %8
%44 = load i32*, i32** %6
%45 = load i32, i32* %44
%46 = load i32*, i32** %7
%47 = load i32, i32* %46
%48 = mul nsw i32 %45, %47
%49 = mul nsw i32 %48, 3
%50 = call i32 @read(i32 %42, i8* %43, i32 %49)
%51 = load i32, i32* %9
%52 = call i32 @close(i32 %51)
%53 = load i8*, i8** %8
store i8* %53, i8** %4
br label %54
54: ; preds = %26, %25
%55 = load i8*, i8** %4
ret i8* %55
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define noalias i8* @ppm_load(i8* nocapture %0, i32* nocapture %1, i32* nocapture %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %24, label %7
7: ; preds = %3
%8 = tail call signext i8 @nextchar(i32 %5)
%9 = icmp eq i8 %8, 80
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = tail call signext i8 @nextchar(i32 %5)
%12 = icmp eq i8 %11, 54
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = tail call i32 @cutint(i32 %5)
store i32 %14, i32* %2
%15 = tail call i32 @cutint(i32 %5)
store i32 %15, i32* %1
%16 = tail call i32 @cutint(i32 %5)
%17 = load i32, i32* %1
%18 = load i32, i32* %2
%19 = mul i32 %17, 3
%20 = mul i32 %19, %18
%21 = tail call i8* @malloc(i32 %20)
%22 = tail call i32 @read(i32 %5, i8* %21, i32 %20)
%23 = tail call i32 @close(i32 %5)
br label %24
24: ; preds = %3, %7, %10, %13
%25 = phi i8* [ %21, %13 ], [ null, %10 ], [ null, %7 ], [ null, %3 ]
ret i8* %25
}