#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_boxfilwin(int, int, int, int, int, int);
int /*<<< orphan*/ api_end();
int api_getkey(int);
int /*<<< orphan*/ api_initmalloc();
int /*<<< orphan*/ api_inittimer(int, int);
char *api_malloc(int);
int api_openwin(char *, int, int, int, char *);
int /*<<< orphan*/ api_putstrwin(int, int, int, int /*<<< orphan*/, int,
                                 char *);
int /*<<< orphan*/ api_settimer(int, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
void HariMain(void) {
  char *buf, s[12];
  int win, timer, sec = 0, min = 0, hou = 0;
  api_initmalloc();
  buf = api_malloc(150 * 50);
  win = api_openwin(buf, 150, 50, -1, "noodle");
  timer = api_alloctimer();
  api_inittimer(timer, 128);
  for (;;) {
    sprintf(s, "%5d:%02d:%02d", hou, min, sec);
    api_boxfilwin(win, 28, 27, 115, 41, 7);
    api_putstrwin(win, 28, 27, 0, 11, s);
    api_settimer(timer, 100);
    if (api_getkey(1) != 128) {
      break;
    }
    sec++;
    if (sec == 60) {
      sec = 0;
      min++;
      if (min == 60) {
        min = 0;
        hou++;
      }
    }
  }
  api_end();
}


x86 assembly (clang, -O0):
<HariMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <api_initmalloc@plt>
mov    $0x1d4c,%edi
call   1070 <api_malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x96,%esi
mov    $0x32,%edx
mov    $0xffffffff,%ecx
lea    0xe04(%rip),%r8
call   10b0 <api_openwin@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <api_alloctimer@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x80,%esi
call   1050 <api_inittimer@plt>
lea    -0x14(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xdd7(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x18(%rbp),%edi
mov    $0x1c,%esi
mov    $0x1b,%edx
mov    $0x73,%ecx
mov    $0x29,%r8d
mov    $0x7,%r9d
call   10d0 <api_boxfilwin@plt>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%r9
mov    $0x1c,%esi
mov    $0x1b,%edx
xor    %ecx,%ecx
mov    $0xb,%r8d
call   10a0 <api_putstrwin@plt>
mov    -0x1c(%rbp),%edi
mov    $0x64,%esi
call   1060 <api_settimer@plt>
mov    $0x1,%edi
call   1090 <api_getkey@plt>
cmp    $0x80,%eax
je     129d <HariMain+0xed>
jmp    12e4 <HariMain+0x134>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x3c,-0x20(%rbp)
jne    12df <HariMain+0x12f>
movl   $0x0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x3c,-0x24(%rbp)
jne    12da <HariMain+0x12a>
movl   $0x0,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12df <HariMain+0x12f>
jmp    121b <HariMain+0x6b>
mov    $0x0,%al
call   1030 <api_end@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HariMain>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1040 <api_initmalloc@plt>
mov    $0x1d4c,%edi
call   1070 <api_malloc@plt>
lea    0xe2a(%rip),%r8
mov    %rax,%rdi
mov    $0x96,%esi
mov    $0x32,%edx
mov    $0xffffffff,%ecx
call   10b0 <api_openwin@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <api_alloctimer@plt>
mov    %eax,%r15d
mov    %eax,%edi
mov    $0x80,%esi
call   1050 <api_inittimer@plt>
lea    0xc(%rsp),%r12
xor    %ebp,%ebp
xor    %r13d,%r13d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
lea    0xddd(%rip),%rsi
mov    %r13d,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
call   10c0 <sprintf@plt>
mov    %ebx,%edi
mov    $0x1c,%esi
mov    $0x1b,%edx
mov    $0x73,%ecx
mov    $0x29,%r8d
mov    $0x7,%r9d
call   10d0 <api_boxfilwin@plt>
mov    %ebx,%edi
mov    $0x1c,%esi
mov    $0x1b,%edx
xor    %ecx,%ecx
mov    $0xb,%r8d
mov    %r12,%r9
call   10a0 <api_putstrwin@plt>
mov    %r15d,%edi
mov    $0x64,%esi
call   1060 <api_settimer@plt>
mov    $0x1,%edi
call   1090 <api_getkey@plt>
cmp    $0x80,%eax
jne    12b8 <HariMain+0x108>
add    $0x1,%r14d
cmp    $0x3c,%r14d
jne    1220 <HariMain+0x70>
add    $0x1,%ebp
xor    %eax,%eax
cmp    $0x3c,%ebp
sete   %al
mov    $0x0,%ecx
cmove  %ecx,%ebp
add    %eax,%r13d
jmp    120f <HariMain+0x5f>
xor    %eax,%eax
call   1030 <api_end@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"noodle\00"
@.str.1 = [14 x i8] c"%5d:%02d:%02d\00"
define void @HariMain() {
%1 = alloca i8*
%2 = alloca [12 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = call i32 (...) @api_initmalloc()
%9 = call i8* @api_malloc(i32 7500)
store i8* %9, i8** %1
%10 = load i8*, i8** %1
%11 = call i32 @api_openwin(i8* %10, i32 150, i32 50, i32 -1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %3
%12 = call i32 (...) @api_alloctimer()
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = call i32 @api_inittimer(i32 %13, i32 128)
br label %15
15: ; preds = %45, %0
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = load i32, i32* %5
%20 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18, i32 %19)
%21 = load i32, i32* %3
%22 = call i32 @api_boxfilwin(i32 %21, i32 28, i32 27, i32 115, i32 41, i32 7)
%23 = load i32, i32* %3
%24 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%25 = call i32 @api_putstrwin(i32 %23, i32 28, i32 27, i32 0, i32 11, i8* %24)
%26 = load i32, i32* %4
%27 = call i32 @api_settimer(i32 %26, i32 100)
%28 = call i32 @api_getkey(i32 1)
%29 = icmp ne i32 %28, 128
br i1 %29, label %30, label %31
30: ; preds = %15
br label %46
31: ; preds = %15
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, 60
br i1 %35, label %36, label %45
36: ; preds = %31
store i32 0, i32* %5
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, 60
br i1 %40, label %41, label %44
41: ; preds = %36
store i32 0, i32* %6
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %44
44: ; preds = %41, %36
br label %45
45: ; preds = %44, %31
br label %15
46: ; preds = %30
%47 = call i32 (...) @api_end()
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"noodle\00"
@.str.1 = [14 x i8] c"%5d:%02d:%02d\00"
define void @HariMain() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @api_initmalloc()
%4 = tail call i8* @api_malloc(i32 7500)
%5 = tail call i32 @api_openwin(i8* %4, i32 150, i32 50, i32 -1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (...) @api_alloctimer()
%7 = tail call i32 @api_inittimer(i32 %6, i32 128)
br label %8
8: ; preds = %22, %0
%9 = phi i32 [ %25, %22 ], [ 0, %0 ]
%10 = phi i32 [ %27, %22 ], [ 0, %0 ]
br label %11
11: ; preds = %8, %19
%12 = phi i32 [ %20, %19 ], [ 0, %8 ]
%13 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %9, i32 %12)
%14 = call i32 @api_boxfilwin(i32 %5, i32 28, i32 27, i32 115, i32 41, i32 7)
%15 = call i32 @api_putstrwin(i32 %5, i32 28, i32 27, i32 0, i32 11, i8* %2)
%16 = call i32 @api_settimer(i32 %6, i32 100)
%17 = call i32 @api_getkey(i32 1)
%18 = icmp eq i32 %17, 128
br i1 %18, label %19, label %28
19: ; preds = %11
%20 = add nuw nsw i32 %12, 1
%21 = icmp eq i32 %20, 60
br i1 %21, label %22, label %11
22: ; preds = %19
%23 = add nsw i32 %9, 1
%24 = icmp eq i32 %23, 60
%25 = select i1 %24, i32 0, i32 %23
%26 = zext i1 %24 to i32
%27 = add nuw nsw i32 %10, %26
br label %8
28: ; preds = %11
%29 = call i32 (...) @api_end()
ret void
}