#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 IFF_NO_PI;
int IFF_TUN;
int IFNAMSIZ;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char const *);
int tun_alloc(char *, int);
int init_tun() {
  int tun_fd = 0;
  char tun_name[IFNAMSIZ];
  const char *command;
  command = "ip tuntap add dev tun0 mode tun user root";
  system(command);
  command = "ip link set tun0 up";
  system(command);
  command = "ip -6 addr add BBBB:0000:0000:0000::1/64 dev tun0";
  system(command);
  command = "ip -6 addr add fe80::1/64 dev tun0";
  system(command);
  strcpy(tun_name, "tun0");
  tun_fd = tun_alloc(tun_name, IFF_TUN | IFF_NO_PI);
  if (tun_fd < 0) {
    return -1;
  }
  return tun_fd;
}


x86 assembly (clang, -O0):
<init_tun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x8(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
lea    0xe8e(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
lea    0xea4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
lea    0xea4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
lea    0xec2(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
mov    -0x30(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
mov    0x2de9(%rip),%rax
or     (%rax),%esi
call   1050 <tun_alloc@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1206 <init_tun+0xd6>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    1213 <init_tun+0xe3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_tun>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xea9(%rip),%rdi
call   1040 <system@plt>
lea    0xec7(%rip),%rdi
call   1040 <system@plt>
lea    0xecf(%rip),%rdi
call   1040 <system@plt>
lea    0xef5(%rip),%rdi
call   1040 <system@plt>
lea    0xee4(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    0x2e42(%rip),%rax
mov    0x2e2b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1050 <tun_alloc@plt>
test   %eax,%eax
mov    $0xffffffff,%ecx
cmovs  %ecx,%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@IFNAMSIZ = global i32 0
@.str = [42 x i8] c"ip tuntap add dev tun0 mode tun user root\00"
@.str.1 = [20 x i8] c"ip link set tun0 up\00"
@.str.2 = [50 x i8] c"ip -6 addr add BBBB:0000:0000:0000::1/64 dev tun0\00"
@.str.3 = [35 x i8] c"ip -6 addr add fe80::1/64 dev tun0\00"
@.str.4 = [5 x i8] c"tun0\00"
@IFF_TUN = global i32 0
@IFF_NO_PI = global i32 0
define i32 @init_tun() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %2
%7 = load i32, i32* @IFNAMSIZ
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8** %5
%11 = load i8*, i8** %5
%12 = call i32 @system(i8* %11)
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8** %5
%13 = load i8*, i8** %5
%14 = call i32 @system(i8* %13)
store i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @system(i8* %15)
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8** %5
%17 = load i8*, i8** %5
%18 = call i32 @system(i8* %17)
%19 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32, i32* @IFF_TUN
%21 = load i32, i32* @IFF_NO_PI
%22 = or i32 %20, %21
%23 = call i32 @tun_alloc(i8* %10, i32 %22)
store i32 %23, i32* %2
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %0
store i32 -1, i32* %1
store i32 1, i32* %6
br label %29
27: ; preds = %0
%28 = load i32, i32* %2
store i32 %28, i32* %1
store i32 1, i32* %6
br label %29
29: ; preds = %27, %26
%30 = load i8*, i8** %3
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@IFNAMSIZ = global i32 0
@.str = [42 x i8] c"ip tuntap add dev tun0 mode tun user root\00"
@.str.1 = [20 x i8] c"ip link set tun0 up\00"
@.str.2 = [50 x i8] c"ip -6 addr add BBBB:0000:0000:0000::1/64 dev tun0\00"
@.str.3 = [35 x i8] c"ip -6 addr add fe80::1/64 dev tun0\00"
@.str.4 = [5 x i8] c"tun0\00"
@IFF_TUN = global i32 0
@IFF_NO_PI = global i32 0
define i32 @init_tun() {
%1 = load i32, i32* @IFNAMSIZ
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = tail call i32 @system(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @system(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @system(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%9 = load i32, i32* @IFF_TUN
%10 = load i32, i32* @IFF_NO_PI
%11 = or i32 %10, %9
%12 = call i32 @tun_alloc(i8* %3, i32 %11)
%13 = icmp sgt i32 %12, -1
%14 = select i1 %13, i32 %12, i32 -1
ret i32 %14
}