#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(scalar_t__);
char *realloc(char *, int);
scalar_t__ strlen(char const *);
char tolower(char const);
char *imcomm_simplify_sn(const char *sn) {
  char *temp;
  int x, count;
  temp = malloc(strlen(sn) + 1);
  for (x = 0, count = 0; x < (int)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):
<imcomm_simplify_sn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
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    %rax,%rcx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11df <imcomm_simplify_sn+0x9f>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11aa <imcomm_simplify_sn+0x6a>
jmp    11d1 <imcomm_simplify_sn+0x91>
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    1173 <imcomm_simplify_sn+0x33>
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):
<imcomm_simplify_sn>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    11a1 <imcomm_simplify_sn+0x61>
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    1183 <imcomm_simplify_sn+0x43>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11a4 <imcomm_simplify_sn+0x64>
movzbl (%r12,%rbx,1),%eax
cmp    $0x20,%al
je     1170 <imcomm_simplify_sn+0x30>
movsbl %al,%edi
call   1040 <tolower@plt>
movslq %r15d,%r15
mov    %al,(%r14,%r15,1)
add    $0x1,%r15d
jmp    1170 <imcomm_simplify_sn+0x30>
xor    %r15d,%r15d
lea    0x1(%r15),%esi
mov    %r14,%rdi
call   1060 <realloc@plt>
movslq %r15d,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @imcomm_simplify_sn(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i8* @malloc(i64 %3)
%5 = trunc i64 %2 to i32
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %25
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 i64 @strlen(i8* dereferenceable(1) %0)
%22 = shl i64 %21, 32
%23 = ashr exact i64 %22, 32
%24 = icmp slt i64 %20, %23
br i1 %24, label %7, label %25
25: ; preds = %18, %1
%26 = phi i32 [ 0, %1 ], [ %19, %18 ]
%27 = add nsw i32 %26, 1
%28 = tail call i8* @realloc(i8* %4, i32 %27)
%29 = sext i32 %26 to i64
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8 0, i8* %30
ret i8* %28
}