#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 strlen(char *);
char *strip(char *s) {
  char *e;
  while (*s == ' ')
    ++s;
  if (*s)
    for (e = s + strlen(s); *--e == ' '; *e = '\0')
      ;
  return s;
}


x86 assembly (clang, -O0):
<strip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    113d <strip+0x2d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    111c <strip+0xc>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     119d <strip+0x8d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0x20,%eax
jne    1198 <strip+0x88>
jmp    118c <strip+0x7c>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    116b <strip+0x5b>
jmp    119d <strip+0x8d>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip>:
push   %rbx
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx),%eax
cmp    $0x20,%al
jne    112d <strip+0x1d>
add    $0x1,%rbx
jmp    1120 <strip+0x10>
test   %al,%al
je     1160 <strip+0x50>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x20,-0x1(%rbx,%rax,1)
jne    1160 <strip+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,-0x1(%rbx,%rax,1)
cmpb   $0x20,-0x2(%rbx,%rax,1)
lea    -0x1(%rax),%rax
je     1150 <strip+0x40>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @strip(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
br label %4
4: ; preds = %9, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 32
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %2
br label %4
12: ; preds = %4
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = load i8*, i8** %2
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8* %21, i8** %3
br label %22
22: ; preds = %29, %16
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 32
br i1 %27, label %28, label %31
28: ; preds = %22
br label %29
29: ; preds = %28
%30 = load i8*, i8** %3
store i8 0, i8* %30
br label %22
31: ; preds = %22
br label %32
32: ; preds = %31, %12
%33 = load i8*, i8** %2
ret i8* %33
}

LLVM IR (-O2):
define i8* @strip(i8* %0) {
br label %2
2: ; preds = %5, %1
%3 = phi i8* [ %0, %1 ], [ %6, %5 ]
%4 = load i8, i8* %3
switch i8 %4, label %7 [
i8 32, label %5
i8 0, label %19
]
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %3)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %3, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 32
br i1 %13, label %14, label %19
14: ; preds = %7, %14
%15 = phi i8* [ %16, %14 ], [ %11, %7 ]
store i8 0, i8* %15
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 32
br i1 %18, label %14, label %19
19: ; preds = %2, %14, %7
ret i8* %3
}