#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 *malloc(int);
char *realloc(char *, int);
int strlen(char const *);
char tolower(char const);
char *simplify_sn(const char *sn) {
  char *temp;
  int x, count;
  temp = malloc(strlen(sn) + 1);
  for (x = 0, count = 0; x < strlen(sn); x++) {
    if (sn[x] == ' ')
      continue;
    temp[count] = tolower(sn[x]);
    count++;
  }
  temp = realloc(temp, count + 1);
  temp[count] = 0;
  return temp;
}


x86 assembly (clang, -O0):
<simplify_sn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11dc <simplify_sn+0x9c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11a7 <simplify_sn+0x67>
jmp    11ce <simplify_sn+0x8e>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1171 <simplify_sn+0x31>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplify_sn>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11a1 <simplify_sn+0x61>
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    1183 <simplify_sn+0x43>
xchg   %ax,%ax
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11a4 <simplify_sn+0x64>
movzbl (%r15,%rbx,1),%eax
cmp    $0x20,%al
je     1170 <simplify_sn+0x30>
movsbl %al,%edi
call   1040 <tolower@plt>
movslq %r12d,%r12
mov    %al,(%r14,%r12,1)
add    $0x1,%r12d
jmp    1170 <simplify_sn+0x30>
xor    %r12d,%r12d
lea    0x1(%r12),%esi
mov    %r14,%rdi
call   1060 <realloc@plt>
movslq %r12d,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @simplify_sn(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %1, %18
%8 = phi i64 [ %20, %18 ], [ 0, %1 ]
%9 = phi i32 [ %19, %18 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 32
br i1 %12, label %18, label %13
13: ; preds = %7
%14 = tail call signext i8 @tolower(i8 signext %11)
%15 = sext i32 %9 to i64
%16 = getelementptr inbounds i8, i8* %4, i64 %15
store i8 %14, i8* %16
%17 = add nsw i32 %9, 1
br label %18
18: ; preds = %7, %13
%19 = phi i32 [ %9, %7 ], [ %17, %13 ]
%20 = add nuw nsw i64 %8, 1
%21 = tail call i32 @strlen(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %7, label %24
24: ; preds = %18, %1
%25 = phi i32 [ 0, %1 ], [ %19, %18 ]
%26 = add nsw i32 %25, 1
%27 = tail call i8* @realloc(i8* %4, i32 %26)
%28 = sext i32 %25 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 0, i8* %29
ret i8* %27
}