#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 rx_at(char *, size_t, size_t);
size_t find_range_end(char *rx, size_t rxn) {
  for (size_t i = 1;; i++) {
    char c = rx_at(rx, rxn, i);
    if (c == '\0')
      return 0;
    if (c == '\\') {
      i++;
      continue;
    }
    if (c != ']')
      continue;
    return i;
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_range_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <rx_at@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jne    1156 <find_range_end+0x46>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <find_range_end+0x94>
movsbl -0x21(%rbp),%eax
cmp    $0x5c,%eax
jne    1174 <find_range_end+0x64>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1193 <find_range_end+0x83>
movsbl -0x21(%rbp),%eax
cmp    $0x5d,%eax
je     1186 <find_range_end+0x76>
jmp    1193 <find_range_end+0x83>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a4 <find_range_end+0x94>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1128 <find_range_end+0x18>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_range_end>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x1,%ebx
jmp    1138 <find_range_end+0x28>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
add    $0x1,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <rx_at@plt>
cmp    $0x5c,%al
je     1130 <find_range_end+0x20>
test   %al,%al
je     1154 <find_range_end+0x44>
cmp    $0x5d,%al
jne    1134 <find_range_end+0x24>
jmp    1156 <find_range_end+0x46>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @find_range_end(i8* %0, i64 %1) {
br label %3
3: ; preds = %8, %2
%4 = phi i64 [ 1, %2 ], [ %10, %8 ]
%5 = tail call signext i8 @rx_at(i8* %0, i64 %1, i64 %4)
switch i8 %5, label %8 [
i8 0, label %11
i8 92, label %6
i8 93, label %12
]
6: ; preds = %3
%7 = add i64 %4, 1
br label %8
8: ; preds = %3, %6
%9 = phi i64 [ %7, %6 ], [ %4, %3 ]
%10 = add i64 %9, 1
br label %3
11: ; preds = %3
br label %12
12: ; preds = %3, %11
%13 = phi i64 [ 0, %11 ], [ %4, %3 ]
ret i64 %13
}