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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *, int *, int *, char *,
                          int *, int *, int *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int checkWlanCli(char *usermac) {
  FILE *fp;
  char buf[64] = {0};
  char mac_str[32] = {0};
  int aid, psm, mimops, mcs, sgi, stbc;
  char bw[8] = {0};
  system("echo "
         " > /proc/wl_list");
  system("iwpriv ra0 show stainfo");
  fp = popen("cat /proc/wl_list", "r");
  if (!fp) {
    return -1;
  }
  while (fgets(buf, sizeof(buf), fp)) {
    sscanf(buf, "%s %d %d %d %s %d %d %d", mac_str, &aid, &psm, &mimops, bw,
           &mcs, &sgi, &stbc);
    if (16 > strlen(mac_str)) {
      pclose(fp);
      return 0;
    }
    if (0 == memcmp(usermac, mac_str, 17)) {
      printf("usermac = %s,mac_str = %s\n", usermac, mac_str);
      pclose(fp);
      return 1;
    }
  }
  pclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<checkWlanCli>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0xb8,%rsp
mov    %rdi,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    0xe26(%rip),%rdi
call   1040 <system@plt>
lea    0xe30(%rip),%rdi
call   1040 <system@plt>
lea    0xe3c(%rip),%rdi
lea    0xe47(%rip),%rsi
call   10b0 <popen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1219 <checkWlanCli+0x89>
movl   $0xffffffff,-0xc(%rbp)
jmp    131d <checkWlanCli+0x18d>
jmp    121e <checkWlanCli+0x8e>
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x40,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     130d <checkWlanCli+0x17d>
lea    -0x60(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    -0xa0(%rbp),%rbx
lea    0xdf2(%rip),%rsi
lea    -0x84(%rbp),%rcx
lea    -0x88(%rbp),%r8
lea    -0x8c(%rbp),%r9
lea    -0x90(%rbp),%r11
lea    -0x94(%rbp),%r10
lea    -0x98(%rbp),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   10a0 <sscanf@plt>
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0x10,%eax
cmp    %ecx,%eax
jle    12bf <checkWlanCli+0x12f>
mov    -0x20(%rbp),%rdi
call   1060 <pclose@plt>
movl   $0x0,-0xc(%rbp)
jmp    131d <checkWlanCli+0x18d>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x11,%edx
call   1080 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1308 <checkWlanCli+0x178>
mov    -0x18(%rbp),%rsi
lea    -0x80(%rbp),%rdx
lea    0xd6c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <pclose@plt>
movl   $0x1,-0xc(%rbp)
jmp    131d <checkWlanCli+0x18d>
jmp    121e <checkWlanCli+0x8e>
mov    -0x20(%rbp),%rdi
call   1060 <pclose@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xb8,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkWlanCli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,(%rsp)
lea    0xe3c(%rip),%rdi
call   1040 <system@plt>
lea    0xe46(%rip),%rdi
call   1040 <system@plt>
lea    0xe52(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   10a0 <popen@plt>
test   %rax,%rax
je     12a6 <checkWlanCli+0x126>
mov    %rax,%r13
lea    0x40(%rsp),%r15
lea    0x20(%rsp),%rbx
lea    0x14(%rsp),%rbp
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x40,%esi
mov    %r13,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     129c <checkWlanCli+0x11c>
mov    %r15,%rdi
lea    0xe13(%rip),%rsi
mov    %rbx,%rdx
lea    0x1c(%rsp),%rcx
lea    0x18(%rsp),%r8
mov    %rbp,%r9
lea    0x8(%rsp),%rax
push   %rax
lea    0x14(%rsp),%rax
push   %rax
lea    0x20(%rsp),%rax
push   %rax
lea    0x18(%rsp),%rax
push   %rax
call   1090 <sscanf@plt>
add    $0x20,%rsp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x10,%eax
jl     129c <checkWlanCli+0x11c>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x11,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    1210 <checkWlanCli+0x90>
lea    0xdd1(%rip),%rdi
lea    0x20(%rsp),%rdx
mov    %r14,%rsi
call   1050 <printf@plt>
mov    $0x1,%r12d
mov    %r13,%rdi
call   1060 <pclose@plt>
jmp    12ac <checkWlanCli+0x12c>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"echo > /proc/wl_list\00"
@.str.1 = [24 x i8] c"iwpriv ra0 show stainfo\00"
@.str.2 = [18 x i8] c"cat /proc/wl_list\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [24 x i8] c"%s %d %d %d %s %d %d %d\00"
@.str.5 = [27 x i8] c"usermac = %s,mac_str = %s\0A\00"
define i32 @checkWlanCli(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [64 x i8]
%6 = alloca [32 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [8 x i8]
store i8* %0, i8** %3
%14 = bitcast [64 x i8]* %5 to i8*
%15 = bitcast [32 x i8]* %6 to i8*
%16 = bitcast [8 x i8]* %13 to i8*
%17 = call i32 @system(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @system(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32* @popen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %19, i32** %4
%20 = load i32*, i32** %4
%21 = icmp ne i32* %20, null
br i1 %21, label %23, label %22
22: ; preds = %1
store i32 -1, i32* %2
br label %55
23: ; preds = %1
br label %24
24: ; preds = %51, %23
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%26 = load i32*, i32** %4
%27 = call i64 @fgets(i8* %25, i32 64, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %52
29: ; preds = %24
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%33 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %31, i32* %7, i32* %8, i32* %9, i8* %32, i32* %10, i32* %11, i32* %12)
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = icmp sgt i32 16, %35
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = load i32*, i32** %4
%39 = call i32 @pclose(i32* %38)
store i32 0, i32* %2
br label %55
40: ; preds = %29
%41 = load i8*, i8** %3
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%43 = call i64 @memcmp(i8* %41, i8* %42, i32 17)
%44 = icmp eq i64 0, %43
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = load i8*, i8** %3
%47 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%48 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %46, i8* %47)
%49 = load i32*, i32** %4
%50 = call i32 @pclose(i32* %49)
store i32 1, i32* %2
br label %55
51: ; preds = %40
br label %24
52: ; preds = %24
%53 = load i32*, i32** %4
%54 = call i32 @pclose(i32* %53)
store i32 0, i32* %2
br label %55
55: ; preds = %52, %45, %37, %22
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
@.str = [22 x i8] c"echo > /proc/wl_list\00"
@.str.1 = [24 x i8] c"iwpriv ra0 show stainfo\00"
@.str.2 = [18 x i8] c"cat /proc/wl_list\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [24 x i8] c"%s %d %d %d %s %d %d %d\00"
@.str.5 = [27 x i8] c"usermac = %s,mac_str = %s\0A\00"
define i32 @checkWlanCli(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%13 = bitcast i32* %4 to i8*
%14 = bitcast i32* %5 to i8*
%15 = bitcast i32* %6 to i8*
%16 = bitcast i32* %7 to i8*
%17 = bitcast i32* %8 to i8*
%18 = bitcast i32* %9 to i8*
%19 = bitcast i64* %10 to i8*
store i64 0, i64* %10
%20 = tail call i32 @system(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @system(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32* @popen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %39, label %24
24: ; preds = %1, %31
%25 = call i64 @fgets(i8* %11, i32 64, i32* %22)
%26 = icmp eq i64 %25, 0
br i1 %26, label %36, label %27
27: ; preds = %24
%28 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %12, i32* %4, i32* %5, i32* %6, i8* %19, i32* %7, i32* %8, i32* %9)
%29 = call i32 @strlen(i8* %12)
%30 = icmp slt i32 %29, 16
br i1 %30, label %36, label %31
31: ; preds = %27
%32 = call i64 @memcmp(i8* %0, i8* %12, i32 17)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %24
34: ; preds = %31
%35 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %12)
br label %36
36: ; preds = %24, %27, %34
%37 = phi i32 [ 1, %34 ], [ 0, %27 ], [ 0, %24 ]
%38 = call i32 @pclose(i32* %22)
br label %39
39: ; preds = %36, %1
%40 = phi i32 [ -1, %1 ], [ %37, %36 ]
ret i32 %40
}