#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 */
char *deblank(char *);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char tolower(char);
char *str_tolower(const char *str) {
  int length = strlen(str);
  char *word = malloc(length);
  strcpy(word, str);
  word[length] = '\0';
  unsigned int i;
  for (i = 0; word[i] != '\0' && i < length; i++) {
    word[i] = tolower(word[i]);
  }
  return deblank(word);
}


x86 assembly (clang, -O0):
<str_tolower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     11b9 <str_tolower+0x69>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
setb   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11c9 <str_tolower+0x79>
jmp    11f3 <str_tolower+0xa3>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1050 <tolower@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1194 <str_tolower+0x44>
mov    -0x18(%rbp),%rdi
call   1070 <deblank@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_tolower>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    (%rbx),%al
test   %al,%al
je     11b0 <str_tolower+0x60>
test   %ebp,%ebp
je     11b0 <str_tolower+0x60>
mov    %ebp,%r14d
mov    $0x1,%ebp
nopl   0x0(%rax)
movsbl %al,%edi
call   1050 <tolower@plt>
mov    %al,-0x1(%rbx,%rbp,1)
movzbl (%rbx,%rbp,1),%eax
test   %al,%al
je     11b0 <str_tolower+0x60>
lea    0x1(%rbp),%rcx
cmp    %r14,%rbp
mov    %rcx,%rbp
jb     1190 <str_tolower+0x40>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <deblank@plt>

LLVM IR (-O0):
define i8* @str_tolower(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = load i8*, i8** %2
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = load i8*, i8** %4
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8 0, i8* %16
store i32 0, i32* %5
br label %17
17: ; preds = %42, %1
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %17
%26 = load i32, i32* %5
%27 = load i32, i32* %3
%28 = icmp ult i32 %26, %27
br label %29
29: ; preds = %25, %17
%30 = phi i1 [ false, %17 ], [ %28, %25 ]
br i1 %30, label %31, label %45
31: ; preds = %29
%32 = load i8*, i8** %4
%33 = load i32, i32* %5
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = call signext i8 @tolower(i8 signext %36)
%38 = load i8*, i8** %4
%39 = load i32, i32* %5
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 %37, i8* %41
br label %42
42: ; preds = %31
%43 = load i32, i32* %5
%44 = add i32 %43, 1
store i32 %44, i32* %5
br label %17
45: ; preds = %29
%46 = load i8*, i8** %4
%47 = call i8* @deblank(i8* %46)
ret i8* %47
}

LLVM IR (-O2):
define i8* @str_tolower(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i8* @malloc(i32 %2)
%4 = tail call i32 @strcpy(i8* %3, i8* %0)
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i8, i8* %3, i64 %5
store i8 0, i8* %6
%7 = load i8, i8* %3
%8 = icmp ne i8 %7, 0
%9 = icmp ne i32 %2, 0
%10 = and i1 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %1
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %18, %13 ]
%15 = phi i8 [ %7, %11 ], [ %20, %13 ]
%16 = phi i8* [ %3, %11 ], [ %19, %13 ]
%17 = tail call signext i8 @tolower(i8 signext %15)
store i8 %17, i8* %16
%18 = add nuw nsw i64 %14, 1
%19 = getelementptr inbounds i8, i8* %3, i64 %18
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 0
%22 = icmp ult i64 %18, %12
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %13, label %24
24: ; preds = %13, %1
%25 = tail call i8* @deblank(i8* %3)
ret i8* %25
}