#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__ xisblack(char);
scalar_t__ xiswhite(char);
char *xstrip(char *str) {
  char *s = str;
  char *d = str;
  while (xiswhite(*s)) {
    ++s;
  }
  char *e = str;
  while (*s) {
    if (xisblack(*s))
      e = d + 1;
    *d++ = *s++;
  }
  *e = 0;
  return str;
}


x86 assembly (clang, -O0):
<xstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <xiswhite@plt>
cmp    $0x0,%rax
je     1163 <xstrip+0x43>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113c <xstrip+0x1c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c1 <xstrip+0xa1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <xisblack@plt>
cmp    $0x0,%rax
je     119a <xstrip+0x7a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    116b <xstrip+0x4b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrip>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rdi,%rbx
xchg   %ax,%ax
movsbl (%rbx),%edi
call   1040 <xiswhite@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <xstrip+0x10>
mov    -0x1(%rbx),%al
mov    %r14,%r15
test   %al,%al
je     1187 <xstrip+0x67>
lea    0x1(%r14),%r12
mov    %r14,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <xisblack@plt>
test   %rax,%rax
cmovne %r12,%r15
movzbl -0x1(%rbx),%eax
mov    %al,-0x1(%r12)
movzbl (%rbx),%eax
add    $0x1,%r12
add    $0x1,%rbx
test   %al,%al
jne    1160 <xstrip+0x40>
movb   $0x0,(%r15)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @xstrip(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 @xiswhite(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 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %8, %11
%12 = phi i8 [ %22, %11 ], [ %9, %8 ]
%13 = phi i8* [ %19, %11 ], [ %0, %8 ]
%14 = phi i8* [ %18, %11 ], [ %0, %8 ]
%15 = phi i8* [ %20, %11 ], [ %3, %8 ]
%16 = tail call i64 @xisblack(i8 signext %12)
%17 = icmp eq i64 %16, 0
%18 = getelementptr inbounds i8, i8* %14, i64 1
%19 = select i1 %17, i8* %13, i8* %18
%20 = getelementptr inbounds i8, i8* %15, i64 1
%21 = load i8, i8* %15
store i8 %21, i8* %14
%22 = load i8, i8* %20
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %11
24: ; preds = %11, %8
%25 = phi i8* [ %0, %8 ], [ %19, %11 ]
store i8 0, i8* %25
ret i8* %0
}