#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*/ init_palette();
int /*<<< orphan*/ io_hlt();
void HariMain(void) {
  int i;
  char *p;
  init_palette();
  p = (char *)0xa0000;
  for (i = 0; i < 0xffff; ++i)
    p[i] = i & 0x0f;
  for (;;)
    io_hlt();
}


x86 assembly (clang, -O0):
<HariMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <init_palette@plt>
mov    $0xa0000,%eax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0xffff,-0x4(%rbp)
jge    116d <HariMain+0x4d>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    113f <HariMain+0x1f>
jmp    1172 <HariMain+0x52>
mov    $0x0,%al
call   1030 <io_hlt@plt>
jmp    1172 <HariMain+0x52>

x86 assembly (clang, -O2):
<HariMain>:
push   %r14
push   %rbx
push   %rax
mov    $0xa0040,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <init_palette@plt>
movdqa 0xec5(%rip),%xmm0
movdqa 0xecd(%rip),%xmm1
movdqa 0xed5(%rip),%xmm2
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm3
pand   %xmm1,%xmm3
movdqa %xmm3,-0x40(%r14,%rbx,1)
movdqa %xmm3,-0x30(%r14,%rbx,1)
movdqa %xmm3,-0x20(%r14,%rbx,1)
movdqa %xmm3,-0x10(%r14,%rbx,1)
movdqa %xmm3,(%r14,%rbx,1)
add    $0x50,%rbx
paddb  %xmm2,%xmm0
cmp    $0xfff0,%rbx
jne    1150 <HariMain+0x30>
movb   $0x0,0xafff0
movb   $0x1,0xafff1
01
movb   $0x2,0xafff2
02
movb   $0x3,0xafff3
03
movb   $0x4,0xafff4
04
movb   $0x5,0xafff5
05
movb   $0x6,0xafff6
06
movb   $0x7,0xafff7
07
movb   $0x8,0xafff8
08
movb   $0x9,0xafff9
09
movb   $0xa,0xafffa
0a
movb   $0xb,0xafffb
0b
movb   $0xc,0xafffc
0c
movb   $0xd,0xafffd
0d
movb   $0xe,0xafffe
0e
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <io_hlt@plt>
jmp    1210 <HariMain+0xf0>

LLVM IR (-O0):
define void @HariMain() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i32 (...) @init_palette()
store i8* inttoptr (i64 655360 to i8*), i8** %2
store i32 0, i32* %1
br label %4
4: ; preds = %15, %0
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 65535
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = load i32, i32* %1
%9 = and i32 %8, 15
%10 = trunc i32 %9 to i8
%11 = load i8*, i8** %2
%12 = load i32, i32* %1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8 %10, i8* %14
br label %15
15: ; preds = %7
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
br label %4
18: ; preds = %4
br label %19
19: ; preds = %19, %18
%20 = call i32 (...) @io_hlt()
br label %19
}

LLVM IR (-O2):
define void @HariMain() {
%1 = tail call i32 (...) @init_palette()
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 0, %0 ], [ %24, %2 ]
%4 = phi <16 x i8> [ <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, %0 ], [ %25, %2 ]
%5 = and <16 x i8> %4, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%6 = getelementptr inbounds i8, i8* inttoptr (i64 655360 to i8*), i64 %3
%7 = bitcast i8* %6 to <16 x i8>*
store <16 x i8> %5, <16 x i8>* %7
%8 = add nuw nsw i64 %3, 16
%9 = and <16 x i8> %4, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%10 = getelementptr inbounds i8, i8* inttoptr (i64 655360 to i8*), i64 %8
%11 = bitcast i8* %10 to <16 x i8>*
store <16 x i8> %9, <16 x i8>* %11
%12 = add nuw nsw i64 %3, 32
%13 = and <16 x i8> %4, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%14 = getelementptr inbounds i8, i8* inttoptr (i64 655360 to i8*), i64 %12
%15 = bitcast i8* %14 to <16 x i8>*
store <16 x i8> %13, <16 x i8>* %15
%16 = add nuw nsw i64 %3, 48
%17 = and <16 x i8> %4, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%18 = getelementptr inbounds i8, i8* inttoptr (i64 655360 to i8*), i64 %16
%19 = bitcast i8* %18 to <16 x i8>*
store <16 x i8> %17, <16 x i8>* %19
%20 = add nuw nsw i64 %3, 64
%21 = and <16 x i8> %4, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%22 = getelementptr inbounds i8, i8* inttoptr (i64 655360 to i8*), i64 %20
%23 = bitcast i8* %22 to <16 x i8>*
store <16 x i8> %21, <16 x i8>* %23
%24 = add nuw nsw i64 %3, 80
%25 = add <16 x i8> %4, <i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80>
%26 = icmp eq i64 %24, 65520
br i1 %26, label %27, label %2
27: ; preds = %2
store i8 0, i8* inttoptr (i64 720880 to i8*)
store i8 1, i8* inttoptr (i64 720881 to i8*)
store i8 2, i8* inttoptr (i64 720882 to i8*)
store i8 3, i8* inttoptr (i64 720883 to i8*)
store i8 4, i8* inttoptr (i64 720884 to i8*)
store i8 5, i8* inttoptr (i64 720885 to i8*)
store i8 6, i8* inttoptr (i64 720886 to i8*)
store i8 7, i8* inttoptr (i64 720887 to i8*)
store i8 8, i8* inttoptr (i64 720888 to i8*)
store i8 9, i8* inttoptr (i64 720889 to i8*)
store i8 10, i8* inttoptr (i64 720890 to i8*)
store i8 11, i8* inttoptr (i64 720891 to i8*)
store i8 12, i8* inttoptr (i64 720892 to i8*)
store i8 13, i8* inttoptr (i64 720893 to i8*)
store i8 14, i8* inttoptr (i64 720894 to i8*)
br label %28
28: ; preds = %27, %28
%29 = tail call i32 (...) @io_hlt()
br label %28
}