#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 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_info() {
  char buffer[512];
  FILE *read_fp;
  int chars_read;
  int ret = 0;
  memset(buffer, 0, 512);
  read_fp = popen("ifconfig | grep wlan0", "r");
  if (read_fp != NULL) {
    chars_read = fread(buffer, sizeof(char), 512 - 1, read_fp);
    if (chars_read > 0) {
      ret = 1;
    } else {
      ret = 0;
    }
    pclose(read_fp);
  }
  if (ret == 0)
    return 1;
  memset(buffer, 0, 512);
  read_fp = popen("wl -i wlan0 assoclist", "r");
  if (read_fp != NULL) {
    chars_read = fread(buffer, sizeof(char), 512 - 1, read_fp);
    if (chars_read > 0) {
      ret = 1;
    } else {
      ret = 0;
    }
    pclose(read_fp);
  }
  if (ret == 1)
    return ret;
  memset(buffer, 0, 512);
  read_fp = popen("wl -i wl0.1 assoclist", "r");
  if (read_fp != NULL) {
    chars_read = fread(buffer, sizeof(char), 512 - 1, read_fp);
    if (chars_read > 0) {
      ret = 1;
    } else {
      ret = 0;
    }
    pclose(read_fp);
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_wifi_connect_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    0xe91(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
je     11e5 <get_wifi_connect_info+0xa5>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1ff,%edx
call   1030 <fread@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0x0,-0x21c(%rbp)
jle    11cf <get_wifi_connect_info+0x8f>
movl   $0x1,-0x220(%rbp)
jmp    11d9 <get_wifi_connect_info+0x99>
movl   $0x0,-0x220(%rbp)
mov    -0x218(%rbp),%rdi
call   1040 <pclose@plt>
cmpl   $0x0,-0x220(%rbp)
jne    11fe <get_wifi_connect_info+0xbe>
movl   $0x1,-0x4(%rbp)
jmp    1342 <get_wifi_connect_info+0x202>
lea    -0x210(%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,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
je     128e <get_wifi_connect_info+0x14e>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1ff,%edx
call   1030 <fread@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0x0,-0x21c(%rbp)
jle    1278 <get_wifi_connect_info+0x138>
movl   $0x1,-0x220(%rbp)
jmp    1282 <get_wifi_connect_info+0x142>
movl   $0x0,-0x220(%rbp)
mov    -0x218(%rbp),%rdi
call   1040 <pclose@plt>
cmpl   $0x1,-0x220(%rbp)
jne    12a9 <get_wifi_connect_info+0x169>
mov    -0x220(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1342 <get_wifi_connect_info+0x202>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    0xd6b(%rip),%rdi
lea    0xd4c(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
je     1339 <get_wifi_connect_info+0x1f9>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1ff,%edx
call   1030 <fread@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0x0,-0x21c(%rbp)
jle    1323 <get_wifi_connect_info+0x1e3>
movl   $0x1,-0x220(%rbp)
jmp    132d <get_wifi_connect_info+0x1ed>
movl   $0x0,-0x220(%rbp)
mov    -0x218(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0x220(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_wifi_connect_info>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    0xe9d(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     1254 <get_wifi_connect_info+0x114>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%r15d
mov    $0x1,%esi
mov    $0x1ff,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <pclose@plt>
test   %ebp,%ebp
jle    125a <get_wifi_connect_info+0x11a>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    0xe5a(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     125a <get_wifi_connect_info+0x11a>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%r15d
mov    $0x1,%esi
mov    $0x1ff,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <pclose@plt>
test   %ebp,%ebp
jg     125a <get_wifi_connect_info+0x11a>
mov    %rsp,%rdi
xor    %r15d,%r15d
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    0xe16(%rip),%rdi
lea    0xdf7(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     125a <get_wifi_connect_info+0x11a>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1ff,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
xor    %r15d,%r15d
test   %eax,%eax
setg   %r15b
mov    %r14,%rdi
call   1040 <pclose@plt>
jmp    125a <get_wifi_connect_info+0x11a>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"ifconfig | grep wlan0\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"wl -i wlan0 assoclist\00"
@.str.3 = [22 x i8] c"wl -i wl0.1 assoclist\00"
define i32 @get_wifi_connect_info() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %5
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 512)
%8 = call i32* @popen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %22
11: ; preds = %0
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%13 = load i32*, i32** %3
%14 = call i32 @fread(i8* %12, i32 1, i32 511, i32* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 1, i32* %5
br label %19
18: ; preds = %11
store i32 0, i32* %5
br label %19
19: ; preds = %18, %17
%20 = load i32*, i32** %3
%21 = call i32 @pclose(i32* %20)
br label %22
22: ; preds = %19, %0
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 1, i32* %1
br label %67
26: ; preds = %22
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%28 = call i32 @memset(i8* %27, i32 0, i32 512)
%29 = call i32* @popen(i8* getelementptr inbounds ([22 x i8], [22 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* %29, i32** %3
%30 = load i32*, i32** %3
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %43
32: ; preds = %26
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%34 = load i32*, i32** %3
%35 = call i32 @fread(i8* %33, i32 1, i32 511, i32* %34)
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %32
store i32 1, i32* %5
br label %40
39: ; preds = %32
store i32 0, i32* %5
br label %40
40: ; preds = %39, %38
%41 = load i32*, i32** %3
%42 = call i32 @pclose(i32* %41)
br label %43
43: ; preds = %40, %26
%44 = load i32, i32* %5
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = load i32, i32* %5
store i32 %47, i32* %1
br label %67
48: ; preds = %43
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%50 = call i32 @memset(i8* %49, i32 0, i32 512)
%51 = call i32* @popen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %51, i32** %3
%52 = load i32*, i32** %3
%53 = icmp ne i32* %52, null
br i1 %53, label %54, label %65
54: ; preds = %48
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%56 = load i32*, i32** %3
%57 = call i32 @fread(i8* %55, i32 1, i32 511, i32* %56)
store i32 %57, i32* %4
%58 = load i32, i32* %4
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %54
store i32 1, i32* %5
br label %62
61: ; preds = %54
store i32 0, i32* %5
br label %62
62: ; preds = %61, %60
%63 = load i32*, i32** %3
%64 = call i32 @pclose(i32* %63)
br label %65
65: ; preds = %62, %48
%66 = load i32, i32* %5
store i32 %66, i32* %1
br label %67
67: ; preds = %65, %46, %25
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
@.str = [22 x i8] c"ifconfig | grep wlan0\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"wl -i wlan0 assoclist\00"
@.str.3 = [22 x i8] c"wl -i wl0.1 assoclist\00"
define i32 @get_wifi_connect_info() {
%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 ([22 x i8], [22 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 %27, label %6
6: ; preds = %0
%7 = call i32 @fread(i8* %2, i32 1, i32 511, i32* %4)
%8 = icmp sgt i32 %7, 0
%9 = call i32 @pclose(i32* %4)
br i1 %8, label %10, label %27
10: ; preds = %6
%11 = call i32 @memset(i8* %2, i32 0, i32 512)
%12 = call i32* @popen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %27, label %14
14: ; preds = %10
%15 = call i32 @fread(i8* %2, i32 1, i32 511, i32* %12)
%16 = icmp sgt i32 %15, 0
%17 = call i32 @pclose(i32* %12)
br i1 %16, label %27, label %18
18: ; preds = %14
%19 = call i32 @memset(i8* %2, i32 0, i32 512)
%20 = call i32* @popen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = call i32 @fread(i8* %2, i32 1, i32 511, i32* %20)
%24 = icmp sgt i32 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @pclose(i32* %20)
br label %27
27: ; preds = %14, %10, %0, %6, %18, %22
%28 = phi i32 [ %25, %22 ], [ 0, %18 ], [ 1, %6 ], [ 1, %0 ], [ 1, %10 ], [ 1, %14 ]
ret i32 %28
}