#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*/ inb(int);
int keyboard_getData();
int /*<<< orphan*/ keyboard_sendCommand(int);
int /*<<< orphan*/ keyboard_sendData(int);
int keyboard_init() {
  unsigned char ccbValue;
  int i;
  ;
  ;
  keyboard_sendCommand(0xAD);
  keyboard_sendCommand(0xA7);
  inb(0x60);
  ;
  keyboard_sendCommand(0x20);
  ccbValue = keyboard_getData();
  keyboard_sendCommand(0x60);
  keyboard_sendData(ccbValue & ~(0x01 | 0x02 | 0x40));
  ;
  keyboard_sendCommand(0xAA);
  if (keyboard_getData() != 0x55) {
    ;
    return 2;
  };
  keyboard_sendCommand(0xAB);
  if (keyboard_getData() != 0x00) {
    ;
    return 3;
  };
  keyboard_sendCommand(0x20);
  ccbValue = keyboard_getData();
  keyboard_sendCommand(0x60);
  keyboard_sendData(ccbValue | 0x01 | 0x02);
  keyboard_sendCommand(0xAE);
  keyboard_sendData(0xFF);
  if (keyboard_getData() != 0xFA) {
    ;
    return 4;
  }
  keyboard_getData();
  ;
  keyboard_sendData(0xF0);
  if ((ccbValue = keyboard_getData()) != 0xFA) {
    ;
    ;
    ;
    ;
    return 5;
  }
  keyboard_sendData(0x02);
  if ((ccbValue = keyboard_getData()) != 0xFA) {
    ;
    ;
    ;
    ;
    if (ccbValue != 1)
      return ccbValue;
    else
      return 6;
  };
  return 1;
}


