#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 const *);
void string_trimRight(unsigned char *string) {
  unsigned char *p = string + strlen((const char *)string) - 1;
  while (*p == ' ' || *p == '\r' || *p == '\n' || *p == '\t')
    p--;
  *(p + 1) = 0;
  return;
}


x86 assembly (clang, -O0):
<string_trimRight>:
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
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x19(%rbp)
je     1190 <string_trimRight+0x80>
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x19(%rbp)
je     1190 <string_trimRight+0x80>
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     1190 <string_trimRight+0x80>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a0 <string_trimRight+0x90>
jmp    11b1 <string_trimRight+0xa1>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1141 <string_trimRight+0x31>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_trimRight>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rdx
add    %rbx,%rdx
movabs $0x100002600,%rax
nopl   0x0(%rax)
mov    %rdx,%rcx
movzbl -0x1(%rdx),%esi
cmp    $0x20,%rsi
ja     1147 <string_trimRight+0x37>
lea    -0x1(%rcx),%rdx
bt     %rsi,%rax
jb     1130 <string_trimRight+0x20>
movb   $0x0,(%rcx)
pop    %rbx
ret

LLVM IR (-O0):
define void @string_trimRight(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 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %3
br label %10
10: ; preds = %32, %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = zext 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 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 13
br i1 %19, label %30, label %20
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = zext 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 = zext i8 %27 to i32
%29 = icmp eq i32 %28, 9
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, i64 1
store i8 0, i8* %37
ret void
}

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