#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__ calloc(size_t, int);
int /*<<< orphan*/ isspace(unsigned char);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
size_t strlen(char const *);
unsigned char *die_spaces_die(unsigned char *in_str) {
  size_t in_str_len;
  unsigned char *ret_str;
  in_str_len = strlen((const char *)in_str);
  ret_str = (unsigned char *)calloc(in_str_len + 1, sizeof(char));
  if (!(ret_str)) {
    perror(NULL);
    return NULL;
  };
  int i, j = 0;
  for (i = 0; i < in_str_len; i++) {
    if (!isspace(in_str[i]))
      ret_str[j++] = in_str[i];
  }
  ret_str[j] = '\0';
  return ret_str;
}


x86 assembly (clang, -O0):
<die_spaces_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <die_spaces_die+0x50>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    120d <die_spaces_die+0xcd>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11f9 <die_spaces_die+0xb9>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    11e6 <die_spaces_die+0xa6>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x28(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11eb <die_spaces_die+0xab>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119e <die_spaces_die+0x5e>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<die_spaces_die>:
push   %rbp
push   %r15
push   %r14
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>
test   %rax,%rax
je     11be <die_spaces_die+0x7e>
mov    %rax,%r14
test   %r15,%r15
je     11a8 <die_spaces_die+0x68>
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1189 <die_spaces_die+0x49>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%r15
je     11aa <die_spaces_die+0x6a>
movzbl (%r12,%rbx,1),%edi
call   1040 <isspace@plt>
test   %eax,%eax
jne    1180 <die_spaces_die+0x40>
movzbl (%r12,%rbx,1),%eax
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%r14,%rcx,1)
jmp    1180 <die_spaces_die+0x40>
xor    %ebp,%ebp
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
xor    %edi,%edi
call   1060 <perror@plt>
jmp    11b2 <die_spaces_die+0x72>

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

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