#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*/ DoTrace(char *);
int /*<<< orphan*/ TracePrintf(char *, void *, void *);
char *XTL_FindComment(char *);
char *XTL_FindClosingSquareBrace(char *line, int *Braces) {
  char *p;
  char *comment;
  TracePrintf("start - XTL_FindClosingSquareBrace, %p, %p\n", (void *)line,
              (void *)Braces);
  if (line == NULL || *line == 0 || Braces == NULL || *Braces < 1)
    return NULL;
  DoTrace("in - XTL_FindClosingSquareBrace");
  comment = XTL_FindComment(line);
  for (p = line; *p != 0; p++) {
    switch (*p) {
    case '\\':
      ++p;
      if (*p == 0)
        --p;
      break;
    case '[':
      ++(*Braces);
      break;
    case ']':
      --(*Braces);
      if (*Braces == 0) {
        DoTrace("out1 - XTL_FindClosingSquareBrace");
        return p;
      }
      break;
    case '%':
      if (comment != NULL && p == comment) {
        DoTrace("out2 - XTL_FindClosingSquareBrace");
        return NULL;
      }
      break;
    }
  }
  DoTrace("out - XTL_FindClosingSquareBrace");
  return NULL;
}


x86 assembly (clang, -O0):
<XTL_FindClosingSquareBrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xeb1(%rip),%rdi
call   1050 <TracePrintf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1187 <XTL_FindClosingSquareBrace+0x57>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1187 <XTL_FindClosingSquareBrace+0x57>
cmpq   $0x0,-0x18(%rbp)
je     1187 <XTL_FindClosingSquareBrace+0x57>
mov    -0x18(%rbp),%rax
cmpl   $0x1,(%rax)
jge    1194 <XTL_FindClosingSquareBrace+0x64>
movq   $0x0,-0x8(%rbp)
jmp    12e4 <XTL_FindClosingSquareBrace+0x1b4>
lea    0xe91(%rip),%rdi
call   1030 <DoTrace@plt>
mov    -0x10(%rbp),%rdi
call   1040 <XTL_FindComment@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12d0 <XTL_FindClosingSquareBrace+0x1a0>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x25,%eax
je     1283 <XTL_FindClosingSquareBrace+0x153>
jmp    11dd <XTL_FindClosingSquareBrace+0xad>
mov    -0x2c(%rbp),%eax
sub    $0x5b,%eax
je     123d <XTL_FindClosingSquareBrace+0x10d>
jmp    11ee <XTL_FindClosingSquareBrace+0xbe>
mov    -0x2c(%rbp),%eax
sub    $0x5c,%eax
je     1210 <XTL_FindClosingSquareBrace+0xe0>
jmp    11ff <XTL_FindClosingSquareBrace+0xcf>
mov    -0x2c(%rbp),%eax
sub    $0x5d,%eax
je     124d <XTL_FindClosingSquareBrace+0x11d>
jmp    12ba <XTL_FindClosingSquareBrace+0x18a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1238 <XTL_FindClosingSquareBrace+0x108>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    12ba <XTL_FindClosingSquareBrace+0x18a>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    12ba <XTL_FindClosingSquareBrace+0x18a>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    127e <XTL_FindClosingSquareBrace+0x14e>
lea    0xde0(%rip),%rdi
call   1030 <DoTrace@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12e4 <XTL_FindClosingSquareBrace+0x1b4>
jmp    12ba <XTL_FindClosingSquareBrace+0x18a>
cmpq   $0x0,-0x28(%rbp)
je     12b5 <XTL_FindClosingSquareBrace+0x185>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    12b5 <XTL_FindClosingSquareBrace+0x185>
lea    0xdcb(%rip),%rdi
call   1030 <DoTrace@plt>
movq   $0x0,-0x8(%rbp)
jmp    12e4 <XTL_FindClosingSquareBrace+0x1b4>
jmp    12ba <XTL_FindClosingSquareBrace+0x18a>
jmp    12bf <XTL_FindClosingSquareBrace+0x18f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11b5 <XTL_FindClosingSquareBrace+0x85>
lea    0xdb9(%rip),%rdi
call   1030 <DoTrace@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XTL_FindClosingSquareBrace>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xebf(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <TracePrintf@plt>
xor    %eax,%eax
test   %rbx,%rbx
je     122b <XTL_FindClosingSquareBrace+0xfb>
test   %r14,%r14
je     122b <XTL_FindClosingSquareBrace+0xfb>
cmpb   $0x0,(%rbx)
je     122b <XTL_FindClosingSquareBrace+0xfb>
cmpl   $0x0,(%r14)
jle    1229 <XTL_FindClosingSquareBrace+0xf9>
lea    0xeb2(%rip),%rdi
call   1030 <DoTrace@plt>
mov    %rbx,%rdi
call   1040 <XTL_FindComment@plt>
mov    (%rbx),%cl
lea    0xf00(%rip),%rdi
test   %cl,%cl
je     121d <XTL_FindClosingSquareBrace+0xed>
lea    0xecf(%rip),%rsi
lea    0xea6(%rip),%rdx
jmp    11cc <XTL_FindClosingSquareBrace+0x9c>
nopl   0x0(%rax,%rax,1)
addl   $0xffffffff,(%r14)
je     1233 <XTL_FindClosingSquareBrace+0x103>
cs nopw 0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     121d <XTL_FindClosingSquareBrace+0xed>
movsbl %cl,%ecx
cmp    $0x5b,%ecx
jg     11f0 <XTL_FindClosingSquareBrace+0xc0>
cmp    $0x25,%ecx
je     1210 <XTL_FindClosingSquareBrace+0xe0>
cmp    $0x5b,%ecx
jne    11c0 <XTL_FindClosingSquareBrace+0x90>
addl   $0x1,(%r14)
jmp    11c0 <XTL_FindClosingSquareBrace+0x90>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x5d,%ecx
je     11b0 <XTL_FindClosingSquareBrace+0x80>
cmp    $0x5c,%ecx
jne    11c0 <XTL_FindClosingSquareBrace+0x90>
cmpb   $0x0,0x1(%rbx)
je     11c0 <XTL_FindClosingSquareBrace+0x90>
add    $0x1,%rbx
jmp    11c0 <XTL_FindClosingSquareBrace+0x90>
cs nopw 0x0(%rax,%rax,1)
test   %rax,%rax
je     11c0 <XTL_FindClosingSquareBrace+0x90>
cmp    %rax,%rbx
jne    11c0 <XTL_FindClosingSquareBrace+0x90>
mov    %rsi,%rdi
xor    %ebx,%ebx
call   1030 <DoTrace@plt>
mov    %rbx,%rax
jmp    122b <XTL_FindClosingSquareBrace+0xfb>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rdx,%rdi
jmp    121f <XTL_FindClosingSquareBrace+0xef>

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

LLVM IR (-O2):
@.str = [44 x i8] c"start - XTL_FindClosingSquareBrace, %p, %p\0A\00"
@.str.1 = [32 x i8] c"in - XTL_FindClosingSquareBrace\00"
@.str.2 = [34 x i8] c"out1 - XTL_FindClosingSquareBrace\00"
@.str.3 = [34 x i8] c"out2 - XTL_FindClosingSquareBrace\00"
@.str.4 = [33 x i8] c"out - XTL_FindClosingSquareBrace\00"
define i8* @XTL_FindClosingSquareBrace(i8* %0, i32* %1) {
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 @TracePrintf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %3)
%5 = icmp eq i8* %0, null
br i1 %5, label %49, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
%9 = icmp eq i32* %1, null
%10 = or i1 %9, %8
br i1 %10, label %49, label %11
11: ; preds = %6
%12 = load i32, i32* %1
%13 = icmp slt i32 %12, 1
br i1 %13, label %49, label %14
14: ; preds = %11
%15 = tail call i32 @DoTrace(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i8* @XTL_FindComment(i8* %0)
%17 = load i8, i8* %0
%18 = icmp eq i8 %17, 0
br i1 %18, label %45, label %19
19: ; preds = %14
%20 = icmp ne i8* %16, null
br label %21
21: ; preds = %19, %40
%22 = phi i8 [ %17, %19 ], [ %43, %40 ]
%23 = phi i8* [ %0, %19 ], [ %42, %40 ]
%24 = sext i8 %22 to i32
switch i32 %24, label %40 [
i32 92, label %25
i32 91, label %30
i32 93, label %33
i32 37, label %37
]
25: ; preds = %21
%26 = getelementptr inbounds i8, i8* %23, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
%29 = select i1 %28, i8* %23, i8* %26
br label %40
30: ; preds = %21
%31 = load i32, i32* %1
%32 = add nsw i32 %31, 1
store i32 %32, i32* %1
br label %40
33: ; preds = %21
%34 = load i32, i32* %1
%35 = add nsw i32 %34, -1
store i32 %35, i32* %1
%36 = icmp eq i32 %35, 0
br i1 %36, label %45, label %40
37: ; preds = %21
%38 = icmp eq i8* %23, %16
%39 = and i1 %20, %38
br i1 %39, label %45, label %40
40: ; preds = %25, %30, %21, %33, %37
%41 = phi i8* [ %23, %21 ], [ %23, %37 ], [ %23, %33 ], [ %23, %30 ], [ %29, %25 ]
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 0
br i1 %44, label %45, label %21
45: ; preds = %40, %37, %33, %14
%46 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), %14 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), %33 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), %37 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), %40 ]
%47 = phi i8* [ null, %14 ], [ %23, %33 ], [ null, %37 ], [ null, %40 ]
%48 = tail call i32 @DoTrace(i8* %46)
br label %49
49: ; preds = %45, %2, %6, %11
%50 = phi i8* [ null, %11 ], [ null, %6 ], [ null, %2 ], [ %47, %45 ]
ret i8* %50
}