#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 /*<<< orphan*/ memmove(char *, char *, int);
int strlen(char *);
void strip(char *str) {
  char *p = str;
  int l;
  while ((isspace(*p))) {
    p++;
  }
  l = strlen(p);
  if (p != str) {
    memmove(str, p, l + 1);
  }
  if (!l) {
    return;
  }
  p = str + l - 1;
  while ((isspace(*p))) {
    *p-- = 0;
  }
}


x86 assembly (clang, -O0):
<strip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     116b <strip+0x3b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <strip+0x14>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     1198 <strip+0x68>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1050 <memmove@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11a7 <strip+0x77>
jmp    11e7 <strip+0xb7>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11e7 <strip+0xb7>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    11ba <strip+0x8a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
xor    %ebx,%ebx
nopl   (%rax)
movsbl (%r12,%rbx,1),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <strip+0x10>
lea    (%r12,%rbx,1),%r15
add    $0xffffffffffffffff,%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
cmp    $0x1,%rbx
je     117b <strip+0x4b>
lea    0x1(%r14),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <memmove@plt>
test   %r14d,%r14d
je     11b5 <strip+0x85>
movslq %r14d,%rbx
movsbl -0x1(%r12,%rbx,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     11b5 <strip+0x85>
add    %r12,%rbx
add    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    11a0 <strip+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @strip(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 signext %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 = icmp eq i8* %3, %0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = add nsw i32 %9, 1
%13 = tail call i32 @memmove(i8* %0, i8* %3, i32 %12)
br label %14
14: ; preds = %11, %8
%15 = icmp eq i32 %9, 0
br i1 %15, label %29, label %16
16: ; preds = %14
%17 = sext i32 %9 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 -1
%20 = load i8, i8* %19
%21 = tail call i64 @isspace(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %16, %23
%24 = phi i8* [ %25, %23 ], [ %19, %16 ]
store i8 0, i8* %24
%25 = getelementptr inbounds i8, i8* %24, i64 -1
%26 = load i8, i8* %25
%27 = tail call i64 @isspace(i8 signext %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %23
29: ; preds = %23, %16, %14
ret void
}