#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__ strchr(char *, char);
scalar_t__ strlen(char *);
char *xmalloc(scalar_t__);
char *m330_cleanse(char *istring) {
  static char m330_valid_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ "
                                   "abcdefghijklmnopqrstuvwxyz"
                                   "0123456789+-.'/!@#<%^&>()=:\\";
  char *rstring = xmalloc(strlen(istring) + 1);
  char *o, *i;
  for (o = rstring, i = istring; *i; i++) {
    if (strchr(m330_valid_chars, *i)) {
      *o++ = *i;
    }
  }
  *o = 0;
  return rstring;
}


x86 assembly (clang, -O0):
<m330_cleanse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11bc <m330_cleanse+0x8c>
mov    -0x20(%rbp),%rax
lea    0x2ec3(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11a6 <m330_cleanse+0x76>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11ab <m330_cleanse+0x7b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1165 <m330_cleanse+0x35>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m330_cleanse>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <xmalloc@plt>
mov    %rax,%r14
mov    (%rbx),%al
mov    %r14,%r12
test   %al,%al
je     1199 <m330_cleanse+0x69>
add    $0x1,%rbx
lea    0x2ee0(%rip),%r15
mov    %r14,%r12
jmp    117b <m330_cleanse+0x4b>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1199 <m330_cleanse+0x69>
movsbl %al,%esi
mov    %r15,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1170 <m330_cleanse+0x40>
movzbl -0x1(%rbx),%eax
mov    %al,(%r12)
add    $0x1,%r12
jmp    1170 <m330_cleanse+0x40>
movb   $0x0,(%r12)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@m330_cleanse.m330_valid_chars = internal global [82 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789+-.'/!@#<%^&>()=:\\\00"
define i8* @m330_cleanse(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 1
%9 = call i8* @xmalloc(i64 %8)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
store i8* %10, i8** %4
%11 = load i8*, i8** %2
store i8* %11, i8** %5
br label %12
12: ; preds = %27, %1
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = call i64 @strchr(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @m330_cleanse.m330_valid_chars, i64 0, i64 0), i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
store i8 %23, i8* %24
br label %26
26: ; preds = %21, %16
br label %27
27: ; preds = %26
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
br label %12
30: ; preds = %12
%31 = load i8*, i8** %4
store i8 0, i8* %31
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
@m330_cleanse.m330_valid_chars = internal global [82 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789+-.'/!@#<%^&>()=:\\\00"
define i8* @m330_cleanse(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i8* @xmalloc(i64 %3)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %1, %16
%8 = phi i8 [ %19, %16 ], [ %5, %1 ]
%9 = phi i8* [ %18, %16 ], [ %0, %1 ]
%10 = phi i8* [ %17, %16 ], [ %4, %1 ]
%11 = tail call i64 @strchr(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @m330_cleanse.m330_valid_chars, i64 0, i64 0), i8 signext %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = load i8, i8* %9
%15 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %14, i8* %10
br label %16
16: ; preds = %7, %13
%17 = phi i8* [ %15, %13 ], [ %10, %7 ]
%18 = getelementptr inbounds i8, i8* %9, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %7
21: ; preds = %16, %1
%22 = phi i8* [ %4, %1 ], [ %17, %16 ]
store i8 0, i8* %22
ret i8* %4
}