#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*/ isalnum(unsigned char);
scalar_t__ isupper(unsigned char);
unsigned char tolower(unsigned char);
unsigned char *canoncolor(char *orig, unsigned char *out) {
  unsigned char c;
  unsigned char *p = out;
  while ((c = *(unsigned char *)orig++)) {
    if (isalnum(c) == (0))
      continue;
    if (isupper(c))
      c = tolower(c);
    *p++ = c;
  }
  *p = '\0';
  return out;
}


x86 assembly (clang, -O0):
<canoncolor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
cmp    $0x0,%al
je     11b3 <canoncolor+0x83>
movzbl -0x11(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%eax
jne    117b <canoncolor+0x4b>
jmp    1148 <canoncolor+0x18>
movzbl -0x11(%rbp),%edi
call   1050 <isupper@plt>
cmp    $0x0,%rax
je     119a <canoncolor+0x6a>
movzbl -0x11(%rbp),%edi
call   1040 <tolower@plt>
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1148 <canoncolor+0x18>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canoncolor>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%ebp
test   %bpl,%bpl
je     118d <canoncolor+0x5d>
add    $0x1,%rbx
movzbl %bpl,%r15d
mov    %r15d,%edi
call   1030 <isalnum@plt>
test   %eax,%eax
je     1150 <canoncolor+0x20>
mov    %r15d,%edi
call   1050 <isupper@plt>
test   %rax,%rax
je     1183 <canoncolor+0x53>
mov    %r15d,%edi
call   1040 <tolower@plt>
mov    %eax,%ebp
mov    %bpl,(%r12)
add    $0x1,%r12
jmp    1150 <canoncolor+0x20>
movb   $0x0,(%r12)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @canoncolor(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
store i8* %7, i8** %6
br label %8
8: ; preds = %25, %17, %2
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %3
%11 = load i8, i8* %9
store i8 %11, i8* %5
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %8
%14 = load i8, i8* %5
%15 = call i32 @isalnum(i8 zeroext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %8
18: ; preds = %13
%19 = load i8, i8* %5
%20 = call i64 @isupper(i8 zeroext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i8, i8* %5
%24 = call zeroext i8 @tolower(i8 zeroext %23)
store i8 %24, i8* %5
br label %25
25: ; preds = %22, %18
%26 = load i8, i8* %5
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
store i8 %26, i8* %27
br label %8
29: ; preds = %8
%30 = load i8*, i8** %6
store i8 0, i8* %30
%31 = load i8*, i8** %4
ret i8* %31
}

LLVM IR (-O2):
define i8* @canoncolor(i8* nocapture %0, i8* returned writeonly %1) {
br label %3
3: ; preds = %19, %2
%4 = phi i8* [ %8, %19 ], [ %0, %2 ]
%5 = phi i8* [ %21, %19 ], [ %1, %2 ]
br label %6
6: ; preds = %3, %11
%7 = phi i8* [ %8, %11 ], [ %4, %3 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %7
%10 = icmp eq i8 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %6
%12 = tail call i32 @isalnum(i8 zeroext %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %11
%15 = tail call i64 @isupper(i8 zeroext %9)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call zeroext i8 @tolower(i8 zeroext %9)
br label %19
19: ; preds = %17, %14
%20 = phi i8 [ %18, %17 ], [ %9, %14 ]
%21 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %20, i8* %5
br label %3
22: ; preds = %6
store i8 0, i8* %5
ret i8* %1
}