#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__ isblank(char);
int /*<<< orphan*/ memmove(char *, char *, int);
int strlen(char *);
char *strip(char *string) {
  char *start = string;
  while (isblank(*start))
    start++;
  int end = strlen(start);
  if (start != string) {
    memmove(string, start, end);
    string[end] = '\0';
  }
  while (isblank(*(string + end - 1)))
    end--;
  string[end] = '\0';
  return string;
}


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 <isblank@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     11a1 <strip+0x71>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11a6 <strip+0x76>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl -0x1(%rax,%rcx,1),%edi
call   1040 <isblank@plt>
cmp    $0x0,%rax
je     11d0 <strip+0xa0>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <strip+0x76>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
movsbl (%rbx,%rbp,1),%edi
call   1040 <isblank@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1140 <strip+0x10>
lea    (%rbx,%rbp,1),%r15
add    $0xffffffffffffffff,%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
cmp    $0x1,%rbp
je     1182 <strip+0x52>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <memmove@plt>
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    1185 <strip+0x55>
movslq %r14d,%rax
lea    (%rax,%rbx,1),%rbp
add    $0x1,%rbp
nopl   (%rax)
movsbl -0x2(%rbp),%edi
call   1040 <isblank@plt>
add    $0xffffffffffffffff,%rbp
test   %rax,%rax
jne    1190 <strip+0x60>
movb   $0x0,0x0(%rbp)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @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 @isblank(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 %29
20: ; preds = %14
%21 = load i8*, i8** %2
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = call i32 @memmove(i8* %21, i8* %22, i32 %23)
%25 = load i8*, i8** %2
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %20, %14
br label %30
30: ; preds = %39, %29
%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
%36 = load i8, i8* %35
%37 = call i64 @isblank(i8 signext %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %30
%40 = load i32, i32* %4
%41 = add nsw i32 %40, -1
store i32 %41, i32* %4
br label %30
42: ; preds = %30
%43 = load i8*, i8** %2
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 0, i8* %46
%47 = load i8*, i8** %2
ret i8* %47
}

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