#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 inb(int);
int /*<<< orphan*/ panic(char *);
unsigned int keyb_inb(int port) {
  while (!inb(0x64) & 1)
    ;
  int retval = inb(port);
  if (retval == 0xFA)
    return 0;
  if (retval == 0xFE)
    panic("keyboard sent a RESEND command, but it's not implemented yet!\n");
  return retval;
}


x86 assembly (clang, -O0):
<keyb_inb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x64,%edi
call   1040 <inb@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1153 <keyb_inb+0x33>
jmp    112b <keyb_inb+0xb>
mov    -0x8(%rbp),%edi
call   1040 <inb@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xfa,-0xc(%rbp)
jne    1177 <keyb_inb+0x57>
movl   $0x0,-0x4(%rbp)
jmp    1196 <keyb_inb+0x76>
cmpl   $0xfe,-0xc(%rbp)
jne    1190 <keyb_inb+0x70>
lea    0xe75(%rip),%rdi
call   1030 <panic@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keyb_inb>:
push   %rbx
mov    %edi,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x64,%edi
call   1040 <inb@plt>
test   %eax,%eax
je     1130 <keyb_inb+0x10>
mov    %ebx,%edi
call   1040 <inb@plt>
cmp    $0xfa,%eax
je     1163 <keyb_inb+0x43>
mov    %eax,%ebx
cmp    $0xfe,%eax
jne    1165 <keyb_inb+0x45>
lea    0xea4(%rip),%rdi
call   1030 <panic@plt>
jmp    1165 <keyb_inb+0x45>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [63 x i8] c"keyboard sent a RESEND command, but it's not implemented yet!\0A\00"
define i32 @keyb_inb(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
br label %5
5: ; preds = %12, %1
%6 = call i32 @inb(i32 100)
%7 = icmp ne i32 %6, 0
%8 = xor i1 %7, true
%9 = zext i1 %8 to i32
%10 = and i32 %9, 1
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %5
br label %5
13: ; preds = %5
%14 = load i32, i32* %3
%15 = call i32 @inb(i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 250
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 0, i32* %2
br label %26
19: ; preds = %13
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 254
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @panic(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = load i32, i32* %4
store i32 %25, i32* %2
br label %26
26: ; preds = %24, %18
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [63 x i8] c"keyboard sent a RESEND command, but it's not implemented yet!\0A\00"
define i32 @keyb_inb(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = tail call i32 @inb(i32 100)
%4 = icmp eq i32 %3, 0
br i1 %4, label %2, label %5
5: ; preds = %2
%6 = tail call i32 @inb(i32 %0)
switch i32 %6, label %9 [
i32 250, label %10
i32 254, label %7
]
7: ; preds = %5
%8 = tail call i32 @panic(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %5, %7
br label %10
10: ; preds = %5, %9
%11 = phi i32 [ %6, %9 ], [ 0, %5 ]
ret i32 %11
}