#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);
int strlen(char *);
char *stripspace(char *s) {
  char *end = s + strlen(s) - 1;
  while (isspace(*s))
    s++;
  while (isspace(*end)) {
    *end-- = 0;
  }
  return s;
}


x86 assembly (clang, -O0):
<stripspace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1178 <stripspace+0x58>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1151 <stripspace+0x31>
jmp    117d <stripspace+0x5d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11aa <stripspace+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    117d <stripspace+0x5d>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripspace>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
movslq %eax,%r15
lea    -0x1(%r14),%r12
nopw   0x0(%rax,%rax,1)
movsbl 0x1(%r12),%edi
add    $0x1,%r12
call   1040 <isspace@plt>
test   %rax,%rax
jne    1140 <stripspace+0x20>
movsbl -0x1(%r14,%r15,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1185 <stripspace+0x65>
lea    (%r14,%r15,1),%rbx
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
movb   $0x0,(%rbx)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1170 <stripspace+0x50>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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