#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int O_APPEND;
int O_CREAT;
int O_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int open(char const *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int OpenFileAppend(const char *filename) {
  int fd;
  fd = open(filename, O_RDWR | O_CREAT | O_APPEND,
            S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  if (fd < 0) {
    fprintf(stderr, "Cannot open file '%s' for appending [%s].\n", filename,
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  return (fd);
}


x86 assembly (clang, -O0):
<OpenFileAppend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e98(%rip),%rax
or     (%rax),%esi
mov    0x2e27(%rip),%rax
or     (%rax),%esi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
mov    0x2e5d(%rip),%rax
or     (%rax),%edx
mov    0x2e34(%rip),%rax
or     (%rax),%edx
mov    0x2e23(%rip),%rax
or     (%rax),%edx
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11e7 <OpenFileAppend+0xa7>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe2c(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OpenFileAppend>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e96(%rip),%rax
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e34(%rip),%rax
or     (%rax),%esi
mov    0x2e3b(%rip),%rax
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e41(%rip),%rax
or     (%rax),%edx
mov    %rdi,%rbx
mov    0x2e2d(%rip),%rax
or     (%rax),%edx
call   1040 <open@plt>
test   %eax,%eax
js     1195 <OpenFileAppend+0x55>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e2c(%rip),%rax
mov    (%rax),%ebp
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe4d(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Cannot open file '%s' for appending [%s].\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @OpenFileAppend(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = load i32, i32* @O_APPEND
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRGRP
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IROTH
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %4, i32 %9, i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %1
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %2
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %1
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Cannot open file '%s' for appending [%s].\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @OpenFileAppend(i8* %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_APPEND
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IROTH
%13 = or i32 %11, %12
%14 = tail call i32 @open(i8* %0, i32 %6, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %1
ret i32 %14
}