#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*/ fprintf(int /*<<< orphan*/, char *, int);
int get_specification();
int /*<<< orphan*/ stderr;
int get_xloader_offset() {
  int spec = get_specification();
  if (spec < 0) {
    return -1;
  }
  if (spec & 0x1 && spec & 0x8) {
    return 0;
  } else if (spec & 0x1 && spec & 0x4 && !(spec & 0x10)) {
    return 0x20000;
  } else if (spec & 0x1 && spec & 0x4 && spec & 0x10) {
    return 0x20000 * 2;
  } else if (spec & 0x2 && spec & 0x4) {
    return 0x20000 * 3;
  }
  fprintf(stderr, "Unsupported spec for bootloader.img: %d", spec);
  return -1;
}


x86 assembly (clang, -O0):
<get_xloader_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <get_specification@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1148 <get_xloader_offset+0x28>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <get_xloader_offset+0x11c>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1172 <get_xloader_offset+0x52>
mov    -0x8(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1172 <get_xloader_offset+0x52>
movl   $0x0,-0x4(%rbp)
jmp    123c <get_xloader_offset+0x11c>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11ab <get_xloader_offset+0x8b>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11ab <get_xloader_offset+0x8b>
mov    -0x8(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
jne    11ab <get_xloader_offset+0x8b>
movl   $0x20000,-0x4(%rbp)
jmp    123c <get_xloader_offset+0x11c>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11e4 <get_xloader_offset+0xc4>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11e4 <get_xloader_offset+0xc4>
mov    -0x8(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     11e4 <get_xloader_offset+0xc4>
movl   $0x40000,-0x4(%rbp)
jmp    123c <get_xloader_offset+0x11c>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     120e <get_xloader_offset+0xee>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     120e <get_xloader_offset+0xee>
movl   $0x60000,-0x4(%rbp)
jmp    123c <get_xloader_offset+0x11c>
jmp    1213 <get_xloader_offset+0xf3>
jmp    1218 <get_xloader_offset+0xf8>
jmp    121d <get_xloader_offset+0xfd>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xdd0(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_xloader_offset>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <get_specification@plt>
test   %eax,%eax
js     1175 <get_xloader_offset+0x55>
mov    %eax,%ecx
not    %ecx
test   $0x9,%cl
je     117a <get_xloader_offset+0x5a>
mov    %eax,%edx
and    $0x15,%edx
cmp    $0x5,%edx
je     114d <get_xloader_offset+0x2d>
cmp    $0x15,%edx
jne    1154 <get_xloader_offset+0x34>
mov    $0x40000,%ebx
jmp    117a <get_xloader_offset+0x5a>
mov    $0x20000,%ebx
jmp    117a <get_xloader_offset+0x5a>
mov    $0x60000,%ebx
test   $0x6,%cl
je     117a <get_xloader_offset+0x5a>
mov    0x2e7b(%rip),%rcx
mov    (%rcx),%edi
lea    0xe92(%rip),%rsi
mov    %eax,%edx
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Unsupported spec for bootloader.img: %d\00"
define i32 @get_xloader_offset() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @get_specification()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 -1, i32* %1
br label %58
7: ; preds = %0
%8 = load i32, i32* %2
%9 = and i32 %8, 1
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i32, i32* %2
%13 = and i32 %12, 8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 0, i32* %1
br label %58
16: ; preds = %11, %7
%17 = load i32, i32* %2
%18 = and i32 %17, 1
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i32, i32* %2
%22 = and i32 %21, 4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i32, i32* %2
%26 = and i32 %25, 16
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %24
store i32 131072, i32* %1
br label %58
29: ; preds = %24, %20, %16
%30 = load i32, i32* %2
%31 = and i32 %30, 1
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i32, i32* %2
%35 = and i32 %34, 4
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i32, i32* %2
%39 = and i32 %38, 16
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 262144, i32* %1
br label %58
42: ; preds = %37, %33, %29
%43 = load i32, i32* %2
%44 = and i32 %43, 2
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = load i32, i32* %2
%48 = and i32 %47, 4
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 393216, i32* %1
br label %58
51: ; preds = %46, %42
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52
br label %54
54: ; preds = %53
%55 = load i32, i32* @stderr
%56 = load i32, i32* %2
%57 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %56)
store i32 -1, i32* %1
br label %58
58: ; preds = %54, %50, %41, %28, %15, %6
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Unsupported spec for bootloader.img: %d\00"
define i32 @get_xloader_offset() {
%1 = tail call i32 (...) @get_specification()
%2 = icmp slt i32 %1, 0
br i1 %2, label %15, label %3
3: ; preds = %0
%4 = and i32 %1, 9
%5 = icmp eq i32 %4, 9
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = and i32 %1, 21
switch i32 %7, label %8 [
i32 5, label %15
i32 21, label %14
]
8: ; preds = %6
%9 = and i32 %1, 6
%10 = icmp eq i32 %9, 6
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %15
14: ; preds = %6
br label %15
15: ; preds = %6, %14, %8, %3, %0, %11
%16 = phi i32 [ -1, %11 ], [ -1, %0 ], [ 0, %3 ], [ 131072, %6 ], [ 393216, %8 ], [ 262144, %14 ]
ret i32 %16
}