// File: /workspace/github_cpp_makefile_star2_O2/yhirose[P]fizzbuzzlang/./peglib.h
// Function: std::shared_ptr<peg::AstBase<peg::EmptyType>> peg::AstOptimizer::optimize<peg::AstBase<peg::EmptyType>>(std::shared_ptr<peg::AstBase<peg::EmptyType>>, std::shared_ptr<peg::AstBase<peg::EmptyType>>)
std::shared_ptr<T> optimize(std::shared_ptr<T> original,
                              std::shared_ptr<T> parent = nullptr) {
    auto found =
        std::find(rules_.begin(), rules_.end(), original->name) != rules_.end();
    auto opt = mode_ ? !found : found;

    if (opt && original->nodes.size() == 1) {
      auto child = optimize(original->nodes[0], parent);
      auto ast = std::make_shared<T>(*child, original->name.data(),
                                     original->choice_count, original->position,
                                     original->length, original->choice);
      for (auto node : ast->nodes) {
        node->parent = ast;
      }
      return ast;
    }

    auto ast = std::make_shared<T>(*original);
    ast->parent = parent;
    ast->nodes.clear();
    for (auto node : original->nodes) {
      auto child = optimize(node, ast);
      ast->nodes.push_back(child);
    }
    return ast;
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq 0x8(%rsi), %rdi
movq 0x10(%rsi), %rsi
movq (%rdx), %rdx
addq $0x30, %rdx
callq 0x35855
cmpq 0x10(%r12), %rax
setne %al
movq (%r15), %rsi
movq %r12, -0x50(%rbp)
cmpb (%r12), %al
movq %r14, -0x30(%rbp)
je 0x3767a
movq 0xc0(%rsi), %rax
movq 0xc8(%rsi), %rcx
subq %rax, %rcx
cmpq $0x10, %rcx
jne 0x3767a
leaq -0xa0(%rbp), %r12
leaq -0xa8(%rbp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x30710
leaq -0x98(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x30710
leaq -0x60(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x37530
leaq -0x58(%rbp), %r12
leaq -0x90(%rbp), %rdi
callq 0x1106c
leaq -0xa0(%rbp), %rdi
callq 0x1106c
movq -0x8(%r12), %rsi
movq (%r15), %rax
movq 0x30(%rax), %rcx
leaq -0x40(%rbp), %rdx
movq %rcx, (%rdx)
leaq 0x60(%rax), %rcx
leaq 0x50(%rax), %r8
leaq 0x58(%rax), %r9
addq $0x68, %rax
movq %rax, (%rsp)
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0x37913
movq (%rbx), %rax
movq 0xc0(%rax), %rbx
movq 0xc8(%rax), %r12
leaq -0x38(%rbp), %r14
leaq -0x40(%rbp), %r15
movl $0xd8, %r13d
cmpq %r12, %rbx
je 0x37753
movq %r15, %rdi
movq %rbx, %rsi
callq 0x30710
movq -0x40(%rbp), %rdi
addq %r13, %rdi
movq -0x30(%rbp), %rsi
callq 0x37232
movq %r14, %rdi
callq 0x1106c
addq $0x10, %rbx
jmp 0x37648
movq %r14, %rdi
callq 0x37944
movl $0xd8, %edi
addq (%r14), %rdi
movq %rbx, %rsi
callq 0x37232
movl $0xc0, %eax
movq (%r14), %rdi
addq %rax, %rdi
callq 0x37964
movq (%r15), %rax
movq 0xc0(%rax), %r13
movq 0xc8(%rax), %rax
movq %rax, -0x68(%rbp)
leaq -0x80(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x88(%rbp), %r14
leaq -0x78(%rbp), %rbx
leaq -0x40(%rbp), %r12
cmpq -0x68(%rbp), %r13
je 0x3775c
leaq -0x60(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x30710
movq %r14, %rdi
movq %r15, %rsi
callq 0x30710
movq %rbx, %rdi
movq -0x30(%rbp), %r15
movq %r15, %rsi
callq 0x30710
movq %r12, %rdi
movq -0x50(%rbp), %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x37530
leaq -0x70(%rbp), %rdi
callq 0x1106c
leaq -0x80(%rbp), %rdi
callq 0x1106c
movq (%r15), %rdi
movl $0xc0, %eax
addq %rax, %rdi
movq %r12, %rsi
callq 0x37972
leaq -0x38(%rbp), %rdi
callq 0x1106c
leaq -0x58(%rbp), %rdi
callq 0x1106c
addq $0x10, %r13
jmp 0x376ce
leaq -0x58(%rbp), %rdi
callq 0x1106c
movq -0x30(%rbp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x37786
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x1106c
movq %r12, %rdi
jmp 0x377be
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x1106c
jmp 0x377a4
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1106c
leaq -0x58(%rbp), %rdi
callq 0x1106c
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
callq 0x1106c
movq %rbx, %rdi
callq 0x9430
nop