#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 *sspm_strdup(char *);
char tolower(char);
char *sspm_lowercase(char *str) {
  char *p = 0;
  char *ret;
  if (str == 0) {
    return 0;
  }
  ret = sspm_strdup(str);
  for (p = ret; *p != 0; p++) {
    *p = tolower(*p);
  }
  return ret;
}


x86 assembly (clang, -O0):
<sspm_lowercase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114c <sspm_lowercase+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    119e <sspm_lowercase+0x7e>
mov    -0x10(%rbp),%rdi
call   1030 <sspm_strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1196 <sspm_lowercase+0x76>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1161 <sspm_lowercase+0x41>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sspm_lowercase>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1158 <sspm_lowercase+0x38>
call   1030 <sspm_strdup@plt>
mov    %rax,%r14
mov    (%rax),%al
test   %al,%al
je     115b <sspm_lowercase+0x3b>
mov    %r14,%rbx
add    $0x1,%rbx
xchg   %ax,%ax
movsbl %al,%edi
call   1040 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <sspm_lowercase+0x20>
jmp    115b <sspm_lowercase+0x3b>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @sspm_lowercase(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
%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 %28
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @sspm_strdup(i8* %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
store i8* %12, i8** %4
br label %13
13: ; preds = %23, %9
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = call signext i8 @tolower(i8 signext %20)
%22 = load i8*, i8** %4
store i8 %21, i8* %22
br label %23
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
br label %13
26: ; preds = %13
%27 = load i8*, i8** %5
store i8* %27, i8** %2
br label %28
28: ; preds = %26, %8
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
define i8* @sspm_lowercase(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i8* @sspm_strdup(i8* %0)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %3, %7
%8 = phi i8 [ %12, %7 ], [ %5, %3 ]
%9 = phi i8* [ %11, %7 ], [ %4, %3 ]
%10 = tail call signext i8 @tolower(i8 signext %8)
store i8 %10, i8* %9
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %7
14: ; preds = %7, %3, %1
%15 = phi i8* [ null, %1 ], [ %4, %3 ], [ %4, %7 ]
ret i8* %15
}