#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 */
typedef size_t u_int32_t;
typedef int /*<<< orphan*/ s;

/* Variables and functions */
scalar_t__ malloc(size_t);
char tolower(char);
char *convert_to_lowercase(char *s) {
  size_t len = sizeof(s);
  char *new_s = (char *)malloc(len);
  for (u_int32_t i = 0; i < len; ++i) {
    new_s[i] = tolower(s[i]);
  }
  return new_s;
}


x86 assembly (clang, -O0):
<convert_to_lowercase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x8,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1186 <convert_to_lowercase+0x66>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <tolower@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1149 <convert_to_lowercase+0x29>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_to_lowercase>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movsbl (%r14),%edi
call   1030 <tolower@plt>
mov    %al,(%rbx)
movsbl 0x1(%r14),%edi
call   1030 <tolower@plt>
mov    %al,0x1(%rbx)
movsbl 0x2(%r14),%edi
call   1030 <tolower@plt>
mov    %al,0x2(%rbx)
movsbl 0x3(%r14),%edi
call   1030 <tolower@plt>
mov    %al,0x3(%rbx)
movsbl 0x4(%r14),%edi
call   1030 <tolower@plt>
mov    %al,0x4(%rbx)
movsbl 0x5(%r14),%edi
call   1030 <tolower@plt>
mov    %al,0x5(%rbx)
movsbl 0x6(%r14),%edi
call   1030 <tolower@plt>
mov    %al,0x6(%rbx)
movsbl 0x7(%r14),%edi
call   1030 <tolower@plt>
mov    %al,0x7(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @convert_to_lowercase(i8* nocapture %0) {
%2 = tail call i64 @malloc(i64 8)
%3 = inttoptr i64 %2 to i8*
%4 = load i8, i8* %0
%5 = tail call signext i8 @tolower(i8 signext %4)
store i8 %5, i8* %3
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = tail call signext i8 @tolower(i8 signext %7)
%9 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %8, i8* %9
%10 = getelementptr inbounds i8, i8* %0, i64 2
%11 = load i8, i8* %10
%12 = tail call signext i8 @tolower(i8 signext %11)
%13 = getelementptr inbounds i8, i8* %3, i64 2
store i8 %12, i8* %13
%14 = getelementptr inbounds i8, i8* %0, i64 3
%15 = load i8, i8* %14
%16 = tail call signext i8 @tolower(i8 signext %15)
%17 = getelementptr inbounds i8, i8* %3, i64 3
store i8 %16, i8* %17
%18 = getelementptr inbounds i8, i8* %0, i64 4
%19 = load i8, i8* %18
%20 = tail call signext i8 @tolower(i8 signext %19)
%21 = getelementptr inbounds i8, i8* %3, i64 4
store i8 %20, i8* %21
%22 = getelementptr inbounds i8, i8* %0, i64 5
%23 = load i8, i8* %22
%24 = tail call signext i8 @tolower(i8 signext %23)
%25 = getelementptr inbounds i8, i8* %3, i64 5
store i8 %24, i8* %25
%26 = getelementptr inbounds i8, i8* %0, i64 6
%27 = load i8, i8* %26
%28 = tail call signext i8 @tolower(i8 signext %27)
%29 = getelementptr inbounds i8, i8* %3, i64 6
store i8 %28, i8* %29
%30 = getelementptr inbounds i8, i8* %0, i64 7
%31 = load i8, i8* %30
%32 = tail call signext i8 @tolower(i8 signext %31)
%33 = getelementptr inbounds i8, i8* %3, i64 7
store i8 %32, i8* %33
ret i8* %3
}