#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_gps_power_path();
char *om_sysfs_readfile(char const *);
scalar_t__ om_sysfs_writefile(char const *, char *);
int om_gps_power_swap(int value) {
  const char *power_path = om_gps_power_path();
  if (power_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;
  } else {
    if (om_sysfs_writefile(power_path, "0\n") < 0)
      return -1;
    const char *val = om_sysfs_readfile(power_path);
    if (val == NULL)
      return -1;
    if (val[0] == '1') {
      if (om_sysfs_writefile(power_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_gps_power_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <om_gps_power_path@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <om_gps_power_swap+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    129f <om_gps_power_swap+0x15f>
mov    -0x10(%rbp),%rdi
call   1030 <om_sysfs_readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1191 <om_gps_power_swap+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    129f <om_gps_power_swap+0x15f>
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11b4 <om_gps_power_swap+0x74>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    129f <om_gps_power_swap+0x15f>
cmpl   $0x0,-0x8(%rbp)
je     11e9 <om_gps_power_swap+0xa9>
mov    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1050 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    11e4 <om_gps_power_swap+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    129f <om_gps_power_swap+0x15f>
jmp    1299 <om_gps_power_swap+0x159>
mov    -0x10(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1050 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    120f <om_gps_power_swap+0xcf>
movl   $0xffffffff,-0x4(%rbp)
jmp    129f <om_gps_power_swap+0x15f>
mov    -0x10(%rbp),%rdi
call   1030 <om_sysfs_readfile@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1233 <om_gps_power_swap+0xf3>
movl   $0xffffffff,-0x4(%rbp)
jmp    129f <om_gps_power_swap+0x15f>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    1294 <om_gps_power_swap+0x154>
mov    -0x10(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1050 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    1269 <om_gps_power_swap+0x129>
movl   $0xffffffff,-0x4(%rbp)
jmp    129f <om_gps_power_swap+0x15f>
mov    -0x10(%rbp),%rdi
lea    0xd8f(%rip),%rsi
call   1050 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    128f <om_gps_power_swap+0x14f>
movl   $0xffffffff,-0x4(%rbp)
jmp    129f <om_gps_power_swap+0x15f>
jmp    1294 <om_gps_power_swap+0x154>
jmp    1299 <om_gps_power_swap+0x159>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<om_gps_power_swap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <om_gps_power_path@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11e3 <om_gps_power_swap+0xa3>
mov    %rax,%rbp
mov    %rax,%rdi
call   1030 <om_sysfs_readfile@plt>
test   %rax,%rax
je     11e3 <om_gps_power_swap+0xa3>
mov    %rax,%rdi
call   1060 <atoi@plt>
cmp    %ebx,%eax
jne    1180 <om_gps_power_swap+0x40>
mov    %ebx,%r15d
jmp    11e3 <om_gps_power_swap+0xa3>
mov    %eax,%r14d
test   %ebx,%ebx
je     11a0 <om_gps_power_swap+0x60>
lea    0xe72(%rip),%rsi
mov    %rbp,%rdi
call   1050 <om_sysfs_writefile@plt>
test   %rax,%rax
js     11e3 <om_gps_power_swap+0xa3>
mov    %r14d,%r15d
jmp    11e3 <om_gps_power_swap+0xa3>
lea    0xe5c(%rip),%rsi
mov    %rbp,%rdi
call   1050 <om_sysfs_writefile@plt>
test   %rax,%rax
js     11e3 <om_gps_power_swap+0xa3>
mov    %rbp,%rdi
call   1030 <om_sysfs_readfile@plt>
test   %rax,%rax
je     11e3 <om_gps_power_swap+0xa3>
cmpb   $0x31,(%rax)
jne    119b <om_gps_power_swap+0x5b>
lea    0xe33(%rip),%rsi
mov    %rbp,%rdi
call   1050 <om_sysfs_writefile@plt>
test   %rax,%rax
js     11e3 <om_gps_power_swap+0xa3>
lea    0xe22(%rip),%rsi
jmp    118e <om_gps_power_swap+0x4e>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
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_gps_power_swap(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
%8 = call i8* (...) @om_gps_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 %66
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i8* @om_sysfs_readfile(i8* %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 -1, i32* %2
br label %66
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %3
%22 = load i32, i32* %6
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i32, i32* %6
store i32 %25, i32* %2
br label %66
26: ; preds = %18
%27 = load i32, i32* %3
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i8*, i8** %4
%31 = call i64 @om_sysfs_writefile(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 -1, i32* %2
br label %66
34: ; preds = %29
br label %64
35: ; preds = %26
%36 = load i8*, i8** %4
%37 = call i64 @om_sysfs_writefile(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 -1, i32* %2
br label %66
40: ; preds = %35
%41 = load i8*, i8** %4
%42 = call i8* @om_sysfs_readfile(i8* %41)
store i8* %42, i8** %7
%43 = load i8*, i8** %7
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %46
45: ; preds = %40
store i32 -1, i32* %2
br label %66
46: ; preds = %40
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 49
br i1 %51, label %52, label %63
52: ; preds = %46
%53 = load i8*, i8** %4
%54 = call i64 @om_sysfs_writefile(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %52
store i32 -1, i32* %2
br label %66
57: ; preds = %52
%58 = load i8*, i8** %4
%59 = call i64 @om_sysfs_writefile(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %57
store i32 -1, i32* %2
br label %66
62: ; preds = %57
br label %63
63: ; preds = %62, %46
br label %64
64: ; preds = %63, %34
%65 = load i32, i32* %6
store i32 %65, i32* %2
br label %66
66: ; preds = %64, %61, %56, %45, %39, %33, %24, %17, %11
%67 = load i32, i32* %2
ret i32 %67
}

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