#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_alloctimer();
int /*<<< orphan*/ api_beep(int);
int /*<<< orphan*/ api_end();
int api_getkey(int);
int /*<<< orphan*/ api_inittimer(int, int);
int /*<<< orphan*/ api_settimer(int, int);
void HariMain(void) {
  int i, timer;
  timer = api_alloctimer();
  api_inittimer(timer, 128);
  for (i = 20000000; i >= 20000; i -= i / 100) {
    api_beep(i);
    api_settimer(timer, 1);
    if (api_getkey(1) != 128) {
      break;
    }
  }
  api_beep(0);
  api_end();
}


x86 assembly (clang, -O0):
<HariMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <api_alloctimer@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x80,%esi
call   1040 <api_inittimer@plt>
movl   $0x1312d00,-0x4(%rbp)
cmpl   $0x4e20,-0x4(%rbp)
jl     11e1 <HariMain+0x81>
mov    -0x4(%rbp),%edi
call   1080 <api_beep@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1050 <api_settimer@plt>
mov    $0x1,%edi
call   1070 <api_getkey@plt>
cmp    $0x80,%eax
je     11c2 <HariMain+0x62>
jmp    11e1 <HariMain+0x81>
jmp    11c7 <HariMain+0x67>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <HariMain+0x26>
xor    %edi,%edi
call   1080 <api_beep@plt>
mov    $0x0,%al
call   1030 <api_end@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HariMain>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <api_alloctimer@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x80,%esi
call   1040 <api_inittimer@plt>
mov    $0x1312d00,%ebp
nopl   (%rax)
mov    %ebp,%edi
call   1080 <api_beep@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <api_settimer@plt>
mov    $0x1,%edi
call   1070 <api_getkey@plt>
cmp    $0x80,%eax
jne    11bb <HariMain+0x5b>
mov    %ebp,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
sub    %eax,%ebp
cmp    $0x4e1f,%ebp
jg     1180 <HariMain+0x20>
xor    %edi,%edi
call   1080 <api_beep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <api_end@plt>

LLVM IR (-O0):
define void @HariMain() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @api_alloctimer()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @api_inittimer(i32 %4, i32 128)
store i32 20000000, i32* %1
br label %6
6: ; preds = %18, %0
%7 = load i32, i32* %1
%8 = icmp sge i32 %7, 20000
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i32, i32* %1
%11 = call i32 @api_beep(i32 %10)
%12 = load i32, i32* %2
%13 = call i32 @api_settimer(i32 %12, i32 1)
%14 = call i32 @api_getkey(i32 1)
%15 = icmp ne i32 %14, 128
br i1 %15, label %16, label %17
16: ; preds = %9
br label %23
17: ; preds = %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %1
%20 = sdiv i32 %19, 100
%21 = load i32, i32* %1
%22 = sub nsw i32 %21, %20
store i32 %22, i32* %1
br label %6
23: ; preds = %16, %6
%24 = call i32 @api_beep(i32 0)
%25 = call i32 (...) @api_end()
ret void
}

LLVM IR (-O2):
define void @HariMain() {
%1 = tail call i32 (...) @api_alloctimer()
%2 = tail call i32 @api_inittimer(i32 %1, i32 128)
br label %3
3: ; preds = %0, %9
%4 = phi i32 [ 20000000, %0 ], [ %11, %9 ]
%5 = tail call i32 @api_beep(i32 %4)
%6 = tail call i32 @api_settimer(i32 %1, i32 1)
%7 = tail call i32 @api_getkey(i32 1)
%8 = icmp eq i32 %7, 128
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = udiv i32 %4, 100
%11 = sub nsw i32 %4, %10
%12 = icmp sgt i32 %11, 19999
br i1 %12, label %3, label %13
13: ; preds = %3, %9
%14 = tail call i32 @api_beep(i32 0)
%15 = tail call i32 (...) @api_end()
ret void
}