#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*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ stderr;
int checkSyntax(char *code) {
  int brackets = 0;
  int index = 0;
  while (code[index]) {
    if (code[index] == '[') {
      brackets++;
    } else if (code[index] == ']') {
      brackets--;
      if (brackets < 0) {
        fprintf(stderr, "Error at %d: missing '['\n", index);
        return index;
      }
    } else if (code[index] == '-' || code[index] == '.' || code[index] == ',') {
      fprintf(stderr, "Error at %d: forbidden symbol: '%c'\n", index,
              code[index]);
      return index;
    }
    index++;
  }
  if (brackets) {
    fprintf(stderr, "Error at %d: missing ']'\n", index);
    return index;
  }
  return 0;
}


x86 assembly (clang, -O0):
<checkSyntax>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1239 <checkSyntax+0x129>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5b,%eax
jne    115f <checkSyntax+0x4f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122b <checkSyntax+0x11b>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5d,%eax
jne    11b1 <checkSyntax+0xa1>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ac <checkSyntax+0x9c>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126f <checkSyntax+0x15f>
jmp    1226 <checkSyntax+0x116>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
je     11f0 <checkSyntax+0xe0>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     11f0 <checkSyntax+0xe0>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    1221 <checkSyntax+0x111>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126f <checkSyntax+0x15f>
jmp    1226 <checkSyntax+0x116>
jmp    122b <checkSyntax+0x11b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <checkSyntax+0x1a>
cmpl   $0x0,-0x14(%rbp)
je     1268 <checkSyntax+0x158>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126f <checkSyntax+0x15f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkSyntax>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
jmp    112c <checkSyntax+0x1c>
nopw   0x0(%rax,%rax,1)
cmp    $0x5b,%cl
jne    1150 <checkSyntax+0x40>
add    $0x1,%eax
add    $0x1,%rbx
movzbl (%rdi,%rbx,1),%ecx
cmp    $0x5c,%cl
jle    1120 <checkSyntax+0x10>
cmp    $0x5d,%cl
jne    1128 <checkSyntax+0x18>
test   %eax,%eax
jle    1190 <checkSyntax+0x80>
add    $0xffffffff,%eax
add    $0x1,%rbx
jmp    112c <checkSyntax+0x1c>
nopw   0x0(%rax,%rax,1)
lea    -0x2c(%rcx),%edx
cmp    $0x3,%dl
jb     1172 <checkSyntax+0x62>
test   %cl,%cl
jne    1128 <checkSyntax+0x18>
test   %eax,%eax
je     11ab <checkSyntax+0x9b>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xecf(%rip),%rsi
jmp    11a0 <checkSyntax+0x90>
movzbl %cl,%ecx
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11ad <checkSyntax+0x9d>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11ad <checkSyntax+0x9d>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Error at %d: missing '['\0A\00"
@.str.1 = [37 x i8] c"Error at %d: forbidden symbol: '%c'\0A\00"
@.str.2 = [26 x i8] c"Error at %d: missing ']'\0A\00"
define i32 @checkSyntax(i8* nocapture %0) {
br label %2
2: ; preds = %21, %1
%3 = phi i64 [ %23, %21 ], [ 0, %1 ]
%4 = phi i32 [ %22, %21 ], [ 0, %1 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = load i8, i8* %5
switch i8 %6, label %21 [
i8 0, label %24
i8 91, label %7
i8 93, label %9
i8 45, label %16
i8 46, label %16
i8 44, label %16
]
7: ; preds = %2
%8 = add nsw i32 %4, 1
br label %21
9: ; preds = %2
%10 = add nsw i32 %4, -1
%11 = icmp slt i32 %4, 1
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = trunc i64 %3 to i32
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %30
16: ; preds = %2, %2, %2
%17 = trunc i64 %3 to i32
%18 = load i32, i32* @stderr
%19 = zext i8 %6 to i32
%20 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %19)
br label %30
21: ; preds = %2, %9, %7
%22 = phi i32 [ %8, %7 ], [ %10, %9 ], [ %4, %2 ]
%23 = add nuw i64 %3, 1
br label %2
24: ; preds = %2
%25 = trunc i64 %3 to i32
%26 = icmp eq i32 %4, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %30
30: ; preds = %24, %27, %16, %12
%31 = phi i32 [ %13, %12 ], [ %17, %16 ], [ %25, %27 ], [ 0, %24 ]
ret i32 %31
}