#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__ mouse_read(unsigned char *);
int /*<<< orphan*/ printk(char *, unsigned char);
int wait_self_test(void) {
  unsigned char b;
  while (mouse_read(&b))
    continue;
  if (b != 0xaa) {
    printk("self test failed (%02x)\n", b);
    return -1;
  }
  while (mouse_read(&b))
    continue;
  return 0;
}


x86 assembly (clang, -O0):
<wait_self_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x5(%rbp),%rdi
call   1040 <mouse_read@plt>
cmp    $0x0,%rax
je     1140 <wait_self_test+0x20>
jmp    1128 <wait_self_test+0x8>
movzbl -0x5(%rbp),%eax
cmp    $0xaa,%eax
je     116b <wait_self_test+0x4b>
lea    0xeaa(%rip),%rdi
movzbl -0x5(%rbp),%esi
call   1030 <printk@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118f <wait_self_test+0x6f>
jmp    1170 <wait_self_test+0x50>
lea    -0x5(%rbp),%rdi
call   1040 <mouse_read@plt>
cmp    $0x0,%rax
je     1188 <wait_self_test+0x68>
jmp    1170 <wait_self_test+0x50>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_self_test>:
push   %rbx
sub    $0x10,%rsp
lea    0xf(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <mouse_read@plt>
test   %rax,%rax
jne    1130 <wait_self_test+0x10>
mov    0xf(%rsp),%al
cmp    $0xaa,%al
jne    1161 <wait_self_test+0x41>
lea    0xf(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <mouse_read@plt>
test   %rax,%rax
jne    1150 <wait_self_test+0x30>
xor    %eax,%eax
jmp    1175 <wait_self_test+0x55>
movzbl %al,%esi
lea    0xe95(%rip),%rdi
call   1030 <printk@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"self test failed (%02x)\0A\00"
define i32 @wait_self_test() {
%1 = alloca i32
%2 = alloca i8
br label %3
3: ; preds = %6, %0
%4 = call i64 @mouse_read(i8* %2)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %3
br label %3
7: ; preds = %3
%8 = load i8, i8* %2
%9 = zext i8 %8 to i32
%10 = icmp ne i32 %9, 170
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i8, i8* %2
%13 = call i32 @printk(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8 zeroext %12)
store i32 -1, i32* %1
br label %20
14: ; preds = %7
br label %15
15: ; preds = %18, %14
%16 = call i64 @mouse_read(i8* %2)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
br label %15
19: ; preds = %15
store i32 0, i32* %1
br label %20
20: ; preds = %19, %11
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [25 x i8] c"self test failed (%02x)\0A\00"
define i32 @wait_self_test() {
%1 = alloca i8
br label %2
2: ; preds = %2, %0
%3 = call i64 @mouse_read(i8* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %2
5: ; preds = %2
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, -86
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = call i32 @printk(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8 zeroext %6)
br label %13
10: ; preds = %5, %10
%11 = call i64 @mouse_read(i8* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %10
13: ; preds = %10, %8
%14 = phi i32 [ -1, %8 ], [ 0, %10 ]
ret i32 %14
}