#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*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, float);
void dump_result(float *f, int nx, int ny, int nz, char *out_path) {
  FILE *out = fopen(out_path, "w");
  assert(out);
  size_t nitems = nx * ny * nz;
  int i;
  for (i = 0; i < nitems; ++i) {
    fprintf(out, "%f\n", f[i]);
  }
  fclose(out);
}


x86 assembly (clang, -O0):
<dump_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <assert@plt>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    11c7 <dump_result+0x87>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
lea    0xe4e(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118e <dump_result+0x4e>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_result>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xea3(%rip),%rsi
mov    %r8,%rdi
call   1060 <fopen@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <assert@plt>
imul   %r12d,%ebp
imul   %r15d,%ebp
test   %ebp,%ebp
je     11aa <dump_result+0x6a>
movslq %ebp,%rbp
xor    %ebx,%ebx
lea    0xe7a(%rip),%r15
nopl   0x0(%rax,%rax,1)
movss  (%r14,%rbx,4),%xmm0
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <dump_result+0x50>
mov    %r13,%rdi
add    $0x8,%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 = [4 x i8] c"%f\0A\00"
define void @dump_result(float* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca float*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i64
%13 = alloca i32
store float* %0, float** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%14 = load i8*, i8** %10
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %11
%16 = load i32*, i32** %11
%17 = call i32 @assert(i32* %16)
%18 = load i32, i32* %7
%19 = load i32, i32* %8
%20 = mul nsw i32 %18, %19
%21 = load i32, i32* %9
%22 = mul nsw i32 %20, %21
%23 = sext i32 %22 to i64
store i64 %23, i64* %12
store i32 0, i32* %13
br label %24
24: ; preds = %37, %5
%25 = load i32, i32* %13
%26 = sext i32 %25 to i64
%27 = load i64, i64* %12
%28 = icmp ult i64 %26, %27
br i1 %28, label %29, label %40
29: ; preds = %24
%30 = load i32*, i32** %11
%31 = load float*, float** %6
%32 = load i32, i32* %13
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds float, float* %31, i64 %33
%35 = load float, float* %34
%36 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), float %35)
br label %37
37: ; preds = %29
%38 = load i32, i32* %13
%39 = add nsw i32 %38, 1
store i32 %39, i32* %13
br label %24
40: ; preds = %24
%41 = load i32*, i32** %11
%42 = call i32 @fclose(i32* %41)
ret void
}

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