#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 */
scalar_t__ isspace(char);
scalar_t__ rs_str_is_invalid(char *);
size_t strlen(char *);
void rs_str_rstrip(char *str) {
  size_t s;
  if (rs_str_is_invalid(str))
    return;
  s = strlen(str);
  while (s-- && isspace(str[s]))
    str[s] = '\0';
}


x86 assembly (clang, -O0):
<rs_str_rstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <rs_str_is_invalid@plt>
cmp    $0x0,%rax
je     1154 <rs_str_rstrip+0x24>
jmp    11bb <rs_str_rstrip+0x8b>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
mov    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     119a <rs_str_rstrip+0x6a>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11aa <rs_str_rstrip+0x7a>
jmp    11bb <rs_str_rstrip+0x8b>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1161 <rs_str_rstrip+0x31>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rs_str_rstrip>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <rs_str_is_invalid@plt>
test   %rax,%rax
je     1149 <rs_str_rstrip+0x19>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1141 <rs_str_rstrip+0x11>
mov    %rax,%rbx
nopl   0x0(%rax)
movsbl -0x1(%r14,%rbx,1),%edi
call   1050 <isspace@plt>
test   %rax,%rax
je     1141 <rs_str_rstrip+0x11>
movb   $0x0,-0x1(%r14,%rbx,1)
add    $0xffffffffffffffff,%rbx
jne    1160 <rs_str_rstrip+0x30>
jmp    1141 <rs_str_rstrip+0x11>

LLVM IR (-O0):
define void @rs_str_rstrip(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @rs_str_is_invalid(i8* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
br label %28
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %3
br label %11
11: ; preds = %24, %8
%12 = load i64, i64* %3
%13 = add i64 %12, -1
store i64 %13, i64* %3
%14 = icmp ne i64 %12, 0
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = load i64, i64* %3
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @isspace(i8 signext %19)
%21 = icmp ne i64 %20, 0
br label %22
22: ; preds = %15, %11
%23 = phi i1 [ false, %11 ], [ %21, %15 ]
br i1 %23, label %24, label %28
24: ; preds = %22
%25 = load i8*, i8** %2
%26 = load i64, i64* %3
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 0, i8* %27
br label %11
28: ; preds = %7, %22
ret void
}

LLVM IR (-O2):
define void @rs_str_rstrip(i8* %0) {
%2 = tail call i64 @rs_str_is_invalid(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %4, %14
%8 = phi i64 [ %9, %14 ], [ %5, %4 ]
%9 = add i64 %8, -1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @isspace(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %7
store i8 0, i8* %10
%15 = icmp eq i64 %9, 0
br i1 %15, label %16, label %7
16: ; preds = %14, %7, %4, %1
ret void
}