#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 *calloc(scalar_t__, int);
scalar_t__ strlen(char *);
char tolower(char);
char *lower_case(char *s) {
  char *r = calloc(strlen(s) + 1, sizeof(char));
  for (size_t i = 0; s[i]; ++i)
    r[i] = tolower(s[i]);
  return r;
}


x86 assembly (clang, -O0):
<lower_case>:
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
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11a3 <lower_case+0x73>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <tolower@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1162 <lower_case+0x32>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lower_case>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    (%r14),%al
test   %al,%al
je     117a <lower_case+0x4a>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1050 <tolower@plt>
mov    %al,(%r15,%rbx,1)
movzbl 0x1(%r14,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <lower_case+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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