#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__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
scalar_t__ tolower(char);
char *lowercase(const char *string) {
  char *new_string, *p;
  new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
  if (!new_string) {
    return 0;
  }
  strcpy(new_string, string);
  p = new_string;
  while (*p != 0) {
    *p = (char)(tolower(*p));
    ++p;
  }
  return new_string;
}


x86 assembly (clang, -O0):
<lowercase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1180 <lowercase+0x40>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <lowercase+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ca <lowercase+0x8a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1195 <lowercase+0x55>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lowercase>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1198 <lowercase+0x58>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    (%r15),%al
test   %al,%al
je     119b <lowercase+0x5b>
mov    %r15,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1050 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <lowercase+0x40>
jmp    119b <lowercase+0x5b>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @lowercase(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 1
%9 = mul i64 1, %8
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %1
store i8* null, i8** %2
br label %36
16: ; preds = %1
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %4
store i8* %20, i8** %5
br label %21
21: ; preds = %26, %16
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = call i64 @tolower(i8 signext %28)
%30 = trunc i64 %29 to i8
%31 = load i8*, i8** %5
store i8 %30, i8* %31
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
br label %21
34: ; preds = %21
%35 = load i8*, i8** %4
store i8* %35, i8** %2
br label %36
36: ; preds = %34, %15
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
define i8* @lowercase(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %20, label %8
8: ; preds = %1
%9 = tail call i32 @strcpy(i8* %6, i8* %0)
%10 = load i8, i8* %6
%11 = icmp eq i8 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %8, %12
%13 = phi i8 [ %18, %12 ], [ %10, %8 ]
%14 = phi i8* [ %17, %12 ], [ %6, %8 ]
%15 = tail call i64 @tolower(i8 signext %13)
%16 = trunc i64 %15 to i8
store i8 %16, i8* %14
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %12
20: ; preds = %12, %8, %1
%21 = phi i8* [ null, %1 ], [ %6, %8 ], [ %6, %12 ]
ret i8* %21
}