#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*/ api_getkey(int);
int /*<<< orphan*/ api_initmalloc();
char *api_malloc(int);
int api_openwin(char *, int, int, int, char *);
int /*<<< orphan*/ api_refreshwin(int, int, int, int, int);
char rgb2pal(int, int, int /*<<< orphan*/, int, int);
void HariMain(void) {
  char *buf;
  int win, x, y, r, g, b;
  api_initmalloc();
  buf = api_malloc(144 * 164);
  win = api_openwin(buf, 144, 164, -1, "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);
    }
  }
  api_refreshwin(win, 8, 28, 136, 156);
  api_getkey(1);
  api_end();
}


x86 assembly (clang, -O0):
<HariMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <api_initmalloc@plt>
mov    $0x5c40,%edi
call   1050 <api_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 <api_openwin@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   1060 <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 <api_refreshwin@plt>
mov    $0x1,%edi
call   1070 <api_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   1040 <api_initmalloc@plt>
mov    $0x5c40,%edi
call   1050 <api_malloc@plt>
mov    %rax,%r12
lea    0xe67(%rip),%r8
mov    %rax,%rdi
mov    $0x90,%esi
mov    $0xa4,%edx
mov    $0xffffffff,%ecx
call   1090 <api_openwin@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   1060 <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 <api_refreshwin@plt>
mov    $0x1,%edi
call   1070 <api_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 = [7 x i8] c"color2\00"
define void @HariMain() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = call i32 (...) @api_initmalloc()
%9 = call i8* @api_malloc(i32 23616)
store i8* %9, i8** %1
%10 = load i8*, i8** %1
%11 = call i32 @api_openwin(i8* %10, i32 144, i32 164, i32 -1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %2
store i32 0, i32* %4
br label %12
12: ; preds = %40, %0
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 128
br i1 %14, label %15, label %43
15: ; preds = %12
store i32 0, i32* %3
br label %16
16: ; preds = %36, %15
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 128
br i1 %18, label %19, label %39
19: ; preds = %16
%20 = load i32, i32* %3
%21 = mul nsw i32 %20, 2
%22 = load i32, i32* %4
%23 = mul nsw i32 %22, 2
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = call signext i8 @rgb2pal(i32 %21, i32 %23, i32 0, i32 %24, i32 %25)
%27 = load i8*, i8** %1
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 8
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 28
%32 = mul nsw i32 %31, 144
%33 = add nsw i32 %29, %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %27, i64 %34
store i8 %26, i8* %35
br label %36
36: ; preds = %19
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %16
39: ; preds = %16
br label %40
40: ; preds = %39
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %12
43: ; preds = %12
%44 = load i32, i32* %2
%45 = call i32 @api_refreshwin(i32 %44, i32 8, i32 28, i32 136, i32 156)
%46 = call i32 @api_getkey(i32 1)
%47 = call i32 (...) @api_end()
ret void
}

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