#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*/ assert(int);
scalar_t__ isspace(char);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char *);
char *r_trim(char *szOutput, const char *szInput) {
  char *p = NULL;
  assert(szInput != NULL);
  assert(szOutput != NULL);
  assert(szOutput != szInput);
  strcpy(szOutput, szInput);
  for (p = szOutput + strlen(szOutput) - 1; p >= szOutput && isspace(*p); --p) {
    ;
  }
  *(++p) = '\0';
  return szOutput;
}


x86 assembly (clang, -O0):
<r_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
jb     11ec <r_trim+0xac>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11fc <r_trim+0xbc>
jmp    1212 <r_trim+0xd2>
jmp    1201 <r_trim+0xc1>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11c3 <r_trim+0x83>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<r_trim>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1060 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmp    %r14,%r15
setne  %dil
call   1060 <assert@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%r15,1),%rcx
add    $0xffffffffffffffff,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rcx,%rbx
cmp    %r15,%rcx
jb     11b9 <r_trim+0x79>
movsbl (%rbx),%edi
call   1050 <isspace@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
jne    11a0 <r_trim+0x60>
movb   $0x0,0x1(%rbx)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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