#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 /*<<< orphan*/ WhiteSpace(unsigned char);
int /*<<< orphan*/ assert(int);
const char *str_rtrim(const char *start, const char *end) {
  const char *it, *prev;
  assert(start <= end);
  for (it = end; start != it; it = prev) {
    prev = it - 1;
    if (!(WhiteSpace(((unsigned char)(*prev)))))
      return it;
  }
  return start;
}


x86 assembly (clang, -O0):
<str_rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     119b <str_rtrim+0x7b>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movzbl (%rax),%edi
call   1030 <WhiteSpace@plt>
cmp    $0x0,%eax
jne    1189 <str_rtrim+0x69>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <str_rtrim+0x83>
jmp    118e <str_rtrim+0x6e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    114d <str_rtrim+0x2d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_rtrim>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
cmp    %rsi,%r14
setbe  %dil
call   1040 <assert@plt>
nopl   0x0(%rax,%rax,1)
cmp    %r14,%rbx
je     115d <str_rtrim+0x3d>
movzbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1030 <WhiteSpace@plt>
test   %eax,%eax
jne    1140 <str_rtrim+0x20>
add    $0x1,%rbx
mov    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @str_rtrim(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = icmp ule i8* %8, %9
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8*, i8** %5
store i8* %13, i8** %6
br label %14
14: ; preds = %28, %2
%15 = load i8*, i8** %4
%16 = load i8*, i8** %6
%17 = icmp ne i8* %15, %16
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 -1
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = load i8, i8* %21
%23 = call i32 @WhiteSpace(i8 zeroext %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %18
%26 = load i8*, i8** %6
store i8* %26, i8** %3
br label %32
27: ; preds = %18
br label %28
28: ; preds = %27
%29 = load i8*, i8** %7
store i8* %29, i8** %6
br label %14
30: ; preds = %14
%31 = load i8*, i8** %4
store i8* %31, i8** %3
br label %32
32: ; preds = %30, %25
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
define i8* @str_rtrim(i8* readnone %0, i8* %1) {
%3 = icmp ule i8* %0, %1
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
br label %6
6: ; preds = %9, %2
%7 = phi i8* [ %1, %2 ], [ %10, %9 ]
%8 = icmp eq i8* %7, %0
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %7, i64 -1
%11 = load i8, i8* %10
%12 = tail call i32 @WhiteSpace(i8 zeroext %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6, %9
%15 = phi i8* [ %7, %9 ], [ %0, %6 ]
ret i8* %15
}