#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 *malloc(int);
char tolower(char const);
char *makelower(const char *str, size_t t) {
  char *out = malloc(sizeof(char) * (t + 1));
  for (int i = 0; i < t; i++) {
    out[i] = tolower(str[i]);
  }
  out[t] = 0;
  return out;
}


x86 assembly (clang, -O0):
<makelower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1188 <makelower+0x68>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <tolower@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114e <makelower+0x2e>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makelower>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x1(%rsi),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %r15,%r15
je     1157 <makelower+0x37>
xor    %ebx,%ebx
movsbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <makelower+0x20>
movb   $0x0,(%r12,%r15,1)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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