#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);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
char tolower(char);
char *to_lower(char *str) {
  printf(" to_lower: processing %s\n", str);
  int len = strlen(str);
  int i;
  for (i = 0; i < len; i++) {
    if (isupper(str[i])) {
      str[i] = tolower(str[i]);
    }
  }
  printf(" to_lower: return %s\n", str);
  return str;
}


x86 assembly (clang, -O0):
<to_lower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c7 <to_lower+0x87>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <isupper@plt>
cmp    $0x0,%rax
je     11b4 <to_lower+0x74>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <tolower@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11b9 <to_lower+0x79>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116f <to_lower+0x2f>
mov    -0x8(%rbp),%rsi
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_lower>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
lea    0xeb1(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1198 <to_lower+0x58>
mov    %eax,%r14d
xor    %ebx,%ebx
jmp    1179 <to_lower+0x39>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1198 <to_lower+0x58>
movsbl (%r15,%rbx,1),%edi
call   1060 <isupper@plt>
test   %rax,%rax
je     1170 <to_lower+0x30>
movsbl (%r15,%rbx,1),%edi
call   1050 <tolower@plt>
mov    %al,(%r15,%rbx,1)
jmp    1170 <to_lower+0x30>
lea    0xe7b(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c" to_lower: processing %s\0A\00"
@.str.1 = [22 x i8] c" to_lower: return %s\0A\00"
define i8* @to_lower(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %3
store i32 0, i32* %4
br label %9
9: ; preds = %33, %1
%10 = load i32, i32* %4
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = call i64 @isupper(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %13
%22 = load i8*, i8** %2
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call signext i8 @tolower(i8 signext %26)
%28 = load i8*, i8** %2
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %21, %13
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %9
36: ; preds = %9
%37 = load i8*, i8** %2
%38 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
@.str = [26 x i8] c" to_lower: processing %s\0A\00"
@.str.1 = [22 x i8] c" to_lower: return %s\0A\00"
define i8* @to_lower(i8* returned %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %1
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %16
%8 = phi i64 [ 0, %5 ], [ %17, %16 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = tail call i64 @isupper(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = load i8, i8* %9
%15 = tail call signext i8 @tolower(i8 signext %14)
store i8 %15, i8* %9
br label %16
16: ; preds = %7, %13
%17 = add nuw nsw i64 %8, 1
%18 = icmp eq i64 %17, %6
br i1 %18, label %19, label %7
19: ; preds = %16, %1
%20 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
ret i8* %0
}