#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 *, float);
void dump_memory_structure_dense_to_file(float *mem, int sh0) {
  FILE *out;
  int i;
  out = fopen("debug_c.txt", "w");
  for (i = 0; i < sh0; i++) {
    fprintf(out, "%.12lf\n", mem[i]);
  }
  fclose(out);
}


x86 assembly (clang, -O0):
<dump_memory_structure_dense_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1194 <dump_memory_structure_dense_to_file+0x64>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
lea    0xe8d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <dump_memory_structure_dense_to_file+0x2d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_memory_structure_dense_to_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xebc(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
test   %ebp,%ebp
jle    118a <dump_memory_structure_dense_to_file+0x5a>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xeac(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  (%r14,%rbx,4),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <dump_memory_structure_dense_to_file+0x40>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"debug_c.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [8 x i8] c"%.12lf\0A\00"
define void @dump_memory_structure_dense_to_file(float* %0, i32 %1) {
%3 = alloca float*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store float* %0, float** %3
store i32 %1, i32* %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
store i32 0, i32* %6
br label %8
8: ; preds = %20, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i32*, i32** %5
%14 = load float*, float** %3
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds float, float* %14, i64 %16
%18 = load float, float* %17
%19 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), float %18)
br label %20
20: ; preds = %12
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %8
23: ; preds = %8
%24 = load i32*, i32** %5
%25 = call i32 @fclose(i32* %24)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"debug_c.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [8 x i8] c"%.12lf\0A\00"
define void @dump_memory_structure_dense_to_file(float* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %12, %7 ]
%9 = getelementptr inbounds float, float* %0, i64 %8
%10 = load float, float* %9
%11 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), float %10)
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, %6
br i1 %13, label %14, label %7
14: ; preds = %7, %2
%15 = tail call i32 @fclose(i32* %3)
ret void
}