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


x86 assembly (clang, -O0):
<get_end_of_text>:
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_text+0x61>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <gather_esc_offsets@plt>
cmp    $0x0,%rax
je     1180 <get_end_of_text+0x50>
jmp    1191 <get_end_of_text+0x61>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1144 <get_end_of_text+0x14>
cmpq   $0x0,-0x18(%rbp)
je     11a9 <get_end_of_text+0x79>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11ca <get_end_of_text+0x9a>
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_text>:
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     11a8 <get_end_of_text+0x78>
mov    %rax,%r14
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1050 <gather_esc_offsets@plt>
test   %rax,%rax
jne    119e <get_end_of_text+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_text+0x6e>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1050 <gather_esc_offsets@plt>
test   %rax,%rax
je     1170 <get_end_of_text+0x40>
mov    0x8(%rsp),%rax
test   %rax,%rax
jne    11b5 <get_end_of_text+0x85>
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_text(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, i8** %4, i32* null)
%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 %22
20: ; preds = %17
%21 = load i8*, i8** %4
br label %28
22: ; preds = %17
%23 = load i8*, i8** %2
%24 = load i8*, i8** %2
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
br label %28
28: ; preds = %22, %20
%29 = phi i8* [ %21, %20 ], [ %27, %22 ]
ret i8* %29
}

LLVM IR (-O2):
define i8* @get_end_of_text(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 %21, label %6
6: ; preds = %1
%7 = call i64 @gather_esc_offsets(i8* %4, i8** %2, i32* null)
%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, i8** %2, i32* null)
%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 %21, label %26
21: ; preds = %1, %17
%22 = phi i8* [ %18, %17 ], [ %0, %1 ]
%23 = call i32 @strlen(i8* %22)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
br label %26
26: ; preds = %17, %21
%27 = phi i8* [ %25, %21 ], [ %19, %17 ]
ret i8* %27
}