x86 assembly (clang, -O0):
<keyboard_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xad,%edi
call   1060 <keyboard_sendCommand@plt>
mov    $0xa7,%edi
call   1060 <keyboard_sendCommand@plt>
mov    $0x60,%edi
call   1030 <inb@plt>
mov    $0x20,%edi
call   1060 <keyboard_sendCommand@plt>
mov    $0x0,%al
call   1040 <keyboard_getData@plt>
mov    %al,-0x5(%rbp)
mov    $0x60,%edi
call   1060 <keyboard_sendCommand@plt>
movzbl -0x5(%rbp),%edi
and    $0xffffffbc,%edi
call   1050 <keyboard_sendData@plt>
mov    $0xaa,%edi
call   1060 <keyboard_sendCommand@plt>
mov    $0x0,%al
call   1040 <keyboard_getData@plt>
cmp    $0x55,%eax
je     11b6 <keyboard_init+0x76>
movl   $0x2,-0x4(%rbp)
jmp    12be <keyboard_init+0x17e>
mov    $0xab,%edi
call   1060 <keyboard_sendCommand@plt>
mov    $0x0,%al
call   1040 <keyboard_getData@plt>
cmp    $0x0,%eax
je     11dc <keyboard_init+0x9c>
movl   $0x3,-0x4(%rbp)
jmp    12be <keyboard_init+0x17e>
mov    $0x20,%edi
call   1060 <keyboard_sendCommand@plt>
mov    $0x0,%al
call   1040 <keyboard_getData@plt>
mov    %al,-0x5(%rbp)
mov    $0x60,%edi
call   1060 <keyboard_sendCommand@plt>
movzbl -0x5(%rbp),%edi
or     $0x1,%edi
or     $0x2,%edi
call   1050 <keyboard_sendData@plt>
mov    $0xae,%edi
call   1060 <keyboard_sendCommand@plt>
mov    $0xff,%edi
call   1050 <keyboard_sendData@plt>
mov    $0x0,%al
call   1040 <keyboard_getData@plt>
cmp    $0xfa,%eax
je     123b <keyboard_init+0xfb>
movl   $0x4,-0x4(%rbp)
jmp    12be <keyboard_init+0x17e>
mov    $0x0,%al
call   1040 <keyboard_getData@plt>
mov    $0xf0,%edi
call   1050 <keyboard_sendData@plt>
mov    $0x0,%al
call   1040 <keyboard_getData@plt>
mov    %al,-0x5(%rbp)
movzbl %al,%eax
cmp    $0xfa,%eax
je     1270 <keyboard_init+0x130>
movl   $0x5,-0x4(%rbp)
jmp    12be <keyboard_init+0x17e>
mov    $0x2,%edi
call   1050 <keyboard_sendData@plt>
mov    $0x0,%al
call   1040 <keyboard_getData@plt>
mov    %al,-0x5(%rbp)
movzbl %al,%eax
cmp    $0xfa,%eax
je     12b7 <keyboard_init+0x177>
movzbl -0x5(%rbp),%eax
cmp    $0x1,%eax
je     12ab <keyboard_init+0x16b>
movzbl -0x5(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12be <keyboard_init+0x17e>
movl   $0x6,-0x4(%rbp)
jmp    12be <keyboard_init+0x17e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keyboard_init>:
push   %rbx
mov    $0xad,%edi
call   1060 <keyboard_sendCommand@plt>
mov    $0xa7,%edi
call   1060 <keyboard_sendCommand@plt>
mov    $0x60,%edi
call   1030 <inb@plt>
mov    $0x20,%edi
call   1060 <keyboard_sendCommand@plt>
xor    %eax,%eax
call   1040 <keyboard_getData@plt>
mov    %eax,%ebx
mov    $0x60,%edi
call   1060 <keyboard_sendCommand@plt>
and    $0xbc,%ebx
mov    %ebx,%edi
call   1050 <keyboard_sendData@plt>
mov    $0xaa,%edi
call   1060 <keyboard_sendCommand@plt>
xor    %eax,%eax
call   1040 <keyboard_getData@plt>
mov    %eax,%ecx
mov    $0x2,%eax
cmp    $0x55,%ecx
jne    11c2 <keyboard_init+0x82>
mov    $0xab,%edi
call   1060 <keyboard_sendCommand@plt>
xor    %eax,%eax
call   1040 <keyboard_getData@plt>
mov    %eax,%ecx
mov    $0x3,%eax
test   %ecx,%ecx
je     11c4 <keyboard_init+0x84>
pop    %rbx
ret
mov    $0x20,%edi
call   1060 <keyboard_sendCommand@plt>
xor    %eax,%eax
call   1040 <keyboard_getData@plt>
mov    %eax,%ebx
mov    $0x60,%edi
call   1060 <keyboard_sendCommand@plt>
or     $0x3,%ebx
movzbl %bl,%edi
call   1050 <keyboard_sendData@plt>
mov    $0xae,%edi
call   1060 <keyboard_sendCommand@plt>
mov    $0xff,%edi
call   1050 <keyboard_sendData@plt>
xor    %eax,%eax
call   1040 <keyboard_getData@plt>
mov    %eax,%ecx
mov    $0x4,%eax
cmp    $0xfa,%ecx
jne    11c2 <keyboard_init+0x82>
xor    %eax,%eax
call   1040 <keyboard_getData@plt>
mov    $0xf0,%edi
call   1050 <keyboard_sendData@plt>
xor    %eax,%eax
call   1040 <keyboard_getData@plt>
mov    %eax,%ecx
mov    $0x5,%eax
cmp    $0xfa,%cl
jne    11c2 <keyboard_init+0x82>
mov    $0x2,%edi
call   1050 <keyboard_sendData@plt>
xor    %eax,%eax
call   1040 <keyboard_getData@plt>
cmp    $0xfa,%al
je     125a <keyboard_init+0x11a>
cmp    $0x1,%al
jne    1261 <keyboard_init+0x121>
mov    $0x6,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret
movzbl %al,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @keyboard_init() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = call i32 @keyboard_sendCommand(i32 173)
%5 = call i32 @keyboard_sendCommand(i32 167)
%6 = call i32 @inb(i32 96)
%7 = call i32 @keyboard_sendCommand(i32 32)
%8 = call i32 (...) @keyboard_getData()
%9 = trunc i32 %8 to i8
store i8 %9, i8* %2
%10 = call i32 @keyboard_sendCommand(i32 96)
%11 = load i8, i8* %2
%12 = zext i8 %11 to i32
%13 = and i32 %12, -68
%14 = call i32 @keyboard_sendData(i32 %13)
%15 = call i32 @keyboard_sendCommand(i32 170)
%16 = call i32 (...) @keyboard_getData()
%17 = icmp ne i32 %16, 85
br i1 %17, label %18, label %19
18: ; preds = %0
store i32 2, i32* %1
br label %62
19: ; preds = %0
%20 = call i32 @keyboard_sendCommand(i32 171)
%21 = call i32 (...) @keyboard_getData()
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 3, i32* %1
br label %62
24: ; preds = %19
%25 = call i32 @keyboard_sendCommand(i32 32)
%26 = call i32 (...) @keyboard_getData()
%27 = trunc i32 %26 to i8
store i8 %27, i8* %2
%28 = call i32 @keyboard_sendCommand(i32 96)
%29 = load i8, i8* %2
%30 = zext i8 %29 to i32
%31 = or i32 %30, 1
%32 = or i32 %31, 2
%33 = call i32 @keyboard_sendData(i32 %32)
%34 = call i32 @keyboard_sendCommand(i32 174)
%35 = call i32 @keyboard_sendData(i32 255)
%36 = call i32 (...) @keyboard_getData()
%37 = icmp ne i32 %36, 250
br i1 %37, label %38, label %39
38: ; preds = %24
store i32 4, i32* %1
br label %62
39: ; preds = %24
%40 = call i32 (...) @keyboard_getData()
%41 = call i32 @keyboard_sendData(i32 240)
%42 = call i32 (...) @keyboard_getData()
%43 = trunc i32 %42 to i8
store i8 %43, i8* %2
%44 = zext i8 %43 to i32
%45 = icmp ne i32 %44, 250
br i1 %45, label %46, label %47
46: ; preds = %39
store i32 5, i32* %1
br label %62
47: ; preds = %39
%48 = call i32 @keyboard_sendData(i32 2)
%49 = call i32 (...) @keyboard_getData()
%50 = trunc i32 %49 to i8
store i8 %50, i8* %2
%51 = zext i8 %50 to i32
%52 = icmp ne i32 %51, 250
br i1 %52, label %53, label %61
53: ; preds = %47
%54 = load i8, i8* %2
%55 = zext i8 %54 to i32
%56 = icmp ne i32 %55, 1
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i8, i8* %2
%59 = zext i8 %58 to i32
store i32 %59, i32* %1
br label %62
60: ; preds = %53
store i32 6, i32* %1
br label %62
61: ; preds = %47
store i32 1, i32* %1
br label %62
62: ; preds = %61, %60, %57, %46, %38, %23, %18
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
define i32 @keyboard_init() {
%1 = tail call i32 @keyboard_sendCommand(i32 173)
%2 = tail call i32 @keyboard_sendCommand(i32 167)
%3 = tail call i32 @inb(i32 96)
%4 = tail call i32 @keyboard_sendCommand(i32 32)
%5 = tail call i32 (...) @keyboard_getData()
%6 = tail call i32 @keyboard_sendCommand(i32 96)
%7 = and i32 %5, 188
%8 = tail call i32 @keyboard_sendData(i32 %7)
%9 = tail call i32 @keyboard_sendCommand(i32 170)
%10 = tail call i32 (...) @keyboard_getData()
%11 = icmp eq i32 %10, 85
br i1 %11, label %12, label %40
12: ; preds = %0
%13 = tail call i32 @keyboard_sendCommand(i32 171)
%14 = tail call i32 (...) @keyboard_getData()
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %40
16: ; preds = %12
%17 = tail call i32 @keyboard_sendCommand(i32 32)
%18 = tail call i32 (...) @keyboard_getData()
%19 = tail call i32 @keyboard_sendCommand(i32 96)
%20 = and i32 %18, 252
%21 = or i32 %20, 3
%22 = tail call i32 @keyboard_sendData(i32 %21)
%23 = tail call i32 @keyboard_sendCommand(i32 174)
%24 = tail call i32 @keyboard_sendData(i32 255)
%25 = tail call i32 (...) @keyboard_getData()
%26 = icmp eq i32 %25, 250
br i1 %26, label %27, label %40
27: ; preds = %16
%28 = tail call i32 (...) @keyboard_getData()
%29 = tail call i32 @keyboard_sendData(i32 240)
%30 = tail call i32 (...) @keyboard_getData()
%31 = and i32 %30, 255
%32 = icmp eq i32 %31, 250
br i1 %32, label %33, label %40
33: ; preds = %27
%34 = tail call i32 @keyboard_sendData(i32 2)
%35 = tail call i32 (...) @keyboard_getData()
%36 = and i32 %35, 255
%37 = trunc i32 %35 to i8
switch i8 %37, label %40 [
i8 -6, label %39
i8 1, label %38
]
38: ; preds = %33
br label %40
39: ; preds = %33
br label %40
40: ; preds = %33, %27, %16, %12, %0, %39, %38
%41 = phi i32 [ 6, %38 ], [ 1, %39 ], [ 2, %0 ], [ 3, %12 ], [ 4, %16 ], [ 5, %27 ], [ %36, %33 ]
ret i32 %41
}