#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);
void mouse_wait(char a_type) {
  unsigned int _time_out = 100000;
  if (a_type == 0) {
    while (_time_out--) {
      if ((inb(0x64) & 1) == 1) {
        return;
      }
    }
    return;
  } else {
    while (_time_out--) {
      if ((inb(0x64) & 2) == 0) {
        return;
      }
    }
    return;
  }
}


x86 assembly (clang, -O0):
<mouse_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x186a0,-0x8(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x0,%eax
jne    1170 <mouse_wait+0x60>
jmp    1137 <mouse_wait+0x27>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     116b <mouse_wait+0x5b>
mov    $0x64,%edi
call   1030 <inb@plt>
and    $0x1,%eax
cmp    $0x1,%eax
jne    1166 <mouse_wait+0x56>
jmp    11ae <mouse_wait+0x9e>
jmp    1137 <mouse_wait+0x27>
jmp    11ae <mouse_wait+0x9e>
jmp    1175 <mouse_wait+0x65>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11a9 <mouse_wait+0x99>
mov    $0x64,%edi
call   1030 <inb@plt>
and    $0x2,%eax
cmp    $0x0,%eax
jne    11a4 <mouse_wait+0x94>
jmp    11ae <mouse_wait+0x9e>
jmp    1175 <mouse_wait+0x65>
jmp    11ae <mouse_wait+0x9e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mouse_wait>:
push   %rbx
mov    $0xfffe795f,%ebx
test   %dil,%dil
je     1140 <mouse_wait+0x30>
nopl   0x0(%rax,%rax,1)
inc    %ebx
je     1152 <mouse_wait+0x42>
mov    $0x64,%edi
call   1030 <inb@plt>
test   $0x2,%al
jne    1120 <mouse_wait+0x10>
jmp    1152 <mouse_wait+0x42>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
inc    %ebx
je     1152 <mouse_wait+0x42>
mov    $0x64,%edi
call   1030 <inb@plt>
test   $0x1,%al
je     1140 <mouse_wait+0x30>
pop    %rbx
ret

LLVM IR (-O0):
define void @mouse_wait(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
store i32 100000, i32* %3
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %1
br label %8
8: ; preds = %17, %7
%9 = load i32, i32* %3
%10 = add i32 %9, -1
store i32 %10, i32* %3
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = call i32 @inb(i32 100)
%14 = and i32 %13, 1
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %12
br label %31
17: ; preds = %12
br label %8
18: ; preds = %8
br label %31
19: ; preds = %1
br label %20
20: ; preds = %29, %19
%21 = load i32, i32* %3
%22 = add i32 %21, -1
store i32 %22, i32* %3
%23 = icmp ne i32 %21, 0
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = call i32 @inb(i32 100)
%26 = and i32 %25, 2
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
br label %31
29: ; preds = %24
br label %20
30: ; preds = %20
br label %31
31: ; preds = %30, %28, %18, %16
ret void
}

LLVM IR (-O2):
define void @mouse_wait(i8 signext %0) {
%2 = icmp eq i8 %0, 0
br i1 %2, label %3, label %11
3: ; preds = %1, %6
%4 = phi i32 [ %7, %6 ], [ 100000, %1 ]
%5 = icmp eq i32 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = add nsw i32 %4, -1
%8 = tail call i32 @inb(i32 100)
%9 = and i32 %8, 1
%10 = icmp eq i32 %9, 0
br i1 %10, label %3, label %19
11: ; preds = %1, %14
%12 = phi i32 [ %15, %14 ], [ 100000, %1 ]
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = add nsw i32 %12, -1
%16 = tail call i32 @inb(i32 100)
%17 = and i32 %16, 2
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %11
19: ; preds = %11, %14, %3, %6
ret void
}