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

/* Type definitions */
struct TYPE_5__ {
  scalar_t__ *sa_data;
};
struct TYPE_6__ {
  TYPE_2__ ap_addr;
};
struct TYPE_4__ {
  int /*<<< orphan*/ ifrn_name;
};
struct iwreq {
  TYPE_3__ u;
  TYPE_1__ ifr_ifrn;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIWAP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct iwreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int check_assoc(char *ifname) {
  int socket_id, i;
  struct iwreq wrq;
  socket_id = socket(AF_INET, SOCK_DGRAM, 0);
  strcpy(wrq.ifr_ifrn.ifrn_name, ifname);
  ioctl(socket_id, SIOCGIWAP, &wrq);
  close(socket_id);
  for (i = 0; i < 6; i++)
    if (wrq.u.ap_addr.sa_data[i])
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<check_assoc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x6,-0x18(%rbp)
jge    11d4 <check_assoc+0x94>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11c1 <check_assoc+0x81>
movl   $0x1,-0x4(%rbp)
jmp    11db <check_assoc+0x9b>
jmp    11c6 <check_assoc+0x86>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1198 <check_assoc+0x58>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_assoc>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebp
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x8(%rsp),%rcx
mov    $0x1,%eax
cmpq   $0x0,(%rcx)
jne    11be <check_assoc+0x7e>
cmpq   $0x0,0x8(%rcx)
jne    11be <check_assoc+0x7e>
cmpq   $0x0,0x10(%rcx)
jne    11be <check_assoc+0x7e>
cmpq   $0x0,0x18(%rcx)
jne    11be <check_assoc+0x7e>
cmpq   $0x0,0x20(%rcx)
jne    11be <check_assoc+0x7e>
xor    %eax,%eax
cmpq   $0x0,0x28(%rcx)
setne  %al
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.iwreq = type { %struct.TYPE_6__, %struct.TYPE_4__ }
%struct.TYPE_6__ = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i64* }
%struct.TYPE_4__ = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCGIWAP = global i32 0
define i32 @check_assoc(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.iwreq
store i8* %0, i8** %3
%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* %6, i32 0, i32 1
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load i8*, i8** %3
%14 = call i32 @strcpy(i32 %12, i8* %13)
%15 = load i32, i32* %4
%16 = load i32, i32* @SIOCGIWAP
%17 = call i32 @ioctl(i32 %15, i32 %16, %struct.iwreq* %6)
%18 = load i32, i32* %4
%19 = call i32 @close(i32 %18)
store i32 0, i32* %5
br label %20
20: ; preds = %35, %1
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 6
br i1 %22, label %23, label %38
23: ; preds = %20
%24 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %6, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %24, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %25, i32 0, i32 0
%27 = load i64*, i64** %26
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i64, i64* %27, i64 %29
%31 = load i64, i64* %30
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %23
store i32 1, i32* %2
br label %39
34: ; preds = %23
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %20
38: ; preds = %20
store i32 0, i32* %2
br label %39
39: ; preds = %38, %33
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
%struct.iwreq = type { %struct.TYPE_6__, %struct.TYPE_4__ }
%struct.TYPE_6__ = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i64* }
%struct.TYPE_4__ = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCGIWAP = global i32 0
define i32 @check_assoc(i8* %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 = tail call i32 @strcpy(i32 undef, i8* %0)
%8 = load i32, i32* @SIOCGIWAP
%9 = call i32 @ioctl(i32 %6, i32 %8, %struct.iwreq* %2)
%10 = call i32 @close(i32 %6)
%11 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i64 0, i32 0, i32 0, i32 0
%12 = load i64*, i64** %11
%13 = load i64, i64* %12
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %1
%16 = getelementptr inbounds i64, i64* %12, i64 1
%17 = load i64, i64* %16
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = getelementptr inbounds i64, i64* %12, i64 2
%21 = load i64, i64* %20
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = getelementptr inbounds i64, i64* %12, i64 3
%25 = load i64, i64* %24
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = getelementptr inbounds i64, i64* %12, i64 4
%29 = load i64, i64* %28
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = getelementptr inbounds i64, i64* %12, i64 5
%33 = load i64, i64* %32
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i32
br label %36
36: ; preds = %31, %27, %23, %19, %15, %1
%37 = phi i32 [ 1, %1 ], [ 1, %15 ], [ 1, %19 ], [ 1, %23 ], [ 1, %27 ], [ %35, %31 ]
ret i32 %37
}