#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 */
void *calloc(size_t, int);
int /*<<< orphan*/ *get_fp(char *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, double *);
char *strtok_r(char *, char *, char **);
double **get_a(char *filename, int dim) {
  double **a = calloc(dim, sizeof(double *));
  for (int row = 0; row < dim; row++) {
    a[row] = calloc(dim, sizeof(double));
  }
  FILE *fp = get_fp(filename, "r");
  size_t m = 4096;
  char *line_buf = calloc(m, sizeof(char));
  double result;
  int cur_row = 0;
  int cur_element;
  char *tok;
  char *tok_ptr;
  while (getline(&line_buf, &m, fp) != -1) {
    cur_element = 0;
    for (tok = strtok_r(line_buf, " ", &tok_ptr); tok;
         tok = strtok_r(NULL, " ", &tok_ptr)) {
      sscanf(tok, "%lf", &result);
      a[cur_row][cur_element] = result;
      cur_element++;
    }
    cur_row++;
  }
  return (a);
}


x86 assembly (clang, -O0):
<get_a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rdi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11af <get_a+0x5f>
movslq -0xc(%rbp),%rdi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <get_a+0x28>
mov    -0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1070 <get_fp@plt>
mov    %rax,-0x28(%rbp)
movq   $0x1000,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     128a <get_a+0x13a>
movl   $0x0,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xdf2(%rip),%rsi
lea    -0x58(%rbp),%rdx
call   1030 <strtok_r@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     127c <get_a+0x12c>
mov    -0x50(%rbp),%rdi
lea    0xdd1(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <sscanf@plt>
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x48(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd98(%rip),%rsi
lea    -0x58(%rbp),%rdx
call   1030 <strtok_r@plt>
mov    %rax,-0x50(%rbp)
jmp    121d <get_a+0xcd>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11e4 <get_a+0x94>
mov    -0x18(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_a>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
movslq %esi,%r12
mov    %r12,%rdi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
test   %r12d,%r12d
jle    11aa <get_a+0x5a>
mov    %r15d,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1190 <get_a+0x40>
mov    %rbx,0x10(%rsp)
lea    0xe4a(%rip),%rsi
mov    %r14,%rdi
call   1070 <get_fp@plt>
mov    %rax,%rbp
movq   $0x1000,0x18(%rsp)
mov    $0x1000,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %rbp,0x20(%rsp)
mov    %rbp,%rdx
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     12b3 <get_a+0x163>
xor    %ebp,%ebp
lea    0xdfb(%rip),%rax
lea    0x30(%rsp),%rbx
mov    0x10(%rsp),%r15
jmp    1244 <get_a+0xf4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    0x20(%rsp),%rdx
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
lea    0xdc0(%rip),%rax
je     12b3 <get_a+0x163>
mov    0x8(%rsp),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1030 <strtok_r@plt>
test   %rax,%rax
lea    0xda6(%rip),%rcx
lea    0x28(%rsp),%r14
je     1220 <get_a+0xd0>
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
mov    %rcx,%r12
mov    %rcx,%rsi
mov    %r14,%rdx
call   1050 <sscanf@plt>
movsd  0x28(%rsp),%xmm0
mov    (%r15,%rbp,8),%rax
movsd  %xmm0,(%rax,%r13,1)
xor    %edi,%edi
lea    0xd68(%rip),%rsi
mov    %rbx,%rdx
call   1030 <strtok_r@plt>
mov    %r12,%rcx
add    $0x8,%r13
test   %rax,%rax
jne    1270 <get_a+0x120>
jmp    1220 <get_a+0xd0>
mov    0x10(%rsp),%rax
add    $0x38,%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 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"%lf\00"
define double** @get_a(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = call i8* @calloc(i64 %16, i32 8)
%18 = bitcast i8* %17 to double**
store double** %18, double*** %5
store i32 0, i32* %6
br label %19
19: ; preds = %32, %2
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = call i8* @calloc(i64 %25, i32 8)
%27 = bitcast i8* %26 to double*
%28 = load double**, double*** %5
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
store double* %27, double** %31
br label %32
32: ; preds = %23
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %19
35: ; preds = %19
%36 = load i8*, i8** %3
%37 = call i32* @get_fp(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %37, i32** %7
store i64 4096, i64* %8
%38 = load i64, i64* %8
%39 = call i8* @calloc(i64 %38, i32 1)
store i8* %39, i8** %9
store i32 0, i32* %11
br label %40
40: ; preds = %66, %35
%41 = load i32*, i32** %7
%42 = call i32 @getline(i8** %9, i64* %8, i32* %41)
%43 = icmp ne i32 %42, -1
br i1 %43, label %44, label %69
44: ; preds = %40
store i32 0, i32* %12
%45 = load i8*, i8** %9
%46 = call i8* @strtok_r(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %14)
store i8* %46, i8** %13
br label %47
47: ; preds = %64, %44
%48 = load i8*, i8** %13
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %66
50: ; preds = %47
%51 = load i8*, i8** %13
%52 = call i32 @sscanf(i8* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %10)
%53 = load double, double* %10
%54 = load double**, double*** %5
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double*, double** %54, i64 %56
%58 = load double*, double** %57
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
store double %53, double* %61
%62 = load i32, i32* %12
%63 = add nsw i32 %62, 1
store i32 %63, i32* %12
br label %64
64: ; preds = %50
%65 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %14)
store i8* %65, i8** %13
br label %47
66: ; preds = %47
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %40
69: ; preds = %40
%70 = load double**, double*** %5
ret double** %70
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"%lf\00"
define double** @get_a(i8* %0, i32 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca double
%6 = alloca i8*
%7 = sext i32 %1 to i64
%8 = tail call i8* @calloc(i64 %7, i32 8)
%9 = bitcast i8* %8 to double**
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = zext i32 %1 to i64
br label %22
13: ; preds = %22, %2
%14 = tail call i32* @get_fp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = bitcast i64* %3 to i8*
store i64 4096, i64* %3
%16 = bitcast i8** %4 to i8*
%17 = tail call i8* @calloc(i64 4096, i32 1)
store i8* %17, i8** %4
%18 = bitcast double* %5 to i8*
%19 = bitcast i8** %6 to i8*
%20 = call i32 @getline(i8** %4, i64* %3, i32* %14)
%21 = icmp eq i32 %20, -1
br i1 %21, label %50, label %29
22: ; preds = %11, %22
%23 = phi i64 [ 0, %11 ], [ %27, %22 ]
%24 = tail call i8* @calloc(i64 %7, i32 8)
%25 = getelementptr inbounds double*, double** %9, i64 %23
%26 = bitcast double** %25 to i8**
store i8* %24, i8** %26
%27 = add nuw nsw i64 %23, 1
%28 = icmp eq i64 %27, %12
br i1 %28, label %13, label %22
29: ; preds = %13, %46
%30 = phi i64 [ %47, %46 ], [ 0, %13 ]
%31 = load i8*, i8** %4
%32 = call i8* @strtok_r(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %6)
%33 = icmp eq i8* %32, null
br i1 %33, label %46, label %34
34: ; preds = %29
%35 = getelementptr inbounds double*, double** %9, i64 %30
br label %36
36: ; preds = %34, %36
%37 = phi i64 [ 0, %34 ], [ %43, %36 ]
%38 = phi i8* [ %32, %34 ], [ %44, %36 ]
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %5)
%40 = load double, double* %5
%41 = load double*, double** %35
%42 = getelementptr inbounds double, double* %41, i64 %37
store double %40, double* %42
%43 = add nuw i64 %37, 1
%44 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %6)
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %36
46: ; preds = %36, %29
%47 = add nuw i64 %30, 1
%48 = call i32 @getline(i8** %4, i64* %3, i32* %14)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %29
50: ; preds = %46, %13
ret double** %9
}