#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ print_error_global(char *, char *, int /*<<< orphan*/);
void write_data_double(char *file_data, int N, int M, double *dat) {
  FILE *file = NULL;
  int i, j;
  file = fopen(file_data, "w");
  if (!file)
    print_error_global("open", file_data, 0);
  for (i = 0; i < N; i++) {
    for (j = 0; j < M - 1; j++) {
      fprintf(file, "%G ", dat[i * M + j]);
    }
    fprintf(file, "%G", dat[i * M + (M - 1)]);
    fprintf(file, "\n");
  }
  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
lea    0xe97(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <write_data_double+0x4f>
mov    -0x8(%rbp),%rsi
lea    0xe7a(%rip),%rdi
xor    %edx,%edx
call   1060 <print_error_global@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    123d <write_data_double+0xfd>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11f0 <write_data_double+0xb0>
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    0xe2c(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a9 <write_data_double+0x69>
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    0xdf5(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1196 <write_data_double+0x56>
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
mov    %rdi,%rbp
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118a <write_data_double+0x3a>
test   %r12d,%r12d
jg     11a4 <write_data_double+0x54>
jmp    125f <write_data_double+0x10f>
lea    0xe71(%rip),%rdi
mov    %rbp,%rsi
xor    %edx,%edx
call   1070 <print_error_global@plt>
test   %r12d,%r12d
jle    125f <write_data_double+0x10f>
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    0xe30(%rip),%r12
mov    0x8(%rsp),%r13
jmp    1223 <write_data_double+0xd3>
xchg   %ax,%ax
add    0x20(%rsp),%r14
mov    0x8(%rsp),%rax
movsd  (%rax,%r14,8),%xmm0
mov    %rbx,%rdi
lea    0xe11(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    0x30(%rsp),%r14
add    $0x1,%r14
add    0x10(%rsp),%r13
cmp    0x18(%rsp),%r14
je     125f <write_data_double+0x10f>
mov    %r14,0x30(%rsp)
mov    0x28(%rsp),%rax
imul   %rax,%r14
cmp    $0x2,%eax
jl     11e0 <write_data_double+0x90>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  0x0(%r13,%rbp,8),%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1240 <write_data_double+0xf0>
jmp    11e0 <write_data_double+0x90>
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 = [2 x i8] c"w\00"
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [4 x i8] c"%G \00"
@.str.3 = [3 x i8] c"%G\00"
@.str.4 = [2 x i8] c"\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(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %9
%14 = load i32*, i32** %9
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %4
%17 = load i8*, i8** %5
%18 = call i32 @print_error_global(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 0)
br label %19
19: ; preds = %16, %4
store i32 0, i32* %10
br label %20
20: ; preds = %60, %19
%21 = load i32, i32* %10
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %63
24: ; preds = %20
store i32 0, i32* %11
br label %25
25: ; preds = %42, %24
%26 = load i32, i32* %11
%27 = load i32, i32* %7
%28 = sub nsw i32 %27, 1
%29 = icmp slt i32 %26, %28
br i1 %29, label %30, label %45
30: ; preds = %25
%31 = load i32*, i32** %9
%32 = load double*, double** %8
%33 = load i32, i32* %10
%34 = load i32, i32* %7
%35 = mul nsw i32 %33, %34
%36 = load i32, i32* %11
%37 = add nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %32, i64 %38
%40 = load double, double* %39
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %40)
br label %42
42: ; preds = %30
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %25
45: ; preds = %25
%46 = load i32*, i32** %9
%47 = load double*, double** %8
%48 = load i32, i32* %10
%49 = load i32, i32* %7
%50 = mul nsw i32 %48, %49
%51 = load i32, i32* %7
%52 = sub nsw i32 %51, 1
%53 = add nsw i32 %50, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %47, i64 %54
%56 = load double, double* %55
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), double %56)
%58 = load i32*, i32** %9
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %45
%61 = load i32, i32* %10
%62 = add nsw i32 %61, 1
store i32 %62, i32* %10
br label %20
63: ; preds = %20
%64 = load i32*, i32** %9
%65 = call i32 @fclose(i32* %64)
ret void
}

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