#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 *);
void remove_trailing_whitespace(char *s) {
  int len = strlen(s) - 1;
  do {
    switch (s[len]) {
    case '\t':
    case ' ':
    case '\r':
    case '\n':
      s[len] = '\0';
      len--;
    default:
      return;
    }
  } while (1);
}


x86 assembly (clang, -O0):
<remove_trailing_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x10(%rbp)
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     116d <remove_trailing_whitespace+0x5d>
jmp    114b <remove_trailing_whitespace+0x3b>
mov    -0x10(%rbp),%eax
sub    $0xd,%eax
je     116d <remove_trailing_whitespace+0x5d>
jmp    115c <remove_trailing_whitespace+0x4c>
mov    -0x10(%rbp),%eax
sub    $0x20,%eax
jne    1182 <remove_trailing_whitespace+0x72>
jmp    116d <remove_trailing_whitespace+0x5d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1187 <remove_trailing_whitespace+0x77>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_trailing_whitespace>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%ecx
cmp    $0x20,%ecx
ja     113a <remove_trailing_whitespace+0x2a>
movabs $0x100002600,%rdx
bt     %rcx,%rdx
jae    113a <remove_trailing_whitespace+0x2a>
movb   $0x0,-0x1(%rbx,%rax,1)
pop    %rbx
ret

LLVM IR (-O0):
define void @remove_trailing_whitespace(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = sub nsw i32 %5, 1
store i32 %6, i32* %3
br label %7
7: ; preds = %22, %1
%8 = load i8*, i8** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %21 [
i32 9, label %14
i32 32, label %14
i32 13, label %14
i32 10, label %14
]
14: ; preds = %7, %7, %7, %7
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 0, i8* %18
%19 = load i32, i32* %3
%20 = add nsw i32 %19, -1
store i32 %20, i32* %3
br label %21
21: ; preds = %7, %14
br label %23
22: ; No predecessors!
br i1 true, label %7, label %23
23: ; preds = %21, %22
ret void
}

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