#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 strlen(char *);
char toupper(char);
void capitalize(char *sentence) {
  int i;
  *sentence = toupper(*sentence);
  for (i = 1; i < strlen(sentence); i++)
    if (*(sentence + i - 1) == ' ')
      *(sentence + i) = toupper(*(sentence + i));
  return;
}


x86 assembly (clang, -O0):
<capitalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jge    11aa <capitalize+0x8a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1197 <capitalize+0x77>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    119c <capitalize+0x7c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1147 <capitalize+0x27>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<capitalize>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <toupper@plt>
mov    %al,(%r14)
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     117b <capitalize+0x5b>
mov    $0x1,%ebx
jmp    1163 <capitalize+0x43>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    117b <capitalize+0x5b>
cmpb   $0x20,-0x1(%r14,%rbx,1)
jne    1150 <capitalize+0x30>
movsbl (%r14,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%r14,%rbx,1)
jmp    1150 <capitalize+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @capitalize(i8* %0) {
%2 = load i8, i8* %0
%3 = tail call signext i8 @toupper(i8 signext %2)
store i8 %3, i8* %0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 1
br i1 %5, label %6, label %20
6: ; preds = %1, %15
%7 = phi i64 [ %16, %15 ], [ 1, %1 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 32
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = load i8, i8* %8
%14 = tail call signext i8 @toupper(i8 signext %13)
store i8 %14, i8* %8
br label %15
15: ; preds = %6, %12
%16 = add nuw nsw i64 %7, 1
%17 = tail call i32 @strlen(i8* %0)
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %6, label %20
20: ; preds = %15, %1
ret void
}