#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 const *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ malloc(int);
void readMat(const char *file_name, int ***mat, int *num_rows, int *num_cols) {
  int i, j;
  FILE *fptr;
  fptr = fopen(file_name, "r");
  fscanf(fptr, "%d", num_rows);
  fscanf(fptr, "%d", num_cols);
  *mat = (int **)malloc(*num_rows * sizeof(int *));
  for (i = 0; i < *num_rows; i++) {
    (*mat)[i] = (int *)malloc(*num_cols * sizeof(int));
  }
  for (i = 0; i < *num_rows; i++) {
    for (j = 0; j < *num_cols; j++) {
      fscanf(fptr, "%d", &((*mat)[i][j]));
    }
  }
  fclose(fptr);
}


x86 assembly (clang, -O0):
<readMat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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
call   1040 <fscanf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe73(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    11f8 <readMat+0xb8>
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b7 <readMat+0x77>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    126f <readMat+0x12f>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    125c <readMat+0x11c>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xdb9(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1215 <readMat+0xd5>
jmp    1261 <readMat+0x121>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ff <readMat+0xbf>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readMat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
lea    0xe95(%rip),%r13
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %rbp,0x18(%rsp)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15,0x8(%rsp)
mov    %r15,%rdx
call   1040 <fscanf@plt>
mov    (%r14),%edi
shl    $0x3,%edi
call   1050 <malloc@plt>
mov    %rbx,0x10(%rsp)
mov    %rax,(%rbx)
cmpl   $0x0,(%r14)
jle    1262 <readMat+0x122>
xor    %ebp,%ebp
mov    0x8(%rsp),%r15
mov    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    (%r15),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    (%rbx),%rcx
mov    %rax,(%rcx,%rbp,8)
add    $0x1,%rbp
movslq (%r14),%rax
cmp    %rax,%rbp
jl     11c0 <readMat+0x80>
test   %eax,%eax
jle    1262 <readMat+0x122>
mov    0x8(%rsp),%rcx
mov    (%rcx),%ecx
xor    %r15d,%r15d
lea    0xe0b(%rip),%r12
mov    %r14,0x20(%rsp)
mov    0x8(%rsp),%rbx
mov    0x10(%rsp),%rbp
jmp    121c <readMat+0xdc>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
movslq %eax,%rdx
cmp    %rdx,%r15
jge    1262 <readMat+0x122>
test   %ecx,%ecx
jle    1210 <readMat+0xd0>
xor    %r14d,%r14d
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp),%rax
mov    (%rax,%r15,8),%rdx
add    %r14,%rdx
mov    0x18(%rsp),%rdi
mov    %r12,%rsi
call   1040 <fscanf@plt>
add    $0x1,%r13
movslq (%rbx),%rcx
add    $0x4,%r14
cmp    %rcx,%r13
jl     1230 <readMat+0xf0>
mov    0x20(%rsp),%r14
mov    (%r14),%eax
jmp    1210 <readMat+0xd0>
mov    0x18(%rsp),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define void @readMat(i8* %0, i32*** %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32***
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i8* %0, i8** %5
store i32*** %1, i32**** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %11
%14 = load i32*, i32** %11
%15 = load i32*, i32** %7
%16 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%17 = load i32*, i32** %11
%18 = load i32*, i32** %8
%19 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = load i32*, i32** %7
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i32**
%27 = load i32***, i32**** %6
store i32** %26, i32*** %27
store i32 0, i32* %9
br label %28
28: ; preds = %46, %4
%29 = load i32, i32* %9
%30 = load i32*, i32** %7
%31 = load i32, i32* %30
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %49
33: ; preds = %28
%34 = load i32*, i32** %8
%35 = load i32, i32* %34
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 4
%38 = trunc i64 %37 to i32
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i32*
%41 = load i32***, i32**** %6
%42 = load i32**, i32*** %41
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32*, i32** %42, i64 %44
store i32* %40, i32** %45
br label %46
46: ; preds = %33
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %28
49: ; preds = %28
store i32 0, i32* %9
br label %50
50: ; preds = %77, %49
%51 = load i32, i32* %9
%52 = load i32*, i32** %7
%53 = load i32, i32* %52
%54 = icmp slt i32 %51, %53
br i1 %54, label %55, label %80
55: ; preds = %50
store i32 0, i32* %10
br label %56
56: ; preds = %73, %55
%57 = load i32, i32* %10
%58 = load i32*, i32** %8
%59 = load i32, i32* %58
%60 = icmp slt i32 %57, %59
br i1 %60, label %61, label %76
61: ; preds = %56
%62 = load i32*, i32** %11
%63 = load i32***, i32**** %6
%64 = load i32**, i32*** %63
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32*, i32** %64, i64 %66
%68 = load i32*, i32** %67
%69 = load i32, i32* %10
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %68, i64 %70
%72 = call i32 @fscanf(i32* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %71)
br label %73
73: ; preds = %61
%74 = load i32, i32* %10
%75 = add nsw i32 %74, 1
store i32 %75, i32* %10
br label %56
76: ; preds = %56
br label %77
77: ; preds = %76
%78 = load i32, i32* %9
%79 = add nsw i32 %78, 1
store i32 %79, i32* %9
br label %50
80: ; preds = %50
%81 = load i32*, i32** %11
%82 = call i32 @fclose(i32* %81)
ret void
}

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