#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  short ifru_flags;
};
struct ifreq {
  TYPE_1__ ifr_ifru;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
short IFF_UP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int __tuntap_up(const char *name) {
  int s;
  struct ifreq ifr;
  short flag;
  if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0)
    return -1;
  strcpy(ifr.ifr_name, name);
  flag = IFF_UP;
  if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
    return -1;
  ifr.ifr_ifru.ifru_flags |= flag;
  if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<__tuntap_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    116d <__tuntap_up+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <__tuntap_up+0xc2>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%ax
mov    %ax,-0x22(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11b2 <__tuntap_up+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <__tuntap_up+0xc2>
movswl -0x22(%rbp),%ecx
movswl -0x20(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11eb <__tuntap_up+0xbb>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <__tuntap_up+0xc2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__tuntap_up>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     11ae <__tuntap_up+0x7e>
mov    %eax,%ebp
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    0x2e72(%rip),%rax
movzwl (%rax),%r14d
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     11ae <__tuntap_up+0x7e>
or     %r14w,0x8(%rsp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
mov    %rax,%rbx
sar    $0x3f,%rbx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i16 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IFF_UP = global i16 0
@SIOCGIFFLAGS = global i32 0
@SIOCSIFFLAGS = global i32 0
define i32 @__tuntap_up(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.ifreq
%6 = alloca i16
store i8* %0, i8** %3
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %38
12: ; preds = %1
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 1
%14 = load i32, i32* %13
%15 = load i8*, i8** %3
%16 = call i32 @strcpy(i32 %14, i8* %15)
%17 = load i16, i16* @IFF_UP
store i16 %17, i16* %6
%18 = load i32, i32* %4
%19 = load i32, i32* @SIOCGIFFLAGS
%20 = call i64 @ioctl(i32 %18, i32 %19, %struct.ifreq* %5)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %12
store i32 -1, i32* %2
br label %38
23: ; preds = %12
%24 = load i16, i16* %6
%25 = sext i16 %24 to i32
%26 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 0
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
%28 = load i16, i16* %27
%29 = sext i16 %28 to i32
%30 = or i32 %29, %25
%31 = trunc i32 %30 to i16
store i16 %31, i16* %27
%32 = load i32, i32* %4
%33 = load i32, i32* @SIOCSIFFLAGS
%34 = call i64 @ioctl(i32 %32, i32 %33, %struct.ifreq* %5)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %23
store i32 -1, i32* %2
br label %38
37: ; preds = %23
store i32 0, i32* %2
br label %38
38: ; preds = %37, %36, %22, %11
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i16 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IFF_UP = global i16 0
@SIOCGIFFLAGS = global i32 0
@SIOCSIFFLAGS = global i32 0
define i32 @__tuntap_up(i8* %0) {
%2 = alloca %struct.ifreq
%3 = bitcast %struct.ifreq* %2 to i8*
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %1
%9 = tail call i32 @strcpy(i32 undef, i8* %0)
%10 = load i16, i16* @IFF_UP
%11 = load i32, i32* @SIOCGIFFLAGS
%12 = call i64 @ioctl(i32 %6, i32 %11, %struct.ifreq* %2)
%13 = icmp slt i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %8
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0, i32 0
%16 = load i16, i16* %15
%17 = or i16 %16, %10
store i16 %17, i16* %15
%18 = load i32, i32* @SIOCSIFFLAGS
%19 = call i64 @ioctl(i32 %6, i32 %18, %struct.ifreq* %2)
%20 = ashr i64 %19, 63
%21 = trunc i64 %20 to i32
br label %22
22: ; preds = %14, %8, %1
%23 = phi i32 [ -1, %1 ], [ -1, %8 ], [ %21, %14 ]
ret i32 %23
}