#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 /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strstr(char *, char *);
int need_wireless_suggest(char *iface) {
  FILE *file;
  char line[1024];
  int ret = 0;
  sprintf(line, "/sbin/iwpriv %s get_power 2> /dev/null", iface);
  file = popen(line, "r");
  if (!file)
    return 0;
  while (!feof(file)) {
    memset(line, 0, 1024);
    if (fgets(line, 1023, file) == NULL)
      break;
    if (strstr(line, "Power save level: 6 (AC)")) {
      ret = 1;
      break;
    }
  }
  pclose(file);
  return ret;
}


x86 assembly (clang, -O0):
<need_wireless_suggest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe65(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ce <need_wireless_suggest+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    126b <need_wireless_suggest+0xfb>
jmp    11d3 <need_wireless_suggest+0x63>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f1 <need_wireless_suggest+0x81>
jmp    1259 <need_wireless_suggest+0xe9>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3ff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1228 <need_wireless_suggest+0xb8>
jmp    1259 <need_wireless_suggest+0xe9>
lea    -0x420(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1254 <need_wireless_suggest+0xe4>
movl   $0x1,-0x424(%rbp)
jmp    1259 <need_wireless_suggest+0xe9>
jmp    11d3 <need_wireless_suggest+0x63>
mov    -0x18(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x424(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<need_wireless_suggest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rdx
lea    0xe79(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     1207 <need_wireless_suggest+0x97>
mov    %rax,%rbx
mov    %rsp,%r14
lea    0xe76(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    120b <need_wireless_suggest+0x9b>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0x3ff,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     120d <need_wireless_suggest+0x9d>
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11c0 <need_wireless_suggest+0x50>
mov    $0x1,%ebp
jmp    120d <need_wireless_suggest+0x9d>
xor    %ebp,%ebp
jmp    1215 <need_wireless_suggest+0xa5>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <pclose@plt>
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"/sbin/iwpriv %s get_power 2> /dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Power save level: 6 (AC)\00"
define i32 @need_wireless_suggest(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %6
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %1
store i32 0, i32* %2
br label %39
15: ; preds = %1
br label %16
16: ; preds = %34, %15
%17 = load i32*, i32** %4
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %35
21: ; preds = %16
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 1024)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%25 = load i32*, i32** %4
%26 = call i32* @fgets(i8* %24, i32 1023, i32* %25)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %21
br label %35
29: ; preds = %21
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%31 = call i64 @strstr(i8* %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 1, i32* %6
br label %35
34: ; preds = %29
br label %16
35: ; preds = %33, %28, %16
%36 = load i32*, i32** %4
%37 = call i32 @pclose(i32* %36)
%38 = load i32, i32* %6
store i32 %38, i32* %2
br label %39
39: ; preds = %35, %14
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [39 x i8] c"/sbin/iwpriv %s get_power 2> /dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Power save level: 6 (AC)\00"
define i32 @need_wireless_suggest(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %20, label %7
7: ; preds = %1, %14
%8 = call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = call i32 @memset(i8* %3, i32 0, i32 1024)
%12 = call i32* @fgets(i8* %3, i32 1023, i32* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = call i64 @strstr(i8* %3, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %7, label %17
17: ; preds = %14, %10, %7
%18 = phi i32 [ 0, %10 ], [ 0, %7 ], [ 1, %14 ]
%19 = call i32 @pclose(i32* %5)
br label %20
20: ; preds = %1, %17
%21 = phi i32 [ %18, %17 ], [ 0, %1 ]
ret i32 %21
}