#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 */
char *strdup(char const *);
size_t strlen(char *);
char *Capitalized(const char *input) {
  char *result;
  size_t i;
  result = strdup(input);
  if (result[0] > 90) {
    result[0] -= 32;
  }
  for (i = 1; i < strlen(result); i++) {
    if ((result[i] > 64) && (result[i] < 91)) {
      result[i] += 32;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<Capitalized>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5a,%eax
jle    1155 <Capitalized+0x35>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
sub    $0x20,%ecx
mov    %cl,(%rax)
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jae    11d0 <Capitalized+0xb0>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x40,%eax
jle    11ba <Capitalized+0x9a>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5b,%eax
jge    11ba <Capitalized+0x9a>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
add    $0x20,%edx
mov    %dl,(%rax,%rcx,1)
jmp    11bf <Capitalized+0x9f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115d <Capitalized+0x3d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Capitalized>:
push   %r14
push   %rbx
push   %rax
call   1040 <strdup@plt>
mov    %rax,%r14
mov    (%rax),%al
cmp    $0x5b,%al
jl     1137 <Capitalized+0x17>
add    $0xe0,%al
mov    %al,(%r14)
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%rax
jb     1176 <Capitalized+0x56>
mov    $0x1,%ebx
jmp    1161 <Capitalized+0x41>
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %rax,%rbx
jae    1176 <Capitalized+0x56>
movzbl (%r14,%rbx,1),%eax
lea    -0x41(%rax),%ecx
cmp    $0x19,%cl
ja     1150 <Capitalized+0x30>
add    $0x20,%al
mov    %al,(%r14,%rbx,1)
jmp    1150 <Capitalized+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define noalias i8* @Capitalized(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = load i8, i8* %2
%4 = icmp sgt i8 %3, 90
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = add nsw i8 %3, -32
store i8 %6, i8* %2
br label %7
7: ; preds = %5, %1
%8 = tail call i64 @strlen(i8* %2)
%9 = icmp ugt i64 %8, 1
br i1 %9, label %10, label %22
10: ; preds = %7, %18
%11 = phi i64 [ %19, %18 ], [ 1, %7 ]
%12 = getelementptr inbounds i8, i8* %2, i64 %11
%13 = load i8, i8* %12
%14 = add i8 %13, -65
%15 = icmp ult i8 %14, 26
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = add nuw nsw i8 %13, 32
store i8 %17, i8* %12
br label %18
18: ; preds = %10, %16
%19 = add nuw i64 %11, 1
%20 = tail call i64 @strlen(i8* %2)
%21 = icmp ult i64 %19, %20
br i1 %21, label %10, label %22
22: ; preds = %18, %7
ret i8* %2
}