#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);
char *strtrim(char *s) {
  char *p;
  for (p = s; *p; p++)
    ;
  while (--p >= s && isspace(*p & 0xff))
    ;
  p[1] = 0;
  return s;
}


x86 assembly (clang, -O0):
<strtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1147 <strtrim+0x37>
jmp    1136 <strtrim+0x26>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <strtrim+0x14>
jmp    114c <strtrim+0x3c>
mov    -0x10(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x11(%rbp)
jb     1185 <strtrim+0x75>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xff,%eax
movsbl %al,%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1195 <strtrim+0x85>
jmp    119a <strtrim+0x8a>
jmp    114c <strtrim+0x3c>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtrim>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    -0x2(%rdi),%rcx
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x2(%rcx)
lea    0x1(%rcx),%rcx
jne    1120 <strtrim+0x10>
jmp    1141 <strtrim+0x31>
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1030 <isspace@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
je     1149 <strtrim+0x39>
mov    %rcx,%rbx
cmp    %r14,%rcx
jae    1130 <strtrim+0x20>
movb   $0x0,0x1(%rbx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @strtrim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
br label %5
5: ; preds = %10, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %5
br label %10
10: ; preds = %9
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
br label %5
13: ; preds = %5
br label %14
14: ; preds = %29, %13
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 -1
store i8* %16, i8** %3
%17 = load i8*, i8** %2
%18 = icmp uge i8* %16, %17
br i1 %18, label %19, label %27
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = and i32 %22, 255
%24 = trunc i32 %23 to i8
%25 = call i64 @isspace(i8 signext %24)
%26 = icmp ne i64 %25, 0
br label %27
27: ; preds = %19, %14
%28 = phi i1 [ false, %14 ], [ %26, %19 ]
br i1 %28, label %29, label %30
29: ; preds = %27
br label %14
30: ; preds = %27
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8 0, i8* %32
%33 = load i8*, i8** %2
ret i8* %33
}

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