void skip_trailing_space(str) char *str;
{
  register char *cp;
  cp = str;
  while (*cp)
    ++cp;
  --cp;
  while (cp >= str && isspace(*cp))
    --cp;
  cp[1] = '\0';
}


x86 assembly (clang, -O0):
<skip_trailing_space>:
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     1142 <skip_trailing_space+0x32>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <skip_trailing_space+0x14>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x11(%rbp)
jb     1176 <skip_trailing_space+0x66>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1186 <skip_trailing_space+0x76>
jmp    1197 <skip_trailing_space+0x87>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    114e <skip_trailing_space+0x3e>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip_trailing_space>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    -0x2(%rdi),%rcx
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x2(%rcx)
lea    0x1(%rcx),%rcx
jne    1120 <skip_trailing_space+0x10>
jmp    1140 <skip_trailing_space+0x30>
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1030 <isspace@plt>
lea    -0x1(%rbx),%rcx
test   %eax,%eax
je     1148 <skip_trailing_space+0x38>
mov    %rcx,%rbx
cmp    %r14,%rcx
jae    1130 <skip_trailing_space+0x20>
movb   $0x0,0x1(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @skip_trailing_space(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 = %9, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %3
br label %5
12: ; preds = %5
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 -1
store i8* %14, i8** %3
br label %15
15: ; preds = %27, %12
%16 = load i8*, i8** %3
%17 = load i8*, i8** %2
%18 = icmp uge i8* %16, %17
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i8*, 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 = %19, %15
%26 = phi i1 [ false, %15 ], [ %24, %19 ]
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %3
br label %15
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8 0, i8* %32
ret void
}

LLVM IR (-O2):
define void @skip_trailing_space(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, %11
%8 = phi i8* [ %9, %11 ], [ %3, %2 ]
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = icmp ult i8* %9, %0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = load i8, i8* %9
%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, %11
store i8 0, i8* %8
ret void
}