#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ isspace(char);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
void stripws(char *target) {
  size_t len;
  char *wrk, *cpf, *cpt;
  len = strlen(target);
  wrk = malloc(len + 1);
  if (!wrk) {
    perror("malloc()");
    exit(EXIT_FAILURE);
  }
  cpf = target;
  cpt = wrk;
  while (*cpf) {
    if (isspace(*cpf) == 0) {
      *cpt = *cpf;
      cpt++;
    }
    cpf++;
  }
  *cpt = '\0';
  strcpy(target, wrk);
  free(wrk);
}


x86 assembly (clang, -O0):
<stripws>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bf <stripws+0x4f>
lea    0xe54(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     121b <stripws+0xab>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
jne    120a <stripws+0x9a>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11cf <stripws+0x5f>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripws>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11f9 <stripws+0x89>
mov    %rax,%r15
mov    (%r14),%al
mov    %r15,%r12
test   %al,%al
je     11d6 <stripws+0x66>
lea    0x1(%r14),%rbx
mov    %r15,%r12
jmp    11bb <stripws+0x4b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11d6 <stripws+0x66>
movsbl %al,%edi
call   1060 <isspace@plt>
test   %rax,%rax
jne    11b0 <stripws+0x40>
movzbl -0x1(%rbx),%eax
mov    %al,(%r12)
add    $0x1,%r12
jmp    11b0 <stripws+0x40>
movb   $0x0,(%r12)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>
lea    0xe00(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

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

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