#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 = 0, p = 0;
  l = strlen(s);
  if (l == 0) {
    return;
  }
  p = l - 1;
  while (s[p] == ' ' || s[p] == '\t') {
    s[p--] = '\0';
    if (p < 0) {
      break;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1145 <rtrim+0x35>
jmp    11bc <rtrim+0xac>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x11(%rbp)
je     117d <rtrim+0x6d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    118d <rtrim+0x7d>
jmp    11b7 <rtrim+0xa7>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x10(%rbp)
jge    11b2 <rtrim+0xa2>
jmp    11b7 <rtrim+0xa7>
jmp    114e <rtrim+0x3e>
jmp    11bc <rtrim+0xac>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
je     114e <rtrim+0x3e>
cltq
add    $0x1,%rax
jmp    113f <rtrim+0x2f>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,-0x2(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
jle    114e <rtrim+0x3e>
movzbl -0x2(%rbx,%rax,1),%ecx
cmp    $0x20,%cl
je     1130 <rtrim+0x20>
cmp    $0x9,%cl
je     1130 <rtrim+0x20>
pop    %rbx
ret

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

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