#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 */
scalar_t__ EBUSY;
int O_EXCL;
int O_RDWR;
scalar_t__ errno;
int /*<<< orphan*/ error_reason(char *);
int open(char const *, int);
char *strerror(scalar_t__);
int misc_open_exclusive(const char *filename) {
  int fd;
  fd = open(filename, O_RDWR | O_EXCL);
  if (fd == -1 && errno == EBUSY)
    error_reason("Device is in use (probably mounted)");
  else if (fd == -1)
    error_reason(strerror(errno));
  return fd;
}


x86 assembly (clang, -O0):
<misc_open_exclusive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
mov    0x2e88(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    118f <misc_open_exclusive+0x5f>
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%rax
jne    118f <misc_open_exclusive+0x5f>
lea    0xe7b(%rip),%rdi
call   1030 <error_reason@plt>
jmp    11b5 <misc_open_exclusive+0x85>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b0 <misc_open_exclusive+0x80>
mov    0x2e30(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,%rdi
call   1030 <error_reason@plt>
jmp    11b5 <misc_open_exclusive+0x85>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<misc_open_exclusive>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117b <misc_open_exclusive+0x4b>
mov    0x2e7a(%rip),%rax
mov    (%rax),%rdi
mov    0x2e68(%rip),%rax
cmp    (%rax),%rdi
jne    116e <misc_open_exclusive+0x3e>
lea    0xe94(%rip),%rdi
jmp    1176 <misc_open_exclusive+0x46>
call   1050 <strerror@plt>
mov    %rax,%rdi
call   1030 <error_reason@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@errno = global i64 0
@EBUSY = global i64 0
@.str = [36 x i8] c"Device is in use (probably mounted)\00"
define i32 @misc_open_exclusive(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_EXCL
%7 = or i32 %5, %6
%8 = call i32 @open(i8* %4, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = load i64, i64* @EBUSY
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @error_reason(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %25
17: ; preds = %11, %1
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i64, i64* @errno
%22 = call i8* @strerror(i64 %21)
%23 = call i32 @error_reason(i8* %22)
br label %24
24: ; preds = %20, %17
br label %25
25: ; preds = %24, %15
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@errno = global i64 0
@EBUSY = global i64 0
@.str = [36 x i8] c"Device is in use (probably mounted)\00"
define i32 @misc_open_exclusive(i8* nocapture %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_EXCL
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = load i64, i64* @errno
%9 = load i64, i64* @EBUSY
%10 = icmp eq i64 %8, %9
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i8* @strerror(i64 %8)
br label %13
13: ; preds = %7, %11
%14 = phi i8* [ %12, %11 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), %7 ]
%15 = tail call i32 @error_reason(i8* %14)
br label %16
16: ; preds = %13, %1
ret i32 %5
}