#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(unsigned char);
int strlen(char *);
void trim_spaces(char *input) {
  char *dst = input, *src = input;
  char *end;
  while (isspace((unsigned char)*src)) {
    ++src;
  }
  end = src + strlen(src) - 1;
  while (end > src && isspace((unsigned char)*end)) {
    *end-- = 0;
  }
  if (src != dst) {
    while ((*dst++ = *src++))
      ;
  }
}


x86 assembly (clang, -O0):
<trim_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1163 <trim_spaces+0x43>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113c <trim_spaces+0x1c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x29(%rbp)
jbe    11b1 <trim_spaces+0x91>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11c1 <trim_spaces+0xa1>
jmp    11d8 <trim_spaces+0xb8>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
jmp    1188 <trim_spaces+0x68>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     121f <trim_spaces+0xff>
jmp    11eb <trim_spaces+0xcb>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%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     121a <trim_spaces+0xfa>
jmp    11eb <trim_spaces+0xcb>
jmp    121f <trim_spaces+0xff>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_spaces>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
lea    -0x2(%rdi),%rbx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x2(%rbx),%edi
call   1040 <isspace@plt>
add    $0xffffffffffffffff,%r13
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <trim_spaces+0x20>
mov    %r13,%r15
not    %r15
add    %r14,%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
movslq %eax,%r12
add    %r14,%r12
sub    %r13,%r12
add    $0xfffffffffffffffe,%r12
cmp    %r15,%r12
jbe    119d <trim_spaces+0x7d>
nopl   0x0(%rax)
movzbl (%r12),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     119d <trim_spaces+0x7d>
movb   $0x0,(%r12)
add    $0xffffffffffffffff,%r12
cmp    %r15,%r12
ja     1180 <trim_spaces+0x60>
cmp    $0xffffffffffffffff,%r13
je     11c3 <trim_spaces+0xa3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r15),%eax
add    $0x1,%r15
mov    %al,(%r14)
add    $0x1,%r14
test   %al,%al
jne    11b0 <trim_spaces+0x90>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @trim_spaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
%7 = load i8*, i8** %2
store i8* %7, i8** %4
br label %8
8: ; preds = %13, %1
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = call i64 @isspace(i8 zeroext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
br label %8
16: ; preds = %8
%17 = load i8*, i8** %4
%18 = load i8*, i8** %4
%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 = %34, %16
%24 = load i8*, i8** %5
%25 = load i8*, i8** %4
%26 = icmp ugt 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 zeroext %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 %37
34: ; preds = %32
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i32 -1
store i8* %36, i8** %5
store i8 0, i8* %35
br label %23
37: ; preds = %32
%38 = load i8*, i8** %4
%39 = load i8*, i8** %3
%40 = icmp ne i8* %38, %39
br i1 %40, label %41, label %51
41: ; preds = %37
br label %42
42: ; preds = %49, %41
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %4
%45 = load i8, i8* %43
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %3
store i8 %45, i8* %46
%48 = icmp ne i8 %45, 0
br i1 %48, label %49, label %50
49: ; preds = %42
br label %42
50: ; preds = %42
br label %51
51: ; preds = %50, %37
ret void
}

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