#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__ isWhiteSpace(char);
size_t strlen(char *);
void trimRight(char *str) {
  size_t len = strlen(str);
  while (len >= 0 && isWhiteSpace(str[len])) {
    str[len--] = 0;
  }
}


x86 assembly (clang, -O0):
<trimRight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jb     1164 <trimRight+0x44>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isWhiteSpace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1174 <trimRight+0x54>
jmp    1190 <trimRight+0x70>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x10(%rbp)
movb   $0x0,(%rax,%rcx,1)
jmp    1139 <trimRight+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trimRight>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r14
movsbl (%rbx,%rax,1),%edi
call   1040 <isWhiteSpace@plt>
test   %rax,%rax
je     1155 <trimRight+0x35>
add    %r14,%rbx
movb   $0x0,(%rbx)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1040 <isWhiteSpace@plt>
test   %rax,%rax
jne    1140 <trimRight+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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