#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 *string, size_t len) {
  char ch;
  do {
    ch = string[--len];
    if ((ch == ' ') || (ch == '\n') || (ch == '\t') ||
        (ch == '\r' && *(string + 1) == '\n')) {
      string[len] = '\0';
    } else
      break;
  } while (len);
  return string;
}


x86 assembly (clang, -O0):
<rtrim>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x10(%rbp)
mov    -0x1(%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
je     116b <rtrim+0x6b>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
je     116b <rtrim+0x6b>
movsbl -0x11(%rbp),%eax
cmp    $0x9,%eax
je     116b <rtrim+0x6b>
movsbl -0x11(%rbp),%eax
cmp    $0xd,%eax
jne    117c <rtrim+0x7c>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0xa,%eax
jne    117c <rtrim+0x7c>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1181 <rtrim+0x81>
jmp    1191 <rtrim+0x91>
jmp    1186 <rtrim+0x86>
cmpq   $0x0,-0x10(%rbp)
jne    110c <rtrim+0xc>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
mov    %rdi,%rax
jmp    111b <rtrim+0x1b>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,-0x1(%rax,%rsi,1)
add    $0xffffffffffffffff,%rsi
je     1138 <rtrim+0x38>
movzbl -0x1(%rax,%rsi,1),%ecx
lea    -0x9(%rcx),%edx
cmp    $0x2,%dl
jb     1110 <rtrim+0x10>
cmp    $0x20,%cl
je     1110 <rtrim+0x10>
cmp    $0xd,%cl
jne    1138 <rtrim+0x38>
cmpb   $0xa,0x1(%rax)
je     1110 <rtrim+0x10>
ret

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

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