#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 atoi(char const *);
char *om_bt_power_path();
char *om_bt_reset_path();
char *om_sysfs_readfile(char const *);
scalar_t__ om_sysfs_writefile(char const *, char *);
int om_bt_power_swap(int value) {
  const char *power_path = om_bt_power_path();
  if (power_path == NULL)
    return -1;
  const char *reset_path = om_bt_reset_path();
  if (reset_path == NULL)
    return -1;
  const char *val = om_sysfs_readfile(power_path);
  if (val == NULL)
    return -1;
  int old_val = atoi(val);
  if (value == old_val)
    return old_val;
  if (value) {
    if (om_sysfs_writefile(power_path, "1\n") < 0)
      return -1;
    if (om_sysfs_writefile(reset_path, "0\n") < 0)
      return -1;
  } else {
    if (om_sysfs_writefile(reset_path, "1\n") < 0)
      return -1;
    if (om_sysfs_writefile(power_path, "0\n") < 0)
      return -1;
  }
  return old_val;
}


x86 assembly (clang, -O0):
<om_bt_power_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <om_bt_power_path@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117d <om_bt_power_swap+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_bt_power_swap+0x148>
mov    $0x0,%al
call   1030 <om_bt_reset_path@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119f <om_bt_power_swap+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_bt_power_swap+0x148>
mov    -0x10(%rbp),%rdi
call   1040 <om_sysfs_readfile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c3 <om_bt_power_swap+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_bt_power_swap+0x148>
mov    -0x20(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    11e6 <om_bt_power_swap+0x96>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1298 <om_bt_power_swap+0x148>
cmpl   $0x0,-0x8(%rbp)
je     1241 <om_bt_power_swap+0xf1>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1060 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    1216 <om_bt_power_swap+0xc6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_bt_power_swap+0x148>
mov    -0x18(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1060 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    123c <om_bt_power_swap+0xec>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_bt_power_swap+0x148>
jmp    1292 <om_bt_power_swap+0x142>
mov    -0x18(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1060 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    1267 <om_bt_power_swap+0x117>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_bt_power_swap+0x148>
mov    -0x10(%rbp),%rdi
lea    0xd91(%rip),%rsi
call   1060 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    128d <om_bt_power_swap+0x13d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_bt_power_swap+0x148>
jmp    1292 <om_bt_power_swap+0x142>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<om_bt_power_swap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <om_bt_power_path@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11e7 <om_bt_power_swap+0x97>
mov    %rax,%rbp
xor    %eax,%eax
call   1030 <om_bt_reset_path@plt>
test   %rax,%rax
je     11e7 <om_bt_power_swap+0x97>
mov    %rax,%r12
mov    %rbp,%rdi
call   1040 <om_sysfs_readfile@plt>
test   %rax,%rax
je     11e7 <om_bt_power_swap+0x97>
mov    %rax,%rdi
call   1070 <atoi@plt>
cmp    %ebx,%eax
jne    119c <om_bt_power_swap+0x4c>
mov    %ebx,%r15d
jmp    11e7 <om_bt_power_swap+0x97>
mov    %eax,%r14d
lea    0xe5a(%rip),%rsi
test   %ebx,%ebx
je     11c3 <om_bt_power_swap+0x73>
mov    %rbp,%rdi
call   1060 <om_sysfs_writefile@plt>
test   %rax,%rax
js     11e7 <om_bt_power_swap+0x97>
lea    0xe45(%rip),%rsi
mov    %r12,%rdi
jmp    11da <om_bt_power_swap+0x8a>
mov    %r12,%rdi
call   1060 <om_sysfs_writefile@plt>
test   %rax,%rax
js     11e7 <om_bt_power_swap+0x97>
lea    0xe2c(%rip),%rsi
mov    %rbp,%rdi
call   1060 <om_sysfs_writefile@plt>
test   %rax,%rax
js     11e7 <om_bt_power_swap+0x97>
mov    %r14d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"1\0A\00"
@.str.1 = [3 x i8] c"0\0A\00"
define i32 @om_bt_power_swap(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
%8 = call i8* (...) @om_bt_power_path()
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %58
12: ; preds = %1
%13 = call i8* (...) @om_bt_reset_path()
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 -1, i32* %2
br label %58
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = call i8* @om_sysfs_readfile(i8* %18)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 -1, i32* %2
br label %58
23: ; preds = %17
%24 = load i8*, i8** %6
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i32, i32* %3
%27 = load i32, i32* %7
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = load i32, i32* %7
store i32 %30, i32* %2
br label %58
31: ; preds = %23
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %31
%35 = load i8*, i8** %4
%36 = call i64 @om_sysfs_writefile(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 -1, i32* %2
br label %58
39: ; preds = %34
%40 = load i8*, i8** %5
%41 = call i64 @om_sysfs_writefile(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 -1, i32* %2
br label %58
44: ; preds = %39
br label %56
45: ; preds = %31
%46 = load i8*, i8** %5
%47 = call i64 @om_sysfs_writefile(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %45
store i32 -1, i32* %2
br label %58
50: ; preds = %45
%51 = load i8*, i8** %4
%52 = call i64 @om_sysfs_writefile(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %50
store i32 -1, i32* %2
br label %58
55: ; preds = %50
br label %56
56: ; preds = %55, %44
%57 = load i32, i32* %7
store i32 %57, i32* %2
br label %58
58: ; preds = %56, %54, %49, %43, %38, %29, %22, %16, %11
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"1\0A\00"
@.str.1 = [3 x i8] c"0\0A\00"
define i32 @om_bt_power_swap(i32 %0) {
%2 = tail call i8* (...) @om_bt_power_path()
%3 = icmp eq i8* %2, null
br i1 %3, label %28, label %4
4: ; preds = %1
%5 = tail call i8* (...) @om_bt_reset_path()
%6 = icmp eq i8* %5, null
br i1 %6, label %28, label %7
7: ; preds = %4
%8 = tail call i8* @om_sysfs_readfile(i8* %2)
%9 = icmp eq i8* %8, null
br i1 %9, label %28, label %10
10: ; preds = %7
%11 = tail call i32 @atoi(i8* %8)
%12 = icmp eq i32 %11, %0
br i1 %12, label %28, label %13
13: ; preds = %10
%14 = icmp eq i32 %0, 0
br i1 %14, label %21, label %15
15: ; preds = %13
%16 = tail call i64 @om_sysfs_writefile(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp slt i64 %16, 0
br i1 %17, label %28, label %18
18: ; preds = %15
%19 = tail call i64 @om_sysfs_writefile(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp slt i64 %19, 0
br i1 %20, label %28, label %27
21: ; preds = %13
%22 = tail call i64 @om_sysfs_writefile(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp slt i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = tail call i64 @om_sysfs_writefile(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp slt i64 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %24, %18
br label %28
28: ; preds = %4, %27, %10, %15, %18, %21, %24, %7, %1
%29 = phi i32 [ -1, %1 ], [ -1, %4 ], [ -1, %7 ], [ %11, %27 ], [ %0, %10 ], [ -1, %15 ], [ -1, %18 ], [ -1, %21 ], [ -1, %24 ]
ret i32 %29
}