#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
void readPictureP5(char *fileName, char *mode, int **imageMatrix,
                   char *magicNumber, int idim, int jdim, int headerSize) {
  char fileLine[2048];
  int row = 0;
  int column = 0;
  unsigned char buffer[jdim];
  FILE *file;
  file = fopen(fileName, mode);
  if (file != NULL) {
    if (strcmp(magicNumber, "P5")) {
      for (row = 0; row < headerSize; row++) {
        fgets(fileLine, 2048, file);
      }
      for (row = 0; row < idim; row++) {
        fread(buffer, sizeof(unsigned char), jdim, file);
        for (column = 0; column < jdim; column++) {
          imageMatrix[row][column] = (int)buffer[column];
        }
      }
    } else {
      printf("Your file is not a P5 pgm file");
    }
    fclose(file);
  } else {
    printf("Error opening file readPicture");
  }
}


x86 assembly (clang, -O0):
<readPictureP5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movl   $0x0,-0x834(%rbp)
movl   $0x0,-0x838(%rbp)
mov    -0x28(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x840(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x858(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x848(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x850(%rbp)
cmpq   $0x0,-0x850(%rbp)
je     1311 <readPictureP5+0x1b1>
mov    -0x20(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12f4 <readPictureP5+0x194>
movl   $0x0,-0x834(%rbp)
mov    -0x834(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    124a <readPictureP5+0xea>
lea    -0x830(%rbp),%rdi
mov    -0x850(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
mov    -0x834(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x834(%rbp)
jmp    120f <readPictureP5+0xaf>
movl   $0x0,-0x834(%rbp)
mov    -0x834(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12ef <readPictureP5+0x18f>
mov    -0x858(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x850(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
movl   $0x0,-0x838(%rbp)
mov    -0x838(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12d6 <readPictureP5+0x176>
mov    -0x858(%rbp),%rax
movslq -0x838(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    -0x18(%rbp),%rax
movslq -0x834(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x838(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x838(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x838(%rbp)
jmp    1288 <readPictureP5+0x128>
jmp    12db <readPictureP5+0x17b>
mov    -0x834(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x834(%rbp)
jmp    1254 <readPictureP5+0xf4>
jmp    1300 <readPictureP5+0x1a0>
lea    0xd08(%rip),%rdi
call   1050 <printf@plt>
mov    -0x850(%rbp),%rdi
call   1040 <fclose@plt>
jmp    131d <readPictureP5+0x1bd>
lea    0xd0a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x840(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readPictureP5>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    %r9d,%r15d
mov    %r8d,-0x30(%rbp)
mov    %rcx,%r13
mov    %rdx,-0x60(%rbp)
mov    %rsp,%r12
mov    %r9d,%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1080 <fopen@plt>
test   %rax,%rax
je     136f <readPictureP5+0x20f>
mov    %rax,-0x38(%rbp)
lea    0xe4e(%rip),%rsi
mov    %r13,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
mov    %r12,-0x40(%rbp)
je     137d <readPictureP5+0x21d>
mov    0x10(%rbp),%r12d
test   %r12d,%r12d
mov    -0x38(%rbp),%r13
jle    11fa <readPictureP5+0x9a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    -0x860(%rbp),%rdi
mov    $0x800,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
add    $0xffffffff,%r12d
jne    11e0 <readPictureP5+0x80>
mov    -0x30(%rbp),%ecx
test   %ecx,%ecx
mov    %r13,%rax
jle    138d <readPictureP5+0x22d>
mov    %ecx,%ecx
mov    %rcx,-0x30(%rbp)
mov    %r14d,%ecx
and    $0xfffffff8,%ecx
mov    %rcx,-0x58(%rbp)
add    $0xfffffffffffffff8,%rcx
mov    %rcx,-0x50(%rbp)
shr    $0x3,%rcx
add    $0x1,%rcx
mov    %rcx,%r12
and    $0xfffffffffffffffe,%rcx
mov    %rcx,-0x48(%rbp)
xor    %r13d,%r13d
jmp    1252 <readPictureP5+0xf2>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    -0x30(%rbp),%r13
mov    -0x38(%rbp),%rax
je     138d <readPictureP5+0x22d>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
pxor   %xmm2,%xmm2
test   %r15d,%r15d
jle    1240 <readPictureP5+0xe0>
mov    -0x60(%rbp),%rax
mov    (%rax,%r13,8),%rax
cmp    $0x8,%r15d
jae    1290 <readPictureP5+0x130>
xor    %ecx,%ecx
jmp    1350 <readPictureP5+0x1f0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpq   $0x0,-0x50(%rbp)
je     1365 <readPictureP5+0x205>
mov    -0x48(%rbp),%rdx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movdqa (%rbx,%rcx,1),%xmm0
movd   0x4(%rbx,%rcx,1),%xmm1
punpcklbw %xmm2,%xmm0
punpcklwd %xmm2,%xmm0
punpcklbw %xmm2,%xmm1
punpcklwd %xmm2,%xmm1
movdqu %xmm0,(%rax,%rcx,4)
movdqu %xmm1,0x10(%rax,%rcx,4)
movq   0x8(%rbx,%rcx,1),%xmm0
movd   0xc(%rbx,%rcx,1),%xmm1
punpcklbw %xmm2,%xmm0
punpcklwd %xmm2,%xmm0
punpcklbw %xmm2,%xmm1
punpcklwd %xmm2,%xmm1
movdqu %xmm0,0x20(%rax,%rcx,4)
movdqu %xmm1,0x30(%rax,%rcx,4)
add    $0x10,%rcx
add    $0xfffffffffffffffe,%rdx
jne    12b0 <readPictureP5+0x150>
test   $0x1,%r12b
je     1334 <readPictureP5+0x1d4>
movq   (%rbx,%rcx,1),%xmm0
movd   0x4(%rbx,%rcx,1),%xmm1
punpcklbw %xmm2,%xmm0
punpcklwd %xmm2,%xmm0
punpcklbw %xmm2,%xmm1
punpcklwd %xmm2,%xmm1
movdqu %xmm0,(%rax,%rcx,4)
movdqu %xmm1,0x10(%rax,%rcx,4)
mov    -0x58(%rbp),%rdx
mov    %rdx,%rcx
cmp    %r14,%rdx
je     1240 <readPictureP5+0xe0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx,%rcx,1),%edx
mov    %edx,(%rax,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%r14
jne    1350 <readPictureP5+0x1f0>
jmp    1240 <readPictureP5+0xe0>
xor    %ecx,%ecx
test   $0x1,%r12b
jne    130e <readPictureP5+0x1ae>
jmp    1334 <readPictureP5+0x1d4>
lea    0xcac(%rip),%rdi
call   1050 <printf@plt>
jmp    1399 <readPictureP5+0x239>
lea    0xc7f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%r12
mov    %r12,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"P5\00"
@.str.1 = [31 x i8] c"Your file is not a P5 pgm file\00"
@.str.2 = [31 x i8] c"Error opening file readPicture\00"
define void @readPictureP5(i8* %0, i8* %1, i32** %2, i8* %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32**
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [2048 x i8]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i32*
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32** %2, i32*** %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
store i32 0, i32* %16
store i32 0, i32* %17
%21 = load i32, i32* %13
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %18
%24 = alloca i8, i64 %22
store i64 %22, i64* %19
%25 = load i8*, i8** %8
%26 = load i8*, i8** %9
%27 = call i32* @fopen(i8* %25, i8* %26)
store i32* %27, i32** %20
%28 = load i32*, i32** %20
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %86
30: ; preds = %7
%31 = load i8*, i8** %11
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %81
34: ; preds = %30
store i32 0, i32* %16
br label %35
35: ; preds = %43, %34
%36 = load i32, i32* %16
%37 = load i32, i32* %14
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %15, i64 0, i64 0
%41 = load i32*, i32** %20
%42 = call i32 @fgets(i8* %40, i32 2048, i32* %41)
br label %43
43: ; preds = %39
%44 = load i32, i32* %16
%45 = add nsw i32 %44, 1
store i32 %45, i32* %16
br label %35
46: ; preds = %35
store i32 0, i32* %16
br label %47
47: ; preds = %77, %46
%48 = load i32, i32* %16
%49 = load i32, i32* %12
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %80
51: ; preds = %47
%52 = load i32, i32* %13
%53 = load i32*, i32** %20
%54 = call i32 @fread(i8* %24, i32 1, i32 %52, i32* %53)
store i32 0, i32* %17
br label %55
55: ; preds = %73, %51
%56 = load i32, i32* %17
%57 = load i32, i32* %13
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %76
59: ; preds = %55
%60 = load i32, i32* %17
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %24, i64 %61
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = load i32**, i32*** %10
%66 = load i32, i32* %16
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32*, i32** %65, i64 %67
%69 = load i32*, i32** %68
%70 = load i32, i32* %17
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %69, i64 %71
store i32 %64, i32* %72
br label %73
73: ; preds = %59
%74 = load i32, i32* %17
%75 = add nsw i32 %74, 1
store i32 %75, i32* %17
br label %55
76: ; preds = %55
br label %77
77: ; preds = %76
%78 = load i32, i32* %16
%79 = add nsw i32 %78, 1
store i32 %79, i32* %16
br label %47
80: ; preds = %47
br label %83
81: ; preds = %30
%82 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %83
83: ; preds = %81, %80
%84 = load i32*, i32** %20
%85 = call i32 @fclose(i32* %84)
br label %88
86: ; preds = %7
%87 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %88
88: ; preds = %86, %83
%89 = load i8*, i8** %18
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"P5\00"
@.str.1 = [31 x i8] c"Your file is not a P5 pgm file\00"
@.str.2 = [31 x i8] c"Error opening file readPicture\00"
define void @readPictureP5(i8* nocapture %0, i8* nocapture %1, i32** nocapture %2, i8* %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca [2048 x i8]
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%10 = zext i32 %5 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = tail call i32* @fopen(i8* %0, i8* %1)
%14 = icmp eq i32* %13, null
br i1 %14, label %112, label %15
15: ; preds = %7
%16 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %108, label %18
18: ; preds = %15
%19 = icmp sgt i32 %6, 0
br i1 %19, label %36, label %20
20: ; preds = %36, %18
%21 = icmp sgt i32 %4, 0
br i1 %21, label %22, label %110
22: ; preds = %20
%23 = icmp sgt i32 %5, 0
%24 = zext i32 %4 to i64
%25 = and i64 %10, 4294967288
%26 = add nsw i64 %25, -8
%27 = lshr exact i64 %26, 3
%28 = add nuw nsw i64 %27, 1
%29 = icmp ult i32 %5, 8
%30 = and i64 %10, 4294967288
%31 = and i64 %28, 1
%32 = icmp eq i64 %26, 0
%33 = and i64 %28, 4611686018427387902
%34 = icmp eq i64 %31, 0
%35 = icmp eq i64 %30, %10
br label %41
36: ; preds = %18, %36
%37 = phi i32 [ %39, %36 ], [ 0, %18 ]
%38 = call i32 @fgets(i8* %9, i32 2048, i32* %13)
%39 = add nuw nsw i32 %37, 1
%40 = icmp eq i32 %39, %6
br i1 %40, label %20, label %36
41: ; preds = %22, %105
%42 = phi i64 [ 0, %22 ], [ %106, %105 ]
%43 = call i32 @fread(i8* %12, i32 1, i32 %5, i32* %13)
br i1 %23, label %44, label %105
44: ; preds = %41
%45 = getelementptr inbounds i32*, i32** %2, i64 %42
%46 = load i32*, i32** %45
br i1 %29, label %95, label %47
47: ; preds = %44
br i1 %32, label %79, label %48
48: ; preds = %47, %48
%49 = phi i64 [ %76, %48 ], [ 0, %47 ]
%50 = phi i64 [ %77, %48 ], [ 0, %47 ]
%51 = getelementptr inbounds i8, i8* %12, i64 %49
%52 = bitcast i8* %51 to <4 x i8>*
%53 = load <4 x i8>, <4 x i8>* %52
%54 = getelementptr inbounds i8, i8* %51, i64 4
%55 = bitcast i8* %54 to <4 x i8>*
%56 = load <4 x i8>, <4 x i8>* %55
%57 = zext <4 x i8> %53 to <4 x i32>
%58 = zext <4 x i8> %56 to <4 x i32>
%59 = getelementptr inbounds i32, i32* %46, i64 %49
%60 = bitcast i32* %59 to <4 x i32>*
store <4 x i32> %57, <4 x i32>* %60
%61 = getelementptr inbounds i32, i32* %59, i64 4
%62 = bitcast i32* %61 to <4 x i32>*
store <4 x i32> %58, <4 x i32>* %62
%63 = or i64 %49, 8
%64 = getelementptr inbounds i8, i8* %12, i64 %63
%65 = bitcast i8* %64 to <4 x i8>*
%66 = load <4 x i8>, <4 x i8>* %65
%67 = getelementptr inbounds i8, i8* %64, i64 4
%68 = bitcast i8* %67 to <4 x i8>*
%69 = load <4 x i8>, <4 x i8>* %68
%70 = zext <4 x i8> %66 to <4 x i32>
%71 = zext <4 x i8> %69 to <4 x i32>
%72 = getelementptr inbounds i32, i32* %46, i64 %63
%73 = bitcast i32* %72 to <4 x i32>*
store <4 x i32> %70, <4 x i32>* %73
%74 = getelementptr inbounds i32, i32* %72, i64 4
%75 = bitcast i32* %74 to <4 x i32>*
store <4 x i32> %71, <4 x i32>* %75
%76 = add nuw i64 %49, 16
%77 = add i64 %50, 2
%78 = icmp eq i64 %77, %33
br i1 %78, label %79, label %48
79: ; preds = %48, %47
%80 = phi i64 [ 0, %47 ], [ %76, %48 ]
br i1 %34, label %94, label %81
81: ; preds = %79
%82 = getelementptr inbounds i8, i8* %12, i64 %80
%83 = bitcast i8* %82 to <4 x i8>*
%84 = load <4 x i8>, <4 x i8>* %83
%85 = getelementptr inbounds i8, i8* %82, i64 4
%86 = bitcast i8* %85 to <4 x i8>*
%87 = load <4 x i8>, <4 x i8>* %86
%88 = zext <4 x i8> %84 to <4 x i32>
%89 = zext <4 x i8> %87 to <4 x i32>
%90 = getelementptr inbounds i32, i32* %46, i64 %80
%91 = bitcast i32* %90 to <4 x i32>*
store <4 x i32> %88, <4 x i32>* %91
%92 = getelementptr inbounds i32, i32* %90, i64 4
%93 = bitcast i32* %92 to <4 x i32>*
store <4 x i32> %89, <4 x i32>* %93
br label %94
94: ; preds = %79, %81
br i1 %35, label %105, label %95
95: ; preds = %44, %94
%96 = phi i64 [ 0, %44 ], [ %30, %94 ]
br label %97
97: ; preds = %95, %97
%98 = phi i64 [ %103, %97 ], [ %96, %95 ]
%99 = getelementptr inbounds i8, i8* %12, i64 %98
%100 = load i8, i8* %99
%101 = zext i8 %100 to i32
%102 = getelementptr inbounds i32, i32* %46, i64 %98
store i32 %101, i32* %102
%103 = add nuw nsw i64 %98, 1
%104 = icmp eq i64 %103, %10
br i1 %104, label %105, label %97
105: ; preds = %97, %94, %41
%106 = add nuw nsw i64 %42, 1
%107 = icmp eq i64 %106, %24
br i1 %107, label %110, label %41
108: ; preds = %15
%109 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %110
110: ; preds = %105, %20, %108
%111 = call i32 @fclose(i32* %13)
br label %114
112: ; preds = %7
%113 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %114
114: ; preds = %112, %110
ret void
}