#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*/ strcpy(char *, char *);
int strlen(char *);
int strspn(char *, char *);
void stripws(char *p) {
  int l;
  l = strspn(p, " ");
  if (l != 0)
    strcpy(p, p + l);
  l = strlen(p);
  while (--l >= 0) {
    if (*(p + l) != ' ')
      break;
  }
  *(p + l + 1) = '\0';
}


x86 assembly (clang, -O0):
<stripws>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strspn@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     116d <stripws+0x3d>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     11aa <stripws+0x7a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     11a5 <stripws+0x75>
jmp    11aa <stripws+0x7a>
jmp    1179 <stripws+0x49>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripws>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rsi
call   1050 <strspn@plt>
test   %eax,%eax
je     1152 <stripws+0x22>
movslq %eax,%rsi
add    %rbx,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
xor    %ecx,%ecx
test   %eax,%eax
cmovs  %eax,%ecx
add    $0xffffffff,%ecx
cs nopw 0x0(%rax,%rax,1)
test   %edx,%edx
jle    1182 <stripws+0x52>
add    $0xffffffffffffffff,%rdx
mov    %edx,%eax
cmpb   $0x20,(%rbx,%rax,1)
je     1170 <stripws+0x40>
mov    %edx,%ecx
movslq %ecx,%rax
movb   $0x0,0x1(%rbx,%rax,1)
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define void @stripws(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strspn(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = call i32 @strcpy(i8* %9, i8* %13)
br label %15
15: ; preds = %8, %1
%16 = load i8*, i8** %2
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %3
br label %18
18: ; preds = %31, %15
%19 = load i32, i32* %3
%20 = add nsw i32 %19, -1
store i32 %20, i32* %3
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 32
br i1 %29, label %30, label %31
30: ; preds = %22
br label %32
31: ; preds = %22
br label %18
32: ; preds = %30, %18
%33 = load i8*, i8** %2
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8 0, i8* %37
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @stripws(i8* %0) {
%2 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = tail call i32 @strcpy(i8* %0, i8* %6)
br label %8
8: ; preds = %4, %1
%9 = tail call i32 @strlen(i8* %0)
%10 = zext i32 %9 to i64
%11 = call i32 @llvm.smin.i32(i32 %9, i32 0)
%12 = add i32 %11, -1
br label %13
13: ; preds = %18, %8
%14 = phi i64 [ %15, %18 ], [ %10, %8 ]
%15 = add nsw i64 %14, -1
%16 = trunc i64 %14 to i32
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %13
%19 = and i64 %15, 4294967295
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 32
br i1 %22, label %13, label %23
23: ; preds = %18
%24 = trunc i64 %15 to i32
br label %25
25: ; preds = %13, %23
%26 = phi i32 [ %24, %23 ], [ %12, %13 ]
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 0, i8* %29
ret void
}