#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;
  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 = call i32 (...) @api_initmalloc()
%6 = call i8* @api_malloc(i32 23616)
store i8* %6, i8** %1
%7 = load i8*, i8** %1
%8 = call i32 @api_openwin(i8* %7, i32 144, i32 164, i32 -1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %2
store i32 0, i32* %4
br label %9
9: ; preds = %37, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 128
br i1 %11, label %12, label %40
12: ; preds = %9
store i32 0, i32* %3
br label %13
13: ; preds = %33, %12
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 128
br i1 %15, label %16, label %36
16: ; preds = %13
%17 = load i32, i32* %3
%18 = mul nsw i32 %17, 2
%19 = load i32, i32* %4
%20 = mul nsw i32 %19, 2
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = call signext i8 @rgb2pal(i32 %18, i32 %20, i32 0, i32 %21, i32 %22)
%24 = load i8*, i8** %1
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 8
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 28
%29 = mul nsw i32 %28, 144
%30 = add nsw i32 %26, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %24, i64 %31
store i8 %23, i8* %32
br label %33
33: ; preds = %16
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %13
36: ; preds = %13
br label %37
37: ; preds = %36
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %9
40: ; preds = %9
%41 = load i32, i32* %2
%42 = call i32 @api_refreshwin(i32 %41, i32 8, i32 28, i32 136, i32 156)
%43 = call i32 @api_getkey(i32 1)
%44 = 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
}