#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 *);
char *remove_chasing_whitespaces(char *str) {
  char *s = (str + (sizeof(char) * (strlen(str) - 1)));
  while (s >= str) {
    if (!((*s == ' ') || (*s == '\t')))
      break;
    *s = '\0';
    --s;
  }
  return str;
}


x86 assembly (clang, -O0):
<remove_chasing_whitespaces>:
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
shl    $0x0,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     118f <remove_chasing_whitespaces+0x7f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     1177 <remove_chasing_whitespaces+0x67>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
je     1177 <remove_chasing_whitespaces+0x67>
jmp    118f <remove_chasing_whitespaces+0x7f>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <remove_chasing_whitespaces+0x34>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_chasing_whitespaces>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1149 <remove_chasing_whitespaces+0x39>
add    $0xffffffff,%eax
add    %rbx,%rax
jmp    113c <remove_chasing_whitespaces+0x2c>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jb     1149 <remove_chasing_whitespaces+0x39>
movzbl (%rax),%ecx
cmp    $0x20,%cl
je     1130 <remove_chasing_whitespaces+0x20>
cmp    $0x9,%cl
je     1130 <remove_chasing_whitespaces+0x20>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @remove_chasing_whitespaces(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 = mul i64 1, %8
%10 = getelementptr inbounds i8, i8* %4, i64 %9
store i8* %10, i8** %3
br label %11
11: ; preds = %26, %1
%12 = load i8*, i8** %3
%13 = load i8*, i8** %2
%14 = icmp uge i8* %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %26, 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, 9
br i1 %24, label %26, label %25
25: ; preds = %20
br label %30
26: ; preds = %20, %15
%27 = load i8*, i8** %3
store i8 0, i8* %27
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %3
br label %11
30: ; preds = %25, %11
%31 = load i8*, i8** %2
ret i8* %31
}

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