#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 */
scalar_t__ om_sysfs_writefile(char *, char *);
int om_wifi_power_get();
int om_wifi_power_swap(int value) {
  int old_val = om_wifi_power_get();
  if (value == old_val)
    return old_val;
  if (value) {
    if (om_sysfs_writefile("/sys/bus/platform/drivers/s3c2440-sdi"
                           "/bind",
                           "s3c2440-sdi\n") < 0)
      return -1;
  } else {
    if (om_sysfs_writefile("/sys/bus/platform/drivers/s3c2440-sdi"
                           "/unbind",
                           "s3c2440-sdi\n") < 0)
      return -1;
  }
  return old_val;
}


x86 assembly (clang, -O0):
<om_wifi_power_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <om_wifi_power_get@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    114c <om_wifi_power_swap+0x2c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b8 <om_wifi_power_swap+0x98>
cmpl   $0x0,-0x8(%rbp)
je     1184 <om_wifi_power_swap+0x64>
lea    0xea3(%rip),%rdi
lea    0xec7(%rip),%rsi
call   1030 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    117f <om_wifi_power_swap+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <om_wifi_power_swap+0x98>
jmp    11b2 <om_wifi_power_swap+0x92>
lea    0xead(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1030 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    11ad <om_wifi_power_swap+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <om_wifi_power_swap+0x98>
jmp    11b2 <om_wifi_power_swap+0x92>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<om_wifi_power_swap>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <om_wifi_power_get@plt>
cmp    %ebp,%eax
je     1160 <om_wifi_power_swap+0x40>
mov    %eax,%ebx
test   %ebp,%ebp
je     113f <om_wifi_power_swap+0x1f>
lea    0xec3(%rip),%rdi
jmp    1146 <om_wifi_power_swap+0x26>
lea    0xef2(%rip),%rdi
lea    0xede(%rip),%rsi
call   1030 <om_sysfs_writefile@plt>
test   %rax,%rax
js     115b <om_wifi_power_swap+0x3b>
mov    %ebx,%ebp
jmp    1160 <om_wifi_power_swap+0x40>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"/sys/bus/platform/drivers/s3c2440-sdi/bind\00"
@.str.1 = [13 x i8] c"s3c2440-sdi\0A\00"
@.str.2 = [45 x i8] c"/sys/bus/platform/drivers/s3c2440-sdi/unbind\00"
define i32 @om_wifi_power_swap(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = call i32 (...) @om_wifi_power_get()
store i32 %5, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* %4
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32, i32* %4
store i32 %10, i32* %2
br label %26
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = call i64 @om_sysfs_writefile(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 -1, i32* %2
br label %26
18: ; preds = %14
br label %24
19: ; preds = %11
%20 = call i64 @om_sysfs_writefile(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 -1, i32* %2
br label %26
23: ; preds = %19
br label %24
24: ; preds = %23, %18
%25 = load i32, i32* %4
store i32 %25, i32* %2
br label %26
26: ; preds = %24, %22, %17, %9
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [43 x i8] c"/sys/bus/platform/drivers/s3c2440-sdi/bind\00"
@.str.1 = [13 x i8] c"s3c2440-sdi\0A\00"
@.str.2 = [45 x i8] c"/sys/bus/platform/drivers/s3c2440-sdi/unbind\00"
define i32 @om_wifi_power_swap(i32 %0) {
%2 = tail call i32 (...) @om_wifi_power_get()
%3 = icmp eq i32 %2, %0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = icmp eq i32 %0, 0
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = tail call i64 @om_sysfs_writefile(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp slt i64 %7, 0
br i1 %8, label %13, label %12
9: ; preds = %4
%10 = tail call i64 @om_sysfs_writefile(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp slt i64 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %9, %6
br label %13
13: ; preds = %9, %6, %1, %12
%14 = phi i32 [ %2, %12 ], [ %0, %1 ], [ -1, %6 ], [ -1, %9 ]
ret i32 %14
}