#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*/ str_toupper(char *);
scalar_t__ strcmp(char *, char *);
bool is_color_valid(char color_str[], int *color) {
  bool is_valid = false;
  str_toupper(color_str);
  if (strcmp(color_str, "B") == 0 || strcmp(color_str, "BLACK") == 0) {
    *color = 1;
    is_valid = true;
  } else if (strcmp(color_str, "W") == 0 || strcmp(color_str, "WHITE") == 0) {
    *color = -1;
    is_valid = true;
  } else {
    color = NULL;
  }
  return is_valid;
}


x86 assembly (clang, -O0):
<is_color_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <str_toupper@plt>
mov    -0x8(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     1174 <is_color_valid+0x54>
mov    -0x8(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    118a <is_color_valid+0x6a>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x14(%rbp)
jmp    11e1 <is_color_valid+0xc1>
mov    -0x8(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11be <is_color_valid+0x9e>
mov    -0x8(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11d4 <is_color_valid+0xb4>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x1,-0x14(%rbp)
jmp    11dc <is_color_valid+0xbc>
movq   $0x0,-0x10(%rbp)
jmp    11e1 <is_color_valid+0xc1>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_color_valid>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <str_toupper@plt>
lea    0xeca(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     118e <is_color_valid+0x6e>
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     118e <is_color_valid+0x6e>
lea    0xea5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     118e <is_color_valid+0x6e>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1196 <is_color_valid+0x76>
mov    %ebp,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"B\00"
@.str.1 = [6 x i8] c"BLACK\00"
@.str.2 = [2 x i8] c"W\00"
@.str.3 = [6 x i8] c"WHITE\00"
define i32 @is_color_valid(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = call i32 @str_toupper(i8* %6)
%8 = load i8*, i8** %3
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11, %2
%16 = load i32*, i32** %4
store i32 1, i32* %16
store i32 1, i32* %5
br label %29
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21, %17
%26 = load i32*, i32** %4
store i32 -1, i32* %26
store i32 1, i32* %5
br label %28
27: ; preds = %21
store i32* null, i32** %4
br label %28
28: ; preds = %27, %25
br label %29
29: ; preds = %28, %15
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
@.str = [2 x i8] c"B\00"
@.str.1 = [6 x i8] c"BLACK\00"
@.str.2 = [2 x i8] c"W\00"
@.str.3 = [6 x i8] c"WHITE\00"
define i32 @is_color_valid(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @str_toupper(i8* %0)
%4 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9, %12, %2, %6
%16 = phi i32 [ 1, %6 ], [ 1, %2 ], [ -1, %12 ], [ -1, %9 ]
store i32 %16, i32* %1
br label %17
17: ; preds = %15, %12
%18 = phi i32 [ 0, %12 ], [ 1, %15 ]
ret i32 %18
}