#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 sscanf(char const *, char *, int *);
int /*<<< orphan*/ strcmp(char const *, char *);
int readcolor(const char *clr) {
  if (!strcmp(clr, "red"))
    return 0xff0000;
  if (!strcmp(clr, "green"))
    return 0x00ff00;
  if (!strcmp(clr, "blue"))
    return 0x0000ff;
  if (!strcmp(clr, "cyan"))
    return 0x00ffff;
  if (!strcmp(clr, "magenta"))
    return 0xff00ff;
  if (!strcmp(clr, "yellow"))
    return 0xffff00;
  if (!strcmp(clr, "white"))
    return 0xffffff;
  if (!strcmp(clr, "black"))
    return 0x000000;
  int rgb;
  if (sscanf(clr, "%6x", &rgb) == 1)
    return rgb;
  return 0;
}


x86 assembly (clang, -O0):
<readcolor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1151 <readcolor+0x31>
movl   $0xff0000,-0x4(%rbp)
jmp    1283 <readcolor+0x163>
mov    -0x10(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1176 <readcolor+0x56>
movl   $0xff00,-0x4(%rbp)
jmp    1283 <readcolor+0x163>
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    119b <readcolor+0x7b>
movl   $0xff,-0x4(%rbp)
jmp    1283 <readcolor+0x163>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11c0 <readcolor+0xa0>
movl   $0xffff,-0x4(%rbp)
jmp    1283 <readcolor+0x163>
mov    -0x10(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11e5 <readcolor+0xc5>
movl   $0xff00ff,-0x4(%rbp)
jmp    1283 <readcolor+0x163>
mov    -0x10(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    120a <readcolor+0xea>
movl   $0xffff00,-0x4(%rbp)
jmp    1283 <readcolor+0x163>
mov    -0x10(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    122f <readcolor+0x10f>
movl   $0xffffff,-0x4(%rbp)
jmp    1283 <readcolor+0x163>
mov    -0x10(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1254 <readcolor+0x134>
movl   $0x0,-0x4(%rbp)
jmp    1283 <readcolor+0x163>
mov    -0x10(%rbp),%rdi
lea    0xdd0(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    127c <readcolor+0x15c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1283 <readcolor+0x163>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readcolor>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xed1(%rip),%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11f0 <readcolor+0xd0>
lea    0xec1(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11f7 <readcolor+0xd7>
lea    0xeb0(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11fe <readcolor+0xde>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1205 <readcolor+0xe5>
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     120c <readcolor+0xec>
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1213 <readcolor+0xf3>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     121a <readcolor+0xfa>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1221 <readcolor+0x101>
lea    0xe5b(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    1223 <readcolor+0x103>
mov    0xc(%rsp),%eax
jmp    1223 <readcolor+0x103>
mov    $0xff0000,%eax
jmp    1223 <readcolor+0x103>
mov    $0xff00,%eax
jmp    1223 <readcolor+0x103>
mov    $0xff,%eax
jmp    1223 <readcolor+0x103>
mov    $0xffff,%eax
jmp    1223 <readcolor+0x103>
mov    $0xff00ff,%eax
jmp    1223 <readcolor+0x103>
mov    $0xffff00,%eax
jmp    1223 <readcolor+0x103>
mov    $0xffffff,%eax
jmp    1223 <readcolor+0x103>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"red\00"
@.str.1 = [6 x i8] c"green\00"
@.str.2 = [5 x i8] c"blue\00"
@.str.3 = [5 x i8] c"cyan\00"
@.str.4 = [8 x i8] c"magenta\00"
@.str.5 = [7 x i8] c"yellow\00"
@.str.6 = [6 x i8] c"white\00"
@.str.7 = [6 x i8] c"black\00"
@.str.8 = [4 x i8] c"%6x\00"
define i32 @readcolor(i8* nocapture %0) {
%2 = alloca i32
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %32, label %5
5: ; preds = %1
%6 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %32, label %8
8: ; preds = %5
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %8
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %32, label %14
14: ; preds = %11
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %32, label %17
17: ; preds = %14
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %32, label %20
20: ; preds = %17
%21 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %20
%24 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = bitcast i32* %2 to i8*
%28 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32* %2)
%29 = icmp eq i32 %28, 1
%30 = load i32, i32* %2
%31 = select i1 %29, i32 %30, i32 0
br label %32
32: ; preds = %23, %20, %17, %14, %11, %8, %5, %1, %26
%33 = phi i32 [ %31, %26 ], [ 16711680, %1 ], [ 65280, %5 ], [ 255, %8 ], [ 65535, %11 ], [ 16711935, %14 ], [ 16776960, %17 ], [ 16777215, %20 ], [ 0, %23 ]
ret i32 %33
}