#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 */
unsigned long strlen(char *);
void TrimRight(char *cpString) {
  unsigned long ulStrLen = 0;
  if ('\0' == *cpString) {
    return;
  }
  ulStrLen = strlen(cpString);
  while (' ' == cpString[ulStrLen - 1] || '\t' == cpString[ulStrLen - 1] ||
         '\r' == cpString[ulStrLen - 1] || '\n' == cpString[ulStrLen - 1]) {
    ulStrLen--;
  }
  cpString[ulStrLen] = '\0';
}


x86 assembly (clang, -O0):
<TrimRight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    113a <TrimRight+0x2a>
jmp    11f7 <TrimRight+0xe7>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%edx
mov    $0x1,%al
mov    $0x20,%ecx
cmp    %edx,%ecx
mov    %al,-0x11(%rbp)
je     11ca <TrimRight+0xba>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%edx
mov    $0x1,%al
mov    $0x9,%ecx
cmp    %edx,%ecx
mov    %al,-0x11(%rbp)
je     11ca <TrimRight+0xba>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%edx
mov    $0x1,%al
mov    $0xd,%ecx
cmp    %edx,%ecx
mov    %al,-0x11(%rbp)
je     11ca <TrimRight+0xba>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11da <TrimRight+0xca>
jmp    11eb <TrimRight+0xdb>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1147 <TrimRight+0x37>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TrimRight>:
push   %rbx
cmpb   $0x0,(%rdi)
je     1149 <TrimRight+0x39>
mov    %rdi,%rbx
call   1030 <strlen@plt>
add    %rbx,%rax
movabs $0x100002600,%rcx
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rax),%edx
cmp    $0x20,%rdx
ja     1146 <TrimRight+0x36>
bt     %rdx,%rcx
jae    1146 <TrimRight+0x36>
add    $0xffffffffffffffff,%rax
jmp    1130 <TrimRight+0x20>
movb   $0x0,(%rax)
pop    %rbx
ret

LLVM IR (-O0):
define void @TrimRight(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %3
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = icmp eq i32 0, %6
br i1 %7, label %8, label %9
8: ; preds = %1
br label %53
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %3
br label %12
12: ; preds = %46, %9
%13 = load i8*, i8** %2
%14 = load i64, i64* %3
%15 = sub i64 %14, 1
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 32, %18
br i1 %19, label %44, label %20
20: ; preds = %12
%21 = load i8*, i8** %2
%22 = load i64, i64* %3
%23 = sub i64 %22, 1
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 9, %26
br i1 %27, label %44, label %28
28: ; preds = %20
%29 = load i8*, i8** %2
%30 = load i64, i64* %3
%31 = sub i64 %30, 1
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 13, %34
br i1 %35, label %44, label %36
36: ; preds = %28
%37 = load i8*, i8** %2
%38 = load i64, i64* %3
%39 = sub i64 %38, 1
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 10, %42
br label %44
44: ; preds = %36, %28, %20, %12
%45 = phi i1 [ true, %28 ], [ true, %20 ], [ true, %12 ], [ %43, %36 ]
br i1 %45, label %46, label %49
46: ; preds = %44
%47 = load i64, i64* %3
%48 = add i64 %47, -1
store i64 %48, i64* %3
br label %12
49: ; preds = %44
%50 = load i8*, i8** %2
%51 = load i64, i64* %3
%52 = getelementptr inbounds i8, i8* %50, i64 %51
store i8 0, i8* %52
br label %53
53: ; preds = %49, %8
ret void
}

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