#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__ isblank(char);
void rmTrailingBlank(char str[]) {
  int len = 0;
  while (*str) {
    ++len;
    ++str;
  }
  while (isblank(str[len - 1])) {
    --len;
  }
  str[len] = '\0';
}


x86 assembly (clang, -O0):
<rmTrailingBlank>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     114a <rmTrailingBlank+0x3a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <rmTrailingBlank+0x13>
jmp    114f <rmTrailingBlank+0x3f>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isblank@plt>
cmp    $0x0,%rax
je     117d <rmTrailingBlank+0x6d>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <rmTrailingBlank+0x3f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmTrailingBlank>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     1141 <rmTrailingBlank+0x31>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x0,0x1(%r14,%rax,1)
lea    0x1(%rax),%rax
jne    1130 <rmTrailingBlank+0x20>
add    %rax,%r14
jmp    1143 <rmTrailingBlank+0x33>
xor    %eax,%eax
lea    (%rax,%r14,1),%rbx
add    $0xffffffffffffffff,%rbx
shl    $0x20,%rax
movabs $0x100000000,%r15
add    %rax,%r15
movabs $0xffffffff00000000,%r12
ff ff ff
cs nopw 0x0(%rax,%rax,1)
add    %r12,%r15
movsbl (%rbx),%edi
call   1030 <isblank@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1170 <rmTrailingBlank+0x60>
sar    $0x20,%r15
movb   $0x0,(%r14,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @rmTrailingBlank(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %8, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %2
br label %4
13: ; preds = %4
br label %14
14: ; preds = %23, %13
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i8, i8* %19
%21 = call i64 @isblank(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %14
%24 = load i32, i32* %3
%25 = add nsw i32 %24, -1
store i32 %25, i32* %3
br label %14
26: ; preds = %14
%27 = load i8*, i8** %2
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
ret void
}

LLVM IR (-O2):
define void @rmTrailingBlank(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %6, label %9
4: ; preds = %9
%5 = zext i32 %12 to i64
br label %6
6: ; preds = %4, %1
%7 = phi i8* [ %0, %1 ], [ %13, %4 ]
%8 = phi i64 [ 0, %1 ], [ %5, %4 ]
br label %16
9: ; preds = %1, %9
%10 = phi i32 [ %12, %9 ], [ 0, %1 ]
%11 = phi i8* [ %13, %9 ], [ %0, %1 ]
%12 = add nuw nsw i32 %10, 1
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %4, label %9
16: ; preds = %6, %16
%17 = phi i64 [ %8, %6 ], [ %18, %16 ]
%18 = add nsw i64 %17, -1
%19 = getelementptr inbounds i8, i8* %7, i64 %18
%20 = load i8, i8* %19
%21 = tail call i64 @isblank(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %16
23: ; preds = %16
%24 = shl i64 %17, 32
%25 = ashr exact i64 %24, 32
%26 = getelementptr inbounds i8, i8* %7, i64 %25
store i8 0, i8* %26
ret void
}