#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 node_stack_at(int, unsigned int *, unsigned int);
int /*<<< orphan*/ pop_node_stack(unsigned int **, unsigned int *);
void parse_array_end(unsigned int **stack, unsigned int *stack_size,
                     unsigned int *array_depth) {
  int stack_top = node_stack_at(0, *stack, *stack_size);
  int parent = node_stack_at(1, *stack, *stack_size);
  if (parent == 0x00000000 &&
      (stack_top == 0x00000004 || stack_top == 0x00000005)) {
    (*array_depth)--;
    if (stack_top == 0x00000005) {
      pop_node_stack(stack, stack_size);
    } else {
      if ((*array_depth) == 0) {
        pop_node_stack(stack, stack_size);
      }
    }
  } else if ((parent == 0x00000004 || parent == 0x00000005) &&
             stack_top == 0x00000008) {
    (*array_depth)--;
    pop_node_stack(stack, stack_size);
  }
}


x86 assembly (clang, -O0):
<parse_array_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
xor    %edi,%edi
call   1040 <node_stack_at@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1040 <node_stack_at@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11ce <parse_array_end+0xae>
cmpl   $0x4,-0x1c(%rbp)
je     1183 <parse_array_end+0x63>
cmpl   $0x5,-0x1c(%rbp)
jne    11ce <parse_array_end+0xae>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
cmpl   $0x5,-0x1c(%rbp)
jne    11aa <parse_array_end+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <pop_node_stack@plt>
jmp    11c9 <parse_array_end+0xa9>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11c4 <parse_array_end+0xa4>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <pop_node_stack@plt>
jmp    11c9 <parse_array_end+0xa9>
jmp    1209 <parse_array_end+0xe9>
cmpl   $0x4,-0x20(%rbp)
je     11e2 <parse_array_end+0xc2>
cmpl   $0x5,-0x20(%rbp)
jne    1204 <parse_array_end+0xe4>
cmpl   $0x8,-0x1c(%rbp)
jne    1204 <parse_array_end+0xe4>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <pop_node_stack@plt>
jmp    1209 <parse_array_end+0xe9>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_array_end>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rsi
mov    (%r14),%edx
xor    %edi,%edi
call   1040 <node_stack_at@plt>
mov    %eax,%ebp
mov    (%rbx),%rsi
mov    (%r14),%edx
mov    $0x1,%edi
call   1040 <node_stack_at@plt>
test   %eax,%eax
jne    1171 <parse_array_end+0x51>
mov    %ebp,%ecx
and    $0xfffffffe,%ecx
cmp    $0x4,%ecx
jne    1171 <parse_array_end+0x51>
mov    (%r15),%eax
add    $0xffffffff,%eax
mov    %eax,(%r15)
cmp    $0x5,%ebp
je     1182 <parse_array_end+0x62>
test   %eax,%eax
jne    1197 <parse_array_end+0x77>
jmp    1182 <parse_array_end+0x62>
and    $0xfffffffe,%eax
cmp    $0x4,%eax
jne    1197 <parse_array_end+0x77>
cmp    $0x8,%ebp
jne    1197 <parse_array_end+0x77>
addl   $0xffffffff,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <pop_node_stack@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @parse_array_end(i32** %0, i32* %1, i32* %2) {
%4 = alloca i32**
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32** %0, i32*** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%9 = load i32**, i32*** %4
%10 = load i32*, i32** %9
%11 = load i32*, i32** %5
%12 = load i32, i32* %11
%13 = call i32 @node_stack_at(i32 0, i32* %10, i32 %12)
store i32 %13, i32* %7
%14 = load i32**, i32*** %4
%15 = load i32*, i32** %14
%16 = load i32*, i32** %5
%17 = load i32, i32* %16
%18 = call i32 @node_stack_at(i32 1, i32* %15, i32 %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %47
21: ; preds = %3
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 4
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 5
br i1 %26, label %27, label %47
27: ; preds = %24, %21
%28 = load i32*, i32** %6
%29 = load i32, i32* %28
%30 = add i32 %29, -1
store i32 %30, i32* %28
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 5
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = load i32**, i32*** %4
%35 = load i32*, i32** %5
%36 = call i32 @pop_node_stack(i32** %34, i32* %35)
br label %46
37: ; preds = %27
%38 = load i32*, i32** %6
%39 = load i32, i32* %38
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32**, i32*** %4
%43 = load i32*, i32** %5
%44 = call i32 @pop_node_stack(i32** %42, i32* %43)
br label %45
45: ; preds = %41, %37
br label %46
46: ; preds = %45, %33
br label %64
47: ; preds = %24, %3
%48 = load i32, i32* %8
%49 = icmp eq i32 %48, 4
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 5
br i1 %52, label %53, label %63
53: ; preds = %50, %47
%54 = load i32, i32* %7
%55 = icmp eq i32 %54, 8
br i1 %55, label %56, label %63
56: ; preds = %53
%57 = load i32*, i32** %6
%58 = load i32, i32* %57
%59 = add i32 %58, -1
store i32 %59, i32* %57
%60 = load i32**, i32*** %4
%61 = load i32*, i32** %5
%62 = call i32 @pop_node_stack(i32** %60, i32* %61)
br label %63
63: ; preds = %56, %53, %50
br label %64
64: ; preds = %63, %46
ret void
}

LLVM IR (-O2):
define void @parse_array_end(i32** %0, i32* %1, i32* nocapture %2) {
%4 = load i32*, i32** %0
%5 = load i32, i32* %1
%6 = tail call i32 @node_stack_at(i32 0, i32* %4, i32 %5)
%7 = load i32*, i32** %0
%8 = load i32, i32* %1
%9 = tail call i32 @node_stack_at(i32 1, i32* %7, i32 %8)
%10 = icmp eq i32 %9, 0
%11 = and i32 %6, -2
%12 = icmp eq i32 %11, 4
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %20
14: ; preds = %3
%15 = icmp eq i32 %6, 5
%16 = load i32, i32* %2
%17 = add i32 %16, -1
store i32 %17, i32* %2
%18 = icmp eq i32 %17, 0
%19 = select i1 %15, i1 true, i1 %18
br i1 %19, label %28, label %30
20: ; preds = %3
%21 = and i32 %9, -2
%22 = icmp eq i32 %21, 4
%23 = icmp eq i32 %6, 8
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32, i32* %2
%27 = add i32 %26, -1
store i32 %27, i32* %2
br label %28
28: ; preds = %14, %25
%29 = tail call i32 @pop_node_stack(i32** %0, i32* %1)
br label %30
30: ; preds = %14, %28, %20
ret void
}