#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 /*<<< orphan*/ isspace(char);
void rtrim(char *buf) {
  char *tmp;
  for (tmp = buf - 1; buf[0]; buf++)
    if (!isspace(buf[0]))
      tmp = buf;
  tmp[1] = 0;
}


x86 assembly (clang, -O0):
<rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1168 <rtrim+0x58>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%eax
jne    1152 <rtrim+0x42>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1157 <rtrim+0x47>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1128 <rtrim+0x18>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
push   %r14
push   %rbx
push   %rax
lea    -0x1(%rdi),%r14
mov    (%rdi),%al
test   %al,%al
je     114a <rtrim+0x3a>
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <isspace@plt>
test   %eax,%eax
cmove  %rbx,%r14
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <rtrim+0x20>
movb   $0x0,0x1(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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