#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*/ api_end();
int getkey(int);
int /*<<< orphan*/ init_mem();
scalar_t__ malloc(int);
int /*<<< orphan*/ win_close(int);
int /*<<< orphan*/ win_fill(int, int, int, int, int, int /*<<< orphan*/);
int win_open(char *, int, int, int, char *);
int /*<<< orphan*/ win_puts(int, int, int, int, int, char *);
void HariMain(void) {
  char *buf;
  int win;
  int key, x, y;
  init_mem();
  buf = (char *)malloc(160 * 100);
  win = win_open(buf, 160, 100, -1, "WIN-WALK");
  win_fill(win, 4, 24, 155, 95, 0);
  x = 76;
  y = 56;
  win_puts(win, x, y, 3, 1, "*");
  for (;;) {
    key = getkey(1);
    win_puts(win, x, y, 0, 1, "*");
    if ('a' == key && x > 4)
      x -= 8;
    if ('d' == key && x < 148)
      x += 8;
    if ('w' == key && y > 24)
      y -= 8;
    if ('s' == key && y < 80)
      y += 8;
    if (0x0a == key)
      break;
    win_puts(win, x, y, 3, 1, "*");
  }
  win_close(win);
  api_end();
}


x86 assembly (clang, -O0):
<HariMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <init_mem@plt>
mov    $0x3e80,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xa0,%esi
mov    $0x64,%edx
mov    $0xffffffff,%ecx
lea    0xe49(%rip),%r8
call   10a0 <win_open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x4,%esi
mov    $0x18,%edx
mov    $0x9b,%ecx
mov    $0x5f,%r8d
xor    %r9d,%r9d
call   1040 <win_fill@plt>
movl   $0x4c,-0x14(%rbp)
movl   $0x38,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    $0x3,%ecx
mov    $0x1,%r8d
lea    0xe01(%rip),%r9
call   1090 <win_puts@plt>
mov    $0x1,%edi
call   1080 <getkey@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
xor    %ecx,%ecx
mov    $0x1,%r8d
lea    0xdd7(%rip),%r9
call   1090 <win_puts@plt>
mov    $0x61,%eax
cmp    -0x10(%rbp),%eax
jne    1258 <HariMain+0xd8>
cmpl   $0x4,-0x14(%rbp)
jle    1258 <HariMain+0xd8>
mov    -0x14(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    $0x64,%eax
cmp    -0x10(%rbp),%eax
jne    127c <HariMain+0xfc>
cmpl   $0x94,-0x14(%rbp)
jge    127c <HariMain+0xfc>
mov    -0x14(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    $0x77,%eax
cmp    -0x10(%rbp),%eax
jne    129d <HariMain+0x11d>
cmpl   $0x18,-0x18(%rbp)
jle    129d <HariMain+0x11d>
mov    -0x18(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    $0x73,%eax
cmp    -0x10(%rbp),%eax
jne    12be <HariMain+0x13e>
cmpl   $0x50,-0x18(%rbp)
jge    12be <HariMain+0x13e>
mov    -0x18(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    $0xa,%eax
cmp    -0x10(%rbp),%eax
jne    12d1 <HariMain+0x151>
jmp    12f6 <HariMain+0x176>
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    $0x3,%ecx
mov    $0x1,%r8d
lea    0xd1d(%rip),%r9
call   1090 <win_puts@plt>
jmp    120d <HariMain+0x8d>
mov    -0xc(%rbp),%edi
call   1050 <win_close@plt>
mov    $0x0,%al
call   1030 <api_end@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HariMain>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1060 <init_mem@plt>
mov    $0x3e80,%edi
call   1070 <malloc@plt>
lea    0xe60(%rip),%r8
mov    %rax,%rdi
mov    $0xa0,%esi
mov    $0x64,%edx
mov    $0xffffffff,%ecx
call   10a0 <win_open@plt>
mov    %eax,%r15d
mov    %eax,%edi
mov    $0x4,%esi
mov    $0x18,%edx
mov    $0x9b,%ecx
mov    $0x5f,%r8d
xor    %r9d,%r9d
call   1040 <win_fill@plt>
lea    0xe29(%rip),%r14
mov    $0x4c,%ebx
mov    $0x38,%ebp
mov    %r15d,%edi
mov    $0x4c,%esi
mov    $0x38,%edx
nopw   0x0(%rax,%rax,1)
mov    $0x3,%ecx
mov    $0x1,%r8d
mov    %r14,%r9
call   1090 <win_puts@plt>
mov    $0x1,%edi
call   1080 <getkey@plt>
mov    %eax,%r12d
mov    %r15d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    $0x1,%r8d
mov    %r14,%r9
call   1090 <win_puts@plt>
lea    -0x8(%rbx),%eax
cmp    $0x5,%ebx
cmovl  %ebx,%eax
cmp    $0x61,%r12d
cmovne %ebx,%eax
lea    0x8(%rax),%ebx
cmp    $0x94,%eax
cmovge %eax,%ebx
cmp    $0x64,%r12d
cmovne %eax,%ebx
lea    -0x8(%rbp),%eax
cmp    $0x19,%ebp
cmovl  %ebp,%eax
cmp    $0x77,%r12d
cmovne %ebp,%eax
lea    0x8(%rax),%ebp
cmp    $0x50,%eax
cmovge %eax,%ebp
cmp    $0x73,%r12d
cmovne %eax,%ebp
cmp    $0xa,%r12d
je     128b <HariMain+0x10b>
mov    %r15d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
jmp    1200 <HariMain+0x80>
mov    %r15d,%edi
call   1050 <win_close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <api_end@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"WIN-WALK\00"
@.str.1 = [2 x i8] c"*\00"
define void @HariMain() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (...) @init_mem()
%7 = call i64 @malloc(i32 16000)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %1
%9 = load i8*, i8** %1
%10 = call i32 @win_open(i8* %9, i32 160, i32 100, i32 -1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = call i32 @win_fill(i32 %11, i32 4, i32 24, i32 155, i32 95, i32 0)
store i32 76, i32* %4
store i32 56, i32* %5
%13 = load i32, i32* %2
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = call i32 @win_puts(i32 %13, i32 %14, i32 %15, i32 3, i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %62, %0
%18 = call i32 @getkey(i32 1)
store i32 %18, i32* %3
%19 = load i32, i32* %2
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = call i32 @win_puts(i32 %19, i32 %20, i32 %21, i32 0, i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %3
%24 = icmp eq i32 97, %23
br i1 %24, label %25, label %31
25: ; preds = %17
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 4
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %4
%30 = sub nsw i32 %29, 8
store i32 %30, i32* %4
br label %31
31: ; preds = %28, %25, %17
%32 = load i32, i32* %3
%33 = icmp eq i32 100, %32
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i32, i32* %4
%36 = icmp slt i32 %35, 148
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 8
store i32 %39, i32* %4
br label %40
40: ; preds = %37, %34, %31
%41 = load i32, i32* %3
%42 = icmp eq i32 119, %41
br i1 %42, label %43, label %49
43: ; preds = %40
%44 = load i32, i32* %5
%45 = icmp sgt i32 %44, 24
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* %5
%48 = sub nsw i32 %47, 8
store i32 %48, i32* %5
br label %49
49: ; preds = %46, %43, %40
%50 = load i32, i32* %3
%51 = icmp eq i32 115, %50
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i32, i32* %5
%54 = icmp slt i32 %53, 80
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 8
store i32 %57, i32* %5
br label %58
58: ; preds = %55, %52, %49
%59 = load i32, i32* %3
%60 = icmp eq i32 10, %59
br i1 %60, label %61, label %62
61: ; preds = %58
br label %67
62: ; preds = %58
%63 = load i32, i32* %2
%64 = load i32, i32* %4
%65 = load i32, i32* %5
%66 = call i32 @win_puts(i32 %63, i32 %64, i32 %65, i32 3, i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %17
67: ; preds = %61
%68 = load i32, i32* %2
%69 = call i32 @win_close(i32 %68)
%70 = call i32 (...) @api_end()
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"WIN-WALK\00"
@.str.1 = [2 x i8] c"*\00"
define void @HariMain() {
%1 = tail call i32 (...) @init_mem()
%2 = tail call i64 @malloc(i32 16000)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @win_open(i8* %3, i32 160, i32 100, i32 -1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @win_fill(i32 %4, i32 4, i32 24, i32 155, i32 95, i32 0)
%6 = tail call i32 @win_puts(i32 %4, i32 76, i32 56, i32 3, i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %33, %0
%8 = phi i32 [ 76, %0 ], [ %21, %33 ]
%9 = phi i32 [ 56, %0 ], [ %31, %33 ]
%10 = tail call i32 @getkey(i32 1)
%11 = tail call i32 @win_puts(i32 %4, i32 %8, i32 %9, i32 0, i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32 %10, 97
%13 = icmp sgt i32 %8, 4
%14 = select i1 %12, i1 %13, i1 false
%15 = add nsw i32 %8, -8
%16 = select i1 %14, i32 %15, i32 %8
%17 = icmp eq i32 %10, 100
%18 = icmp slt i32 %16, 148
%19 = select i1 %17, i1 %18, i1 false
%20 = add nsw i32 %16, 8
%21 = select i1 %19, i32 %20, i32 %16
%22 = icmp eq i32 %10, 119
%23 = icmp sgt i32 %9, 24
%24 = select i1 %22, i1 %23, i1 false
%25 = add nsw i32 %9, -8
%26 = select i1 %24, i32 %25, i32 %9
%27 = icmp eq i32 %10, 115
%28 = icmp slt i32 %26, 80
%29 = select i1 %27, i1 %28, i1 false
%30 = add nsw i32 %26, 8
%31 = select i1 %29, i32 %30, i32 %26
%32 = icmp eq i32 %10, 10
br i1 %32, label %35, label %33
33: ; preds = %7
%34 = tail call i32 @win_puts(i32 %4, i32 %21, i32 %31, i32 3, i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %7
35: ; preds = %7
%36 = tail call i32 @win_close(i32 %4)
%37 = tail call i32 (...) @api_end()
ret void
}