#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 EACCES;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(void) {
  FILE *passdb;
  if ((passdb = fopen("/etc/passwd", "w")) == NULL) {
    fprintf(stderr, "EACCES %d: %s\n", EACCES, strerror(EACCES));
    exit(EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b9 <main+0x79>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    %rax,%rcx
lea    0xe68(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     116b <main+0x2b>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e66(%rip),%rax
mov    (%rax),%ebx
mov    0x2e6d(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1060 <strerror@plt>
lea    0xe83(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/etc/passwd\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"EACCES %d: %s\0A\00"
@EACCES = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %13
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i32, i32* @EACCES
%8 = load i32, i32* @EACCES
%9 = call i8* @strerror(i32 %8)
%10 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* @EXIT_SUCCESS
ret i32 %14
}

LLVM IR (-O2):
@.str = [12 x i8] c"/etc/passwd\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"EACCES %d: %s\0A\00"
@EACCES = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %10
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = load i32, i32* @EACCES
%6 = tail call i8* @strerror(i32 %5)
%7 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %5, i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i32, i32* @EXIT_SUCCESS
ret i32 %11
}