#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 /*<<< orphan*/ buffer;

/* Variables and functions */
int IFF_NO_PI;
int IFF_TUN;
int IFNAMSIZ;
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int tun_alloc(char *, int);
void main() {
  char tun_name[IFNAMSIZ];
  char buffer[2048];
  int nread;
  strcpy(tun_name, "tun2");
  int tun_fd = tun_alloc(tun_name, IFF_TUN | IFF_NO_PI);
  printf("%d\n", tun_fd);
  while (1) {
    nread = read(tun_fd, buffer, sizeof(buffer));
  }
  printf("Read %d bytes from device %s\n", nread, tun_name);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x8(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x820(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x10(%rbp)
lea    0xe7f(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x820(%rbp),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    0x2e2b(%rip),%rax
or     (%rax),%esi
call   1050 <tun_alloc@plt>
mov    %eax,-0x818(%rbp)
mov    -0x818(%rbp),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c3 <main+0x83>
mov    -0x818(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x800,%edx
call   1060 <read@plt>
mov    %eax,-0x814(%rbp)
jmp    11be <main+0x7e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe91(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    0x2e5a(%rip),%rax
mov    0x2e43(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1050 <tun_alloc@plt>
mov    %eax,%ebx
lea    0xe6b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x810(%rbp),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x800,%edx
call   1060 <read@plt>
jmp    11b0 <main+0x70>

LLVM IR (-O0):
@IFNAMSIZ = global i32 0
@.str = [5 x i8] c"tun2\00"
@IFF_TUN = global i32 0
@IFF_NO_PI = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define void @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca [2048 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = load i32, i32* @IFNAMSIZ
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %1
%9 = alloca i8, i64 %7
store i64 %7, i64* %2
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @IFF_TUN
%12 = load i32, i32* @IFF_NO_PI
%13 = or i32 %11, %12
%14 = call i32 @tun_alloc(i8* %9, i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %18, %0
br label %18
18: ; preds = %17
%19 = load i32, i32* %5
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 2048)
store i32 %21, i32* %4
br label %17
}

LLVM IR (-O2):
@IFNAMSIZ = global i32 0
@.str = [5 x i8] c"tun2\00"
@IFF_TUN = global i32 0
@IFF_NO_PI = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define void @main() {
%1 = alloca [2048 x i8]
%2 = load i32, i32* @IFNAMSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%6 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @IFF_TUN
%8 = load i32, i32* @IFF_NO_PI
%9 = or i32 %8, %7
%10 = call i32 @tun_alloc(i8* %4, i32 %9)
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %12, %0
%13 = call i32 @read(i32 %10, i8* %5, i32 2048)
br label %12
}