#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*/ isprint(char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void clean(char *string) {
  int loc = 0, i = 0;
  for (; i < strlen(string); i++) {
    if (!isprint(string[i])) {
      loc = i;
      break;
    }
  }
  if (loc > 0) {
    char newstr[1024];
    for (i = 0; i < loc; i++)
      newstr[i] = string[i];
    newstr[i++] = '\0';
    strcpy(string, newstr);
  }
}


x86 assembly (clang, -O0):
<clean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x414(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x414(%rbp),%eax
cmp    %ecx,%eax
jge    11a7 <clean+0x77>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isprint@plt>
cmp    $0x0,%eax
jne    1194 <clean+0x64>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11a7 <clean+0x77>
jmp    1199 <clean+0x69>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114d <clean+0x1d>
cmpl   $0x0,-0xc(%rbp)
jle    120d <clean+0xdd>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e8 <clean+0xb8>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b8 <clean+0x88>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
jle    11a7 <clean+0x67>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
call   1060 <isprint@plt>
test   %eax,%eax
je     1183 <clean+0x43>
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1160 <clean+0x20>
jmp    11a7 <clean+0x67>
test   %ebx,%ebx
je     11a7 <clean+0x67>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @clean(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %22, %1
%7 = load i32, i32* %4
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %25
11: ; preds = %6
%12 = load i8*, i8** %2
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @isprint(i8 signext %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %11
%20 = load i32, i32* %4
store i32 %20, i32* %3
br label %25
21: ; preds = %11
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %6
25: ; preds = %19, %6
%26 = load i32, i32* %3
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %53
28: ; preds = %25
store i32 0, i32* %4
br label %29
29: ; preds = %42, %28
%30 = load i32, i32* %4
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i8*, i8** %2
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %40
store i8 %38, i8* %41
br label %42
42: ; preds = %33
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %29
45: ; preds = %29
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %2
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%52 = call i32 @strcpy(i8* %50, i8* %51)
br label %53
53: ; preds = %45, %25
ret void
}

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