#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 */
unsigned int colorcode(char const *, char *, int /*<<< orphan*/ *, int, int *);
unsigned int strlen(char const *);
int color_strlen(const char *src) {
  register unsigned int i = 0;
  int len = 0;
  if (!src || !*src)
    return 0;
  for (i = 0; i < strlen(src);) {
    char dst[20];
    int vislen;
    switch (src[i]) {
    case '&':
    case '^':
    case '}':
      *dst = '\0';
      vislen = 0;
      i += colorcode(&src[i], dst, NULL, 20, &vislen);
      len += vislen;
      break;
    default:
      ++len;
      ++i;
      break;
    }
  }
  return len;
}


x86 assembly (clang, -O0):
<color_strlen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1152 <color_strlen+0x32>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    115e <color_strlen+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    121b <color_strlen+0xfb>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jae    1215 <color_strlen+0xf5>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x26,%eax
je     11bf <color_strlen+0x9f>
jmp    119d <color_strlen+0x7d>
mov    -0x3c(%rbp),%eax
sub    $0x5e,%eax
je     11bf <color_strlen+0x9f>
jmp    11ae <color_strlen+0x8e>
mov    -0x3c(%rbp),%eax
sub    $0x7d,%eax
jne    11fe <color_strlen+0xde>
jmp    11bf <color_strlen+0x9f>
movb   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x14,%ecx
lea    -0x34(%rbp),%r8
call   1040 <colorcode@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x34(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1210 <color_strlen+0xf0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <color_strlen+0x45>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<color_strlen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %r14d,%r14d
test   %rdi,%rdi
je     11bb <color_strlen+0x9b>
mov    %rdi,%r13
cmpb   $0x0,(%rdi)
je     11bb <color_strlen+0x9b>
mov    %r13,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11bb <color_strlen+0x9b>
xor    %r14d,%r14d
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
xor    %ebx,%ebx
jmp    1199 <color_strlen+0x79>
nop
add    %r13,%rdi
movb   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
mov    %r15,%rsi
xor    %edx,%edx
mov    $0x14,%ecx
mov    %r12,%r8
call   1040 <colorcode@plt>
mov    %eax,%ebp
add    %ebx,%ebp
add    0xc(%rsp),%r14d
mov    %ebp,%ebx
mov    %r13,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jae    11bb <color_strlen+0x9b>
mov    %ebx,%edi
movsbl 0x0(%r13,%rdi,1),%eax
cmp    $0x26,%eax
je     1160 <color_strlen+0x40>
cmp    $0x7d,%eax
je     1160 <color_strlen+0x40>
cmp    $0x5e,%eax
je     1160 <color_strlen+0x40>
add    $0x1,%r14d
add    $0x1,%ebx
mov    %ebx,%ebp
jmp    118d <color_strlen+0x6d>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @color_strlen(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [20 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10, %1
store i32 0, i32* %2
br label %49
15: ; preds = %10
store i32 0, i32* %4
br label %16
16: ; preds = %46, %15
%17 = load i32, i32* %4
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
%20 = icmp ult i32 %17, %19
br i1 %20, label %21, label %47
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %41 [
i32 38, label %28
i32 94, label %28
i32 125, label %28
]
28: ; preds = %21, %21, %21
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
store i8 0, i8* %29
store i32 0, i32* %7
%30 = load i8*, i8** %3
%31 = load i32, i32* %4
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%35 = call i32 @colorcode(i8* %33, i8* %34, i32* null, i32 20, i32* %7)
%36 = load i32, i32* %4
%37 = add i32 %36, %35
store i32 %37, i32* %4
%38 = load i32, i32* %7
%39 = load i32, i32* %5
%40 = add nsw i32 %39, %38
store i32 %40, i32* %5
br label %46
41: ; preds = %21
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
%44 = load i32, i32* %4
%45 = add i32 %44, 1
store i32 %45, i32* %4
br label %46
46: ; preds = %41, %28
br label %16
47: ; preds = %16
%48 = load i32, i32* %5
store i32 %48, i32* %2
br label %49
49: ; preds = %47, %14
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
define i32 @color_strlen(i8* %0) {
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = icmp eq i8* %0, null
br i1 %4, label %34, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %34, label %8
8: ; preds = %5
%9 = call i32 @strlen(i8* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %34, label %11
11: ; preds = %8
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%13 = bitcast i32* %3 to i8*
br label %14
14: ; preds = %11, %29
%15 = phi i32 [ 0, %11 ], [ %31, %29 ]
%16 = phi i32 [ 0, %11 ], [ %30, %29 ]
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
switch i32 %20, label %26 [
i32 38, label %21
i32 94, label %21
i32 125, label %21
]
21: ; preds = %14, %14, %14
store i8 0, i8* %12
store i32 0, i32* %3
%22 = call i32 @colorcode(i8* %18, i8* %12, i32* null, i32 20, i32* %3)
%23 = add i32 %22, %16
%24 = load i32, i32* %3
%25 = add nsw i32 %24, %15
br label %29
26: ; preds = %14
%27 = add nsw i32 %15, 1
%28 = add nuw i32 %16, 1
br label %29
29: ; preds = %26, %21
%30 = phi i32 [ %28, %26 ], [ %23, %21 ]
%31 = phi i32 [ %27, %26 ], [ %25, %21 ]
%32 = call i32 @strlen(i8* %0)
%33 = icmp ult i32 %30, %32
br i1 %33, label %14, label %34
34: ; preds = %29, %8, %1, %5
%35 = phi i32 [ 0, %5 ], [ 0, %1 ], [ 0, %8 ], [ %31, %29 ]
ret i32 %35
}