#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
double **new_matrix2(int, int);
double **load_data(char *filename, int *n_ptr, int *d_ptr) {
  FILE *f = fopen(filename, "r");
  int n, d, i, j;
  fscanf(f, "%d %d\n", &n, &d);
  double **X = new_matrix2(n, d);
  for (i = 0; i < n; i++)
    for (j = 0; j < d; j++)
      fscanf(f, "%lf", &X[i][j]);
  *n_ptr = n;
  *d_ptr = d;
  return X;
}


x86 assembly (clang, -O0):
<load_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe9f(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
mov    $0x0,%al
call   1030 <fscanf@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <new_matrix2@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11f1 <load_data+0xc1>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11de <load_data+0xae>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x30(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1030 <fscanf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    119b <load_data+0x6b>
jmp    11e3 <load_data+0xb3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1188 <load_data+0x58>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
lea    0xea4(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %rax,%rdi
xor    %eax,%eax
call   1030 <fscanf@plt>
mov    0x4(%rsp),%edi
mov    (%rsp),%esi
call   1040 <new_matrix2@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%ecx
mov    (%rsp),%eax
test   %ecx,%ecx
jle    11eb <load_data+0xbb>
lea    0xe78(%rip),%r13
xor    %ebp,%ebp
jmp    11ac <load_data+0x7c>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
movslq %ecx,%rdx
cmp    %rdx,%rbp
jge    11eb <load_data+0xbb>
test   %eax,%eax
jle    11a0 <load_data+0x70>
xor    %r14d,%r14d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx,%rbp,8),%rdx
add    %r14,%rdx
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <fscanf@plt>
add    $0x1,%r15
movslq (%rsp),%rax
add    $0x8,%r14
cmp    %rax,%r15
jl     11c0 <load_data+0x90>
mov    0x4(%rsp),%ecx
jmp    11a0 <load_data+0x70>
mov    0x8(%rsp),%rdx
mov    %ecx,(%rdx)
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx)
mov    %rbx,%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 = [7 x i8] c"%d %d\0A\00"
@.str.2 = [4 x i8] c"%lf\00"
define double** @load_data(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double**
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = call i32 (i32*, i8*, ...) @fscanf(i32* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %8, i32* %9)
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = call double** @new_matrix2(i32 %17, i32 %18)
store double** %19, double*** %12
store i32 0, i32* %10
br label %20
20: ; preds = %44, %3
%21 = load i32, i32* %10
%22 = load i32, i32* %8
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %47
24: ; preds = %20
store i32 0, i32* %11
br label %25
25: ; preds = %40, %24
%26 = load i32, i32* %11
%27 = load i32, i32* %9
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %43
29: ; preds = %25
%30 = load i32*, i32** %7
%31 = load double**, double*** %12
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double*, double** %31, i64 %33
%35 = load double*, double** %34
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = call i32 (i32*, i8*, ...) @fscanf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %38)
br label %40
40: ; preds = %29
%41 = load i32, i32* %11
%42 = add nsw i32 %41, 1
store i32 %42, i32* %11
br label %25
43: ; preds = %25
br label %44
44: ; preds = %43
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %20
47: ; preds = %20
%48 = load i32, i32* %8
%49 = load i32*, i32** %5
store i32 %48, i32* %49
%50 = load i32, i32* %9
%51 = load i32*, i32** %6
store i32 %50, i32* %51
%52 = load double**, double*** %12
ret double** %52
}

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