#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 EINVAL;
int errno;
int readSector(char const *, int /*<<< orphan*/, int, unsigned char *);
int readBootsect(const char *inputName, unsigned char *bootSect) {
  int status = 0;
  do {
  } while (0);
  status = readSector(inputName, 0, 512, bootSect);
  if (status < 0) {
    do {
    } while (0);
    return (errno = status);
  }
  if ((bootSect[510] != 0x55) || (bootSect[511] != 0xAA)) {
    do {
    } while (0);
    errno = EINVAL;
    return (-1);
  }
  return (errno = status = 0);
}


x86 assembly (clang, -O0):
<readBootsect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    112c <readBootsect+0x1c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
xor    %esi,%esi
mov    $0x200,%edx
call   1030 <readSector@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    116b <readBootsect+0x5b>
jmp    1152 <readBootsect+0x42>
jmp    1157 <readBootsect+0x47>
mov    -0x1c(%rbp),%eax
mov    0x2e7f(%rip),%rcx
mov    %eax,(%rcx)
mov    %eax,-0x4(%rbp)
jmp    11d8 <readBootsect+0xc8>
mov    -0x18(%rbp),%rax
movzbl 0x1fe(%rax),%eax
cmp    $0x55,%eax
jne    1195 <readBootsect+0x85>
mov    -0x18(%rbp),%rax
movzbl 0x1ff(%rax),%eax
cmp    $0xaa,%eax
je     11bd <readBootsect+0xad>
jmp    119a <readBootsect+0x8a>
jmp    119f <readBootsect+0x8f>
mov    0x2e32(%rip),%rax
mov    (%rax),%ecx
mov    0x2e31(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <readBootsect+0xc8>
movl   $0x0,-0x1c(%rbp)
mov    0x2e15(%rip),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readBootsect>:
push   %rbx
mov    %rsi,%rbx
xor    %esi,%esi
mov    $0x200,%edx
mov    %rbx,%rcx
call   1030 <readSector@plt>
test   %eax,%eax
js     1150 <readBootsect+0x40>
cmpb   $0x55,0x1fe(%rbx)
jne    1140 <readBootsect+0x30>
xor    %eax,%eax
cmpb   $0xaa,0x1ff(%rbx)
mov    $0x0,%ecx
je     1152 <readBootsect+0x42>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    $0xffffffff,%ecx
jmp    1152 <readBootsect+0x42>
mov    %eax,%ecx
mov    0x2e87(%rip),%rdx
mov    %eax,(%rdx)
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i32 0
@EINVAL = global i32 0
define i32 @readBootsect(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %2
br label %8
8: ; preds = %7
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i32 @readSector(i8* %9, i32 0, i32 512, i8* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %8
br label %15
15: ; preds = %14
br label %16
16: ; preds = %15
%17 = load i32, i32* %6
store i32 %17, i32* @errno
store i32 %17, i32* %3
br label %35
18: ; preds = %8
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 510
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp ne i32 %22, 85
br i1 %23, label %30, label %24
24: ; preds = %18
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 511
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = icmp ne i32 %28, 170
br i1 %29, label %30, label %34
30: ; preds = %24, %18
br label %31
31: ; preds = %30
br label %32
32: ; preds = %31
%33 = load i32, i32* @EINVAL
store i32 %33, i32* @errno
store i32 -1, i32* %3
br label %35
34: ; preds = %24
store i32 0, i32* %6
store i32 0, i32* @errno
store i32 0, i32* %3
br label %35
35: ; preds = %34, %32, %16
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@errno = global i32 0
@EINVAL = global i32 0
define i32 @readBootsect(i8* %0, i8* %1) {
%3 = tail call i32 @readSector(i8* %0, i32 0, i32 512, i8* %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %1, i64 510
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 85
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %1, i64 511
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, -86
br i1 %12, label %15, label %13
13: ; preds = %5, %9
%14 = load i32, i32* @EINVAL
br label %15
15: ; preds = %9, %2, %13
%16 = phi i32 [ %14, %13 ], [ %3, %2 ], [ 0, %9 ]
%17 = phi i32 [ -1, %13 ], [ %3, %2 ], [ 0, %9 ]
store i32 %16, i32* @errno
ret i32 %17
}