#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 */
int /*<<< orphan*/ assert(char *);
scalar_t__ isspace(char const);
int /*<<< orphan*/ memmove(char *, char const *, size_t);
int strlen(char const *);
void stripLeadingAndTrailingSpaces(char *string) {
  assert(string);
  const char *firstNonSpace = string;
  while (*firstNonSpace != '\0' && isspace(*firstNonSpace)) {
    ++firstNonSpace;
  }
  size_t len = strlen(firstNonSpace) + 1;
  memmove(string, firstNonSpace, len);
  char *endOfString = string + len;
  while (string < endOfString && isspace(*endOfString)) {
    --endOfString;
  }
  *endOfString = '\0';
}


x86 assembly (clang, -O0):
<stripLeadingAndTrailingSpaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     1188 <stripLeadingAndTrailingSpaces+0x48>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1198 <stripLeadingAndTrailingSpaces+0x58>
jmp    11a9 <stripLeadingAndTrailingSpaces+0x69>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115d <stripLeadingAndTrailingSpaces+0x1d>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <memmove@plt>
mov    -0x8(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x22(%rbp)
jae    1201 <stripLeadingAndTrailingSpaces+0xc1>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    1211 <stripLeadingAndTrailingSpaces+0xd1>
jmp    1222 <stripLeadingAndTrailingSpaces+0xe2>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11d8 <stripLeadingAndTrailingSpaces+0x98>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripLeadingAndTrailingSpaces>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1050 <assert@plt>
mov    (%r14),%al
mov    %r14,%rbx
test   %al,%al
je     1179 <stripLeadingAndTrailingSpaces+0x39>
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1179 <stripLeadingAndTrailingSpaces+0x39>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <stripLeadingAndTrailingSpaces+0x20>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%r15
lea    0x1(%r15),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <memmove@plt>
lea    (%r14,%r15,1),%rbx
add    $0x1,%rbx
test   %r15d,%r15d
js     11b6 <stripLeadingAndTrailingSpaces+0x76>
movsbl (%rbx),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     11b6 <stripLeadingAndTrailingSpaces+0x76>
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
ja     11a0 <stripLeadingAndTrailingSpaces+0x60>
movb   $0x0,(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @stripLeadingAndTrailingSpaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @assert(i8* %6)
%8 = load i8*, i8** %2
store i8* %8, i8** %3
br label %9
9: ; preds = %21, %1
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = call i64 @isspace(i8 signext %16)
%18 = icmp ne i64 %17, 0
br label %19
19: ; preds = %14, %9
%20 = phi i1 [ false, %9 ], [ %18, %14 ]
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
br label %9
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
store i64 %28, i64* %4
%29 = load i8*, i8** %2
%30 = load i8*, i8** %3
%31 = load i64, i64* %4
%32 = call i32 @memmove(i8* %29, i8* %30, i64 %31)
%33 = load i8*, i8** %2
%34 = load i64, i64* %4
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %5
br label %36
36: ; preds = %47, %24
%37 = load i8*, i8** %2
%38 = load i8*, i8** %5
%39 = icmp ult i8* %37, %38
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = call i64 @isspace(i8 signext %42)
%44 = icmp ne i64 %43, 0
br label %45
45: ; preds = %40, %36
%46 = phi i1 [ false, %36 ], [ %44, %40 ]
br i1 %46, label %47, label %50
47: ; preds = %45
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i32 -1
store i8* %49, i8** %5
br label %36
50: ; preds = %45
%51 = load i8*, i8** %5
store i8 0, i8* %51
ret void
}

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