#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 *astrcpy(char *);
char *astrleft(char const *, size_t);
int /*<<< orphan*/ isspace(char const);
int strlen(char const *);
char *astrrtrim(const char *s) {
  char *result = NULL;
  size_t ii;
  for (ii = strlen(s) - 1; ii >= 0; --ii) {
    if (!isspace(s[ii])) {
      result = astrleft(s, ii + 1);
      break;
    }
  }
  if (result == NULL)
    result = astrcpy("");
  return result;
}


x86 assembly (clang, -O0):
<astrrtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jb     11bb <astrrtrim+0x7b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isspace@plt>
cmp    $0x0,%eax
jne    11a5 <astrrtrim+0x65>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1040 <astrleft@plt>
mov    %rax,-0x10(%rbp)
jmp    11bb <astrrtrim+0x7b>
jmp    11aa <astrrtrim+0x6a>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1166 <astrrtrim+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    11d6 <astrrtrim+0x96>
lea    0xe33(%rip),%rdi
call   1060 <astrcpy@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astrrtrim>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
movslq %eax,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl -0x2(%r14,%rbx,1),%edi
call   1050 <isspace@plt>
add    $0xffffffffffffffff,%rbx
test   %eax,%eax
jne    1160 <astrrtrim+0x20>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <astrleft@plt>
test   %rax,%rax
je     118b <astrrtrim+0x4b>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6e(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <astrcpy@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @astrrtrim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %3
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sub nsw i32 %6, 1
%8 = sext i32 %7 to i64
store i64 %8, i64* %4
br label %9
9: ; preds = %25, %1
%10 = load i64, i64* %4
%11 = icmp uge i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = load i8*, i8** %2
%14 = load i64, i64* %4
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @isspace(i8 signext %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %12
%20 = load i8*, i8** %2
%21 = load i64, i64* %4
%22 = add i64 %21, 1
%23 = call i8* @astrleft(i8* %20, i64 %22)
store i8* %23, i8** %3
br label %28
24: ; preds = %12
br label %25
25: ; preds = %24
%26 = load i64, i64* %4
%27 = add i64 %26, -1
store i64 %27, i64* %4
br label %9
28: ; preds = %19, %9
%29 = load i8*, i8** %3
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i8* @astrcpy(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %32, i8** %3
br label %33
33: ; preds = %31, %28
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @astrrtrim(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = sext i32 %3 to i64
br label %5
5: ; preds = %5, %1
%6 = phi i64 [ %4, %1 ], [ %11, %5 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = tail call i32 @isspace(i8 signext %8)
%10 = icmp eq i32 %9, 0
%11 = add i64 %6, -1
br i1 %10, label %12, label %5
12: ; preds = %5
%13 = add i64 %6, 1
%14 = tail call i8* @astrleft(i8* %0, i64 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i8* @astrcpy(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = phi i8* [ %17, %16 ], [ %14, %12 ]
ret i8* %19
}