#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 */

/* Type definitions */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ strbuf;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int snprintf(char *, int, char *, char const *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int test_wlan_interface(const char *iface) {
  char strbuf[512];
  struct stat sbuf;
  int ret;
  ret = snprintf(strbuf, sizeof(strbuf), "/sys/class/net/%s/phy80211/subsystem",
                 iface);
  if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat(strbuf, &sbuf))) {
    fprintf(stderr, "Did not find 802.11 interface `%s'. Exiting.\n", iface);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_wlan_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x200,%esi
lea    0xe9a(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0x0,-0x21c(%rbp)
jl     11b2 <test_wlan_interface+0x72>
movslq -0x21c(%rbp),%rax
cmp    $0x200,%rax
jae    11b2 <test_wlan_interface+0x72>
lea    -0x210(%rbp),%rdi
lea    -0x218(%rbp),%rsi
call   1050 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11d5 <test_wlan_interface+0x95>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_wlan_interface>:
push   %rbx
sub    $0x210,%rsp
mov    %rdi,%rbx
lea    0xeae(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x200,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
cmp    $0x1ff,%eax
ja     118a <test_wlan_interface+0x4a>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %rax,%rax
jne    118a <test_wlan_interface+0x4a>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbx
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [37 x i8] c"/sys/class/net/%s/phy80211/subsystem\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"Did not find 802.11 interface `%s'. Exiting.\0A\00"
define i32 @test_wlan_interface(i8* %0) {
%2 = alloca i8*
%3 = alloca [512 x i8]
%4 = alloca %struct.stat
%5 = alloca i32
store i8* %0, i8** %2
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @snprintf(i8* %6, i32 512, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %1
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = icmp uge i64 %13, 512
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%17 = call i64 @stat(i8* %16, %struct.stat* %4)
%18 = icmp ne i64 0, %17
br i1 %18, label %19, label %24
19: ; preds = %15, %11, %1
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %2
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [37 x i8] c"/sys/class/net/%s/phy80211/subsystem\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"Did not find 802.11 interface `%s'. Exiting.\0A\00"
define i32 @test_wlan_interface(i8* %0) {
%2 = alloca [512 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = bitcast %struct.stat* %3 to i8*
%6 = call i32 @snprintf(i8* %4, i32 512, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = icmp ugt i32 %6, 511
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = call i64 @stat(i8* %4, %struct.stat* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8, %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %8
ret i32 0
}