#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_write(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
void write_data_double(char *file_data, int N, int M, double *dat) {
  FILE *file = NULL;
  int i, j;
  file = fopen_write(file_data);
  for (i = 0; i < N; i++) {
    for (j = 0; j < M - 1; j++) {
      fprintf(file, "%G ", dat[i * M + j]);
    }
    fprintf(file, "%G\n", dat[i * M + (M - 1)]);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<write_data_double>:
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)
mov    -0x8(%rbp),%rdi
call   1040 <fopen_write@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f3 <write_data_double+0xc3>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ba <write_data_double+0x8a>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1175 <write_data_double+0x45>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x10(%rbp),%ecx
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe24(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <write_data_double+0x32>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_data_double>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%r15d
mov    %esi,%r12d
call   1040 <fopen_write@plt>
mov    %rax,%rbx
test   %r12d,%r12d
jle    120d <write_data_double+0xdd>
movslq %r15d,%rax
add    $0xffffffff,%r15d
movslq %r15d,%rcx
mov    %rcx,0x20(%rsp)
mov    %r12d,%ecx
mov    %rcx,0x18(%rsp)
mov    %rax,0x28(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x10(%rsp)
xor    %r14d,%r14d
lea    0xe73(%rip),%r12
mov    0x8(%rsp),%r13
jmp    11d4 <write_data_double+0xa4>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    0x20(%rsp),%r14
mov    0x8(%rsp),%rax
movsd  (%rax,%r14,8),%xmm0
mov    %rbx,%rdi
lea    0xe4a(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x30(%rsp),%r14
add    $0x1,%r14
add    0x10(%rsp),%r13
cmp    0x18(%rsp),%r14
je     120d <write_data_double+0xdd>
mov    %r14,0x30(%rsp)
mov    0x28(%rsp),%rax
imul   %rax,%r14
cmp    $0x2,%eax
jl     11a0 <write_data_double+0x70>
xor    %ebp,%ebp
nopl   0x0(%rax)
movsd  0x0(%r13,%rbp,8),%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11f0 <write_data_double+0xc0>
jmp    11a0 <write_data_double+0x70>
mov    %rbx,%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%G \00"
@.str.1 = [4 x i8] c"%G\0A\00"
define void @write_data_double(i8* %0, i32 %1, i32 %2, double* nocapture %3) {
%5 = tail call i32* @fopen_write(i8* %0)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %32
7: ; preds = %4
%8 = add i32 %2, -1
%9 = icmp sgt i32 %2, 1
%10 = sext i32 %2 to i64
%11 = sext i32 %8 to i64
%12 = zext i32 %1 to i64
%13 = zext i32 %8 to i64
br label %14
14: ; preds = %7, %25
%15 = phi i64 [ 0, %7 ], [ %30, %25 ]
%16 = mul nsw i64 %15, %10
br i1 %9, label %17, label %25
17: ; preds = %14, %17
%18 = phi i64 [ %23, %17 ], [ 0, %14 ]
%19 = add nsw i64 %18, %16
%20 = getelementptr inbounds double, double* %3, i64 %19
%21 = load double, double* %20
%22 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %21)
%23 = add nuw nsw i64 %18, 1
%24 = icmp eq i64 %23, %13
br i1 %24, label %25, label %17
25: ; preds = %17, %14
%26 = add nsw i64 %16, %11
%27 = getelementptr inbounds double, double* %3, i64 %26
%28 = load double, double* %27
%29 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %28)
%30 = add nuw nsw i64 %15, 1
%31 = icmp eq i64 %30, %12
br i1 %31, label %32, label %14
32: ; preds = %25, %4
%33 = tail call i32 @fclose(i32* %5)
ret void
}