#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 ifr_flags;
  char *ifr_name;
};

/* Variables and functions */
int IFF_RUNNING;
int IFF_UP;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int set_intf_up(struct ifreq ifr, int sock) {
  if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
    return (-1);
  }
  ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
  if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
    fprintf(stderr, "failed to bring up interface %s: %s", ifr.ifr_name,
            strerror(errno));
    return -1;
  }
  return (0);
}


x86 assembly (clang, -O0):
<set_intf_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x18(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    116d <set_intf_up+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <set_intf_up+0xbf>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    0x2e63(%rip),%rcx
or     (%rcx),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11e8 <set_intf_up+0xb8>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe29(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <set_intf_up+0xbf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_intf_up>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %edi,0x8(%rsp)
mov    %rsi,0x10(%rsp)
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     11ce <set_intf_up+0x9e>
mov    0x2e6d(%rip),%rax
mov    0x2e6e(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,0x8(%rsp)
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    11ce <set_intf_up+0x9e>
mov    0x2e20(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%r14
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe44(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ifreq = type { i32, i8* }
@SIOCGIFFLAGS = global i32 0
@IFF_UP = global i32 0
@IFF_RUNNING = global i32 0
@SIOCSIFFLAGS = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"failed to bring up interface %s: %s\00"
@errno = global i32 0
define i32 @set_intf_up(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.ifreq
%6 = alloca i32
%7 = bitcast %struct.ifreq* %5 to { i32, i8* }*
%8 = getelementptr inbounds { i32, i8* }, { i32, i8* }* %7, i32 0, i32 0
store i32 %0, i32* %8
%9 = getelementptr inbounds { i32, i8* }, { i32, i8* }* %7, i32 0, i32 1
store i8* %1, i8** %9
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* @SIOCGIFFLAGS
%12 = call i64 @ioctl(i32 %10, i32 %11, %struct.ifreq* %5)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %34
15: ; preds = %3
%16 = load i32, i32* @IFF_UP
%17 = load i32, i32* @IFF_RUNNING
%18 = or i32 %16, %17
%19 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 0
%20 = load i32, i32* %19
%21 = or i32 %20, %18
store i32 %21, i32* %19
%22 = load i32, i32* %6
%23 = load i32, i32* @SIOCSIFFLAGS
%24 = call i64 @ioctl(i32 %22, i32 %23, %struct.ifreq* %5)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %15
%27 = load i32, i32* @stderr
%28 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 1
%29 = load i8*, i8** %28
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %31)
store i32 -1, i32* %4
br label %34
33: ; preds = %15
store i32 0, i32* %4
br label %34
34: ; preds = %33, %26, %14
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i8* }
@SIOCGIFFLAGS = global i32 0
@IFF_UP = global i32 0
@IFF_RUNNING = global i32 0
@SIOCSIFFLAGS = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"failed to bring up interface %s: %s\00"
@errno = global i32 0
define i32 @set_intf_up(i32 %0, i8* %1, i32 %2) {
%4 = alloca %struct.ifreq
%5 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0
store i32 %0, i32* %5
%6 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 1
store i8* %1, i8** %6
%7 = load i32, i32* @SIOCGIFFLAGS
%8 = call i64 @ioctl(i32 %2, i32 %7, %struct.ifreq* %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %3
%11 = load i32, i32* @IFF_UP
%12 = load i32, i32* @IFF_RUNNING
%13 = or i32 %12, %11
%14 = load i32, i32* %5
%15 = or i32 %13, %14
store i32 %15, i32* %5
%16 = load i32, i32* @SIOCSIFFLAGS
%17 = call i64 @ioctl(i32 %2, i32 %16, %struct.ifreq* %4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %10
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %6
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
br label %25
25: ; preds = %10, %3, %19
%26 = phi i32 [ -1, %19 ], [ -1, %3 ], [ 0, %10 ]
ret i32 %26
}