#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__ emalloc(size_t);
scalar_t__ isalpha(char const);
size_t strlen(char const *);
char *sanitizer(char const *word) {
  size_t length = strlen(word);
  size_t current = 0;
  size_t index;
  char *result = (char *)emalloc(length + 1);
  for (index = 0; index < length; index++) {
    if (isalpha(word[index])) {
      result[current] = word[index];
      current++;
    }
  }
  result[current] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<sanitizer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1040 <emalloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11cb <sanitizer+0x9b>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     11b5 <sanitizer+0x85>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11ba <sanitizer+0x8a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116a <sanitizer+0x3a>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitizer>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
call   1040 <emalloc@plt>
mov    %rax,%r14
xor    %r13d,%r13d
test   %r15,%r15
je     1187 <sanitizer+0x57>
xor    %ebx,%ebx
jmp    1169 <sanitizer+0x39>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1187 <sanitizer+0x57>
movsbl (%r12,%rbx,1),%edi
call   1050 <isalpha@plt>
test   %rax,%rax
je     1160 <sanitizer+0x30>
movzbl (%r12,%rbx,1),%eax
mov    %al,(%r14,%r13,1)
add    $0x1,%r13
jmp    1160 <sanitizer+0x30>
movb   $0x0,(%r14,%r13,1)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @sanitizer(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 1
%4 = tail call i64 @emalloc(i64 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %2, 0
br i1 %6, label %22, label %7
7: ; preds = %1, %18
%8 = phi i64 [ %19, %18 ], [ 0, %1 ]
%9 = phi i64 [ %20, %18 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @isalpha(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %7
%15 = load i8, i8* %10
%16 = getelementptr inbounds i8, i8* %5, i64 %8
store i8 %15, i8* %16
%17 = add i64 %8, 1
br label %18
18: ; preds = %7, %14
%19 = phi i64 [ %17, %14 ], [ %8, %7 ]
%20 = add nuw i64 %9, 1
%21 = icmp eq i64 %20, %2
br i1 %21, label %22, label %7
22: ; preds = %18, %1
%23 = phi i64 [ 0, %1 ], [ %19, %18 ]
%24 = getelementptr inbounds i8, i8* %5, i64 %23
store i8 0, i8* %24
ret i8* %5
}