#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(unsigned char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
void ipr_load_ppm(unsigned char image[][256], const char path[]) {
  char magic_number[2];
  int width, height;
  int max_intensity;
  FILE *fp;
  fp = fopen(path, "rb");
  if (fp == NULL) {
    fprintf(stderr, "%s が開けませんでした．\n", path);
    exit(1);
  }
  fscanf(fp, "%c%c", &magic_number[0], &magic_number[1]);
  if (magic_number[0] != 'P' || magic_number[1] != '5') {
    fprintf(stderr, "%s はバイナリ型 PGM ではありません．\n", path);
    fclose(fp);
    exit(1);
  }
  fscanf(fp, "%d %d", &width, &height);
  if (width != 256 || height != 256) {
    fprintf(stderr, "画像のサイズが異なります．\n");
    fprintf(stderr, "  想定サイズ：WIDTH = %d, HEIGHT = %d\n", 256, 256);
    fprintf(stderr, "  実サイズ：  width = %d, height = %d\n", width, height);
    fclose(fp);
    exit(1);
  }
  fscanf(fp, "%d", &max_intensity);
  if (max_intensity != 255) {
    fprintf(stderr, "最大階調値が不正な値です（%d）．\n", max_intensity);
    fclose(fp);
    exit(1);
  }
  fgetc(fp);
  fread(image, sizeof(unsigned char), 256 * 256, fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<ipr_load_ppm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c4 <ipr_load_ppm+0x54>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    -0x12(%rbp),%rdx
lea    -0x12(%rbp),%rcx
add    $0x1,%rcx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
movsbl -0x12(%rbp),%eax
cmp    $0x50,%eax
jne    11fc <ipr_load_ppm+0x8c>
movsbl -0x11(%rbp),%eax
cmp    $0x35,%eax
je     122a <ipr_load_ppm+0xba>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xe2a(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
mov    $0x0,%al
call   1050 <fscanf@plt>
cmpl   $0x100,-0x18(%rbp)
jne    125e <ipr_load_ppm+0xee>
cmpl   $0x100,-0x1c(%rbp)
je     12c3 <ipr_load_ppm+0x153>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
mov    $0x100,%ecx
mov    %ecx,%edx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xd94(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
cmpl   $0xff,-0x20(%rbp)
je     1313 <ipr_load_ppm+0x1a3>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1030 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipr_load_ppm>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe7a(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1257 <ipr_load_ppm+0xe7>
mov    %rax,%rbx
lea    0x3(%rsp),%rcx
lea    0xe80(%rip),%rsi
lea    0x2(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
cmpb   $0x50,0x2(%rsp)
jne    127b <ipr_load_ppm+0x10b>
cmpb   $0x35,0x3(%rsp)
jne    127b <ipr_load_ppm+0x10b>
lea    0xe8d(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
cmpl   $0x100,0x8(%rsp)
jne    1297 <ipr_load_ppm+0x127>
cmpl   $0x100,0x4(%rsp)
jne    1297 <ipr_load_ppm+0x127>
lea    0xe59(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    0xc(%rsp),%edx
cmp    $0xff,%edx
jne    12e5 <ipr_load_ppm+0x175>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xd9c(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12fc <ipr_load_ppm+0x18c>
mov    0x2d42(%rip),%r14
mov    (%r14),%edi
lea    0xdbd(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r14),%edi
lea    0xdd5(%rip),%rsi
mov    $0x100,%edx
mov    $0x100,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r14),%edi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
lea    0xddf(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12fc <ipr_load_ppm+0x18c>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"%s \E3\81\8C\E9\96\8B\E3\81\91\E3\81\BE\E3\81\9B\E3\82\93\E3\81\A7\E3\81\97\E3\81\9F\EF\BC\8E\0A\00"
@.str.2 = [5 x i8] c"%c%c\00"
@.str.3 = [52 x i8] c"%s \E3\81\AF\E3\83\90\E3\82\A4\E3\83\8A\E3\83\AA\E5\9E\8B PGM \E3\81\A7\E3\81\AF\E3\81\82\E3\82\8A\E3\81\BE\E3\81\9B\E3\82\93\EF\BC\8E\0A\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [41 x i8] c"\E7\94\BB\E5\83\8F\E3\81\AE\E3\82\B5\E3\82\A4\E3\82\BA\E3\81\8C\E7\95\B0\E3\81\AA\E3\82\8A\E3\81\BE\E3\81\99\EF\BC\8E\0A\00"
@.str.6 = [45 x i8] c" \E6\83\B3\E5\AE\9A\E3\82\B5\E3\82\A4\E3\82\BA\EF\BC\9AWIDTH = %d, HEIGHT = %d\0A\00"
@.str.7 = [44 x i8] c" \E5\AE\9F\E3\82\B5\E3\82\A4\E3\82\BA\EF\BC\9A width = %d, height = %d\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [49 x i8] c"\E6\9C\80\E5\A4\A7\E9\9A\8E\E8\AA\BF\E5\80\A4\E3\81\8C\E4\B8\8D\E6\AD\A3\E3\81\AA\E5\80\A4\E3\81\A7\E3\81\99\EF\BC\88%d\EF\BC\89\EF\BC\8E\0A\00"
define void @ipr_load_ppm([256 x i8]* %0, i8* %1) {
%3 = alloca [256 x i8]*
%4 = alloca i8*
%5 = alloca [2 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store [256 x i8]* %0, [256 x i8]** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32*, i32** %9
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
%23 = call i32 (i32*, i8*, ...) @fscanf(i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %22)
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 80
br i1 %27, label %33, label %28
28: ; preds = %19
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 53
br i1 %32, label %33, label %40
33: ; preds = %28, %19
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %4
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = load i32*, i32** %9
%38 = call i32 @fclose(i32* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %28
%41 = load i32*, i32** %9
%42 = call i32 (i32*, i8*, ...) @fscanf(i32* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %6, i32* %7)
%43 = load i32, i32* %6
%44 = icmp ne i32 %43, 256
br i1 %44, label %48, label %45
45: ; preds = %40
%46 = load i32, i32* %7
%47 = icmp ne i32 %46, 256
br i1 %47, label %48, label %60
48: ; preds = %45, %40
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i32 256, i32 256)
%53 = load i32, i32* @stderr
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i32 %54, i32 %55)
%57 = load i32*, i32** %9
%58 = call i32 @fclose(i32* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %45
%61 = load i32*, i32** %9
%62 = call i32 (i32*, i8*, ...) @fscanf(i32* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %8)
%63 = load i32, i32* %8
%64 = icmp ne i32 %63, 255
br i1 %64, label %65, label %72
65: ; preds = %60
%66 = load i32, i32* @stderr
%67 = load i32, i32* %8
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0), i32 %67)
%69 = load i32*, i32** %9
%70 = call i32 @fclose(i32* %69)
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %60
%73 = load i32*, i32** %9
%74 = call i32 @fgetc(i32* %73)
%75 = load [256 x i8]*, [256 x i8]** %3
%76 = bitcast [256 x i8]* %75 to i8**
%77 = load i32*, i32** %9
%78 = call i32 @fread(i8** %76, i32 1, i32 65536, i32* %77)
%79 = load i32*, i32** %9
%80 = call i32 @fclose(i32* %79)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"%s \E3\81\8C\E9\96\8B\E3\81\91\E3\81\BE\E3\81\9B\E3\82\93\E3\81\A7\E3\81\97\E3\81\9F\EF\BC\8E\0A\00"
@.str.2 = [5 x i8] c"%c%c\00"
@.str.3 = [52 x i8] c"%s \E3\81\AF\E3\83\90\E3\82\A4\E3\83\8A\E3\83\AA\E5\9E\8B PGM \E3\81\A7\E3\81\AF\E3\81\82\E3\82\8A\E3\81\BE\E3\81\9B\E3\82\93\EF\BC\8E\0A\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [41 x i8] c"\E7\94\BB\E5\83\8F\E3\81\AE\E3\82\B5\E3\82\A4\E3\82\BA\E3\81\8C\E7\95\B0\E3\81\AA\E3\82\8A\E3\81\BE\E3\81\99\EF\BC\8E\0A\00"
@.str.6 = [45 x i8] c" \E6\83\B3\E5\AE\9A\E3\82\B5\E3\82\A4\E3\82\BA\EF\BC\9AWIDTH = %d, HEIGHT = %d\0A\00"
@.str.7 = [44 x i8] c" \E5\AE\9F\E3\82\B5\E3\82\A4\E3\82\BA\EF\BC\9A width = %d, height = %d\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [49 x i8] c"\E6\9C\80\E5\A4\A7\E9\9A\8E\E8\AA\BF\E5\80\A4\E3\81\8C\E4\B8\8D\E6\AD\A3\E3\81\AA\E5\80\A4\E3\81\A7\E3\81\99\EF\BC\88%d\EF\BC\89\EF\BC\8E\0A\00"
define void @ipr_load_ppm([256 x i8]* nocapture %0, i8* %1) {
%3 = alloca [2 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
%19 = call i32 (i32*, i8*, ...) @fscanf(i32* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %18)
%20 = load i8, i8* %7
%21 = icmp ne i8 %20, 80
%22 = load i8, i8* %18
%23 = icmp ne i8 %22, 53
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %25, label %30
25: ; preds = %17
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%28 = call i32 @fclose(i32* %11)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = call i32 (i32*, i8*, ...) @fscanf(i32* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %4, i32* %5)
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 256
%34 = load i32, i32* %5
%35 = icmp ne i32 %34, 256
%36 = select i1 %33, i1 true, i1 %35
br i1 %36, label %37, label %48
37: ; preds = %30
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i32 256, i32 256)
%42 = load i32, i32* @stderr
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i32 %43, i32 %44)
%46 = call i32 @fclose(i32* %11)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %30
%49 = call i32 (i32*, i8*, ...) @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %6)
%50 = load i32, i32* %6
%51 = icmp eq i32 %50, 255
br i1 %51, label %57, label %52
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0), i32 %50)
%55 = call i32 @fclose(i32* %11)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
%58 = call i32 @fgetc(i32* %11)
%59 = bitcast [256 x i8]* %0 to i8**
%60 = call i32 @fread(i8** %59, i32 1, i32 65536, i32* %11)
%61 = call i32 @fclose(i32* %11)
ret void
}