#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(char);
void rtrim(char *s) {
  char *t = s;
  if (!s || !*s) {
    return;
  }
  while (*s) {
    s++;
  }
  s--;
  while ((s >= t) && isspace(*s)) {
    *s = 0;
    s--;
  }
}


x86 assembly (clang, -O0):
<rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     113c <rtrim+0x2c>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1141 <rtrim+0x31>
jmp    11c1 <rtrim+0xb1>
jmp    1146 <rtrim+0x36>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1164 <rtrim+0x54>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1146 <rtrim+0x36>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x11(%rbp)
jb     1199 <rtrim+0x89>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11a9 <rtrim+0x99>
jmp    11c1 <rtrim+0xb1>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1170 <rtrim+0x60>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1159 <rtrim+0x49>
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     1159 <rtrim+0x49>
lea    -0x1(%r14),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x0,0x2(%rbx)
lea    0x1(%rbx),%rbx
jne    1130 <rtrim+0x20>
jmp    1147 <rtrim+0x37>
nopl   0x0(%rax)
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jb     1159 <rtrim+0x49>
movsbl (%rbx),%edi
call   1030 <isspace@plt>
test   %rax,%rax
jne    1140 <rtrim+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
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
store i8* %4, i8** %3
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %7, %1
br label %38
12: ; preds = %7
br label %13
13: ; preds = %17, %12
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %2
br label %13
20: ; preds = %13
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i32 -1
store i8* %22, i8** %2
br label %23
23: ; preds = %34, %20
%24 = load i8*, i8** %2
%25 = load i8*, i8** %3
%26 = icmp uge i8* %24, %25
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i8*, i8** %2
%29 = load i8, i8* %28
%30 = call i64 @isspace(i8 signext %29)
%31 = icmp ne i64 %30, 0
br label %32
32: ; preds = %27, %23
%33 = phi i1 [ false, %23 ], [ %31, %27 ]
br i1 %33, label %34, label %38
34: ; preds = %32
%35 = load i8*, i8** %2
store i8 0, i8* %35
%36 = load i8*, i8** %2
%37 = getelementptr inbounds i8, i8* %36, i32 -1
store i8* %37, i8** %2
br label %23
38: ; preds = %11, %32
ret void
}

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