#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 */
const char *find_loop_end(const char *code) {
  int depth = 1;
  char ch;
  while (ch = *++code, depth > 0) {
    switch (ch) {
    case '[':
      depth++;
      break;
    case ']':
      depth--;
      break;
    case '\0':
      return NULL;
    }
  }
  return code - 1;
}


x86 assembly (clang, -O0):
<find_loop_end>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x1(%rax),%al
mov    %al,-0x15(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1192 <find_loop_end+0x92>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     1180 <find_loop_end+0x80>
jmp    1142 <find_loop_end+0x42>
mov    -0x1c(%rbp),%eax
sub    $0x5b,%eax
je     1164 <find_loop_end+0x64>
jmp    1153 <find_loop_end+0x53>
mov    -0x1c(%rbp),%eax
sub    $0x5d,%eax
je     1172 <find_loop_end+0x72>
jmp    118d <find_loop_end+0x8d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <find_loop_end+0x8d>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <find_loop_end+0x8d>
movq   $0x0,-0x8(%rbp)
jmp    119e <find_loop_end+0x9e>
jmp    110f <find_loop_end+0xf>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_loop_end>:
mov    %rdi,%rax
mov    $0x1,%ecx
jmp    111b <find_loop_end+0x1b>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ecx
add    $0x1,%rax
test   %ecx,%ecx
jle    1135 <find_loop_end+0x35>
movsbl 0x1(%rax),%edx
cmp    $0x5b,%edx
je     1130 <find_loop_end+0x30>
cmp    $0x5d,%edx
je     1110 <find_loop_end+0x10>
test   %edx,%edx
jne    1113 <find_loop_end+0x13>
jmp    1136 <find_loop_end+0x36>
nop
add    $0x1,%ecx
jmp    1113 <find_loop_end+0x13>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i8* @find_loop_end(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %3
store i32 1, i32* %4
br label %6
6: ; preds = %22, %1
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i32 1
store i8* %8, i8** %3
%9 = load i8, i8* %8
store i8 %9, i8* %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %6
%13 = load i8, i8* %5
%14 = sext i8 %13 to i32
switch i32 %14, label %22 [
i32 91, label %15
i32 93, label %18
i32 0, label %21
]
15: ; preds = %12
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %22
18: ; preds = %12
%19 = load i32, i32* %4
%20 = add nsw i32 %19, -1
store i32 %20, i32* %4
br label %22
21: ; preds = %12
store i8* null, i8** %2
br label %26
22: ; preds = %12, %18, %15
br label %6
23: ; preds = %6
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 -1
store i8* %25, i8** %2
br label %26
26: ; preds = %23, %21
%27 = load i8*, i8** %2
ret i8* %27
}

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