#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
extern int Open(const char *path, int flags, ...) {
  int fd;
  if ((fd = open(path, flags, 0700)) < 0) {
    perror("open file error");
    fprintf(stderr, "path was %s\n", path);
    fprintf(stderr, "flags were %d\n", flags);
    exit(7);
  }
  return fd;
}


x86 assembly (clang, -O0):
<Open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x1c0,%edx
call   1040 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11b7 <Open+0x77>
lea    0xe8d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x7,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Open>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x1c0,%edx
call   1040 <open@plt>
test   %eax,%eax
js     115c <Open+0x1c>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe9d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e71(%rip),%r14
mov    (%r14),%edi
lea    0xe97(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
lea    0xe90(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x7,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"open file error\00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"path was %s\0A\00"
@.str.2 = [15 x i8] c"flags were %d\0A\00"
define i32 @Open(i8* %0, i32 %1, ...) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = call i32 @open(i8* %6, i32 %7, i32 448)
store i32 %8, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @stderr
%16 = load i32, i32* %4
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = call i32 @exit(i32 7)
unreachable
19: ; preds = %2
%20 = load i32, i32* %5
ret i32 %20
}

LLVM IR (-O2):
@.str = [16 x i8] c"open file error\00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"path was %s\0A\00"
@.str.2 = [15 x i8] c"flags were %d\0A\00"
define i32 @Open(i8* %0, i32 %1, ...) {
%3 = tail call i32 @open(i8* %0, i32 %1, i32 448)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%11 = tail call i32 @exit(i32 7)
unreachable
12: ; preds = %2
ret i32 %3
}