#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ printf(char *);
void read_file(char *filename, float *input, int data_rows, int data_cols,
               int major) {
  FILE *fid;
  int i, j;
  float temp;
  fid = fopen(filename, "r");
  if (fid == NULL) {
    printf("The file was not opened for reading\n");
    fflush(0);
    return;
  }
  if (major == 0) {
    for (i = 0; i < data_rows; i++) {
      for (j = 0; j < data_cols; j++) {
        fscanf(fid, "%f", &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, "%f", &temp);
        input[j * data_rows + i] = (float)temp;
      }
    }
  }
  fclose(fid);
}


x86 assembly (clang, -O0):
<read_file>:
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    11a1 <read_file+0x51>
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
jmp    12aa <read_file+0x15a>
cmpl   $0x0,-0x1c(%rbp)
jne    1226 <read_file+0xd6>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1221 <read_file+0xd1>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    120e <read_file+0xbe>
mov    -0x28(%rbp),%rdi
lea    0xe4b(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   1050 <fscanf@plt>
movss  -0x34(%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    11c5 <read_file+0x75>
jmp    1213 <read_file+0xc3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b2 <read_file+0x62>
jmp    12a1 <read_file+0x151>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    129c <read_file+0x14c>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1289 <read_file+0x139>
mov    -0x28(%rbp),%rdi
lea    0xdd0(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   1050 <fscanf@plt>
movss  -0x34(%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    1240 <read_file+0xf0>
jmp    128e <read_file+0x13e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    122d <read_file+0xdd>
jmp    12a1 <read_file+0x151>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%ebx
mov    %ecx,(%rsp)
mov    %edx,%r14d
mov    %rsi,%r15
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1215 <read_file+0xc5>
mov    %rax,%rbp
test   %ebx,%ebx
je     1236 <read_file+0xe6>
mov    %r15,0x8(%rsp)
test   %r14d,%r14d
jle    12c5 <read_file+0x175>
mov    %r14d,%eax
mov    (%rsp),%ecx
mov    %rcx,0x20(%rsp)
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,4),%r14
xor    %eax,%eax
lea    0xe49(%rip),%r15
lea    0x4(%rsp),%rbx
jmp    11da <read_file+0x8a>
mov    0x18(%rsp),%rax
add    $0x1,%rax
addq   $0x4,0x8(%rsp)
cmp    0x10(%rsp),%rax
je     12c5 <read_file+0x175>
mov    %rax,0x18(%rsp)
cmpl   $0x0,(%rsp)
jle    11c0 <read_file+0x70>
mov    0x20(%rsp),%r13
mov    0x8(%rsp),%r12
nop
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
movss  0x4(%rsp),%xmm0
movss  %xmm0,(%r12)
add    %r14,%r12
add    $0xffffffffffffffff,%r13
jne    11f0 <read_file+0xa0>
jmp    11c0 <read_file+0x70>
lea    0xde9(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fflush@plt>
test   %r14d,%r14d
jle    12c5 <read_file+0x175>
mov    (%rsp),%eax
movslq %eax,%rcx
mov    %r14d,%edx
mov    %rdx,0x10(%rsp)
mov    %eax,%ebx
shl    $0x2,%rcx
mov    %rcx,0x8(%rsp)
xor    %eax,%eax
lea    0xda1(%rip),%r12
lea    0x4(%rsp),%r14
jmp    1285 <read_file+0x135>
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rax
add    $0x1,%rax
add    0x8(%rsp),%r15
cmp    0x10(%rsp),%rax
je     12c5 <read_file+0x175>
mov    %rax,0x18(%rsp)
cmpl   $0x0,(%rsp)
jle    1270 <read_file+0x120>
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <fscanf@plt>
movss  0x4(%rsp),%xmm0
movss  %xmm0,(%r15,%r13,4)
add    $0x1,%r13
cmp    %r13,%rbx
jne    12a0 <read_file+0x150>
jmp    1270 <read_file+0x120>
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"%f\00"
define void @read_file(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 float
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
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %11
%17 = load i32*, i32** %11
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @fflush(i32 0)
br label %88
22: ; preds = %5
%23 = load i32, i32* %10
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %55
25: ; preds = %22
store i32 0, i32* %12
br label %26
26: ; preds = %51, %25
%27 = load i32, i32* %12
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %54
30: ; preds = %26
store i32 0, i32* %13
br label %31
31: ; preds = %47, %30
%32 = load i32, i32* %13
%33 = load i32, i32* %9
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i32*, i32** %11
%37 = call i32 @fscanf(i32* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %14)
%38 = load float, float* %14
%39 = load float*, float** %7
%40 = load i32, i32* %12
%41 = load i32, i32* %9
%42 = mul nsw i32 %40, %41
%43 = load i32, i32* %13
%44 = add nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds float, float* %39, i64 %45
store float %38, float* %46
br label %47
47: ; preds = %35
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
store i32 %49, i32* %13
br label %31
50: ; preds = %31
br label %51
51: ; preds = %50
%52 = load i32, i32* %12
%53 = add nsw i32 %52, 1
store i32 %53, i32* %12
br label %26
54: ; preds = %26
br label %85
55: ; preds = %22
store i32 0, i32* %12
br label %56
56: ; preds = %81, %55
%57 = load i32, i32* %12
%58 = load i32, i32* %8
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %84
60: ; preds = %56
store i32 0, i32* %13
br label %61
61: ; preds = %77, %60
%62 = load i32, i32* %13
%63 = load i32, i32* %9
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %80
65: ; preds = %61
%66 = load i32*, i32** %11
%67 = call i32 @fscanf(i32* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %14)
%68 = load float, float* %14
%69 = load float*, float** %7
%70 = load i32, i32* %13
%71 = load i32, i32* %8
%72 = mul nsw i32 %70, %71
%73 = load i32, i32* %12
%74 = add nsw i32 %72, %73
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds float, float* %69, i64 %75
store float %68, float* %76
br label %77
77: ; preds = %65
%78 = load i32, i32* %13
%79 = add nsw i32 %78, 1
store i32 %79, i32* %13
br label %61
80: ; preds = %61
br label %81
81: ; preds = %80
%82 = load i32, i32* %12
%83 = add nsw i32 %82, 1
store i32 %83, i32* %12
br label %56
84: ; preds = %56
br label %85
85: ; preds = %84, %54
%86 = load i32*, i32** %11
%87 = call i32 @fclose(i32* %86)
br label %88
88: ; preds = %85, %19
ret void
}

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