#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 _remove_trailing_whitespace(char *buf, int buflen) {
  char *temp;
  temp = buf + buflen;
  for (--temp; temp >= buf; temp--) {
    if (isspace(*temp))
      *temp = '\0';
    else
      break;
    buflen--;
  }
  return buflen;
}


x86 assembly (clang, -O0):
<_remove_trailing_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     1189 <_remove_trailing_whitespace+0x79>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     116a <_remove_trailing_whitespace+0x5a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    116f <_remove_trailing_whitespace+0x5f>
jmp    1189 <_remove_trailing_whitespace+0x79>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    113a <_remove_trailing_whitespace+0x2a>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_remove_trailing_whitespace>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%eax
movslq %esi,%rbx
lea    (%rdi,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rdi,%rcx
jb     1158 <_remove_trailing_whitespace+0x48>
mov    %rdi,%r14
lea    -0x1(%rdi),%r15
xchg   %ax,%ax
movsbl (%r15,%rbx,1),%edi
call   1030 <isspace@plt>
test   %rax,%rax
je     1156 <_remove_trailing_whitespace+0x46>
movb   $0x0,-0x1(%r14,%rbx,1)
lea    (%r15,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rax
jae    1130 <_remove_trailing_whitespace+0x20>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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