#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*/ SEEK_END;
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int check_bootloader_status() {
  int file = open("/dev/block/platform/msm_sdcc.1/by-name/aboot", O_RDWR);
  char buffer[17];
  lseek(file, -512, SEEK_END);
  read(file, buffer, 17);
  if (buffer[16] == 0) {
    return 0;
  } else if (buffer[16] == 1) {
    return 1;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<check_bootloader_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
lea    0xeb8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e86(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffe00,%esi
call   1030 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x11,%edx
call   1040 <read@plt>
movsbl -0x10(%rbp),%eax
cmp    $0x0,%eax
jne    1190 <check_bootloader_status+0x60>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <check_bootloader_status+0x80>
movsbl -0x10(%rbp),%eax
cmp    $0x1,%eax
jne    11a9 <check_bootloader_status+0x79>
movl   $0x1,-0x4(%rbp)
jmp    11b0 <check_bootloader_status+0x80>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_bootloader_status>:
push   %rbx
sub    $0x20,%rsp
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
lea    0xebb(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xfffffe00,%esi
call   1030 <lseek@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x11,%edx
call   1040 <read@plt>
mov    0x10(%rsp),%cl
xor    %eax,%eax
cmp    $0x1,%cl
sete   %al
lea    (%rax,%rax,1),%edx
add    $0xffffffff,%edx
xor    %eax,%eax
test   %cl,%cl
cmovne %edx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [45 x i8] c"/dev/block/platform/msm_sdcc.1/by-name/aboot\00"
@O_RDWR = global i32 0
@SEEK_END = global i32 0
define i32 @check_bootloader_status() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [17 x i8]
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = load i32, i32* @SEEK_END
%8 = call i32 @lseek(i32 %6, i32 -512, i32 %7)
%9 = load i32, i32* %2
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 17)
%12 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 16
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %0
store i32 0, i32* %1
br label %24
17: ; preds = %0
%18 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 16
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 1, i32* %1
br label %24
23: ; preds = %17
store i32 -1, i32* %1
br label %24
24: ; preds = %23, %22, %16
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [45 x i8] c"/dev/block/platform/msm_sdcc.1/by-name/aboot\00"
@O_RDWR = global i32 0
@SEEK_END = global i32 0
define i32 @check_bootloader_status() {
%1 = alloca [17 x i8]
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @lseek(i32 %3, i32 -512, i32 %5)
%7 = call i32 @read(i32 %3, i8* %4, i32 17)
%8 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 16
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 1
%11 = select i1 %10, i32 1, i32 -1
%12 = icmp eq i8 %9, 0
%13 = select i1 %12, i32 0, i32 %11
ret i32 %13
}