#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_keep_on_in_suspend_path();
char *om_sysfs_readfile(char const *);
scalar_t__ om_sysfs_writefile(char const *, char *);
int om_gps_keep_on_in_suspend_swap(int value) {
  const char *keep_on_in_suspend_path = om_gps_keep_on_in_suspend_path();
  if (keep_on_in_suspend_path == NULL)
    return -1;
  const char *val = om_sysfs_readfile(keep_on_in_suspend_path);
  if (val == NULL)
    return -1;
  int old_val = atoi(val);
  if (value == old_val)
    return old_val;
  if (om_sysfs_writefile(keep_on_in_suspend_path, value ? "1\n" : "0\n") < 0)
    return -1;
  return old_val;
}


x86 assembly (clang, -O0):
<om_gps_keep_on_in_suspend_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <om_gps_keep_on_in_suspend_path@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <om_gps_keep_on_in_suspend_swap+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <om_gps_keep_on_in_suspend_swap+0xb1>
mov    -0x10(%rbp),%rdi
call   1030 <om_sysfs_readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1191 <om_gps_keep_on_in_suspend_swap+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <om_gps_keep_on_in_suspend_swap+0xb1>
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11b4 <om_gps_keep_on_in_suspend_swap+0x74>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <om_gps_keep_on_in_suspend_swap+0xb1>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%ecx
lea    0xe41(%rip),%rsi
lea    0xe37(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1050 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    11eb <om_gps_keep_on_in_suspend_swap+0xab>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <om_gps_keep_on_in_suspend_swap+0xb1>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<om_gps_keep_on_in_suspend_swap>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %eax,%eax
call   1040 <om_gps_keep_on_in_suspend_path@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11a4 <om_gps_keep_on_in_suspend_swap+0x64>
mov    %rax,%rbp
mov    %rax,%rdi
call   1030 <om_sysfs_readfile@plt>
test   %rax,%rax
je     11a4 <om_gps_keep_on_in_suspend_swap+0x64>
mov    %rax,%rdi
call   1060 <atoi@plt>
cmp    %r14d,%eax
jne    117a <om_gps_keep_on_in_suspend_swap+0x3a>
mov    %r14d,%ebx
jmp    11a4 <om_gps_keep_on_in_suspend_swap+0x64>
mov    %eax,%ebx
test   %r14d,%r14d
lea    0xe7d(%rip),%rax
lea    0xe73(%rip),%rsi
cmove  %rax,%rsi
mov    %rbp,%rdi
call   1050 <om_sysfs_writefile@plt>
test   %rax,%rax
mov    $0xffffffff,%eax
cmovs  %eax,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
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_keep_on_in_suspend_swap(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
%7 = call i8* (...) @om_gps_keep_on_in_suspend_path()
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %36
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i8* @om_sysfs_readfile(i8* %12)
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 = %11
store i32 -1, i32* %2
br label %36
17: ; preds = %11
%18 = load i8*, i8** %5
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %3
%21 = load i32, i32* %6
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = load i32, i32* %6
store i32 %24, i32* %2
br label %36
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = load i32, i32* %3
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%31 = call i64 @om_sysfs_writefile(i8* %26, i8* %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %25
store i32 -1, i32* %2
br label %36
34: ; preds = %25
%35 = load i32, i32* %6
store i32 %35, i32* %2
br label %36
36: ; preds = %34, %33, %23, %16, %10
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [3 x i8] c"1\0A\00"
@.str.1 = [3 x i8] c"0\0A\00"
define i32 @om_gps_keep_on_in_suspend_swap(i32 %0) {
%2 = tail call i8* (...) @om_gps_keep_on_in_suspend_path()
%3 = icmp eq i8* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call i8* @om_sysfs_readfile(i8* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %4
%8 = tail call i32 @atoi(i8* %5)
%9 = icmp eq i32 %8, %0
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = icmp eq i32 %0, 0
%12 = select i1 %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%13 = tail call i64 @om_sysfs_writefile(i8* %2, i8* %12)
%14 = icmp slt i64 %13, 0
%15 = select i1 %14, i32 -1, i32 %8
br label %16
16: ; preds = %4, %10, %7, %1
%17 = phi i32 [ -1, %1 ], [ -1, %4 ], [ %0, %7 ], [ %15, %10 ]
ret i32 %17
}