#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
int writevectorf(char *file, double *beta, int p) {
  int i;
  FILE *out = NULL;
  if (!(out = fopen(file, "w"))) {
    fprintf(stderr, "can't open file %s\n", file);
    return 0;
  }
  for (i = 0; i < p; i++)
    fprintf(out, "%.10f\n", beta[i]);
  fflush(out);
  fclose(out);
  return 1;
}


x86 assembly (clang, -O0):
<writevectorf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a1 <writevectorf+0x61>
mov    0x2e60(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fa <writevectorf+0xba>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e1 <writevectorf+0xa1>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe4a(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a8 <writevectorf+0x68>
mov    -0x28(%rbp),%rdi
call   1050 <fflush@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writevectorf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b3 <writevectorf+0x73>
mov    %rax,%r12
test   %ebp,%ebp
jle    119c <writevectorf+0x5c>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xea3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%r14,%rbx,8),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <writevectorf+0x40>
mov    %r12,%rdi
call   1050 <fflush@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebx
jmp    11d0 <writevectorf+0x90>
mov    0x2e26(%rip),%rax
movslq (%rax),%rdi
lea    0xe3e(%rip),%rsi
xor    %ebx,%ebx
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"can't open file %s\0A\00"
@.str.2 = [7 x i8] c"%.10f\0A\00"
define i32 @writevectorf(i8* %0, double* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %22
8: ; preds = %6
%9 = zext i32 %2 to i64
br label %15
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %25
15: ; preds = %8, %15
%16 = phi i64 [ 0, %8 ], [ %20, %15 ]
%17 = getelementptr inbounds double, double* %1, i64 %16
%18 = load double, double* %17
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %18)
%20 = add nuw nsw i64 %16, 1
%21 = icmp eq i64 %20, %9
br i1 %21, label %22, label %15
22: ; preds = %15, %6
%23 = tail call i32 @fflush(i32* %4)
%24 = tail call i32 @fclose(i32* %4)
br label %25
25: ; preds = %22, %10
%26 = phi i32 [ 1, %22 ], [ 0, %10 ]
ret i32 %26
}