#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int /*<<< orphan*/ isspace(char);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
unsigned char *read_ppm_ascii(const char *filename, int *textureWidth,
                              int *textureHeight) {
  FILE *fp;
  char c;
  int width = 0, height = 0, color_depth = 0;
  int r = 0, g = 0, b = 0;
  char buffer[3];
  unsigned char *image = 0;
  unsigned char *loc;
  int num_pixels;
  int i, rv;
  int comment_is_there = 0;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    printf("Cannot open file");
    return NULL;
  }
  i = 0;
  while (i < 3) {
    c = fgetc(fp);
    if (c == EOF) {
      printf("\n%s : Unexpected end of file", filename);
      fclose(fp);
      return NULL;
    }
    buffer[i++] = c;
  }
  if (buffer[0] != 'P' || buffer[1] != '3' || !isspace(buffer[2])) {
    printf("\n%s : P3(ascii ppm signature) not found", filename);
    fclose(fp);
    return NULL;
  }
  c = fgetc(fp);
  if (c == '#') {
    while ((c = fgetc(fp)) != '\n') {
      if (c == EOF) {
        printf("\n%s : Unexpected end of file", filename);
        fclose(fp);
        return NULL;
      }
    }
  } else if (c == EOF) {
    printf("\n%s : Unexpected end of file", filename);
    fclose(fp);
    return NULL;
  } else {
    ungetc(c, fp);
  }
  fscanf(fp, "%d", &width);
  fscanf(fp, "%d", &height);
  fscanf(fp, "%d", &color_depth);
  num_pixels = width * height;
  image = (unsigned char *)malloc(num_pixels * 4 * sizeof(unsigned char));
  loc = image;
  for (i = 0; i < num_pixels; ++i) {
    rv = fscanf(fp, "%d%d%d", &r, &g, &b);
    *loc++ = b;
    *loc++ = g;
    *loc++ = r;
    *loc++ = 255;
    if (rv == EOF)
      break;
  }
  *textureWidth = width;
  *textureHeight = height;
  return image;
}


