#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);
int strlen(char *);
char *CFG_trimTrailingWhitespace(char *str) {
  char *tmp = NULL;
  if (!str)
    return str;
  if (strlen(str) <= 0)
    return str;
  tmp = str + strlen(str) - 1;
  while (isspace(*tmp) && tmp >= str) {
    *tmp = 0;
    tmp--;
  }
  return str;
}


x86 assembly (clang, -O0):
<CFG_trimTrailingWhitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114c <CFG_trimTrailingWhitespace+0x2c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <CFG_trimTrailingWhitespace+0xcc>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jg     116b <CFG_trimTrailingWhitespace+0x4b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <CFG_trimTrailingWhitespace+0xcc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     11bc <CFG_trimTrailingWhitespace+0x9c>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
setae  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11cc <CFG_trimTrailingWhitespace+0xac>
jmp    11e4 <CFG_trimTrailingWhitespace+0xc4>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1190 <CFG_trimTrailingWhitespace+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CFG_trimTrailingWhitespace>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rdi,%rdi
je     118a <CFG_trimTrailingWhitespace+0x6a>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    118a <CFG_trimTrailingWhitespace+0x6a>
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
lea    (%r14,%rbx,1),%r15
add    $0xffffffffffffffff,%r15
movsbl -0x1(%r14,%rbx,1),%edi
call   1040 <isspace@plt>
cmp    %r14,%r15
jb     118a <CFG_trimTrailingWhitespace+0x6a>
test   %rax,%rax
je     118a <CFG_trimTrailingWhitespace+0x6a>
add    %r14,%rbx
add    $0xfffffffffffffffe,%rbx
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x1(%rbx)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
cmp    %r14,%rbx
jb     118a <CFG_trimTrailingWhitespace+0x6a>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1170 <CFG_trimTrailingWhitespace+0x50>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @CFG_trimTrailingWhitespace(i8* returned %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %24, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %4, 1
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = load i8, i8* %10
%12 = tail call i64 @isspace(i8 signext %11)
%13 = icmp ne i64 %12, 0
%14 = icmp uge i8* %10, %0
%15 = and i1 %14, %13
br i1 %15, label %16, label %24
16: ; preds = %6, %16
%17 = phi i8* [ %18, %16 ], [ %10, %6 ]
store i8 0, i8* %17
%18 = getelementptr inbounds i8, i8* %17, i64 -1
%19 = load i8, i8* %18
%20 = tail call i64 @isspace(i8 signext %19)
%21 = icmp ne i64 %20, 0
%22 = icmp uge i8* %18, %0
%23 = and i1 %22, %21
br i1 %23, label %16, label %24
24: ; preds = %16, %6, %3, %1
ret i8* %0
}