#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*/ strlen(char *);
char *wr_trim(char *pBuf) {
  char *pNew = NULL;
  while (*pBuf <= ' ' && *pBuf != '\0') {
    ++pBuf;
  }
  pNew = pBuf;
  if (*pBuf != '\0') {
    pBuf += strlen(pBuf);
    while (*(--pBuf) <= ' ') {
      *pBuf = '\0';
    }
  }
  return pNew;
}


x86 assembly (clang, -O0):
<wr_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x11(%rbp)
jg     1149 <wr_trim+0x39>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1159 <wr_trim+0x49>
jmp    116a <wr_trim+0x5a>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1124 <wr_trim+0x14>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c8 <wr_trim+0xb8>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x8(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0x20,%eax
jg     11c3 <wr_trim+0xb3>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    119b <wr_trim+0x8b>
jmp    11c8 <wr_trim+0xb8>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wr_trim>:
push   %rbx
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0x20,%al
jg     1130 <wr_trim+0x20>
test   %al,%al
jne    1120 <wr_trim+0x10>
test   %al,%al
je     1160 <wr_trim+0x50>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x20,-0x1(%rbx,%rax,1)
jg     1160 <wr_trim+0x50>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,-0x1(%rbx,%rax,1)
cmpb   $0x21,-0x2(%rbx,%rax,1)
lea    -0x1(%rax),%rax
jl     1150 <wr_trim+0x40>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @wr_trim(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %8, %2 ]
%4 = load i8, i8* %3
%5 = icmp sgt i8 %4, 32
%6 = icmp eq i8 %4, 0
%7 = or i1 %5, %6
%8 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %7, label %9, label %2
9: ; preds = %2
br i1 %6, label %22, label %10
10: ; preds = %9
%11 = tail call i32 @strlen(i8* %3)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %3, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = load i8, i8* %14
%16 = icmp slt i8 %15, 33
br i1 %16, label %17, label %22
17: ; preds = %10, %17
%18 = phi i8* [ %19, %17 ], [ %14, %10 ]
store i8 0, i8* %18
%19 = getelementptr inbounds i8, i8* %18, i64 -1
%20 = load i8, i8* %19
%21 = icmp slt i8 %20, 33
br i1 %21, label %17, label %22
22: ; preds = %17, %10, %9
ret i8* %3
}