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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EOPNOTSUPP;
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ SIOCGIWSTATS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct iwreq *);
int /*<<< orphan*/ memset(struct iwreq *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
void iw_getstat_real(struct iw_statistics *stat) {
  struct iwreq wrq;
  int skfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (skfd < 0) {
    fprintf(stderr, "%s: cannot open socket\n", "iw_getstat_real");
    return;
  }
  wrq.u.data.pointer = (caddr_t)stat;
  wrq.u.data.length = sizeof(*stat);
  wrq.u.data.flags = 0;
  strncpy(wrq.ifr_name, "wlan0", IFNAMSIZ);
  if (ioctl(skfd, SIOCGIWSTATS, &wrq) < 0) {
    if (errno != EOPNOTSUPP) {
      fprintf(stderr, "cannot obtain iw statistics\n");
      return;
    }
    errno = 0;
    memset(&wrq, 0, sizeof(wrq));
  }
  close(skfd);
}


x86 assembly (clang, -O0):
<iw_getstat_real>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11b5 <iw_getstat_real+0x55>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
lea    0xe6f(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    125f <iw_getstat_real+0xff>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x4,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
lea    0xe49(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x2c(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1257 <iw_getstat_real+0xf7>
mov    0x2dae(%rip),%rax
mov    (%rax),%rax
mov    0x2dac(%rip),%rcx
cmp    (%rcx),%rax
je     1239 <iw_getstat_real+0xd9>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    125f <iw_getstat_real+0xff>
mov    0x2d78(%rip),%rax
movq   $0x0,(%rax)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iw_getstat_real>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     1205 <iw_getstat_real+0xa5>
mov    %eax,%ebx
mov    %r14,0x20(%rsp)
movl   $0x4,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
lea    0xe79(%rip),%rsi
call   1030 <strncpy@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
jns    11fc <iw_getstat_real+0x9c>
mov    0x2de3(%rip),%rax
mov    (%rax),%rcx
mov    0x2de1(%rip),%rdx
cmp    (%rdx),%rcx
jne    122a <iw_getstat_real+0xca>
movq   $0x0,(%rax)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    1241 <iw_getstat_real+0xe1>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
lea    0xdfc(%rip),%rdx
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1070 <fprintf@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.iw_statistics = type { i32 }
%struct.iwreq = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i64, i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"%s: cannot open socket\0A\00"
@.str.1 = [16 x i8] c"iw_getstat_real\00"
@.str.2 = [6 x i8] c"wlan0\00"
@IFNAMSIZ = global i32 0
@SIOCGIWSTATS = global i32 0
@errno = global i64 0
@EOPNOTSUPP = global i64 0
@.str.3 = [29 x i8] c"cannot obtain iw statistics\0A\00"
define void @iw_getstat_real(%struct.iw_statistics* %0) {
%2 = alloca %struct.iw_statistics*
%3 = alloca %struct.iwreq
%4 = alloca i32
store %struct.iw_statistics* %0, %struct.iw_statistics** %2
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %45
13: ; preds = %1
%14 = load %struct.iw_statistics*, %struct.iw_statistics** %2
%15 = ptrtoint %struct.iw_statistics* %14 to i64
%16 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %3, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %16, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i32 0, i32 2
store i64 %15, i64* %18
%19 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %3, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %19, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i32 0, i32 0
store i32 4, i32* %21
%22 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %3, i32 0, i32 1
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %22, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 1
store i64 0, i64* %24
%25 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %3, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @IFNAMSIZ
%28 = call i32 @strncpy(i32 %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %4
%30 = load i32, i32* @SIOCGIWSTATS
%31 = call i64 @ioctl(i32 %29, i32 %30, %struct.iwreq* %3)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %13
%34 = load i64, i64* @errno
%35 = load i64, i64* @EOPNOTSUPP
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %45
40: ; preds = %33
store i64 0, i64* @errno
%41 = call i32 @memset(%struct.iwreq* %3, i32 0, i32 32)
br label %42
42: ; preds = %40, %13
%43 = load i32, i32* %4
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %42, %37, %10
ret void
}

LLVM IR (-O2):
%struct.iw_statistics = type { i32 }
%struct.iwreq = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i64, i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"%s: cannot open socket\0A\00"
@.str.1 = [16 x i8] c"iw_getstat_real\00"
@.str.2 = [6 x i8] c"wlan0\00"
@IFNAMSIZ = global i32 0
@SIOCGIWSTATS = global i32 0
@errno = global i64 0
@EOPNOTSUPP = global i64 0
@.str.3 = [29 x i8] c"cannot obtain iw statistics\0A\00"
define void @iw_getstat_real(%struct.iw_statistics* %0) {
%2 = alloca %struct.iwreq
%3 = bitcast %struct.iwreq* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %32
11: ; preds = %1
%12 = ptrtoint %struct.iw_statistics* %0 to i64
%13 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i64 0, i32 1, i32 0, i32 2
store i64 %12, i64* %13
%14 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i64 0, i32 1, i32 0, i32 0
store i32 4, i32* %14
%15 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i64 0, i32 1, i32 0, i32 1
store i64 0, i64* %15
%16 = load i32, i32* @IFNAMSIZ
%17 = tail call i32 @strncpy(i32 undef, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @SIOCGIWSTATS
%19 = call i64 @ioctl(i32 %6, i32 %18, %struct.iwreq* %2)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %11
%22 = load i64, i64* @errno
%23 = load i64, i64* @EOPNOTSUPP
%24 = icmp eq i64 %22, %23
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %32
28: ; preds = %21
store i64 0, i64* @errno
%29 = call i32 @memset(%struct.iwreq* %2, i32 0, i32 32)
br label %30
30: ; preds = %28, %11
%31 = call i32 @close(i32 %6)
br label %32
32: ; preds = %30, %25, %8
ret void
}