#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, double *);
void readMatrix(char *filename, double *matrix, int n) {
  int i, j;
  double x;
  FILE *fp = fopen(filename, "r");
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      fscanf(fp, "%lf", &x);
      matrix[i * n + j] = x;
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<readMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11cd <readMatrix+0x9d>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ba <readMatrix+0x8a>
mov    -0x30(%rbp),%rdi
lea    0xe7a(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <fscanf@plt>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <readMatrix+0x41>
jmp    11bf <readMatrix+0x8f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115e <readMatrix+0x2e>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    11c5 <readMatrix+0x95>
mov    %ebp,%ebp
lea    0x0(,%rbp,8),%rax
mov    %rax,(%rsp)
xor    %eax,%eax
lea    0xe95(%rip),%r15
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rbx,%r13,8)
add    $0x1,%r13
cmp    %r13,%rbp
jne    1190 <readMatrix+0x60>
mov    0x8(%rsp),%rax
add    $0x1,%rax
add    (%rsp),%rbx
cmp    %rbp,%rax
jne    1180 <readMatrix+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x18,%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 = [4 x i8] c"%lf\00"
define void @readMatrix(i8* %0, double* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i32*
store i8* %0, i8** %4
store double* %1, double** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
store i32 0, i32* %7
br label %13
13: ; preds = %38, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %41
17: ; preds = %13
store i32 0, i32* %8
br label %18
18: ; preds = %34, %17
%19 = load i32, i32* %8
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = load i32*, i32** %10
%24 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %9)
%25 = load double, double* %9
%26 = load double*, double** %5
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %8
%31 = add nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %26, i64 %32
store double %25, double* %33
br label %34
34: ; preds = %22
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %18
37: ; preds = %18
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %13
41: ; preds = %13
%42 = load i32*, i32** %10
%43 = call i32 @fclose(i32* %42)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%lf\00"
define void @readMatrix(i8* nocapture %0, double* nocapture writeonly %1, i32 %2) {
%4 = alloca double
%5 = bitcast double* %4 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %25
8: ; preds = %3
%9 = zext i32 %2 to i64
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %22, %8
%12 = phi i64 [ 0, %8 ], [ %23, %22 ]
%13 = mul nsw i64 %12, %9
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %20, %14 ]
%16 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %4)
%17 = load double, double* %4
%18 = add nuw nsw i64 %15, %13
%19 = getelementptr inbounds double, double* %1, i64 %18
store double %17, double* %19
%20 = add nuw nsw i64 %15, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %22, label %14
22: ; preds = %14
%23 = add nuw nsw i64 %12, 1
%24 = icmp eq i64 %23, %10
br i1 %24, label %25, label %11
25: ; preds = %22, %3
%26 = call i32 @fclose(i32* %6)
ret void
}