#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__ is_ws(char);
void despace(char str[]) {
  int e;
  for (e = 0; str[e] != '\0'; ++e)
    ;
  for (--e; is_ws(str[e]) && e >= 0; --e)
    ;
  str[e + 1] = '\0';
}


x86 assembly (clang, -O0):
<despace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     114b <despace+0x3b>
jmp    113d <despace+0x2d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <despace+0x13>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <is_ws@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xd(%rbp)
je     1181 <despace+0x71>
cmpl   $0x0,-0xc(%rbp)
setge  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1191 <despace+0x81>
jmp    11a4 <despace+0x94>
jmp    1196 <despace+0x86>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1154 <despace+0x44>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<despace>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
movabs $0xffffffff00000000,%r15
ff ff ff
mov    $0xffffffff,%r12d
movabs $0x100000000,%rax
mov    %rdi,%rcx
mov    %r15,%rbx
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12d
add    %rax,%rbx
cmpb   $0x0,(%rcx)
lea    0x1(%rcx),%rcx
jne    1140 <despace+0x30>
sar    $0x20,%rbx
shl    $0x20,%r12
add    %rax,%r12
nopl   0x0(%rax,%rax,1)
movsbl -0x1(%r14,%rbx,1),%edi
call   1030 <is_ws@plt>
add    %r15,%r12
test   %rax,%rax
je     117f <despace+0x6f>
lea    -0x1(%rbx),%rax
test   %rbx,%rbx
mov    %rax,%rbx
jg     1160 <despace+0x50>
sar    $0x20,%r12
movb   $0x0,(%r14,%r12,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @despace(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %7, %2 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
%7 = add nuw i64 %3, 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = shl i64 %3, 32
%10 = ashr exact i64 %9, 32
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ %10, %8 ], [ %13, %11 ]
%13 = add nsw i64 %12, -1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = tail call i64 @is_ws(i8 signext %15)
%17 = icmp ne i64 %16, 0
%18 = icmp sgt i64 %12, 0
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %11, label %20
20: ; preds = %11
%21 = shl i64 %12, 32
%22 = ashr exact i64 %21, 32
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 0, i8* %23
ret void
}