#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 */
char *strdup(char const *);
size_t strlen(char *);
char *flu_strrtrim(const char *s) {
  char *r = strdup(s);
  for (size_t l = strlen(r); l > 0; l--) {
    char c = r[l - 1];
    if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
      r[l - 1] = '\0';
    else
      break;
  }
  return r;
}


x86 assembly (clang, -O0):
<flu_strrtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11c7 <flu_strrtrim+0xa7>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
je     1197 <flu_strrtrim+0x77>
movsbl -0x19(%rbp),%eax
cmp    $0x9,%eax
je     1197 <flu_strrtrim+0x77>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
je     1197 <flu_strrtrim+0x77>
movsbl -0x19(%rbp),%eax
cmp    $0xd,%eax
jne    11ac <flu_strrtrim+0x8c>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11b1 <flu_strrtrim+0x91>
jmp    11c7 <flu_strrtrim+0xa7>
jmp    11b6 <flu_strrtrim+0x96>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1146 <flu_strrtrim+0x26>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flu_strrtrim>:
push   %rbx
call   1040 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     116a <flu_strrtrim+0x4a>
movabs $0x100002600,%rcx
movzbl -0x1(%rbx,%rax,1),%edx
cmp    $0x20,%rdx
ja     116a <flu_strrtrim+0x4a>
bt     %rdx,%rcx
jae    116a <flu_strrtrim+0x4a>
movb   $0x0,-0x1(%rbx,%rax,1)
cmp    $0x20,%dl
ja     116a <flu_strrtrim+0x4a>
movzbl %dl,%edx
bt     %rdx,%rcx
jae    116a <flu_strrtrim+0x4a>
add    $0xffffffffffffffff,%rax
jne    1140 <flu_strrtrim+0x20>
mov    %rbx,%rax
pop    %rbx
ret

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

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