#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 */
char *strchr(char *, char);
int strlen(char *);
void trimRight(char *psz) {
  char trim[] = " \t\r\n";
  for (int i = 0; i < strlen(trim); ++i) {
    char *pTmp = strchr(psz, trim[i]);
    if (pTmp != NULL)
      *pTmp = '\0';
  }
}


x86 assembly (clang, -O0):
<trimRight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xece(%rip),%eax
mov    %eax,-0xd(%rbp)
mov    0xec9(%rip),%al
mov    %al,-0x9(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0xd(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    119c <trimRight+0x7c>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
movsbl -0xd(%rbp,%rax,1),%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1189 <trimRight+0x69>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    118e <trimRight+0x6e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1145 <trimRight+0x25>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trimRight>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
movb   $0x0,0xc(%rsp)
movl   $0xa0d0920,0x8(%rsp)
0a
lea    0x8(%rsp),%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    117a <trimRight+0x5a>
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
jmp    1163 <trimRight+0x43>
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    117a <trimRight+0x5a>
movsbl 0x8(%rsp,%rbx,1),%esi
mov    %r15,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1150 <trimRight+0x30>
movb   $0x0,(%rax)
jmp    1150 <trimRight+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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