#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 strlen(char *);
scalar_t__ tolower(char);
char *toLowerCase(char *src) {
  char *result = (char *)malloc(sizeof(char) * (1023 + 1));
  int srcLen = strlen(src);
  for (int i = 0; i < srcLen; i++) {
    result[i] = (char)tolower(src[i]);
  }
  result[srcLen] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<toLowerCase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1195 <toLowerCase+0x65>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115d <toLowerCase+0x2d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toLowerCase>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
test   %eax,%eax
jle    1177 <toLowerCase+0x47>
mov    %r15d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%edi
call   1040 <tolower@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <toLowerCase+0x30>
movslq %r15d,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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