void trim_trailing_spaces(s) char *s;
{
  char *p;
  for (p = s; *p; ++p)
    continue;
  while (p > s && isspace(*--p))
    continue;
  if (p > s)
    ++p;
  *p = '\0';
}


x86 assembly (clang, -O0):
<trim_trailing_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1147 <trim_trailing_spaces+0x37>
jmp    1136 <trim_trailing_spaces+0x26>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <trim_trailing_spaces+0x14>
jmp    114c <trim_trailing_spaces+0x3c>
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x11(%rbp)
jbe    1180 <trim_trailing_spaces+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movsbl -0x1(%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1190 <trim_trailing_spaces+0x80>
jmp    1195 <trim_trailing_spaces+0x85>
jmp    114c <trim_trailing_spaces+0x3c>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    11af <trim_trailing_spaces+0x9f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_trailing_spaces>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    -0x1(%rdi),%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1120 <trim_trailing_spaces+0x10>
jmp    1141 <trim_trailing_spaces+0x31>
nopl   0x0(%rax)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1030 <isspace@plt>
test   %eax,%eax
je     1146 <trim_trailing_spaces+0x36>
cmp    %r14,%rbx
ja     1130 <trim_trailing_spaces+0x20>
cmp    %rbx,%r14
adc    $0x0,%rbx
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @trim_trailing_spaces(i8* %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, %10
%8 = phi i8* [ %11, %10 ], [ %3, %2 ]
%9 = icmp ugt i8* %8, %0
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %8, i64 -1
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = tail call i32 @isspace(i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %7
16: ; preds = %7, %10
%17 = phi i8* [ %11, %10 ], [ %8, %7 ]
%18 = icmp ugt i8* %17, %0
%19 = zext i1 %18 to i64
%20 = getelementptr i8, i8* %17, i64 %19
store i8 0, i8* %20
ret void
}