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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void set_wifi_power(int on) {
  int fd;
  fd = open("/dev/wifi_power", O_RDWR);
  if (fd != -1) {
    if (on == 1) {
      if (ioctl(fd, _IO('m', 1)) < 0) {
        if (ioctl(fd, _IO('m', 3)) < 0) {
          printf("Set Wi-Fi power up error!!!\n");
          return;
        }
      }
    } else {
      if (ioctl(fd, _IO('m', 2)) < 0) {
        if (ioctl(fd, _IO('m', 4)) < 0) {
          printf("Set Wi-Fi power down error!!!\n");
          return;
        }
      }
    }
  } else {
    printf("Device open failed !!!\n");
  }
  close(fd);
  return;
}


x86 assembly (clang, -O0):
<set_wifi_power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     1266 <set_wifi_power+0x116>
cmpl   $0x1,-0x4(%rbp)
jne    11f4 <set_wifi_power+0xa4>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x6d,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    11ef <set_wifi_power+0x9f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x6d,%edi
mov    $0x3,%esi
call   1040 <_IO@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    11ea <set_wifi_power+0x9a>
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
jmp    127a <set_wifi_power+0x12a>
jmp    11ef <set_wifi_power+0x9f>
jmp    1261 <set_wifi_power+0x111>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x6d,%edi
mov    $0x2,%esi
call   1040 <_IO@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    125c <set_wifi_power+0x10c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x6d,%edi
mov    $0x4,%esi
call   1040 <_IO@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1257 <set_wifi_power+0x107>
lea    0xde0(%rip),%rdi
call   1030 <printf@plt>
jmp    127a <set_wifi_power+0x12a>
jmp    125c <set_wifi_power+0x10c>
jmp    1261 <set_wifi_power+0x111>
jmp    1272 <set_wifi_power+0x122>
lea    0xddf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_wifi_power>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11b9 <set_wifi_power+0x69>
mov    $0x6d,%edi
cmp    $0x1,%ebp
jne    11c7 <set_wifi_power+0x77>
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
test   %rax,%rax
jns    11fc <set_wifi_power+0xac>
mov    $0x6d,%edi
mov    $0x3,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
test   %rax,%rax
jns    11fc <set_wifi_power+0xac>
lea    0xe8e(%rip),%rdi
jmp    1210 <set_wifi_power+0xc0>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
jmp    11fc <set_wifi_power+0xac>
mov    $0x2,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
test   %rax,%rax
jns    11fc <set_wifi_power+0xac>
mov    $0x6d,%edi
mov    $0x4,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
test   %rax,%rax
js     1209 <set_wifi_power+0xb9>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <close@plt>
lea    0xe17(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/wifi_power\00"
@O_RDWR = global i32 0
@.str.1 = [29 x i8] c"Set Wi-Fi power up error!!!\0A\00"
@.str.2 = [31 x i8] c"Set Wi-Fi power down error!!!\0A\00"
@.str.3 = [24 x i8] c"Device open failed !!!\0A\00"
define void @set_wifi_power(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, -1
br i1 %7, label %8, label %40
8: ; preds = %1
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i32, i32* %3
%13 = call i32 @_IO(i8 signext 109, i32 1)
%14 = call i64 @ioctl(i32 %12, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i32, i32* %3
%18 = call i32 @_IO(i8 signext 109, i32 3)
%19 = call i64 @ioctl(i32 %17, i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %45
23: ; preds = %16
br label %24
24: ; preds = %23, %11
br label %39
25: ; preds = %8
%26 = load i32, i32* %3
%27 = call i32 @_IO(i8 signext 109, i32 2)
%28 = call i64 @ioctl(i32 %26, i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %25
%31 = load i32, i32* %3
%32 = call i32 @_IO(i8 signext 109, i32 4)
%33 = call i64 @ioctl(i32 %31, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %45
37: ; preds = %30
br label %38
38: ; preds = %37, %25
br label %39
39: ; preds = %38, %24
br label %42
40: ; preds = %1
%41 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %39
%43 = load i32, i32* %3
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %42, %35, %21
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/wifi_power\00"
@O_RDWR = global i32 0
@str = [23 x i8] c"Device open failed !!!\00"
@str.4 = [30 x i8] c"Set Wi-Fi power down error!!!\00"
@str.5 = [28 x i8] c"Set Wi-Fi power up error!!!\00"
define void @set_wifi_power(i32 %0) {
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %27, label %5
5: ; preds = %1
%6 = icmp eq i32 %0, 1
br i1 %6, label %7, label %17
7: ; preds = %5
%8 = tail call i32 @_IO(i8 signext 109, i32 1)
%9 = tail call i64 @ioctl(i32 %3, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %29
11: ; preds = %7
%12 = tail call i32 @_IO(i8 signext 109, i32 3)
%13 = tail call i64 @ioctl(i32 %3, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.5, i64 0, i64 0))
br label %31
17: ; preds = %5
%18 = tail call i32 @_IO(i8 signext 109, i32 2)
%19 = tail call i64 @ioctl(i32 %3, i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = tail call i32 @_IO(i8 signext 109, i32 4)
%23 = tail call i64 @ioctl(i32 %3, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.4, i64 0, i64 0))
br label %31
27: ; preds = %1
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %11, %7, %21, %17, %27
%30 = tail call i32 @close(i32 %3)
br label %31
31: ; preds = %29, %25, %15
ret void
}