#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 *calloc(size_t, int);
int /*<<< orphan*/ isspace(char const);
int /*<<< orphan*/ perror(char *);
size_t strlen(char const *);
char *strip_spaces(const char *in) {
  char *out;
  size_t t, l, i;
  t = strlen(in);
  out = calloc(t + 1, sizeof(char));
  if (!out) {
    perror("calloc");
    return NULL;
  }
  for (i = 0, l = 0; i < t; ++i) {
    if (!isspace(in[i]))
      out[l++] = in[i];
  }
  return out;
}


x86 assembly (clang, -O0):
<strip_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1193 <strip_spaces+0x53>
lea    0xe7f(%rip),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    120a <strip_spaces+0xca>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1202 <strip_spaces+0xc2>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    11ec <strip_spaces+0xac>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    11f1 <strip_spaces+0xb1>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11a3 <strip_spaces+0x63>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_spaces>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     11a6 <strip_spaces+0x66>
test   %r15,%r15
je     11b2 <strip_spaces+0x72>
xor    %ebx,%ebx
xor    %r13d,%r13d
jmp    1189 <strip_spaces+0x49>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     11b2 <strip_spaces+0x72>
movsbl (%r12,%rbx,1),%edi
call   1040 <isspace@plt>
test   %eax,%eax
jne    1180 <strip_spaces+0x40>
movzbl (%r12,%rbx,1),%eax
mov    %al,(%r14,%r13,1)
add    $0x1,%r13
jmp    1180 <strip_spaces+0x40>
lea    0xe53(%rip),%rdi
call   1060 <perror@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"calloc\00"
define i8* @strip_spaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = add i64 %10, 1
%12 = call i8* @calloc(i64 %11, i32 1)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %44
17: ; preds = %1
store i64 0, i64* %7
store i64 0, i64* %6
br label %18
18: ; preds = %39, %17
%19 = load i64, i64* %7
%20 = load i64, i64* %5
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %42
22: ; preds = %18
%23 = load i8*, i8** %3
%24 = load i64, i64* %7
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @isspace(i8 signext %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %38, label %29
29: ; preds = %22
%30 = load i8*, i8** %3
%31 = load i64, i64* %7
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8, i8* %32
%34 = load i8*, i8** %4
%35 = load i64, i64* %6
%36 = add i64 %35, 1
store i64 %36, i64* %6
%37 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 %33, i8* %37
br label %38
38: ; preds = %29, %22
br label %39
39: ; preds = %38
%40 = load i64, i64* %7
%41 = add i64 %40, 1
store i64 %41, i64* %7
br label %18
42: ; preds = %18
%43 = load i8*, i8** %4
store i8* %43, i8** %2
br label %44
44: ; preds = %42, %15
%45 = load i8*, i8** %2
ret i8* %45
}

LLVM IR (-O2):
@.str = [7 x i8] c"calloc\00"
define i8* @strip_spaces(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 1
%4 = tail call i8* @calloc(i64 %3, i32 1)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = icmp eq i64 %2, 0
br i1 %7, label %25, label %10
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %25
10: ; preds = %6, %21
%11 = phi i64 [ %23, %21 ], [ 0, %6 ]
%12 = phi i64 [ %22, %21 ], [ 0, %6 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %11
%14 = load i8, i8* %13
%15 = tail call i32 @isspace(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i8, i8* %13
%19 = add i64 %12, 1
%20 = getelementptr inbounds i8, i8* %4, i64 %12
store i8 %18, i8* %20
br label %21
21: ; preds = %10, %17
%22 = phi i64 [ %12, %10 ], [ %19, %17 ]
%23 = add nuw i64 %11, 1
%24 = icmp eq i64 %23, %2
br i1 %24, label %25, label %10
25: ; preds = %21, %6, %8
ret i8* %4
}