#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_4__ {
  int length;
  int flags;
  scalar_t__ pointer;
};
struct TYPE_3__ {
  TYPE_2__ data;
};
struct iwreq {
  TYPE_1__ u;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ data;
typedef scalar_t__ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ SIOCIWFIRSTPRIV;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int ioctl(int, scalar_t__, struct iwreq *);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int getWscStatus(char *interface) {
  int socket_id;
  struct iwreq wrq;
  int data = 0;
  socket_id = socket(AF_INET, SOCK_DGRAM, 0);
  strcpy(wrq.ifr_name, interface);
  wrq.u.data.length = sizeof(data);
  wrq.u.data.pointer = (caddr_t)&data;
  wrq.u.data.flags = ((0x0D010750 + 0x01) & 0xffff);
  if (ioctl(socket_id, (SIOCIWFIRSTPRIV + 0x01), &wrq) == -1) {
    perror("ioctl error");
    close(socket_id);
    return -1;
  }
  close(socket_id);
  return data;
}


x86 assembly (clang, -O0):
<getWscStatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x4,-0x30(%rbp)
lea    -0x34(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x751,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%rsi
add    $0x1,%rsi
lea    -0x30(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11e4 <getWscStatus+0x94>
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <getWscStatus+0xa2>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getWscStatus>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
movl   $0x0,0xc(%rsp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
mov    %r14,%rsi
call   1030 <strcpy@plt>
movabs $0x75100000004,%rax
mov    %rax,0x10(%rsp)
lea    0xc(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    0x2e23(%rip),%rax
mov    (%rax),%rsi
add    $0x1,%rsi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11d0 <getWscStatus+0x80>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0xc(%rsp),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe29(%rip),%rdi
call   1060 <perror@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
jmp    11c8 <getWscStatus+0x78>

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

LLVM IR (-O2):
%struct.iwreq = type { %struct.TYPE_3__, i32 }
%struct.TYPE_3__ = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32, i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCIWFIRSTPRIV = global i64 0
@.str = [12 x i8] c"ioctl error\00"
define i32 @getWscStatus(i8* %0) {
%2 = alloca %struct.iwreq
%3 = alloca i32
%4 = bitcast %struct.iwreq* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = tail call i32 @strcpy(i32 undef, i8* %0)
%10 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i64 0, i32 0, i32 0, i32 0
store i32 4, i32* %10
%11 = ptrtoint i32* %3 to i64
%12 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i64 0, i32 0, i32 0, i32 2
store i64 %11, i64* %12
%13 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i64 0, i32 0, i32 0, i32 1
store i32 1873, i32* %13
%14 = load i64, i64* @SIOCIWFIRSTPRIV
%15 = add nsw i64 %14, 1
%16 = call i32 @ioctl(i32 %8, i64 %15, %struct.iwreq* %2)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @close(i32 %8)
br label %24
21: ; preds = %1
%22 = call i32 @close(i32 %8)
%23 = load i32, i32* %3
br label %24
24: ; preds = %21, %18
%25 = phi i32 [ -1, %18 ], [ %23, %21 ]
ret i32 %25
}