#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 api_getkey(int);
int /*<<< orphan*/ api_settimer(int, int);
void wait(int i, int timer, char *keyflag) {
  int j;
  if (i > 0) {
    api_settimer(timer, i);
    i = 128;
  } else {
    i = 0x0a;
  }
  for (;;) {
    j = api_getkey(1);
    if (i == j) {
      break;
    }
    if (j == '4') {
      keyflag[0] = 1;
    }
    if (j == '6') {
      keyflag[1] = 1;
    }
    if (j == ' ') {
      keyflag[2] = 1;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1153 <wait+0x33>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <api_settimer@plt>
movl   $0x80,-0x4(%rbp)
jmp    115a <wait+0x3a>
movl   $0xa,-0x4(%rbp)
jmp    115f <wait+0x3f>
mov    $0x1,%edi
call   1040 <api_getkey@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    117d <wait+0x5d>
jmp    11b7 <wait+0x97>
cmpl   $0x34,-0x14(%rbp)
jne    118e <wait+0x6e>
mov    -0x10(%rbp),%rax
movb   $0x1,(%rax)
cmpl   $0x36,-0x14(%rbp)
jne    11a0 <wait+0x80>
mov    -0x10(%rbp),%rax
movb   $0x1,0x1(%rax)
cmpl   $0x20,-0x14(%rbp)
jne    11b2 <wait+0x92>
mov    -0x10(%rbp),%rax
movb   $0x1,0x2(%rax)
jmp    115f <wait+0x3f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
test   %edi,%edi
jle    1140 <wait+0x20>
mov    %edi,%eax
mov    %esi,%edi
mov    %eax,%esi
call   1030 <api_settimer@plt>
mov    $0x80,%ebp
jmp    1145 <wait+0x25>
mov    $0xa,%ebp
mov    $0x1,%edi
call   1040 <api_getkey@plt>
cmp    %eax,%ebp
jne    115e <wait+0x3e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x2(%rbx),%r14
lea    0x1(%rbx),%r15
jmp    1184 <wait+0x64>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rcx
movb   $0x1,(%rcx)
mov    $0x1,%edi
call   1040 <api_getkey@plt>
cmp    %eax,%ebp
je     1153 <wait+0x33>
cmp    $0x20,%eax
je     1170 <wait+0x50>
mov    %rbx,%rcx
cmp    $0x34,%eax
je     1173 <wait+0x53>
mov    %r15,%rcx
cmp    $0x36,%eax
je     1173 <wait+0x53>
jmp    1176 <wait+0x56>

LLVM IR (-O0):
define void @wait(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = call i32 @api_settimer(i32 %11, i32 %12)
store i32 128, i32* %4
br label %15
14: ; preds = %3
store i32 10, i32* %4
br label %15
15: ; preds = %14, %10
br label %16
16: ; preds = %40, %15
%17 = call i32 @api_getkey(i32 1)
store i32 %17, i32* %7
%18 = load i32, i32* %4
%19 = load i32, i32* %7
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %16
br label %41
22: ; preds = %16
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 52
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 1, i8* %27
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 54
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8 1, i8* %33
br label %34
34: ; preds = %31, %28
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 32
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i64 2
store i8 1, i8* %39
br label %40
40: ; preds = %37, %34
br label %16
41: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @wait(i32 %0, i32 %1, i8* nocapture writeonly %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @api_settimer(i32 %1, i32 %0)
br label %7
7: ; preds = %3, %5
%8 = phi i32 [ 128, %5 ], [ 10, %3 ]
%9 = tail call i32 @api_getkey(i32 1)
%10 = icmp eq i32 %8, %9
br i1 %10, label %23, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %2, i64 2
%13 = getelementptr inbounds i8, i8* %2, i64 1
br label %14
14: ; preds = %11, %20
%15 = phi i32 [ %9, %11 ], [ %21, %20 ]
switch i32 %15, label %20 [
i32 52, label %18
i32 54, label %16
i32 32, label %17
]
16: ; preds = %14
br label %18
17: ; preds = %14
br label %18
18: ; preds = %14, %17, %16
%19 = phi i8* [ %13, %16 ], [ %12, %17 ], [ %2, %14 ]
store i8 1, i8* %19
br label %20
20: ; preds = %18, %14
%21 = tail call i32 @api_getkey(i32 1)
%22 = icmp eq i32 %8, %21
br i1 %22, label %23, label %14
23: ; preds = %20, %7
ret void
}