#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);
void trim(char *s) {
  char *d = s;
  while (isspace(*s++))
    ;
  s--;
  while (*d++ = *s++)
    ;
  d--;
  while (isspace(*--d))
    *d = 0;
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     114a <trim+0x3a>
jmp    1124 <trim+0x14>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %al,(%rcx)
cmp    $0x0,%al
je     1185 <trim+0x75>
jmp    1156 <trim+0x46>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movsbl -0x1(%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     11bf <trim+0xaf>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1191 <trim+0x81>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    %rdi,%r15
nopl   0x0(%rax,%rax,1)
movsbl (%r15),%edi
add    $0x1,%r15
call   1030 <isspace@plt>
test   %rax,%rax
jne    1120 <trim+0x10>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%r15,%rbx,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
test   %al,%al
jne    1140 <trim+0x30>
movsbl -0x2(%r14,%rbx,1),%edi
call   1030 <isspace@plt>
test   %rax,%rax
je     1185 <trim+0x75>
add    %r14,%rbx
add    $0xfffffffffffffffe,%rbx
nopl   0x0(%rax)
movb   $0x0,(%rbx)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1030 <isspace@plt>
test   %rax,%rax
jne    1170 <trim+0x60>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @trim(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 = %11, %1
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %7, i8** %2
%8 = load i8, i8* %6
%9 = call i64 @isspace(i8 signext %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %5
br label %5
12: ; preds = %5
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i32 -1
store i8* %14, i8** %2
br label %15
15: ; preds = %22, %12
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %2
%18 = load i8, i8* %16
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
store i8 %18, i8* %19
%21 = icmp ne i8 %18, 0
br i1 %21, label %22, label %23
22: ; preds = %15
br label %15
23: ; preds = %15
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %3
br label %26
26: ; preds = %32, %23
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %3
%29 = load i8, i8* %28
%30 = call i64 @isspace(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = load i8*, i8** %3
store i8 0, i8* %33
br label %26
34: ; preds = %26
ret void
}

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