#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*/ printf(char *, ...);
int /*<<< orphan*/ unlink(char *);
int mbox_open() {
  int file_desc;
  file_desc = open("/dev/vcio", 0);
  if (file_desc >= 0) {
    printf("Using mbox device "
           "/dev/vcio"
           ".\n");
    return file_desc;
  }
  unlink("mbox");
  if (mknod("mbox", S_IFCHR | 0600, makedev(249, 0)) >= 0 &&
      (file_desc = open("mbox", 0)) >= 0) {
    printf("Using local mbox device file with major %d.\n", 249);
    return file_desc;
  }
  unlink("mbox");
  if (mknod("mbox", S_IFCHR | 0600, makedev(100, 0)) >= 0 &&
      (file_desc = open("mbox", 0)) >= 0) {
    printf("Using local mbox device file with major %d.\n", 100);
    return file_desc;
  }
  return -1;
}


x86 assembly (clang, -O0):
<mbox_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     118c <mbox_open+0x3c>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128b <mbox_open+0x13b>
lea    0xe95(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
or     $0x180,%eax
mov    %eax,-0xc(%rbp)
mov    $0xf9,%edi
xor    %esi,%esi
call   1070 <makedev@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe67(%rip),%rdi
call   1050 <mknod@plt>
cmp    $0x0,%rax
jl     1208 <mbox_open+0xb8>
lea    0xe51(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     1208 <mbox_open+0xb8>
lea    0xe3c(%rip),%rdi
mov    $0xf9,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128b <mbox_open+0x13b>
lea    0xe19(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
or     $0x180,%eax
mov    %eax,-0x10(%rbp)
mov    $0x64,%edi
xor    %esi,%esi
call   1070 <makedev@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xdeb(%rip),%rdi
call   1050 <mknod@plt>
cmp    $0x0,%rax
jl     1284 <mbox_open+0x134>
lea    0xdd5(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     1284 <mbox_open+0x134>
lea    0xdc0(%rip),%rdi
mov    $0x64,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128b <mbox_open+0x13b>
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    0xe92(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
js     1194 <mbox_open+0x34>
mov    %eax,%ebx
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe6f(%rip),%r14
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    0x2e36(%rip),%r15
mov    $0x180,%ebp
mov    (%r15),%ebx
or     %ebp,%ebx
mov    $0xf9,%edi
xor    %esi,%esi
call   1080 <makedev@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1060 <mknod@plt>
test   %rax,%rax
js     11fa <mbox_open+0x9a>
lea    0xe32(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
js     11fa <mbox_open+0x9a>
mov    %eax,%ebx
lea    0xe23(%rip),%rdi
mov    $0xf9,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1187 <mbox_open+0x27>
lea    0xe09(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
or     (%r15),%ebp
mov    $0x64,%edi
xor    %esi,%esi
call   1080 <makedev@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1060 <mknod@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     1187 <mbox_open+0x27>
lea    0xdd1(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
js     1187 <mbox_open+0x27>
mov    %eax,%ebp
lea    0xdbe(%rip),%rdi
mov    $0x64,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%ebx
jmp    1187 <mbox_open+0x27>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/vcio\00"
@.str.1 = [30 x i8] c"Using mbox device /dev/vcio.\0A\00"
@.str.2 = [5 x i8] c"mbox\00"
@S_IFCHR = global i32 0
@.str.3 = [45 x i8] c"Using local mbox device file with major %d.\0A\00"
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 %9
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* %2
store i32 %8, i32* %1
br label %36
9: ; preds = %0
%10 = call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @S_IFCHR
%12 = or i32 %11, 384
%13 = call i32 @makedev(i32 249, i32 0)
%14 = call i64 @mknod(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %13)
%15 = icmp sge i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %9
%17 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32 %17, i32* %2
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 249)
%21 = load i32, i32* %2
store i32 %21, i32* %1
br label %36
22: ; preds = %16, %9
%23 = call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @S_IFCHR
%25 = or i32 %24, 384
%26 = call i32 @makedev(i32 100, i32 0)
%27 = call i64 @mknod(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %26)
%28 = icmp sge i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %22
%30 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32 %30, i32* %2
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 100)
%34 = load i32, i32* %2
store i32 %34, i32* %1
br label %36
35: ; preds = %29, %22
store i32 -1, i32* %1
br label %36
36: ; preds = %35, %32, %19, %6
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/vcio\00"
@.str.2 = [5 x i8] c"mbox\00"
@S_IFCHR = global i32 0
@.str.3 = [45 x i8] c"Using local mbox device file with major %d.\0A\00"
@str = [29 x i8] c"Using mbox device /dev/vcio.\00"
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 %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %29
5: ; preds = %0
%6 = tail call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* @S_IFCHR
%8 = or i32 %7, 384
%9 = tail call i32 @makedev(i32 249, i32 0)
%10 = tail call i64 @mknod(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %9)
%11 = icmp sgt i64 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %5
%13 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0)
%14 = icmp sgt i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 249)
br label %29
17: ; preds = %12, %5
%18 = tail call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @S_IFCHR
%20 = or i32 %19, 384
%21 = tail call i32 @makedev(i32 100, i32 0)
%22 = tail call i64 @mknod(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %21)
%23 = icmp sgt i64 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0)
%26 = icmp sgt i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 100)
br label %29
29: ; preds = %17, %24, %27, %15, %3
%30 = phi i32 [ %1, %3 ], [ %13, %15 ], [ %25, %27 ], [ -1, %24 ], [ -1, %17 ]
ret i32 %30
}