#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 *, double);
void write_file(double *sig, int length, char *name) {
  FILE *f;
  f = fopen(name, "w+");
  int i = 0;
  for (i = 0; i < length; i++) {
    fprintf(f, "%f ", sig[i]);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119c <write_file+0x6c>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe7a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1165 <write_file+0x35>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xebc(%rip),%rsi
mov    %rdx,%rdi
call   1050 <fopen@plt>
mov    %rax,%r12
test   %ebp,%ebp
jle    117a <write_file+0x4a>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xea5(%rip),%r15
xchg   %ax,%ax
movsd  (%r14,%rbx,8),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <write_file+0x30>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

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