#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 */
typedef int uint8_t;
typedef int uint16_t;
typedef int /*<<< orphan*/ original;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, size_t, char *, int, int);
void getColor(uint16_t value, char *color, size_t length) {
  uint8_t original[] = {8,   255, 1,   255, 2,   255, 3,   255, 4,   255, 5,
                        255, 6,   255, 7,   255, 9,   0,   10,  0,   11,  0,
                        12,  0,   13,  0,   14,  0,   255, 0,   255, 0};
  uint8_t *scheme = original;
  uint8_t *background = scheme + 0;
  uint8_t *foreground = scheme + 1;
  if (value > 0)
    while (value >>= 1) {
      if (background + 2 < scheme + sizeof(original)) {
        background += 2;
        foreground += 2;
      }
    }
  snprintf(color, length, "\033[38;5;%d;48;5;%dm", *foreground, *background);
}


x86 assembly (clang, -O0):
<getColor>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xebc(%rip),%rsi
mov    $0x80,%edx
call   1040 <memcpy@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0xa8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0xb8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    11ed <getColor+0xcd>
jmp    118b <getColor+0x6b>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     11e8 <getColor+0xc8>
mov    -0xb0(%rbp),%rax
add    $0x8,%rax
mov    -0xa8(%rbp),%rcx
add    $0x200,%rcx
cmp    %rcx,%rax
jae    11e3 <getColor+0xc3>
mov    -0xb0(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0xb0(%rbp)
mov    -0xb8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0xb8(%rbp)
jmp    118b <getColor+0x6b>
jmp    11ed <getColor+0xcd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xb8(%rbp),%rax
mov    (%rax),%ecx
mov    -0xb0(%rbp),%rax
mov    (%rax),%r8d
lea    0xe71(%rip),%rdx
call   1030 <snprintf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getColor>:
sub    $0x88,%rsp
mov    %rsi,%r9
movaps 0xf4f(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xf33(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xf17(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xefb(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xec3(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe8b(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x2,%edi
jge    118b <getColor+0x7b>
mov    $0xff,%ecx
mov    $0x8,%r8d
jmp    11c3 <getColor+0xb3>
lea    0x4(%rsp),%r11
mov    %rsp,%rsi
lea    0x200(%rsp),%r8
mov    %edi,%ecx
nopl   (%rax)
sar    %ecx
lea    0x8(%rsi),%r10
xor    %eax,%eax
cmp    %r8,%r10
setb   %al
cmovb  %r10,%rsi
lea    (%r11,%rax,8),%r11
cmp    $0x3,%edi
mov    %ecx,%edi
ja     11a0 <getColor+0x90>
mov    (%r11),%ecx
mov    (%rsi),%r8d
lea    0xeb6(%rip),%rax
mov    %r9,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
call   1030 <snprintf@plt>
add    $0x88,%rsp
ret

LLVM IR (-O0):
@__const.getColor.original = [32 x i32] [i32 8, i32 255, i32 1, i32 255, i32 2, i32 255, i32 3, i32 255, i32 4, i32 255, i32 5, i32 255, i32 6, i32 255, i32 7, i32 255, i32 9, i32 0, i32 10, i32 0, i32 11, i32 0, i32 12, i32 0, i32 13, i32 0, i32 14, i32 0, i32 255, i32 0, i32 255, i32 0]
@.str = [19 x i8] c"\1B[38;5;%d;48;5;%dm\00"
define void @getColor(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [32 x i32]
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%11 = bitcast [32 x i32]* %7 to i8*
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 0
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = getelementptr inbounds i32, i32* %13, i64 0
store i32* %14, i32** %9
%15 = load i32*, i32** %8
%16 = getelementptr inbounds i32, i32* %15, i64 1
store i32* %16, i32** %10
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %3
br label %20
20: ; preds = %35, %19
%21 = load i32, i32* %4
%22 = ashr i32 %21, 1
store i32 %22, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i32*, i32** %9
%26 = getelementptr inbounds i32, i32* %25, i64 2
%27 = load i32*, i32** %8
%28 = getelementptr inbounds i32, i32* %27, i64 128
%29 = icmp ult i32* %26, %28
br i1 %29, label %30, label %35
30: ; preds = %24
%31 = load i32*, i32** %9
%32 = getelementptr inbounds i32, i32* %31, i64 2
store i32* %32, i32** %9
%33 = load i32*, i32** %10
%34 = getelementptr inbounds i32, i32* %33, i64 2
store i32* %34, i32** %10
br label %35
35: ; preds = %30, %24
br label %20
36: ; preds = %20
br label %37
37: ; preds = %36, %3
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = load i32*, i32** %10
%41 = load i32, i32* %40
%42 = load i32*, i32** %9
%43 = load i32, i32* %42
%44 = call i32 @snprintf(i8* %38, i64 %39, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %43)
ret void
}

LLVM IR (-O2):
@__const.getColor.original = [32 x i32] [i32 8, i32 255, i32 1, i32 255, i32 2, i32 255, i32 3, i32 255, i32 4, i32 255, i32 5, i32 255, i32 6, i32 255, i32 7, i32 255, i32 9, i32 0, i32 10, i32 0, i32 11, i32 0, i32 12, i32 0, i32 13, i32 0, i32 14, i32 0, i32 255, i32 0, i32 255, i32 0]
@.str = [19 x i8] c"\1B[38;5;%d;48;5;%dm\00"
define void @getColor(i32 %0, i8* %1, i64 %2) {
%4 = alloca [32 x i32]
%5 = bitcast [32 x i32]* %4 to i8*
%6 = icmp slt i32 %0, 2
br i1 %6, label %25, label %7
7: ; preds = %3
%8 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 1
%9 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 0
%10 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 128
br label %11
11: ; preds = %7, %11
%12 = phi i32* [ %8, %7 ], [ %20, %11 ]
%13 = phi i32* [ %9, %7 ], [ %18, %11 ]
%14 = phi i32 [ %0, %7 ], [ %15, %11 ]
%15 = ashr i32 %14, 1
%16 = getelementptr inbounds i32, i32* %13, i64 2
%17 = icmp ult i32* %16, %10
%18 = select i1 %17, i32* %16, i32* %13
%19 = select i1 %17, i64 2, i64 0
%20 = getelementptr i32, i32* %12, i64 %19
%21 = icmp ult i32 %14, 4
br i1 %21, label %22, label %11
22: ; preds = %11
%23 = load i32, i32* %20
%24 = load i32, i32* %18
br label %25
25: ; preds = %22, %3
%26 = phi i32 [ 8, %3 ], [ %24, %22 ]
%27 = phi i32 [ 255, %3 ], [ %23, %22 ]
%28 = call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %26)
ret void
}