#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 /*<<< orphan*/ asprintf(char **, char *, char *);
char tolower(char);
char *strToLower(char *str) {
  if (str == NULL)
    return NULL;
  char *retstr;
  asprintf(&retstr, "%s", str);
  int i;
  for (i = 0; retstr[i] != '\0'; i++)
    retstr[i] = tolower(str[i]);
  return retstr;
}


x86 assembly (clang, -O0):
<strToLower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <strToLower+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <strToLower+0x88>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1040 <asprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11a0 <strToLower+0x80>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <tolower@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <strToLower+0x3f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strToLower>:
test   %rdi,%rdi
je     1178 <strToLower+0x58>
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xecd(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
call   1040 <asprintf@plt>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     1170 <strToLower+0x50>
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
mov    (%rsp),%rcx
mov    %al,(%rcx,%rbx,1)
mov    (%rsp),%rax
cmpb   $0x0,0x1(%rax,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1150 <strToLower+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i8* @strToLower(i8* %0) {
%2 = alloca i8*
%3 = icmp eq i8* %0, null
br i1 %3, label %24, label %4
4: ; preds = %1
%5 = bitcast i8** %2 to i8*
%6 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %4, %10
%11 = phi i64 [ %17, %10 ], [ 0, %4 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = call signext i8 @tolower(i8 signext %13)
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 %11
store i8 %14, i8* %16
%17 = add nuw i64 %11, 1
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i64 %17
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %10
22: ; preds = %10, %4
%23 = phi i8* [ %7, %4 ], [ %18, %10 ]
br label %24
24: ; preds = %1, %22
%25 = phi i8* [ %23, %22 ], [ null, %1 ]
ret i8* %25
}