#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 *, ...);
int /*<<< orphan*/ print_error_global(char *, char *, int /*<<< orphan*/);
void write_data_float(char *file_data, int N, int M, float *dat) {
  FILE *file = NULL;
  int i, j;
  file = fopen_write(file_data);
  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_float>:
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)
cmpq   $0x0,-0x20(%rbp)
jne    1188 <write_data_float+0x48>
mov    -0x8(%rbp),%rsi
lea    0xe7f(%rip),%rdi
xor    %edx,%edx
call   1060 <print_error_global@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    123e <write_data_float+0xfe>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ed <write_data_float+0xad>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe2d(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a2 <write_data_float+0x62>
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
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf2(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118f <write_data_float+0x4f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_data_float>:
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
call   1050 <fopen_write@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1183 <write_data_float+0x33>
test   %r12d,%r12d
jg     119d <write_data_float+0x4d>
jmp    1266 <write_data_float+0x116>
lea    0xe76(%rip),%rdi
mov    %rbp,%rsi
xor    %edx,%edx
call   1070 <print_error_global@plt>
test   %r12d,%r12d
jle    1266 <write_data_float+0x116>
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,4),%rax
mov    %rax,0x10(%rsp)
xor    %r14d,%r14d
lea    0xe35(%rip),%r12
mov    0x8(%rsp),%r13
jmp    1227 <write_data_float+0xd7>
nopw   0x0(%rax,%rax,1)
add    0x20(%rsp),%r14
mov    0x8(%rsp),%rax
movss  (%rax,%r14,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
lea    0xe0b(%rip),%rsi
mov    $0x1,%al
call   1060 <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     1266 <write_data_float+0x116>
mov    %r14,0x30(%rsp)
mov    0x28(%rsp),%rax
imul   %rax,%r14
cmp    $0x2,%eax
jl     11e0 <write_data_float+0x90>
xor    %ebp,%ebp
nopl   0x0(%rax)
movss  0x0(%r13,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1240 <write_data_float+0xf0>
jmp    11e0 <write_data_float+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 = [5 x i8] c"open\00"
@.str.1 = [4 x i8] c"%G \00"
@.str.2 = [3 x i8] c"%G\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @write_data_float(i8* %0, i32 %1, i32 %2, float* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca float*
%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 float* %3, float** %8
store i32* null, i32** %9
%12 = load i8*, i8** %5
%13 = call i32* @fopen_write(i8* %12)
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, 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 = %62, %19
%21 = load i32, i32* %10
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %65
24: ; preds = %20
store i32 0, i32* %11
br label %25
25: ; preds = %43, %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 %46
30: ; preds = %25
%31 = load i32*, i32** %9
%32 = load float*, float** %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 float, float* %32, i64 %38
%40 = load float, float* %39
%41 = fpext float %40 to double
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %41)
br label %43
43: ; preds = %30
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
br label %25
46: ; preds = %25
%47 = load i32*, i32** %9
%48 = load float*, float** %8
%49 = load i32, i32* %10
%50 = load i32, i32* %7
%51 = mul nsw i32 %49, %50
%52 = load i32, i32* %7
%53 = sub nsw i32 %52, 1
%54 = add nsw i32 %51, %53
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds float, float* %48, i64 %55
%57 = load float, float* %56
%58 = fpext float %57 to double
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double %58)
%60 = load i32*, i32** %9
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %46
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %20
65: ; preds = %20
%66 = load i32*, i32** %9
%67 = call i32 @fclose(i32* %66)
ret void
}

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