#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ name;
};
struct iwreq {
  TYPE_1__ u;
};
struct ifreq {
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int ENODEV;
int ENOTSUP;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCGIWNAME;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
scalar_t__ iw_get_ext(int, char *, int /*<<< orphan*/, struct iwreq *);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int check_wext(int skfd, char *ifname, char *iwname) {
  struct iwreq wrq;
  if (iw_get_ext(skfd, ifname, SIOCGIWNAME, &wrq) < 0) {
    struct ifreq ifr;
    strcpy(ifr.ifr_name, ifname);
    if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
      return (-ENODEV);
    else
      return (-ENOTSUP);
  } else {
    strncpy(iwname, wrq.u.name, 16);
    iwname[16] = '\0';
  }
  return (1);
}


x86 assembly (clang, -O0):
<check_wext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
call   1050 <iw_get_ext@plt>
cmp    $0x0,%rax
jge    11c7 <check_wext+0x87>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    11b4 <check_wext+0x74>
xor    %eax,%eax
mov    0x2e1e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <check_wext+0xa7>
xor    %eax,%eax
mov    0x2e2b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <check_wext+0xa7>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    $0x10,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x10(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_wext>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
call   1050 <iw_get_ext@plt>
test   %rax,%rax
js     1182 <check_wext+0x42>
mov    (%rsp),%esi
mov    %r14,%rdi
mov    $0x10,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x10(%r14)
mov    $0x1,%eax
jmp    11b8 <check_wext+0x78>
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1060 <ioctl@plt>
test   %rax,%rax
jns    11ad <check_wext+0x6d>
mov    0x2e1d(%rip),%rcx
jmp    11b4 <check_wext+0x74>
mov    0x2e34(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.iwreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.ifreq = type { i32 }
@SIOCGIWNAME = global i32 0
@SIOCGIFFLAGS = global i32 0
@ENODEV = global i32 0
@ENOTSUP = global i32 0
define i32 @check_wext(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.iwreq
%9 = alloca %struct.ifreq
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i32, i32* %5
%11 = load i8*, i8** %6
%12 = load i32, i32* @SIOCGIWNAME
%13 = call i64 @iw_get_ext(i32 %10, i8* %11, i32 %12, %struct.iwreq* %8)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %3
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %9, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i8*, i8** %6
%19 = call i32 @strcpy(i32 %17, i8* %18)
%20 = load i32, i32* %5
%21 = load i32, i32* @SIOCGIFFLAGS
%22 = call i64 @ioctl(i32 %20, i32 %21, %struct.ifreq* %9)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %15
%25 = load i32, i32* @ENODEV
%26 = sub nsw i32 0, %25
store i32 %26, i32* %4
br label %39
27: ; preds = %15
%28 = load i32, i32* @ENOTSUP
%29 = sub nsw i32 0, %28
store i32 %29, i32* %4
br label %39
30: ; preds = %3
%31 = load i8*, i8** %7
%32 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %8, i32 0, i32 0
%33 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @strncpy(i8* %31, i32 %34, i32 16)
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i64 16
store i8 0, i8* %37
br label %38
38: ; preds = %30
store i32 1, i32* %4
br label %39
39: ; preds = %38, %27, %24
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
%struct.iwreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.ifreq = type { i32 }
@SIOCGIWNAME = global i32 0
@SIOCGIFFLAGS = global i32 0
@ENODEV = global i32 0
@ENOTSUP = global i32 0
define i32 @check_wext(i32 %0, i8* %1, i8* %2) {
%4 = alloca %struct.iwreq
%5 = alloca %struct.ifreq
%6 = bitcast %struct.iwreq* %4 to i8*
%7 = load i32, i32* @SIOCGIWNAME
%8 = call i64 @iw_get_ext(i32 %0, i8* %1, i32 %7, %struct.iwreq* %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %3
%11 = bitcast %struct.ifreq* %5 to i8*
%12 = call i32 @strcpy(i32 undef, i8* %1)
%13 = load i32, i32* @SIOCGIFFLAGS
%14 = call i64 @ioctl(i32 %0, i32 %13, %struct.ifreq* %5)
%15 = icmp slt i64 %14, 0
%16 = load i32, i32* @ENODEV
%17 = load i32, i32* @ENOTSUP
%18 = select i1 %15, i32 %16, i32 %17
%19 = sub nsw i32 0, %18
br label %25
20: ; preds = %3
%21 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %4, i64 0, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @strncpy(i8* %2, i32 %22, i32 16)
%24 = getelementptr inbounds i8, i8* %2, i64 16
store i8 0, i8* %24
br label %25
25: ; preds = %20, %10
%26 = phi i32 [ %19, %10 ], [ 1, %20 ]
ret i32 %26
}