#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 */
scalar_t__ isspace(int);
int strlen(char *);
char *Str_TrimRight(char *s) {
  char *p = s + strlen(s);
  while ((--p) >= s && isspace((int)*p))
    *(++p) = '\0';
  return s;
}


x86 assembly (clang, -O0):
<Str_TrimRight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
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),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jb     117e <Str_TrimRight+0x5e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    118e <Str_TrimRight+0x6e>
jmp    11a6 <Str_TrimRight+0x86>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,0x1(%rax)
jmp    114d <Str_TrimRight+0x2d>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Str_TrimRight>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
movslq %eax,%rbx
lea    (%r14,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
cmp    %r14,%rax
jb     1161 <Str_TrimRight+0x41>
movsbl (%rax),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1161 <Str_TrimRight+0x41>
add    %r14,%rbx
nopl   0x0(%rax)
movb   $0x0,(%rbx)
movsbl -0x1(%rbx),%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1150 <Str_TrimRight+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @Str_TrimRight(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
store i8* %8, i8** %3
br label %9
9: ; preds = %22, %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i32 -1
store i8* %11, i8** %3
%12 = load i8*, i8** %2
%13 = icmp uge i8* %11, %12
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = call i64 @isspace(i32 %17)
%19 = icmp ne i64 %18, 0
br label %20
20: ; preds = %14, %9
%21 = phi i1 [ false, %9 ], [ %19, %14 ]
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
store i8 0, i8* %24
br label %9
25: ; preds = %20
%26 = load i8*, i8** %2
ret i8* %26
}

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