#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 lch(char);
int /*<<< orphan*/ memset(char *, char, unsigned long);
unsigned long strlen(char *);
char *lcase(char *str) {
  register unsigned long int i, l;
  char lc[20480];
  l = strlen(str);
  memset(lc, '\0', l + 1);
  for (i = 0; i < l; i++)
    lc[i] = lch(str[i]);
  return lc;
}


x86 assembly (clang, -O0):
<lcase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5020,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x5020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a7 <lcase+0x77>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <lch@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,-0x5020(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    116a <lcase+0x3a>
lea    -0x5020(%rbp),%rax
add    $0x5020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcase>:
push   %r15
push   %r14
push   %rbx
sub    $0x5000,%rsp
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdx
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
test   %r15,%r15
je     1176 <lcase+0x46>
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%edi
call   1050 <lch@plt>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <lcase+0x30>
mov    %rsp,%rax
add    $0x5000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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