#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);
size_t strlen(char *);
void StripTrailingWhitespace(char *str) {
  size_t len;
  char *ptr;
  len = (str ? strlen(str) : 0);
  if (len == 0)
    return;
  for (ptr = str + len - 1; (ptr >= str) && isspace(*ptr); ptr--)
    *ptr = '\0';
}


x86 assembly (clang, -O0):
<StripTrailingWhitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1149 <StripTrailingWhitespace+0x29>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
jmp    1154 <StripTrailingWhitespace+0x34>
xor    %eax,%eax
mov    %rax,-0x20(%rbp)
jmp    1154 <StripTrailingWhitespace+0x34>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116c <StripTrailingWhitespace+0x4c>
jmp    11cd <StripTrailingWhitespace+0xad>
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
jb     11a5 <StripTrailingWhitespace+0x85>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11b5 <StripTrailingWhitespace+0x95>
jmp    11cd <StripTrailingWhitespace+0xad>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    117c <StripTrailingWhitespace+0x5c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StripTrailingWhitespace>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1169 <StripTrailingWhitespace+0x49>
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %rax,%rax
je     1169 <StripTrailingWhitespace+0x49>
lea    (%r14,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jb     1169 <StripTrailingWhitespace+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1169 <StripTrailingWhitespace+0x49>
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jae    1150 <StripTrailingWhitespace+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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