#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*/ close_keyboard();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ init_keyboard();
scalar_t__ kbhit();
int /*<<< orphan*/ printf(char *, ...);
int readch();
int /*<<< orphan*/ sleep(int);
int main() {
  int ch = 0;
  init_keyboard();
  while (ch != 'q') {
    printf("looping\n");
    sleep(1);
    if (kbhit()) {
      ch = readch();
      printf("you hit %c\n", ch);
    }
  }
  close_keyboard();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <init_keyboard@plt>
cmpl   $0x71,-0x8(%rbp)
je     11e0 <main+0x70>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    $0x0,%al
call   1040 <kbhit@plt>
cmp    $0x0,%rax
je     11db <main+0x6b>
mov    $0x0,%al
call   1090 <readch@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118d <main+0x1d>
mov    $0x0,%al
call   1060 <close_keyboard@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1060 <init_keyboard@plt>
lea    0xe7a(%rip),%rbx
lea    0xe67(%rip),%r14
xor    %ebp,%ebp
jmp    11a5 <main+0x25>
nopl   (%rax)
cmp    $0x71,%ebp
je     11da <main+0x5a>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
call   1050 <kbhit@plt>
test   %rax,%rax
je     11a0 <main+0x20>
xor    %eax,%eax
call   10a0 <readch@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <main+0x20>
xor    %eax,%eax
call   1070 <close_keyboard@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"looping\0A\00"
@.str.1 = [12 x i8] c"you hit %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%3 = call i32 (...) @init_keyboard()
br label %4
4: ; preds = %16, %0
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 113
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @sleep(i32 1)
%10 = call i64 (...) @kbhit()
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = call i32 (...) @readch()
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %12, %7
br label %4
17: ; preds = %4
%18 = call i32 (...) @close_keyboard()
%19 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"you hit %c\0A\00"
@str = [8 x i8] c"looping\00"
define i32 @main() {
%1 = tail call i32 (...) @init_keyboard()
br label %2
2: ; preds = %0, %11
%3 = phi i32 [ 0, %0 ], [ %12, %11 ]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @sleep(i32 1)
%6 = tail call i64 (...) @kbhit()
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 (...) @readch()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %2
%12 = phi i32 [ %9, %8 ], [ %3, %2 ]
%13 = icmp eq i32 %12, 113
br i1 %13, label %14, label %2
14: ; preds = %11
%15 = tail call i32 (...) @close_keyboard()
%16 = tail call i32 @exit(i32 0)
unreachable
}