#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*/ check_input(int, char **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ print_file_type_error();
int /*<<< orphan*/ print_matrix_in_file(char *, int ***, int, int);
int /*<<< orphan*/ remove_comment_from_file(int /*<<< orphan*/ *);
int ***set_image(int /*<<< orphan*/ *, int, int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (!check_input(argc, argv))
    return 1;
  char file_type[2];
  int width;
  int height;
  FILE *input;
  input = fopen(argv[1], "r");
  fscanf(input, "%s", file_type);
  if (strcmp(file_type, "P3")) {
    print_file_type_error();
    return 0;
  }
  remove_comment_from_file(input);
  fscanf(input, "%d", &width);
  fscanf(input, "%d", &height);
  int ***image = set_image(input, width, height);
  print_matrix_in_file(argv[2], image, width, height);
  fclose(input);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <check_input@plt>
cmp    $0x0,%eax
jne    11c7 <main+0x37>
movl   $0x1,-0x4(%rbp)
jmp    1291 <main+0x101>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x12(%rbp),%rdx
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1070 <fscanf@plt>
lea    -0x12(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1222 <main+0x92>
mov    $0x0,%al
call   1080 <print_file_type_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1291 <main+0x101>
mov    -0x28(%rbp),%rdi
call   10a0 <remove_comment_from_file@plt>
mov    -0x28(%rbp),%rdi
lea    0xdd2(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    -0x28(%rbp),%rdi
lea    0xdbc(%rip),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <set_image@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1060 <print_matrix_in_file@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
call   1050 <check_input@plt>
test   %eax,%eax
je     11ee <main+0x5e>
mov    0x8(%rbx),%rdi
lea    0xe50(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
lea    0xe43(%rip),%rsi
lea    0xe(%rsp),%r15
mov    %rax,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
lea    0xe2d(%rip),%rsi
mov    %r15,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     11f5 <main+0x65>
xor    %eax,%eax
call   1080 <print_file_type_error@plt>
jmp    1254 <main+0xc4>
mov    $0x1,%eax
jmp    1256 <main+0xc6>
mov    %r14,%rdi
call   10a0 <remove_comment_from_file@plt>
lea    0xe04(%rip),%r15
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <fscanf@plt>
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    %r14,%rdi
call   1030 <set_image@plt>
mov    0x10(%rbx),%rdi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %rax,%rsi
call   1060 <print_matrix_in_file@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"P3\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32***
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @check_input(i32 %11, i8** %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 1, i32* %3
br label %49
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %9
%21 = load i32*, i32** %9
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%23 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %16
%28 = call i32 (...) @print_file_type_error()
store i32 0, i32* %3
br label %49
29: ; preds = %16
%30 = load i32*, i32** %9
%31 = call i32 @remove_comment_from_file(i32* %30)
%32 = load i32*, i32** %9
%33 = call i32 (i32*, i8*, ...) @fscanf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%34 = load i32*, i32** %9
%35 = call i32 (i32*, i8*, ...) @fscanf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%36 = load i32*, i32** %9
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = call i32*** @set_image(i32* %36, i32 %37, i32 %38)
store i32*** %39, i32**** %10
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = load i32***, i32**** %10
%44 = load i32, i32* %7
%45 = load i32, i32* %8
%46 = call i32 @print_matrix_in_file(i8* %42, i32*** %43, i32 %44, i32 %45)
%47 = load i32*, i32** %9
%48 = call i32 @fclose(i32* %47)
store i32 0, i32* %3
br label %49
49: ; preds = %29, %27, %15
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"P3\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = tail call i32 @check_input(i32 %0, i8** %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %34, label %8
8: ; preds = %2
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (i32*, i8*, ...) @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%16 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %8
%19 = call i32 (...) @print_file_type_error()
br label %33
20: ; preds = %8
%21 = call i32 @remove_comment_from_file(i32* %14)
%22 = call i32 (i32*, i8*, ...) @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%23 = call i32 (i32*, i8*, ...) @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = call i32*** @set_image(i32* %14, i32 %24, i32 %25)
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = call i32 @print_matrix_in_file(i8* %28, i32*** %26, i32 %29, i32 %30)
%32 = call i32 @fclose(i32* %14)
br label %33
33: ; preds = %20, %18
br label %34
34: ; preds = %2, %33
%35 = phi i32 [ 0, %33 ], [ 1, %2 ]
ret i32 %35
}