#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 rtrim(char *s) {
  int l;
  l = strlen(s) - 1;
  for (;;) {
    if (l < 1)
      break;
    if (s[l] != ' ' && s[l] != '\t')
      break;
    s[l] = 0;
    l--;
  }
}


x86 assembly (clang, -O0):
<rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    113a <rtrim+0x2a>
jmp    1183 <rtrim+0x73>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1169 <rtrim+0x59>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
je     1169 <rtrim+0x59>
jmp    1183 <rtrim+0x73>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    112b <rtrim+0x1b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     114f <rtrim+0x3f>
mov    %eax,%eax
add    $0x1,%rax
jmp    113e <rtrim+0x2e>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x2,%rax
jbe    114f <rtrim+0x3f>
lea    -0x2(%rax),%ecx
movzbl (%rbx,%rcx,1),%edx
cmp    $0x20,%dl
je     1130 <rtrim+0x20>
cmp    $0x9,%dl
je     1130 <rtrim+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define void @rtrim(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = sub nsw i32 %5, 1
store i32 %6, i32* %3
br label %7
7: ; preds = %28, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %7
br label %35
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
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 32
br i1 %18, label %19, label %28
19: ; preds = %11
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 9
br i1 %26, label %27, label %28
27: ; preds = %19
br label %35
28: ; preds = %19, %11
%29 = load i8*, i8** %2
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i32, i32* %3
%34 = add nsw i32 %33, -1
store i32 %34, i32* %3
br label %7
35: ; preds = %27, %10
ret void
}

LLVM IR (-O2):
define void @rtrim(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp slt i32 %2, 2
br i1 %3, label %14, label %4
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 9, label %12
]
12: ; preds = %6, %6
store i8 0, i8* %10
%13 = icmp ult i64 %7, 3
br i1 %13, label %14, label %6
14: ; preds = %12, %6, %1
ret void
}