#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 *galloc(int);
unsigned int str_length(char const *);
char *str_lower(const char *s) {
  char *ret = galloc(str_length(s) + 1);
  for (unsigned i = 0; i <= str_length(s); i++)
    if (s[i] >= 'A' && s[i] <= 'Z')
      ret[i] = s[i] + 0x20;
    else
      ret[i] = s[i];
  return ret;
}


x86 assembly (clang, -O0):
<str_lower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <str_length@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1040 <galloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <str_length@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
ja     11d4 <str_lower+0xb4>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x41,%eax
jl     11ad <str_lower+0x8d>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5a,%eax
jg     11ad <str_lower+0x8d>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
add    $0x20,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    11c1 <str_lower+0xa1>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    11c6 <str_lower+0xa6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <str_lower+0x2a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_lower>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <str_length@plt>
lea    0x1(%rax),%edi
call   1040 <galloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <str_length@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
movzbl (%rbx,%rax,1),%ecx
lea    -0x41(%rcx),%edx
lea    0x20(%rcx),%esi
cmp    $0x1a,%dl
movzbl %sil,%edx
cmovae %ecx,%edx
mov    %dl,(%r14,%rax,1)
add    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <str_length@plt>
cmp    %eax,%ebp
jbe    1150 <str_lower+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @str_lower(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @str_length(i8* %5)
%7 = add i32 %6, 1
%8 = call i8* @galloc(i32 %7)
store i8* %8, i8** %3
store i32 0, i32* %4
br label %9
9: ; preds = %54, %1
%10 = load i32, i32* %4
%11 = load i8*, i8** %2
%12 = call i32 @str_length(i8* %11)
%13 = icmp ule i32 %10, %12
br i1 %13, label %14, label %57
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = load i32, i32* %4
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp sge i32 %20, 65
br i1 %21, label %22, label %43
22: ; preds = %14
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp sle i32 %28, 90
br i1 %29, label %30, label %43
30: ; preds = %22
%31 = load i8*, i8** %2
%32 = load i32, i32* %4
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = add nsw i32 %36, 32
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %3
%40 = load i32, i32* %4
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
br label %53
43: ; preds = %22, %14
%44 = load i8*, i8** %2
%45 = load i32, i32* %4
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = load i8*, i8** %3
%50 = load i32, i32* %4
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 %48, i8* %52
br label %53
53: ; preds = %43, %30
br label %54
54: ; preds = %53
%55 = load i32, i32* %4
%56 = add i32 %55, 1
store i32 %56, i32* %4
br label %9
57: ; preds = %9
%58 = load i8*, i8** %3
ret i8* %58
}

LLVM IR (-O2):
define i8* @str_lower(i8* %0) {
%2 = tail call i32 @str_length(i8* %0)
%3 = add i32 %2, 1
%4 = tail call i8* @galloc(i32 %3)
%5 = tail call i32 @str_length(i8* %0)
br label %7
6: ; preds = %7
ret i8* %4
7: ; preds = %1, %7
%8 = phi i32 [ 0, %1 ], [ %17, %7 ]
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = add i8 %11, -65
%13 = icmp ult i8 %12, 26
%14 = add nuw nsw i8 %11, 32
%15 = select i1 %13, i8 %14, i8 %11
%16 = getelementptr inbounds i8, i8* %4, i64 %9
store i8 %15, i8* %16
%17 = add i32 %8, 1
%18 = tail call i32 @str_length(i8* %0)
%19 = icmp ugt i32 %17, %18
br i1 %19, label %6, label %7
}