#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__ eMalloc(size_t);
scalar_t__ strlen(char const *);
char tolower(int);
extern char *newLowerString(const char *str) {
  char *const result =
      (char *)eMalloc((size_t)(strlen(str) + 1) * sizeof(char));
  int i = 0;
  do
    result[i] = tolower((int)str[i]);
  while (str[i++] != '\0');
  return result;
}


x86 assembly (clang, -O0):
<newLowerString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1040 <eMalloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <tolower@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1160 <newLowerString+0x30>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newLowerString>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1040 <eMalloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1050 <tolower@plt>
mov    %al,(%r14,%rbx,1)
cmpb   $0x0,(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1150 <newLowerString+0x20>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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