#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, ...);
void *malloc(int);
int **load_matrix_int(char *fname, int *N, int *dim) {
  FILE *f;
  int **x;
  int i, j, k;
  int tmp;
  *N = 0;
  *dim = 0;
  k = 0;
  f = fopen(fname, "r");
  while (!feof(f)) {
    i = fscanf(f, "%*[^\n]%*[\n]");
    k++;
  }
  fclose(f);
  *N = k;
  k = 0;
  f = fopen(fname, "r");
  while (!feof(f)) {
    i = fscanf(f, "%d", &tmp);
    k++;
  }
  fclose(f);
  *dim = (k / *N);
  f = fopen(fname, "r");
  x = malloc(*N * sizeof(double *));
  for (i = 0; i < *N; i++) {
    x[i] = malloc(*dim * sizeof(double));
    for (j = 0; j < *dim; j++) {
      k = fscanf(f, "%d", &tmp);
      x[i][j] = tmp;
    }
  }
  fclose(f);
  return x;
}


x86 assembly (clang, -O0):
<load_matrix_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b1 <load_matrix_int+0x61>
jmp    11d4 <load_matrix_int+0x84>
mov    -0x20(%rbp),%rdi
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1193 <load_matrix_int+0x43>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    121f <load_matrix_int+0xcf>
jmp    1246 <load_matrix_int+0xf6>
mov    -0x20(%rbp),%rdi
lea    0xde4(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1201 <load_matrix_int+0xb1>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x34(%rbp),%eax
mov    -0x10(%rbp),%rcx
cltd
idivl  (%rcx)
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xd94(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1328 <load_matrix_int+0x1d8>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1315 <load_matrix_int+0x1c5>
mov    -0x20(%rbp),%rdi
lea    0xd2b(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12c9 <load_matrix_int+0x179>
jmp    131a <load_matrix_int+0x1ca>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1292 <load_matrix_int+0x142>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_matrix_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r15
mov    %rsi,0x10(%rsp)
movl   $0x0,(%rsi)
mov    %rdx,0x8(%rsp)
movl   $0x0,(%rdx)
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
mov    $0x0,%ebx
test   %eax,%eax
jne    11cc <load_matrix_int+0x7c>
lea    0xe62(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fscanf@plt>
add    $0x1,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     11b0 <load_matrix_int+0x60>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    0x10(%rsp),%rax
mov    %ebx,(%rax)
lea    0xe1e(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    122f <load_matrix_int+0xdf>
lea    0xe0e(%rip),%r14
lea    0x4(%rsp),%r13
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1210 <load_matrix_int+0xc0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
cltd
mov    0x10(%rsp),%rbx
idivl  (%rbx)
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
lea    0xdb1(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
mov    %rax,%r13
mov    (%rbx),%ebx
lea    0x0(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
test   %ebx,%ebx
jle    1314 <load_matrix_int+0x1c4>
mov    %rbx,%r15
mov    0x8(%rsp),%rax
mov    (%rax),%r12d
lea    0x4(%rsp),%rbp
xor    %r14d,%r14d
jmp    129c <load_matrix_int+0x14c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
movslq %r15d,%rax
cmp    %rax,%r14
jge    1314 <load_matrix_int+0x1c4>
lea    0x0(,%r12,8),%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    0x18(%rsp),%rax
mov    %rcx,(%rax,%r14,8)
test   %r12d,%r12d
jle    1290 <load_matrix_int+0x140>
mov    %r14,0x20(%rsp)
mov    %r13,%r14
mov    0x8(%rsp),%r13
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
lea    0xd34(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
mov    %rcx,%rbx
call   1040 <fscanf@plt>
mov    %rbx,%rcx
mov    0x4(%rsp),%eax
mov    %eax,(%rbx,%r15,4)
add    $0x1,%r15
movslq 0x0(%r13),%r12
cmp    %r12,%r15
jl     12d0 <load_matrix_int+0x180>
mov    0x10(%rsp),%rax
mov    (%rax),%r15d
mov    %r14,%r13
mov    0x20(%rsp),%r14
jmp    1290 <load_matrix_int+0x140>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    0x18(%rsp),%rax
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 = [12 x i8] c"%*[^\0A]%*[\0A]\00"
@.str.2 = [3 x i8] c"%d\00"
define i32** @load_matrix_int(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 i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%13 = load i32*, i32** %5
store i32 0, i32* %13
%14 = load i32*, i32** %6
store i32 0, i32* %14
store i32 0, i32* %11
%15 = load i8*, i8** %4
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %7
br label %17
17: ; preds = %22, %3
%18 = load i32*, i32** %7
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32*, i32** %7
%24 = call i32 (i32*, i8*, ...) @fscanf(i32* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 %24, i32* %9
%25 = load i32, i32* %11
%26 = add nsw i32 %25, 1
store i32 %26, i32* %11
br label %17
27: ; preds = %17
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %11
%31 = load i32*, i32** %5
store i32 %30, i32* %31
store i32 0, i32* %11
%32 = load i8*, i8** %4
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %33, i32** %7
br label %34
34: ; preds = %39, %27
%35 = load i32*, i32** %7
%36 = call i32 @feof(i32* %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32*, i32** %7
%41 = call i32 (i32*, i8*, ...) @fscanf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %12)
store i32 %41, i32* %9
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %34
44: ; preds = %34
%45 = load i32*, i32** %7
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* %11
%48 = load i32*, i32** %5
%49 = load i32, i32* %48
%50 = sdiv i32 %47, %49
%51 = load i32*, i32** %6
store i32 %50, i32* %51
%52 = load i8*, i8** %4
%53 = call i32* @fopen(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %53, i32** %7
%54 = load i32*, i32** %5
%55 = load i32, i32* %54
%56 = sext i32 %55 to i64
%57 = mul i64 %56, 8
%58 = trunc i64 %57 to i32
%59 = call i8* @malloc(i32 %58)
%60 = bitcast i8* %59 to i32**
store i32** %60, i32*** %8
store i32 0, i32* %9
br label %61
61: ; preds = %99, %44
%62 = load i32, i32* %9
%63 = load i32*, i32** %5
%64 = load i32, i32* %63
%65 = icmp slt i32 %62, %64
br i1 %65, label %66, label %102
66: ; preds = %61
%67 = load i32*, i32** %6
%68 = load i32, i32* %67
%69 = sext i32 %68 to i64
%70 = mul i64 %69, 8
%71 = trunc i64 %70 to i32
%72 = call i8* @malloc(i32 %71)
%73 = bitcast i8* %72 to i32*
%74 = load i32**, i32*** %8
%75 = load i32, i32* %9
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32*, i32** %74, i64 %76
store i32* %73, i32** %77
store i32 0, i32* %10
br label %78
78: ; preds = %95, %66
%79 = load i32, i32* %10
%80 = load i32*, i32** %6
%81 = load i32, i32* %80
%82 = icmp slt i32 %79, %81
br i1 %82, label %83, label %98
83: ; preds = %78
%84 = load i32*, i32** %7
%85 = call i32 (i32*, i8*, ...) @fscanf(i32* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %12)
store i32 %85, i32* %11
%86 = load i32, i32* %12
%87 = load i32**, i32*** %8
%88 = load i32, i32* %9
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32*, i32** %87, i64 %89
%91 = load i32*, i32** %90
%92 = load i32, i32* %10
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i32, i32* %91, i64 %93
store i32 %86, i32* %94
br label %95
95: ; preds = %83
%96 = load i32, i32* %10
%97 = add nsw i32 %96, 1
store i32 %97, i32* %10
br label %78
98: ; preds = %78
br label %99
99: ; preds = %98
%100 = load i32, i32* %9
%101 = add nsw i32 %100, 1
store i32 %101, i32* %9
br label %61
102: ; preds = %61
%103 = load i32*, i32** %7
%104 = call i32 @fclose(i32* %103)
%105 = load i32**, i32*** %8
ret i32** %105
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [12 x i8] c"%*[^\0A]%*[\0A]\00"
@.str.2 = [3 x i8] c"%d\00"
define noalias i32** @load_matrix_int(i8* nocapture %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %1
store i32 0, i32* %2
%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 @feof(i32* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %3, %9
%10 = phi i32 [ %12, %9 ], [ 0, %3 ]
%11 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%12 = add nuw nsw i32 %10, 1
%13 = tail call i32 @feof(i32* %6)
%14 = icmp eq i32 %13, 0
br i1 %14, label %9, label %15
15: ; preds = %9, %3
%16 = phi i32 [ 0, %3 ], [ %12, %9 ]
%17 = tail call i32 @fclose(i32* %6)
store i32 %16, i32* %1
%18 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @feof(i32* %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %15, %21
%22 = phi i32 [ %24, %21 ], [ 0, %15 ]
%23 = call i32 (i32*, i8*, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%24 = add nuw nsw i32 %22, 1
%25 = call i32 @feof(i32* %18)
%26 = icmp eq i32 %25, 0
br i1 %26, label %21, label %27
27: ; preds = %21, %15
%28 = phi i32 [ 0, %15 ], [ %24, %21 ]
%29 = call i32 @fclose(i32* %18)
%30 = load i32, i32* %1
%31 = sdiv i32 %28, %30
store i32 %31, i32* %2
%32 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* %1
%34 = shl i32 %33, 3
%35 = call i8* @malloc(i32 %34)
%36 = bitcast i8* %35 to i32**
%37 = icmp sgt i32 %33, 0
br i1 %37, label %38, label %67
38: ; preds = %27
%39 = load i32, i32* %2
br label %40
40: ; preds = %38, %61
%41 = phi i32 [ %33, %38 ], [ %62, %61 ]
%42 = phi i32 [ %39, %38 ], [ %63, %61 ]
%43 = phi i64 [ 0, %38 ], [ %64, %61 ]
%44 = shl i32 %42, 3
%45 = call i8* @malloc(i32 %44)
%46 = getelementptr inbounds i32*, i32** %36, i64 %43
%47 = bitcast i32** %46 to i8**
store i8* %45, i8** %47
%48 = icmp sgt i32 %42, 0
%49 = bitcast i8* %45 to i32*
br i1 %48, label %50, label %61
50: ; preds = %40, %50
%51 = phi i64 [ %55, %50 ], [ 0, %40 ]
%52 = call i32 (i32*, i8*, ...) @fscanf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%53 = load i32, i32* %4
%54 = getelementptr inbounds i32, i32* %49, i64 %51
store i32 %53, i32* %54
%55 = add nuw nsw i64 %51, 1
%56 = load i32, i32* %2
%57 = sext i32 %56 to i64
%58 = icmp slt i64 %55, %57
br i1 %58, label %50, label %59
59: ; preds = %50
%60 = load i32, i32* %1
br label %61
61: ; preds = %59, %40
%62 = phi i32 [ %60, %59 ], [ %41, %40 ]
%63 = phi i32 [ %56, %59 ], [ %42, %40 ]
%64 = add nuw nsw i64 %43, 1
%65 = sext i32 %62 to i64
%66 = icmp slt i64 %64, %65
br i1 %66, label %40, label %67
67: ; preds = %61, %27
%68 = call i32 @fclose(i32* %32)
ret i32** %36
}