#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*/ error(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ lg(char *, char *);
void dappend_bin(char *fname, double *vec, int N) {
  int m;
  FILE *fp;
  lg("Appending to %s\n", fname);
  if (NULL == (fp = fopen(fname, "ab")))
    error("Cant append");
  if (N != fwrite(vec, sizeof(double), N, fp))
    error("Cant write");
  fclose(fp);
}


x86 assembly (clang, -O0):
<dappend_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe92(%rip),%rdi
call   1040 <lg@plt>
mov    -0x8(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11a1 <dappend_bin+0x51>
lea    0xe78(%rip),%rdi
call   1050 <error@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x8,%esi
call   1070 <fwrite@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
je     11d5 <dappend_bin+0x85>
lea    0xe50(%rip),%rdi
call   1050 <error@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dappend_bin>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe9d(%rip),%rdi
mov    %rbx,%rsi
call   1040 <lg@plt>
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118e <dappend_bin+0x3e>
lea    0xe8b(%rip),%rdi
call   1050 <error@plt>
mov    %r14,%rdi
mov    $0x8,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
cmp    %ebp,%eax
je     11b0 <dappend_bin+0x60>
lea    0xe75(%rip),%rdi
call   1050 <error@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Appending to %s\0A\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [12 x i8] c"Cant append\00"
@.str.3 = [11 x i8] c"Cant write\00"
define void @dappend_bin(i8* %0, double* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %4
store double* %1, double** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @lg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %8
%13 = icmp eq i32* null, %12
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %3
%17 = load i32, i32* %6
%18 = load double*, double** %5
%19 = load i32, i32* %6
%20 = load i32*, i32** %8
%21 = call i32 @fwrite(double* %18, i32 8, i32 %19, i32* %20)
%22 = icmp ne i32 %17, %21
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %16
%26 = load i32*, i32** %8
%27 = call i32 @fclose(i32* %26)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Appending to %s\0A\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [12 x i8] c"Cant append\00"
@.str.3 = [11 x i8] c"Cant write\00"
define void @dappend_bin(i8* %0, double* nocapture %1, i32 %2) {
%4 = tail call i32 @lg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
%10 = tail call i32 @fwrite(double* %1, i32 8, i32 %2, i32* %5)
%11 = icmp eq i32 %10, %2
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = tail call i32 @fclose(i32* %5)
ret void
}