#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 toascii(unsigned char);
unsigned char HTCleanTelnetString(char *str) {
  char *cur = str;
  if (!str)
    return 0;
  while (*cur) {
    int a = toascii((unsigned char)*cur);
    if (a != 0x9 && (a < 0x20 || (a > 0x7E && a < 0xA0) || a > 0xFE)) {
      ;
      *cur = 0;
      ;
      return 1;
    }
    cur++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<HTCleanTelnetString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1138 <HTCleanTelnetString+0x28>
movb   $0x0,-0x1(%rbp)
jmp    11b6 <HTCleanTelnetString+0xa6>
jmp    113d <HTCleanTelnetString+0x2d>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b2 <HTCleanTelnetString+0xa2>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <toascii@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x9,-0x1c(%rbp)
je     11a1 <HTCleanTelnetString+0x91>
cmpl   $0x20,-0x1c(%rbp)
jl     1191 <HTCleanTelnetString+0x81>
cmpl   $0x7e,-0x1c(%rbp)
jle    1184 <HTCleanTelnetString+0x74>
cmpl   $0xa0,-0x1c(%rbp)
jl     1191 <HTCleanTelnetString+0x81>
cmpl   $0xfe,-0x1c(%rbp)
jle    11a1 <HTCleanTelnetString+0x91>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movb   $0x1,-0x1(%rbp)
jmp    11b6 <HTCleanTelnetString+0xa6>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113d <HTCleanTelnetString+0x2d>
movb   $0x0,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HTCleanTelnetString>:
push   %rbx
test   %rdi,%rdi
je     1164 <HTCleanTelnetString+0x54>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1164 <HTCleanTelnetString+0x54>
add    $0x1,%rbx
jmp    113b <HTCleanTelnetString+0x2b>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1164 <HTCleanTelnetString+0x54>
movzbl %al,%edi
call   1030 <toascii@plt>
cmp    $0x9,%eax
je     1130 <HTCleanTelnetString+0x20>
cmp    $0x20,%eax
jl     115c <HTCleanTelnetString+0x4c>
cmp    $0xfe,%eax
ja     115c <HTCleanTelnetString+0x4c>
add    $0xffffff81,%eax
cmp    $0x20,%eax
ja     1130 <HTCleanTelnetString+0x20>
movb   $0x0,-0x1(%rbx)
mov    $0x1,%al
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define zeroext i8 @HTCleanTelnetString(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %3, %19
%7 = phi i8 [ %21, %19 ], [ %4, %3 ]
%8 = phi i8* [ %20, %19 ], [ %0, %3 ]
%9 = tail call i32 @toascii(i8 zeroext %7)
%10 = icmp eq i32 %9, 9
br i1 %10, label %19, label %11
11: ; preds = %6
%12 = icmp slt i32 %9, 32
br i1 %12, label %18, label %13
13: ; preds = %11
%14 = add nsw i32 %9, -127
%15 = icmp ult i32 %14, 33
%16 = icmp ugt i32 %9, 254
%17 = or i1 %16, %15
br i1 %17, label %18, label %19
18: ; preds = %11, %13
store i8 0, i8* %8
br label %23
19: ; preds = %6, %13
%20 = getelementptr inbounds i8, i8* %8, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %6
23: ; preds = %19, %3, %18, %1
%24 = phi i8 [ 0, %1 ], [ 1, %18 ], [ 0, %3 ], [ 0, %19 ]
ret i8 %24
}