#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 O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ errno;
int open(char const *, int);
int /*<<< orphan*/ printf(char *, char const *);
char *strerror(int /*<<< orphan*/);
int myOpen(const char *device) {
  printf("myOpen: Device Path: %s\n", device);
  int fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    printf("myOpen: fail: %s\n", strerror(errno));
  }
  return fd;
}


x86 assembly (clang, -O0):
<myOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    0x2e78(%rip),%rax
or     (%rax),%esi
mov    0x2e5f(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    119a <myOpen+0x6a>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myOpen>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e9e(%rip),%rax
mov    0x2e87(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6c(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    118a <myOpen+0x5a>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe97(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"myOpen: Device Path: %s\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [18 x i8] c"myOpen: fail: %s\0A\00"
@errno = global i32 0
define i32 @myOpen(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = load i8*, i8** %2
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NOCTTY
%9 = or i32 %7, %8
%10 = load i32, i32* @O_NDELAY
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %6, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %15, %1
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [25 x i8] c"myOpen: Device Path: %s\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [18 x i8] c"myOpen: fail: %s\0A\00"
@errno = global i32 0
define i32 @myOpen(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %4, %3
%6 = load i32, i32* @O_NDELAY
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %10, %1
ret i32 %8
}