#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_RDWR;
int O_SYNC;
int open(char const *, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int drvOCM_OpenDev(const char *dev) {
  int fd = 0;
  fd = open(dev, O_RDWR | O_SYNC);
  if (fd < 0) {
    printf("%s Can't Open %s\n", "[drvOCM]", dev);
    return -1;
  } else {
    printf("%s Open %s Success \n", "[drvOCM]", dev);
    printf("%s fd is : %d\n", "[drvOCM]", fd);
    return fd;
  }
}


x86 assembly (clang, -O0):
<drvOCM_OpenDev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1180 <drvOCM_OpenDev+0x60>
mov    -0x10(%rbp),%rdx
lea    0xe9a(%rip),%rdi
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <drvOCM_OpenDev+0x97>
mov    -0x10(%rbp),%rdx
lea    0xe90(%rip),%rdi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edx
lea    0xe8d(%rip),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drvOCM_OpenDev>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2eba(%rip),%rax
mov    0x2eab(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1040 <open@plt>
test   %eax,%eax
js     1174 <drvOCM_OpenDev+0x54>
mov    %eax,%ebp
lea    0xed0(%rip),%rdi
lea    0xec0(%rip),%r14
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1191 <drvOCM_OpenDev+0x71>
lea    0xe85(%rip),%rdi
lea    0xe90(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str = [18 x i8] c"%s Can't Open %s\0A\00"
@.str.1 = [9 x i8] c"[drvOCM]\00"
@.str.2 = [21 x i8] c"%s Open %s Success \0A\00"
@.str.3 = [15 x i8] c"%s fd is : %d\0A\00"
define i32 @drvOCM_OpenDev(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%5 = load i8*, i8** %3
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_SYNC
%8 = or i32 %6, %7
%9 = call i32 @open(i8* %5, i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 -1, i32* %2
br label %21
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %4
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %21
21: ; preds = %15, %12
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str = [18 x i8] c"%s Can't Open %s\0A\00"
@.str.1 = [9 x i8] c"[drvOCM]\00"
@.str.2 = [21 x i8] c"%s Open %s Success \0A\00"
@.str.3 = [15 x i8] c"%s fd is : %d\0A\00"
define i32 @drvOCM_OpenDev(i8* %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_SYNC
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %12
9: ; preds = %1
%10 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ -1, %7 ], [ %5, %9 ]
ret i32 %13
}