#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__ isspace(char const);
int strlen(char *);
char *talloc_strdup(void *, char const *);
char *String_StripSpaces(void *talloc_context, const char *s) {
  char *r = 0;
  if (s) {
    while (isspace(*s))
      s++;
    r = talloc_strdup(talloc_context, s);
    if (*r != '\0') {
      char *p = r + strlen(r) - 1;
      while (isspace(*p))
        *p-- = '\0';
    }
  }
  return r;
}


x86 assembly (clang, -O0):
<String_StripSpaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11fc <String_StripSpaces+0xcc>
jmp    1158 <String_StripSpaces+0x28>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     117f <String_StripSpaces+0x4f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1158 <String_StripSpaces+0x28>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <talloc_strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f7 <String_StripSpaces+0xc7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11f2 <String_StripSpaces+0xc2>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
jmp    11c5 <String_StripSpaces+0x95>
jmp    11f7 <String_StripSpaces+0xc7>
jmp    11fc <String_StripSpaces+0xcc>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<String_StripSpaces>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     11b7 <String_StripSpaces+0x87>
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1150 <String_StripSpaces+0x20>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <talloc_strdup@plt>
mov    %rax,%r14
cmpb   $0x0,(%rax)
je     11ba <String_StripSpaces+0x8a>
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
movsbl -0x1(%r14,%rbx,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     11ba <String_StripSpaces+0x8a>
add    %r14,%rbx
add    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    11a0 <String_StripSpaces+0x70>
jmp    11ba <String_StripSpaces+0x8a>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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