#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 */
size_t strlen(char *);
char tolower(char);
char *euca_strtolower(char *restrict string) {
  register size_t i = 0;
  register size_t len = 0;
  if (string) {
    len = strlen(string);
    for (i = 0; i < len; i++) {
      string[i] = tolower(string[i]);
    }
  }
  return (string);
}


x86 assembly (clang, -O0):
<euca_strtolower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119e <euca_strtolower+0x7e>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1199 <euca_strtolower+0x79>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115c <euca_strtolower+0x3c>
jmp    119e <euca_strtolower+0x7e>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euca_strtolower>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
test   %rdi,%rdi
je     1157 <euca_strtolower+0x37>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1157 <euca_strtolower+0x37>
mov    %rax,%r14
xor    %ebx,%ebx
nop
movsbl (%r15,%rbx,1),%edi
call   1040 <tolower@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <euca_strtolower+0x20>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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