#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 *);
void rtrim(char *string) {
  if (!*string) {
    return;
  }
  char *end = string + strlen(string) - 1;
  while (isspace((int)*end) && end >= string) {
    *end = '\0';
    --end;
  }
}


x86 assembly (clang, -O0):
<rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    113e <rtrim+0x1e>
jmp    11b7 <rtrim+0x97>
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
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     118f <rtrim+0x6f>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
setae  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119f <rtrim+0x7f>
jmp    11b7 <rtrim+0x97>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1163 <rtrim+0x43>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
push   %r15
push   %r14
push   %rbx
cmpb   $0x0,(%rdi)
je     117a <rtrim+0x5a>
mov    %rdi,%r14
call   1030 <strlen@plt>
movslq %eax,%rbx
lea    (%r14,%rbx,1),%r15
add    $0xffffffffffffffff,%r15
movsbl -0x1(%r14,%rbx,1),%edi
call   1040 <isspace@plt>
cmp    %r14,%r15
jb     117a <rtrim+0x5a>
test   %rax,%rax
je     117a <rtrim+0x5a>
add    %r14,%rbx
add    $0xfffffffffffffffe,%rbx
nopl   0x0(%rax)
movb   $0x0,0x1(%rbx)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
cmp    %r14,%rbx
jb     117a <rtrim+0x5a>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1160 <rtrim+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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