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

/* Variables and functions */
int /*<<< orphan*/ IFF_UP;
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCSIFFLAGS;
int interfaceIoctl(int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
int tunBringUp(const char *dev) {
  struct ifreq ifr;
  int err;
  memset(&ifr, 0, sizeof(ifr));
  ;
  strncpy(ifr.ifr_name, dev, IFNAMSIZ);
  if ((err = interfaceIoctl(SIOCGIFFLAGS, &ifr)) < 0) {
    perror("tunBringUp: ioctl SIOCGIFFLAGS");
    return err;
  }
  ifr.ifr_flags |= IFF_UP;
  if ((err = interfaceIoctl(SIOCSIFFLAGS, &ifr)) < 0) {
    perror("tunBringUp: ioctl set IFF_UP");
    return err;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tunBringUp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1060 <interfaceIoctl@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11a6 <tunBringUp+0x66>
lea    0xe6a(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <tunBringUp+0xb1>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1060 <interfaceIoctl@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11ea <tunBringUp+0xaa>
lea    0xe45(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <tunBringUp+0xb1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tunBringUp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rbp
xor    %r14d,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0xc(%rsp),%edi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
call   1060 <interfaceIoctl@plt>
test   %eax,%eax
js     11bc <tunBringUp+0x7c>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
or     %eax,0x8(%rsp)
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1060 <interfaceIoctl@plt>
test   %eax,%eax
js     11c5 <tunBringUp+0x85>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe3d(%rip),%rdi
jmp    11cc <tunBringUp+0x8c>
lea    0xe53(%rip),%rdi
mov    %eax,%r14d
call   1050 <perror@plt>
jmp    11b0 <tunBringUp+0x70>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@IFNAMSIZ = global i32 0
@SIOCGIFFLAGS = global i32 0
@.str = [31 x i8] c"tunBringUp: ioctl SIOCGIFFLAGS\00"
@IFF_UP = global i32 0
@SIOCSIFFLAGS = global i32 0
@.str.1 = [29 x i8] c"tunBringUp: ioctl set IFF_UP\00"
define i32 @tunBringUp(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.ifreq
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 @memset(%struct.ifreq* %4, i32 0, i32 8)
%7 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 1
%8 = load i32, i32* %7
%9 = load i8*, i8** %3
%10 = load i32, i32* @IFNAMSIZ
%11 = call i32 @strncpy(i32 %8, i8* %9, i32 %10)
%12 = load i32, i32* @SIOCGIFFLAGS
%13 = call i32 @interfaceIoctl(i32 %12, %struct.ifreq* %4)
store i32 %13, i32* %5
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %5
store i32 %17, i32* %2
br label %30
18: ; preds = %1
%19 = load i32, i32* @IFF_UP
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%21 = load i32, i32* %20
%22 = or i32 %21, %19
store i32 %22, i32* %20
%23 = load i32, i32* @SIOCSIFFLAGS
%24 = call i32 @interfaceIoctl(i32 %23, %struct.ifreq* %4)
store i32 %24, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* %5
store i32 %28, i32* %2
br label %30
29: ; preds = %18
store i32 0, i32* %2
br label %30
30: ; preds = %29, %26, %15
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@IFNAMSIZ = global i32 0
@SIOCGIFFLAGS = global i32 0
@.str = [31 x i8] c"tunBringUp: ioctl SIOCGIFFLAGS\00"
@IFF_UP = global i32 0
@SIOCSIFFLAGS = global i32 0
@.str.1 = [29 x i8] c"tunBringUp: ioctl set IFF_UP\00"
define i32 @tunBringUp(i8* %0) {
%2 = alloca %struct.ifreq
%3 = bitcast %struct.ifreq* %2 to i8*
%4 = call i32 @memset(%struct.ifreq* %2, i32 0, i32 8)
%5 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 1
%6 = load i32, i32* %5
%7 = load i32, i32* @IFNAMSIZ
%8 = call i32 @strncpy(i32 %6, i8* %0, i32 %7)
%9 = load i32, i32* @SIOCGIFFLAGS
%10 = call i32 @interfaceIoctl(i32 %9, %struct.ifreq* %2)
%11 = icmp slt i32 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %1
%13 = load i32, i32* @IFF_UP
%14 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0
%15 = load i32, i32* %14
%16 = or i32 %15, %13
store i32 %16, i32* %14
%17 = load i32, i32* @SIOCSIFFLAGS
%18 = call i32 @interfaceIoctl(i32 %17, %struct.ifreq* %2)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %12, %1
%21 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), %12 ]
%22 = phi i32 [ %10, %1 ], [ %18, %12 ]
%23 = call i32 @perror(i8* %21)
br label %24
24: ; preds = %20, %12
%25 = phi i32 [ 0, %12 ], [ %22, %20 ]
ret i32 %25
}