#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 */
char *rib_find_rbracket(char *scanbegin) {
  int skipcount = 0;
  char *p = scanbegin;
  while (*p != '\0') {
    if (*p == '[')
      skipcount++;
    else if (*p == ']') {
      skipcount--;
      if (skipcount == 0)
        return p;
    }
    p++;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<rib_find_rbracket>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1190 <rib_find_rbracket+0x90>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    1145 <rib_find_rbracket+0x45>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117f <rib_find_rbracket+0x7f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
jne    117a <rib_find_rbracket+0x7a>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1175 <rib_find_rbracket+0x75>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1198 <rib_find_rbracket+0x98>
jmp    117a <rib_find_rbracket+0x7a>
jmp    117f <rib_find_rbracket+0x7f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1117 <rib_find_rbracket+0x17>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<rib_find_rbracket>:
mov    %rdi,%rax
xor    %ecx,%ecx
jmp    1117 <rib_find_rbracket+0x17>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ecx
add    $0x1,%rax
movzbl (%rax),%edx
cmp    $0x5b,%dl
je     1110 <rib_find_rbracket+0x10>
cmp    $0x5d,%dl
je     1130 <rib_find_rbracket+0x30>
test   %dl,%dl
jne    1113 <rib_find_rbracket+0x13>
jmp    1136 <rib_find_rbracket+0x36>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ecx
jne    1113 <rib_find_rbracket+0x13>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i8* @rib_find_rbracket(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
br label %7
7: ; preds = %34, %1
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %37
12: ; preds = %7
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 91
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %34
20: ; preds = %12
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 93
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load i32, i32* %4
%27 = add nsw i32 %26, -1
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = load i8*, i8** %5
store i8* %31, i8** %2
br label %38
32: ; preds = %25
br label %33
33: ; preds = %32, %20
br label %34
34: ; preds = %33, %17
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %5
br label %7
37: ; preds = %7
store i8* null, i8** %2
br label %38
38: ; preds = %37, %30
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
define i8* @rib_find_rbracket(i8* %0) {
br label %2
2: ; preds = %11, %1
%3 = phi i32 [ 0, %1 ], [ %12, %11 ]
%4 = phi i8* [ %0, %1 ], [ %13, %11 ]
%5 = load i8, i8* %4
switch i8 %5, label %11 [
i8 0, label %14
i8 91, label %6
i8 93, label %8
]
6: ; preds = %2
%7 = add nsw i32 %3, 1
br label %11
8: ; preds = %2
%9 = add nsw i32 %3, -1
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2, %8, %6
%12 = phi i32 [ %7, %6 ], [ %9, %8 ], [ %3, %2 ]
%13 = getelementptr inbounds i8, i8* %4, i64 1
br label %2
14: ; preds = %2, %8
%15 = phi i8* [ %4, %8 ], [ null, %2 ]
ret i8* %15
}