#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usleep(int);
int write(int, char *, int /*<<< orphan*/);
int sec_gps_power(int power) {
  char gpio_power_path[] = "/sys/class/sec/gps/GPS_PWR_EN/value";
  char gpio_on_value[] = "1\n";
  char gpio_off_value[] = "0\n";
  int fd = -1;
  int rc;
  fd = open(gpio_power_path, O_RDWR);
  if (fd < 0)
    return -1;
  if (power) {
    rc = write(fd, gpio_on_value, strlen(gpio_on_value));
  } else {
    rc = write(fd, gpio_off_value, strlen(gpio_off_value));
  }
  if (rc <= 0) {
    close(fd);
    return -1;
  }
  close(fd);
  usleep(250000);
  return 0;
}


x86 assembly (clang, -O0):
<sec_gps_power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe8a(%rip),%rsi
mov    $0x24,%edx
call   1060 <memcpy@plt>
mov    0xe9d(%rip),%ax
mov    %ax,-0x33(%rbp)
mov    0xe95(%rip),%al
mov    %al,-0x31(%rbp)
mov    0xe8c(%rip),%ax
mov    %ax,-0x36(%rbp)
mov    0xe84(%rip),%al
mov    %al,-0x34(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
lea    -0x30(%rbp),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    11da <sec_gps_power+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <sec_gps_power+0x110>
cmpl   $0x0,-0x8(%rbp)
je     1211 <sec_gps_power+0xb1>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x33(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x33(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x40(%rbp)
jmp    1239 <sec_gps_power+0xd9>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x36(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x36(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jg     1257 <sec_gps_power+0xf7>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <sec_gps_power+0x110>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
mov    $0x3d090,%edi
call   1080 <usleep@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sec_gps_power>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %edi,%r14d
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x65756c,0x30(%rsp)
movb   $0x0,0xe(%rsp)
movw   $0xa31,0xc(%rsp)
movb   $0x0,0xa(%rsp)
movw   $0xa30,0x8(%rsp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1060 <open@plt>
mov    $0xffffffff,%r15d
test   %eax,%eax
js     11f3 <sec_gps_power+0xa3>
mov    %eax,%ebp
test   %r14d,%r14d
lea    0x8(%rsp),%rax
lea    0xc(%rsp),%rbx
cmove  %rax,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
test   %ebx,%ebx
jle    11f3 <sec_gps_power+0xa3>
mov    $0x3d090,%edi
call   1070 <usleep@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.sec_gps_power.gpio_power_path = [36 x i8] c"/sys/class/sec/gps/GPS_PWR_EN/value\00"
@__const.sec_gps_power.gpio_on_value = [3 x i8] c"1\0A\00"
@__const.sec_gps_power.gpio_off_value = [3 x i8] c"0\0A\00"
@O_RDWR = global i32 0
define i32 @sec_gps_power(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [36 x i8]
%5 = alloca [3 x i8]
%6 = alloca [3 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
%9 = bitcast [36 x i8]* %4 to i8*
%10 = bitcast [3 x i8]* %5 to i8*
%11 = bitcast [3 x i8]* %6 to i8*
store i32 -1, i32* %7
%12 = getelementptr inbounds [36 x i8], [36 x i8]* %4, i64 0, i64 0
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 -1, i32* %2
br label %43
18: ; preds = %1
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* %7
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @write(i32 %22, i8* %23, i32 %25)
store i32 %26, i32* %8
br label %33
27: ; preds = %18
%28 = load i32, i32* %7
%29 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @write(i32 %28, i8* %29, i32 %31)
store i32 %32, i32* %8
br label %33
33: ; preds = %27, %21
%34 = load i32, i32* %8
%35 = icmp sle i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* %7
%38 = call i32 @close(i32 %37)
store i32 -1, i32* %2
br label %43
39: ; preds = %33
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
%42 = call i32 @usleep(i32 250000)
store i32 0, i32* %2
br label %43
43: ; preds = %39, %36, %17
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@__const.sec_gps_power.gpio_power_path = [36 x i8] c"/sys/class/sec/gps/GPS_PWR_EN/value\00"
@__const.sec_gps_power.gpio_on_value = [3 x i8] c"1\0A\00"
@__const.sec_gps_power.gpio_off_value = [3 x i8] c"0\0A\00"
@O_RDWR = global i32 0
define i32 @sec_gps_power(i32 %0) {
%2 = alloca [36 x i8]
%3 = alloca [3 x i8]
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [36 x i8], [36 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* %5, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %1
%12 = icmp eq i32 %0, 0
%13 = select i1 %12, i8* %7, i8* %6
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @write(i32 %9, i8* %13, i32 %14)
%16 = icmp slt i32 %15, 1
%17 = call i32 @close(i32 %9)
br i1 %16, label %20, label %18
18: ; preds = %11
%19 = call i32 @usleep(i32 250000)
br label %20
20: ; preds = %11, %1, %18
%21 = phi i32 [ 0, %18 ], [ -1, %1 ], [ -1, %11 ]
ret i32 %21
}