#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 */
int /*<<< orphan*/ memcmp(char *, char const *, int);
int isAnsiEscape(const char *buf, size_t buf_len, size_t *len) {
  if (buf_len > 2 && !memcmp("\033[", buf, 2)) {
    size_t off = 2;
    while (off < buf_len) {
      switch (buf[off++]) {
      case 'A':
      case 'B':
      case 'C':
      case 'D':
      case 'E':
      case 'F':
      case 'G':
      case 'H':
      case 'J':
      case 'K':
      case 'S':
      case 'T':
      case 'f':
      case 'm':
        *len = off;
        return 1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<isAnsiEscape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x2,-0x18(%rbp)
jbe    11f9 <isAnsiEscape+0xe9>
mov    -0x10(%rbp),%rsi
lea    0xec6(%rip),%rdi
mov    $0x2,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    11f9 <isAnsiEscape+0xe9>
movq   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11f4 <isAnsiEscape+0xe4>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
add    $0xffffffbf,%eax
sub    $0x8,%eax
jb     11d8 <isAnsiEscape+0xc8>
jmp    118e <isAnsiEscape+0x7e>
mov    -0x2c(%rbp),%eax
add    $0xffffffb6,%eax
sub    $0x2,%eax
jb     11d8 <isAnsiEscape+0xc8>
jmp    11a2 <isAnsiEscape+0x92>
mov    -0x2c(%rbp),%eax
add    $0xffffffad,%eax
sub    $0x2,%eax
jb     11d8 <isAnsiEscape+0xc8>
jmp    11b6 <isAnsiEscape+0xa6>
mov    -0x2c(%rbp),%eax
sub    $0x66,%eax
je     11d8 <isAnsiEscape+0xc8>
jmp    11c7 <isAnsiEscape+0xb7>
mov    -0x2c(%rbp),%eax
sub    $0x6d,%eax
jne    11ef <isAnsiEscape+0xdf>
jmp    11d8 <isAnsiEscape+0xc8>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1200 <isAnsiEscape+0xf0>
jmp    1155 <isAnsiEscape+0x45>
jmp    11f9 <isAnsiEscape+0xe9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isAnsiEscape>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
cmp    $0x3,%rsi
jb     1175 <isAnsiEscape+0x65>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xed0(%rip),%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
jne    1175 <isAnsiEscape+0x65>
mov    $0x2,%eax
movabs $0x1020000c06ff,%rcx
cmp    %rax,%rbx
je     1175 <isAnsiEscape+0x65>
movsbl 0x0(%rbp,%rax,1),%edx
add    $0x1,%rax
add    $0xffffffbf,%edx
cmp    $0x2c,%edx
ja     1150 <isAnsiEscape+0x40>
bt     %rdx,%rcx
jae    1150 <isAnsiEscape+0x40>
mov    %rax,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\1B[\00"
define i32 @isAnsiEscape(i8* %0, i64 %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64* %2, i64** %7
%9 = load i64, i64* %6
%10 = icmp ugt i64 %9, 2
br i1 %10, label %11, label %32
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = call i32 @memcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12, i32 2)
%14 = icmp ne i32 %13, 0
br i1 %14, label %32, label %15
15: ; preds = %11
store i64 2, i64* %8
br label %16
16: ; preds = %30, %15
%17 = load i64, i64* %8
%18 = load i64, i64* %6
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = load i8*, i8** %5
%22 = load i64, i64* %8
%23 = add i64 %22, 1
store i64 %23, i64* %8
%24 = getelementptr inbounds i8, i8* %21, i64 %22
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
switch i32 %26, label %30 [
i32 65, label %27
i32 66, label %27
i32 67, label %27
i32 68, label %27
i32 69, label %27
i32 70, label %27
i32 71, label %27
i32 72, label %27
i32 74, label %27
i32 75, label %27
i32 83, label %27
i32 84, label %27
i32 102, label %27
i32 109, label %27
]
27: ; preds = %20, %20, %20, %20, %20, %20, %20, %20, %20, %20, %20, %20, %20, %20
%28 = load i64, i64* %8
%29 = load i64*, i64** %7
store i64 %28, i64* %29
store i32 1, i32* %4
br label %33
30: ; preds = %20
br label %16
31: ; preds = %16
br label %32
32: ; preds = %31, %11, %3
store i32 0, i32* %4
br label %33
33: ; preds = %32, %27
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"\1B[\00"
define i32 @isAnsiEscape(i8* %0, i64 %1, i64* nocapture writeonly %2) {
%4 = icmp ugt i64 %1, 2
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = tail call i32 @memcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0, i32 2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %5, %11
%9 = phi i64 [ %12, %11 ], [ 2, %5 ]
%10 = icmp eq i64 %9, %1
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = add i64 %9, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %9
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %8 [
i32 65, label %16
i32 66, label %16
i32 67, label %16
i32 68, label %16
i32 69, label %16
i32 70, label %16
i32 71, label %16
i32 72, label %16
i32 74, label %16
i32 75, label %16
i32 83, label %16
i32 84, label %16
i32 102, label %16
i32 109, label %16
]
16: ; preds = %11, %11, %11, %11, %11, %11, %11, %11, %11, %11, %11, %11, %11, %11
store i64 %12, i64* %2
br label %17
17: ; preds = %8, %3, %5, %16
%18 = phi i32 [ 1, %16 ], [ 0, %5 ], [ 0, %3 ], [ 0, %8 ]
ret i32 %18
}