#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*/ isalnum(char);
int _find_next_substitution(char *string, char **start, char **end) {
  char *str_ptr;
  int escaped = 0;
  int in_literal_quote = 0;
  int in_brace = 0;
  int variable = 0;
  int found = 0;
  int end_of_word;
  *start = NULL;
  *end = NULL;
  for (str_ptr = string; *str_ptr != '\0' && !found; str_ptr++) {
    switch (*str_ptr) {
    case '\'':
      in_literal_quote = !escaped && !in_literal_quote;
      escaped = 0;
      break;
    case '\\':
      escaped = !escaped;
      break;
    case '$':
      if (!escaped && !in_literal_quote) {
        variable = 1;
        *start = str_ptr;
      }
      escaped = 0;
      break;
    case '{':
      in_brace = variable && !escaped;
      break;
    case '}':
      if (in_brace) {
        *end = str_ptr;
        found = 1;
      }
      break;
    default:
      end_of_word = !isalnum(*(str_ptr + 1)) && *(str_ptr + 1) != '_' ||
                    *(str_ptr + 1) == '\0';
      if (variable && !in_brace && end_of_word) {
        *end = str_ptr;
        found = 1;
      }
      escaped = 0;
      break;
    }
  }
  return found;
}


x86 assembly (clang, -O0):
<_find_next_substitution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     1186 <_find_next_substitution+0x76>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1196 <_find_next_substitution+0x86>
jmp    134d <_find_next_substitution+0x23d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x40(%rbp)
sub    $0x24,%eax
je     123a <_find_next_substitution+0x12a>
jmp    11ae <_find_next_substitution+0x9e>
mov    -0x40(%rbp),%eax
sub    $0x27,%eax
je     11f2 <_find_next_substitution+0xe2>
jmp    11bf <_find_next_substitution+0xaf>
mov    -0x40(%rbp),%eax
sub    $0x5c,%eax
je     1224 <_find_next_substitution+0x114>
jmp    11d0 <_find_next_substitution+0xc0>
mov    -0x40(%rbp),%eax
sub    $0x7b,%eax
je     126c <_find_next_substitution+0x15c>
jmp    11e1 <_find_next_substitution+0xd1>
mov    -0x40(%rbp),%eax
sub    $0x7d,%eax
je     1297 <_find_next_substitution+0x187>
jmp    12b8 <_find_next_substitution+0x1a8>
xor    %eax,%eax
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x41(%rbp)
jne    120d <_find_next_substitution+0xfd>
cmpl   $0x0,-0x28(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    1337 <_find_next_substitution+0x227>
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
jmp    1337 <_find_next_substitution+0x227>
cmpl   $0x0,-0x24(%rbp)
jne    1260 <_find_next_substitution+0x150>
cmpl   $0x0,-0x28(%rbp)
jne    1260 <_find_next_substitution+0x150>
movl   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
jmp    1337 <_find_next_substitution+0x227>
xor    %eax,%eax
cmpl   $0x0,-0x30(%rbp)
mov    %al,-0x42(%rbp)
je     1287 <_find_next_substitution+0x177>
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x42(%rbp)
mov    -0x42(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
jmp    1337 <_find_next_substitution+0x227>
cmpl   $0x0,-0x2c(%rbp)
je     12b3 <_find_next_substitution+0x1a3>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x34(%rbp)
jmp    1337 <_find_next_substitution+0x227>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%eax
jne    12e4 <_find_next_substitution+0x1d4>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%ecx
mov    $0x1,%al
cmp    $0x5f,%ecx
mov    %al,-0x43(%rbp)
jne    12f5 <_find_next_substitution+0x1e5>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x43(%rbp)
mov    -0x43(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1330 <_find_next_substitution+0x220>
cmpl   $0x0,-0x2c(%rbp)
jne    1330 <_find_next_substitution+0x220>
cmpl   $0x0,-0x38(%rbp)
je     1330 <_find_next_substitution+0x220>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    133c <_find_next_substitution+0x22c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1165 <_find_next_substitution+0x55>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_find_next_substitution>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movq   $0x0,(%rsi)
movq   $0x0,(%rdx)
mov    (%rdi),%cl
test   %cl,%cl
je     121c <_find_next_substitution+0x10c>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %r12d,%r12d
xor    %ebp,%ebp
xor    %r13d,%r13d
xor    %eax,%eax
jmp    1170 <_find_next_substitution+0x60>
test   %r12d,%r12d
setne  %cl
test   %eax,%eax
sete   %dl
and    %cl,%dl
movzbl %dl,%ebp
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     121c <_find_next_substitution+0x10c>
movsbl %cl,%ecx
cmp    $0x5b,%ecx
jle    11a0 <_find_next_substitution+0x90>
cmp    $0x5c,%ecx
je     11b9 <_find_next_substitution+0xa9>
cmp    $0x7b,%ecx
je     1148 <_find_next_substitution+0x38>
cmp    $0x7d,%ecx
jne    11cd <_find_next_substitution+0xbd>
test   %ebp,%ebp
mov    $0x0,%ebp
je     1160 <_find_next_substitution+0x50>
jmp    122d <_find_next_substitution+0x11d>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x24,%ecx
je     11c4 <_find_next_substitution+0xb4>
cmp    $0x27,%ecx
jne    11cd <_find_next_substitution+0xbd>
xor    %ecx,%ecx
or     %r13d,%eax
sete   %cl
xor    %eax,%eax
mov    %ecx,%r13d
jmp    1160 <_find_next_substitution+0x50>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
jmp    1160 <_find_next_substitution+0x50>
or     %r13d,%eax
je     1209 <_find_next_substitution+0xf9>
xor    %eax,%eax
jmp    1160 <_find_next_substitution+0x50>
movsbl 0x1(%rbx),%edi
call   1030 <isalnum@plt>
movzbl 0x1(%rbx),%edx
test   %eax,%eax
jne    11e7 <_find_next_substitution+0xd7>
mov    $0x1,%cl
cmp    $0x5f,%dl
mov    $0x5f,%dl
jne    11ec <_find_next_substitution+0xdc>
test   %dl,%dl
sete   %cl
xor    %eax,%eax
test   %r12d,%r12d
je     1160 <_find_next_substitution+0x50>
test   %ebp,%ebp
jne    1160 <_find_next_substitution+0x50>
test   %cl,%cl
je     1160 <_find_next_substitution+0x50>
jmp    122d <_find_next_substitution+0x11d>
mov    %rbx,(%r15)
mov    $0x1,%r12d
xor    %eax,%eax
xor    %r13d,%r13d
jmp    1160 <_find_next_substitution+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,(%r14)
mov    $0x1,%eax
jmp    121e <_find_next_substitution+0x10e>

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

LLVM IR (-O2):
define i32 @_find_next_substitution(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
store i8* null, i8** %1
store i8* null, i8** %2
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %60, label %6
6: ; preds = %3, %51
%7 = phi i8 [ %57, %51 ], [ %4, %3 ]
%8 = phi i8* [ %56, %51 ], [ %0, %3 ]
%9 = phi i32 [ %55, %51 ], [ 0, %3 ]
%10 = phi i32 [ %54, %51 ], [ 0, %3 ]
%11 = phi i32 [ %53, %51 ], [ 0, %3 ]
%12 = phi i32 [ %52, %51 ], [ 0, %3 ]
%13 = sext i8 %7 to i32
switch i32 %13, label %34 [
i32 39, label %14
i32 92, label %19
i32 36, label %22
i32 123, label %27
i32 125, label %32
]
14: ; preds = %6
%15 = icmp eq i32 %12, 0
%16 = icmp eq i32 %11, 0
%17 = select i1 %15, i1 %16, i1 false
%18 = zext i1 %17 to i32
br label %51
19: ; preds = %6
%20 = icmp eq i32 %12, 0
%21 = zext i1 %20 to i32
br label %51
22: ; preds = %6
%23 = icmp ne i32 %12, 0
%24 = icmp ne i32 %11, 0
%25 = select i1 %23, i1 true, i1 %24
br i1 %25, label %51, label %26
26: ; preds = %22
store i8* %8, i8** %1
br label %51
27: ; preds = %6
%28 = icmp ne i32 %9, 0
%29 = icmp eq i32 %12, 0
%30 = select i1 %28, i1 %29, i1 false
%31 = zext i1 %30 to i32
br label %51
32: ; preds = %6
%33 = icmp eq i32 %10, 0
br i1 %33, label %51, label %59
34: ; preds = %6
%35 = getelementptr inbounds i8, i8* %8, i64 1
%36 = load i8, i8* %35
%37 = tail call i32 @isalnum(i8 signext %36)
%38 = icmp eq i32 %37, 0
%39 = load i8, i8* %35
br i1 %38, label %40, label %42
40: ; preds = %34
%41 = icmp eq i8 %39, 95
br i1 %41, label %42, label %45
42: ; preds = %34, %40
%43 = phi i8 [ 95, %40 ], [ %39, %34 ]
%44 = icmp eq i8 %43, 0
br label %45
45: ; preds = %42, %40
%46 = phi i1 [ true, %40 ], [ %44, %42 ]
%47 = icmp ne i32 %9, 0
%48 = icmp eq i32 %10, 0
%49 = select i1 %47, i1 %48, i1 false
%50 = select i1 %49, i1 %46, i1 false
br i1 %50, label %59, label %51
51: ; preds = %45, %22, %26, %14, %19, %27, %32
%52 = phi i32 [ %12, %32 ], [ %12, %27 ], [ %21, %19 ], [ 0, %14 ], [ 0, %26 ], [ 0, %22 ], [ 0, %45 ]
%53 = phi i32 [ %11, %32 ], [ %11, %27 ], [ %11, %19 ], [ %18, %14 ], [ 0, %26 ], [ %11, %22 ], [ %11, %45 ]
%54 = phi i32 [ 0, %32 ], [ %31, %27 ], [ %10, %19 ], [ %10, %14 ], [ %10, %26 ], [ %10, %22 ], [ %10, %45 ]
%55 = phi i32 [ %9, %32 ], [ %9, %27 ], [ %9, %19 ], [ %9, %14 ], [ 1, %26 ], [ %9, %22 ], [ %9, %45 ]
%56 = getelementptr inbounds i8, i8* %8, i64 1
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 0
br i1 %58, label %60, label %6
59: ; preds = %45, %32
store i8* %8, i8** %2
br label %60
60: ; preds = %51, %59, %3
%61 = phi i32 [ 0, %3 ], [ 1, %59 ], [ 0, %51 ]
ret i32 %61
}