#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*/ isspace(char);
int /*<<< orphan*/ memmove(char *, char *, long);
long strlen(char *);
char *_inplace_trim(char *in_string) {
  long len = strlen(in_string);
  for (long i = 0; i < len; i++) {
    if (!isspace(in_string[i])) {
      memmove(in_string, in_string + i, len - i + 1);
      break;
    }
  }
  len = strlen(in_string);
  for (long i = len - 1; i >= 0; i--) {
    if (!isspace(in_string[i])) {
      in_string[i + 1] = 0;
      break;
    }
  }
  return in_string;
}


x86 assembly (clang, -O0):
<_inplace_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11b1 <_inplace_trim+0x81>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    119b <_inplace_trim+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
sub    -0x18(%rbp),%rdx
add    $0x1,%rdx
call   1050 <memmove@plt>
jmp    11b1 <_inplace_trim+0x81>
jmp    11a0 <_inplace_trim+0x70>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <_inplace_trim+0x21>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     1217 <_inplace_trim+0xe7>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    1201 <_inplace_trim+0xd1>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
jmp    1217 <_inplace_trim+0xe7>
jmp    1206 <_inplace_trim+0xd6>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11ca <_inplace_trim+0x9a>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_inplace_trim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %rax,%rax
jle    117a <_inplace_trim+0x4a>
mov    %rax,%r15
add    $0x1,%r15
mov    %r14,%rbx
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
test   %eax,%eax
je     116c <_inplace_trim+0x3c>
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
cmp    $0x1,%r15
jne    1150 <_inplace_trim+0x20>
jmp    117a <_inplace_trim+0x4a>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <memmove@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
test   %rbx,%rbx
jle    11ae <_inplace_trim+0x7e>
movsbl -0x1(%r14,%rbx,1),%edi
call   1040 <isspace@plt>
add    $0xffffffffffffffff,%rbx
test   %eax,%eax
jne    1190 <_inplace_trim+0x60>
movb   $0x0,0x1(%r14,%rbx,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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