#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*/ va_list;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ lll_vfprint(int /*<<< orphan*/ *, char const *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void lll_vpprint(const char *path, const char *template, va_list va_ptr) {
  FILE *stream;
  stream = fopen(path, "a");
  if (stream != NULL) {
    lll_vfprint(stream, template, va_ptr);
    fclose(stream);
  } else {
    fprintf(stderr, "Failed to open %s in append mode", path);
    perror(" ");
  }
}


x86 assembly (clang, -O0):
<lll_vpprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a0 <lll_vpprint+0x50>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <lll_vfprint@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11c5 <lll_vpprint+0x75>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe4e(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe63(%rip),%rdi
call   1070 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lll_vpprint>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1194 <lll_vpprint+0x44>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <lll_vfprint@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
lea    0xe70(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <perror@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Failed to open %s in append mode\00"
@.str.2 = [2 x i8] c" \00"
define void @lll_vpprint(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%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** %7
%10 = load i32*, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %19
12: ; preds = %3
%13 = load i32*, i32** %7
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = call i32 @lll_vfprint(i32* %13, i8* %14, i32 %15)
%17 = load i32*, i32** %7
%18 = call i32 @fclose(i32* %17)
br label %24
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %4
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %19, %12
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Failed to open %s in append mode\00"
@.str.2 = [2 x i8] c" \00"
define void @lll_vpprint(i8* %0, i8* %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 %9, label %6
6: ; preds = %3
%7 = tail call i32 @lll_vfprint(i32* %4, i8* %1, i32 %2)
%8 = tail call i32 @fclose(i32* %4)
br label %13
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = tail call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %9, %6
ret void
}