#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 isGraphChar(char);
int gsft_space_elim(const char *src, size_t src_len, char *dest) {
  char *dest_ptr = dest;
  const char *src_ptr = src;
  int lastCharIsGraph = 0;
  for (size_t n = src_len; n != 0; n--) {
    char chr = *src_ptr++;
    if (chr == 0x00) {
      break;
    }
    if (!lastCharIsGraph && !isGraphChar(chr)) {
      continue;
    }
    *dest_ptr++ = chr;
    lastCharIsGraph = isGraphChar(chr);
  }
  *dest_ptr = 0x00;
  if (dest_ptr > dest) {
    char last_chr = *(dest_ptr - 1);
    if (!isGraphChar(last_chr)) {
      *(dest_ptr - 1) = 0x00;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<gsft_space_elim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11c6 <gsft_space_elim+0xb6>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%al
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%eax
cmp    $0x0,%eax
jne    1174 <gsft_space_elim+0x64>
jmp    11c6 <gsft_space_elim+0xb6>
cmpl   $0x0,-0x2c(%rbp)
jne    1195 <gsft_space_elim+0x85>
movsbl -0x39(%rbp),%edi
call   1030 <isGraphChar@plt>
cmp    $0x0,%eax
jne    1195 <gsft_space_elim+0x85>
jmp    11b5 <gsft_space_elim+0xa5>
mov    -0x39(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
movsbl -0x39(%rbp),%edi
call   1030 <isGraphChar@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
jmp    1143 <gsft_space_elim+0x33>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1204 <gsft_space_elim+0xf4>
mov    -0x20(%rbp),%rax
mov    -0x1(%rax),%al
mov    %al,-0x3a(%rbp)
movsbl -0x3a(%rbp),%edi
call   1030 <isGraphChar@plt>
cmp    $0x0,%eax
jne    11ff <gsft_space_elim+0xef>
mov    -0x20(%rbp),%rax
movb   $0x0,-0x1(%rax)
jmp    1204 <gsft_space_elim+0xf4>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsft_space_elim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1199 <gsft_space_elim+0x89>
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
mov    %rdx,(%rsp)
mov    %rdx,%r13
xor    %eax,%eax
jmp    1158 <gsft_space_elim+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14b,0x0(%r13)
add    $0x1,%r13
mov    %ebp,%edi
call   1030 <isGraphChar@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
je     1179 <gsft_space_elim+0x69>
movzbl (%r15,%rbx,1),%r14d
test   %r14b,%r14b
je     1179 <gsft_space_elim+0x69>
movsbl %r14b,%ebp
test   %eax,%eax
jne    1140 <gsft_space_elim+0x30>
mov    %ebp,%edi
call   1030 <isGraphChar@plt>
test   %eax,%eax
jne    1140 <gsft_space_elim+0x30>
xor    %eax,%eax
jmp    114f <gsft_space_elim+0x3f>
movb   $0x0,0x0(%r13)
cmp    (%rsp),%r13
jbe    119c <gsft_space_elim+0x8c>
movsbl -0x1(%r13),%edi
call   1030 <isGraphChar@plt>
test   %eax,%eax
jne    119c <gsft_space_elim+0x8c>
add    $0xffffffffffffffff,%r13
mov    %r13,%rdx
movb   $0x0,(%rdx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gsft_space_elim(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8
%12 = alloca i8
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%13 = load i8*, i8** %6
store i8* %13, i8** %7
%14 = load i8*, i8** %4
store i8* %14, i8** %8
store i32 0, i32* %9
%15 = load i64, i64* %5
store i64 %15, i64* %10
br label %16
16: ; preds = %41, %3
%17 = load i64, i64* %10
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %44
19: ; preds = %16
%20 = load i8*, i8** %8
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %8
%22 = load i8, i8* %20
store i8 %22, i8* %11
%23 = load i8, i8* %11
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19
br label %44
27: ; preds = %19
%28 = load i32, i32* %9
%29 = icmp ne i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %27
%31 = load i8, i8* %11
%32 = call i32 @isGraphChar(i8 signext %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %30
br label %41
35: ; preds = %30, %27
%36 = load i8, i8* %11
%37 = load i8*, i8** %7
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %7
store i8 %36, i8* %37
%39 = load i8, i8* %11
%40 = call i32 @isGraphChar(i8 signext %39)
store i32 %40, i32* %9
br label %41
41: ; preds = %35, %34
%42 = load i64, i64* %10
%43 = add i64 %42, -1
store i64 %43, i64* %10
br label %16
44: ; preds = %26, %16
%45 = load i8*, i8** %7
store i8 0, i8* %45
%46 = load i8*, i8** %7
%47 = load i8*, i8** %6
%48 = icmp ugt i8* %46, %47
br i1 %48, label %49, label %60
49: ; preds = %44
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i64 -1
%52 = load i8, i8* %51
store i8 %52, i8* %12
%53 = load i8, i8* %12
%54 = call i32 @isGraphChar(i8 signext %53)
%55 = icmp ne i32 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %49
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i64 -1
store i8 0, i8* %58
br label %59
59: ; preds = %56, %49
br label %60
60: ; preds = %59, %44
ret i32 0
}

LLVM IR (-O2):
define i32 @gsft_space_elim(i8* nocapture %0, i64 %1, i8* %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %34, label %5
5: ; preds = %3, %21
%6 = phi i8* [ %23, %21 ], [ %2, %3 ]
%7 = phi i8* [ %10, %21 ], [ %0, %3 ]
%8 = phi i64 [ %24, %21 ], [ %1, %3 ]
%9 = phi i32 [ %22, %21 ], [ 0, %3 ]
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = load i8, i8* %7
%12 = icmp eq i8 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %5
%14 = icmp eq i32 %9, 0
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = tail call i32 @isGraphChar(i8 signext %11)
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15, %13
%19 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %11, i8* %6
%20 = tail call i32 @isGraphChar(i8 signext %11)
br label %21
21: ; preds = %18, %15
%22 = phi i32 [ 0, %15 ], [ %20, %18 ]
%23 = phi i8* [ %6, %15 ], [ %19, %18 ]
%24 = add i64 %8, -1
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %5
26: ; preds = %21, %5
%27 = phi i8* [ %23, %21 ], [ %6, %5 ]
store i8 0, i8* %27
%28 = icmp ugt i8* %27, %2
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = getelementptr inbounds i8, i8* %27, i64 -1
%31 = load i8, i8* %30
%32 = tail call i32 @isGraphChar(i8 signext %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29, %3
%35 = phi i8* [ %2, %3 ], [ %30, %29 ]
store i8 0, i8* %35
br label %36
36: ; preds = %34, %29, %26
ret i32 0
}