#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 */
unsigned long strlen(char *);
void trim_trailing_whitespace(char *str) {
  unsigned long l;
  if (str == NULL) {
    return;
  }
  l = strlen(str);
  if (l < 1) {
    return;
  }
  while ((l > 0) && ((str[l - 1] == ' ') || (str[l - 1] == '\n') ||
                     (str[l - 1] == '\r') || (str[l - 1] == '\t'))) {
    str[l - 1] = '\0';
    l = strlen(str);
  }
}


x86 assembly (clang, -O0):
<trim_trailing_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    112c <trim_trailing_whitespace+0x1c>
jmp    1209 <trim_trailing_whitespace+0xf9>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jae    1149 <trim_trailing_whitespace+0x39>
jmp    1209 <trim_trailing_whitespace+0xf9>
jmp    114e <trim_trailing_whitespace+0x3e>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jbe    11d7 <trim_trailing_whitespace+0xc7>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x12(%rbp)
je     11d1 <trim_trailing_whitespace+0xc1>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x12(%rbp)
je     11d1 <trim_trailing_whitespace+0xc1>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x12(%rbp)
je     11d1 <trim_trailing_whitespace+0xc1>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11e7 <trim_trailing_whitespace+0xd7>
jmp    1209 <trim_trailing_whitespace+0xf9>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
jmp    114e <trim_trailing_whitespace+0x3e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_trailing_whitespace>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1153 <trim_trailing_whitespace+0x43>
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
je     1153 <trim_trailing_whitespace+0x43>
movabs $0x100002600,%r14
movzbl -0x1(%rax,%rbx,1),%ecx
cmp    $0x20,%rcx
ja     1153 <trim_trailing_whitespace+0x43>
bt     %rcx,%r14
jae    1153 <trim_trailing_whitespace+0x43>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
jne    1130 <trim_trailing_whitespace+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @trim_trailing_whitespace(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
br label %60
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %3
%10 = load i64, i64* %3
%11 = icmp ult i64 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %7
br label %60
13: ; preds = %7
br label %14
14: ; preds = %53, %13
%15 = load i64, i64* %3
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %51
17: ; preds = %14
%18 = load i8*, i8** %2
%19 = load i64, i64* %3
%20 = sub i64 %19, 1
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 32
br i1 %24, label %49, label %25
25: ; preds = %17
%26 = load i8*, i8** %2
%27 = load i64, i64* %3
%28 = sub i64 %27, 1
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 10
br i1 %32, label %49, label %33
33: ; preds = %25
%34 = load i8*, i8** %2
%35 = load i64, i64* %3
%36 = sub i64 %35, 1
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 13
br i1 %40, label %49, label %41
41: ; preds = %33
%42 = load i8*, i8** %2
%43 = load i64, i64* %3
%44 = sub i64 %43, 1
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 9
br label %49
49: ; preds = %41, %33, %25, %17
%50 = phi i1 [ true, %33 ], [ true, %25 ], [ true, %17 ], [ %48, %41 ]
br label %51
51: ; preds = %49, %14
%52 = phi i1 [ false, %14 ], [ %50, %49 ]
br i1 %52, label %53, label %60
53: ; preds = %51
%54 = load i8*, i8** %2
%55 = load i64, i64* %3
%56 = sub i64 %55, 1
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 0, i8* %57
%58 = load i8*, i8** %2
%59 = call i64 @strlen(i8* %58)
store i64 %59, i64* %3
br label %14
60: ; preds = %6, %12, %51
ret void
}

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