#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*/ isspace(char const);
scalar_t__ malloc(size_t);
size_t strlen(char const *);
char *convert(const char *str) {
  size_t len = strlen(str);
  char *ret = (char *)malloc(len + 1), *cur = ret;
  while (*str) {
    if (!isspace(*str)) {
      *cur++ = *str++;
    } else {
      ++str;
    }
  }
  *cur = 0;
  return ret;
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11bc <convert+0x8c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    11ab <convert+0x7b>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11b7 <convert+0x87>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1162 <convert+0x32>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    (%rbx),%al
test   %al,%al
je     1184 <convert+0x54>
add    $0x1,%rbx
mov    %r14,%r15
jmp    116b <convert+0x3b>
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1187 <convert+0x57>
movsbl %al,%edi
call   1040 <isspace@plt>
test   %eax,%eax
jne    1160 <convert+0x30>
movzbl -0x1(%rbx),%eax
mov    %al,(%r15)
add    $0x1,%r15
jmp    1160 <convert+0x30>
mov    %r14,%r15
movb   $0x0,(%r15)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @convert(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = add i64 %8, 1
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %4
%12 = load i8*, i8** %4
store i8* %12, i8** %5
br label %13
13: ; preds = %31, %1
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = call i32 @isspace(i8 signext %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %17
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %2
%25 = load i8, i8* %23
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
store i8 %25, i8* %26
br label %31
28: ; preds = %17
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %2
br label %31
31: ; preds = %28, %22
br label %13
32: ; preds = %13
%33 = load i8*, i8** %5
store i8 0, i8* %33
%34 = load i8*, i8** %4
ret i8* %34
}

LLVM IR (-O2):
define i8* @convert(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 1
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %4 to i8*
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %1, %17
%9 = phi i8 [ %20, %17 ], [ %6, %1 ]
%10 = phi i8* [ %18, %17 ], [ %5, %1 ]
%11 = phi i8* [ %19, %17 ], [ %0, %1 ]
%12 = tail call i32 @isspace(i8 signext %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i8, i8* %11
%16 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %15, i8* %10
br label %17
17: ; preds = %8, %14
%18 = phi i8* [ %16, %14 ], [ %10, %8 ]
%19 = getelementptr inbounds i8, i8* %11, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %8
22: ; preds = %17, %1
%23 = phi i8* [ %5, %1 ], [ %18, %17 ]
store i8 0, i8* %23
ret i8* %5
}