#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 */
struct passwd {
  long pw_uid;
};
struct ifreq {
  int ifr_flags;
  char *ifr_name;
};
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int IFF_NO_PI;
int IFF_TAP;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ TUNSETIFF;
int /*<<< orphan*/ TUNSETOWNER;
int /*<<< orphan*/ TUNSETPERSIST;
int /*<<< orphan*/ Usage(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
long geteuid();
int getopt(int, char **, char *);
struct passwd *getpwnam(char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, long);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
char *optarg;
scalar_t__ optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, int);
long strtol(char *, char **, int /*<<< orphan*/);
int main(int argc, char **argv) {
  struct ifreq ifr;
  struct passwd *pw;
  long owner = geteuid();
  int tap_fd, opt, delete = 0, brief = 0;
  char *tun = "", *file = "/dev/net/tun", *name = argv[0], *end;
  while ((opt = getopt(argc, argv, "bd:f:t:u:")) > 0) {
    switch (opt) {
    case 'b':
      brief = 1;
      break;
    case 'd':
      delete = 1;
      tun = optarg;
      break;
    case 'f':
      file = optarg;
      break;
    case 'u':
      pw = getpwnam(optarg);
      if (pw != NULL) {
        owner = pw->pw_uid;
        break;
      }
      owner = strtol(optarg, &end, 0);
      if (*end != '\0') {
        fprintf(stderr, "'%s' is neither a username nor a numeric uid.\n",
                optarg);
        Usage(name);
      }
      break;
    case 't':
      tun = optarg;
      break;
    case 'h':
    default:
      Usage(name);
    }
  }
  argv += optind;
  argc -= optind;
  if (argc > 0)
    Usage(name);
  if ((tap_fd = open(file, O_RDWR)) < 0) {
    fprintf(stderr, "Failed to open '%s' : ", file);
    perror("");
    exit(1);
  }
  memset(&ifr, 0, sizeof(ifr));
  ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
  strncpy(ifr.ifr_name, tun, sizeof(ifr.ifr_name) - 1);
  if (ioctl(tap_fd, TUNSETIFF, (void *)&ifr) < 0) {
    perror("TUNSETIFF");
    exit(1);
  }
  if (delete) {
    if (ioctl(tap_fd, TUNSETPERSIST, 0) < 0) {
      perror("TUNSETPERSIST");
      exit(1);
    }
    printf("Set '%s' nonpersistent\n", ifr.ifr_name);
  } else {
    if (ioctl(tap_fd, TUNSETPERSIST, 1) < 0) {
      perror("TUNSETPERSIST");
      exit(1);
    }
    if (ioctl(tap_fd, TUNSETOWNER, owner) < 0) {
      perror("TUNSETPERSIST");
      exit(1);
    }
    if (brief)
      printf("%s\n", ifr.ifr_name);
    else
      printf("Set '%s' persistent and owned by uid %ld\n", ifr.ifr_name, owner);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
lea    0xe8f(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe3f(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe2f(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jle    134b <main+0x17b>
mov    -0x38(%rbp),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x68(%rbp)
sub    $0x13,%eax
ja     133d <main+0x16d>
mov    -0x68(%rbp),%rax
lea    0xda1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x40(%rbp)
jmp    1346 <main+0x176>
movl   $0x1,-0x3c(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    1346 <main+0x176>
mov    0x2d63(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    1346 <main+0x176>
mov    0x2d50(%rip),%rax
mov    (%rax),%rdi
call   1090 <getpwnam@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12cf <main+0xff>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1346 <main+0x176>
mov    0x2d22(%rip),%rax
mov    (%rax),%rdi
lea    -0x60(%rbp),%rsi
xor    %edx,%edx
call   10b0 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    -0x60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1320 <main+0x150>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
mov    0x2cf0(%rip),%rax
mov    (%rax),%rdx
lea    0xd55(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x58(%rbp),%rdi
call   1080 <Usage@plt>
jmp    1346 <main+0x176>
mov    0x2ccc(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    1346 <main+0x176>
jmp    133d <main+0x16d>
mov    -0x58(%rbp),%rdi
call   1080 <Usage@plt>
jmp    1220 <main+0x50>
mov    0x2c7e(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2c68(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1388 <main+0x1b8>
mov    -0x58(%rbp),%rdi
call   1080 <Usage@plt>
mov    -0x50(%rbp),%rdi
mov    0x2c4d(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    13d5 <main+0x205>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%rdx
lea    0xcdc(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0xccf(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2bd4(%rip),%rax
mov    (%rax),%eax
mov    0x2ba3(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    -0x34(%rbp),%edi
mov    0x2b9a(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    1441 <main+0x271>
lea    0xc7b(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x3c(%rbp)
je     1497 <main+0x2c7>
mov    -0x34(%rbp),%edi
mov    0x2b53(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    1480 <main+0x2b0>
lea    0xc46(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xc3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    153e <main+0x36e>
mov    -0x34(%rbp),%edi
mov    0x2b07(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    14cd <main+0x2fd>
lea    0xbf9(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x34(%rbp),%edi
mov    0x2b01(%rip),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    1502 <main+0x332>
lea    0xbc4(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x40(%rbp)
je     1523 <main+0x353>
mov    -0x18(%rbp),%rsi
lea    0xbc6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1539 <main+0x369>
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xbaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    153e <main+0x36e>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %rax,0x18(%rsp)
mov    (%rbx),%rax
mov    %rax,0x28(%rsp)
lea    0xe5f(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   10e0 <getopt@plt>
test   %eax,%eax
jle    131d <main+0x14d>
xor    %r15d,%r15d
lea    0xe7b(%rip),%rcx
mov    %rcx,0x10(%rsp)
lea    0xe2a(%rip),%rcx
mov    %rcx,0x20(%rsp)
lea    0xe2b(%rip),%r14
lea    0xdc7(%rip),%r12
movl   $0x0,0xc(%rsp)
jmp    12a5 <main+0xd5>
mov    0x0(%r13),%rdi
lea    0x40(%rsp),%rsi
xor    %edx,%edx
call   10b0 <strtol@plt>
mov    %rax,0x18(%rsp)
mov    0x40(%rsp),%rax
cmpb   $0x0,(%rax)
je     128a <main+0xba>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xdf1(%rip),%rsi
call   10a0 <fprintf@plt>
nopl   0x0(%rax,%rax,1)
mov    0x28(%rsp),%rdi
call   1080 <Usage@plt>
mov    %r15d,%r13d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10e0 <getopt@plt>
mov    %r13d,%r15d
test   %eax,%eax
jle    1340 <main+0x170>
add    $0xffffff9e,%eax
cmp    $0x13,%eax
ja     1280 <main+0xb0>
mov    $0x1,%r13d
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0x2d35(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
movl   $0x1,0xc(%rsp)
jmp    128a <main+0xba>
mov    0x2d1c(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
jmp    128a <main+0xba>
mov    0x2d0b(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    128a <main+0xba>
mov    0x2cfa(%rip),%r13
mov    0x0(%r13),%rdi
call   1090 <getpwnam@plt>
test   %rax,%rax
je     1243 <main+0x73>
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
jmp    128a <main+0xba>
movl   $0x0,0xc(%rsp)
lea    0xd24(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xd5d(%rip),%rax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
mov    0x2c89(%rip),%rax
sub    (%rax),%ebp
test   %ebp,%ebp
jle    1357 <main+0x187>
mov    0x28(%rsp),%rdi
call   1080 <Usage@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%esi
mov    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     1470 <main+0x2a0>
mov    %eax,%ebx
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2c2e(%rip),%rax
mov    0x2bff(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x30(%rsp)
mov    0x38(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    0x2bf4(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   1070 <ioctl@plt>
test   %rax,%rax
js     1491 <main+0x2c1>
mov    0x2bd0(%rip),%rax
mov    (%rax),%esi
cmpl   $0x0,0xc(%rsp)
je     13fd <main+0x22d>
mov    %ebx,%edi
xor    %edx,%edx
call   1070 <ioctl@plt>
test   %rax,%rax
js     1467 <main+0x297>
mov    0x38(%rsp),%rsi
lea    0xcca(%rip),%rdi
jmp    143c <main+0x26c>
mov    $0x1,%edx
mov    %ebx,%edi
call   1070 <ioctl@plt>
test   %rax,%rax
js     1467 <main+0x297>
mov    0x2bc3(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    0x18(%rsp),%rbx
mov    %rbx,%rdx
call   1070 <ioctl@plt>
test   %rax,%rax
js     1467 <main+0x297>
mov    0x38(%rsp),%rsi
test   %r13d,%r13d
je     1454 <main+0x284>
lea    0xca1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc86(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1443 <main+0x273>
lea    0xc49(%rip),%rdi
jmp    1498 <main+0x2c8>
mov    0x2b41(%rip),%rax
mov    (%rax),%edi
lea    0xc16(%rip),%rsi
mov    %rbp,%rdx
call   10a0 <fprintf@plt>
lea    0xc06(%rip),%rdi
jmp    1498 <main+0x2c8>
lea    0xc15(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32, i8* }
%struct.passwd = type { i64 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [13 x i8] c"/dev/net/tun\00"
@.str.2 = [10 x i8] c"bd:f:t:u:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.3 = [47 x i8] c"'%s' is neither a username nor a numeric uid.\0A\00"
@optind = global i64 0
@O_RDWR = global i32 0
@.str.4 = [23 x i8] c"Failed to open '%s' : \00"
@IFF_TAP = global i32 0
@IFF_NO_PI = global i32 0
@TUNSETIFF = global i32 0
@.str.5 = [10 x i8] c"TUNSETIFF\00"
@TUNSETPERSIST = global i32 0
@.str.6 = [14 x i8] c"TUNSETPERSIST\00"
@.str.7 = [24 x i8] c"Set '%s' nonpersistent\0A\00"
@TUNSETOWNER = global i32 0
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [42 x i8] c"Set '%s' persistent and owned by uid %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ifreq
%7 = alloca %struct.passwd*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = call i64 (...) @geteuid()
store i64 %17, i64* %8
store i32 0, i32* %11
store i32 0, i32* %12
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %13
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
store i8* %20, i8** %15
br label %21
21: ; preds = %62, %2
%22 = load i32, i32* %4
%23 = load i8**, i8*** %5
%24 = call i32 @getopt(i32 %22, i8** %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 %24, i32* %10
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %63
26: ; preds = %21
%27 = load i32, i32* %10
switch i32 %27, label %59 [
i32 98, label %28
i32 100, label %29
i32 102, label %31
i32 117, label %33
i32 116, label %56
i32 104, label %58
]
28: ; preds = %26
store i32 1, i32* %12
br label %62
29: ; preds = %26
store i32 1, i32* %11
%30 = load i8*, i8** @optarg
store i8* %30, i8** %13
br label %62
31: ; preds = %26
%32 = load i8*, i8** @optarg
store i8* %32, i8** %14
br label %62
33: ; preds = %26
%34 = load i8*, i8** @optarg
%35 = call %struct.passwd* @getpwnam(i8* %34)
store %struct.passwd* %35, %struct.passwd** %7
%36 = load %struct.passwd*, %struct.passwd** %7
%37 = icmp ne %struct.passwd* %36, null
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load %struct.passwd*, %struct.passwd** %7
%40 = getelementptr inbounds %struct.passwd, %struct.passwd* %39, i32 0, i32 0
%41 = load i64, i64* %40
store i64 %41, i64* %8
br label %62
42: ; preds = %33
%43 = load i8*, i8** @optarg
%44 = call i64 @strtol(i8* %43, i8** %16, i32 0)
store i64 %44, i64* %8
%45 = load i8*, i8** %16
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %42
%50 = load i32, i32* @stderr
%51 = load i8*, i8** @optarg
%52 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = load i8*, i8** %15
%54 = call i32 @Usage(i8* %53)
br label %55
55: ; preds = %49, %42
br label %62
56: ; preds = %26
%57 = load i8*, i8** @optarg
store i8* %57, i8** %13
br label %62
58: ; preds = %26
br label %59
59: ; preds = %26, %58
%60 = load i8*, i8** %15
%61 = call i32 @Usage(i8* %60)
br label %62
62: ; preds = %59, %56, %55, %38, %31, %29, %28
br label %21
63: ; preds = %21
%64 = load i64, i64* @optind
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 %64
store i8** %66, i8*** %5
%67 = load i64, i64* @optind
%68 = load i32, i32* %4
%69 = sext i32 %68 to i64
%70 = sub nsw i64 %69, %67
%71 = trunc i64 %70 to i32
store i32 %71, i32* %4
%72 = load i32, i32* %4
%73 = icmp sgt i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %63
%75 = load i8*, i8** %15
%76 = call i32 @Usage(i8* %75)
br label %77
77: ; preds = %74, %63
%78 = load i8*, i8** %14
%79 = load i32, i32* @O_RDWR
%80 = call i32 @open(i8* %78, i32 %79)
store i32 %80, i32* %9
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %88
82: ; preds = %77
%83 = load i32, i32* @stderr
%84 = load i8*, i8** %14
%85 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %84)
%86 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %77
%89 = call i32 @memset(%struct.ifreq* %6, i32 0, i32 16)
%90 = load i32, i32* @IFF_TAP
%91 = load i32, i32* @IFF_NO_PI
%92 = or i32 %90, %91
%93 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
store i32 %92, i32* %93
%94 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%95 = load i8*, i8** %94
%96 = load i8*, i8** %13
%97 = call i32 @strncpy(i8* %95, i8* %96, i32 7)
%98 = load i32, i32* %9
%99 = load i32, i32* @TUNSETIFF
%100 = bitcast %struct.ifreq* %6 to i8*
%101 = ptrtoint i8* %100 to i64
%102 = call i64 @ioctl(i32 %98, i32 %99, i64 %101)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %107
104: ; preds = %88
%105 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %88
%108 = load i32, i32* %11
%109 = icmp ne i32 %108, 0
br i1 %109, label %110, label %122
110: ; preds = %107
%111 = load i32, i32* %9
%112 = load i32, i32* @TUNSETPERSIST
%113 = call i64 @ioctl(i32 %111, i32 %112, i64 0)
%114 = icmp slt i64 %113, 0
br i1 %114, label %115, label %118
115: ; preds = %110
%116 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %110
%119 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%120 = load i8*, i8** %119
%121 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %120)
br label %152
122: ; preds = %107
%123 = load i32, i32* %9
%124 = load i32, i32* @TUNSETPERSIST
%125 = call i64 @ioctl(i32 %123, i32 %124, i64 1)
%126 = icmp slt i64 %125, 0
br i1 %126, label %127, label %130
127: ; preds = %122
%128 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%129 = call i32 @exit(i32 1)
unreachable
130: ; preds = %122
%131 = load i32, i32* %9
%132 = load i32, i32* @TUNSETOWNER
%133 = load i64, i64* %8
%134 = call i64 @ioctl(i32 %131, i32 %132, i64 %133)
%135 = icmp slt i64 %134, 0
br i1 %135, label %136, label %139
136: ; preds = %130
%137 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%138 = call i32 @exit(i32 1)
unreachable
139: ; preds = %130
%140 = load i32, i32* %12
%141 = icmp ne i32 %140, 0
br i1 %141, label %142, label %146
142: ; preds = %139
%143 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%144 = load i8*, i8** %143
%145 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %144)
br label %151
146: ; preds = %139
%147 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%148 = load i8*, i8** %147
%149 = load i64, i64* %8
%150 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0), i8* %148, i64 %149)
br label %151
151: ; preds = %146, %142
br label %152
152: ; preds = %151, %118
ret i32 0
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i8* }
%struct.passwd = type { i64 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [13 x i8] c"/dev/net/tun\00"
@.str.2 = [10 x i8] c"bd:f:t:u:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.3 = [47 x i8] c"'%s' is neither a username nor a numeric uid.\0A\00"
@optind = global i64 0
@O_RDWR = global i32 0
@.str.4 = [23 x i8] c"Failed to open '%s' : \00"
@IFF_TAP = global i32 0
@IFF_NO_PI = global i32 0
@TUNSETIFF = global i32 0
@.str.5 = [10 x i8] c"TUNSETIFF\00"
@TUNSETPERSIST = global i32 0
@.str.6 = [14 x i8] c"TUNSETPERSIST\00"
@.str.7 = [24 x i8] c"Set '%s' nonpersistent\0A\00"
@TUNSETOWNER = global i32 0
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [42 x i8] c"Set '%s' persistent and owned by uid %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.ifreq
%4 = alloca i8*
%5 = bitcast %struct.ifreq* %3 to i8*
%6 = tail call i64 (...) @geteuid()
%7 = load i8*, i8** %1
%8 = bitcast i8** %4 to i8*
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %52
11: ; preds = %2, %44
%12 = phi i32 [ %50, %44 ], [ %9, %2 ]
%13 = phi i8* [ %49, %44 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %2 ]
%14 = phi i8* [ %48, %44 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%15 = phi i32 [ %47, %44 ], [ 0, %2 ]
%16 = phi i32 [ %46, %44 ], [ 0, %2 ]
%17 = phi i64 [ %45, %44 ], [ %6, %2 ]
switch i32 %12, label %42 [
i32 98, label %44
i32 100, label %18
i32 102, label %20
i32 117, label %22
i32 116, label %40
]
18: ; preds = %11
%19 = load i8*, i8** @optarg
br label %44
20: ; preds = %11
%21 = load i8*, i8** @optarg
br label %44
22: ; preds = %11
%23 = load i8*, i8** @optarg
%24 = tail call %struct.passwd* @getpwnam(i8* %23)
%25 = icmp eq %struct.passwd* %24, null
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %24, i64 0, i32 0
%28 = load i64, i64* %27
br label %44
29: ; preds = %22
%30 = load i8*, i8** @optarg
%31 = call i64 @strtol(i8* %30, i8** %4, i32 0)
%32 = load i8*, i8** %4
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %44, label %35
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i8*, i8** @optarg
%38 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = tail call i32 @Usage(i8* %7)
br label %44
40: ; preds = %11
%41 = load i8*, i8** @optarg
br label %44
42: ; preds = %11
%43 = tail call i32 @Usage(i8* %7)
br label %44
44: ; preds = %11, %29, %35, %42, %40, %26, %20, %18
%45 = phi i64 [ %17, %42 ], [ %17, %40 ], [ %28, %26 ], [ %31, %35 ], [ %31, %29 ], [ %17, %20 ], [ %17, %18 ], [ %17, %11 ]
%46 = phi i32 [ %16, %42 ], [ %16, %40 ], [ %16, %26 ], [ %16, %35 ], [ %16, %29 ], [ %16, %20 ], [ 1, %18 ], [ %16, %11 ]
%47 = phi i32 [ %15, %42 ], [ %15, %40 ], [ %15, %26 ], [ %15, %35 ], [ %15, %29 ], [ %15, %20 ], [ %15, %18 ], [ 1, %11 ]
%48 = phi i8* [ %14, %42 ], [ %41, %40 ], [ %14, %26 ], [ %14, %35 ], [ %14, %29 ], [ %14, %20 ], [ %19, %18 ], [ %14, %11 ]
%49 = phi i8* [ %13, %42 ], [ %13, %40 ], [ %13, %26 ], [ %13, %35 ], [ %13, %29 ], [ %21, %20 ], [ %13, %18 ], [ %13, %11 ]
%50 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp sgt i32 %50, 0
br i1 %51, label %11, label %52
52: ; preds = %44, %2
%53 = phi i64 [ %6, %2 ], [ %45, %44 ]
%54 = phi i32 [ 0, %2 ], [ %46, %44 ]
%55 = phi i32 [ 0, %2 ], [ %47, %44 ]
%56 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ], [ %48, %44 ]
%57 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %49, %44 ]
%58 = load i64, i64* @optind
%59 = trunc i64 %58 to i32
%60 = sub i32 %0, %59
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %52
%63 = tail call i32 @Usage(i8* %7)
br label %64
64: ; preds = %62, %52
%65 = load i32, i32* @O_RDWR
%66 = tail call i32 @open(i8* %57, i32 %65)
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %64
%69 = load i32, i32* @stderr
%70 = tail call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%71 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%72 = tail call i32 @exit(i32 1)
unreachable
73: ; preds = %64
%74 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 16)
%75 = load i32, i32* @IFF_TAP
%76 = load i32, i32* @IFF_NO_PI
%77 = or i32 %76, %75
%78 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store i32 %77, i32* %78
%79 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%80 = load i8*, i8** %79
%81 = call i32 @strncpy(i8* %80, i8* %56, i32 7)
%82 = load i32, i32* @TUNSETIFF
%83 = ptrtoint %struct.ifreq* %3 to i64
%84 = call i64 @ioctl(i32 %66, i32 %82, i64 %83)
%85 = icmp slt i64 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %73
%87 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %73
%90 = icmp eq i32 %54, 0
%91 = load i32, i32* @TUNSETPERSIST
br i1 %90, label %101, label %92
92: ; preds = %89
%93 = call i64 @ioctl(i32 %66, i32 %91, i64 0)
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %92
%99 = load i8*, i8** %79
%100 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %99)
br label %121
101: ; preds = %89
%102 = call i64 @ioctl(i32 %66, i32 %91, i64 1)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %107
104: ; preds = %101
%105 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %101
%108 = load i32, i32* @TUNSETOWNER
%109 = call i64 @ioctl(i32 %66, i32 %108, i64 %53)
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %114
111: ; preds = %107
%112 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %107
%115 = icmp eq i32 %55, 0
%116 = load i8*, i8** %79
br i1 %115, label %119, label %117
117: ; preds = %114
%118 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %116)
br label %121
119: ; preds = %114
%120 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0), i8* %116, i64 %53)
br label %121
121: ; preds = %117, %119, %98
ret i32 0
}