#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;
  while (len >= 0) {
    switch (s[len]) {
    case '\t':
    case ' ':
    case '\r':
    case '\n':
      s[len] = '\0';
      len--;
    default:
      return;
    }
  }
}


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)
cmpl   $0x0,-0xc(%rbp)
jl     1191 <remove_trailing_whitespace+0x81>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x10(%rbp)
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     1177 <remove_trailing_whitespace+0x67>
jmp    1155 <remove_trailing_whitespace+0x45>
mov    -0x10(%rbp),%eax
sub    $0xd,%eax
je     1177 <remove_trailing_whitespace+0x67>
jmp    1166 <remove_trailing_whitespace+0x56>
mov    -0x10(%rbp),%eax
sub    $0x20,%eax
jne    118c <remove_trailing_whitespace+0x7c>
jmp    1177 <remove_trailing_whitespace+0x67>
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    1191 <remove_trailing_whitespace+0x81>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_trailing_whitespace>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    113d <remove_trailing_whitespace+0x2d>
add    $0xffffffff,%eax
movsbl (%rbx,%rax,1),%ecx
cmp    $0x20,%ecx
ja     113d <remove_trailing_whitespace+0x2d>
movabs $0x100002600,%rdx
bt     %rcx,%rdx
jae    113d <remove_trailing_whitespace+0x2d>
movb   $0x0,(%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 = %1
%8 = load i32, i32* %3
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %24 [
i32 9, label %17
i32 32, label %17
i32 13, label %17
i32 10, label %17
]
17: ; preds = %10, %10, %10, %10
%18 = load i8*, i8** %2
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 0, i8* %21
%22 = load i32, i32* %3
%23 = add nsw i32 %22, -1
store i32 %23, i32* %3
br label %24
24: ; preds = %10, %17
br label %25
25: ; preds = %24, %7
ret void
}

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