#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 strlen(char *);
char *untrim(char *str) {
  unsigned int i;
  char *nstr = (char *)malloc((strlen(str) * 2) + 2);
  nstr[0] = '\0';
  for (i = 0; i < (strlen(str)); i++) {
    nstr[i * 2] = ' ';
    nstr[(i * 2) + 1] = str[i];
  }
  nstr[strlen(str) * 2] = ' ';
  nstr[(strlen(str) * 2) + 1] = '\0';
  return nstr;
}


x86 assembly (clang, -O0):
<untrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jae    11aa <untrim+0x8a>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x20,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1154 <untrim+0x34>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
shl    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<untrim>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     118d <untrim+0x6d>
mov    $0x1,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x1(%r12),%eax
movb   $0x20,(%r15,%rax,1)
movzbl (%r14,%rbx,1),%eax
mov    %r12d,%ecx
mov    %al,(%r15,%rcx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
add    $0x2,%r12d
cmp    %rax,%rbx
jb     1160 <untrim+0x40>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x20,(%r15,%rax,2)
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %eax,%eax
cltq
movb   $0x0,0x1(%r15,%rax,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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