#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);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *ansi_filter(char *source) {
  char *result, ch[3];
  int i, flag = 0, slen = strlen(source);
  result = (char *)malloc((slen + 10) * sizeof(char));
  for (i = 0; i < slen; i++) {
    if (source[i] == '') {
      flag = 1;
      continue;
    } else if (flag == 1 && is_alpha(source[i])) {
      flag = 0;
      continue;
    } else if (flag == 1) {
      continue;
    } else {
      sprintf(ch, "%c", source[i]);
      strcat(result, ch);
    }
  }
  return (char *)result;
}


x86 assembly (clang, -O0):
<ansi_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0xa,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1240 <ansi_filter+0xf0>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x1b,%eax
jne    11ba <ansi_filter+0x6a>
movl   $0x1,-0x1c(%rbp)
jmp    1232 <ansi_filter+0xe2>
cmpl   $0x1,-0x1c(%rbp)
jne    11eb <ansi_filter+0x9b>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <is_alpha@plt>
cmp    $0x0,%rax
je     11eb <ansi_filter+0x9b>
movl   $0x0,-0x1c(%rbp)
jmp    1232 <ansi_filter+0xe2>
cmpl   $0x1,-0x1c(%rbp)
jne    11fa <ansi_filter+0xaa>
jmp    1232 <ansi_filter+0xe2>
lea    -0x13(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xdf3(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x13(%rbp),%rsi
call   1050 <strcat@plt>
jmp    1228 <ansi_filter+0xd8>
jmp    122d <ansi_filter+0xdd>
jmp    1232 <ansi_filter+0xe2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118d <ansi_filter+0x3d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ansi_filter>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%r15d
lea    0xa(%r15),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    11c7 <ansi_filter+0x87>
mov    %r15d,%r13d
xor    %ebx,%ebx
lea    0xd(%rsp),%r15
xor    %eax,%eax
jmp    11a1 <ansi_filter+0x61>
nopw   0x0(%rax,%rax,1)
mov    %dl,0xd(%rsp)
movb   $0x0,0xe(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
xor    %ecx,%ecx
add    $0x1,%rbx
mov    %ecx,%eax
cmp    %rbx,%r13
je     11c7 <ansi_filter+0x87>
movzbl (%r12,%rbx,1),%edx
mov    $0x1,%ecx
cmp    $0x1b,%dl
je     1196 <ansi_filter+0x56>
cmp    $0x1,%eax
jne    1180 <ansi_filter+0x40>
movsbl %dl,%edi
call   1060 <is_alpha@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
jmp    1196 <ansi_filter+0x56>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define i8* @ansi_filter(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [3 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %6
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = add nsw i32 %10, 10
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %3
store i32 0, i32* %5
br label %17
17: ; preds = %60, %1
%18 = load i32, i32* %5
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %63
21: ; preds = %17
%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, 27
br i1 %28, label %29, label %30
29: ; preds = %21
store i32 1, i32* %6
br label %60
30: ; preds = %21
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load i8*, i8** %2
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = call i64 @is_alpha(i8 signext %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 0, i32* %6
br label %60
42: ; preds = %33, %30
%43 = load i32, i32* %6
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %46
45: ; preds = %42
br label %60
46: ; preds = %42
%47 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%48 = load i8*, i8** %2
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %52)
%54 = load i8*, i8** %3
%55 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%56 = call i32 @strcat(i8* %54, i8* %55)
br label %57
57: ; preds = %46
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
br label %60
60: ; preds = %59, %45, %41, %29
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %17
63: ; preds = %17
%64 = load i8*, i8** %3
ret i8* %64
}

LLVM IR (-O2):
define i8* @ansi_filter(i8* %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 10
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp sgt i32 %4, 0
br i1 %8, label %9, label %30
9: ; preds = %1
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
%11 = zext i32 %4 to i64
br label %12
12: ; preds = %9, %26
%13 = phi i64 [ 0, %9 ], [ %28, %26 ]
%14 = phi i32 [ 0, %9 ], [ %27, %26 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %13
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 27
br i1 %17, label %26, label %18
18: ; preds = %12
%19 = icmp eq i32 %14, 1
br i1 %19, label %20, label %24
20: ; preds = %18
%21 = call i64 @is_alpha(i8 signext %16)
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
br label %26
24: ; preds = %18
store i8 %16, i8* %3
store i8 0, i8* %10
%25 = call i32 @strcat(i8* %7, i8* %3)
br label %26
26: ; preds = %20, %12, %24
%27 = phi i32 [ 0, %24 ], [ 1, %12 ], [ %23, %20 ]
%28 = add nuw nsw i64 %13, 1
%29 = icmp eq i64 %28, %11
br i1 %29, label %30, label %12
30: ; preds = %26, %1
ret i8* %7
}