#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 */
unsigned int strlen(char const *);
char tolower(char const);
void regulo_strcpy_tolower(void *dest, const char *source) {
  unsigned int i;
  for (i = 0; i < strlen(source); i++) {
    ((char *)dest)[i] = tolower(source[i]);
  }
  ((char *)dest)[i] = '\0';
}


x86 assembly (clang, -O0):
<regulo_strcpy_tolower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jae    117d <regulo_strcpy_tolower+0x5d>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <regulo_strcpy_tolower+0x17>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regulo_strcpy_tolower>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1161 <regulo_strcpy_tolower+0x41>
nopl   0x0(%rax)
movsbl (%r15,%rbx,1),%edi
call   1040 <tolower@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1140 <regulo_strcpy_tolower+0x20>
movb   $0x0,(%r14,%rbx,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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