#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 */
int strlen(char *);
void rtrim(char *s) {
  char *p;
  p = s + (strlen(s) - 1);
  while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') {
    --p;
  }
  ++p;
  *p = 0;
}


x86 assembly (clang, -O0):
<rtrim>:
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
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x19(%rbp)
je     118f <rtrim+0x7f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x19(%rbp)
je     118f <rtrim+0x7f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     118f <rtrim+0x7f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119f <rtrim+0x8f>
jmp    11b0 <rtrim+0xa0>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1140 <rtrim+0x30>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
movabs $0x100002600,%rcx
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rax),%edx
cmp    $0x20,%rdx
ja     1146 <rtrim+0x36>
bt     %rdx,%rcx
jae    1146 <rtrim+0x36>
add    $0xffffffffffffffff,%rax
jmp    1130 <rtrim+0x20>
movb   $0x0,(%rax)
pop    %rbx
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** %2
%6 = call i32 @strlen(i8* %5)
%7 = sub nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %4, i64 %8
store i8* %9, i8** %3
br label %10
10: ; preds = %32, %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 32
br i1 %14, label %30, label %15
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 9
br i1 %19, label %30, label %20
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = load i8*, i8** %3
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 13
br label %30
30: ; preds = %25, %20, %15, %10
%31 = phi i1 [ true, %20 ], [ true, %15 ], [ true, %10 ], [ %29, %25 ]
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 -1
store i8* %34, i8** %3
br label %10
35: ; preds = %30
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
%38 = load i8*, i8** %3
store i8 0, i8* %38
ret void
}

LLVM IR (-O2):
define void @rtrim(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
br label %6
6: ; preds = %9, %1
%7 = phi i8* [ %5, %1 ], [ %10, %9 ]
%8 = load i8, i8* %7
switch i8 %8, label %11 [
i8 32, label %9
i8 9, label %9
i8 10, label %9
i8 13, label %9
]
9: ; preds = %6, %6, %6, %6
%10 = getelementptr inbounds i8, i8* %7, i64 -1
br label %6
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 0, i8* %12
ret void
}