#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 A_BOLD;
int COLOR_BLUE;
int COLOR_CYAN;
int COLOR_GREEN;
int COLOR_MAGENTA;
int COLOR_RED;
int COLOR_WHITE;
int COLOR_YELLOW;
int rand();
int get_colour() {
  int attr, tmp;
  attr = (rand() % 8) + 1;
  if (attr == 1)
    attr = COLOR_RED;
  else if (attr == 2)
    attr = COLOR_BLUE;
  else if (attr == 3)
    attr = COLOR_GREEN;
  else if (attr == 4)
    attr = COLOR_CYAN;
  else if (attr == 5)
    attr = COLOR_RED;
  else if (attr == 6)
    attr = COLOR_MAGENTA;
  else if (attr == 7)
    attr = COLOR_YELLOW;
  else if (attr == 8)
    attr = COLOR_WHITE;
  tmp = (rand() % 2) + 1;
  if (tmp > 1)
    attr |= A_BOLD;
  return (attr);
}


x86 assembly (clang, -O0):
<get_colour>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1148 <get_colour+0x38>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <get_colour+0x113>
cmpl   $0x2,-0x4(%rbp)
jne    1163 <get_colour+0x53>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    121e <get_colour+0x10e>
cmpl   $0x3,-0x4(%rbp)
jne    117e <get_colour+0x6e>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1219 <get_colour+0x109>
cmpl   $0x4,-0x4(%rbp)
jne    1199 <get_colour+0x89>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1214 <get_colour+0x104>
cmpl   $0x5,-0x4(%rbp)
jne    11b4 <get_colour+0xa4>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120f <get_colour+0xff>
cmpl   $0x6,-0x4(%rbp)
jne    11cf <get_colour+0xbf>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120a <get_colour+0xfa>
cmpl   $0x7,-0x4(%rbp)
jne    11ea <get_colour+0xda>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1205 <get_colour+0xf5>
cmpl   $0x8,-0x4(%rbp)
jne    1200 <get_colour+0xf0>
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1205 <get_colour+0xf5>
jmp    120a <get_colour+0xfa>
jmp    120f <get_colour+0xff>
jmp    1214 <get_colour+0x104>
jmp    1219 <get_colour+0x109>
jmp    121e <get_colour+0x10e>
jmp    1223 <get_colour+0x113>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1251 <get_colour+0x141>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_colour>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <rand@plt>
mov    %eax,%ebx
lea    0x7(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffff8,%eax
sub    %eax,%ebx
je     114c <get_colour+0x3c>
lea    -0x1(%rbx),%eax
cmp    $0x6,%eax
ja     117c <get_colour+0x6c>
lea    0xec6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e6e(%rip),%rax
jmp    1153 <get_colour+0x43>
mov    0x2e55(%rip),%rax
mov    (%rax),%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <rand@plt>
and    $0x80000001,%eax
cmp    $0x1,%eax
jne    1171 <get_colour+0x61>
mov    0x2e41(%rip),%rax
mov    (%rax),%ebp
or     %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
add    $0x1,%ebx
jmp    1155 <get_colour+0x45>
mov    0x2e58(%rip),%rax
jmp    1153 <get_colour+0x43>
mov    0x2e57(%rip),%rax
jmp    1153 <get_colour+0x43>
mov    0x2e36(%rip),%rax
jmp    1153 <get_colour+0x43>
mov    0x2e1d(%rip),%rax
jmp    1153 <get_colour+0x43>
mov    0x2e1c(%rip),%rax
jmp    1153 <get_colour+0x43>

LLVM IR (-O0):
@COLOR_RED = global i32 0
@COLOR_BLUE = global i32 0
@COLOR_GREEN = global i32 0
@COLOR_CYAN = global i32 0
@COLOR_MAGENTA = global i32 0
@COLOR_YELLOW = global i32 0
@COLOR_WHITE = global i32 0
@A_BOLD = global i32 0
define i32 @get_colour() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @rand()
%4 = srem i32 %3, 8
%5 = add nsw i32 %4, 1
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = load i32, i32* @COLOR_RED
store i32 %9, i32* %1
br label %52
10: ; preds = %0
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i32, i32* @COLOR_BLUE
store i32 %14, i32* %1
br label %51
15: ; preds = %10
%16 = load i32, i32* %1
%17 = icmp eq i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i32, i32* @COLOR_GREEN
store i32 %19, i32* %1
br label %50
20: ; preds = %15
%21 = load i32, i32* %1
%22 = icmp eq i32 %21, 4
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i32, i32* @COLOR_CYAN
store i32 %24, i32* %1
br label %49
25: ; preds = %20
%26 = load i32, i32* %1
%27 = icmp eq i32 %26, 5
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i32, i32* @COLOR_RED
store i32 %29, i32* %1
br label %48
30: ; preds = %25
%31 = load i32, i32* %1
%32 = icmp eq i32 %31, 6
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i32, i32* @COLOR_MAGENTA
store i32 %34, i32* %1
br label %47
35: ; preds = %30
%36 = load i32, i32* %1
%37 = icmp eq i32 %36, 7
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load i32, i32* @COLOR_YELLOW
store i32 %39, i32* %1
br label %46
40: ; preds = %35
%41 = load i32, i32* %1
%42 = icmp eq i32 %41, 8
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = load i32, i32* @COLOR_WHITE
store i32 %44, i32* %1
br label %45
45: ; preds = %43, %40
br label %46
46: ; preds = %45, %38
br label %47
47: ; preds = %46, %33
br label %48
48: ; preds = %47, %28
br label %49
49: ; preds = %48, %23
br label %50
50: ; preds = %49, %18
br label %51
51: ; preds = %50, %13
br label %52
52: ; preds = %51, %8
%53 = call i32 (...) @rand()
%54 = srem i32 %53, 2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
%56 = load i32, i32* %2
%57 = icmp sgt i32 %56, 1
br i1 %57, label %58, label %62
58: ; preds = %52
%59 = load i32, i32* @A_BOLD
%60 = load i32, i32* %1
%61 = or i32 %60, %59
store i32 %61, i32* %1
br label %62
62: ; preds = %58, %52
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
@COLOR_RED = global i32 0
@COLOR_BLUE = global i32 0
@COLOR_GREEN = global i32 0
@COLOR_CYAN = global i32 0
@COLOR_MAGENTA = global i32 0
@COLOR_YELLOW = global i32 0
@COLOR_WHITE = global i32 0
@A_BOLD = global i32 0
define i32 @get_colour() {
%1 = tail call i32 (...) @rand()
%2 = srem i32 %1, 8
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = load i32, i32* @COLOR_RED
br label %22
6: ; preds = %0
%7 = add nsw i32 %2, 1
switch i32 %2, label %22 [
i32 1, label %8
i32 2, label %10
i32 3, label %12
i32 4, label %14
i32 5, label %16
i32 6, label %18
i32 7, label %20
]
8: ; preds = %6
%9 = load i32, i32* @COLOR_BLUE
br label %22
10: ; preds = %6
%11 = load i32, i32* @COLOR_GREEN
br label %22
12: ; preds = %6
%13 = load i32, i32* @COLOR_CYAN
br label %22
14: ; preds = %6
%15 = load i32, i32* @COLOR_RED
br label %22
16: ; preds = %6
%17 = load i32, i32* @COLOR_MAGENTA
br label %22
18: ; preds = %6
%19 = load i32, i32* @COLOR_YELLOW
br label %22
20: ; preds = %6
%21 = load i32, i32* @COLOR_WHITE
br label %22
22: ; preds = %6, %8, %12, %16, %20, %18, %14, %10, %4
%23 = phi i32 [ %5, %4 ], [ %9, %8 ], [ %11, %10 ], [ %13, %12 ], [ %15, %14 ], [ %17, %16 ], [ %19, %18 ], [ %21, %20 ], [ %7, %6 ]
%24 = tail call i32 (...) @rand()
%25 = and i32 %24, -2147483647
%26 = icmp eq i32 %25, 1
%27 = load i32, i32* @A_BOLD
%28 = select i1 %26, i32 %27, i32 0
%29 = or i32 %28, %23
ret i32 %29
}