#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_CLOEXEC;
int O_RDWR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int open(char const *, int);
int /*<<< orphan*/ stderr;
int create_and_open_dev(const char *path, const char *name, const int minor) {
  int fd;
  fd = open(path, O_RDWR | O_CLOEXEC);
  if (fd < 0) {
    fprintf(stderr, "create_and_open_dev: Unable to open device %s", path);
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<create_and_open_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
mov    0x2e81(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1180 <create_and_open_dev+0x60>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe91(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1186 <create_and_open_dev+0x66>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_and_open_dev>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ebd(%rip),%rax
mov    0x2e96(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1040 <open@plt>
test   %eax,%eax
js     1141 <create_and_open_dev+0x21>
pop    %rbx
ret
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CLOEXEC = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"create_and_open_dev: Unable to open device %s\00"
define i32 @create_and_open_dev(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CLOEXEC
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %9, i32 %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %5
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %4
br label %22
20: ; preds = %3
%21 = load i32, i32* %8
store i32 %21, i32* %4
br label %22
22: ; preds = %20, %16
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CLOEXEC = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"create_and_open_dev: Unable to open device %s\00"
define i32 @create_and_open_dev(i8* %0, i8* nocapture readnone %1, i32 %2) {
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CLOEXEC
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %3, %9
%13 = phi i32 [ -1, %9 ], [ %7, %3 ]
ret i32 %13
}