#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__ isupper(char const);
char const tolower(char const);
char *memcpy_lowcase(char *dest, char const *src, size_t len) {
  while (len-- > 0)
    dest[len] = (isupper(src[len]) ? tolower(src[len]) : (src[len]));
  return dest;
}


x86 assembly (clang, -O0):
<memcpy_lowcase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
jbe    11a8 <memcpy_lowcase+0x88>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isupper@plt>
cmp    $0x0,%rax
je     1184 <memcpy_lowcase+0x64>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <tolower@plt>
movsbl %al,%eax
mov    %eax,-0x1c(%rbp)
jmp    1193 <memcpy_lowcase+0x73>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1134 <memcpy_lowcase+0x14>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcpy_lowcase>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdx,%rdx
je     1174 <memcpy_lowcase+0x54>
mov    %rdx,%rbx
mov    %rsi,%r15
jmp    114d <memcpy_lowcase+0x2d>
nopl   0x0(%rax,%rax,1)
mov    %al,-0x1(%r14,%rbx,1)
mov    %r12,%rbx
test   %r12,%r12
je     1174 <memcpy_lowcase+0x54>
lea    -0x1(%rbx),%r12
movsbl -0x1(%r15,%rbx,1),%edi
call   1040 <isupper@plt>
mov    %rax,%rcx
movzbl -0x1(%r15,%rbx,1),%eax
test   %rcx,%rcx
je     1140 <memcpy_lowcase+0x20>
movsbl %al,%edi
call   1030 <tolower@plt>
jmp    1140 <memcpy_lowcase+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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