#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*/ assert(int);
char *match_right(char *line) {
  char *c;
  int count = 0;
  assert(line != NULL);
  assert(line[0] == '[');
  for (c = line + 1; *c != '\0'; ++c) {
    if (*c == '[')
      ++count;
    else if (*c == ']') {
      if (count != 0)
        --count;
      else
        return c;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<match_right>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11db <match_right+0xcb>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    1186 <match_right+0x76>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c5 <match_right+0xb5>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
jne    11c0 <match_right+0xb0>
cmpl   $0x0,-0x1c(%rbp)
je     11ae <match_right+0x9e>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bb <match_right+0xab>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <match_right+0xd3>
jmp    11c0 <match_right+0xb0>
jmp    11c5 <match_right+0xb5>
jmp    11ca <match_right+0xba>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1158 <match_right+0x48>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_right>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpb   $0x5b,(%rbx)
sete   %dil
call   1030 <assert@plt>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x1(%rbx),%ecx
test   %cl,%cl
je     1164 <match_right+0x54>
add    $0x1,%rbx
cmp    $0x5d,%cl
je     115b <match_right+0x4b>
cmp    $0x5b,%cl
jne    1140 <match_right+0x30>
add    $0x1,%eax
jmp    1140 <match_right+0x30>
test   %eax,%eax
je     1166 <match_right+0x56>
add    $0xffffffff,%eax
jmp    1140 <match_right+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @match_right(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 91
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %4
br label %19
19: ; preds = %48, %1
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %51
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 91
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %47
32: ; preds = %24
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 93
br i1 %36, label %37, label %46
37: ; preds = %32
%38 = load i32, i32* %5
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* %5
%42 = add nsw i32 %41, -1
store i32 %42, i32* %5
br label %45
43: ; preds = %37
%44 = load i8*, i8** %4
store i8* %44, i8** %2
br label %52
45: ; preds = %40
br label %46
46: ; preds = %45, %32
br label %47
47: ; preds = %46, %29
br label %48
48: ; preds = %47
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %4
br label %19
51: ; preds = %19
store i8* null, i8** %2
br label %52
52: ; preds = %51, %43
%53 = load i8*, i8** %2
ret i8* %53
}

LLVM IR (-O2):
define i8* @match_right(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 91
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
br label %9
9: ; preds = %18, %1
%10 = phi i8* [ %0, %1 ], [ %14, %18 ]
%11 = phi i32 [ 0, %1 ], [ %19, %18 ]
br label %12
12: ; preds = %9, %12
%13 = phi i8* [ %14, %12 ], [ %10, %9 ]
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
switch i8 %15, label %12 [
i8 0, label %24
i8 91, label %16
i8 93, label %20
]
16: ; preds = %12
%17 = add nsw i32 %11, 1
br label %18
18: ; preds = %16, %22
%19 = phi i32 [ %23, %22 ], [ %17, %16 ]
br label %9
20: ; preds = %12
%21 = icmp eq i32 %11, 0
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = add nsw i32 %11, -1
br label %18
24: ; preds = %20, %12
%25 = phi i8* [ null, %12 ], [ %14, %20 ]
ret i8* %25
}