#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*/);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
scalar_t__ xmalloc(int);
char *xstrdup(char *);
char *strip_white_spaces(const char *str) {
  char *clean;
  int n;
  assert(str != NULL);
  n = strlen(str);
  while (n > 0 && ((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 = xstrdup("");
  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   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jle    11c8 <strip_white_spaces+0x78>
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,-0x16(%rbp)
je     11c2 <strip_white_spaces+0x72>
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,-0x16(%rbp)
mov    -0x16(%rbp),%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11d8 <strip_white_spaces+0x88>
jmp    11e6 <strip_white_spaces+0x96>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    117a <strip_white_spaces+0x2a>
jmp    11eb <strip_white_spaces+0x9b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x17(%rbp)
je     122b <strip_white_spaces+0xdb>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x18(%rbp)
je     1225 <strip_white_spaces+0xd5>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x18(%rbp)
mov    -0x18(%rbp),%al
mov    %al,-0x17(%rbp)
mov    -0x17(%rbp),%al
test   $0x1,%al
jne    123b <strip_white_spaces+0xeb>
jmp    1255 <strip_white_spaces+0x105>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11eb <strip_white_spaces+0x9b>
cmpl   $0x0,-0x14(%rbp)
jle    1297 <strip_white_spaces+0x147>
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    12a7 <strip_white_spaces+0x157>
lea    0xd62(%rip),%rdi
call   1060 <xstrdup@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   1070 <assert@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    11b7 <strip_white_spaces+0x67>
mov    %ebx,%ebx
jmp    118d <strip_white_spaces+0x3d>
nopl   0x0(%rax,%rax,1)
lea    0x1(%rax),%rcx
mov    %rax,%rbx
cmp    $0x1,%rcx
jbe    11a4 <strip_white_spaces+0x54>
lea    -0x1(%rbx),%rax
mov    %eax,%ecx
movzbl (%r14,%rcx,1),%ecx
cmp    $0x20,%cl
je     1180 <strip_white_spaces+0x30>
cmp    $0x9,%cl
je     1180 <strip_white_spaces+0x30>
jmp    11b7 <strip_white_spaces+0x67>
xor    %ebx,%ebx
jmp    11b7 <strip_white_spaces+0x67>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
add    $0xffffffff,%ebx
movzbl (%r14),%eax
cmp    $0x20,%al
je     11b0 <strip_white_spaces+0x60>
cmp    $0x9,%al
je     11b0 <strip_white_spaces+0x60>
test   %ebx,%ebx
jle    11ef <strip_white_spaces+0x9f>
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    0xe0a(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <xstrdup@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 = %36, %1
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %34
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 32
br i1 %22, label %32, label %23
23: ; preds = %14
%24 = load i8*, i8** %2
%25 = load i32, i32* %4
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 9
br label %32
32: ; preds = %23, %14
%33 = phi i1 [ true, %14 ], [ %31, %23 ]
br label %34
34: ; preds = %32, %11
%35 = phi i1 [ false, %11 ], [ %33, %32 ]
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = load i32, i32* %4
%38 = add nsw i32 %37, -1
store i32 %38, i32* %4
br label %11
39: ; preds = %34
br label %40
40: ; preds = %59, %39
%41 = load i8*, i8** %2
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %57
45: ; preds = %40
%46 = load i8*, i8** %2
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 32
br i1 %49, label %55, label %50
50: ; preds = %45
%51 = load i8*, i8** %2
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 9
br label %55
55: ; preds = %50, %45
%56 = phi i1 [ true, %45 ], [ %54, %50 ]
br label %57
57: ; preds = %55, %40
%58 = phi i1 [ false, %40 ], [ %56, %55 ]
br i1 %58, label %59, label %64
59: ; preds = %57
%60 = load i8*, i8** %2
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %2
%62 = load i32, i32* %4
%63 = add nsw i32 %62, -1
store i32 %63, i32* %4
br label %40
64: ; preds = %57
%65 = load i32, i32* %4
%66 = icmp sgt i32 %65, 0
br i1 %66, label %67, label %83
67: ; preds = %64
%68 = load i32, i32* %4
%69 = add nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = mul i64 %70, 1
%72 = trunc i64 %71 to i32
%73 = call i64 @xmalloc(i32 %72)
%74 = inttoptr i64 %73 to i8*
store i8* %74, i8** %3
%75 = load i8*, i8** %3
%76 = load i8*, i8** %2
%77 = load i32, i32* %4
%78 = call i32 @strncpy(i8* %75, i8* %76, i32 %77)
%79 = load i8*, i8** %3
%80 = load i32, i32* %4
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %79, i64 %81
store i8 0, i8* %82
br label %85
83: ; preds = %64
%84 = call i8* @xstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %84, i8** %3
br label %85
85: ; preds = %83, %67
%86 = load i8*, i8** %3
ret i8* %86
}

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 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %1
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %15
%10 = phi i64 [ %8, %7 ], [ %11, %15 ]
%11 = add nsw i64 %10, -1
%12 = and i64 %11, 4294967295
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %17 [
i8 32, label %15
i8 9, label %15
]
15: ; preds = %9, %9
%16 = icmp ugt i64 %10, 1
br i1 %16, label %9, label %19
17: ; preds = %9
%18 = trunc i64 %10 to i32
br label %19
19: ; preds = %15, %17, %1
%20 = phi i32 [ %5, %1 ], [ %18, %17 ], [ 0, %15 ]
br label %21
21: ; preds = %19, %25
%22 = phi i8* [ %26, %25 ], [ %0, %19 ]
%23 = phi i32 [ %27, %25 ], [ %20, %19 ]
%24 = load i8, i8* %22
switch i8 %24, label %28 [
i8 9, label %25
i8 32, label %25
]
25: ; preds = %21, %21
%26 = getelementptr inbounds i8, i8* %22, i64 1
%27 = add nsw i32 %23, -1
br label %21
28: ; preds = %21
%29 = icmp sgt i32 %23, 0
br i1 %29, label %30, label %37
30: ; preds = %28
%31 = add nuw nsw i32 %23, 1
%32 = tail call i64 @xmalloc(i32 %31)
%33 = inttoptr i64 %32 to i8*
%34 = tail call i32 @strncpy(i8* %33, i8* %22, i32 %23)
%35 = zext i32 %23 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
br label %39
37: ; preds = %28
%38 = tail call i8* @xstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %39
39: ; preds = %37, %30
%40 = phi i8* [ %33, %30 ], [ %38, %37 ]
ret i8* %40
}