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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ SIOCIWFIRSTPRIV;
int /*<<< orphan*/ SOCK_DGRAM;
int ioctl(int, scalar_t__, struct ifreq *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
int om_wifi_maxperf_set(const char *ifname, int mode) {
  int sock, ret;
  struct ifreq ifr;
  int buf[64];
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0)
    return -1;
  memset(ifr.ifr_name, '\0', sizeof(ifr.ifr_name));
  strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  buf[0] = mode ? 2 : 0;
  ifr.ifr_data = buf;
  ret = ioctl(sock, (SIOCIWFIRSTPRIV + 11), &ifr);
  if (ret != 0)
    return -2;
  return 0;
}


x86 assembly (clang, -O0):
<om_wifi_maxperf_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1184 <om_wifi_maxperf_set+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <om_wifi_maxperf_set+0xbf>
mov    -0x28(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x130(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%rsi
add    $0xb,%rsi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11f8 <om_wifi_maxperf_set+0xb8>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11ff <om_wifi_maxperf_set+0xbf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<om_wifi_maxperf_set>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11c7 <om_wifi_maxperf_set+0x87>
mov    %eax,%ebx
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %rbp,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
test   %r14d,%r14d
setne  %al
add    %eax,%eax
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,(%rsp)
mov    0x2e21(%rip),%rax
mov    (%rax),%rsi
add    $0xb,%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,1),%eax
add    $0xfffffffe,%eax
jmp    11cc <om_wifi_maxperf_set+0x8c>
mov    $0xffffffff,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i32*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCIWFIRSTPRIV = global i64 0
define i32 @om_wifi_maxperf_set(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.ifreq
%9 = alloca [64 x i32]
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %39
16: ; preds = %2
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 @memset(i32 %18, i8 signext 0, i32 4)
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load i8*, i8** %4
%23 = call i32 @strncpy(i32 %21, i8* %22, i32 4)
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 2, i32 0
%28 = getelementptr inbounds [64 x i32], [64 x i32]* %9, i64 0, i64 0
store i32 %27, i32* %28
%29 = getelementptr inbounds [64 x i32], [64 x i32]* %9, i64 0, i64 0
%30 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
store i32* %29, i32** %30
%31 = load i32, i32* %6
%32 = load i64, i64* @SIOCIWFIRSTPRIV
%33 = add nsw i64 %32, 11
%34 = call i32 @ioctl(i32 %31, i64 %33, %struct.ifreq* %8)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %16
store i32 -2, i32* %3
br label %39
38: ; preds = %16
store i32 0, i32* %3
br label %39
39: ; preds = %38, %37, %15
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.ifreq = type { i32*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCIWFIRSTPRIV = global i64 0
define i32 @om_wifi_maxperf_set(i8* %0, i32 %1) {
%3 = alloca %struct.ifreq
%4 = alloca [64 x i32]
%5 = bitcast %struct.ifreq* %3 to i8*
%6 = bitcast [64 x i32]* %4 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %2
%12 = tail call i32 @memset(i32 undef, i8 signext 0, i32 4)
%13 = tail call i32 @strncpy(i32 undef, i8* %0, i32 4)
%14 = icmp eq i32 %1, 0
%15 = select i1 %14, i32 0, i32 2
%16 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 0
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store i32* %16, i32** %17
%18 = load i64, i64* @SIOCIWFIRSTPRIV
%19 = add nsw i64 %18, 11
%20 = call i32 @ioctl(i32 %9, i64 %19, %struct.ifreq* %3)
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i32 0, i32 -2
br label %23
23: ; preds = %11, %2
%24 = phi i32 [ -1, %2 ], [ %22, %11 ]
ret i32 %24
}