#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*/ strcpy(char *, char *);
void pick_colour(int colour, char colour_code[]) {
  switch (colour) {
  case 1:
    strcpy(colour_code, "00ffff");
    break;
  case 2:
    strcpy(colour_code, "0000ff");
    break;
  case 3:
    strcpy(colour_code, "ff00ff");
    break;
  case 4:
    strcpy(colour_code, "ff0000");
    break;
  case 5:
    strcpy(colour_code, "ffff00");
    break;
  case 6:
    strcpy(colour_code, "00ff00");
    break;
  case 8:
    strcpy(colour_code, "ffffff");
    break;
  default:
    strcpy(colour_code, "000000");
    break;
  }
}


x86 assembly (clang, -O0):
<pick_colour>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x7,%eax
ja     11db <pick_colour+0xcb>
mov    -0x18(%rbp),%rax
lea    0xec1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xecd(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11eb <pick_colour+0xdb>
mov    -0x10(%rbp),%rdi
lea    0xebf(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11eb <pick_colour+0xdb>
mov    -0x10(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11eb <pick_colour+0xdb>
mov    -0x10(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11eb <pick_colour+0xdb>
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11eb <pick_colour+0xdb>
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11eb <pick_colour+0xdb>
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11eb <pick_colour+0xdb>
mov    -0x10(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pick_colour>:
mov    %rsi,%rax
add    $0xffffffff,%edi
cmp    $0x7,%edi
ja     1134 <pick_colour+0x24>
movslq %edi,%rcx
lea    0xf13(%rip),%rdx
movslq (%rdx,%rcx,4),%rsi
add    %rdx,%rsi
mov    %rax,%rdi
jmp    1030 <strcpy@plt>
lea    0xef6(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"00ffff\00"
@.str.1 = [7 x i8] c"0000ff\00"
@.str.2 = [7 x i8] c"ff00ff\00"
@.str.3 = [7 x i8] c"ff0000\00"
@.str.4 = [7 x i8] c"ffff00\00"
@.str.5 = [7 x i8] c"00ff00\00"
@.str.6 = [7 x i8] c"ffffff\00"
@.str.7 = [7 x i8] c"000000\00"
define void @pick_colour(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
switch i32 %5, label %27 [
i32 1, label %6
i32 2, label %9
i32 3, label %12
i32 4, label %15
i32 5, label %18
i32 6, label %21
i32 8, label %24
]
6: ; preds = %2
%7 = load i8*, i8** %4
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %30
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %30
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %30
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %30
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %30
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %30
24: ; preds = %2
%25 = load i8*, i8** %4
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %30
27: ; preds = %2
%28 = load i8*, i8** %4
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %30
30: ; preds = %27, %24, %21, %18, %15, %12, %9, %6
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"00ffff\00"
@.str.1 = [7 x i8] c"0000ff\00"
@.str.2 = [7 x i8] c"ff00ff\00"
@.str.3 = [7 x i8] c"ff0000\00"
@.str.4 = [7 x i8] c"ffff00\00"
@.str.5 = [7 x i8] c"00ff00\00"
@.str.6 = [7 x i8] c"ffffff\00"
@.str.7 = [7 x i8] c"000000\00"
@reltable.pick_colour = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.pick_colour to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.pick_colour to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.pick_colour to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.pick_colour to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.pick_colour to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.pick_colour to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.pick_colour to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.pick_colour to i64)) to i32)]
define void @pick_colour(i32 %0, i8* %1) {
%3 = add i32 %0, -1
%4 = icmp ult i32 %3, 8
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = sext i32 %3 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.pick_colour to i8*), i64 %7)
br label %9
9: ; preds = %2, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), %2 ]
%11 = tail call i32 @strcpy(i8* %1, i8* %10)
ret void
}