#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *);
void write_image(double **image, int line, int row, char *name) {
  FILE *f;
  f = fopen(name, "w+");
  if (f == NULL) {
    printf("failed to crate file\n");
  }
  int i = 0, j = 0;
  for (i = 0; i < row; i++) {
    for (j = 0; j < line; j++) {
      fprintf(f, "%f ", image[j][i]);
    }
    fprintf(f, "\n");
  }
}


x86 assembly (clang, -O0):
<write_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)
mov    -0x18(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1171 <write_image+0x41>
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11fa <write_image+0xca>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11da <write_image+0xaa>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe54(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1199 <write_image+0x69>
mov    -0x20(%rbp),%rdi
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1186 <write_image+0x56>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_image>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %esi,0xc(%rsp)
mov    %rdi,%r13
lea    0xea1(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1176 <write_image+0x36>
test   %r15d,%r15d
jg     1187 <write_image+0x47>
jmp    11f3 <write_image+0xb3>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
test   %r15d,%r15d
jle    11f3 <write_image+0xb3>
mov    %r15d,%eax
mov    %rax,0x10(%rsp)
mov    0xc(%rsp),%ebx
xor    %r14d,%r14d
lea    0xe66(%rip),%r15
jmp    11b8 <write_image+0x78>
nop
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     11f3 <write_image+0xb3>
cmpl   $0x0,0xc(%rsp)
jle    11a0 <write_image+0x60>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13,%r12,8),%rax
movsd  (%rax,%r14,8),%xmm0
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%rbx
jne    11d0 <write_image+0x90>
jmp    11a0 <write_image+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"%f \00"
@str = [21 x i8] c"failed to crate file\00"
define void @write_image(double** nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %7, %4
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %30
11: ; preds = %9
%12 = icmp sgt i32 %1, 0
%13 = zext i32 %2 to i64
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %11, %26
%16 = phi i64 [ 0, %11 ], [ %28, %26 ]
br i1 %12, label %17, label %26
17: ; preds = %15, %17
%18 = phi i64 [ %24, %17 ], [ 0, %15 ]
%19 = getelementptr inbounds double*, double** %0, i64 %18
%20 = load double*, double** %19
%21 = getelementptr inbounds double, double* %20, i64 %16
%22 = load double, double* %21
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %22)
%24 = add nuw nsw i64 %18, 1
%25 = icmp eq i64 %24, %14
br i1 %25, label %26, label %17
26: ; preds = %17, %15
%27 = tail call i32 @fputc(i32 10, i32* %5)
%28 = add nuw nsw i64 %16, 1
%29 = icmp eq i64 %28, %13
br i1 %29, label %30, label %15
30: ; preds = %26, %9
ret void
}