#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int length;
  scalar_t__ flags;
  scalar_t__ pointer;
};
struct TYPE_4__ {
  TYPE_1__ data;
};
struct iwreq {
  TYPE_2__ u;
};
struct iw_range {
  int we_version_compiled;
};
typedef scalar_t__ caddr_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ SIOCGIWRANGE;
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ iw_get_ext(int, char const *, int /*<<< orphan*/, struct iwreq *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int iw_get_range_info(int skfd, const char *ifname, struct iw_range *range) {
  struct iwreq wrq;
  char buffer[sizeof(struct iw_range) * 2];
  struct iw_range *range_raw;
  bzero(buffer, sizeof(buffer));
  wrq.u.data.pointer = (caddr_t)buffer;
  wrq.u.data.length = sizeof(buffer);
  wrq.u.data.flags = 0;
  if (iw_get_ext(skfd, ifname, SIOCGIWRANGE, &wrq) < 0)
    return (-1);
  range_raw = (struct iw_range *)buffer;
  if (wrq.u.data.length < 300) {
    range_raw->we_version_compiled = 9;
  }
  if (range_raw->we_version_compiled > 15) {
    memcpy((char *)range, buffer, sizeof(struct iw_range));
  } else {
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<iw_get_range_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0x8,%esi
call   1050 <bzero@plt>
lea    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x8,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
call   1030 <iw_get_ext@plt>
cmp    $0x0,%rax
jge    1197 <iw_get_range_info+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <iw_get_range_info+0xbd>
lea    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x12c,-0x30(%rbp)
jge    11b6 <iw_get_range_info+0x86>
mov    -0x40(%rbp),%rax
movl   $0x9,(%rax)
mov    -0x40(%rbp),%rax
cmpl   $0xf,(%rax)
jle    11da <iw_get_range_info+0xaa>
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
jmp    11e6 <iw_get_range_info+0xb6>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <iw_get_range_info+0xbd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iw_get_range_info>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1050 <bzero@plt>
mov    %rbx,0x20(%rsp)
movl   $0x8,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <iw_get_ext@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     11b4 <iw_get_range_info+0x84>
cmpl   $0x12c,0x10(%rsp)
jl     11b4 <iw_get_range_info+0x84>
cmpl   $0x10,0x8(%rsp)
jl     11b4 <iw_get_range_info+0x84>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iw_range = type { i32 }
%struct.iwreq = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i64, i64 }
@SIOCGIWRANGE = global i32 0
define i32 @iw_get_range_info(i32 %0, i8* %1, %struct.iw_range* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.iw_range*
%8 = alloca %struct.iwreq
%9 = alloca [8 x i8]
%10 = alloca %struct.iw_range*
store i32 %0, i32* %5
store i8* %1, i8** %6
store %struct.iw_range* %2, %struct.iw_range** %7
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%12 = call i32 @bzero(i8* %11, i32 8)
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%14 = ptrtoint i8* %13 to i64
%15 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %8, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 2
store i64 %14, i64* %17
%18 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %8, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %18, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %19, i32 0, i32 0
store i32 8, i32* %20
%21 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %8, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %21, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i32 0, i32 1
store i64 0, i64* %23
%24 = load i32, i32* %5
%25 = load i8*, i8** %6
%26 = load i32, i32* @SIOCGIWRANGE
%27 = call i64 @iw_get_ext(i32 %24, i8* %25, i32 %26, %struct.iwreq* %8)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %3
store i32 -1, i32* %4
br label %53
30: ; preds = %3
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%32 = bitcast i8* %31 to %struct.iw_range*
store %struct.iw_range* %32, %struct.iw_range** %10
%33 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %8, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = icmp slt i32 %36, 300
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load %struct.iw_range*, %struct.iw_range** %10
%40 = getelementptr inbounds %struct.iw_range, %struct.iw_range* %39, i32 0, i32 0
store i32 9, i32* %40
br label %41
41: ; preds = %38, %30
%42 = load %struct.iw_range*, %struct.iw_range** %10
%43 = getelementptr inbounds %struct.iw_range, %struct.iw_range* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = icmp sgt i32 %44, 15
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = load %struct.iw_range*, %struct.iw_range** %7
%48 = bitcast %struct.iw_range* %47 to i8*
%49 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%50 = call i32 @memcpy(i8* %48, i8* %49, i32 4)
br label %52
51: ; preds = %41
store i32 -1, i32* %4
br label %53
52: ; preds = %46
store i32 0, i32* %4
br label %53
53: ; preds = %52, %51, %29
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
%struct.iw_range = type { i32 }
%struct.iwreq = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i64, i64 }
@SIOCGIWRANGE = global i32 0
define i32 @iw_get_range_info(i32 %0, i8* %1, %struct.iw_range* %2) {
%4 = alloca %struct.iwreq
%5 = alloca [8 x i8]
%6 = bitcast %struct.iwreq* %4 to i8*
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%8 = call i32 @bzero(i8* %7, i32 8)
%9 = ptrtoint [8 x i8]* %5 to i64
%10 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %4, i64 0, i32 0, i32 0, i32 2
store i64 %9, i64* %10
%11 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %4, i64 0, i32 0, i32 0, i32 0
store i32 8, i32* %11
%12 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %4, i64 0, i32 0, i32 0, i32 1
store i64 0, i64* %12
%13 = load i32, i32* @SIOCGIWRANGE
%14 = call i64 @iw_get_ext(i32 %0, i8* %1, i32 %13, %struct.iwreq* %4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %26, label %16
16: ; preds = %3
%17 = load i32, i32* %11
%18 = icmp sgt i32 %17, 299
%19 = bitcast [8 x i8]* %5 to i32*
%20 = load i32, i32* %19
%21 = icmp sgt i32 %20, 15
%22 = select i1 %18, i1 %21, i1 false
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = bitcast %struct.iw_range* %2 to i8*
%25 = call i32 @memcpy(i8* %24, i8* %7, i32 4)
br label %26
26: ; preds = %16, %3, %23
%27 = phi i32 [ 0, %23 ], [ -1, %3 ], [ -1, %16 ]
ret i32 %27
}