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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int, struct iwreq *);
int /*<<< orphan*/ memset(char *, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
unsigned char get_failreason(void) {
  int socket_id;
  struct iwreq wrq;
  char data[10];
  socket_id = socket(AF_INET, SOCK_DGRAM, 0);
  memset(data, 0x00, 10);
  strcpy(wrq.ifr_name, "apcli0");
  strcpy(data, "p");
  wrq.u.data.length = strlen(data);
  wrq.u.data.pointer = data;
  wrq.u.data.flags = 0;
  ioctl(socket_id, (0x8BE0 + 0x1E), &wrq);
  close(socket_id);
  return (unsigned char)data[0];
}


x86 assembly (clang, -O0):
<get_failreason>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x4(%rbp)
lea    -0x32(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x32(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x32(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
lea    -0x32(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8bfe,%esi
lea    -0x28(%rbp),%rdx
call   1060 <ioctl@plt>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
movzbl -0x32(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_failreason>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebp
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <memset@plt>
lea    0xe64(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,0x30(%rsp)
mov    %rbx,0x20(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x18(%rsp),%rdx
mov    %ebp,%edi
mov    $0x8bfe,%esi
call   1060 <ioctl@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    0xe(%rsp),%al
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.iwreq = type { i8*, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i8*, i64, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"apcli0\00"
@.str.1 = [2 x i8] c"p\00"
define zeroext i8 @get_failreason() {
%1 = alloca i32
%2 = alloca %struct.iwreq
%3 = alloca [10 x i8]
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %1
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 10)
%9 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i32 0, i32 0
%10 = load i8*, i8** %9
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %17, i32 0, i32 2
store i32 %15, i32* %18
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %21, i32 0, i32 0
store i8* %19, i8** %22
%23 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %2, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 1
store i64 0, i64* %25
%26 = load i32, i32* %1
%27 = call i32 @ioctl(i32 %26, i32 35838, %struct.iwreq* %2)
%28 = load i32, i32* %1
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%31 = load i8, i8* %30
ret i8 %31
}

LLVM IR (-O2):
%struct.iwreq = type { i8*, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i8*, i64, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"apcli0\00"
@.str.1 = [2 x i8] c"p\00"
define zeroext i8 @get_failreason() {
%1 = alloca %struct.iwreq
%2 = alloca [10 x i8]
%3 = bitcast %struct.iwreq* %1 to i8*
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = call i32 @memset(i8* %4, i32 0, i32 10)
%9 = call i32 @strcpy(i8* undef, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @strlen(i8* %4)
%12 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %1, i64 0, i32 1, i32 0, i32 2
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %1, i64 0, i32 1, i32 0, i32 0
store i8* %4, i8** %13
%14 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %1, i64 0, i32 1, i32 0, i32 1
store i64 0, i64* %14
%15 = call i32 @ioctl(i32 %7, i32 35838, %struct.iwreq* %1)
%16 = call i32 @close(i32 %7)
%17 = load i8, i8* %4
ret i8 %17
}