#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*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strdown(char *);
scalar_t__ strlen(char *);
char *normalize(char *s) {
  static char buf[2048];
  char *t, *u;
  int x = 0;
  u = t = malloc(strlen(s) + 1);
  strcpy(t, s);
  strdown(t);
  while (*t) {
    if (*t != ' ') {
      buf[x] = *t;
      x++;
    }
    t++;
  }
  buf[x] = '\0';
  free(u);
  return buf;
}


x86 assembly (clang, -O0):
<normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1070 <strdown@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e1 <normalize+0x91>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     11d0 <normalize+0x80>
mov    -0x10(%rbp),%rax
mov    (%rax),%dl
movslq -0x1c(%rbp),%rcx
lea    0x2e9c(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1196 <normalize+0x46>
movslq -0x1c(%rbp),%rcx
lea    0x2e74(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0x2e60(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1070 <strdown@plt>
xor    %eax,%eax
lea    0x2edc(%rip),%rbx
mov    %r14,%rcx
jmp    1194 <normalize+0x44>
nopl   0x0(%rax)
add    $0x1,%rcx
movzbl (%rcx),%edx
cmp    $0x20,%dl
je     1190 <normalize+0x40>
cltq
test   %dl,%dl
je     11aa <normalize+0x5a>
mov    %dl,(%rax,%rbx,1)
add    $0x1,%eax
jmp    1190 <normalize+0x40>
movb   $0x0,(%rax,%rbx,1)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@normalize.buf = internal global [2048 x i8] zeroinitializer
define i8* @normalize(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%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 i8* %9, i8** %4
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = load i8*, i8** %3
%14 = call i32 @strdown(i8* %13)
br label %15
15: ; preds = %32, %1
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 32
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* @normalize.buf, i64 0, i64 %28
store i8 %26, i8* %29
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %24, %19
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
br label %15
35: ; preds = %15
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* @normalize.buf, i64 0, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %4
%40 = call i32 @free(i8* %39)
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @normalize.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@normalize.buf = internal global [2048 x i8] zeroinitializer
define i8* @normalize(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i8* @malloc(i64 %3)
%5 = tail call i32 @strcpy(i8* %4, i8* %0)
%6 = tail call i32 @strdown(i8* %4)
br label %7
7: ; preds = %15, %1
%8 = phi i8* [ %4, %1 ], [ %17, %15 ]
%9 = phi i32 [ 0, %1 ], [ %16, %15 ]
%10 = load i8, i8* %8
switch i8 %10, label %11 [
i8 0, label %18
i8 32, label %15
]
11: ; preds = %7
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* @normalize.buf, i64 0, i64 %12
store i8 %10, i8* %13
%14 = add nsw i32 %9, 1
br label %15
15: ; preds = %7, %11
%16 = phi i32 [ %14, %11 ], [ %9, %7 ]
%17 = getelementptr inbounds i8, i8* %8, i64 1
br label %7
18: ; preds = %7
%19 = sext i32 %9 to i64
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* @normalize.buf, i64 0, i64 %19
store i8 0, i8* %20
%21 = tail call i32 @free(i8* %4)
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @normalize.buf, i64 0, i64 0)
}