#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 */
typedef int mode_t;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int S_IFCHR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXUSR;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ tun_gnu_dev_makedev(int, int);
bool tun_create_dev(void) {
  mode_t mask =
      S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
  if (!(access("/dev/net", F_OK) == 0) && ((0) != mkdir("/dev/net", mask))) {
    return false;
  }
  if ((0) != mknod("/dev/net/tun", S_IFCHR | S_IRUSR | S_IWUSR,
                   tun_gnu_dev_makedev(10, 200))) {
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<tun_create_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    0x2e80(%rip),%rcx
or     (%rcx),%eax
mov    0x2e87(%rip),%rcx
or     (%rcx),%eax
mov    0x2e56(%rip),%rcx
or     (%rcx),%eax
mov    0x2e6d(%rip),%rcx
or     (%rcx),%eax
mov    0x2e3c(%rip),%rcx
or     (%rcx),%eax
mov    0x2e1b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    0xe66(%rip),%rdi
call   1060 <access@plt>
cmp    $0x0,%rax
je     11d0 <tun_create_dev+0x90>
mov    -0x8(%rbp),%esi
lea    0xe4d(%rip),%rdi
call   1030 <mkdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     11d0 <tun_create_dev+0x90>
movl   $0x0,-0x4(%rbp)
jmp    122d <tun_create_dev+0xed>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    0x2dd0(%rip),%rcx
or     (%rcx),%eax
mov    0x2def(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xc(%rbp)
mov    $0xa,%edi
mov    $0xc8,%esi
call   1040 <tun_gnu_dev_makedev@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe00(%rip),%rdi
call   1050 <mknod@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1226 <tun_create_dev+0xe6>
movl   $0x0,-0x4(%rbp)
jmp    122d <tun_create_dev+0xed>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tun_create_dev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e79(%rip),%rax
mov    (%rax),%ebx
mov    0x2e80(%rip),%rax
mov    (%rax),%ebp
mov    0x2e4f(%rip),%rax
mov    (%rax),%r13d
mov    0x2e65(%rip),%rax
mov    (%rax),%r14d
mov    0x2e33(%rip),%rax
mov    (%rax),%r15d
mov    0x2e11(%rip),%rax
mov    (%rax),%r12d
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
je     11d4 <tun_create_dev+0x94>
or     0x4(%rsp),%ebx
or     %ebp,%ebx
or     %r13d,%ebx
or     %r14d,%ebx
or     %r15d,%ebx
or     %r12d,%ebx
lea    0xe3b(%rip),%rdi
mov    %ebx,%esi
call   1030 <mkdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    1217 <tun_create_dev+0xd7>
mov    0x2ded(%rip),%rax
mov    0x2dce(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2deb(%rip),%rax
or     (%rax),%ebx
mov    $0xa,%edi
mov    $0xc8,%esi
call   1040 <tun_gnu_dev_makedev@plt>
lea    0xe04(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <mknod@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str = [9 x i8] c"/dev/net\00"
@F_OK = global i32 0
@.str.1 = [13 x i8] c"/dev/net/tun\00"
@S_IFCHR = global i32 0
define i32 @tun_create_dev() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @S_IRUSR
%4 = load i32, i32* @S_IWUSR
%5 = or i32 %3, %4
%6 = load i32, i32* @S_IXUSR
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRGRP
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IWGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IROTH
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IWOTH
%15 = or i32 %13, %14
store i32 %15, i32* %2
%16 = load i32, i32* @F_OK
%17 = call i64 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %0
%20 = load i32, i32* %2
%21 = call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = icmp ne i32 0, %21
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 0, i32* %1
br label %35
24: ; preds = %19, %0
%25 = load i32, i32* @S_IFCHR
%26 = load i32, i32* @S_IRUSR
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IWUSR
%29 = or i32 %27, %28
%30 = call i32 @tun_gnu_dev_makedev(i32 10, i32 200)
%31 = call i32 @mknod(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %30)
%32 = icmp ne i32 0, %31
br i1 %32, label %33, label %34
33: ; preds = %24
store i32 0, i32* %1
br label %35
34: ; preds = %24
store i32 1, i32* %1
br label %35
35: ; preds = %34, %33, %23
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str = [9 x i8] c"/dev/net\00"
@F_OK = global i32 0
@.str.1 = [13 x i8] c"/dev/net/tun\00"
@S_IFCHR = global i32 0
define i32 @tun_create_dev() {
%1 = load i32, i32* @S_IRUSR
%2 = load i32, i32* @S_IWUSR
%3 = load i32, i32* @S_IXUSR
%4 = load i32, i32* @S_IRGRP
%5 = load i32, i32* @S_IWGRP
%6 = load i32, i32* @S_IROTH
%7 = load i32, i32* @S_IWOTH
%8 = load i32, i32* @F_OK
%9 = tail call i64 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %0
%12 = or i32 %2, %1
%13 = or i32 %12, %3
%14 = or i32 %13, %4
%15 = or i32 %14, %5
%16 = or i32 %15, %6
%17 = or i32 %16, %7
%18 = tail call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %11, %0
%21 = load i32, i32* @S_IFCHR
%22 = load i32, i32* @S_IRUSR
%23 = or i32 %22, %21
%24 = load i32, i32* @S_IWUSR
%25 = or i32 %23, %24
%26 = tail call i32 @tun_gnu_dev_makedev(i32 10, i32 200)
%27 = tail call i32 @mknod(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %26)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %20, %11
%31 = phi i32 [ 0, %11 ], [ %29, %20 ]
ret i32 %31
}