#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__ is_alpha(char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void my_ansi_filter(char *source) {
  char result[500];
  int i, flag = 0, loc = 0;
  for (i = 0; i < strlen(source); i++) {
    if (source[i] == '') {
      flag = 1;
      continue;
    } else if (flag == 1 && is_alpha(source[i])) {
      flag = 0;
      continue;
    } else if (flag == 1) {
      continue;
    } else {
      result[loc++] = source[i];
    }
  }
  result[loc] = '\0';
  strncpy(source, result, loc + 1);
}


x86 assembly (clang, -O0):
<my_ansi_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x208(%rbp)
movl   $0x0,-0x20c(%rbp)
movl   $0x0,-0x204(%rbp)
mov    -0x204(%rbp),%eax
mov    %eax,-0x210(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x210(%rbp),%eax
cmp    %ecx,%eax
jge    1240 <my_ansi_filter+0x110>
mov    -0x8(%rbp),%rax
movslq -0x204(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x1b,%eax
jne    11a9 <my_ansi_filter+0x79>
movl   $0x1,-0x208(%rbp)
jmp    122c <my_ansi_filter+0xfc>
cmpl   $0x1,-0x208(%rbp)
jne    11e3 <my_ansi_filter+0xb3>
mov    -0x8(%rbp),%rax
movslq -0x204(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <is_alpha@plt>
cmp    $0x0,%rax
je     11e3 <my_ansi_filter+0xb3>
movl   $0x0,-0x208(%rbp)
jmp    122c <my_ansi_filter+0xfc>
cmpl   $0x1,-0x208(%rbp)
jne    11f5 <my_ansi_filter+0xc5>
jmp    122c <my_ansi_filter+0xfc>
mov    -0x8(%rbp),%rax
movslq -0x204(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x20c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x20c(%rbp)
cltq
mov    %cl,-0x200(%rbp,%rax,1)
jmp    1222 <my_ansi_filter+0xf2>
jmp    1227 <my_ansi_filter+0xf7>
jmp    122c <my_ansi_filter+0xfc>
mov    -0x204(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x204(%rbp)
jmp    115d <my_ansi_filter+0x2d>
movslq -0x20c(%rbp),%rax
movb   $0x0,-0x200(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x200(%rbp),%rsi
mov    -0x20c(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_ansi_filter>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1f8,%rsp
mov    %rdi,%r15
call   1040 <strlen@plt>
test   %eax,%eax
jle    11a6 <my_ansi_filter+0x76>
xor    %ebp,%ebp
xor    %r14d,%r14d
xor    %ecx,%ecx
jmp    1181 <my_ansi_filter+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %r14d,%rcx
add    $0x1,%r14d
mov    %al,(%rsp,%rcx,1)
xor    %ebx,%ebx
add    $0x1,%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
mov    %ebx,%ecx
cmp    %rax,%rbp
jge    11a9 <my_ansi_filter+0x79>
movzbl (%r15,%rbp,1),%eax
mov    $0x1,%ebx
cmp    $0x1b,%al
je     116c <my_ansi_filter+0x3c>
cmp    $0x1,%ecx
jne    1160 <my_ansi_filter+0x30>
movsbl %al,%edi
call   1050 <is_alpha@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
jmp    116c <my_ansi_filter+0x3c>
xor    %r14d,%r14d
movslq %r14d,%rdx
movb   $0x0,(%rsp,%rdx,1)
add    $0x1,%edx
mov    %rsp,%rsi
mov    %r15,%rdi
call   1030 <strncpy@plt>
add    $0x1f8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @my_ansi_filter(i8* %0) {
%2 = alloca [500 x i8]
%3 = getelementptr inbounds [500 x i8], [500 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 %30
6: ; preds = %1, %23
%7 = phi i64 [ %26, %23 ], [ 0, %1 ]
%8 = phi i32 [ %25, %23 ], [ 0, %1 ]
%9 = phi i32 [ %24, %23 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %7
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 27
br i1 %12, label %23, label %13
13: ; preds = %6
%14 = icmp eq i32 %9, 1
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = tail call i64 @is_alpha(i8 signext %11)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
br label %23
19: ; preds = %13
%20 = add nsw i32 %8, 1
%21 = sext i32 %8 to i64
%22 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 %21
store i8 %11, i8* %22
br label %23
23: ; preds = %15, %6, %19
%24 = phi i32 [ 0, %19 ], [ 1, %6 ], [ %18, %15 ]
%25 = phi i32 [ %20, %19 ], [ %8, %6 ], [ %8, %15 ]
%26 = add nuw nsw i64 %7, 1
%27 = tail call i32 @strlen(i8* %0)
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %6, label %30
30: ; preds = %23, %1
%31 = phi i32 [ 0, %1 ], [ %25, %23 ]
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 %32
store i8 0, i8* %33
%34 = add nsw i32 %31, 1
%35 = call i32 @strncpy(i8* %0, i8* %3, i32 %34)
ret void
}