#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__ strchr(char *, char);
int strlen(char *);
char *rTrim(char *buf) {
  if (buf) {
    char *tp = buf + strlen(buf);
    while (tp >= buf && strchr("\n\r\t ", *tp))
      tp--;
    *(tp + 1) = 0;
  }
  return buf;
}


x86 assembly (clang, -O0):
<rTrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b1 <rTrim+0x91>
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
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jb     1188 <rTrim+0x68>
mov    -0x10(%rbp),%rax
lea    0xe8a(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1198 <rTrim+0x78>
jmp    11a9 <rTrim+0x89>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1158 <rTrim+0x38>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rTrim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
test   %rdi,%rdi
je     116d <rTrim+0x4d>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
lea    (%r15,%rax,1),%rbx
test   %eax,%eax
js     1169 <rTrim+0x49>
lea    0xeba(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
movsbl (%rbx),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1169 <rTrim+0x49>
add    $0xffffffffffffffff,%rbx
cmp    %r15,%rbx
jae    1150 <rTrim+0x30>
movb   $0x0,0x1(%rbx)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\0A\0D\09 \00"
define i8* @rTrim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %29
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8* %11, i8** %3
br label %12
12: ; preds = %23, %6
%13 = load i8*, i8** %3
%14 = load i8*, i8** %2
%15 = icmp uge i8* %13, %14
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = call i64 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %18)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %3
br label %12
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8 0, i8* %28
br label %29
29: ; preds = %26, %1
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@.str = [5 x i8] c"\0A\0D\09 \00"
define i8* @rTrim(i8* returned %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = icmp slt i32 %4, 0
br i1 %7, label %16, label %8
8: ; preds = %3, %13
%9 = phi i8* [ %14, %13 ], [ %6, %3 ]
%10 = load i8, i8* %9
%11 = tail call i64 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %9, i64 -1
%15 = icmp ult i8* %14, %0
br i1 %15, label %16, label %8
16: ; preds = %8, %13, %3
%17 = phi i8* [ %6, %3 ], [ %14, %13 ], [ %9, %8 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 0, i8* %18
br label %19
19: ; preds = %16, %1
ret i8* %0
}