#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);
void _right_trim(char *arg) {
  char *ptr;
  if (!arg)
    return;
  if (*arg == '\0')
    return;
  for (ptr = arg; *ptr; ptr++)
    ;
  ptr--;
  for (; ptr > arg && isspace(*ptr); ptr--)
    ;
  ptr++;
  *ptr = '\0';
}


x86 assembly (clang, -O0):
<_right_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    112c <_right_trim+0x1c>
jmp    11da <_right_trim+0xca>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1141 <_right_trim+0x31>
jmp    11da <_right_trim+0xca>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     116c <_right_trim+0x5c>
jmp    115b <_right_trim+0x4b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1149 <_right_trim+0x39>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x11(%rbp)
jbe    11a1 <_right_trim+0x91>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11b1 <_right_trim+0xa1>
jmp    11c7 <_right_trim+0xb7>
jmp    11b6 <_right_trim+0xa6>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1178 <_right_trim+0x68>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_right_trim>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     115d <_right_trim+0x4d>
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     115d <_right_trim+0x4d>
lea    -0x1(%r14),%rcx
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x0,0x2(%rcx)
lea    0x1(%rcx),%rcx
jne    1130 <_right_trim+0x20>
jmp    1151 <_right_trim+0x41>
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1030 <isspace@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
je     1159 <_right_trim+0x49>
mov    %rcx,%rbx
cmp    %r14,%rcx
ja     1140 <_right_trim+0x30>
movb   $0x0,0x1(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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