#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 S_IFCHR;
int /*<<< orphan*/ makedev(int, int /*<<< orphan*/);
scalar_t__ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int mbox_open() {
  int file_desc;
  file_desc = open("/dev/vcio", 0);
  if (file_desc >= 0) {
    return file_desc;
  }
  unlink("/tmp/mbox");
  if (mknod("/tmp/mbox", S_IFCHR | 0600, makedev(249, 0)) >= 0 &&
      (file_desc = open("/tmp/mbox", 0)) >= 0) {
    return file_desc;
  }
  unlink("/tmp/mbox");
  if (mknod("/tmp/mbox", S_IFCHR | 0600, makedev(100, 0)) >= 0 &&
      (file_desc = open("/tmp/mbox", 0)) >= 0) {
    return file_desc;
  }
  return -1;
}


x86 assembly (clang, -O0):
<mbox_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     116e <mbox_open+0x2e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <mbox_open+0x107>
lea    0xe95(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
or     $0x180,%eax
mov    %eax,-0xc(%rbp)
mov    $0xf9,%edi
xor    %esi,%esi
call   1060 <makedev@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe67(%rip),%rdi
call   1040 <mknod@plt>
cmp    $0x0,%rax
jl     11d7 <mbox_open+0x97>
lea    0xe51(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     11d7 <mbox_open+0x97>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <mbox_open+0x107>
lea    0xe2c(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
or     $0x180,%eax
mov    %eax,-0x10(%rbp)
mov    $0x64,%edi
xor    %esi,%esi
call   1060 <makedev@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xdfe(%rip),%rdi
call   1040 <mknod@plt>
cmp    $0x0,%rax
jl     1240 <mbox_open+0x100>
lea    0xde8(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     1240 <mbox_open+0x100>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <mbox_open+0x107>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mbox_open>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
test   %eax,%eax
js     1164 <mbox_open+0x24>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe9f(%rip),%r14
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    0x2e66(%rip),%r15
mov    $0x180,%ebx
mov    (%r15),%ebp
or     %ebx,%ebp
mov    $0xf9,%edi
xor    %esi,%esi
call   1060 <makedev@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <mknod@plt>
test   %rax,%rax
js     11b3 <mbox_open+0x73>
lea    0xe62(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
test   %eax,%eax
jns    1159 <mbox_open+0x19>
lea    0xe50(%rip),%rbp
mov    %rbp,%rdi
call   1030 <unlink@plt>
or     (%r15),%ebx
mov    $0x64,%edi
xor    %esi,%esi
call   1060 <makedev@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <mknod@plt>
test   %rax,%rax
js     11f8 <mbox_open+0xb8>
lea    0xe21(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
test   %eax,%eax
jns    1159 <mbox_open+0x19>
mov    $0xffffffff,%eax
jmp    1159 <mbox_open+0x19>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/vcio\00"
@.str.1 = [10 x i8] c"/tmp/mbox\00"
@S_IFCHR = global i32 0
define i32 @mbox_open() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp sge i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = load i32, i32* %2
store i32 %7, i32* %1
br label %33
8: ; preds = %0
%9 = call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @S_IFCHR
%11 = or i32 %10, 384
%12 = call i32 @makedev(i32 249, i32 0)
%13 = call i64 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
%14 = icmp sge i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %16, i32* %2
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i32, i32* %2
store i32 %19, i32* %1
br label %33
20: ; preds = %15, %8
%21 = call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @S_IFCHR
%23 = or i32 %22, 384
%24 = call i32 @makedev(i32 100, i32 0)
%25 = call i64 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24)
%26 = icmp sge i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %20
%28 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %28, i32* %2
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i32, i32* %2
store i32 %31, i32* %1
br label %33
32: ; preds = %27, %20
store i32 -1, i32* %1
br label %33
33: ; preds = %32, %30, %18, %6
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/vcio\00"
@.str.1 = [10 x i8] c"/tmp/mbox\00"
@S_IFCHR = global i32 0
define i32 @mbox_open() {
%1 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
%2 = icmp sgt i32 %1, -1
br i1 %2, label %24, label %3
3: ; preds = %0
%4 = tail call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @S_IFCHR
%6 = or i32 %5, 384
%7 = tail call i32 @makedev(i32 249, i32 0)
%8 = tail call i64 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %7)
%9 = icmp sgt i64 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 0)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %24, label %13
13: ; preds = %10, %3
%14 = tail call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @S_IFCHR
%16 = or i32 %15, 384
%17 = tail call i32 @makedev(i32 100, i32 0)
%18 = tail call i64 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
%19 = icmp sgt i64 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 0)
%22 = icmp sgt i32 %21, -1
br i1 %22, label %24, label %23
23: ; preds = %20, %13
br label %24
24: ; preds = %20, %10, %0, %23
%25 = phi i32 [ -1, %23 ], [ %1, %0 ], [ %11, %10 ], [ %21, %20 ]
ret i32 %25
}