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

/* Variables and functions */
int IFNAMSIZ;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
int tun_open(char *);
int main() {
  char name[IFNAMSIZ];
  char cmd[1024];
  int fd;
  memset(name, 0, IFNAMSIZ);
  fd = tun_open(name);
  if (fd == -1)
    return 1;
  fprintf(stdout, "%s opened\n", name);
  sprintf(cmd, "ifconfig %s 10.0.1.1 up", name);
  system(cmd);
  sprintf(cmd, "route add 10.0.1.2 dev %s", name);
  system(cmd);
  while (1)
    read(fd, cmd, sizeof(cmd));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x430(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x430(%rbp),%rdi
call   1070 <tun_open@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    11e6 <main+0x86>
movl   $0x1,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret
mov    -0x430(%rbp),%rdx
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x430(%rbp),%rdx
lea    -0x420(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1030 <system@plt>
mov    -0x430(%rbp),%rdx
lea    -0x420(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1030 <system@plt>
jmp    1253 <main+0xf3>
mov    -0x424(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
jmp    124e <main+0xee>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14,%rdi
call   1070 <tun_open@plt>
cmp    $0xffffffff,%eax
je     1211 <main+0xb1>
mov    %eax,%ebx
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
lea    0xe46(%rip),%rsi
lea    -0x420(%rbp),%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1030 <system@plt>
lea    0xe3d(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1030 <system@plt>
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
jmp    1200 <main+0xa0>
mov    $0x1,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@IFNAMSIZ = global i32 0
@stdout = global i32 0
@.str = [11 x i8] c"%s opened\0A\00"
@.str.1 = [24 x i8] c"ifconfig %s 10.0.1.1 up\00"
@.str.2 = [26 x i8] c"route add 10.0.1.2 dev %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca [1024 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @IFNAMSIZ
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %2
%9 = alloca i8, i64 %7
store i64 %7, i64* %3
%10 = load i32, i32* @IFNAMSIZ
%11 = call i32 @memset(i8* %9, i32 0, i32 %10)
%12 = call i32 @tun_open(i8* %9)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %0
store i32 1, i32* %1
%16 = load i8*, i8** %2
%17 = load i32, i32* %1
ret i32 %17
18: ; preds = %0
%19 = load i32, i32* @stdout
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %9)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%22 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = call i32 @system(i8* %23)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%26 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%28 = call i32 @system(i8* %27)
br label %29
29: ; preds = %30, %18
br label %30
30: ; preds = %29
%31 = load i32, i32* %5
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%33 = call i32 @read(i32 %31, i8* %32, i32 1024)
br label %29
}

LLVM IR (-O2):
@IFNAMSIZ = global i32 0
@stdout = global i32 0
@.str = [11 x i8] c"%s opened\0A\00"
@.str.1 = [24 x i8] c"ifconfig %s 10.0.1.1 up\00"
@.str.2 = [26 x i8] c"route add 10.0.1.2 dev %s\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = load i32, i32* @IFNAMSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%6 = call i32 @memset(i8* %4, i32 0, i32 %2)
%7 = call i32 @tun_open(i8* %4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %0
ret i32 1
10: ; preds = %0
%11 = load i32, i32* @stdout
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %4)
%13 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%14 = call i32 @system(i8* %5)
%15 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%16 = call i32 @system(i8* %5)
br label %17
17: ; preds = %17, %10
%18 = call i32 @read(i32 %7, i8* %5, i32 1024)
br label %17
}