#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__ a20_test_long();
scalar_t__ a20_test_short();
int /*<<< orphan*/ empty_8042();
int /*<<< orphan*/ enable_a20_bios();
int /*<<< orphan*/ enable_a20_fast();
int /*<<< orphan*/ enable_a20_kbc();
int enable_a20(void) {
  int loops = 255;
  while (loops--) {
    if (a20_test_short())
      return 0;
    enable_a20_bios();
    if (a20_test_short())
      return 0;
    empty_8042();
    if (a20_test_short())
      return 0;
    enable_a20_kbc();
    if (a20_test_long())
      return 0;
    enable_a20_fast();
    if (a20_test_long())
      return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<enable_a20>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xff,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1235 <enable_a20+0xd5>
mov    $0x0,%al
call   1080 <a20_test_short@plt>
cmp    $0x0,%rax
je     11a0 <enable_a20+0x40>
movl   $0x0,-0x4(%rbp)
jmp    123c <enable_a20+0xdc>
mov    $0x0,%al
call   1040 <enable_a20_bios@plt>
mov    $0x0,%al
call   1080 <a20_test_short@plt>
cmp    $0x0,%rax
je     11c4 <enable_a20+0x64>
movl   $0x0,-0x4(%rbp)
jmp    123c <enable_a20+0xdc>
mov    $0x0,%al
call   1070 <empty_8042@plt>
mov    $0x0,%al
call   1080 <a20_test_short@plt>
cmp    $0x0,%rax
je     11e8 <enable_a20+0x88>
movl   $0x0,-0x4(%rbp)
jmp    123c <enable_a20+0xdc>
mov    $0x0,%al
call   1060 <enable_a20_kbc@plt>
mov    $0x0,%al
call   1050 <a20_test_long@plt>
cmp    $0x0,%rax
je     120c <enable_a20+0xac>
movl   $0x0,-0x4(%rbp)
jmp    123c <enable_a20+0xdc>
mov    $0x0,%al
call   1030 <enable_a20_fast@plt>
mov    $0x0,%al
call   1050 <a20_test_long@plt>
cmp    $0x0,%rax
je     1230 <enable_a20+0xd0>
movl   $0x0,-0x4(%rbp)
jmp    123c <enable_a20+0xdc>
jmp    116f <enable_a20+0xf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enable_a20>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffff00,%ebp
nopl   0x0(%rax,%rax,1)
inc    %ebp
je     11d8 <enable_a20+0x78>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <a20_test_short@plt>
test   %rax,%rax
jne    11dd <enable_a20+0x7d>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <enable_a20_bios@plt>
xor    %eax,%eax
call   1080 <a20_test_short@plt>
test   %rax,%rax
jne    11dd <enable_a20+0x7d>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <empty_8042@plt>
xor    %eax,%eax
call   1080 <a20_test_short@plt>
test   %rax,%rax
jne    11dd <enable_a20+0x7d>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <enable_a20_kbc@plt>
xor    %eax,%eax
call   1050 <a20_test_long@plt>
test   %rax,%rax
jne    11dd <enable_a20+0x7d>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <enable_a20_fast@plt>
xor    %eax,%eax
call   1050 <a20_test_long@plt>
test   %rax,%rax
je     1170 <enable_a20+0x10>
jmp    11dd <enable_a20+0x7d>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @enable_a20() {
%1 = alloca i32
%2 = alloca i32
store i32 255, i32* %2
br label %3
3: ; preds = %31, %0
%4 = load i32, i32* %2
%5 = add nsw i32 %4, -1
store i32 %5, i32* %2
%6 = icmp ne i32 %4, 0
br i1 %6, label %7, label %32
7: ; preds = %3
%8 = call i64 (...) @a20_test_short()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 0, i32* %1
br label %33
11: ; preds = %7
%12 = call i32 (...) @enable_a20_bios()
%13 = call i64 (...) @a20_test_short()
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 0, i32* %1
br label %33
16: ; preds = %11
%17 = call i32 (...) @empty_8042()
%18 = call i64 (...) @a20_test_short()
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %1
br label %33
21: ; preds = %16
%22 = call i32 (...) @enable_a20_kbc()
%23 = call i64 (...) @a20_test_long()
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 0, i32* %1
br label %33
26: ; preds = %21
%27 = call i32 (...) @enable_a20_fast()
%28 = call i64 (...) @a20_test_long()
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %1
br label %33
31: ; preds = %26
br label %3
32: ; preds = %3
store i32 -1, i32* %1
br label %33
33: ; preds = %32, %30, %25, %20, %15, %10
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
define i32 @enable_a20() {
br label %1
1: ; preds = %20, %0
%2 = phi i32 [ 255, %0 ], [ %3, %20 ]
%3 = add nsw i32 %2, -1
%4 = icmp eq i32 %2, 0
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = tail call i64 (...) @a20_test_short()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = tail call i32 (...) @enable_a20_bios()
%10 = tail call i64 (...) @a20_test_short()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = tail call i32 (...) @empty_8042()
%14 = tail call i64 (...) @a20_test_short()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = tail call i32 (...) @enable_a20_kbc()
%18 = tail call i64 (...) @a20_test_long()
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = tail call i32 (...) @enable_a20_fast()
%22 = tail call i64 (...) @a20_test_long()
%23 = icmp eq i64 %22, 0
br i1 %23, label %1, label %24
24: ; preds = %1, %20, %16, %12, %8, %5
%25 = phi i32 [ 0, %5 ], [ 0, %8 ], [ 0, %12 ], [ 0, %16 ], [ 0, %20 ], [ -1, %1 ]
ret i32 %25
}