#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*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *);
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) {
    printf("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    119a <read_graphics+0x4a>
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
jmp    12db <read_graphics+0x18b>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jge    11d2 <read_graphics+0x82>
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
cmp    $0xa,%eax
jne    11cd <read_graphics+0x7d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a1 <read_graphics+0x51>
cmpl   $0x0,-0x1c(%rbp)
jne    1257 <read_graphics+0x107>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1252 <read_graphics+0x102>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    123f <read_graphics+0xef>
mov    -0x28(%rbp),%rdi
lea    0xe1a(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <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    11f6 <read_graphics+0xa6>
jmp    1244 <read_graphics+0xf4>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e3 <read_graphics+0x93>
jmp    12d2 <read_graphics+0x182>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12cd <read_graphics+0x17d>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12ba <read_graphics+0x16a>
mov    -0x28(%rbp),%rdi
lea    0xd9f(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <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    1271 <read_graphics+0x121>
jmp    12bf <read_graphics+0x16f>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    125e <read_graphics+0x10e>
jmp    12d2 <read_graphics+0x182>
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   1060 <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     1262 <read_graphics+0x112>
test   %r15d,%r15d
jle    12f9 <read_graphics+0x1a9>
mov    %r15d,%eax
mov    (%rsp),%ecx
mov    %rcx,0x20(%rsp)
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,4),%r14
xor    %eax,%eax
lea    0xe29(%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     12f9 <read_graphics+0x1a9>
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   1050 <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>
lea    0xdb6(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
test   %r15d,%r15d
jle    12f9 <read_graphics+0x1a9>
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    0xd71(%rip),%r15
lea    0x4(%rsp),%r14
jmp    12b5 <read_graphics+0x165>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
add    $0x1,%rax
add    0x18(%rsp),%r13
cmp    0x10(%rsp),%rax
je     12f9 <read_graphics+0x1a9>
mov    %rax,0x8(%rsp)
cmpl   $0x0,(%rsp)
jle    12a0 <read_graphics+0x150>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <fscanf@plt>
xorps  %xmm0,%xmm0
cvtsi2ssl 0x4(%rsp),%xmm0
movss  %xmm0,0x0(%r13,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    12d0 <read_graphics+0x180>
jmp    12a0 <read_graphics+0x150>
mov    %rbp,%rdi
call   1040 <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"
@.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 %22
20: ; preds = %5
%21 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %104
22: ; preds = %5
store i32 0, i32* %12
br label %23
23: ; preds = %35, %22
%24 = load i32, i32* %12
%25 = icmp slt i32 %24, 3
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i32*, i32** %11
%28 = call signext i8 @fgetc(i32* %27)
store i8 %28, i8* %14
%29 = load i8, i8* %14
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i32, i32* %12
%34 = add nsw i32 %33, 1
store i32 %34, i32* %12
br label %35
35: ; preds = %32, %26
br label %23
36: ; preds = %23
%37 = load i32, i32* %10
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %70
39: ; preds = %36
store i32 0, i32* %12
br label %40
40: ; preds = %66, %39
%41 = load i32, i32* %12
%42 = load i32, i32* %8
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %69
44: ; preds = %40
store i32 0, i32* %13
br label %45
45: ; preds = %62, %44
%46 = load i32, i32* %13
%47 = load i32, i32* %9
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %65
49: ; preds = %45
%50 = load i32*, i32** %11
%51 = call i32 @fscanf(i32* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%52 = load i32, i32* %15
%53 = sitofp i32 %52 to float
%54 = load float*, float** %7
%55 = load i32, i32* %12
%56 = load i32, i32* %9
%57 = mul nsw i32 %55, %56
%58 = load i32, i32* %13
%59 = add nsw i32 %57, %58
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds float, float* %54, i64 %60
store float %53, float* %61
br label %62
62: ; preds = %49
%63 = load i32, i32* %13
%64 = add nsw i32 %63, 1
store i32 %64, i32* %13
br label %45
65: ; preds = %45
br label %66
66: ; preds = %65
%67 = load i32, i32* %12
%68 = add nsw i32 %67, 1
store i32 %68, i32* %12
br label %40
69: ; preds = %40
br label %101
70: ; preds = %36
store i32 0, i32* %12
br label %71
71: ; preds = %97, %70
%72 = load i32, i32* %12
%73 = load i32, i32* %8
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %100
75: ; preds = %71
store i32 0, i32* %13
br label %76
76: ; preds = %93, %75
%77 = load i32, i32* %13
%78 = load i32, i32* %9
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %96
80: ; preds = %76
%81 = load i32*, i32** %11
%82 = call i32 @fscanf(i32* %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%83 = load i32, i32* %15
%84 = sitofp i32 %83 to float
%85 = load float*, float** %7
%86 = load i32, i32* %13
%87 = load i32, i32* %8
%88 = mul nsw i32 %86, %87
%89 = load i32, i32* %12
%90 = add nsw i32 %88, %89
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds float, float* %85, i64 %91
store float %84, float* %92
br label %93
93: ; preds = %80
%94 = load i32, i32* %13
%95 = add nsw i32 %94, 1
store i32 %95, i32* %13
br label %76
96: ; preds = %76
br label %97
97: ; preds = %96
%98 = load i32, i32* %12
%99 = add nsw i32 %98, 1
store i32 %99, i32* %12
br label %71
100: ; preds = %71
br label %101
101: ; preds = %100, %69
%102 = load i32*, i32** %11
%103 = call i32 @fclose(i32* %102)
br label %104
104: ; preds = %101, %20
ret void
}

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