#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 *);
void parse2D(double **a, int X, int Y, char *filename) {
  int i, j;
  FILE *f = fopen(filename, "r");
  for (i = 0; i < X; i++)
    for (j = 0; j < Y; j++)
      fscanf(f, "%lf", &a[i][j]);
}


x86 assembly (clang, -O0):
<parse2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xebf(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b8 <parse2D+0x98>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11a5 <parse2D+0x85>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe70(%rip),%rsi
call   1030 <fscanf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1164 <parse2D+0x44>
jmp    11aa <parse2D+0x8a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1151 <parse2D+0x31>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse2D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0xc(%rsp)
mov    %esi,%r15d
mov    %rdi,%r13
lea    0xec1(%rip),%rsi
mov    %rcx,%rdi
call   1040 <fopen@plt>
test   %r15d,%r15d
jle    11ae <parse2D+0x8e>
mov    %rax,%rbp
mov    %r15d,%eax
mov    %rax,0x10(%rsp)
mov    0xc(%rsp),%ebx
shl    $0x3,%rbx
xor    %r14d,%r14d
lea    0xe99(%rip),%r15
jmp    117b <parse2D+0x5b>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     11ae <parse2D+0x8e>
cmpl   $0x0,0xc(%rsp)
jle    1170 <parse2D+0x50>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%r14,8),%rdx
add    %r12,%rdx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <fscanf@plt>
add    $0x8,%r12
cmp    %r12,%rbx
jne    1190 <parse2D+0x70>
jmp    1170 <parse2D+0x50>
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 = [4 x i8] c"%lf\00"
define void @parse2D(double** %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store double** %0, double*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = load i8*, i8** %8
%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
store i32 0, i32* %9
br label %14
14: ; preds = %38, %4
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %41
18: ; preds = %14
store i32 0, i32* %10
br label %19
19: ; preds = %34, %18
%20 = load i32, i32* %10
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %37
23: ; preds = %19
%24 = load i32*, i32** %11
%25 = load double**, double*** %5
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double*, double** %25, i64 %27
%29 = load double*, double** %28
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %32)
br label %34
34: ; preds = %23
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %19
37: ; preds = %19
br label %38
38: ; preds = %37
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %14
41: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%lf\00"
define void @parse2D(double** nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = icmp sgt i32 %2, 0
%9 = zext i32 %1 to i64
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %7, %22
%12 = phi i64 [ 0, %7 ], [ %23, %22 ]
br i1 %8, label %13, label %22
13: ; preds = %11
%14 = getelementptr inbounds double*, double** %0, i64 %12
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %20, %15 ]
%17 = load double*, double** %14
%18 = getelementptr inbounds double, double* %17, i64 %16
%19 = tail call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %18)
%20 = add nuw nsw i64 %16, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %22, label %15
22: ; preds = %15, %11
%23 = add nuw nsw i64 %12, 1
%24 = icmp eq i64 %23, %9
br i1 %24, label %25, label %11
25: ; preds = %22, %4
ret void
}