#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()) {
      printf("enter ");
      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     11ee <main+0x7e>
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     11e9 <main+0x79>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1090 <readch@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe2e(%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   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <init_keyboard@plt>
lea    0xe7e(%rip),%rbx
lea    0xe64(%rip),%r14
lea    0xe64(%rip),%r15
xor    %ebp,%ebp
jmp    11b5 <main+0x35>
nopw   0x0(%rax,%rax,1)
cmp    $0x71,%ebp
je     11f4 <main+0x74>
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     11b0 <main+0x30>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   10a0 <readch@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b0 <main+0x30>
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 = [7 x i8] c"enter \00"
@.str.2 = [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 = %17, %0
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 113
br i1 %6, label %7, label %18
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 %17
12: ; preds = %7
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (...) @readch()
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %12, %7
br label %4
18: ; preds = %4
%19 = call i32 (...) @close_keyboard()
%20 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"enter \00"
@.str.2 = [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, %12
%3 = phi i32 [ 0, %0 ], [ %13, %12 ]
%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 %12, label %8
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 (...) @readch()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %2
%13 = phi i32 [ %10, %8 ], [ %3, %2 ]
%14 = icmp eq i32 %13, 113
br i1 %14, label %15, label %2
15: ; preds = %12
%16 = tail call i32 (...) @close_keyboard()
%17 = tail call i32 @exit(i32 0)
unreachable
}