#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 */
int strlen(char *);
char tolower(char);
void stolower(char *str) {
  int i;
  if (!str) {
    return;
  }
  for (i = 0; i <= strlen(str); i++) {
    str[i] = tolower(str[i]);
  }
}


x86 assembly (clang, -O0):
<stolower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113c <stolower+0x1c>
jmp    118b <stolower+0x6b>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jg     118b <stolower+0x6b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <stolower+0x23>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stolower>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1163 <stolower+0x43>
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
js     1163 <stolower+0x43>
mov    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
movsbl 0x1(%r14,%rbx,1),%edi
call   1040 <tolower@plt>
mov    %al,0x1(%r14,%rbx,1)
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1140 <stolower+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @stolower(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %15, 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 nsw i64 %7, 1
%12 = tail call i32 @strlen(i8* %0)
%13 = sext i32 %12 to i64
%14 = icmp slt i64 %7, %13
br i1 %14, label %6, label %15
15: ; preds = %6, %3, %1
ret void
}