#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 */
scalar_t__ get_tlv_item(int, unsigned char *, unsigned char *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int get_boot_abort(unsigned short *flag) {
  unsigned char buf[128];
  unsigned char len;
  memset(buf, 0, 128);
  if (get_tlv_item(0x41, &len, buf) < 0) {
    printf("Get abort flag failed.\n");
    return -1;
  }
  *flag = (unsigned short)(((unsigned short)buf[0] << 8) | buf[1]);
  printf("%s\n", (*flag == 1) ? "Enabled" : "Disabled");
  return 0;
}


x86 assembly (clang, -O0):
<get_boot_abort>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0x90(%rbp),%rdx
mov    $0x41,%edi
lea    -0x91(%rbp),%rsi
call   1030 <get_tlv_item@plt>
cmp    $0x0,%rax
jge    118e <get_boot_abort+0x5e>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <get_boot_abort+0xaf>
movzbl -0x90(%rbp),%eax
movzwl %ax,%eax
shl    $0x8,%eax
movzbl -0x8f(%rbp),%ecx
or     %ecx,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
mov    -0x10(%rbp),%rax
movzwl (%rax),%ecx
lea    0xe68(%rip),%rsi
lea    0xe59(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_boot_abort>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xf(%rsp),%rsi
mov    $0x41,%edi
mov    %rbx,%rdx
call   1040 <get_tlv_item@plt>
test   %rax,%rax
js     1190 <get_boot_abort+0x60>
movzwl 0x10(%rsp),%eax
rol    $0x8,%ax
mov    %ax,(%r14)
cmp    $0x1,%ax
lea    0xe7d(%rip),%rax
lea    0xe7e(%rip),%rdi
cmove  %rax,%rdi
jmp    119c <get_boot_abort+0x6c>
mov    $0xffffffff,%ebp
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Get abort flag failed.\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [8 x i8] c"Enabled\00"
@.str.3 = [9 x i8] c"Disabled\00"
define i32 @get_boot_abort(i16* %0) {
%2 = alloca i32
%3 = alloca i16*
%4 = alloca [128 x i8]
%5 = alloca i8
store i16* %0, i16** %3
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 128)
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = call i64 @get_tlv_item(i32 65, i8* %5, i8* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %32
13: ; preds = %1
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%15 = load i8, i8* %14
%16 = zext i8 %15 to i16
%17 = zext i16 %16 to i32
%18 = shl i32 %17, 8
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 1
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = or i32 %18, %21
%23 = trunc i32 %22 to i16
%24 = load i16*, i16** %3
store i16 %23, i16* %24
%25 = load i16*, i16** %3
%26 = load i16, i16* %25
%27 = zext i16 %26 to i32
%28 = icmp eq i32 %27, 1
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %30)
store i32 0, i32* %2
br label %32
32: ; preds = %13, %11
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str.2 = [8 x i8] c"Enabled\00"
@.str.3 = [9 x i8] c"Disabled\00"
@str = [23 x i8] c"Get abort flag failed.\00"
define i32 @get_boot_abort(i16* nocapture writeonly %0) {
%2 = alloca [128 x i8]
%3 = alloca i8
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 128)
%6 = call i64 @get_tlv_item(i32 65, i8* %3, i8* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %18, label %8
8: ; preds = %1
%9 = load i8, i8* %4
%10 = zext i8 %9 to i16
%11 = shl nuw i16 %10, 8
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 1
%13 = load i8, i8* %12
%14 = zext i8 %13 to i16
%15 = or i16 %11, %14
store i16 %15, i16* %0
%16 = icmp eq i16 %15, 1
%17 = select i1 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0)
br label %18
18: ; preds = %1, %8
%19 = phi i8* [ %17, %8 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0), %1 ]
%20 = phi i32 [ 0, %8 ], [ -1, %1 ]
%21 = call i32 @puts(i8* dereferenceable(1) %19)
ret i32 %20
}