char *stripsp(cp)
register char *cp;
{
  register char *ep, *lastp;
  while (*cp == ' ')
    ++cp;
  if (*cp) {
    ep = cp + strlen(cp);
    while (*--ep == ' ')
      ;
    *++ep = 0;
  }
  return cp;
}


x86 assembly (clang, -O0):
<stripsp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    113d <stripsp+0x2d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    111c <stripsp+0xc>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     119d <stripsp+0x8d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
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    118a <stripsp+0x7a>
jmp    1169 <stripsp+0x59>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
define i8* @stripsp(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 %16
]
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
7: ; preds = %2
%8 = tail call i64 @strlen(i8* %3)
%9 = getelementptr inbounds i8, i8* %3, i64 %8
br label %10
10: ; preds = %10, %7
%11 = phi i8* [ %9, %7 ], [ %12, %10 ]
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 32
br i1 %14, label %10, label %15
15: ; preds = %10
store i8 0, i8* %11
br label %16
16: ; preds = %2, %15
ret i8* %3
}