#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__ gather_esc_offsets(char const *, int /*<<< orphan*/ *,
                              char const **);
char *strchr(char const *, char);
int strlen(char const *);
const char *get_end_of_esc(const char *p) {
  const char *esc;
  const char *end = NULL;
  while ((esc = strchr(p, '\033'))) {
    if (gather_esc_offsets(esc, NULL, &end))
      break;
    p = esc + 1;
  }
  return end ? end + 1 : p + strlen(p);
}


x86 assembly (clang, -O0):
<get_end_of_esc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1191 <get_end_of_esc+0x61>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
call   1050 <gather_esc_offsets@plt>
cmp    $0x0,%rax
je     1180 <get_end_of_esc+0x50>
jmp    1191 <get_end_of_esc+0x61>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1144 <get_end_of_esc+0x14>
cmpq   $0x0,-0x18(%rbp)
je     11ad <get_end_of_esc+0x7d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ce <get_end_of_esc+0x9e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_end_of_esc>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
mov    $0x1b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ae <get_end_of_esc+0x7e>
mov    %rax,%r14
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <gather_esc_offsets@plt>
test   %rax,%rax
jne    119e <get_end_of_esc+0x6e>
lea    0x8(%rsp),%r15
mov    %r14,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x1b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     119e <get_end_of_esc+0x6e>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1050 <gather_esc_offsets@plt>
test   %rax,%rax
je     1170 <get_end_of_esc+0x40>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     11ae <get_end_of_esc+0x7e>
add    $0x1,%rax
jmp    11bb <get_end_of_esc+0x8b>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @get_end_of_esc(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %4
br label %5
5: ; preds = %14, %1
%6 = load i8*, i8** %2
%7 = call i8* @strchr(i8* %6, i8 signext 27)
store i8* %7, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %17
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = call i64 @gather_esc_offsets(i8* %10, i32* null, i8** %4)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
br label %17
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %16, i8** %2
br label %5
17: ; preds = %13, %5
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
br label %29
23: ; preds = %17
%24 = load i8*, i8** %2
%25 = load i8*, i8** %2
%26 = call i32 @strlen(i8* %25)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
br label %29
29: ; preds = %23, %20
%30 = phi i8* [ %22, %20 ], [ %28, %23 ]
ret i8* %30
}

LLVM IR (-O2):
define i8* @get_end_of_esc(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 27)
%5 = icmp eq i8* %4, null
br i1 %5, label %23, label %6
6: ; preds = %1
%7 = call i64 @gather_esc_offsets(i8* %4, i32* null, i8** %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %6, %14
%10 = phi i8* [ %12, %14 ], [ %4, %6 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = call i8* @strchr(i8* dereferenceable(1) %11, i8 signext 27)
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = call i64 @gather_esc_offsets(i8* %12, i32* null, i8** %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %9, label %17
17: ; preds = %14, %9, %6
%18 = phi i8* [ %0, %6 ], [ %11, %9 ], [ %11, %14 ]
%19 = load i8*, i8** %2
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %19, i64 1
br label %28
23: ; preds = %1, %17
%24 = phi i8* [ %18, %17 ], [ %0, %1 ]
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
br label %28
28: ; preds = %23, %21
%29 = phi i8* [ %22, %21 ], [ %27, %23 ]
ret i8* %29
}