#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 strlen(char *const);
void TOOLS_RemoveTrailingSpaces(char *const pInputStr) {
  char *pEndPtr;
  if (pInputStr == NULL) {
    return;
  }
  for (pEndPtr = (pInputStr + strlen(pInputStr) - 1); *pEndPtr == ' ';
       pEndPtr--) {
  }
  *(pEndPtr + 1) = '\0';
  return;
}


x86 assembly (clang, -O0):
<TOOLS_RemoveTrailingSpaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    112c <TOOLS_RemoveTrailingSpaces+0x1c>
jmp    117f <TOOLS_RemoveTrailingSpaces+0x6f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1177 <TOOLS_RemoveTrailingSpaces+0x67>
jmp    1166 <TOOLS_RemoveTrailingSpaces+0x56>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1151 <TOOLS_RemoveTrailingSpaces+0x41>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TOOLS_RemoveTrailingSpaces>:
test   %rdi,%rdi
je     113e <TOOLS_RemoveTrailingSpaces+0x2e>
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0x1,%rax
nopw   0x0(%rax,%rax,1)
cmpb   $0x20,-0x2(%rax)
lea    -0x1(%rax),%rax
je     1130 <TOOLS_RemoveTrailingSpaces+0x20>
movb   $0x0,(%rax)
pop    %rbx
ret

LLVM IR (-O0):
define void @TOOLS_RemoveTrailingSpaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
br label %26
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
store i8* %13, i8** %3
br label %14
14: ; preds = %20, %7
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 32
br i1 %18, label %19, label %23
19: ; preds = %14
br label %20
20: ; preds = %19
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 -1
store i8* %22, i8** %3
br label %14
23: ; preds = %14
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 0, i8* %25
br label %26
26: ; preds = %23, %6
ret void
}

LLVM IR (-O2):
define void @TOOLS_RemoveTrailingSpaces(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
br label %7
7: ; preds = %7, %3
%8 = phi i8* [ %6, %3 ], [ %9, %7 ]
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 32
br i1 %11, label %7, label %12
12: ; preds = %7
store i8 0, i8* %8
br label %13
13: ; preds = %1, %12
ret void
}