#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*/ isxdigit(char const);
int strlen(char const *);
int valid_bw_color(const char *colour) {
  int i;
  if (!colour || strlen(colour) != 3 || colour[0] != '#')
    return 0;
  for (i = 1; i < 3; i++) {
    if (!isxdigit(colour[i]))
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<valid_bw_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1159 <valid_bw_color+0x39>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jne    1159 <valid_bw_color+0x39>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1165 <valid_bw_color+0x45>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <valid_bw_color+0x96>
movl   $0x1,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11af <valid_bw_color+0x8f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%eax
jne    119c <valid_bw_color+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <valid_bw_color+0x96>
jmp    11a1 <valid_bw_color+0x81>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116c <valid_bw_color+0x4c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<valid_bw_color>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     115a <valid_bw_color+0x3a>
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x3,%eax
jne    115a <valid_bw_color+0x3a>
cmpb   $0x23,(%rbx)
jne    115a <valid_bw_color+0x3a>
movsbl 0x1(%rbx),%edi
call   1040 <isxdigit@plt>
test   %eax,%eax
je     115a <valid_bw_color+0x3a>
movsbl 0x2(%rbx),%edi
call   1040 <isxdigit@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @valid_bw_color(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp ne i32 %9, 3
br i1 %10, label %17, label %11
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 35
br i1 %16, label %17, label %18
17: ; preds = %11, %7, %1
store i32 0, i32* %2
br label %36
18: ; preds = %11
store i32 1, i32* %4
br label %19
19: ; preds = %32, %18
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %35
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @isxdigit(i8 signext %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %22
store i32 0, i32* %2
br label %36
31: ; preds = %22
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %19
35: ; preds = %19
store i32 1, i32* %2
br label %36
36: ; preds = %35, %30, %17
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
define i32 @valid_bw_color(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %20, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 3
br i1 %5, label %6, label %20
6: ; preds = %3
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 35
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
%12 = tail call i32 @isxdigit(i8 signext %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %0, i64 2
%16 = load i8, i8* %15
%17 = tail call i32 @isxdigit(i8 signext %16)
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %14, %9, %1, %3, %6
%21 = phi i32 [ 0, %6 ], [ 0, %3 ], [ 0, %1 ], [ 0, %9 ], [ %19, %14 ]
ret i32 %21
}