#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*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
unsigned int wait_keypress();
int main() {
  unsigned int start_value;
  unsigned int scancode;
  for (unsigned int i = 0; i < 64; i++) {
    scancode = wait_keypress();
    if (scancode != i) {
      printf("FAIL: mismatch: want %02x got %02x", i, scancode);
      break;
    }
    printf("%02x\n", scancode);
  }
  printf("overrun...\n");
  usleep(5000);
  start_value = wait_keypress();
  printf("%02x\n", start_value);
  for (unsigned int i = 1; i < 32; i++) {
    scancode = wait_keypress();
    if (scancode != i + start_value) {
      printf("FAIL: mismatch: want %02x got %02x", i + start_value, scancode);
      break;
    }
    printf("%02x\n", scancode);
  }
  printf("PASS\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x40,-0x10(%rbp)
jae    119e <main+0x6e>
mov    $0x0,%al
call   1040 <wait_keypress@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     117f <main+0x4f>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119e <main+0x6e>
mov    -0xc(%rbp),%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <main+0x16>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1388,%edi
call   1050 <usleep@plt>
mov    $0x0,%al
call   1040 <wait_keypress@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jae    1238 <main+0x108>
mov    $0x0,%al
call   1040 <wait_keypress@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x8(%rbp),%ecx
cmp    %ecx,%eax
je     1219 <main+0xe9>
mov    -0x14(%rbp),%esi
add    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1238 <main+0x108>
mov    -0xc(%rbp),%esi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d8 <main+0xa8>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xed7(%rip),%r14
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <wait_keypress@plt>
cmp    %eax,%ebx
jne    1171 <main+0x31>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    $0x40,%ebx
jne    1150 <main+0x10>
jmp    1183 <main+0x43>
lea    0xe88(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1388,%edi
call   1060 <usleep@plt>
xor    %eax,%eax
call   1050 <wait_keypress@plt>
mov    %eax,%r15d
lea    0xe79(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <wait_keypress@plt>
lea    (%r15,%rbx,1),%esi
cmp    %eax,%esi
jne    11e5 <main+0xa5>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    $0x20,%ebx
jne    11c0 <main+0x80>
jmp    11f5 <main+0xb5>
lea    0xe14(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [35 x i8] c"FAIL: mismatch: want %02x got %02x\00"
@.str.1 = [6 x i8] c"%02x\0A\00"
@.str.2 = [12 x i8] c"overrun...\0A\00"
@.str.3 = [6 x i8] c"PASS\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
br label %6
6: ; preds = %21, %0
%7 = load i32, i32* %4
%8 = icmp ult i32 %7, 64
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = call i32 (...) @wait_keypress()
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
br label %24
18: ; preds = %9
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18
%22 = load i32, i32* %4
%23 = add i32 %22, 1
store i32 %23, i32* %4
br label %6
24: ; preds = %14, %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @usleep(i32 5000)
%27 = call i32 (...) @wait_keypress()
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i32 1, i32* %5
br label %30
30: ; preds = %49, %24
%31 = load i32, i32* %5
%32 = icmp ult i32 %31, 32
br i1 %32, label %33, label %52
33: ; preds = %30
%34 = call i32 (...) @wait_keypress()
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = load i32, i32* %5
%37 = load i32, i32* %2
%38 = add i32 %36, %37
%39 = icmp ne i32 %35, %38
br i1 %39, label %40, label %46
40: ; preds = %33
%41 = load i32, i32* %5
%42 = load i32, i32* %2
%43 = add i32 %41, %42
%44 = load i32, i32* %3
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %43, i32 %44)
br label %52
46: ; preds = %33
%47 = load i32, i32* %3
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %46
%50 = load i32, i32* %5
%51 = add i32 %50, 1
store i32 %51, i32* %5
br label %30
52: ; preds = %40, %30
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"FAIL: mismatch: want %02x got %02x\00"
@.str.1 = [6 x i8] c"%02x\0A\00"
@str = [11 x i8] c"overrun...\00"
@str.4 = [5 x i8] c"PASS\00"
define i32 @main() {
br label %1
1: ; preds = %0, %7
%2 = phi i32 [ 0, %0 ], [ %9, %7 ]
%3 = tail call i32 (...) @wait_keypress()
%4 = icmp eq i32 %3, %2
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3)
br label %11
7: ; preds = %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%9 = add nuw nsw i32 %2, 1
%10 = icmp eq i32 %9, 64
br i1 %10, label %11, label %1
11: ; preds = %7, %5
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @usleep(i32 5000)
%14 = tail call i32 (...) @wait_keypress()
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %11, %23
%17 = phi i32 [ 1, %11 ], [ %25, %23 ]
%18 = tail call i32 (...) @wait_keypress()
%19 = add i32 %17, %14
%20 = icmp eq i32 %18, %19
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %18)
br label %27
23: ; preds = %16
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%25 = add nuw nsw i32 %17, 1
%26 = icmp eq i32 %25, 32
br i1 %26, label %27, label %16
27: ; preds = %23, %21
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0))
ret i32 0
}