#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*/ strcpy(char *, char *);
int strcspn(char *, char *);
int brackrange(char *cp, int *start, int *length, char **endp) {
  char endstr[6];
  int endlen;
  int nest;
  int len;
  switch (*cp) {
  case '^':
    endstr[0] = cp[1];
    strcpy(endstr + 1, "\n");
    *start = 2;
    endlen = 1;
    break;
  case '<':
    strcpy(endstr, "<>\n");
    endlen = 1;
    *start = 1;
    break;
  default:
    return 0;
  }
  cp += *start;
  len = 0;
  nest = 1;
  while (nest) {
    int sublen;
    sublen = strcspn(cp + len, endstr);
    if (cp[len + sublen] == '<')
      nest++;
    else
      nest--;
    len += sublen;
  }
  *length = len;
  if (endp)
    *endp = cp + len + endlen;
  return 1;
}


x86 assembly (clang, -O0):
<brackrange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x44(%rbp)
sub    $0x3c,%eax
je     1195 <brackrange+0x75>
jmp    1150 <brackrange+0x30>
mov    -0x44(%rbp),%eax
sub    $0x5e,%eax
jne    11bb <brackrange+0x9b>
jmp    1161 <brackrange+0x41>
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x2e(%rbp)
lea    -0x2e(%rbp),%rdi
add    $0x1,%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movl   $0x2,(%rax)
movl   $0x1,-0x34(%rbp)
jmp    11c7 <brackrange+0xa7>
lea    -0x2e(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    11c7 <brackrange+0xa7>
movl   $0x0,-0x4(%rbp)
jmp    127d <brackrange+0x15d>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x1,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1249 <brackrange+0x129>
mov    -0x10(%rbp),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
lea    -0x2e(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    -0x40(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3c,%eax
jne    1232 <brackrange+0x112>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    123b <brackrange+0x11b>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    11e9 <brackrange+0xc9>
mov    -0x3c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1276 <brackrange+0x156>
mov    -0x10(%rbp),%rcx
movslq -0x3c(%rbp),%rax
add    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<brackrange>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
movsbl (%rdi),%ecx
cmp    $0x3c,%ecx
je     116a <brackrange+0x4a>
xor    %eax,%eax
cmp    $0x5e,%ecx
jne    11df <brackrange+0xbf>
mov    0x1(%r13),%al
mov    %al,0x2(%rsp)
lea    0x3(%rsp),%rdi
lea    0xea4(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x2,%eax
jmp    1180 <brackrange+0x60>
lea    0xe8f(%rip),%rsi
lea    0x2(%rsp),%rdi
call   1030 <strcpy@plt>
mov    $0x1,%eax
mov    %eax,(%r12)
mov    %eax,%eax
add    %rax,%r13
mov    $0x1,%ebp
xor    %ebx,%ebx
lea    0x2(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebx,%rbx
lea    (%rbx,%r13,1),%rdi
mov    %r12,%rsi
call   1040 <strcspn@plt>
add    %eax,%ebx
movslq %ebx,%rcx
xor    %eax,%eax
cmpb   $0x3c,0x0(%r13,%rcx,1)
sete   %al
lea    0x0(%rbp,%rax,2),%ebp
add    $0xffffffff,%ebp
jne    11a0 <brackrange+0x80>
mov    %ebx,(%r15)
mov    $0x1,%eax
test   %r14,%r14
je     11df <brackrange+0xbf>
add    %r13,%rcx
add    $0x1,%rcx
mov    %rcx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [4 x i8] c"<>\0A\00"
define i32 @brackrange(i8* %0, i32* %1, i32* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8**
%10 = alloca [6 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i8** %3, i8*** %9
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %31 [
i32 94, label %18
i32 60, label %27
]
18: ; preds = %4
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
store i8 %21, i8* %22
%23 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = load i32*, i32** %7
store i32 2, i32* %26
store i32 1, i32* %11
br label %32
27: ; preds = %4
%28 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %11
%30 = load i32*, i32** %7
store i32 1, i32* %30
br label %32
31: ; preds = %4
store i32 0, i32* %5
br label %82
32: ; preds = %27, %18
%33 = load i32*, i32** %7
%34 = load i32, i32* %33
%35 = load i8*, i8** %6
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8* %37, i8** %6
store i32 0, i32* %13
store i32 1, i32* %12
br label %38
38: ; preds = %63, %32
%39 = load i32, i32* %12
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %67
41: ; preds = %38
%42 = load i8*, i8** %6
%43 = load i32, i32* %13
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%47 = call i32 @strcspn(i8* %45, i8* %46)
store i32 %47, i32* %14
%48 = load i8*, i8** %6
%49 = load i32, i32* %13
%50 = load i32, i32* %14
%51 = add nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %48, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 60
br i1 %56, label %57, label %60
57: ; preds = %41
%58 = load i32, i32* %12
%59 = add nsw i32 %58, 1
store i32 %59, i32* %12
br label %63
60: ; preds = %41
%61 = load i32, i32* %12
%62 = add nsw i32 %61, -1
store i32 %62, i32* %12
br label %63
63: ; preds = %60, %57
%64 = load i32, i32* %14
%65 = load i32, i32* %13
%66 = add nsw i32 %65, %64
store i32 %66, i32* %13
br label %38
67: ; preds = %38
%68 = load i32, i32* %13
%69 = load i32*, i32** %8
store i32 %68, i32* %69
%70 = load i8**, i8*** %9
%71 = icmp ne i8** %70, null
br i1 %71, label %72, label %81
72: ; preds = %67
%73 = load i8*, i8** %6
%74 = load i32, i32* %13
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i32, i32* %11
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = load i8**, i8*** %9
store i8* %79, i8** %80
br label %81
81: ; preds = %72, %67
store i32 1, i32* %5
br label %82
82: ; preds = %81, %31
%83 = load i32, i32* %5
ret i32 %83
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [4 x i8] c"<>\0A\00"
define i32 @brackrange(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i8** writeonly %3) {
%5 = alloca [6 x i8]
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%7 = load i8, i8* %0
%8 = sext i8 %7 to i32
switch i32 %8, label %39 [
i32 94, label %9
i32 60, label %14
]
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
store i8 %11, i8* %6
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 1
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %16
14: ; preds = %4
%15 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = phi i32 [ 1, %14 ], [ 2, %9 ]
store i32 %17, i32* %1
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
br label %20
20: ; preds = %16, %20
%21 = phi i32 [ 0, %16 ], [ %26, %20 ]
%22 = phi i32 [ 1, %16 ], [ %32, %20 ]
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
%25 = call i32 @strcspn(i8* %24, i8* %6)
%26 = add nsw i32 %25, %21
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %19, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 60
%31 = select i1 %30, i32 1, i32 -1
%32 = add nsw i32 %31, %22
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %20
34: ; preds = %20
store i32 %26, i32* %2
%35 = icmp eq i8** %3, null
br i1 %35, label %39, label %36
36: ; preds = %34
%37 = getelementptr inbounds i8, i8* %19, i64 %27
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8* %38, i8** %3
br label %39
39: ; preds = %34, %36, %4
%40 = phi i32 [ 0, %4 ], [ 1, %36 ], [ 1, %34 ]
ret i32 %40
}