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


x86 assembly (clang, -O0):
<a_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),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <l_trim@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     11d7 <a_trim+0x97>
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    11e7 <a_trim+0xa7>
jmp    11fd <a_trim+0xbd>
jmp    11ec <a_trim+0xac>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11ae <a_trim+0x6e>
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):
<a_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>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <l_trim@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%r15,1),%rcx
add    $0xffffffffffffffff,%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rcx,%rbx
cmp    %r15,%rcx
jb     11a9 <a_trim+0x69>
movsbl (%rbx),%edi
call   1050 <isspace@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
jne    1190 <a_trim+0x50>
movb   $0x0,0x1(%rbx)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @a_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 = call i32 @l_trim(i8* %14, i8* %15)
%17 = load i8*, i8** %3
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 -1
store i8* %22, i8** %5
br label %23
23: ; preds = %35, %2
%24 = load i8*, i8** %5
%25 = load i8*, i8** %3
%26 = icmp uge i8* %24, %25
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = call i64 @isspace(i8 signext %29)
%31 = icmp ne i64 %30, 0
br label %32
32: ; preds = %27, %23
%33 = phi i1 [ false, %23 ], [ %31, %27 ]
br i1 %33, label %34, label %38
34: ; preds = %32
br label %35
35: ; preds = %34
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i32 -1
store i8* %37, i8** %5
br label %23
38: ; preds = %32
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
store i8 0, i8* %40
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
define i8* @a_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 = tail call i32 @l_trim(i8* %0, i8* %1)
%10 = tail call i32 @strlen(i8* %0)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
br label %13
13: ; preds = %17, %2
%14 = phi i8* [ %12, %2 ], [ %15, %17 ]
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = icmp ult i8* %15, %0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i8, i8* %15
%19 = tail call i64 @isspace(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %13
21: ; preds = %13, %17
store i8 0, i8* %14
ret i8* %0
}