#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 */
typedef int int16_t;

/* Variables and functions */
int /*<<< orphan*/ flashywait(int);
int getkey();
int /*<<< orphan*/ gwrite(int, int, char, int);
int /*<<< orphan*/ isalnum(int);
scalar_t__ kbhit();
int16_t getinitial(int16_t x, int16_t y) {
  int16_t i;
  gwrite(x, y, '_', 3);
  do {
    for (i = 0; i < 40; i++) {
      if (kbhit()) {
        int16_t key = getkey();
        if (!isalnum(key))
          continue;
        return key;
      }
      flashywait(15);
    }
    for (i = 0; i < 40; i++) {
      if (kbhit()) {
        gwrite(x, y, '_', 3);
        return getkey();
      }
      flashywait(15);
    }
  } while (1);
}


x86 assembly (clang, -O0):
<getinitial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x5f,%edx
mov    $0x3,%ecx
call   1050 <gwrite@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x28,-0x10(%rbp)
jge    11d8 <getinitial+0x88>
mov    $0x0,%al
call   1040 <kbhit@plt>
cmp    $0x0,%rax
je     11c0 <getinitial+0x70>
mov    $0x0,%al
call   1060 <getkey@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%eax
jne    11b5 <getinitial+0x65>
jmp    11ca <getinitial+0x7a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124a <getinitial+0xfa>
mov    $0xf,%edi
call   1070 <flashywait@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117a <getinitial+0x2a>
movl   $0x0,-0x10(%rbp)
cmpl   $0x28,-0x10(%rbp)
jge    1236 <getinitial+0xe6>
mov    $0x0,%al
call   1040 <kbhit@plt>
cmp    $0x0,%rax
je     121e <getinitial+0xce>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x5f,%edx
mov    $0x3,%ecx
call   1050 <gwrite@plt>
mov    $0x0,%al
call   1060 <getkey@plt>
mov    %eax,-0x4(%rbp)
jmp    124a <getinitial+0xfa>
mov    $0xf,%edi
call   1070 <flashywait@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11df <getinitial+0x8f>
jmp    123b <getinitial+0xeb>
mov    $0x1,%al
test   $0x1,%al
jne    1173 <getinitial+0x23>
jmp    124a <getinitial+0xfa>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getinitial>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
mov    $0x5f,%edx
mov    $0x3,%ecx
call   1050 <gwrite@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <kbhit@plt>
test   %rax,%rax
je     1190 <getinitial+0x40>
xor    %eax,%eax
call   1060 <getkey@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <isalnum@plt>
test   %eax,%eax
je     119a <getinitial+0x4a>
jmp    11f3 <getinitial+0xa3>
mov    $0xf,%edi
call   1070 <flashywait@plt>
add    $0x1,%ebp
cmp    $0x28,%ebp
jne    116e <getinitial+0x1e>
mov    $0x28,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <kbhit@plt>
test   %rax,%rax
jne    11cd <getinitial+0x7d>
mov    $0xf,%edi
call   1070 <flashywait@plt>
add    $0xffffffff,%ebx
jne    11b0 <getinitial+0x60>
jmp    116c <getinitial+0x1c>
mov    %r15d,%edi
mov    %r14d,%esi
mov    $0x5f,%edx
mov    $0x3,%ecx
call   1050 <gwrite@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <getkey@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getinitial(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = call i32 @gwrite(i32 %8, i32 %9, i8 signext 95, i32 3)
br label %11
11: ; preds = %49, %2
store i32 0, i32* %6
br label %12
12: ; preds = %28, %11
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 40
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = call i64 (...) @kbhit()
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = call i32 (...) @getkey()
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = call i32 @isalnum(i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %18
br label %28
24: ; preds = %18
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %50
26: ; preds = %15
%27 = call i32 @flashywait(i32 15)
br label %28
28: ; preds = %26, %23
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %12
31: ; preds = %12
store i32 0, i32* %6
br label %32
32: ; preds = %45, %31
%33 = load i32, i32* %6
%34 = icmp slt i32 %33, 40
br i1 %34, label %35, label %48
35: ; preds = %32
%36 = call i64 (...) @kbhit()
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = call i32 @gwrite(i32 %39, i32 %40, i8 signext 95, i32 3)
%42 = call i32 (...) @getkey()
store i32 %42, i32* %3
br label %50
43: ; preds = %35
%44 = call i32 @flashywait(i32 15)
br label %45
45: ; preds = %43
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %32
48: ; preds = %32
br label %49
49: ; preds = %48
br i1 true, label %11, label %50
50: ; preds = %24, %38, %49
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
define i32 @getinitial(i32 %0, i32 %1) {
%3 = tail call i32 @gwrite(i32 %0, i32 %1, i8 signext 95, i32 3)
br label %4
4: ; preds = %17, %2
%5 = phi i32 [ 0, %2 ], [ %18, %17 ]
%6 = tail call i64 (...) @kbhit()
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = tail call i32 (...) @getkey()
%10 = tail call i32 @isalnum(i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %30
12: ; preds = %4
%13 = tail call i32 @flashywait(i32 15)
br label %14
14: ; preds = %8, %12
%15 = add nuw nsw i32 %5, 1
%16 = icmp eq i32 %15, 40
br i1 %16, label %19, label %17
17: ; preds = %26, %14
%18 = phi i32 [ %15, %14 ], [ 0, %26 ]
br label %4
19: ; preds = %14, %26
%20 = phi i32 [ %28, %26 ], [ 0, %14 ]
%21 = tail call i64 (...) @kbhit()
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = tail call i32 @gwrite(i32 %0, i32 %1, i8 signext 95, i32 3)
%25 = tail call i32 (...) @getkey()
br label %30
26: ; preds = %19
%27 = tail call i32 @flashywait(i32 15)
%28 = add nuw nsw i32 %20, 1
%29 = icmp eq i32 %28, 40
br i1 %29, label %17, label %19
30: ; preds = %8, %23
%31 = phi i32 [ %25, %23 ], [ %9, %8 ]
ret i32 %31
}