#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, double);
void writeVector(char *outputFile, double *vector, int n) {
  char strElement[32];
  FILE *stream;
  int i;
  stream = fopen(outputFile, "wb");
  if (stream == NULL) {
    printf("Output stream is NULL. Program terminates.\n");
    exit(1);
  }
  for (i = 0; i < n; i++) {
    sprintf(strElement, "%f\n", vector[i]);
    if (fputs(strElement, stream) == EOF) {
      printf("fputc() returns NULL. Program terminates.\n");
      exit(1);
    }
  }
  fclose(stream);
}


x86 assembly (clang, -O0):
<writeVector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11a8 <writeVector+0x48>
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121e <writeVector+0xbe>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe5c(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1050 <fputs@plt>
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%rax
jne    120b <writeVector+0xab>
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1210 <writeVector+0xb0>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11af <writeVector+0x4f>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeVector>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
lea    0xe86(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11fa <writeVector+0x9a>
mov    %rax,%r12
test   %ebx,%ebx
jle    11ce <writeVector+0x6e>
mov    %ebx,%r13d
xor    %ebp,%ebp
mov    %rsp,%rbx
mov    0x2e4e(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsd  (%r14,%rbp,8),%xmm0
mov    %rbx,%rdi
lea    0xe53(%rip),%rsi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <fputs@plt>
cmp    (%r15),%rax
je     11e4 <writeVector+0x84>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    11a0 <writeVector+0x40>
mov    %r12,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe30(%rip),%rdi
jmp    11eb <writeVector+0x8b>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [44 x i8] c"Output stream is NULL. Program terminates.\0A\00"
@.str.2 = [4 x i8] c"%f\0A\00"
@EOF = global i64 0
@.str.3 = [43 x i8] c"fputc() returns NULL. Program terminates.\0A\00"
define void @writeVector(i8* %0, double* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32
%7 = alloca [32 x i8]
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %4
store double* %1, double** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
store i32 0, i32* %9
br label %18
18: ; preds = %39, %17
%19 = load i32, i32* %9
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %42
22: ; preds = %18
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%24 = load double*, double** %5
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
%29 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %28)
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%31 = load i32*, i32** %8
%32 = call i64 @fputs(i8* %30, i32* %31)
%33 = load i64, i64* @EOF
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %22
%36 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %22
br label %39
39: ; preds = %38
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %18
42: ; preds = %18
%43 = load i32*, i32** %8
%44 = call i32 @fclose(i32* %43)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.2 = [4 x i8] c"%f\0A\00"
@EOF = global i64 0
@str = [42 x i8] c"fputc() returns NULL. Program terminates.\00"
@str.4 = [43 x i8] c"Output stream is NULL. Program terminates.\00"
define void @writeVector(i8* nocapture %0, double* nocapture %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %29
10: ; preds = %8
%11 = zext i32 %2 to i64
br label %17
12: ; preds = %3
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.4, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %17
%16 = icmp eq i64 %25, %11
br i1 %16, label %29, label %17
17: ; preds = %10, %15
%18 = phi i64 [ 0, %10 ], [ %25, %15 ]
%19 = getelementptr inbounds double, double* %1, i64 %18
%20 = load double, double* %19
%21 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %20)
%22 = call i64 @fputs(i8* %5, i32* %6)
%23 = load i64, i64* @EOF
%24 = icmp eq i64 %22, %23
%25 = add nuw nsw i64 %18, 1
br i1 %24, label %26, label %15
26: ; preds = %17
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %15, %8
%30 = tail call i32 @fclose(i32* %6)
ret void
}