#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 */
typedef int uint8_t;
typedef int off_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int check_for_valid_mbr(const uint8_t *sector, off_t size) {
  if (size < 512) {
    fprintf(stderr, "MBR too small to be valid\n");
    return -1;
  }
  if ((sector[510] != 0x55) || (sector[510 + 1] != 0xAA)) {
    fprintf(stderr, "No MBR signature found\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_for_valid_mbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x200,-0x14(%rbp)
jge    114d <check_for_valid_mbr+0x3d>
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
lea    0xec4(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <check_for_valid_mbr+0x8a>
mov    -0x10(%rbp),%rax
cmpl   $0x55,0x7f8(%rax)
jne    1172 <check_for_valid_mbr+0x62>
mov    -0x10(%rbp),%rax
cmpl   $0xaa,0x7fc(%rax)
je     1193 <check_for_valid_mbr+0x83>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <check_for_valid_mbr+0x8a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_for_valid_mbr>:
push   %rax
cmp    $0x200,%esi
jge    1122 <check_for_valid_mbr+0x12>
lea    0xee0(%rip),%rsi
jmp    1140 <check_for_valid_mbr+0x30>
lea    0xef2(%rip),%rsi
cmpl   $0x55,0x7f8(%rdi)
jne    1140 <check_for_valid_mbr+0x30>
xor    %eax,%eax
cmpl   $0xaa,0x7fc(%rdi)
je     1153 <check_for_valid_mbr+0x43>
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"MBR too small to be valid\0A\00"
@.str.1 = [24 x i8] c"No MBR signature found\0A\00"
define i32 @check_for_valid_mbr(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp slt i32 %6, 512
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %25
11: ; preds = %2
%12 = load i32*, i32** %4
%13 = getelementptr inbounds i32, i32* %12, i64 510
%14 = load i32, i32* %13
%15 = icmp ne i32 %14, 85
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i64 511
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, 170
br i1 %20, label %21, label %24
21: ; preds = %16, %11
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %25
24: ; preds = %16
store i32 0, i32* %3
br label %25
25: ; preds = %24, %21, %8
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"MBR too small to be valid\0A\00"
@.str.1 = [24 x i8] c"No MBR signature found\0A\00"
define i32 @check_for_valid_mbr(i32* nocapture %0, i32 %1) {
%3 = icmp slt i32 %1, 512
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = getelementptr inbounds i32, i32* %0, i64 510
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 85
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = getelementptr inbounds i32, i32* %0, i64 511
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 170
br i1 %11, label %16, label %12
12: ; preds = %4, %8, %2
%13 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %4 ]
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* %13)
br label %16
16: ; preds = %12, %8
%17 = phi i32 [ 0, %8 ], [ -1, %12 ]
ret i32 %17
}