#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;
  if (!buf) {
    ;
    return -1;
  }
  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,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1136 <_remove_trailing_whitespace+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a6 <_remove_trailing_whitespace+0x96>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     11a0 <_remove_trailing_whitespace+0x90>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     1181 <_remove_trailing_whitespace+0x71>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    1186 <_remove_trailing_whitespace+0x76>
jmp    11a0 <_remove_trailing_whitespace+0x90>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1151 <_remove_trailing_whitespace+0x41>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_remove_trailing_whitespace>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     116a <_remove_trailing_whitespace+0x5a>
mov    %esi,%eax
mov    %rdi,%r14
movslq %esi,%rbx
lea    (%rdi,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rdi,%rcx
jb     116f <_remove_trailing_whitespace+0x5f>
lea    -0x1(%r14),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r15,%rbx,1),%edi
call   1030 <isspace@plt>
test   %rax,%rax
je     1166 <_remove_trailing_whitespace+0x56>
movb   $0x0,-0x1(%r14,%rbx,1)
lea    (%r15,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rax
jae    1140 <_remove_trailing_whitespace+0x30>
mov    %ebx,%eax
jmp    116f <_remove_trailing_whitespace+0x5f>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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