#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 *sld_string_allocate(char *);
char toupper(char);
char *sld_string_capitalize(char *string) {
  int i = 0;
  char *capitalized_string = NULL;
  capitalized_string = sld_string_allocate(string);
  while (string[i]) {
    capitalized_string[i] = toupper(string[i]);
    i++;
  }
  return capitalized_string;
}


x86 assembly (clang, -O0):
<sld_string_capitalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <sld_string_allocate@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1186 <sld_string_capitalize+0x66>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1148 <sld_string_capitalize+0x28>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sld_string_capitalize>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <sld_string_allocate@plt>
mov    %rax,%r15
mov    (%r14),%al
test   %al,%al
je     115a <sld_string_capitalize+0x3a>
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%r15,%rbx,1)
movzbl 0x1(%r14,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <sld_string_capitalize+0x20>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @sld_string_capitalize(i8* %0) {
%2 = tail call i8* @sld_string_allocate(i8* %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %10, %5 ], [ 0, %1 ]
%7 = phi i8 [ %12, %5 ], [ %3, %1 ]
%8 = tail call signext i8 @toupper(i8 signext %7)
%9 = getelementptr inbounds i8, i8* %2, i64 %6
store i8 %8, i8* %9
%10 = add nuw i64 %6, 1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %5
14: ; preds = %5, %1
ret i8* %2
}