#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 *rtrim(char *s) {
  char *t = s;
  if (!s)
    return NULL;
  while (*s)
    s++;
  while (*--s == ' ' || *s == '\t' || *s == '\r' || *s == '\n')
    *s = 0;
  return t;
}


x86 assembly (clang, -O0):
<rtrim>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1128 <rtrim+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11cf <rtrim+0xcf>
jmp    112d <rtrim+0x2d>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     114b <rtrim+0x4b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112d <rtrim+0x2d>
jmp    1150 <rtrim+0x50>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movsbl -0x1(%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x19(%rbp)
je     11ab <rtrim+0xab>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x19(%rbp)
je     11ab <rtrim+0xab>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x19(%rbp)
je     11ab <rtrim+0xab>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11bb <rtrim+0xbb>
jmp    11c7 <rtrim+0xc7>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1150 <rtrim+0x50>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
mov    %rdi,%rax
test   %rdi,%rdi
je     1148 <rtrim+0x48>
lea    -0x2(%rax),%rcx
nopl   0x0(%rax)
cmpb   $0x0,0x2(%rcx)
lea    0x1(%rcx),%rcx
jne    1110 <rtrim+0x10>
movabs $0x100002600,%rdx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rcx),%esi
cmp    $0x20,%rsi
ja     1148 <rtrim+0x48>
bt     %rsi,%rdx
jae    1148 <rtrim+0x48>
movb   $0x0,(%rcx)
add    $0xffffffffffffffff,%rcx
jmp    1130 <rtrim+0x30>
ret

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

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