#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 toupper(char);
char *capitalize(char *str) {
  static char outbuf[10000];
  int cnt;
  for (cnt = 0; str[cnt] != 0; cnt++) {
    outbuf[cnt] = toupper(str[cnt]);
  }
  outbuf[cnt] = 0;
  return outbuf;
}


x86 assembly (clang, -O0):
<capitalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1167 <capitalize+0x57>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
movslq -0xc(%rbp),%rcx
lea    0x2eea(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <capitalize+0x13>
movslq -0xc(%rbp),%rcx
lea    0x2ece(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ec3(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<capitalize>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     114e <capitalize+0x3e>
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x2f19(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%rbx,%r15,1)
movzbl 0x1(%r14,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <capitalize+0x20>
mov    %ebx,%ecx
jmp    1150 <capitalize+0x40>
xor    %ecx,%ecx
lea    0x2ee9(%rip),%rax
movb   $0x0,(%rcx,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@capitalize.outbuf = internal global [10000 x i8] zeroinitializer
define i8* @capitalize(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %15, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %9, %4 ], [ 0, %1 ]
%6 = phi i8 [ %11, %4 ], [ %2, %1 ]
%7 = tail call signext i8 @toupper(i8 signext %6)
%8 = getelementptr inbounds [10000 x i8], [10000 x i8]* @capitalize.outbuf, i64 0, i64 %5
store i8 %7, i8* %8
%9 = add nuw i64 %5, 1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = and i64 %9, 4294967295
br label %15
15: ; preds = %13, %1
%16 = phi i64 [ 0, %1 ], [ %14, %13 ]
%17 = getelementptr inbounds [10000 x i8], [10000 x i8]* @capitalize.outbuf, i64 0, i64 %16
store i8 0, i8* %17
ret i8* getelementptr inbounds ([10000 x i8], [10000 x i8]* @capitalize.outbuf, i64 0, i64 0)
}