char *ansstr(aslot)
int aslot;
{
  static char ds[80];
  static int fores[15] = {31, 32, 33, 34, 35, 36, 36, 32,
                          37, 30, 30, 30, 40, 30, 34};
  static int backs[15] = {40, 40, 40, 40, 40, 40, 44, 44,
                          44, 46, 45, 42, 43, 47, 47};
  if (aslot > 15)
    aslot %= 15;
  sprintf(ds, "\033[%d;%dm", backs[aslot], fores[aslot]);
  return (ds);
}


x86 assembly (clang, -O0):
<ansstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xf,-0x4(%rbp)
jle    1133 <ansstr+0x23>
mov    -0x4(%rbp),%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
movslq -0x4(%rbp),%rcx
lea    0x2f32(%rip),%rax
mov    (%rax,%rcx,4),%edx
movslq -0x4(%rbp),%rcx
lea    0x2ee4(%rip),%rax
mov    (%rax,%rcx,4),%ecx
lea    0x2f6a(%rip),%rdi
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
lea    0x2f55(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ansstr>:
cmp    $0x10,%edi
jl     1137 <ansstr+0x27>
movslq %edi,%rax
imul   $0xffffffff88888889,%rax,%rax
shr    $0x20,%rax
add    %edi,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x3,%eax
add    %ecx,%eax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%edi
push   %rbx
movslq %edi,%rax
lea    0xefe(%rip),%rcx
mov    (%rcx,%rax,4),%edx
lea    0xeb4(%rip),%rcx
mov    (%rcx,%rax,4),%ecx
lea    0x2eea(%rip),%rbx
lea    0xf1f(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@ansstr.ds = internal global [80 x i8] zeroinitializer
@ansstr.fores = internal global [15 x i32] [i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 36, i32 32, i32 37, i32 30, i32 30, i32 30, i32 40, i32 30, i32 34]
@ansstr.backs = internal global [15 x i32] [i32 40, i32 40, i32 40, i32 40, i32 40, i32 40, i32 44, i32 44, i32 44, i32 46, i32 45, i32 42, i32 43, i32 47, i32 47]
@.str = [9 x i8] c"\1B[%d;%dm\00"
define i8* @ansstr(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp sgt i32 %3, 15
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* %2
%7 = srem i32 %6, 15
store i32 %7, i32* %2
br label %8
8: ; preds = %5, %1
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [15 x i32], [15 x i32]* @ansstr.backs, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [15 x i32], [15 x i32]* @ansstr.fores, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @ansstr.ds, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %16)
ret i8* getelementptr inbounds ([80 x i8], [80 x i8]* @ansstr.ds, i64 0, i64 0)
}

LLVM IR (-O2):
@ansstr.ds = internal global [80 x i8] zeroinitializer
@ansstr.fores = internal unnamed_addr constant [15 x i32] [i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 36, i32 32, i32 37, i32 30, i32 30, i32 30, i32 40, i32 30, i32 34]
@ansstr.backs = internal unnamed_addr constant [15 x i32] [i32 40, i32 40, i32 40, i32 40, i32 40, i32 40, i32 44, i32 44, i32 44, i32 46, i32 45, i32 42, i32 43, i32 47, i32 47]
@.str = [9 x i8] c"\1B[%d;%dm\00"
define i8* @ansstr(i32 %0) {
%2 = icmp sgt i32 %0, 15
%3 = srem i32 %0, 15
%4 = select i1 %2, i32 %3, i32 %0
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [15 x i32], [15 x i32]* @ansstr.backs, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = getelementptr inbounds [15 x i32], [15 x i32]* @ansstr.fores, i64 0, i64 %5
%9 = load i32, i32* %8
%10 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @ansstr.ds, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %9)
ret i8* getelementptr inbounds ([80 x i8], [80 x i8]* @ansstr.ds, i64 0, i64 0)
}