#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 /*<<< orphan*/ getkey(int);
int /*<<< orphan*/ init_mem();
scalar_t__ malloc(int);
char rgb2pal(int, int, int /*<<< orphan*/, int, int);
int win_open(char *, int, int, int, char *);
int /*<<< orphan*/ win_refresh(int, int, int, int, int);
void HariMain(void) {
  char *buf;
  int win, x, y;
  init_mem();
  buf = (char *)malloc(144 * 164);
  win = win_open(buf, 144, 164, -1, "WIN-COLOR2");
  for (y = 0; y < 128; ++y) {
    for (x = 0; x < 128; ++x)
      buf[(x + 8) + (y + 28) * 144] = rgb2pal(x * 2, y * 2, 0, x, y);
  }
  win_refresh(win, 8, 28, 136, 156);
  getkey(1);
  api_end();
}


x86 assembly (clang, -O0):
<HariMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <init_mem@plt>
mov    $0x5c40,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x90,%esi
mov    $0xa4,%edx
mov    $0xffffffff,%ecx
lea    0xe59(%rip),%r8
call   1090 <win_open@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jge    1232 <HariMain+0xc2>
movl   $0x0,-0x10(%rbp)
cmpl   $0x80,-0x10(%rbp)
jge    121f <HariMain+0xaf>
mov    -0x10(%rbp),%edi
shl    $0x1,%edi
mov    -0x14(%rbp),%esi
shl    $0x1,%esi
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
xor    %edx,%edx
call   1040 <rgb2pal@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x8,%ecx
mov    -0x14(%rbp),%esi
add    $0x1c,%esi
imul   $0x90,%esi,%esi
add    %esi,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ca <HariMain+0x5a>
jmp    1224 <HariMain+0xb4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b6 <HariMain+0x46>
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
mov    $0x1c,%edx
mov    $0x88,%ecx
mov    $0x9c,%r8d
call   1080 <win_refresh@plt>
mov    $0x1,%edi
call   1070 <getkey@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   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <init_mem@plt>
mov    $0x5c40,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
lea    0xe67(%rip),%r8
mov    %rax,%rdi
mov    $0x90,%esi
mov    $0xa4,%edx
mov    $0xffffffff,%ecx
call   1090 <win_open@plt>
mov    %eax,%r15d
add    $0xfc8,%r12
nopw   0x0(%rax,%rax,1)
lea    (%r14,%r14,1),%r13d
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r13d,%esi
xor    %edx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
call   1040 <rgb2pal@plt>
mov    %al,(%r12,%rbp,1)
add    $0x1,%rbp
add    $0x2,%ebx
cmp    $0x80,%rbp
jne    11d0 <HariMain+0x60>
add    $0x1,%r14
add    $0x90,%r12
cmp    $0x80,%r14
jne    11c0 <HariMain+0x50>
mov    %r15d,%edi
mov    $0x8,%esi
mov    $0x1c,%edx
mov    $0x88,%ecx
mov    $0x9c,%r8d
call   1080 <win_refresh@plt>
mov    $0x1,%edi
call   1070 <getkey@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <api_end@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"WIN-COLOR2\00"
define void @HariMain() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (...) @init_mem()
%6 = call i64 @malloc(i32 23616)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = call i32 @win_open(i8* %8, i32 144, i32 164, i32 -1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %9, i32* %2
store i32 0, i32* %4
br label %10
10: ; preds = %38, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 128
br i1 %12, label %13, label %41
13: ; preds = %10
store i32 0, i32* %3
br label %14
14: ; preds = %34, %13
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 128
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = load i32, i32* %3
%19 = mul nsw i32 %18, 2
%20 = load i32, i32* %4
%21 = mul nsw i32 %20, 2
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = call signext i8 @rgb2pal(i32 %19, i32 %21, i32 0, i32 %22, i32 %23)
%25 = load i8*, i8** %1
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 8
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 28
%30 = mul nsw i32 %29, 144
%31 = add nsw i32 %27, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %25, i64 %32
store i8 %24, i8* %33
br label %34
34: ; preds = %17
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %14
37: ; preds = %14
br label %38
38: ; preds = %37
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %10
41: ; preds = %10
%42 = load i32, i32* %2
%43 = call i32 @win_refresh(i32 %42, i32 8, i32 28, i32 136, i32 156)
%44 = call i32 @getkey(i32 1)
%45 = call i32 (...) @api_end()
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"WIN-COLOR2\00"
define void @HariMain() {
%1 = tail call i32 (...) @init_mem()
%2 = tail call i64 @malloc(i32 23616)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @win_open(i8* %3, i32 144, i32 164, i32 -1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %0, %20
%6 = phi i64 [ 0, %0 ], [ %21, %20 ]
%7 = trunc i64 %6 to i32
%8 = shl nuw nsw i32 %7, 1
%9 = mul nuw nsw i64 %6, 144
%10 = add nuw nsw i64 %9, 4040
br label %11
11: ; preds = %5, %11
%12 = phi i64 [ 0, %5 ], [ %18, %11 ]
%13 = trunc i64 %12 to i32
%14 = shl nuw nsw i32 %13, 1
%15 = tail call signext i8 @rgb2pal(i32 %14, i32 %8, i32 0, i32 %13, i32 %7)
%16 = add nuw nsw i64 %10, %12
%17 = getelementptr inbounds i8, i8* %3, i64 %16
store i8 %15, i8* %17
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, 128
br i1 %19, label %20, label %11
20: ; preds = %11
%21 = add nuw nsw i64 %6, 1
%22 = icmp eq i64 %21, 128
br i1 %22, label %23, label %5
23: ; preds = %20
%24 = tail call i32 @win_refresh(i32 %4, i32 8, i32 28, i32 136, i32 156)
%25 = tail call i32 @getkey(i32 1)
%26 = tail call i32 (...) @api_end()
ret void
}