#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*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, char);
char *strdup(char *);
int strlen(char *);
char *strstr(char *, char *);
char *rx_start(char *s, char **first) {
  char *s2, *m, *m2;
  char rx[] = "*.[]()|^$?+";
  char rxc[2];
  s2 = strdup(s);
  int l = 0;
  while (l < strlen(rx) - 1) {
    sprintf(rxc, "\\%c", rx[l]);
    while ((m = strstr(s2, rxc + 1))) {
      m2 = strstr(s2, rxc);
      if (m && (!m2 || (m2 && m2 + 1 != m)))
        *m = '\0';
    }
    l++;
  }
  if (strlen(s2) != strlen(s))
    *first = s + strlen(s2) + 1;
  else
    *first = NULL;
  free(s2);
  return (*first);
}


x86 assembly (clang, -O0):
<rx_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe99(%rip),%rax
mov    %rax,-0x34(%rbp)
mov    0xe97(%rip),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    -0x34(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    123d <rx_start+0xed>
lea    -0x36(%rbp),%rdi
movslq -0x3c(%rbp),%rax
lea    0xe56(%rip),%rsi
movsbl -0x34(%rbp,%rax,1),%edx
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x36(%rbp),%rsi
add    $0x1,%rsi
call   1070 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     122f <rx_start+0xdf>
mov    -0x18(%rbp),%rdi
lea    -0x36(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     122a <rx_start+0xda>
cmpq   $0x0,-0x28(%rbp)
je     1223 <rx_start+0xd3>
cmpq   $0x0,-0x28(%rbp)
je     122a <rx_start+0xda>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
cmp    -0x20(%rbp),%rax
je     122a <rx_start+0xda>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    11c0 <rx_start+0x70>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1188 <rx_start+0x38>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
je     1289 <rx_start+0x139>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rcx
cltq
add    %rax,%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1294 <rx_start+0x144>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rx_start>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x20(%rsp)
movabs $0x5e7c29285d5b2e2a,%rax
29 7c 5e
mov    %rax,0x8(%rsp)
movl   $0x2b3f24,0x10(%rsp)
mov    %rdi,0x18(%rsp)
call   1060 <strdup@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     1222 <rx_start+0xd2>
lea    0x7(%rsp),%r12
xor    %r13d,%r13d
lea    0x6(%rsp),%rbp
lea    0x8(%rsp),%r14
jmp    11c6 <rx_start+0x76>
xchg   %ax,%ax
add    $0x1,%r13
mov    %r14,%rdi
call   1040 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%r13
jge    1222 <rx_start+0xd2>
movsbl 0x8(%rsp,%r13,1),%edx
mov    %rbp,%rdi
lea    0xe36(%rip),%rsi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11b0 <rx_start+0x60>
mov    %rax,%r15
jmp    1207 <rx_start+0xb7>
movb   $0x0,(%r15)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <strstr@plt>
mov    %rax,%r15
test   %rax,%rax
je     11b0 <rx_start+0x60>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11f0 <rx_start+0xa0>
add    $0x1,%rax
cmp    %r15,%rax
je     11f4 <rx_start+0xa4>
jmp    11f0 <rx_start+0xa0>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r14d
jne    1243 <rx_start+0xf3>
xor    %ebp,%ebp
jmp    1254 <rx_start+0x104>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbp
add    $0x1,%rbp
mov    0x20(%rsp),%rax
mov    %rbp,(%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.rx_start.rx = [12 x i8] c"*.[]()|^$?+\00"
@.str = [4 x i8] c"\\%c\00"
define i8* @rx_start(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [12 x i8]
%9 = alloca [2 x i8]
%10 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%11 = bitcast [12 x i8]* %8 to i8*
%12 = load i8*, i8** %3
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %5
store i32 0, i32* %10
br label %14
14: ; preds = %53, %2
%15 = load i32, i32* %10
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %17, 1
%19 = icmp slt i32 %15, %18
br i1 %19, label %20, label %56
20: ; preds = %14
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %25)
br label %27
27: ; preds = %52, %20
%28 = load i8*, i8** %5
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = call i8* @strstr(i8* %28, i8* %30)
store i8* %31, i8** %6
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %53
33: ; preds = %27
%34 = load i8*, i8** %5
%35 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%36 = call i8* @strstr(i8* %34, i8* %35)
store i8* %36, i8** %7
%37 = load i8*, i8** %6
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %52
39: ; preds = %33
%40 = load i8*, i8** %7
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %50
42: ; preds = %39
%43 = load i8*, i8** %7
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = load i8*, i8** %7
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i8*, i8** %6
%49 = icmp ne i8* %47, %48
br i1 %49, label %50, label %52
50: ; preds = %45, %39
%51 = load i8*, i8** %6
store i8 0, i8* %51
br label %52
52: ; preds = %50, %45, %42, %33
br label %27
53: ; preds = %27
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %14
56: ; preds = %14
%57 = load i8*, i8** %5
%58 = call i32 @strlen(i8* %57)
%59 = load i8*, i8** %3
%60 = call i32 @strlen(i8* %59)
%61 = icmp ne i32 %58, %60
br i1 %61, label %62, label %70
62: ; preds = %56
%63 = load i8*, i8** %3
%64 = load i8*, i8** %5
%65 = call i32 @strlen(i8* %64)
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
%68 = getelementptr inbounds i8, i8* %67, i64 1
%69 = load i8**, i8*** %4
store i8* %68, i8** %69
br label %72
70: ; preds = %56
%71 = load i8**, i8*** %4
store i8* null, i8** %71
br label %72
72: ; preds = %70, %62
%73 = load i8*, i8** %5
%74 = call i32 @free(i8* %73)
%75 = load i8**, i8*** %4
%76 = load i8*, i8** %75
ret i8* %76
}

LLVM IR (-O2):
@__const.rx_start.rx = [12 x i8] c"*.[]()|^$?+\00"
@.str = [4 x i8] c"\\%c\00"
define i8* @rx_start(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca [12 x i8]
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @strdup(i8* %0)
%8 = call i32 @strlen(i8* %5)
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %36
10: ; preds = %2
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
br label %12
12: ; preds = %10, %30
%13 = phi i64 [ 0, %10 ], [ %31, %30 ]
%14 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %15)
%17 = call i8* @strstr(i8* dereferenceable(1) %7, i8* %11)
%18 = icmp eq i8* %17, null
br i1 %18, label %30, label %19
19: ; preds = %12, %27
%20 = phi i8* [ %28, %27 ], [ %17, %12 ]
%21 = call i8* @strstr(i8* dereferenceable(1) %7, i8* %6)
%22 = icmp ne i8* %21, null
%23 = getelementptr inbounds i8, i8* %21, i64 1
%24 = icmp eq i8* %23, %20
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %27, label %26
26: ; preds = %19
store i8 0, i8* %20
br label %27
27: ; preds = %19, %26
%28 = call i8* @strstr(i8* dereferenceable(1) %7, i8* %11)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %19
30: ; preds = %27, %12
%31 = add nuw nsw i64 %13, 1
%32 = call i32 @strlen(i8* %5)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %31, %34
br i1 %35, label %12, label %36
36: ; preds = %30, %2
%37 = call i32 @strlen(i8* %7)
%38 = call i32 @strlen(i8* %0)
%39 = icmp eq i32 %37, %38
br i1 %39, label %45, label %40
40: ; preds = %36
%41 = call i32 @strlen(i8* %7)
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %0, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 1
br label %45
45: ; preds = %36, %40
%46 = phi i8* [ %44, %40 ], [ null, %36 ]
store i8* %46, i8** %1
%47 = call i32 @free(i8* %7)
ret i8* %46
}