#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*/ close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(int);
void read_matrix(const char *path, double **A, int *m, int *n) {
  int i, j;
  FILE *f = fopen(path, "r");
  fscanf(f, "%d", m);
  fscanf(f, "%d", n);
  double *t = (double *)malloc(sizeof(double) * (*m) * (*n));
  for (j = 0; j < *m; j++) {
    for (i = 0; i < *n; i++) {
      float fl;
      fscanf(f, "%f", &fl);
      t[i + (*n) * j] = fl;
    }
  }
  close(f);
  *A = t;
}


x86 assembly (clang, -O0):
<read_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1030 <fscanf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1030 <fscanf@plt>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1240 <read_matrix+0x100>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    122d <read_matrix+0xed>
mov    -0x30(%rbp),%rdi
lea    0xe15(%rip),%rsi
lea    -0x3c(%rbp),%rdx
mov    $0x0,%al
call   1030 <fscanf@plt>
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x38(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rdx
mov    (%rdx),%edx
imul   -0x28(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d6 <read_matrix+0x96>
jmp    1232 <read_matrix+0xf2>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c0 <read_matrix+0x80>
mov    -0x30(%rbp),%rdi
call   1040 <close@plt>
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,0x8(%rsp)
lea    0xea0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe93(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1030 <fscanf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <fscanf@plt>
mov    0x0(%rbp),%edi
imul   (%r15),%edi
shl    $0x3,%edi
call   1050 <malloc@plt>
mov    %r15,%rdx
mov    %rax,%r15
mov    %rbp,0x10(%rsp)
mov    0x0(%rbp),%ecx
test   %ecx,%ecx
jle    1229 <read_matrix+0xe9>
mov    (%rdx),%eax
lea    0xe4c(%rip),%r14
lea    0x4(%rsp),%r12
xor    %esi,%esi
jmp    11d7 <read_matrix+0x97>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%esi
cmp    %ecx,%esi
jge    1229 <read_matrix+0xe9>
test   %eax,%eax
jle    11d0 <read_matrix+0x90>
xor    %ebp,%ebp
mov    %esi,(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rdx,%r13
mov    %r12,%rdx
xor    %eax,%eax
call   1030 <fscanf@plt>
mov    (%rsp),%esi
mov    %r13,%rdx
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    0x0(%r13),%eax
mov    %esi,%ecx
imul   %eax,%ecx
movslq %ecx,%rcx
add    %rbp,%rcx
movsd  %xmm0,(%r15,%rcx,8)
add    $0x1,%rbp
cmp    %eax,%ebp
jl     11e0 <read_matrix+0xa0>
mov    0x10(%rsp),%rcx
mov    (%rcx),%ecx
jmp    11d0 <read_matrix+0x90>
mov    %rbx,%rdi
call   1040 <close@plt>
mov    0x8(%rsp),%rax
mov    %r15,(%rax)
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 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%f\00"
define void @read_matrix(i8* %0, double** %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca double**
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca double*
%13 = alloca float
store i8* %0, i8** %5
store double** %1, double*** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %11
%16 = load i32*, i32** %11
%17 = load i32*, i32** %7
%18 = call i32 (i32*, i8*, ...) @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %17)
%19 = load i32*, i32** %11
%20 = load i32*, i32** %8
%21 = call i32 (i32*, i8*, ...) @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = mul i64 8, %24
%26 = load i32*, i32** %8
%27 = load i32, i32* %26
%28 = sext i32 %27 to i64
%29 = mul i64 %25, %28
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to double*
store double* %32, double** %12
store i32 0, i32* %10
br label %33
33: ; preds = %62, %4
%34 = load i32, i32* %10
%35 = load i32*, i32** %7
%36 = load i32, i32* %35
%37 = icmp slt i32 %34, %36
br i1 %37, label %38, label %65
38: ; preds = %33
store i32 0, i32* %9
br label %39
39: ; preds = %58, %38
%40 = load i32, i32* %9
%41 = load i32*, i32** %8
%42 = load i32, i32* %41
%43 = icmp slt i32 %40, %42
br i1 %43, label %44, label %61
44: ; preds = %39
%45 = load i32*, i32** %11
%46 = call i32 (i32*, i8*, ...) @fscanf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %13)
%47 = load float, float* %13
%48 = fpext float %47 to double
%49 = load double*, double** %12
%50 = load i32, i32* %9
%51 = load i32*, i32** %8
%52 = load i32, i32* %51
%53 = load i32, i32* %10
%54 = mul nsw i32 %52, %53
%55 = add nsw i32 %50, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %49, i64 %56
store double %48, double* %57
br label %58
58: ; preds = %44
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 1
store i32 %60, i32* %9
br label %39
61: ; preds = %39
br label %62
62: ; preds = %61
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %33
65: ; preds = %33
%66 = load i32*, i32** %11
%67 = call i32 @close(i32* %66)
%68 = load double*, double** %12
%69 = load double**, double*** %6
store double* %68, double** %69
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%f\00"
define void @read_matrix(i8* nocapture %0, double** nocapture writeonly %1, i32* %2, i32* %3) {
%5 = alloca float
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %2
%10 = shl i32 %9, 3
%11 = load i32, i32* %3
%12 = mul i32 %10, %11
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double*
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %44
17: ; preds = %4
%18 = bitcast float* %5 to i8*
%19 = load i32, i32* %3
br label %20
20: ; preds = %17, %39
%21 = phi i32 [ %15, %17 ], [ %40, %39 ]
%22 = phi i32 [ %19, %17 ], [ %41, %39 ]
%23 = phi i32 [ 0, %17 ], [ %42, %39 ]
%24 = icmp sgt i32 %22, 0
br i1 %24, label %25, label %39
25: ; preds = %20, %25
%26 = phi i32 [ %35, %25 ], [ 0, %20 ]
%27 = call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %5)
%28 = load float, float* %5
%29 = fpext float %28 to double
%30 = load i32, i32* %3
%31 = mul nsw i32 %30, %23
%32 = add nsw i32 %31, %26
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %14, i64 %33
store double %29, double* %34
%35 = add nuw nsw i32 %26, 1
%36 = icmp slt i32 %35, %30
br i1 %36, label %25, label %37
37: ; preds = %25
%38 = load i32, i32* %2
br label %39
39: ; preds = %37, %20
%40 = phi i32 [ %38, %37 ], [ %21, %20 ]
%41 = phi i32 [ %30, %37 ], [ %22, %20 ]
%42 = add nuw nsw i32 %23, 1
%43 = icmp slt i32 %42, %40
br i1 %43, label %20, label %44
44: ; preds = %39, %4
%45 = call i32 @close(i32* %6)
store double* %14, double** %1
ret void
}