#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ my_puts(char *);
int my_strlen(char *);
char *my_strcapitalize(char *str) {
  char *string;
  if ((string = (char *)malloc(my_strlen(str) * sizeof(char))) == NULL) {
    my_puts("ERROR: malloc failed\n");
    return 0;
  }
  for (int i = 0; i < my_strlen(str); i++) {
    if (str[i] >= 'a' && str[i] <= 'z') {
      string[i] = 'A' + str[i] - 'a';
    } else {
      string[i] = str[i];
    }
  }
  return string;
}


x86 assembly (clang, -O0):
<my_strcapitalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1179 <my_strcapitalize+0x49>
lea    0xe99(%rip),%rdi
call   1040 <my_puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    121b <my_strcapitalize+0xeb>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1213 <my_strcapitalize+0xe3>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x61,%eax
jl     11ea <my_strcapitalize+0xba>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7a,%eax
jg     11ea <my_strcapitalize+0xba>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x41,%eax
sub    $0x61,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1200 <my_strcapitalize+0xd0>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1205 <my_strcapitalize+0xd5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <my_strcapitalize+0x50>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_strcapitalize>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <my_strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     118d <my_strcapitalize+0x5d>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <my_strlen@plt>
test   %eax,%eax
jle    119c <my_strcapitalize+0x6c>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
lea    -0x61(%rax),%ecx
lea    -0x20(%rax),%edx
cmp    $0x1a,%cl
movzbl %dl,%ecx
cmovae %eax,%ecx
mov    %cl,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <my_strlen@plt>
cltq
cmp    %rax,%rbx
jl     1160 <my_strcapitalize+0x30>
jmp    119c <my_strcapitalize+0x6c>
lea    0xe6c(%rip),%rdi
call   1040 <my_puts@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"ERROR: malloc failed\0A\00"
define i8* @my_strcapitalize(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @my_strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 1
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @my_puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %68
16: ; preds = %1
store i32 0, i32* %5
br label %17
17: ; preds = %63, %16
%18 = load i32, i32* %5
%19 = load i8*, i8** %3
%20 = call i32 @my_strlen(i8* %19)
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %66
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp sge i32 %28, 97
br i1 %29, label %30, label %52
30: ; preds = %22
%31 = load i8*, i8** %3
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp sle i32 %36, 122
br i1 %37, label %38, label %52
38: ; preds = %30
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = add nsw i32 65, %44
%46 = sub nsw i32 %45, 97
%47 = trunc i32 %46 to i8
%48 = load i8*, i8** %4
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 %47, i8* %51
br label %62
52: ; preds = %30, %22
%53 = load i8*, i8** %3
%54 = load i32, i32* %5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = load i8*, i8** %4
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 %57, i8* %61
br label %62
62: ; preds = %52, %38
br label %63
63: ; preds = %62
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
store i32 %65, i32* %5
br label %17
66: ; preds = %17
%67 = load i8*, i8** %4
store i8* %67, i8** %2
br label %68
68: ; preds = %66, %14
%69 = load i8*, i8** %2
ret i8* %69
}

LLVM IR (-O2):
@.str = [22 x i8] c"ERROR: malloc failed\0A\00"
define i8* @my_strcapitalize(i8* %0) {
%2 = tail call i32 @my_strlen(i8* %0)
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = tail call i32 @my_strlen(i8* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %11, label %24
9: ; preds = %1
%10 = tail call i32 @my_puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %24
11: ; preds = %6, %11
%12 = phi i64 [ %20, %11 ], [ 0, %6 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = add i8 %14, -97
%16 = icmp ult i8 %15, 26
%17 = add nsw i8 %14, -32
%18 = select i1 %16, i8 %17, i8 %14
%19 = getelementptr inbounds i8, i8* %4, i64 %12
store i8 %18, i8* %19
%20 = add nuw nsw i64 %12, 1
%21 = tail call i32 @my_strlen(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %11, label %24
24: ; preds = %11, %6, %9
%25 = phi i8* [ null, %9 ], [ %4, %6 ], [ %4, %11 ]
ret i8* %25
}