#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__ isgraph(char const);
char *malloc(int);
char *substringcln(const char *start, const char *end) {
  char *result = malloc(end - start + 1);
  char *scan_result = result;
  const char *scan = start;
  while (scan < end) {
    if (isgraph(*scan))
      *scan_result++ = *scan;
    scan++;
  }
  *scan_result = 0;
  return result;
}


x86 assembly (clang, -O0):
<substringcln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a6 <substringcln+0x86>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isgraph@plt>
cmp    $0x0,%rax
je     1195 <substringcln+0x75>
mov    -0x28(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    115a <substringcln+0x3a>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<substringcln>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
sub    %r12,%rdi
add    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
mov    %rax,%r13
sub    %r12,%r14
jbe    1177 <substringcln+0x57>
xor    %ebx,%ebx
mov    %r15,%r13
jmp    1159 <substringcln+0x39>
nop
add    $0x1,%rbx
cmp    %rbx,%r14
je     1177 <substringcln+0x57>
movsbl (%r12,%rbx,1),%edi
call   1040 <isgraph@plt>
test   %rax,%rax
je     1150 <substringcln+0x30>
movzbl (%r12,%rbx,1),%eax
mov    %al,0x0(%r13)
add    $0x1,%r13
jmp    1150 <substringcln+0x30>
movb   $0x0,0x0(%r13)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i8* @substringcln(i8* %0, i8* %1) {
%3 = ptrtoint i8* %0 to i64
%4 = ptrtoint i8* %1 to i64
%5 = sub i64 %4, %3
%6 = trunc i64 %5 to i32
%7 = add i32 %6, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp ult i8* %0, %1
br i1 %9, label %10, label %25
10: ; preds = %2
%11 = getelementptr i8, i8* %0, i64 %5
br label %12
12: ; preds = %10, %21
%13 = phi i8* [ %23, %21 ], [ %0, %10 ]
%14 = phi i8* [ %22, %21 ], [ %8, %10 ]
%15 = load i8, i8* %13
%16 = tail call i64 @isgraph(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = load i8, i8* %13
%20 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %19, i8* %14
br label %21
21: ; preds = %18, %12
%22 = phi i8* [ %20, %18 ], [ %14, %12 ]
%23 = getelementptr inbounds i8, i8* %13, i64 1
%24 = icmp eq i8* %23, %11
br i1 %24, label %25, label %12
25: ; preds = %21, %2
%26 = phi i8* [ %8, %2 ], [ %22, %21 ]
store i8 0, i8* %26
ret i8* %8
}