#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__ isalpha(char);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *cleanStr(char *s) {
  char *result = malloc(sizeof(char) * 256);
  char cToStr[2];
  cToStr[1] = '\0';
  for (int i = 0; i < strlen(s); i++) {
    if (isalpha(s[i]) || s[i] == ' ' || s[i] == '\'' || s[i] == '-' ||
        s[i] == '$') {
      cToStr[0] = s[i];
      strcat(result, cToStr);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<cleanStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    121e <cleanStr+0xde>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
jne    11f0 <cleanStr+0xb0>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     11f0 <cleanStr+0xb0>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x27,%eax
je     11f0 <cleanStr+0xb0>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
je     11f0 <cleanStr+0xb0>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x24,%eax
jne    120b <cleanStr+0xcb>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x12(%rbp),%rsi
call   1060 <strcat@plt>
jmp    1210 <cleanStr+0xd0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1165 <cleanStr+0x25>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanStr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r12
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
movb   $0x0,0xf(%rsp)
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11c4 <cleanStr+0x84>
xor    %ebx,%ebx
movabs $0x209100000000,%r13
lea    0xe(%rsp),%r15
nop
movsbl (%r12,%rbx,1),%edi
call   1050 <isalpha@plt>
movzbl (%r12,%rbx,1),%ecx
test   %rax,%rax
jne    11a2 <cleanStr+0x62>
cmp    $0x2d,%cl
ja     11b1 <cleanStr+0x71>
movzbl %cl,%eax
bt     %rax,%r13
jae    11b1 <cleanStr+0x71>
mov    %cl,0xe(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1180 <cleanStr+0x40>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @cleanStr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [2 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i8* @malloc(i32 256)
store i8* %6, i8** %3
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %7
store i32 0, i32* %5
br label %8
8: ; preds = %64, %1
%9 = load i32, i32* %5
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %67
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = call i64 @isalpha(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %53, label %21
21: ; preds = %13
%22 = load i8*, i8** %2
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 32
br i1 %28, label %53, label %29
29: ; preds = %21
%30 = load i8*, i8** %2
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 39
br i1 %36, label %53, label %37
37: ; preds = %29
%38 = load i8*, i8** %2
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 45
br i1 %44, label %53, label %45
45: ; preds = %37
%46 = load i8*, i8** %2
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 36
br i1 %52, label %53, label %63
53: ; preds = %45, %37, %29, %21, %13
%54 = load i8*, i8** %2
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 %58, i8* %59
%60 = load i8*, i8** %3
%61 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%62 = call i32 @strcat(i8* %60, i8* %61)
br label %63
63: ; preds = %53, %45
br label %64
64: ; preds = %63
%65 = load i32, i32* %5
%66 = add nsw i32 %65, 1
store i32 %66, i32* %5
br label %8
67: ; preds = %8
%68 = load i8*, i8** %3
ret i8* %68
}

LLVM IR (-O2):
define i8* @cleanStr(i8* %0) {
%2 = alloca [2 x i8]
%3 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 0, i8* %5
%6 = call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %19, %1
ret i8* %3
9: ; preds = %1, %19
%10 = phi i64 [ %20, %19 ], [ 0, %1 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = call i64 @isalpha(i8 signext %12)
%14 = icmp eq i64 %13, 0
%15 = load i8, i8* %11
br i1 %14, label %16, label %17
16: ; preds = %9
switch i8 %15, label %19 [
i8 32, label %17
i8 39, label %17
i8 45, label %17
i8 36, label %17
]
17: ; preds = %9, %16, %16, %16, %16
store i8 %15, i8* %4
%18 = call i32 @strcat(i8* %3, i8* %4)
br label %19
19: ; preds = %16, %17
%20 = add nuw nsw i64 %10, 1
%21 = call i32 @strlen(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %9, label %8
}