#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__ u8isbasespacec(char *);
char *u8shiftc(char *, int);
char *u8trim(char *str) {
  while (u8isbasespacec(str) && *str != 0)
    ++str;
  char *end = str;
  while (*end != 0)
    end = u8shiftc(end, 1);
  for (end = u8shiftc(end, -1); u8isbasespacec(end); --end)
    *end = 0;
  return str;
}


x86 assembly (clang, -O0):
<u8trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <u8isbasespacec@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     1157 <u8trim+0x37>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1167 <u8trim+0x47>
jmp    1178 <u8trim+0x58>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112c <u8trim+0xc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a7 <u8trim+0x87>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <u8shiftc@plt>
mov    %rax,-0x10(%rbp)
jmp    1180 <u8trim+0x60>
mov    -0x10(%rbp),%rdi
mov    $0xffffffff,%esi
call   1040 <u8shiftc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <u8isbasespacec@plt>
cmp    $0x0,%rax
je     11e4 <u8trim+0xc4>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    11b9 <u8trim+0x99>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u8trim>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
nopw   0x0(%rax,%rax,1)
call   1030 <u8isbasespacec@plt>
test   %rax,%rax
je     1149 <u8trim+0x29>
cmpb   $0x0,(%r14)
je     1174 <u8trim+0x54>
add    $0x1,%r14
mov    %r14,%rdi
jmp    1130 <u8trim+0x10>
cmpb   $0x0,(%r14)
je     1174 <u8trim+0x54>
mov    %r14,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rdi
mov    $0x1,%esi
call   1040 <u8shiftc@plt>
cmpb   $0x0,(%rax)
jne    1160 <u8trim+0x40>
jmp    1177 <u8trim+0x57>
mov    %r14,%rax
mov    %rax,%rdi
mov    $0xffffffff,%esi
call   1040 <u8shiftc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <u8isbasespacec@plt>
test   %rax,%rax
je     11b5 <u8trim+0x95>
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x1(%rbx)
mov    %rbx,%rdi
call   1030 <u8isbasespacec@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    11a0 <u8trim+0x80>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @u8trim(i8* %0) {
%2 = tail call i64 @u8isbasespacec(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1, %8
%5 = phi i8* [ %9, %8 ], [ %0, %1 ]
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %5, i64 1
%10 = tail call i64 @u8isbasespacec(i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %4
12: ; preds = %8, %1
%13 = phi i8* [ %0, %1 ], [ %9, %8 ]
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12, %16
%17 = phi i8* [ %18, %16 ], [ %13, %12 ]
%18 = tail call i8* @u8shiftc(i8* %17, i32 1)
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %16
21: ; preds = %4, %16, %12
%22 = phi i8* [ %13, %12 ], [ %13, %16 ], [ %5, %4 ]
%23 = phi i8* [ %13, %12 ], [ %18, %16 ], [ %5, %4 ]
%24 = tail call i8* @u8shiftc(i8* %23, i32 -1)
%25 = tail call i64 @u8isbasespacec(i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %21, %27
%28 = phi i8* [ %29, %27 ], [ %24, %21 ]
store i8 0, i8* %28
%29 = getelementptr inbounds i8, i8* %28, i64 -1
%30 = tail call i64 @u8isbasespacec(i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %27
32: ; preds = %27, %21
ret i8* %22
}