#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*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int wifi_led_off() {
  int fh;
  int fd1;
  fd1 = open("/proc/led_net_ioctl", 0);
  if (fd1 < 0) {
    printf("can't open led_net_ioctl\n");
    return -1;
  }
  ioctl(fd1, 0);
  close(fd1);
  fh = open("/proc/led_upgrade_ioctl", O_RDWR);
  if (fh < 0) {
    printf("fh null .\n");
    return -1;
  }
  ioctl(fh, 0);
  close(fh);
  return 0;
}


x86 assembly (clang, -O0):
<wifi_led_off>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    117b <wifi_led_off+0x3b>
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <wifi_led_off+0xa0>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1040 <ioctl@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c7 <wifi_led_off+0x87>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <wifi_led_off+0xa0>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1040 <ioctl@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wifi_led_off>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
test   %eax,%eax
js     1196 <wifi_led_off+0x56>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %eax,%edi
xor    %esi,%esi
call   1040 <ioctl@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     119f <wifi_led_off+0x5f>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
call   1040 <ioctl@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11b0 <wifi_led_off+0x70>
lea    0xe99(%rip),%rdi
jmp    11a6 <wifi_led_off+0x66>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/proc/led_net_ioctl\00"
@.str.1 = [26 x i8] c"can't open led_net_ioctl\0A\00"
@.str.2 = [24 x i8] c"/proc/led_upgrade_ioctl\00"
@O_RDWR = global i32 0
@.str.3 = [11 x i8] c"fh null .\0A\00"
define i32 @wifi_led_off() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %25
9: ; preds = %0
%10 = load i32, i32* %3
%11 = call i32 @ioctl(i32 %10, i32 0)
%12 = load i32, i32* %3
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %25
20: ; preds = %9
%21 = load i32, i32* %2
%22 = call i32 @ioctl(i32 %21, i32 0)
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
store i32 0, i32* %1
br label %25
25: ; preds = %20, %18, %7
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [20 x i8] c"/proc/led_net_ioctl\00"
@.str.2 = [24 x i8] c"/proc/led_upgrade_ioctl\00"
@O_RDWR = global i32 0
@str = [10 x i8] c"fh null .\00"
@str.4 = [25 x i8] c"can't open led_net_ioctl\00"
define i32 @wifi_led_off() {
%1 = tail call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 0)
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
br label %16
5: ; preds = %0
%6 = tail call i32 @ioctl(i32 %1, i32 0)
%7 = tail call i32 @close(i32 %1)
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %16
13: ; preds = %5
%14 = tail call i32 @ioctl(i32 %9, i32 0)
%15 = tail call i32 @close(i32 %9)
br label %16
16: ; preds = %13, %11, %3
%17 = phi i32 [ -1, %3 ], [ -1, %11 ], [ 0, %13 ]
ret i32 %17
}