#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*/ assert(int /*<<< orphan*/);
char *strdup(char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
scalar_t__ xmalloc(int);
char *strip_white_spaces(const char *str) {
  char *clean;
  int n;
  assert(str != NULL);
  n = strlen(str);
  while (((str[n - 1]) == ' ' || (str[n - 1]) == '\t'))
    n--;
  while (*str && ((*str) == ' ' || (*str) == '\t')) {
    str++;
    n--;
  }
  if (n > 0) {
    clean = (char *)xmalloc((n + 1) * sizeof(char));
    strncpy(clean, str, n);
    clean[n] = 0;
  } else
    clean = strdup("");
  return clean;
}


x86 assembly (clang, -O0):
<strip_white_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x15(%rbp)
je     11b3 <strip_white_spaces+0x63>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11c3 <strip_white_spaces+0x73>
jmp    11d1 <strip_white_spaces+0x81>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    117a <strip_white_spaces+0x2a>
jmp    11d6 <strip_white_spaces+0x86>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x16(%rbp)
je     1216 <strip_white_spaces+0xc6>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x17(%rbp)
je     1210 <strip_white_spaces+0xc0>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x17(%rbp)
mov    -0x17(%rbp),%al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
test   $0x1,%al
jne    1226 <strip_white_spaces+0xd6>
jmp    1240 <strip_white_spaces+0xf0>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11d6 <strip_white_spaces+0x86>
cmpl   $0x0,-0x14(%rbp)
jle    1282 <strip_white_spaces+0x132>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1292 <strip_white_spaces+0x142>
lea    0xd77(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_white_spaces>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1060 <assert@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
cltq
add    %r14,%rax
add    $0xffffffffffffffff,%rax
jmp    1187 <strip_white_spaces+0x37>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%rax
movzbl (%rax),%ecx
cmp    $0x20,%cl
je     1180 <strip_white_spaces+0x30>
cmp    $0x9,%cl
je     1180 <strip_white_spaces+0x30>
jmp    11a7 <strip_white_spaces+0x57>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14
add    $0xffffffff,%ebx
movzbl (%r14),%eax
cmp    $0x20,%al
je     11a0 <strip_white_spaces+0x50>
cmp    $0x9,%al
je     11a0 <strip_white_spaces+0x50>
test   %ebx,%ebx
jle    11df <strip_white_spaces+0x8f>
lea    0x1(%rbx),%edi
call   1050 <xmalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe1a(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <strdup@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @strip_white_spaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %4
br label %11
11: ; preds = %31, %1
%12 = load i8*, i8** %2
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %29, label %20
20: ; preds = %11
%21 = load i8*, i8** %2
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 9
br label %29
29: ; preds = %20, %11
%30 = phi i1 [ true, %11 ], [ %28, %20 ]
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = load i32, i32* %4
%33 = add nsw i32 %32, -1
store i32 %33, i32* %4
br label %11
34: ; preds = %29
br label %35
35: ; preds = %54, %34
%36 = load i8*, i8** %2
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %52
40: ; preds = %35
%41 = load i8*, i8** %2
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 32
br i1 %44, label %50, label %45
45: ; preds = %40
%46 = load i8*, i8** %2
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 9
br label %50
50: ; preds = %45, %40
%51 = phi i1 [ true, %40 ], [ %49, %45 ]
br label %52
52: ; preds = %50, %35
%53 = phi i1 [ false, %35 ], [ %51, %50 ]
br i1 %53, label %54, label %59
54: ; preds = %52
%55 = load i8*, i8** %2
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %2
%57 = load i32, i32* %4
%58 = add nsw i32 %57, -1
store i32 %58, i32* %4
br label %35
59: ; preds = %52
%60 = load i32, i32* %4
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %78
62: ; preds = %59
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = mul i64 %65, 1
%67 = trunc i64 %66 to i32
%68 = call i64 @xmalloc(i32 %67)
%69 = inttoptr i64 %68 to i8*
store i8* %69, i8** %3
%70 = load i8*, i8** %3
%71 = load i8*, i8** %2
%72 = load i32, i32* %4
%73 = call i32 @strncpy(i8* %70, i8* %71, i32 %72)
%74 = load i8*, i8** %3
%75 = load i32, i32* %4
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
store i8 0, i8* %77
br label %80
78: ; preds = %59
%79 = call i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %79, i8** %3
br label %80
80: ; preds = %78, %62
%81 = load i8*, i8** %3
ret i8* %81
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @strip_white_spaces(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = sext i32 %5 to i64
br label %7
7: ; preds = %12, %1
%8 = phi i64 [ %6, %1 ], [ %9, %12 ]
%9 = add i64 %8, -1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
switch i8 %11, label %13 [
i8 32, label %12
i8 9, label %12
]
12: ; preds = %7, %7
br label %7
13: ; preds = %7
%14 = trunc i64 %8 to i32
br label %15
15: ; preds = %13, %19
%16 = phi i8* [ %20, %19 ], [ %0, %13 ]
%17 = phi i32 [ %21, %19 ], [ %14, %13 ]
%18 = load i8, i8* %16
switch i8 %18, label %22 [
i8 9, label %19
i8 32, label %19
]
19: ; preds = %15, %15
%20 = getelementptr inbounds i8, i8* %16, i64 1
%21 = add nsw i32 %17, -1
br label %15
22: ; preds = %15
%23 = icmp sgt i32 %17, 0
br i1 %23, label %24, label %31
24: ; preds = %22
%25 = add nuw nsw i32 %17, 1
%26 = tail call i64 @xmalloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
%28 = tail call i32 @strncpy(i8* %27, i8* %16, i32 %17)
%29 = zext i32 %17 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
br label %33
31: ; preds = %22
%32 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %24
%34 = phi i8* [ %27, %24 ], [ %32, %31 ]
ret i8* %34
}