#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_get(const char *ifname) {
  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] = 34;
  ifr.ifr_data = buf;
  ret = ioctl(sock, (SIOCIWFIRSTPRIV + 31), &ifr);
  if (ret != 0)
    return -2;
  return ((char *)buf)[0] == 2;
}


x86 assembly (clang, -O0):
<om_wifi_maxperf_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1181 <om_wifi_maxperf_get+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <om_wifi_maxperf_get+0xbe>
mov    -0x20(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movl   $0x22,-0x130(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%rsi
add    $0x1f,%rsi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e9 <om_wifi_maxperf_get+0xa9>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11fe <om_wifi_maxperf_get+0xbe>
movsbl -0x130(%rbp),%eax
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<om_wifi_maxperf_get>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%r14
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11c5 <om_wifi_maxperf_get+0x85>
mov    %eax,%ebx
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movl   $0x22,0x10(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,(%rsp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%rsi
add    $0x1f,%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
test   %ecx,%ecx
jne    11ca <om_wifi_maxperf_get+0x8a>
xor    %eax,%eax
cmpb   $0x2,0x10(%rsp)
sete   %al
jmp    11ca <om_wifi_maxperf_get+0x8a>
mov    $0xffffffff,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
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_get(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.ifreq
%7 = alloca [64 x i32]
store i8* %0, i8** %3
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %40
14: ; preds = %1
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%16 = load i32, i32* %15
%17 = call i32 @memset(i32 %16, i8 signext 0, i32 4)
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load i8*, i8** %3
%21 = call i32 @strncpy(i32 %19, i8* %20, i32 4)
%22 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 0
store i32 34, i32* %22
%23 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 0
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
store i32* %23, i32** %24
%25 = load i32, i32* %4
%26 = load i64, i64* @SIOCIWFIRSTPRIV
%27 = add nsw i64 %26, 31
%28 = call i32 @ioctl(i32 %25, i64 %27, %struct.ifreq* %6)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %14
store i32 -2, i32* %2
br label %40
32: ; preds = %14
%33 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 0
%34 = bitcast i32* %33 to i8*
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 2
%39 = zext i1 %38 to i32
store i32 %39, i32* %2
br label %40
40: ; preds = %32, %31, %13
%41 = load i32, i32* %2
ret i32 %41
}

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