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

/* Variables and functions */
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
int wpa_driver_wired_set_ifflags(const char *ifname, int flags) {
  struct ifreq ifr;
  int s;
  s = socket(PF_INET, SOCK_DGRAM, 0);
  if (s < 0) {
    perror("socket");
    return -1;
  }
  memset(&ifr, 0, sizeof(ifr));
  strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
  ifr.ifr_flags = flags & 0xffff;
  if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) {
    perror("ioctl[SIOCSIFFLAGS]");
    close(s);
    return -1;
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<wpa_driver_wired_set_ifflags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11ad <wpa_driver_wired_set_ifflags+0x4d>
lea    0xe64(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <wpa_driver_wired_set_ifflags+0xcd>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rax
mov    %eax,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    121e <wpa_driver_wired_set_ifflags+0xbe>
lea    0xe02(%rip),%rdi
call   1070 <perror@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <wpa_driver_wired_set_ifflags+0xcd>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wpa_driver_wired_set_ifflags>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
mov    %rdi,%rbp
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11f4 <wpa_driver_wired_set_ifflags+0x94>
mov    %eax,%ebx
lea    0x8(%rsp),%r12
xor    %r14d,%r14d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0xc(%rsp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rsi
call   1030 <strncpy@plt>
movzwl %r15w,%eax
mov    %eax,0x8(%rsp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r12d,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
js     1208 <wpa_driver_wired_set_ifflags+0xa8>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe05(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%r14d
jmp    11e4 <wpa_driver_wired_set_ifflags+0x84>
lea    0xdf8(%rip),%rdi
call   1070 <perror@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0xffffffff,%r14d
jmp    11e4 <wpa_driver_wired_set_ifflags+0x84>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@IFNAMSIZ = global i32 0
@SIOCSIFFLAGS = global i32 0
@.str.1 = [20 x i8] c"ioctl[SIOCSIFFLAGS]\00"
define i32 @wpa_driver_wired_set_ifflags(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.ifreq
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i32, i32* @PF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
15: ; preds = %2
%16 = call i32 @memset(%struct.ifreq* %6, i32 0, i32 8)
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%18 = load i32, i32* %17
%19 = load i8*, i8** %4
%20 = load i32, i32* @IFNAMSIZ
%21 = call i32 @strncpy(i32 %18, i8* %19, i32 %20)
%22 = load i32, i32* %5
%23 = and i32 %22, 65535
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* %7
%26 = load i32, i32* @SIOCSIFFLAGS
%27 = ptrtoint %struct.ifreq* %6 to i32
%28 = call i64 @ioctl(i32 %25, i32 %26, i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %15
%31 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* %7
%33 = call i32 @close(i32 %32)
store i32 -1, i32* %3
br label %37
34: ; preds = %15
%35 = load i32, i32* %7
%36 = call i32 @close(i32 %35)
store i32 0, i32* %3
br label %37
37: ; preds = %34, %30, %13
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@IFNAMSIZ = global i32 0
@SIOCSIFFLAGS = global i32 0
@.str.1 = [20 x i8] c"ioctl[SIOCSIFFLAGS]\00"
define i32 @wpa_driver_wired_set_ifflags(i8* %0, i32 %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %29
11: ; preds = %2
%12 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 8)
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%14 = load i32, i32* %13
%15 = load i32, i32* @IFNAMSIZ
%16 = call i32 @strncpy(i32 %14, i8* %0, i32 %15)
%17 = and i32 %1, 65535
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @SIOCSIFFLAGS
%20 = ptrtoint %struct.ifreq* %3 to i64
%21 = trunc i64 %20 to i32
%22 = call i64 @ioctl(i32 %7, i32 %19, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %11
%25 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @close(i32 %7)
br label %29
27: ; preds = %11
%28 = call i32 @close(i32 %7)
br label %29
29: ; preds = %27, %24, %9
%30 = phi i32 [ -1, %9 ], [ -1, %24 ], [ 0, %27 ]
ret i32 %30
}