// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rsi), %rdi
movq 0x10(%rsi), %rsi
movq (%rdx), %rdx
addq $0x30, %rdx
callq 0x40714
cmpq 0x10(%r14), %rax
setne %al
movq %r14, -0x58(%rbp)
cmpb (%r14), %al
je 0x422a5
movq (%r12), %rcx
movq 0xc0(%rcx), %rax
movq 0xc8(%rcx), %rcx
subq %rax, %rcx
cmpq $0x10, %rcx
jne 0x422a5
movq (%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
testq %rax, %rax
je 0x42408
movq 0x1dcdc(%rip), %rcx     # 0x5ff70
cmpb $0x0, (%rcx)
je 0x42404
incl 0x8(%rax)
jmp 0x42408
movq (%r12), %rcx
movq $0x0, (%rbx)
leaq 0x8(%rbx), %rdi
leaq -0x40(%rbp), %rdx
movq %rdi, -0x90(%rbp)
movq %rbx, %rsi
callq 0x42ae4
movq (%rbx), %rdi
movq (%r15), %rax
movq %rax, 0xd8(%rdi)
addq $0x8, %r15
addq $0xe0, %rdi
movq %r15, %rsi
callq 0x2d4ea
movl $0xc0, %eax
movq (%rbx), %rdi
addq %rax, %rdi
callq 0x42800
movq (%r12), %rax
movq 0xc0(%rax), %r15
movq 0xc8(%rax), %r14
cmpq %r14, %r15
je 0x42542
leaq -0x40(%rbp), %r13
movq (%r15), %rax
movq 0x8(%r15), %r12
testq %r12, %r12
je 0x42335
movq 0x1dc47(%rip), %rcx     # 0x5ff70
cmpb $0x0, (%rcx)
je 0x4233f
incl 0x8(%r12)
jmp 0x42345
movq %rax, -0x50(%rbp)
movq %r12, -0x48(%rbp)
jmp 0x4236b
lock
incl 0x8(%r12)
movq %rax, -0x50(%rbp)
movq %r12, -0x48(%rbp)
testq %r12, %r12
je 0x4236b
movq 0x1dc17(%rip), %rax     # 0x5ff70
cmpb $0x0, (%rax)
je 0x42365
incl 0x8(%r12)
jmp 0x4236b
lock
incl 0x8(%r12)
movq (%rbx), %rax
movq %rax, -0x68(%rbp)
movq 0x8(%rbx), %rax
movq %rax, -0x60(%rbp)
testq %rax, %rax
je 0x42394
movq 0x1dbea(%rip), %rcx     # 0x5ff70
cmpb $0x0, (%rcx)
je 0x42390
incl 0x8(%rax)
jmp 0x42394
lock
incl 0x8(%rax)
movq %r13, %rdi
movq -0x58(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x68(%rbp), %rcx
callq 0x42216
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x423b6
callq 0x13612
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x423c4
callq 0x13612
movq (%rbx), %rdi
movl $0xc0, %eax
addq %rax, %rdi
movq %r13, %rsi
callq 0x42842
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x423e5
callq 0x13612
testq %r12, %r12
je 0x423f2
movq %r12, %rdi
callq 0x13612
addq $0x10, %r15
cmpq %r14, %r15
jne 0x42316
jmp 0x42542
lock
incl 0x8(%rax)
movq (%r15), %rax
movq %rax, -0x78(%rbp)
movq 0x8(%r15), %rax
movq %rax, -0x70(%rbp)
testq %rax, %rax
je 0x42431
movq 0x1db4d(%rip), %rcx     # 0x5ff70
cmpb $0x0, (%rcx)
je 0x4242d
incl 0x8(%rax)
jmp 0x42431
lock
incl 0x8(%rax)
leaq -0x40(%rbp), %rdi
leaq -0x88(%rbp), %rdx
leaq -0x78(%rbp), %rcx
movq -0x58(%rbp), %rsi
callq 0x42216
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x42457
callq 0x13612
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x42465
callq 0x13612
movq -0x40(%rbp), %rcx
movq (%r12), %rax
movq 0x30(%rax), %rdx
leaq -0x98(%rbp), %r8
movq %rdx, (%r8)
leaq 0x60(%rax), %r9
leaq 0x50(%rax), %r10
leaq 0x58(%rax), %r11
addq $0x68, %rax
movq $0x0, (%rbx)
leaq 0x8(%rbx), %r14
subq $0x8, %rsp
leaq -0x29(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rsi
pushq %rax
pushq %r11
pushq %r10
callq 0x42888
addq $0x20, %rsp
movq (%rbx), %rax
movq 0xc0(%rax), %r12
movq 0xc8(%rax), %r13
cmpq %r13, %r12
je 0x42534
movq (%r12), %rdi
movq 0x8(%r12), %r15
testq %r15, %r15
je 0x424e8
movq 0x1da93(%rip), %rax     # 0x5ff70
cmpb $0x0, (%rax)
je 0x42503
incl 0x8(%r15)
jmp 0x42508
movq (%rbx), %rax
movq %rax, 0xd8(%rdi)
addq $0xe0, %rdi
movq %r14, %rsi
callq 0x2d4ea
jmp 0x4252e
lock
incl 0x8(%r15)
movq (%rbx), %rax
movq %rax, 0xd8(%rdi)
addq $0xe0, %rdi
movq %r14, %rsi
callq 0x2d4ea
testq %r15, %r15
je 0x4252e
movq %r15, %rdi
callq 0x13612
addq $0x10, %r12
jmp 0x424c3
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x42542
callq 0x13612
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x38(%rbp), %rdi
jmp 0x42572
movq %rax, %rbx
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x4256e
callq 0x13612
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x425c2
jmp 0x425bd
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x4258a
callq 0x13612
movq -0x48(%rbp), %rdi
jmp 0x42597
movq %rax, %rbx
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x425a1
callq 0x13612
testq %r12, %r12
je 0x425ae
movq %r12, %rdi
callq 0x13612
movq -0x90(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x425c2
callq 0x13612
movq %rbx, %rdi
callq 0x9420