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

/* Variables and functions */
int atoi(char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int get_wifi_connect_count() {
  char buffer[512];
  FILE *read_fp;
  int chars_read;
  int ret = 0;
  int ap_cn = 0, sta_cn = 0;
  memset(buffer, 0, 512);
  read_fp = popen("wl -i wlan0 assoclist | wc | awk '{print $1}'", "r");
  if (read_fp != NULL) {
    chars_read = fread(buffer, sizeof(char), 512 - 1, read_fp);
    if (chars_read > 0) {
      ap_cn = atoi(buffer);
    }
    pclose(read_fp);
  } else {
    ret = -1;
    goto EXIT;
  }
  memset(buffer, 0, 512);
  read_fp = popen("wl -i wl0.1 assoclist | wc | awk '{print $1}'", "r");
  if (read_fp != NULL) {
    chars_read = fread(buffer, sizeof(char), 512 - 1, read_fp);
    if (chars_read > 0) {
      sta_cn = atoi(buffer);
    }
    pclose(read_fp);
  } else {
    ret = -1;
    goto EXIT;
  }
  ret = ap_cn + sta_cn;
EXIT:
  return ret;
}


x86 assembly (clang, -O0):
<get_wifi_connect_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x210(%rbp)
movl   $0x0,-0x214(%rbp)
movl   $0x0,-0x218(%rbp)
lea    -0x200(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    0xe6d(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x208(%rbp)
cmpq   $0x0,-0x208(%rbp)
je     1207 <get_wifi_connect_count+0xb7>
lea    -0x200(%rbp),%rdi
mov    -0x208(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1ff,%edx
call   1030 <fread@plt>
mov    %eax,-0x20c(%rbp)
cmpl   $0x0,-0x20c(%rbp)
jle    11f6 <get_wifi_connect_count+0xa6>
lea    -0x200(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x214(%rbp)
mov    -0x208(%rbp),%rdi
call   1040 <pclose@plt>
jmp    1216 <get_wifi_connect_count+0xc6>
movl   $0xffffffff,-0x210(%rbp)
ff ff ff
jmp    12c5 <get_wifi_connect_count+0x175>
lea    -0x200(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    0xe00(%rip),%rdi
lea    0xdf7(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x208(%rbp)
cmpq   $0x0,-0x208(%rbp)
je     12a4 <get_wifi_connect_count+0x154>
lea    -0x200(%rbp),%rdi
mov    -0x208(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1ff,%edx
call   1030 <fread@plt>
mov    %eax,-0x20c(%rbp)
cmpl   $0x0,-0x20c(%rbp)
jle    1293 <get_wifi_connect_count+0x143>
lea    -0x200(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x218(%rbp)
mov    -0x208(%rbp),%rdi
call   1040 <pclose@plt>
jmp    12b3 <get_wifi_connect_count+0x163>
movl   $0xffffffff,-0x210(%rbp)
ff ff ff
jmp    12c5 <get_wifi_connect_count+0x175>
mov    -0x214(%rbp),%eax
add    -0x218(%rbp),%eax
mov    %eax,-0x210(%rbp)
mov    -0x210(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_wifi_connect_count>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsp,%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    0xe8a(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <popen@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     121d <get_wifi_connect_count+0xcd>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1ff,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11b8 <get_wifi_connect_count+0x68>
mov    %rsp,%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %rsp,%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    0xe58(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     121d <get_wifi_connect_count+0xcd>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1ff,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    120f <get_wifi_connect_count+0xbf>
mov    %rsp,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
add    %r14d,%ebp
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %ebp,%r15d
mov    %r15d,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"wl -i wlan0 assoclist | wc | awk '{print $1}'\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [46 x i8] c"wl -i wl0.1 assoclist | wc | awk '{print $1}'\00"
define i32 @get_wifi_connect_count() {
%1 = alloca [512 x i8]
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 512)
%9 = call i32* @popen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %24
12: ; preds = %0
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%14 = load i32*, i32** %2
%15 = call i32 @fread(i8* %13, i32 1, i32 511, i32* %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %5
br label %21
21: ; preds = %18, %12
%22 = load i32*, i32** %2
%23 = call i32 @pclose(i32* %22)
br label %25
24: ; preds = %0
store i32 -1, i32* %4
br label %48
25: ; preds = %21
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 0, i32 512)
%28 = call i32* @popen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %2
%29 = load i32*, i32** %2
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %43
31: ; preds = %25
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%33 = load i32*, i32** %2
%34 = call i32 @fread(i8* %32, i32 1, i32 511, i32* %33)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %6
br label %40
40: ; preds = %37, %31
%41 = load i32*, i32** %2
%42 = call i32 @pclose(i32* %41)
br label %44
43: ; preds = %25
store i32 -1, i32* %4
br label %48
44: ; preds = %40
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = add nsw i32 %45, %46
store i32 %47, i32* %4
br label %48
48: ; preds = %44, %43, %24
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
@.str = [46 x i8] c"wl -i wlan0 assoclist | wc | awk '{print $1}'\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [46 x i8] c"wl -i wl0.1 assoclist | wc | awk '{print $1}'\00"
define i32 @get_wifi_connect_count() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 512)
%4 = call i32* @popen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %26, label %6
6: ; preds = %0
%7 = call i32 @fread(i8* %2, i32 1, i32 511, i32* %4)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @atoi(i8* %2)
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ %10, %9 ], [ 0, %6 ]
%13 = call i32 @pclose(i32* %4)
%14 = call i32 @memset(i8* %2, i32 0, i32 512)
%15 = call i32* @popen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %26, label %17
17: ; preds = %11
%18 = call i32 @fread(i8* %2, i32 1, i32 511, i32* %15)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @atoi(i8* %2)
br label %22
22: ; preds = %20, %17
%23 = phi i32 [ %21, %20 ], [ 0, %17 ]
%24 = call i32 @pclose(i32* %15)
%25 = add nsw i32 %23, %12
br label %26
26: ; preds = %11, %0, %22
%27 = phi i32 [ %25, %22 ], [ -1, %0 ], [ -1, %11 ]
ret i32 %27
}