#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 */
struct evemu_device {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int errno;
char *evemu_get_devnode(struct evemu_device *);
char *evemu_get_name(struct evemu_device *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int);
int open_evemu_device(struct evemu_device *dev) {
  int fd;
  const char *device_node = evemu_get_devnode(dev);
  if (!device_node) {
    fprintf(stderr, "can not determine device node\n");
    return -1;
  }
  fd = open(device_node, O_RDWR);
  if (fd < 0) {
    fprintf(stderr, "error %d opening %s: %s\n", errno, device_node,
            strerror(errno));
    return -1;
  }
  fprintf(stdout, "%s: %s\n", evemu_get_name(dev), device_node);
  fflush(stdout);
  return fd;
}


x86 assembly (clang, -O0):
<open_evemu_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <evemu_get_devnode@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a7 <open_evemu_device+0x47>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125c <open_evemu_device+0xfc>
mov    -0x20(%rbp),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    121b <open_evemu_device+0xbb>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    %rax,%r8
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125c <open_evemu_device+0xfc>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <evemu_get_name@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
mov    -0x20(%rbp),%rcx
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_evemu_device>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
call   1030 <evemu_get_devnode@plt>
test   %rax,%rax
je     11c4 <open_evemu_device+0x64>
mov    %rax,%r14
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11dd <open_evemu_device+0x7d>
mov    %eax,%ebp
mov    0x2e32(%rip),%r12
mov    (%r12),%r15d
mov    %rbx,%rdi
call   1070 <evemu_get_name@plt>
lea    0xe87(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r12),%edi
call   1050 <fflush@plt>
jmp    1213 <open_evemu_device+0xb3>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    120e <open_evemu_device+0xae>
mov    0x2df4(%rip),%rax
mov    (%rax),%ebx
mov    0x2de3(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe22(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.evemu_device = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"can not determine device node\0A\00"
@O_RDWR = global i32 0
@.str.1 = [25 x i8] c"error %d opening %s: %s\0A\00"
@errno = global i32 0
@stdout = global i32 0
@.str.2 = [8 x i8] c"%s: %s\0A\00"
define i32 @open_evemu_device(%struct.evemu_device* %0) {
%2 = alloca i32
%3 = alloca %struct.evemu_device*
%4 = alloca i32
%5 = alloca i8*
store %struct.evemu_device* %0, %struct.evemu_device** %3
%6 = load %struct.evemu_device*, %struct.evemu_device** %3
%7 = call i8* @evemu_get_devnode(%struct.evemu_device* %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %35
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = load i8*, i8** %5
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %21, i8* %22, i8* %24)
store i32 -1, i32* %2
br label %35
26: ; preds = %13
%27 = load i32, i32* @stdout
%28 = load %struct.evemu_device*, %struct.evemu_device** %3
%29 = call i8* @evemu_get_name(%struct.evemu_device* %28)
%30 = load i8*, i8** %5
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %30)
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
%34 = load i32, i32* %4
store i32 %34, i32* %2
br label %35
35: ; preds = %26, %19, %10
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
%struct.evemu_device = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"can not determine device node\0A\00"
@O_RDWR = global i32 0
@.str.1 = [25 x i8] c"error %d opening %s: %s\0A\00"
@errno = global i32 0
@stdout = global i32 0
@.str.2 = [8 x i8] c"%s: %s\0A\00"
define i32 @open_evemu_device(%struct.evemu_device* %0) {
%2 = tail call i8* @evemu_get_devnode(%struct.evemu_device* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %22
7: ; preds = %1
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* %2, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %2, i8* %14)
br label %22
16: ; preds = %7
%17 = load i32, i32* @stdout
%18 = tail call i8* @evemu_get_name(%struct.evemu_device* %0)
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* %2)
%20 = load i32, i32* @stdout
%21 = tail call i32 @fflush(i32 %20)
br label %22
22: ; preds = %16, %11, %4
%23 = phi i32 [ -1, %11 ], [ %9, %16 ], [ -1, %4 ]
ret i32 %23
}