#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__ checkkbdbuf();
int /*<<< orphan*/ clearkbdbuf();
int /*<<< orphan*/ sleep(int);
int checkkeypress(int stepsize, int numsteps) {
  int i;
  clearkbdbuf();
  for (i = 0; i < numsteps; i++) {
    if (checkkbdbuf())
      return 1;
    sleep(stepsize);
  }
  return 0;
}


x86 assembly (clang, -O0):
<checkkeypress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <clearkbdbuf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118b <checkkeypress+0x5b>
mov    $0x0,%al
call   1040 <checkkbdbuf@plt>
cmp    $0x0,%rax
je     1175 <checkkeypress+0x45>
movl   $0x1,-0x4(%rbp)
jmp    1192 <checkkeypress+0x62>
mov    -0x8(%rbp),%edi
call   1050 <sleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114c <checkkeypress+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkkeypress>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <clearkbdbuf@plt>
test   %ebx,%ebx
jle    1173 <checkkeypress+0x43>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <checkkbdbuf@plt>
test   %rax,%rax
jne    116d <checkkeypress+0x3d>
mov    %ebp,%edi
call   1050 <sleep@plt>
add    $0xffffffff,%ebx
jne    1150 <checkkeypress+0x20>
xor    %r14d,%r14d
jmp    1173 <checkkeypress+0x43>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @checkkeypress(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = call i32 (...) @clearkbdbuf()
store i32 0, i32* %6
br label %8
8: ; preds = %19, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = call i64 (...) @checkkbdbuf()
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 1, i32* %3
br label %23
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 @sleep(i32 %17)
br label %19
19: ; preds = %16
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %8
22: ; preds = %8
store i32 0, i32* %3
br label %23
23: ; preds = %22, %15
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @checkkeypress(i32 %0, i32 %1) {
%3 = tail call i32 (...) @clearkbdbuf()
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %13
5: ; preds = %2, %9
%6 = phi i32 [ %11, %9 ], [ 0, %2 ]
%7 = tail call i64 (...) @checkkbdbuf()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = tail call i32 @sleep(i32 %0)
%11 = add nuw nsw i32 %6, 1
%12 = icmp eq i32 %11, %1
br i1 %12, label %13, label %5
13: ; preds = %5, %9, %2
%14 = phi i32 [ 0, %2 ], [ 0, %9 ], [ 1, %5 ]
ret i32 %14
}