#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 const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void write_file(float *img, const char *file_name) {
  FILE *fout = fopen(file_name, "w");
  int i, j;
  for (i = 0; i < 512; ++i) {
    for (j = 0; j < 512; ++j)
      fprintf(fout, "%f ", img[i * 512 + j]);
    fprintf(fout, "\n");
  }
  fclose(fout);
}


x86 assembly (clang, -O0):
<write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x200,-0x1c(%rbp)
jge    11d5 <write_file+0xa5>
movl   $0x0,-0x20(%rbp)
cmpl   $0x200,-0x20(%rbp)
jge    11b5 <write_file+0x85>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x9,%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe62(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116f <write_file+0x3f>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <write_file+0x2b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rax
mov    %rdi,%r13
lea    0xeaa(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
xor    %r12d,%r12d
lea    0xe97(%rip),%r15
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  0x0(%r13,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    $0x200,%rbx
jne    1180 <write_file+0x40>
mov    $0xa,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
add    $0x1,%r12
add    $0x800,%r13
cmp    $0x200,%r12
jne    1170 <write_file+0x30>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%f \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @write_file(float* %0, i8* %1) {
%3 = alloca float*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store float* %0, float** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
store i32 0, i32* %6
br label %10
10: ; preds = %35, %2
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 512
br i1 %12, label %13, label %38
13: ; preds = %10
store i32 0, i32* %7
br label %14
14: ; preds = %29, %13
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 512
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = load i32*, i32** %5
%19 = load float*, float** %3
%20 = load i32, i32* %6
%21 = mul nsw i32 %20, 512
%22 = load i32, i32* %7
%23 = add nsw i32 %21, %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds float, float* %19, i64 %24
%26 = load float, float* %25
%27 = fpext float %26 to double
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %27)
br label %29
29: ; preds = %17
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %14
32: ; preds = %14
%33 = load i32*, i32** %5
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %32
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %10
38: ; preds = %10
%39 = load i32*, i32** %5
%40 = call i32 @fclose(i32* %39)
ret void
}

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