void trim_spaces(char *str) {
  char *pstr = str;
  char c;
  while (*pstr)
    pstr++;
  while (1) {
    c = *(--pstr);
    if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
      *pstr = 0;
    else
      break;
  }
}


x86 assembly (clang, -O0):
<trim_spaces>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     112e <trim_spaces+0x2e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1110 <trim_spaces+0x10>
jmp    1133 <trim_spaces+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
mov    -0x1(%rax),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
je     117c <trim_spaces+0x7c>
movsbl -0x11(%rbp),%eax
cmp    $0x9,%eax
je     117c <trim_spaces+0x7c>
movsbl -0x11(%rbp),%eax
cmp    $0xd,%eax
je     117c <trim_spaces+0x7c>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    1188 <trim_spaces+0x88>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    118d <trim_spaces+0x8d>
jmp    1192 <trim_spaces+0x92>
jmp    1133 <trim_spaces+0x33>
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_spaces>:
add    $0xfffffffffffffffe,%rdi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x0,0x2(%rdi)
lea    0x1(%rdi),%rdi
jne    1110 <trim_spaces+0x10>
movabs $0x100002600,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rdi),%ecx
cmp    $0x20,%rcx
ja     1148 <trim_spaces+0x48>
bt     %rcx,%rax
jae    1148 <trim_spaces+0x48>
movb   $0x0,(%rdi)
add    $0xffffffffffffffff,%rdi
jmp    1130 <trim_spaces+0x30>
ret

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

LLVM IR (-O2):
define void @trim_spaces(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %6, %2 ]
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
%6 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %5, label %7, label %2
7: ; preds = %2, %11
%8 = phi i8* [ %9, %11 ], [ %3, %2 ]
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = load i8, i8* %9
switch i8 %10, label %12 [
i8 32, label %11
i8 13, label %11
i8 10, label %11
i8 9, label %11
]
11: ; preds = %7, %7, %7, %7
store i8 0, i8* %9
br label %7
12: ; preds = %7
ret void
}