#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 trim_trailing_whitespace(char *s) {
  int i;
  char c;
  i = strlen(s);
  while (--i >= 0) {
    c = s[i];
    if ((c == '\n') || (c == '\r') || (c == ' ') || (c == '\t'))
      s[i] = '\0';
    else
      break;
  }
}


x86 assembly (clang, -O0):
<trim_trailing_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     1197 <trim_trailing_whitespace+0x87>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
je     117c <trim_trailing_whitespace+0x6c>
movsbl -0xd(%rbp),%eax
cmp    $0xd,%eax
je     117c <trim_trailing_whitespace+0x6c>
movsbl -0xd(%rbp),%eax
cmp    $0x20,%eax
je     117c <trim_trailing_whitespace+0x6c>
movsbl -0xd(%rbp),%eax
cmp    $0x9,%eax
jne    118d <trim_trailing_whitespace+0x7d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1192 <trim_trailing_whitespace+0x82>
jmp    1197 <trim_trailing_whitespace+0x87>
jmp    1128 <trim_trailing_whitespace+0x18>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_trailing_whitespace>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1151 <trim_trailing_whitespace+0x41>
mov    %eax,%eax
add    $0x1,%rax
movabs $0x100002600,%rcx
nopl   (%rax)
lea    -0x2(%rax),%edx
movzbl (%rbx,%rdx,1),%esi
cmp    $0x20,%rsi
ja     1151 <trim_trailing_whitespace+0x41>
bt     %rsi,%rcx
jae    1151 <trim_trailing_whitespace+0x41>
movb   $0x0,(%rbx,%rdx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
ja     1130 <trim_trailing_whitespace+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define void @trim_trailing_whitespace(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %3
br label %7
7: ; preds = %38, %1
%8 = load i32, i32* %3
%9 = add nsw i32 %8, -1
store i32 %9, i32* %3
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %39
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
store i8 %16, i8* %4
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %32, label %20
20: ; preds = %11
%21 = load i8, i8* %4
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 13
br i1 %23, label %32, label %24
24: ; preds = %20
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 32
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i8, i8* %4
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 9
br i1 %31, label %32, label %37
32: ; preds = %28, %24, %20, %11
%33 = load i8*, i8** %2
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
br label %38
37: ; preds = %28
br label %39
38: ; preds = %32
br label %7
39: ; preds = %37, %7
ret void
}

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