#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*/ isgraph(char);
int /*<<< orphan*/ memmove(char *, char *, int);
int misc_trimnongraph(char *str, int len) {
  register int i = 0;
  for (i = 0; i < len;) {
    if (!isgraph(str[i]))
      memmove(&str[i], &str[i + 1], --len);
    else
      i++;
  }
  str[len] = '\0';
  return len;
}


x86 assembly (clang, -O0):
<misc_trimnongraph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119e <misc_trimnongraph+0x7e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isgraph@plt>
cmp    $0x0,%eax
jne    1190 <misc_trimnongraph+0x70>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rsi
mov    -0xc(%rbp),%edx
add    $0xffffffff,%edx
mov    %edx,-0xc(%rbp)
call   1030 <memmove@plt>
jmp    1199 <misc_trimnongraph+0x79>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113d <misc_trimnongraph+0x1d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<misc_trimnongraph>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
test   %esi,%esi
jle    1178 <misc_trimnongraph+0x58>
xor    %ebp,%ebp
jmp    115d <misc_trimnongraph+0x3d>
cs nopw 0x0(%rax,%rax,1)
nop
add    %r14,%rbx
movslq %ecx,%rsi
add    %r14,%rsi
add    $0xffffffff,%r15d
mov    %rbx,%rdi
mov    %r15d,%edx
call   1030 <memmove@plt>
cmp    %r15d,%ebp
jge    1178 <misc_trimnongraph+0x58>
movslq %ebp,%rbx
movsbl (%r14,%rbx,1),%edi
call   1040 <isgraph@plt>
lea    0x1(%rbx),%ecx
test   %eax,%eax
je     1140 <misc_trimnongraph+0x20>
mov    %ecx,%ebp
cmp    %r15d,%ebp
jl     115d <misc_trimnongraph+0x3d>
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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