#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 *);
char *rtrim(char *str) {
  char *s;
  if (str[0] == '\0')
    return str;
  s = &str[strlen(str) - 1];
  while (s != str && *s == ' ')
    *s-- = '\0';
  return str;
}


x86 assembly (clang, -O0):
<rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1139 <rtrim+0x29>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11af <rtrim+0x9f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x21(%rbp)
je     1180 <rtrim+0x70>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1190 <rtrim+0x80>
jmp    11a7 <rtrim+0x97>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
jmp    115d <rtrim+0x4d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
push   %rbx
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1140 <rtrim+0x30>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
je     1140 <rtrim+0x30>
cltq
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,(%rbx,%rax,1)
jne    1140 <rtrim+0x30>
movb   $0x0,(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
jne    1130 <rtrim+0x20>
mov    %rbx,%rax
pop    %rbx
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
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i8*, i8** %3
store i8* %11, i8** %2
br label %35
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
store i8* %18, i8** %4
br label %19
19: ; preds = %30, %12
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = icmp ne i8* %20, %21
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 32
br label %28
28: ; preds = %23, %19
%29 = phi i1 [ false, %19 ], [ %27, %23 ]
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %4
store i8 0, i8* %31
br label %19
33: ; preds = %28
%34 = load i8*, i8** %3
store i8* %34, i8** %2
br label %35
35: ; preds = %33, %10
%36 = load i8*, i8** %2
ret i8* %36
}

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