#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 *);
void changeColor(int b) {
  if (b == 0) {
    printf("\033[0m");
  } else {
    switch ((b - 1) % 6) {
    case 0:
      printf("\033[1;43m");
      break;
    case 1:
      printf("\033[1;42m");
      break;
    case 2:
      printf("\033[1;46m");
      break;
    case 3:
      printf("\033[1;44m");
      break;
    case 4:
      printf("\033[1;45m");
      break;
    case 5:
      printf("\033[1;41m");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<changeColor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1136 <changeColor+0x26>
lea    0xeec(%rip),%rdi
call   1030 <printf@plt>
jmp    11e5 <changeColor+0xd5>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
movslq %eax,%rcx
imul   $0x2aaaaaab,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
add    %ecx,%edx
add    %edx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x5,%eax
ja     11e0 <changeColor+0xd0>
mov    -0x10(%rbp),%rax
lea    0xe8a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
jmp    11e0 <changeColor+0xd0>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
jmp    11e0 <changeColor+0xd0>
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
jmp    11e0 <changeColor+0xd0>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
jmp    11e0 <changeColor+0xd0>
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
jmp    11e0 <changeColor+0xd0>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
jmp    11e5 <changeColor+0xd5>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeColor>:
test   %edi,%edi
je     114f <changeColor+0x3f>
add    $0xffffffff,%edi
movslq %edi,%rax
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cmp    $0x5,%eax
ja     115b <changeColor+0x4b>
cltq
lea    0xef5(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    1030 <printf@plt>
lea    0xeaa(%rip),%rdi
jmp    1030 <printf@plt>
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\1B[0m\00"
@.str.1 = [8 x i8] c"\1B[1;43m\00"
@.str.2 = [8 x i8] c"\1B[1;42m\00"
@.str.3 = [8 x i8] c"\1B[1;46m\00"
@.str.4 = [8 x i8] c"\1B[1;44m\00"
@.str.5 = [8 x i8] c"\1B[1;45m\00"
@.str.6 = [8 x i8] c"\1B[1;41m\00"
define void @changeColor(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %24
7: ; preds = %1
%8 = load i32, i32* %2
%9 = sub nsw i32 %8, 1
%10 = srem i32 %9, 6
switch i32 %10, label %23 [
i32 0, label %11
i32 1, label %13
i32 2, label %15
i32 3, label %17
i32 4, label %19
i32 5, label %21
]
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %23
13: ; preds = %7
%14 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %23
15: ; preds = %7
%16 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %23
17: ; preds = %7
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %23
19: ; preds = %7
%20 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %23
21: ; preds = %7
%22 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %23
23: ; preds = %7, %21, %19, %17, %15, %13, %11
br label %24
24: ; preds = %23, %5
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"\1B[0m\00"
@.str.1 = [8 x i8] c"\1B[1;43m\00"
@.str.2 = [8 x i8] c"\1B[1;42m\00"
@.str.3 = [8 x i8] c"\1B[1;46m\00"
@.str.4 = [8 x i8] c"\1B[1;44m\00"
@.str.5 = [8 x i8] c"\1B[1;45m\00"
@.str.6 = [8 x i8] c"\1B[1;41m\00"
@reltable.changeColor = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.changeColor to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.changeColor to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.changeColor to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.changeColor to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.changeColor to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.6 to i64), i64 ptrtoint ([6 x i32]* @reltable.changeColor to i64)) to i32)]
define void @changeColor(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = add nsw i32 %0, -1
%5 = srem i32 %4, 6
%6 = icmp ult i32 %5, 6
br i1 %6, label %7, label %14
7: ; preds = %3
%8 = sext i32 %5 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.changeColor to i8*), i64 %9)
br label %11
11: ; preds = %7, %1
%12 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ], [ %10, %7 ]
%13 = tail call i32 @printf(i8* dereferenceable(1) %12)
br label %14
14: ; preds = %3, %11
ret void
}