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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ SIOCSIFFLAGS;
int af_socket(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ panic(char *);
int /*<<< orphan*/ strlcpy(int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
void device_set_flags(const char *ifname, const short flags) {
  int ret, sock;
  struct ifreq ifr;
  sock = af_socket(AF_INET);
  memset(&ifr, 0, sizeof(ifr));
  strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
  ifr.ifr_flags = flags;
  ret = ioctl(sock, SIOCSIFFLAGS, &ifr);
  if (ret < 0)
    panic("Cannot set NIC flags!\n");
  close(sock);
}


x86 assembly (clang, -O0):
<device_set_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1030 <af_socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
call   1080 <strlcpy@plt>
mov    -0xa(%rbp),%ax
mov    %ax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11df <device_set_flags+0x7f>
lea    0xe26(%rip),%rdi
call   1040 <panic@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<device_set_flags>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1030 <af_socket@plt>
mov    %eax,%ebx
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x4(%rsp),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rsi
call   1080 <strlcpy@plt>
mov    %r14w,(%rsp)
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r15,%rdx
call   1060 <ioctl@plt>
test   %eax,%eax
jns    11cc <device_set_flags+0x6c>
lea    0xe39(%rip),%rdi
call   1040 <panic@plt>
mov    %ebx,%edi
call   1070 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i16, i32 }
@AF_INET = global i32 0
@IFNAMSIZ = global i32 0
@SIOCSIFFLAGS = global i32 0
@.str = [23 x i8] c"Cannot set NIC flags!\0A\00"
define void @device_set_flags(i8* %0, i16 signext %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.ifreq
store i8* %0, i8** %3
store i16 %1, i16* %4
%8 = load i32, i32* @AF_INET
%9 = call i32 @af_socket(i32 %8)
store i32 %9, i32* %6
%10 = call i32 @memset(%struct.ifreq* %7, i32 0, i32 8)
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 1
%12 = load i32, i32* %11
%13 = load i8*, i8** %3
%14 = load i32, i32* @IFNAMSIZ
%15 = call i32 @strlcpy(i32 %12, i8* %13, i32 %14)
%16 = load i16, i16* %4
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
store i16 %16, i16* %17
%18 = load i32, i32* %6
%19 = load i32, i32* @SIOCSIFFLAGS
%20 = call i32 @ioctl(i32 %18, i32 %19, %struct.ifreq* %7)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 @panic(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %2
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i16, i32 }
@AF_INET = global i32 0
@IFNAMSIZ = global i32 0
@SIOCSIFFLAGS = global i32 0
@.str = [23 x i8] c"Cannot set NIC flags!\0A\00"
define void @device_set_flags(i8* %0, i16 signext %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = tail call i32 @af_socket(i32 %5)
%7 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 8)
%8 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%9 = load i32, i32* %8
%10 = load i32, i32* @IFNAMSIZ
%11 = call i32 @strlcpy(i32 %9, i8* %0, i32 %10)
%12 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store i16 %1, i16* %12
%13 = load i32, i32* @SIOCSIFFLAGS
%14 = call i32 @ioctl(i32 %6, i32 %13, %struct.ifreq* %3)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @panic(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = call i32 @close(i32 %6)
ret void
}