#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*/ printf(char *, int, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ xterm2rgb(int, unsigned char *);
int main() {
  int i = 16;
  unsigned char c[3];
  puts("GIMP Palette");
  puts("Name: xterm-256color");
  puts("Columns: 12");
  puts("#");
  for (; i < 256; i++) {
    xterm2rgb(i, c);
    printf("%3d %3d %3d #%d, ", c[0], c[1], c[2], i);
    if (i < 232)
      printf("color cube (%d, %d, %d)\n", ((i - 16) / 36) % 6,
             ((i - 16) / 6) % 6, (i - 16) % 6);
    else
      printf("grey ramp (%d)\n", i - 232);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x10,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x100,-0x8(%rbp)
jge    123b <main+0x10b>
mov    -0x8(%rbp),%edi
lea    -0xb(%rbp),%rsi
call   1050 <xterm2rgb@plt>
movzbl -0xb(%rbp),%esi
movzbl -0xa(%rbp),%edx
movzbl -0x9(%rbp),%ecx
mov    -0x8(%rbp),%r8d
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0xe8,-0x8(%rbp)
jge    1211 <main+0xe1>
mov    -0x8(%rbp),%eax
sub    $0x10,%eax
mov    $0x24,%ecx
cltd
idiv   %ecx
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
mov    -0x8(%rbp),%eax
sub    $0x10,%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x10,%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x10(%rbp),%edx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1228 <main+0xf8>
mov    -0x8(%rbp),%esi
sub    $0xe8,%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122d <main+0xfd>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1176 <main+0x46>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0x5(%rsp),%r14
lea    0xeb9(%rip),%r13
lea    0xec4(%rip),%r15
lea    0xed6(%rip),%r12
xor    %ebx,%ebx
jmp    11af <main+0x7f>
nopl   0x0(%rax)
lea    -0xd8(%rbx),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    $0xf0,%ebx
je     1257 <main+0x127>
lea    0x10(%rbx),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <xterm2rgb@plt>
movzbl 0x5(%rsp),%esi
movzbl 0x6(%rsp),%edx
movzbl 0x7(%rsp),%ecx
mov    %r13,%rdi
mov    %ebp,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0xe7,%ebp
ja     1190 <main+0x60>
movswl %bx,%eax
imul   $0xe39,%eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x11,%ecx
add    %edx,%ecx
movzbl %cl,%ecx
imul   $0xab,%ecx,%edx
shr    $0x9,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,2),%edx
sub    %dl,%cl
movzbl %cl,%esi
imul   $0x2aab,%eax,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
shr    $0x10,%eax
add    %ecx,%eax
movsbl %al,%ecx
imul   $0x2b,%ecx,%ecx
movzwl %cx,%ecx
mov    %ecx,%edx
shr    $0xf,%edx
shr    $0x8,%ecx
add    %dl,%cl
movzbl %cl,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
mov    %eax,%edx
sub    %cl,%dl
movsbl %dl,%edx
add    %eax,%eax
lea    (%rax,%rax,2),%eax
mov    %ebx,%ecx
sub    %eax,%ecx
movswl %cx,%ecx
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"GIMP Palette\00"
@.str.1 = [21 x i8] c"Name: xterm-256color\00"
@.str.2 = [12 x i8] c"Columns: 12\00"
@.str.3 = [2 x i8] c"#\00"
@.str.4 = [18 x i8] c"%3d %3d %3d #%d, \00"
@.str.5 = [25 x i8] c"color cube (%d, %d, %d)\0A\00"
@.str.6 = [16 x i8] c"grey ramp (%d)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x i8]
store i32 0, i32* %1
store i32 16, i32* %2
%4 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %8
8: ; preds = %46, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 256
br i1 %10, label %11, label %49
11: ; preds = %8
%12 = load i32, i32* %2
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%14 = call i32 @xterm2rgb(i32 %12, i8* %13)
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = load i32, i32* %2
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %17, i32 %20, i32 %23, i32 %24)
%26 = load i32, i32* %2
%27 = icmp slt i32 %26, 232
br i1 %27, label %28, label %41
28: ; preds = %11
%29 = load i32, i32* %2
%30 = sub nsw i32 %29, 16
%31 = sdiv i32 %30, 36
%32 = srem i32 %31, 6
%33 = load i32, i32* %2
%34 = sub nsw i32 %33, 16
%35 = sdiv i32 %34, 6
%36 = srem i32 %35, 6
%37 = load i32, i32* %2
%38 = sub nsw i32 %37, 16
%39 = srem i32 %38, 6
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %32, i32 %36, i32 %39)
br label %45
41: ; preds = %11
%42 = load i32, i32* %2
%43 = sub nsw i32 %42, 232
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41, %28
br label %46
46: ; preds = %45
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
store i32 %48, i32* %2
br label %8
49: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"GIMP Palette\00"
@.str.1 = [21 x i8] c"Name: xterm-256color\00"
@.str.2 = [12 x i8] c"Columns: 12\00"
@.str.3 = [2 x i8] c"#\00"
@.str.4 = [18 x i8] c"%3d %3d %3d #%d, \00"
@.str.5 = [25 x i8] c"color cube (%d, %d, %d)\0A\00"
@.str.6 = [16 x i8] c"grey ramp (%d)\0A\00"
define i32 @main() {
%1 = alloca [3 x i8]
%2 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2
br label %9
9: ; preds = %0, %37
%10 = phi i32 [ 16, %0 ], [ %38, %37 ]
%11 = call i32 @xterm2rgb(i32 %10, i8* %2)
%12 = load i8, i8* %2
%13 = zext i8 %12 to i32
%14 = load i8, i8* %7
%15 = zext i8 %14 to i32
%16 = load i8, i8* %8
%17 = zext i8 %16 to i32
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %13, i32 %15, i32 %17, i32 %10)
%19 = icmp ult i32 %10, 232
br i1 %19, label %20, label %34
20: ; preds = %9
%21 = trunc i32 %10 to i16
%22 = add nsw i16 %21, -16
%23 = sdiv i16 %22, 36
%24 = trunc i16 %23 to i8
%25 = urem i8 %24, 6
%26 = zext i8 %25 to i32
%27 = sdiv i16 %22, 6
%28 = trunc i16 %27 to i8
%29 = srem i8 %28, 6
%30 = sext i8 %29 to i32
%31 = srem i16 %22, 6
%32 = sext i16 %31 to i32
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %26, i32 %30, i32 %32)
br label %37
34: ; preds = %9
%35 = add nsw i32 %10, -232
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %20, %34
%38 = add nuw nsw i32 %10, 1
%39 = icmp eq i32 %38, 256
br i1 %39, label %40, label %9
40: ; preds = %37
ret i32 0
}