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

/* Variables and functions */
int /*<<< orphan*/ clear_cmd_results();
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sleep(int);
scalar_t__ strlen(int /*<<< orphan*/);
int /*<<< orphan*/ wifi_lock();
int /*<<< orphan*/ wifi_unlock();
scalar_t__ wpa_cmd_ok();
int /*<<< orphan*/ wpa_cmd_results();
int /*<<< orphan*/ wpa_get_scan_results();
scalar_t__ wpa_request_scan();
const char *Wifi_GetApList(void) {
  int sync = 0;
  static char ap_list[2048];
  wifi_lock();
  if (wpa_request_scan() && wpa_cmd_ok()) {
    clear_cmd_results();
    if (sync) {
      while (0 == strlen(wpa_cmd_results()))
        wpa_get_scan_results();
    } else {
      sleep(1);
      wpa_get_scan_results();
    }
  } else {
    clear_cmd_results();
  }
  memcpy(ap_list, wpa_cmd_results(), 2048);
  wifi_unlock();
  return ap_list;
}


x86 assembly (clang, -O0):
<Wifi_GetApList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <wifi_lock@plt>
mov    $0x0,%al
call   10c0 <wpa_request_scan@plt>
cmp    $0x0,%rax
je     1231 <Wifi_GetApList+0x91>
mov    $0x0,%al
call   1040 <wpa_cmd_ok@plt>
cmp    $0x0,%rax
je     1231 <Wifi_GetApList+0x91>
mov    $0x0,%al
call   1030 <clear_cmd_results@plt>
cmpl   $0x0,-0x4(%rbp)
je     121b <Wifi_GetApList+0x7b>
jmp    11ee <Wifi_GetApList+0x4e>
mov    $0x0,%al
call   1080 <wpa_cmd_results@plt>
mov    %eax,%edi
call   1070 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1216 <Wifi_GetApList+0x76>
mov    $0x0,%al
call   1050 <wpa_get_scan_results@plt>
jmp    11ee <Wifi_GetApList+0x4e>
jmp    122c <Wifi_GetApList+0x8c>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    $0x0,%al
call   1050 <wpa_get_scan_results@plt>
jmp    1238 <Wifi_GetApList+0x98>
mov    $0x0,%al
call   1030 <clear_cmd_results@plt>
mov    $0x0,%al
call   1080 <wpa_cmd_results@plt>
mov    %eax,%esi
lea    0x2e38(%rip),%rdi
mov    $0x800,%edx
call   1090 <memcpy@plt>
mov    $0x0,%al
call   10a0 <wifi_unlock@plt>
lea    0x2e20(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Wifi_GetApList>:
push   %rbx
xor    %eax,%eax
call   1060 <wifi_lock@plt>
xor    %eax,%eax
call   10b0 <wpa_request_scan@plt>
test   %rax,%rax
je     11ca <Wifi_GetApList+0x3a>
xor    %eax,%eax
call   1040 <wpa_cmd_ok@plt>
test   %rax,%rax
je     11ca <Wifi_GetApList+0x3a>
xor    %eax,%eax
call   1030 <clear_cmd_results@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
call   1050 <wpa_get_scan_results@plt>
jmp    11d1 <Wifi_GetApList+0x41>
xor    %eax,%eax
call   1030 <clear_cmd_results@plt>
xor    %eax,%eax
call   1070 <wpa_cmd_results@plt>
lea    0x2ea1(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x800,%edx
call   1080 <memcpy@plt>
xor    %eax,%eax
call   1090 <wifi_unlock@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@Wifi_GetApList.ap_list = internal global [2048 x i8] zeroinitializer
define i8* @Wifi_GetApList() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (...) @wifi_lock()
%3 = call i64 (...) @wpa_request_scan()
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %24
5: ; preds = %0
%6 = call i64 (...) @wpa_cmd_ok()
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = call i32 (...) @clear_cmd_results()
%10 = load i32, i32* %1
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %8
br label %13
13: ; preds = %17, %12
%14 = call i32 (...) @wpa_cmd_results()
%15 = call i64 @strlen(i32 %14)
%16 = icmp eq i64 0, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (...) @wpa_get_scan_results()
br label %13
19: ; preds = %13
br label %23
20: ; preds = %8
%21 = call i32 @sleep(i32 1)
%22 = call i32 (...) @wpa_get_scan_results()
br label %23
23: ; preds = %20, %19
br label %26
24: ; preds = %5, %0
%25 = call i32 (...) @clear_cmd_results()
br label %26
26: ; preds = %24, %23
%27 = call i32 (...) @wpa_cmd_results()
%28 = call i32 @memcpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @Wifi_GetApList.ap_list, i64 0, i64 0), i32 %27, i32 2048)
%29 = call i32 (...) @wifi_unlock()
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @Wifi_GetApList.ap_list, i64 0, i64 0)
}

LLVM IR (-O2):
@Wifi_GetApList.ap_list = internal global [2048 x i8] zeroinitializer
define i8* @Wifi_GetApList() {
%1 = tail call i32 (...) @wifi_lock()
%2 = tail call i64 (...) @wpa_request_scan()
%3 = icmp eq i64 %2, 0
br i1 %3, label %11, label %4
4: ; preds = %0
%5 = tail call i64 (...) @wpa_cmd_ok()
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = tail call i32 (...) @clear_cmd_results()
%9 = tail call i32 @sleep(i32 1)
%10 = tail call i32 (...) @wpa_get_scan_results()
br label %13
11: ; preds = %4, %0
%12 = tail call i32 (...) @clear_cmd_results()
br label %13
13: ; preds = %7, %11
%14 = tail call i32 (...) @wpa_cmd_results()
%15 = tail call i32 @memcpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @Wifi_GetApList.ap_list, i64 0, i64 0), i32 %14, i32 2048)
%16 = tail call i32 (...) @wifi_unlock()
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @Wifi_GetApList.ap_list, i64 0, i64 0)
}