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


x86 assembly (clang, -O0):
<om_gsm_power_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <om_gsm_power_path@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117d <om_gsm_power_swap+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_gsm_power_swap+0x148>
mov    -0x10(%rbp),%rdi
call   1030 <om_sysfs_readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a1 <om_gsm_power_swap+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_gsm_power_swap+0x148>
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11c4 <om_gsm_power_swap+0x74>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1298 <om_gsm_power_swap+0x148>
cmpl   $0x0,-0x8(%rbp)
je     1267 <om_gsm_power_swap+0x117>
mov    $0x0,%al
call   1050 <om_gsm_reset_path@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f0 <om_gsm_power_swap+0xa0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_gsm_power_swap+0x148>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1060 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    1216 <om_gsm_power_swap+0xc6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_gsm_power_swap+0x148>
mov    -0x10(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1060 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    123c <om_gsm_power_swap+0xec>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_gsm_power_swap+0x148>
mov    -0x28(%rbp),%rdi
lea    0xdbc(%rip),%rsi
call   1060 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    1262 <om_gsm_power_swap+0x112>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_gsm_power_swap+0x148>
jmp    1292 <om_gsm_power_swap+0x142>
mov    -0x10(%rbp),%rdi
lea    0xd8e(%rip),%rsi
call   1060 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
jge    128d <om_gsm_power_swap+0x13d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <om_gsm_power_swap+0x148>
jmp    1292 <om_gsm_power_swap+0x142>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<om_gsm_power_swap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <om_gsm_power_path@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11f1 <om_gsm_power_swap+0xa1>
mov    %rax,%rbp
mov    %rax,%rdi
call   1030 <om_sysfs_readfile@plt>
test   %rax,%rax
je     11f1 <om_gsm_power_swap+0xa1>
mov    %rax,%rdi
call   1070 <atoi@plt>
cmp    %ebx,%eax
jne    1190 <om_gsm_power_swap+0x40>
mov    %ebx,%r15d
jmp    11f1 <om_gsm_power_swap+0xa1>
mov    %eax,%r14d
test   %ebx,%ebx
je     11da <om_gsm_power_swap+0x8a>
xor    %eax,%eax
call   1050 <om_gsm_reset_path@plt>
test   %rax,%rax
je     11f1 <om_gsm_power_swap+0xa1>
mov    %rax,%rbx
lea    0xe53(%rip),%rsi
mov    %rbp,%rdi
call   1060 <om_sysfs_writefile@plt>
test   %rax,%rax
js     11f1 <om_gsm_power_swap+0xa1>
lea    0xe42(%rip),%rsi
mov    %rbp,%rdi
call   1060 <om_sysfs_writefile@plt>
test   %rax,%rax
js     11f1 <om_gsm_power_swap+0xa1>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
jmp    11e4 <om_gsm_power_swap+0x94>
lea    0xe1f(%rip),%rsi
mov    %rbp,%rdi
call   1060 <om_sysfs_writefile@plt>
test   %rax,%rax
js     11f1 <om_gsm_power_swap+0xa1>
mov    %r14d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"0\0A\00"
@.str.1 = [3 x i8] c"1\0A\00"
define i32 @om_gsm_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_gsm_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 = 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 %58
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 %58
26: ; preds = %18
%27 = load i32, i32* %3
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %50
29: ; preds = %26
%30 = call i8* (...) @om_gsm_reset_path()
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 -1, i32* %2
br label %58
34: ; preds = %29
%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** %4
%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
%45 = load i8*, i8** %7
%46 = call i64 @om_sysfs_writefile(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %44
store i32 -1, i32* %2
br label %58
49: ; preds = %44
br label %56
50: ; preds = %26
%51 = load i8*, i8** %4
%52 = call i64 @om_sysfs_writefile(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, 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, %49
%57 = load i32, i32* %6
store i32 %57, i32* %2
br label %58
58: ; preds = %56, %54, %48, %43, %38, %33, %24, %17, %11
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"0\0A\00"
@.str.1 = [3 x i8] c"1\0A\00"
define i32 @om_gsm_power_swap(i32 %0) {
%2 = tail call i8* (...) @om_gsm_power_path()
%3 = icmp eq i8* %2, null
br i1 %3, label %28, label %4
4: ; preds = %1
%5 = tail call i8* @om_sysfs_readfile(i8* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %28, label %7
7: ; preds = %4
%8 = tail call i32 @atoi(i8* %5)
%9 = icmp eq i32 %8, %0
br i1 %9, label %28, label %10
10: ; preds = %7
%11 = icmp eq i32 %0, 0
br i1 %11, label %24, label %12
12: ; preds = %10
%13 = tail call i8* (...) @om_gsm_reset_path()
%14 = icmp eq i8* %13, null
br i1 %14, label %28, label %15
15: ; preds = %12
%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* %2, 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 %21
21: ; preds = %18
%22 = tail call i64 @om_sysfs_writefile(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp sgt i64 %22, -1
br i1 %23, label %27, label %28
24: ; preds = %10
%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 %28, label %27
27: ; preds = %24, %21
br label %28
28: ; preds = %4, %18, %15, %12, %24, %7, %21, %27, %1
%29 = phi i32 [ -1, %1 ], [ -1, %4 ], [ %8, %27 ], [ -1, %21 ], [ %0, %7 ], [ -1, %24 ], [ -1, %12 ], [ -1, %15 ], [ -1, %18 ]
ret i32 %29
}