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


x86 assembly (clang, -O0):
<rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114c <rtrim+0x2c>
jmp    11b4 <rtrim+0x94>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
mov    %al,-0x19(%rbp)
jb     118b <rtrim+0x6b>
mov    -0x18(%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    119b <rtrim+0x7b>
jmp    11ac <rtrim+0x8c>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    115f <rtrim+0x3f>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    (%rdi),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1171 <rtrim+0x51>
lea    (%r14,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jae    1150 <rtrim+0x30>
add    %rax,%r14
jmp    116d <rtrim+0x4d>
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1166 <rtrim+0x46>
add    $0xffffffffffffffff,%rbx
cmp    (%r15),%rbx
jae    1150 <rtrim+0x30>
add    $0x1,%rbx
mov    %rbx,%r14
movb   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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