#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__ realloc(char *, scalar_t__);
scalar_t__ strlen(char *);
char *trim(char *phrase) {
  char *old = phrase;
  char *new = phrase;
  while (*old == ' ') {
    *(new ++) = *(old++);
  }
  *new = 0;
  return (char *)realloc(phrase, strlen(phrase) + 1);
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1173 <trim+0x53>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    113c <trim+0x1c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1040 <realloc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %rbx
mov    %rdi,%rbx
cmpb   $0x20,(%rdi)
mov    %rdi,%rax
jne    1140 <trim+0x20>
mov    %rbx,%rcx
nop
lea    0x1(%rcx),%rax
movb   $0x20,(%rcx)
cmpb   $0x20,0x1(%rcx)
mov    %rax,%rcx
je     1130 <trim+0x10>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <realloc@plt>

LLVM IR (-O0):
define i8* @trim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
%6 = load i8*, i8** %2
store i8* %6, i8** %4
br label %7
7: ; preds = %12, %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 32
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %3
%15 = load i8, i8* %13
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %4
store i8 %15, i8* %16
br label %7
18: ; preds = %7
%19 = load i8*, i8** %4
store i8 0, i8* %19
%20 = load i8*, i8** %2
%21 = load i8*, i8** %2
%22 = call i64 @strlen(i8* %21)
%23 = add nsw i64 %22, 1
%24 = call i64 @realloc(i8* %20, i64 %23)
%25 = inttoptr i64 %24 to i8*
ret i8* %25
}

LLVM IR (-O2):
define i8* @trim(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 32
br i1 %3, label %4, label %9
4: ; preds = %1, %4
%5 = phi i8* [ %6, %4 ], [ %0, %1 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8 32, i8* %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 32
br i1 %8, label %4, label %9
9: ; preds = %4, %1
%10 = phi i8* [ %0, %1 ], [ %6, %4 ]
store i8 0, i8* %10
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = add nsw i64 %11, 1
%13 = tail call i64 @realloc(i8* %0, i64 %12)
%14 = inttoptr i64 %13 to i8*
ret i8* %14
}