#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);
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, "color");
  for (y = 0; y < 128; y++) {
    for (x = 0; x < 128; x++) {
      r = x * 2;
      g = y * 2;
      b = 0;
      buf[(x + 8) + (y + 28) * 144] =
          16 + (r / 43) + (g / 43) * 6 + (b / 43) * 36;
    }
  }
  api_refreshwin(win, 8, 28, 136, 156);
  api_getkey(1);
  api_end();
}


x86 assembly (clang, -O0):
<HariMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    0xe69(%rip),%r8
call   1080 <api_openwin@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jge    125f <HariMain+0xff>
movl   $0x0,-0x10(%rbp)
cmpl   $0x80,-0x10(%rbp)
jge    124c <HariMain+0xec>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2b,%ecx
cltd
idiv   %ecx
add    $0x10,%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2b,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
imul   $0x6,%ecx,%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x2b,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   $0x24,%ecx,%ecx
add    %ecx,%eax
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    11ba <HariMain+0x5a>
jmp    1251 <HariMain+0xf1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <HariMain+0x46>
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
mov    $0x1c,%edx
mov    $0x88,%ecx
mov    $0x9c,%r8d
call   1070 <api_refreshwin@plt>
mov    $0x1,%edi
call   1060 <api_getkey@plt>
mov    $0x0,%al
call   1030 <api_end@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HariMain>:
push   %r14
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,%rbx
lea    0xeee(%rip),%r8
mov    %rax,%rdi
mov    $0x90,%esi
mov    $0xa4,%edx
mov    $0xffffffff,%ecx
call   1080 <api_openwin@plt>
add    $0x1038,%rbx
movdqa 0xe57(%rip),%xmm8
movdqa 0xe5f(%rip),%xmm1
movdqa 0xe67(%rip),%xmm2
movdqa 0xe6f(%rip),%xmm3
movdqa 0xe77(%rip),%xmm4
movdqa 0xe7f(%rip),%xmm5
movdqa 0xe87(%rip),%xmm6
nopl   0x0(%rax)
mov    %r14d,%ecx
imul   $0x2fa0be83,%rcx,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
add    $0x10,%cl
movzbl %cl,%ecx
movd   %ecx,%xmm7
punpcklbw %xmm7,%xmm7
pshuflw $0x0,%xmm7,%xmm7
pshufd $0x0,%xmm7,%xmm0
movdqu %xmm0,-0x70(%rbx)
movdqa %xmm0,%xmm7
por    %xmm8,%xmm7
movdqu %xmm7,-0x60(%rbx)
movdqa %xmm0,%xmm7
paddb  %xmm1,%xmm7
movdqu %xmm7,-0x50(%rbx)
movdqa %xmm0,%xmm7
paddb  %xmm2,%xmm7
movdqu %xmm7,-0x40(%rbx)
movdqa %xmm0,%xmm7
paddb  %xmm3,%xmm7
movdqu %xmm7,-0x30(%rbx)
movdqa %xmm0,%xmm7
paddb  %xmm4,%xmm7
movdqu %xmm7,-0x20(%rbx)
movdqa %xmm0,%xmm7
paddb  %xmm5,%xmm7
movdqu %xmm7,-0x10(%rbx)
paddb  %xmm6,%xmm0
movdqu %xmm0,(%rbx)
add    $0x2,%r14
add    $0x90,%rbx
cmp    $0x100,%r14
jne    11e0 <HariMain+0x80>
mov    %eax,%edi
mov    $0x8,%esi
mov    $0x1c,%edx
mov    $0x88,%ecx
mov    $0x9c,%r8d
call   1070 <api_refreshwin@plt>
mov    $0x1,%edi
call   1060 <api_getkey@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <api_end@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"color\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 ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %2
store i32 0, i32* %4
br label %12
12: ; preds = %49, %0
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 128
br i1 %14, label %15, label %52
15: ; preds = %12
store i32 0, i32* %3
br label %16
16: ; preds = %45, %15
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 128
br i1 %18, label %19, label %48
19: ; preds = %16
%20 = load i32, i32* %3
%21 = mul nsw i32 %20, 2
store i32 %21, i32* %5
%22 = load i32, i32* %4
%23 = mul nsw i32 %22, 2
store i32 %23, i32* %6
store i32 0, i32* %7
%24 = load i32, i32* %5
%25 = sdiv i32 %24, 43
%26 = add nsw i32 16, %25
%27 = load i32, i32* %6
%28 = sdiv i32 %27, 43
%29 = mul nsw i32 %28, 6
%30 = add nsw i32 %26, %29
%31 = load i32, i32* %7
%32 = sdiv i32 %31, 43
%33 = mul nsw i32 %32, 36
%34 = add nsw i32 %30, %33
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %1
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 8
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 28
%41 = mul nsw i32 %40, 144
%42 = add nsw i32 %38, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %36, i64 %43
store i8 %35, i8* %44
br label %45
45: ; preds = %19
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %16
48: ; preds = %16
br label %49
49: ; preds = %48
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %12
52: ; preds = %12
%53 = load i32, i32* %2
%54 = call i32 @api_refreshwin(i32 %53, i32 8, i32 28, i32 136, i32 156)
%55 = call i32 @api_getkey(i32 1)
%56 = call i32 (...) @api_end()
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"color\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 ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %0, %4
%5 = phi i64 [ 0, %0 ], [ %46, %4 ]
%6 = mul nuw nsw i64 %5, 144
%7 = trunc i64 %5 to i32
%8 = shl i32 %7, 1
%9 = udiv i32 %8, 43
%10 = trunc i32 %9 to i8
%11 = mul i8 %10, 6
%12 = add i8 %11, 16
%13 = insertelement <16 x i8> poison, i8 %12, i64 0
%14 = shufflevector <16 x i8> %13, <16 x i8> poison, <16 x i32> zeroinitializer
%15 = add nuw nsw i64 %6, 4040
%16 = getelementptr inbounds i8, i8* %2, i64 %15
%17 = bitcast i8* %16 to <16 x i8>*
store <16 x i8> %14, <16 x i8>* %17
%18 = or <16 x i8> %14, <i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
%19 = add nuw nsw i64 %6, 4056
%20 = getelementptr inbounds i8, i8* %2, i64 %19
%21 = bitcast i8* %20 to <16 x i8>*
store <16 x i8> %18, <16 x i8>* %21
%22 = add <16 x i8> %14, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 2, i8 2, i8 2, i8 2, i8 2>
%23 = add nuw nsw i64 %6, 4072
%24 = getelementptr inbounds i8, i8* %2, i64 %23
%25 = bitcast i8* %24 to <16 x i8>*
store <16 x i8> %22, <16 x i8>* %25
%26 = add <16 x i8> %14, <i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2>
%27 = add nuw nsw i64 %6, 4088
%28 = getelementptr inbounds i8, i8* %2, i64 %27
%29 = bitcast i8* %28 to <16 x i8>*
store <16 x i8> %26, <16 x i8>* %29
%30 = add <16 x i8> %14, <i8 2, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3>
%31 = add nuw nsw i64 %6, 4104
%32 = getelementptr inbounds i8, i8* %2, i64 %31
%33 = bitcast i8* %32 to <16 x i8>*
store <16 x i8> %30, <16 x i8>* %33
%34 = add <16 x i8> %14, <i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4>
%35 = add nuw nsw i64 %6, 4120
%36 = getelementptr inbounds i8, i8* %2, i64 %35
%37 = bitcast i8* %36 to <16 x i8>*
store <16 x i8> %34, <16 x i8>* %37
%38 = add <16 x i8> %14, <i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 5, i8 5, i8 5, i8 5>
%39 = add nuw nsw i64 %6, 4136
%40 = getelementptr inbounds i8, i8* %2, i64 %39
%41 = bitcast i8* %40 to <16 x i8>*
store <16 x i8> %38, <16 x i8>* %41
%42 = add <16 x i8> %14, <i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5>
%43 = add nuw nsw i64 %6, 4152
%44 = getelementptr inbounds i8, i8* %2, i64 %43
%45 = bitcast i8* %44 to <16 x i8>*
store <16 x i8> %42, <16 x i8>* %45
%46 = add nuw nsw i64 %5, 1
%47 = icmp eq i64 %46, 128
br i1 %47, label %48, label %4
48: ; preds = %4
%49 = tail call i32 @api_refreshwin(i32 %3, i32 8, i32 28, i32 136, i32 156)
%50 = tail call i32 @api_getkey(i32 1)
%51 = tail call i32 (...) @api_end()
ret void
}