#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 *);
scalar_t__ rfkill_enabled();
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;
  if (rfkill_enabled())
    return 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)
mov    $0x0,%al
call   1040 <rfkill_enabled@plt>
cmp    $0x0,%rax
je     11b6 <need_wireless_suggest+0x36>
movl   $0x0,-0x4(%rbp)
jmp    1298 <need_wireless_suggest+0x118>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe38(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fb <need_wireless_suggest+0x7b>
movl   $0x0,-0x4(%rbp)
jmp    1298 <need_wireless_suggest+0x118>
jmp    1200 <need_wireless_suggest+0x80>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    121e <need_wireless_suggest+0x9e>
jmp    1286 <need_wireless_suggest+0x106>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3ff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1255 <need_wireless_suggest+0xd5>
jmp    1286 <need_wireless_suggest+0x106>
lea    -0x420(%rbp),%rdi
lea    0xdc6(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1281 <need_wireless_suggest+0x101>
movl   $0x1,-0x424(%rbp)
jmp    1286 <need_wireless_suggest+0x106>
jmp    1200 <need_wireless_suggest+0x80>
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   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <rfkill_enabled@plt>
test   %rax,%rax
jne    1231 <need_wireless_suggest+0xb1>
lea    0xe56(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   1090 <sprintf@plt>
lea    0xe68(%rip),%rsi
mov    %r15,%rdi
call   1080 <popen@plt>
test   %rax,%rax
je     1231 <need_wireless_suggest+0xb1>
mov    %rax,%r14
mov    %rsp,%r15
lea    0xe50(%rip),%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1227 <need_wireless_suggest+0xa7>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    $0x3ff,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1229 <need_wireless_suggest+0xa9>
mov    %r15,%rdi
mov    %r12,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11e0 <need_wireless_suggest+0x60>
mov    $0x1,%ebx
jmp    1229 <need_wireless_suggest+0xa9>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <pclose@plt>
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 = call i64 (...) @rfkill_enabled()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %43
10: ; preds = %1
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = call i32* @popen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %4
%16 = load i32*, i32** %4
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %10
store i32 0, i32* %2
br label %43
19: ; preds = %10
br label %20
20: ; preds = %38, %19
%21 = load i32*, i32** %4
%22 = call i32 @feof(i32* %21)
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %25, label %39
25: ; preds = %20
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 0, i32 1024)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = load i32*, i32** %4
%30 = call i32* @fgets(i8* %28, i32 1023, i32* %29)
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %33
32: ; preds = %25
br label %39
33: ; preds = %25
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%35 = call i64 @strstr(i8* %34, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 1, i32* %6
br label %39
38: ; preds = %33
br label %20
39: ; preds = %37, %32, %20
%40 = load i32*, i32** %4
%41 = call i32 @pclose(i32* %40)
%42 = load i32, i32* %6
store i32 %42, i32* %2
br label %43
43: ; preds = %39, %18, %9
%44 = load i32, i32* %2
ret i32 %44
}

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 = tail call i64 (...) @rfkill_enabled()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %23
6: ; preds = %1
%7 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %23, label %10
10: ; preds = %6, %17
%11 = call i32 @feof(i32* %8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = call i32 @memset(i8* %3, i32 0, i32 1024)
%15 = call i32* @fgets(i8* %3, i32 1023, i32* %8)
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i64 @strstr(i8* %3, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %10, label %20
20: ; preds = %17, %13, %10
%21 = phi i32 [ 0, %13 ], [ 0, %10 ], [ 1, %17 ]
%22 = call i32 @pclose(i32* %8)
br label %23
23: ; preds = %6, %1, %20
%24 = phi i32 [ %21, %20 ], [ 0, %1 ], [ 0, %6 ]
ret i32 %24
}