#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*/ strcmp(char const *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
int does_esc_m(const char *cap) {
  const char *capptr;
  int seq;
  if (!strcmp(cap, "\x1b[m") || !strcmp(cap, "\x1b[0m"))
    return 1;
  if (strlen(cap) < 4)
    return 0;
  capptr = cap;
  seq = 0;
  while (*capptr != 0) {
    switch (seq) {
    case 0:
      if (!strncmp(capptr, "\x1b[", 2)) {
        capptr += 2;
        if (*capptr == 'm')
          return 1;
        else {
          seq = 1;
          continue;
        }
      }
      break;
    case 1:
      if (*capptr == '0')
        seq = 4;
      else if (*capptr > '0' && *capptr <= '9')
        seq = 2;
      else if (*capptr != ';')
        seq = 0;
      break;
    case 2:
      if (*capptr == ';')
        seq = 1;
      else if (!(*capptr >= '0' && *capptr <= '9'))
        seq = 0;
      break;
    case 4:
      if (*capptr == 'm')
        return 1;
      else if (!((*capptr >= '0' && *capptr <= '9') || *capptr == ';'))
        seq = 0;
      break;
    default:
      break;
    }
    capptr++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<does_esc_m>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xecd(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     116e <does_esc_m+0x3e>
mov    -0x10(%rbp),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    117a <does_esc_m+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    1368 <does_esc_m+0x238>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jge    1198 <does_esc_m+0x68>
movl   $0x0,-0x4(%rbp)
jmp    1368 <does_esc_m+0x238>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1361 <does_esc_m+0x231>
mov    -0x1c(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x4,%rax
ja     134b <does_esc_m+0x21b>
mov    -0x28(%rbp),%rax
lea    0xe2d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
lea    0xe36(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    122e <does_esc_m+0xfe>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6d,%eax
jne    1222 <does_esc_m+0xf2>
movl   $0x1,-0x4(%rbp)
jmp    1368 <does_esc_m+0x238>
movl   $0x1,-0x1c(%rbp)
jmp    11a7 <does_esc_m+0x77>
jmp    1350 <does_esc_m+0x220>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    124f <does_esc_m+0x11f>
movl   $0x4,-0x1c(%rbp)
jmp    129c <does_esc_m+0x16c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jle    127b <does_esc_m+0x14b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     127b <does_esc_m+0x14b>
movl   $0x2,-0x1c(%rbp)
jmp    1297 <does_esc_m+0x167>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     1292 <does_esc_m+0x162>
movl   $0x0,-0x1c(%rbp)
jmp    1297 <does_esc_m+0x167>
jmp    129c <does_esc_m+0x16c>
jmp    1350 <does_esc_m+0x220>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
jne    12bd <does_esc_m+0x18d>
movl   $0x1,-0x1c(%rbp)
jmp    12e9 <does_esc_m+0x1b9>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     12dd <does_esc_m+0x1ad>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    12e4 <does_esc_m+0x1b4>
movl   $0x0,-0x1c(%rbp)
jmp    12e9 <does_esc_m+0x1b9>
jmp    1350 <does_esc_m+0x220>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6d,%eax
jne    130a <does_esc_m+0x1da>
movl   $0x1,-0x4(%rbp)
jmp    1368 <does_esc_m+0x238>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     132a <does_esc_m+0x1fa>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    1341 <does_esc_m+0x211>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     1341 <does_esc_m+0x211>
movl   $0x0,-0x1c(%rbp)
jmp    1346 <does_esc_m+0x216>
jmp    1350 <does_esc_m+0x220>
jmp    1350 <does_esc_m+0x220>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a7 <does_esc_m+0x77>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<does_esc_m>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec2(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1251 <does_esc_m+0x121>
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1251 <does_esc_m+0x121>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x4,%ecx
jl     1256 <does_esc_m+0x126>
xor    %eax,%eax
lea    0xe89(%rip),%r14
mov    (%rbx),%cl
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
test   %cl,%cl
je     125e <does_esc_m+0x12e>
test   %eax,%eax
jne    11d0 <does_esc_m+0xa0>
lea    -0x1(%rbx),%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    124a <does_esc_m+0x11a>
movzbl 0x1(%rbx),%ecx
add    $0x2,%rbx
mov    $0x1,%eax
cmp    $0x6d,%cl
jne    1190 <does_esc_m+0x60>
jmp    1256 <does_esc_m+0x126>
nopl   0x0(%rax)
cmp    $0x1,%eax
je     11fe <does_esc_m+0xce>
cmp    $0x2,%eax
je     122a <does_esc_m+0xfa>
cmp    $0x4,%eax
jne    1180 <does_esc_m+0x50>
cmp    $0x6d,%cl
je     1251 <does_esc_m+0x121>
lea    -0x30(%rcx),%edx
mov    $0x4,%eax
cmp    $0xa,%dl
jb     1180 <does_esc_m+0x50>
xor    %eax,%eax
cmp    $0x3b,%cl
sete   %al
shl    $0x2,%eax
jmp    1180 <does_esc_m+0x50>
mov    $0x4,%eax
cmp    $0x30,%cl
je     1180 <does_esc_m+0x50>
lea    -0x31(%rcx),%edx
mov    $0x2,%eax
cmp    $0x9,%dl
jb     1180 <does_esc_m+0x50>
xor    %eax,%eax
cmp    $0x3b,%cl
sete   %al
jmp    1180 <does_esc_m+0x50>
mov    $0x1,%eax
cmp    $0x3b,%cl
je     1180 <does_esc_m+0x50>
add    $0xd0,%cl
xor    %eax,%eax
cmp    $0xa,%cl
setb   %al
add    %eax,%eax
jmp    1180 <does_esc_m+0x50>
xor    %eax,%eax
jmp    1180 <does_esc_m+0x50>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
jmp    1256 <does_esc_m+0x126>

LLVM IR (-O0):
@.str = [4 x i8] c"\1B[m\00"
@.str.1 = [5 x i8] c"\1B[0m\00"
@.str.2 = [3 x i8] c"\1B[\00"
define i32 @does_esc_m(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9, %1
store i32 1, i32* %2
br label %116
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %2
br label %116
19: ; preds = %14
%20 = load i8*, i8** %3
store i8* %20, i8** %4
store i32 0, i32* %5
br label %21
21: ; preds = %112, %40, %19
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %115
26: ; preds = %21
%27 = load i32, i32* %5
switch i32 %27, label %111 [
i32 0, label %28
i32 1, label %42
i32 2, label %68
i32 4, label %87
]
28: ; preds = %26
%29 = load i8*, i8** %4
%30 = call i32 @strncmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%31 = icmp ne i32 %30, 0
br i1 %31, label %41, label %32
32: ; preds = %28
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8* %34, i8** %4
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 109
br i1 %38, label %39, label %40
39: ; preds = %32
store i32 1, i32* %2
br label %116
40: ; preds = %32
store i32 1, i32* %5
br label %21
41: ; preds = %28
br label %112
42: ; preds = %26
%43 = load i8*, i8** %4
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 48
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 4, i32* %5
br label %67
48: ; preds = %42
%49 = load i8*, i8** %4
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp sgt i32 %51, 48
br i1 %52, label %53, label %59
53: ; preds = %48
%54 = load i8*, i8** %4
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp sle i32 %56, 57
br i1 %57, label %58, label %59
58: ; preds = %53
store i32 2, i32* %5
br label %66
59: ; preds = %53, %48
%60 = load i8*, i8** %4
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 59
br i1 %63, label %64, label %65
64: ; preds = %59
store i32 0, i32* %5
br label %65
65: ; preds = %64, %59
br label %66
66: ; preds = %65, %58
br label %67
67: ; preds = %66, %47
br label %112
68: ; preds = %26
%69 = load i8*, i8** %4
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 59
br i1 %72, label %73, label %74
73: ; preds = %68
store i32 1, i32* %5
br label %86
74: ; preds = %68
%75 = load i8*, i8** %4
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp sge i32 %77, 48
br i1 %78, label %79, label %84
79: ; preds = %74
%80 = load i8*, i8** %4
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp sle i32 %82, 57
br i1 %83, label %85, label %84
84: ; preds = %79, %74
store i32 0, i32* %5
br label %85
85: ; preds = %84, %79
br label %86
86: ; preds = %85, %73
br label %112
87: ; preds = %26
%88 = load i8*, i8** %4
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 109
br i1 %91, label %92, label %93
92: ; preds = %87
store i32 1, i32* %2
br label %116
93: ; preds = %87
%94 = load i8*, i8** %4
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = icmp sge i32 %96, 48
br i1 %97, label %98, label %103
98: ; preds = %93
%99 = load i8*, i8** %4
%100 = load i8, i8* %99
%101 = sext i8 %100 to i32
%102 = icmp sle i32 %101, 57
br i1 %102, label %109, label %103
103: ; preds = %98, %93
%104 = load i8*, i8** %4
%105 = load i8, i8* %104
%106 = sext i8 %105 to i32
%107 = icmp eq i32 %106, 59
br i1 %107, label %109, label %108
108: ; preds = %103
store i32 0, i32* %5
br label %109
109: ; preds = %108, %103, %98
br label %110
110: ; preds = %109
br label %112
111: ; preds = %26
br label %112
112: ; preds = %111, %110, %86, %67, %41
%113 = load i8*, i8** %4
%114 = getelementptr inbounds i8, i8* %113, i32 1
store i8* %114, i8** %4
br label %21
115: ; preds = %21
store i32 0, i32* %2
br label %116
116: ; preds = %115, %92, %39, %18, %13
%117 = load i32, i32* %2
ret i32 %117
}

LLVM IR (-O2):
@.str = [4 x i8] c"\1B[m\00"
@.str.1 = [5 x i8] c"\1B[0m\00"
@.str.2 = [3 x i8] c"\1B[\00"
define i32 @does_esc_m(i8* %0) {
%2 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %52, label %4
4: ; preds = %1
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %52, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp slt i32 %8, 4
br i1 %9, label %52, label %10
10: ; preds = %7, %49
%11 = phi i8* [ %51, %49 ], [ %0, %7 ]
%12 = phi i32 [ %50, %49 ], [ 0, %7 ]
%13 = load i8, i8* %11
br label %14
14: ; preds = %10, %23
%15 = phi i8 [ %13, %10 ], [ %25, %23 ]
%16 = phi i8* [ %11, %10 ], [ %24, %23 ]
%17 = phi i32 [ %12, %10 ], [ 1, %23 ]
%18 = icmp eq i8 %15, 0
br i1 %18, label %52, label %19
19: ; preds = %14
switch i32 %17, label %49 [
i32 0, label %20
i32 1, label %27
i32 2, label %35
i32 4, label %41
]
20: ; preds = %19
%21 = tail call i32 @strncmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %49
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %16, i64 2
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 109
br i1 %26, label %52, label %14
27: ; preds = %19
%28 = icmp eq i8 %15, 48
br i1 %28, label %49, label %29
29: ; preds = %27
%30 = add i8 %15, -49
%31 = icmp ult i8 %30, 9
br i1 %31, label %49, label %32
32: ; preds = %29
%33 = icmp eq i8 %15, 59
%34 = zext i1 %33 to i32
br label %49
35: ; preds = %19
%36 = icmp eq i8 %15, 59
br i1 %36, label %49, label %37
37: ; preds = %35
%38 = add i8 %15, -48
%39 = icmp ult i8 %38, 10
%40 = select i1 %39, i32 2, i32 0
br label %49
41: ; preds = %19
%42 = icmp eq i8 %15, 109
br i1 %42, label %52, label %43
43: ; preds = %41
%44 = add i8 %15, -48
%45 = icmp ult i8 %44, 10
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = icmp eq i8 %15, 59
%48 = select i1 %47, i32 4, i32 0
br label %49
49: ; preds = %19, %20, %37, %46, %32, %43, %35, %29, %27
%50 = phi i32 [ 4, %27 ], [ 2, %29 ], [ %34, %32 ], [ 1, %35 ], [ 4, %43 ], [ %48, %46 ], [ %40, %37 ], [ 0, %20 ], [ %17, %19 ]
%51 = getelementptr inbounds i8, i8* %16, i64 1
br label %10
52: ; preds = %41, %14, %23, %7, %1, %4
%53 = phi i32 [ 1, %4 ], [ 1, %1 ], [ 0, %7 ], [ 0, %14 ], [ 1, %23 ], [ 1, %41 ]
ret i32 %53
}