#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*/ isspace(char);
int strlen(char *);
char *wPopString();
int /*<<< orphan*/ wPushString(char *);
void wBasRTrim() {
  int len, i;
  char *string;
  string = wPopString();
  len = strlen(string);
  for (i = len - 1; i > -1; i--) {
    if (!isspace(string[i])) {
      string[i + 1] = '\0';
      wPushString(string);
      return;
    }
  }
  string[0] = '\0';
  wPushString(string);
}


x86 assembly (clang, -O0):
<wBasRTrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <wPopString@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jle    11be <wBasRTrim+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isspace@plt>
cmp    $0x0,%eax
jne    11ab <wBasRTrim+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1060 <wPushString@plt>
jmp    11ce <wBasRTrim+0x8e>
jmp    11b0 <wBasRTrim+0x70>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1168 <wBasRTrim+0x28>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1060 <wPushString@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wBasRTrim>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <wPopString@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
nopl   0x0(%rax,%rax,1)
test   %ebx,%ebx
jle    1181 <wBasRTrim+0x41>
movsbl -0x1(%r14,%rbx,1),%edi
call   1050 <isspace@plt>
add    $0xffffffffffffffff,%rbx
test   %eax,%eax
jne    1160 <wBasRTrim+0x20>
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
jmp    1184 <wBasRTrim+0x44>
mov    %r14,%rax
movb   $0x0,(%rax)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <wPushString@plt>

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

LLVM IR (-O2):
define void @wBasRTrim() {
%1 = tail call i8* (...) @wPopString()
%2 = tail call i32 @strlen(i8* %1)
%3 = zext i32 %2 to i64
br label %4
4: ; preds = %9, %0
%5 = phi i64 [ %6, %9 ], [ %3, %0 ]
%6 = add nsw i64 %5, -1
%7 = trunc i64 %5 to i32
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %1, i64 %6
%11 = load i8, i8* %10
%12 = tail call i32 @isspace(i8 signext %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %9
%15 = and i64 %5, 4294967295
%16 = getelementptr inbounds i8, i8* %1, i64 %15
br label %17
17: ; preds = %4, %14
%18 = phi i8* [ %16, %14 ], [ %1, %4 ]
store i8 0, i8* %18
%19 = tail call i32 @wPushString(i8* %1)
ret void
}