#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) {
        printf("Set Wi-Fi power up error!!!\n");
        return;
      }
    } else {
      if (ioctl(fd, _IO('m', 2)) < 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    $0x10,%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     120a <set_wifi_power+0xba>
cmpl   $0x1,-0x4(%rbp)
jne    11c6 <set_wifi_power+0x76>
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    11c1 <set_wifi_power+0x71>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
jmp    121e <set_wifi_power+0xce>
jmp    1205 <set_wifi_power+0xb5>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x6d,%edi
mov    $0x2,%esi
call   1040 <_IO@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1200 <set_wifi_power+0xb0>
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
jmp    121e <set_wifi_power+0xce>
jmp    1205 <set_wifi_power+0xb5>
jmp    1216 <set_wifi_power+0xc6>
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
add    $0x10,%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     119c <set_wifi_power+0x4c>
mov    $0x6d,%edi
cmp    $0x1,%ebp
jne    11aa <set_wifi_power+0x5a>
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
test   %rax,%rax
jns    11c2 <set_wifi_power+0x72>
lea    0xeab(%rip),%rdi
jmp    11d6 <set_wifi_power+0x86>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
jmp    11c2 <set_wifi_power+0x72>
mov    $0x2,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
test   %rax,%rax
js     11cf <set_wifi_power+0x7f>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <close@plt>
lea    0xe51(%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 %28
8: ; preds = %1
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %19
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 %18
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %33
18: ; preds = %11
br label %27
19: ; preds = %8
%20 = load i32, i32* %3
%21 = call i32 @_IO(i8 signext 109, i32 2)
%22 = call i64 @ioctl(i32 %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %33
26: ; preds = %19
br label %27
27: ; preds = %26, %18
br label %30
28: ; preds = %1
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %27
%31 = load i32, i32* %3
%32 = call i32 @close(i32 %31)
br label %33
33: ; preds = %30, %24, %16
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 %19, label %5
5: ; preds = %1
%6 = icmp eq i32 %0, 1
br i1 %6, label %7, label %13
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 %21
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.5, i64 0, i64 0))
br label %23
13: ; preds = %5
%14 = tail call i32 @_IO(i8 signext 109, i32 2)
%15 = tail call i64 @ioctl(i32 %3, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.4, i64 0, i64 0))
br label %23
19: ; preds = %1
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %7, %13, %19
%22 = tail call i32 @close(i32 %3)
br label %23
23: ; preds = %21, %17, %11
ret void
}