#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);
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, r, g, b;
  init_mem();
  buf = (char *)malloc(144 * 164);
  win = win_open(buf, 144, 164, -1, "WIN-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;
    }
  }
  win_refresh(win, 8, 28, 136, 156);
  getkey(1);
  api_end();
}


x86 assembly (clang, -O0):
<HariMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1040 <init_mem@plt>
mov    $0x5c40,%edi
call   1050 <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 <win_open@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 <win_refresh@plt>
mov    $0x1,%edi
call   1060 <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 <init_mem@plt>
mov    $0x5c40,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xeee(%rip),%r8
mov    %rax,%rdi
mov    $0x90,%esi
mov    $0xa4,%edx
mov    $0xffffffff,%ecx
call   1080 <win_open@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 <win_refresh@plt>
mov    $0x1,%edi
call   1060 <getkey@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <api_end@plt>

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

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