#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 *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *);
void load_image(double **image, int line, int row, char *name) {
  FILE *h = NULL;
  int tmp = 0;
  h = fopen(name, "r");
  if (h == NULL) {
    printf("file not found\n");
  } else {
    int i = 0, j = 0;
    for (i = 0; i < row; i++) {
      for (j = 0; j < line; j++) {
        fscanf(h, "%i", &tmp);
        image[j][i] = (double)tmp;
      }
    }
    fclose(h);
  }
}


x86 assembly (clang, -O0):
<load_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1195 <load_image+0x55>
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
jmp    1221 <load_image+0xe1>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1218 <load_image+0xd8>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1205 <load_image+0xc5>
mov    -0x20(%rbp),%rdi
lea    0xe3e(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <fscanf@plt>
cvtsi2sdl -0x24(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11bd <load_image+0x7d>
jmp    120a <load_image+0xca>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11aa <load_image+0x6a>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_image>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r15d
mov    %esi,0x8(%rsp)
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
lea    0xe99(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1218 <load_image+0xd8>
mov    %rax,%r14
mov    %rbx,0x18(%rsp)
test   %r15d,%r15d
jle    1201 <load_image+0xc1>
mov    %r15d,%eax
mov    %rax,0x10(%rsp)
mov    0x8(%rsp),%eax
xor    %ebp,%ebp
lea    0xe64(%rip),%r12
lea    0xc(%rsp),%rbx
mov    %rax,0x20(%rsp)
mov    0x18(%rsp),%r13
jmp    11bb <load_image+0x7b>
nop
add    $0x1,%rbp
cmp    0x10(%rsp),%rbp
je     1201 <load_image+0xc1>
cmpl   $0x0,0x8(%rsp)
jle    11b0 <load_image+0x70>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rsp),%xmm0
mov    0x0(%r13,%r15,8),%rax
movsd  %xmm0,(%rax,%rbp,8)
mov    0x20(%rsp),%rax
add    $0x1,%r15
cmp    %r15,%rax
jne    11d0 <load_image+0x90>
jmp    11b0 <load_image+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde6(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [16 x i8] c"file not found\0A\00"
@.str.2 = [3 x i8] c"%i\00"
define void @load_image(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
%12 = alloca i32
store double** %0, double*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i32* null, i32** %9
store i32 0, i32* %10
%13 = load i8*, i8** %8
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %9
%15 = load i32*, i32** %9
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %52
19: ; preds = %4
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %11
br label %20
20: ; preds = %46, %19
%21 = load i32, i32* %11
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %49
24: ; preds = %20
store i32 0, i32* %12
br label %25
25: ; preds = %42, %24
%26 = load i32, i32* %12
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = load i32*, i32** %9
%31 = call i32 @fscanf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %10)
%32 = load i32, i32* %10
%33 = sitofp i32 %32 to double
%34 = load double**, double*** %5
%35 = load i32, i32* %12
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double*, double** %34, i64 %36
%38 = load double*, double** %37
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
store double %33, double* %41
br label %42
42: ; preds = %29
%43 = load i32, i32* %12
%44 = add nsw i32 %43, 1
store i32 %44, i32* %12
br label %25
45: ; preds = %25
br label %46
46: ; preds = %45
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
store i32 %48, i32* %11
br label %20
49: ; preds = %20
%50 = load i32*, i32** %9
%51 = call i32 @fclose(i32* %50)
br label %52
52: ; preds = %49, %17
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%i\00"
@str = [15 x i8] c"file not found\00"
define void @load_image(double** nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%7 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %32
11: ; preds = %9
%12 = icmp sgt i32 %1, 0
%13 = zext i32 %2 to i64
%14 = zext i32 %1 to i64
br label %17
15: ; preds = %4
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %34
17: ; preds = %11, %29
%18 = phi i64 [ 0, %11 ], [ %30, %29 ]
br i1 %12, label %19, label %29
19: ; preds = %17, %19
%20 = phi i64 [ %27, %19 ], [ 0, %17 ]
%21 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%22 = load i32, i32* %5
%23 = sitofp i32 %22 to double
%24 = getelementptr inbounds double*, double** %0, i64 %20
%25 = load double*, double** %24
%26 = getelementptr inbounds double, double* %25, i64 %18
store double %23, double* %26
%27 = add nuw nsw i64 %20, 1
%28 = icmp eq i64 %27, %14
br i1 %28, label %29, label %19
29: ; preds = %19, %17
%30 = add nuw nsw i64 %18, 1
%31 = icmp eq i64 %30, %13
br i1 %31, label %32, label %17
32: ; preds = %29, %9
%33 = call i32 @fclose(i32* %7)
br label %34
34: ; preds = %32, %15
ret void
}