#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 */
typedef int /*<<< orphan*/ bssid;

/* Variables and functions */
int /*<<< orphan*/ get_status_desc();
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strstr(int /*<<< orphan*/, char *);
int /*<<< orphan*/ wifi_lock();
int /*<<< orphan*/ wifi_unlock();
const char *Wifi_GetCurBssid(void) {
  static char bssid[20] = {0};
  wifi_lock();
  char *p = strstr(get_status_desc(), "bssid");
  if (p) {
    memcpy(bssid, p + 6, 17);
    bssid[18] = '\0';
  } else {
    memset(bssid, 0, sizeof(bssid));
  }
  wifi_unlock();
  return bssid;
}


x86 assembly (clang, -O0):
<Wifi_GetCurBssid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <wifi_lock@plt>
mov    $0x0,%al
call   1060 <get_status_desc@plt>
mov    %eax,%edi
lea    0xe81(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b8 <Wifi_GetCurBssid+0x58>
mov    -0x8(%rbp),%rsi
add    $0x6,%rsi
lea    0x2ebe(%rip),%rdi
mov    $0x11,%edx
call   1050 <memcpy@plt>
movb   $0x0,0x2ebf(%rip)
jmp    11cb <Wifi_GetCurBssid+0x6b>
lea    0x2ea1(%rip),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    $0x0,%al
call   1070 <wifi_unlock@plt>
lea    0x2e87(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Wifi_GetCurBssid>:
push   %rax
xor    %eax,%eax
call   1030 <wifi_lock@plt>
xor    %eax,%eax
call   1060 <get_status_desc@plt>
lea    0xe8a(%rip),%rsi
mov    %eax,%edi
call   1080 <strstr@plt>
test   %rax,%rax
je     11a3 <Wifi_GetCurBssid+0x43>
add    $0x6,%rax
lea    0x2ed3(%rip),%rdi
mov    %rax,%rsi
mov    $0x11,%edx
call   1050 <memcpy@plt>
movb   $0x0,0x2ed1(%rip)
jmp    11b6 <Wifi_GetCurBssid+0x56>
lea    0x2eb6(%rip),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
xor    %eax,%eax
call   1070 <wifi_unlock@plt>
lea    0x2e9c(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@Wifi_GetCurBssid.bssid = internal global [20 x i8] zeroinitializer
@.str = [6 x i8] c"bssid\00"
define i8* @Wifi_GetCurBssid() {
%1 = alloca i8*
%2 = call i32 (...) @wifi_lock()
%3 = call i32 (...) @get_status_desc()
%4 = call i8* @strstr(i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i8*, i8** %1
%9 = getelementptr inbounds i8, i8* %8, i64 6
%10 = call i32 @memcpy(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @Wifi_GetCurBssid.bssid, i64 0, i64 0), i8* %9, i32 17)
store i8 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @Wifi_GetCurBssid.bssid, i64 0, i64 18)
br label %13
11: ; preds = %0
%12 = call i32 @memset(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @Wifi_GetCurBssid.bssid, i64 0, i64 0), i32 0, i32 20)
br label %13
13: ; preds = %11, %7
%14 = call i32 (...) @wifi_unlock()
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @Wifi_GetCurBssid.bssid, i64 0, i64 0)
}

LLVM IR (-O2):
@Wifi_GetCurBssid.bssid = internal global [20 x i8] zeroinitializer
@.str = [6 x i8] c"bssid\00"
define i8* @Wifi_GetCurBssid() {
%1 = tail call i32 (...) @wifi_lock()
%2 = tail call i32 (...) @get_status_desc()
%3 = tail call i8* @strstr(i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = getelementptr inbounds i8, i8* %3, i64 6
%7 = tail call i32 @memcpy(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @Wifi_GetCurBssid.bssid, i64 0, i64 0), i8* %6, i32 17)
store i8 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @Wifi_GetCurBssid.bssid, i64 0, i64 18)
br label %10
8: ; preds = %0
%9 = tail call i32 @memset(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @Wifi_GetCurBssid.bssid, i64 0, i64 0), i32 0, i32 20)
br label %10
10: ; preds = %8, %5
%11 = tail call i32 (...) @wifi_unlock()
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @Wifi_GetCurBssid.bssid, i64 0, i64 0)
}