#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*/ d2x24_end_screen();
int d2x24_getch();
int /*<<< orphan*/ d2x24_printf(int, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int wait_key(char *msg) {
  int mych;
  d2x24_printf(1, "%-24s", msg);
  while (-1 != d2x24_getch())
    ;
  while (1) {
    mych = d2x24_getch();
    if ((mych == 'q') || (mych == 'Q')) {
      d2x24_end_screen();
      exit(0);
    }
    if (mych != -1) {
      break;
    }
    usleep(400000);
    d2x24_printf(1, "%-24s", " ");
    mych = d2x24_getch();
    if ((mych == 'q') || (mych == 'Q')) {
      d2x24_end_screen();
      exit(0);
    }
    if (mych != -1) {
      break;
    }
    usleep(400000);
    d2x24_printf(1, msg);
  }
  return mych;
}


x86 assembly (clang, -O0):
<wait_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1040 <d2x24_printf@plt>
mov    $0x0,%al
call   1030 <d2x24_getch@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     118e <wait_key+0x3e>
jmp    1173 <wait_key+0x23>
jmp    1193 <wait_key+0x43>
mov    $0x0,%al
call   1030 <d2x24_getch@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x71,-0xc(%rbp)
je     11b1 <wait_key+0x61>
cmpl   $0x51,-0xc(%rbp)
jne    11bf <wait_key+0x6f>
mov    $0x0,%al
call   1050 <d2x24_end_screen@plt>
xor    %edi,%edi
call   1060 <exit@plt>
cmpl   $0xffffffff,-0xc(%rbp)
je     11ce <wait_key+0x7e>
jmp    124c <wait_key+0xfc>
mov    $0x61a80,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
lea    0xe1c(%rip),%rsi
lea    0xe1b(%rip),%rdx
mov    $0x0,%al
call   1040 <d2x24_printf@plt>
mov    $0x0,%al
call   1030 <d2x24_getch@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x71,-0xc(%rbp)
je     1210 <wait_key+0xc0>
cmpl   $0x51,-0xc(%rbp)
jne    121e <wait_key+0xce>
mov    $0x0,%al
call   1050 <d2x24_end_screen@plt>
xor    %edi,%edi
call   1060 <exit@plt>
cmpl   $0xffffffff,-0xc(%rbp)
je     122d <wait_key+0xdd>
jmp    124c <wait_key+0xfc>
mov    $0x61a80,%edi
call   1070 <usleep@plt>
mov    -0x8(%rbp),%rsi
mov    $0x1,%edi
mov    $0x0,%al
call   1040 <d2x24_printf@plt>
jmp    1193 <wait_key+0x43>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_key>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xea1(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <d2x24_printf@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <d2x24_getch@plt>
cmp    $0xffffffff,%eax
jne    1170 <wait_key+0x20>
xor    %eax,%eax
call   1030 <d2x24_getch@plt>
mov    %eax,%ecx
and    $0xffffffdf,%ecx
cmp    $0x51,%ecx
je     1201 <wait_key+0xb1>
lea    0xe6c(%rip),%r14
lea    0xe6b(%rip),%r15
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
jne    120f <wait_key+0xbf>
mov    $0x61a80,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <d2x24_printf@plt>
xor    %eax,%eax
call   1030 <d2x24_getch@plt>
mov    %eax,%ecx
and    $0xffffffdf,%ecx
cmp    $0x51,%ecx
je     1201 <wait_key+0xb1>
cmp    $0xffffffff,%eax
jne    120f <wait_key+0xbf>
mov    $0x61a80,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <d2x24_printf@plt>
xor    %eax,%eax
call   1030 <d2x24_getch@plt>
mov    %eax,%ecx
and    $0xffffffdf,%ecx
cmp    $0x51,%ecx
jne    11a0 <wait_key+0x50>
xor    %eax,%eax
call   1050 <d2x24_end_screen@plt>
xor    %edi,%edi
call   1060 <exit@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%-24s\00"
@.str.1 = [2 x i8] c" \00"
define i32 @wait_key(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 (i32, i8*, ...) @d2x24_printf(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %6
6: ; preds = %9, %1
%7 = call i32 (...) @d2x24_getch()
%8 = icmp ne i32 -1, %7
br i1 %8, label %9, label %10
9: ; preds = %6
br label %6
10: ; preds = %6
br label %11
11: ; preds = %10, %41
%12 = call i32 (...) @d2x24_getch()
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 113
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 81
br i1 %17, label %18, label %21
18: ; preds = %15, %11
%19 = call i32 (...) @d2x24_end_screen()
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %15
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %21
br label %45
25: ; preds = %21
%26 = call i32 @usleep(i32 400000)
%27 = call i32 (i32, i8*, ...) @d2x24_printf(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 (...) @d2x24_getch()
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 113
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, 81
br i1 %33, label %34, label %37
34: ; preds = %31, %25
%35 = call i32 (...) @d2x24_end_screen()
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %31
%38 = load i32, i32* %3
%39 = icmp ne i32 %38, -1
br i1 %39, label %40, label %41
40: ; preds = %37
br label %45
41: ; preds = %37
%42 = call i32 @usleep(i32 400000)
%43 = load i8*, i8** %2
%44 = call i32 (i32, i8*, ...) @d2x24_printf(i32 1, i8* %43)
br label %11
45: ; preds = %40, %24
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [6 x i8] c"%-24s\00"
@.str.1 = [2 x i8] c" \00"
define i32 @wait_key(i8* %0) {
%2 = tail call i32 (i32, i8*, ...) @d2x24_printf(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %3
3: ; preds = %3, %1
%4 = tail call i32 (...) @d2x24_getch()
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %3
6: ; preds = %3
%7 = tail call i32 (...) @d2x24_getch()
%8 = and i32 %7, -33
%9 = icmp eq i32 %8, 81
br i1 %9, label %10, label %13
10: ; preds = %27, %6
%11 = tail call i32 (...) @d2x24_end_screen()
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %6, %27
%14 = phi i32 [ %30, %27 ], [ %7, %6 ]
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = tail call i32 @usleep(i32 400000)
%18 = tail call i32 (i32, i8*, ...) @d2x24_printf(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 (...) @d2x24_getch()
%20 = and i32 %19, -33
%21 = icmp eq i32 %20, 81
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = tail call i32 (...) @d2x24_end_screen()
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %16
%26 = icmp eq i32 %19, -1
br i1 %26, label %27, label %33
27: ; preds = %25
%28 = tail call i32 @usleep(i32 400000)
%29 = tail call i32 (i32, i8*, ...) @d2x24_printf(i32 1, i8* %0)
%30 = tail call i32 (...) @d2x24_getch()
%31 = and i32 %30, -33
%32 = icmp eq i32 %31, 81
br i1 %32, label %10, label %13
33: ; preds = %25, %13
%34 = phi i32 [ %14, %13 ], [ %19, %25 ]
ret i32 %34
}