#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*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ stderr;
void read_graphics(char *filename, float *input, int data_rows, int data_cols,
                   int major) {
  FILE *fid;
  int i, j;
  char c;
  int temp;
  fid = fopen(filename, "r");
  if (fid == NULL) {
    fprintf(stderr, "The file was not opened for reading\n");
    return;
  }
  i = 0;
  while (i < 3) {
    c = fgetc(fid);
    if (c == '\n') {
      i = i + 1;
    }
  };
  if (major == 0) {
    for (i = 0; i < data_rows; i++) {
      for (j = 0; j < data_cols; j++) {
        fscanf(fid, "%d", &temp);
        input[i * data_cols + j] = (float)temp;
      }
    }
  } else {
    for (i = 0; i < data_rows; i++) {
      for (j = 0; j < data_cols; j++) {
        fscanf(fid, "%d", &temp);
        input[j * data_rows + i] = (float)temp;
      }
    }
  }
  fclose(fid);
}


x86 assembly (clang, -O0):
<read_graphics>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a3 <read_graphics+0x53>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12e4 <read_graphics+0x194>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jge    11db <read_graphics+0x8b>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
cmp    $0xa,%eax
jne    11d6 <read_graphics+0x86>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11aa <read_graphics+0x5a>
cmpl   $0x0,-0x1c(%rbp)
jne    1260 <read_graphics+0x110>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125b <read_graphics+0x10b>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1248 <read_graphics+0xf8>
mov    -0x28(%rbp),%rdi
lea    0xe11(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <fscanf@plt>
cvtsi2ssl -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11ff <read_graphics+0xaf>
jmp    124d <read_graphics+0xfd>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ec <read_graphics+0x9c>
jmp    12db <read_graphics+0x18b>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12d6 <read_graphics+0x186>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12c3 <read_graphics+0x173>
mov    -0x28(%rbp),%rdi
lea    0xd96(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <fscanf@plt>
cvtsi2ssl -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    127a <read_graphics+0x12a>
jmp    12c8 <read_graphics+0x178>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1267 <read_graphics+0x117>
jmp    12db <read_graphics+0x18b>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_graphics>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r14d
mov    %ecx,(%rsp)
mov    %edx,%r15d
mov    %rsi,%r12
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1248 <read_graphics+0xf8>
mov    %rax,%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
call   1050 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebx
cmp    $0x3,%ebx
jb     1190 <read_graphics+0x40>
test   %r14d,%r14d
je     126b <read_graphics+0x11b>
test   %r15d,%r15d
jle    1309 <read_graphics+0x1b9>
mov    %r15d,%eax
mov    (%rsp),%ecx
mov    %rcx,0x20(%rsp)
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,4),%r14
xor    %eax,%eax
lea    0xe4e(%rip),%r15
lea    0x4(%rsp),%rbx
jmp    11fd <read_graphics+0xad>
mov    0x18(%rsp),%rax
add    $0x1,%rax
mov    0x8(%rsp),%r12
add    $0x4,%r12
cmp    0x10(%rsp),%rax
je     1309 <read_graphics+0x1b9>
mov    %rax,0x18(%rsp)
mov    %r12,0x8(%rsp)
cmpl   $0x0,(%rsp)
jle    11e0 <read_graphics+0x90>
mov    0x20(%rsp),%r13
mov    0x8(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
xorps  %xmm0,%xmm0
cvtsi2ssl 0x4(%rsp),%xmm0
movss  %xmm0,(%r12)
add    %r14,%r12
add    $0xffffffffffffffff,%r13
jne    1220 <read_graphics+0xd0>
jmp    11e0 <read_graphics+0x90>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>
test   %r15d,%r15d
jle    1309 <read_graphics+0x1b9>
mov    %r12,%r13
mov    (%rsp),%eax
movslq %eax,%rdx
mov    %r15d,%esi
mov    %rsi,0x10(%rsp)
mov    %eax,%r12d
shl    $0x2,%rdx
mov    %rdx,0x18(%rsp)
xor    %eax,%eax
lea    0xd8d(%rip),%r15
lea    0x4(%rsp),%r14
jmp    12c5 <read_graphics+0x175>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
add    $0x1,%rax
add    0x18(%rsp),%r13
cmp    0x10(%rsp),%rax
je     1309 <read_graphics+0x1b9>
mov    %rax,0x8(%rsp)
cmpl   $0x0,(%rsp)
jle    12b0 <read_graphics+0x160>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
xorps  %xmm0,%xmm0
cvtsi2ssl 0x4(%rsp),%xmm0
movss  %xmm0,0x0(%r13,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    12e0 <read_graphics+0x190>
jmp    12b0 <read_graphics+0x160>
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"The file was not opened for reading\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define void @read_graphics(i8* %0, float* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca float*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca i32
store i8* %0, i8** %6
store float* %1, float** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%16 = load i8*, i8** %6
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %11
%18 = load i32*, i32** %11
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %5
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %105
23: ; preds = %5
store i32 0, i32* %12
br label %24
24: ; preds = %36, %23
%25 = load i32, i32* %12
%26 = icmp slt i32 %25, 3
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i32*, i32** %11
%29 = call signext i8 @fgetc(i32* %28)
store i8 %29, i8* %14
%30 = load i8, i8* %14
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 10
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = load i32, i32* %12
%35 = add nsw i32 %34, 1
store i32 %35, i32* %12
br label %36
36: ; preds = %33, %27
br label %24
37: ; preds = %24
%38 = load i32, i32* %10
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %71
40: ; preds = %37
store i32 0, i32* %12
br label %41
41: ; preds = %67, %40
%42 = load i32, i32* %12
%43 = load i32, i32* %8
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %70
45: ; preds = %41
store i32 0, i32* %13
br label %46
46: ; preds = %63, %45
%47 = load i32, i32* %13
%48 = load i32, i32* %9
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %66
50: ; preds = %46
%51 = load i32*, i32** %11
%52 = call i32 @fscanf(i32* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%53 = load i32, i32* %15
%54 = sitofp i32 %53 to float
%55 = load float*, float** %7
%56 = load i32, i32* %12
%57 = load i32, i32* %9
%58 = mul nsw i32 %56, %57
%59 = load i32, i32* %13
%60 = add nsw i32 %58, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds float, float* %55, i64 %61
store float %54, float* %62
br label %63
63: ; preds = %50
%64 = load i32, i32* %13
%65 = add nsw i32 %64, 1
store i32 %65, i32* %13
br label %46
66: ; preds = %46
br label %67
67: ; preds = %66
%68 = load i32, i32* %12
%69 = add nsw i32 %68, 1
store i32 %69, i32* %12
br label %41
70: ; preds = %41
br label %102
71: ; preds = %37
store i32 0, i32* %12
br label %72
72: ; preds = %98, %71
%73 = load i32, i32* %12
%74 = load i32, i32* %8
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %101
76: ; preds = %72
store i32 0, i32* %13
br label %77
77: ; preds = %94, %76
%78 = load i32, i32* %13
%79 = load i32, i32* %9
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %97
81: ; preds = %77
%82 = load i32*, i32** %11
%83 = call i32 @fscanf(i32* %82, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%84 = load i32, i32* %15
%85 = sitofp i32 %84 to float
%86 = load float*, float** %7
%87 = load i32, i32* %13
%88 = load i32, i32* %8
%89 = mul nsw i32 %87, %88
%90 = load i32, i32* %12
%91 = add nsw i32 %89, %90
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds float, float* %86, i64 %92
store float %85, float* %93
br label %94
94: ; preds = %81
%95 = load i32, i32* %13
%96 = add nsw i32 %95, 1
store i32 %96, i32* %13
br label %77
97: ; preds = %77
br label %98
98: ; preds = %97
%99 = load i32, i32* %12
%100 = add nsw i32 %99, 1
store i32 %100, i32* %12
br label %72
101: ; preds = %72
br label %102
102: ; preds = %101, %70
%103 = load i32*, i32** %11
%104 = call i32 @fclose(i32* %103)
br label %105
105: ; preds = %102, %20
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"The file was not opened for reading\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define void @read_graphics(i8* nocapture %0, float* nocapture writeonly %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %68
13: ; preds = %5, %13
%14 = phi i32 [ %18, %13 ], [ 0, %5 ]
%15 = tail call signext i8 @fgetc(i32* %8)
%16 = icmp eq i8 %15, 10
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %14, %17
%19 = icmp ult i32 %18, 3
br i1 %19, label %13, label %20
20: ; preds = %13
%21 = icmp eq i32 %4, 0
%22 = icmp sgt i32 %2, 0
br i1 %21, label %29, label %23
23: ; preds = %20
br i1 %22, label %24, label %66
24: ; preds = %23
%25 = icmp sgt i32 %3, 0
%26 = zext i32 %2 to i64
%27 = zext i32 %2 to i64
%28 = zext i32 %3 to i64
br label %51
29: ; preds = %20
br i1 %22, label %30, label %66
30: ; preds = %29
%31 = icmp sgt i32 %3, 0
%32 = sext i32 %3 to i64
%33 = zext i32 %2 to i64
%34 = zext i32 %3 to i64
br label %35
35: ; preds = %30, %48
%36 = phi i64 [ 0, %30 ], [ %49, %48 ]
br i1 %31, label %37, label %48
37: ; preds = %35
%38 = mul nsw i64 %36, %32
br label %39
39: ; preds = %37, %39
%40 = phi i64 [ 0, %37 ], [ %46, %39 ]
%41 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%42 = load i32, i32* %6
%43 = sitofp i32 %42 to float
%44 = add nsw i64 %40, %38
%45 = getelementptr inbounds float, float* %1, i64 %44
store float %43, float* %45
%46 = add nuw nsw i64 %40, 1
%47 = icmp eq i64 %46, %34
br i1 %47, label %48, label %39
48: ; preds = %39, %35
%49 = add nuw nsw i64 %36, 1
%50 = icmp eq i64 %49, %33
br i1 %50, label %66, label %35
51: ; preds = %24, %63
%52 = phi i64 [ 0, %24 ], [ %64, %63 ]
br i1 %25, label %53, label %63
53: ; preds = %51, %53
%54 = phi i64 [ %61, %53 ], [ 0, %51 ]
%55 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%56 = load i32, i32* %6
%57 = sitofp i32 %56 to float
%58 = mul nsw i64 %54, %26
%59 = add nuw nsw i64 %58, %52
%60 = getelementptr inbounds float, float* %1, i64 %59
store float %57, float* %60
%61 = add nuw nsw i64 %54, 1
%62 = icmp eq i64 %61, %28
br i1 %62, label %63, label %53
63: ; preds = %53, %51
%64 = add nuw nsw i64 %52, 1
%65 = icmp eq i64 %64, %27
br i1 %65, label %66, label %51
66: ; preds = %63, %48, %23, %29
%67 = call i32 @fclose(i32* %8)
br label %68
68: ; preds = %66, %10
ret void
}