x86 assembly (clang, -O0):
<read_ppm_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movq   $0x0,-0x50(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1207 <read_ppm_ascii+0x87>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    14d9 <read_ppm_ascii+0x359>
movl   $0x0,-0x60(%rbp)
cmpl   $0x3,-0x60(%rbp)
jge    127b <read_ppm_ascii+0xfb>
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
mov    0x2db9(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1262 <read_ppm_ascii+0xe2>
mov    -0x10(%rbp),%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    14d9 <read_ppm_ascii+0x359>
mov    -0x29(%rbp),%cl
mov    -0x60(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x60(%rbp)
cltq
mov    %cl,-0x47(%rbp,%rax,1)
jmp    120e <read_ppm_ascii+0x8e>
movsbl -0x47(%rbp),%eax
cmp    $0x50,%eax
jne    12a7 <read_ppm_ascii+0x127>
movsbl -0x46(%rbp),%eax
cmp    $0x33,%eax
jne    12a7 <read_ppm_ascii+0x127>
movsbl -0x45(%rbp),%edi
call   1070 <isspace@plt>
cmp    $0x0,%eax
jne    12cf <read_ppm_ascii+0x14f>
mov    -0x10(%rbp),%rsi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    14d9 <read_ppm_ascii+0x359>
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x23,%eax
jne    134d <read_ppm_ascii+0x1cd>
jmp    12ed <read_ppm_ascii+0x16d>
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1348 <read_ppm_ascii+0x1c8>
movsbl -0x29(%rbp),%eax
mov    0x2cd8(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1343 <read_ppm_ascii+0x1c3>
mov    -0x10(%rbp),%rsi
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    14d9 <read_ppm_ascii+0x359>
jmp    12ed <read_ppm_ascii+0x16d>
jmp    139f <read_ppm_ascii+0x21f>
movsbl -0x29(%rbp),%eax
mov    0x2c90(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    138b <read_ppm_ascii+0x20b>
mov    -0x10(%rbp),%rsi
lea    0xca5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    14d9 <read_ppm_ascii+0x359>
mov    -0x29(%rbp),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1090 <ungetc@plt>
jmp    139f <read_ppm_ascii+0x21f>
mov    -0x28(%rbp),%rdi
lea    0xcb2(%rip),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x28(%rbp),%rdi
lea    0xc9c(%rip),%rsi
lea    -0x34(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x28(%rbp),%rdi
lea    0xc86(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x30(%rbp),%eax
imul   -0x34(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jge    14bf <read_ppm_ascii+0x33f>
mov    -0x28(%rbp),%rdi
lea    0xc30(%rip),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    %eax,-0x64(%rbp)
mov    -0x44(%rbp),%eax
mov    %al,%cl
mov    -0x58(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x58(%rbp)
mov    %cl,(%rax)
mov    -0x40(%rbp),%eax
mov    %al,%cl
mov    -0x58(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x58(%rbp)
mov    %cl,(%rax)
mov    -0x3c(%rbp),%eax
mov    %al,%cl
mov    -0x58(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x58(%rbp)
mov    %cl,(%rax)
mov    -0x58(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x58(%rbp)
movb   $0xff,(%rax)
mov    -0x64(%rbp),%eax
mov    0x2b4c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    14ac <read_ppm_ascii+0x32c>
jmp    14bf <read_ppm_ascii+0x33f>
jmp    14b1 <read_ppm_ascii+0x331>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1411 <read_ppm_ascii+0x291>
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ppm_ascii>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r13
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xe32(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     122f <read_ppm_ascii+0xaf>
mov    %rax,%r12
mov    %rbx,0x20(%rsp)
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2df9(%rip),%r14
cmp    (%r14),%al
je     1212 <read_ppm_ascii+0x92>
mov    %eax,%ebx
mov    %r12,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%al
je     1212 <read_ppm_ascii+0x92>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%al
jne    1251 <read_ppm_ascii+0xd1>
lea    0xdfa(%rip),%rdi
xor    %ebx,%ebx
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
jmp    123f <read_ppm_ascii+0xbf>
lea    0xdcc(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x50,%bl
jne    1287 <read_ppm_ascii+0x107>
cmp    $0x33,%bpl
jne    1287 <read_ppm_ascii+0x107>
movsbl %al,%edi
call   1070 <isspace@plt>
test   %eax,%eax
je     1287 <read_ppm_ascii+0x107>
mov    %r12,%rdi
call   1060 <fgetc@plt>
cmp    $0x23,%al
jne    1290 <read_ppm_ascii+0x110>
mov    %r12,%rdi
call   1060 <fgetc@plt>
cmp    $0xa,%al
je     12a4 <read_ppm_ascii+0x124>
cmp    (%r14),%al
jne    1274 <read_ppm_ascii+0xf4>
jmp    1212 <read_ppm_ascii+0x92>
lea    0xda2(%rip),%rdi
jmp    1219 <read_ppm_ascii+0x99>
cmp    (%r14),%al
je     1212 <read_ppm_ascii+0x92>
movsbl %al,%edi
mov    %r12,%rsi
call   1090 <ungetc@plt>
lea    0xdb1(%rip),%rbx
lea    0xc(%rsp),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <fscanf@plt>
lea    0x8(%rsp),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <fscanf@plt>
lea    0x1c(%rsp),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    0x8(%rsp),%r13d
imul   0xc(%rsp),%r13d
lea    0x0(,%r13,4),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
test   %r13d,%r13d
jle    1360 <read_ppm_ascii+0x1e0>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
lea    0xd3e(%rip),%rsi
lea    0x18(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
xor    %eax,%eax
call   1050 <fscanf@plt>
movzbl 0x10(%rsp),%ecx
mov    %cl,(%rbx,%rbp,4)
movzbl 0x14(%rsp),%ecx
mov    %cl,0x1(%rbx,%rbp,4)
movzbl 0x18(%rsp),%ecx
mov    %cl,0x2(%rbx,%rbp,4)
movb   $0xff,0x3(%rbx,%rbp,4)
movsbl (%r14),%ecx
cmp    %ecx,%eax
je     1360 <read_ppm_ascii+0x1e0>
add    $0x1,%rbp
cmp    %r13d,%ebp
jl     1310 <read_ppm_ascii+0x190>
mov    0xc(%rsp),%eax
mov    %eax,(%r15)
mov    0x8(%rsp),%eax
mov    0x20(%rsp),%rcx
mov    %eax,(%rcx)
jmp    123f <read_ppm_ascii+0xbf>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"Cannot open file\00"
@EOF = global i8 0
@.str.2 = [29 x i8] c"\0A%s : Unexpected end of file\00"
@.str.3 = [40 x i8] c"\0A%s : P3(ascii ppm signature) not found\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [7 x i8] c"%d%d%d\00"
define i8* @read_ppm_ascii(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%12 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%13 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%14 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%15 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %3
%19 = tail call signext i8 @fgetc(i32* %16)
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %19, %20
br i1 %21, label %24, label %27
22: ; preds = %3
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %99
24: ; preds = %31, %27, %18
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%26 = tail call i32 @fclose(i32* %16)
br label %99
27: ; preds = %18
%28 = tail call signext i8 @fgetc(i32* %16)
%29 = load i8, i8* @EOF
%30 = icmp eq i8 %28, %29
br i1 %30, label %24, label %31
31: ; preds = %27
%32 = tail call signext i8 @fgetc(i32* %16)
%33 = load i8, i8* @EOF
%34 = icmp eq i8 %32, %33
br i1 %34, label %24, label %35
35: ; preds = %31
%36 = icmp ne i8 %19, 80
%37 = icmp ne i8 %28, 51
%38 = or i1 %36, %37
br i1 %38, label %42, label %39
39: ; preds = %35
%40 = tail call i32 @isspace(i8 signext %32)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39, %35
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%44 = tail call i32 @fclose(i32* %16)
br label %99
45: ; preds = %39
%46 = tail call signext i8 @fgetc(i32* %16)
%47 = icmp eq i8 %46, 35
br i1 %47, label %48, label %57
48: ; preds = %45, %51
%49 = tail call signext i8 @fgetc(i32* %16)
%50 = icmp eq i8 %49, 10
br i1 %50, label %65, label %51
51: ; preds = %48
%52 = load i8, i8* @EOF
%53 = icmp eq i8 %49, %52
br i1 %53, label %54, label %48
54: ; preds = %51
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%56 = tail call i32 @fclose(i32* %16)
br label %99
57: ; preds = %45
%58 = load i8, i8* @EOF
%59 = icmp eq i8 %46, %58
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%62 = tail call i32 @fclose(i32* %16)
br label %99
63: ; preds = %57
%64 = tail call i32 @ungetc(i8 signext %46, i32* %16)
br label %65
65: ; preds = %48, %63
%66 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%67 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %5)
%68 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%69 = load i32, i32* %4
%70 = load i32, i32* %5
%71 = mul nsw i32 %70, %69
%72 = shl nsw i32 %71, 2
%73 = call i64 @malloc(i32 %72)
%74 = inttoptr i64 %73 to i8*
%75 = icmp sgt i32 %71, 0
br i1 %75, label %76, label %96
76: ; preds = %65, %76
%77 = phi i32 [ %93, %76 ], [ 0, %65 ]
%78 = phi i8* [ %92, %76 ], [ %74, %65 ]
%79 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %7, i32* %8, i32* %9)
%80 = load i32, i32* %9
%81 = trunc i32 %80 to i8
%82 = getelementptr inbounds i8, i8* %78, i64 1
store i8 %81, i8* %78
%83 = load i32, i32* %8
%84 = trunc i32 %83 to i8
%85 = getelementptr inbounds i8, i8* %78, i64 2
store i8 %84, i8* %82
%86 = load i32, i32* %7
%87 = trunc i32 %86 to i8
%88 = getelementptr inbounds i8, i8* %78, i64 3
store i8 %87, i8* %85
store i8 -1, i8* %88
%89 = load i8, i8* @EOF
%90 = sext i8 %89 to i32
%91 = icmp ne i32 %79, %90
%92 = getelementptr inbounds i8, i8* %78, i64 4
%93 = add nuw nsw i32 %77, 1
%94 = icmp slt i32 %93, %71
%95 = select i1 %91, i1 %94, i1 false
br i1 %95, label %76, label %96
96: ; preds = %76, %65
%97 = load i32, i32* %4
store i32 %97, i32* %1
%98 = load i32, i32* %5
store i32 %98, i32* %2
br label %99
99: ; preds = %96, %60, %54, %42, %24, %22
%100 = phi i8* [ null, %22 ], [ null, %24 ], [ null, %42 ], [ null, %54 ], [ %74, %96 ], [ null, %60 ]
ret i8* %100
}