#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*/ snprintf(char *, int, char *);
int colortostring(int color, char *result, int resultlen) {
  switch (color % 10) {
  case 0:
    snprintf(result, resultlen, "black");
    return 0;
  case 1:
    snprintf(result, resultlen, "red");
    return 0;
  case 2:
    snprintf(result, resultlen, "green");
    return 0;
  case 3:
    snprintf(result, resultlen, "yellow");
    return 0;
  case 4:
    snprintf(result, resultlen, "blue");
    return 0;
  case 5:
    snprintf(result, resultlen, "magenta");
    return 0;
  case 6:
    snprintf(result, resultlen, "cyan");
    return 0;
  case 7:
    snprintf(result, resultlen, "white");
    return 0;
  case 9:
    snprintf(result, resultlen, "default");
    return 0;
  default:
    snprintf(result, resultlen, "unknown");
    return 1;
  }
}


x86 assembly (clang, -O0):
<colortostring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movslq -0x8(%rbp),%rcx
mov    %ecx,%eax
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rdx
add    %ecx,%edx
add    %edx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x9,%eax
ja     127f <colortostring+0x16f>
mov    -0x20(%rbp),%rax
lea    0xea1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xeb2(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <colortostring+0x189>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe99(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <colortostring+0x189>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe7e(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <colortostring+0x189>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe65(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <colortostring+0x189>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe4d(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <colortostring+0x189>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe33(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <colortostring+0x189>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe1c(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <colortostring+0x189>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe02(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <colortostring+0x189>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xde9(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <colortostring+0x189>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xdd2(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<colortostring>:
push   %rbx
movslq %edi,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rcx
add    %edi,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
cmp    $0x9,%eax
ja     1151 <colortostring+0x41>
movslq %eax,%rcx
lea    0xf02(%rip),%rdi
movslq (%rdi,%rcx,4),%rax
add    %rdi,%rax
lea    0xf1c(%rip),%rdi
mov    (%rdi,%rcx,4),%ebx
jmp    115d <colortostring+0x4d>
mov    $0x1,%ebx
lea    0xeda(%rip),%rax
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rax,%rdx
call   1030 <snprintf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"black\00"
@.str.1 = [4 x i8] c"red\00"
@.str.2 = [6 x i8] c"green\00"
@.str.3 = [7 x i8] c"yellow\00"
@.str.4 = [5 x i8] c"blue\00"
@.str.5 = [8 x i8] c"magenta\00"
@.str.6 = [5 x i8] c"cyan\00"
@.str.7 = [6 x i8] c"white\00"
@.str.8 = [8 x i8] c"default\00"
@.str.9 = [8 x i8] c"unknown\00"
define i32 @colortostring(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
%9 = srem i32 %8, 10
switch i32 %9, label %46 [
i32 0, label %10
i32 1, label %14
i32 2, label %18
i32 3, label %22
i32 4, label %26
i32 5, label %30
i32 6, label %34
i32 7, label %38
i32 9, label %42
]
10: ; preds = %3
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = call i32 @snprintf(i8* %11, i32 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %50
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = call i32 @snprintf(i8* %15, i32 %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %50
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = call i32 @snprintf(i8* %19, i32 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %50
22: ; preds = %3
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = call i32 @snprintf(i8* %23, i32 %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %50
26: ; preds = %3
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = call i32 @snprintf(i8* %27, i32 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %50
30: ; preds = %3
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = call i32 @snprintf(i8* %31, i32 %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %4
br label %50
34: ; preds = %3
%35 = load i8*, i8** %6
%36 = load i32, i32* %7
%37 = call i32 @snprintf(i8* %35, i32 %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %4
br label %50
38: ; preds = %3
%39 = load i8*, i8** %6
%40 = load i32, i32* %7
%41 = call i32 @snprintf(i8* %39, i32 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %4
br label %50
42: ; preds = %3
%43 = load i8*, i8** %6
%44 = load i32, i32* %7
%45 = call i32 @snprintf(i8* %43, i32 %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %4
br label %50
46: ; preds = %3
%47 = load i8*, i8** %6
%48 = load i32, i32* %7
%49 = call i32 @snprintf(i8* %47, i32 %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %4
br label %50
50: ; preds = %46, %42, %38, %34, %30, %26, %22, %18, %14, %10
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [6 x i8] c"black\00"
@.str.1 = [4 x i8] c"red\00"
@.str.2 = [6 x i8] c"green\00"
@.str.3 = [7 x i8] c"yellow\00"
@.str.4 = [5 x i8] c"blue\00"
@.str.5 = [8 x i8] c"magenta\00"
@.str.6 = [5 x i8] c"cyan\00"
@.str.7 = [6 x i8] c"white\00"
@.str.8 = [8 x i8] c"default\00"
@.str.9 = [8 x i8] c"unknown\00"
@reltable.colortostring = [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.colortostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.colortostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.colortostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.colortostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.colortostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.colortostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.colortostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.colortostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.colortostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.colortostring to i64)) to i32)]
@switch.table.colortostring.10 = [10 x i32] [i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 1, i32 0]
define i32 @colortostring(i32 %0, i8* %1, i32 %2) {
%4 = srem i32 %0, 10
%5 = icmp ult i32 %4, 10
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = sext i32 %4 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([10 x i32]* @reltable.colortostring to i8*), i64 %8)
%10 = sext i32 %4 to i64
%11 = getelementptr inbounds [10 x i32], [10 x i32]* @switch.table.colortostring.10, i64 0, i64 %10
%12 = load i32, i32* %11
br label %13
13: ; preds = %3, %6
%14 = phi i8* [ %9, %6 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), %3 ]
%15 = phi i32 [ %12, %6 ], [ 1, %3 ]
%16 = tail call i32 @snprintf(i8* %1, i32 %2, i8* %14)
ret i32 %15
}