// File: /workspace/github_cpp_makefile_star2_O3/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 0x3e5e4
cmpq 0x10(%r14), %rax
setne %al
movq (%r12), %rcx
movq %r14, -0x58(%rbp)
cmpb (%r14), %al
je 0x40155
movq 0xc0(%rcx), %rax
movq 0xc8(%rcx), %rdx
subq %rax, %rdx
cmpq $0x10, %rdx
jne 0x40155
movq (%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
testq %rax, %rax
je 0x402bb
movq 0x1de2c(%rip), %rcx     # 0x5df70
cmpb $0x0, (%rcx)
je 0x402b7
incl 0x8(%rax)
jmp 0x402bb
movq $0x0, (%rbx)
leaq 0x8(%rbx), %rdi
leaq -0x50(%rbp), %rdx
movq %rdi, -0x90(%rbp)
movq %rbx, %rsi
callq 0x40988
movq (%rbx), %rdi
movq (%r15), %rax
movq %rax, 0xd8(%rdi)
addq $0x8, %r15
addq $0xe0, %rdi
movq %r15, %rsi
callq 0x2b902
movl $0xc0, %eax
movq (%rbx), %rdi
addq %rax, %rdi
callq 0x40686
movq (%r12), %rax
movq 0xc0(%rax), %r15
movq 0xc8(%rax), %r14
cmpq %r14, %r15
je 0x403f0
leaq -0x50(%rbp), %r13
movq (%r15), %rax
movq 0x8(%r15), %r12
testq %r12, %r12
je 0x401e9
movq 0x1dd9b(%rip), %rcx     # 0x5df70
cmpb $0x0, (%rcx)
je 0x401f7
incl 0x8(%r12)
movq %rax, -0x40(%rbp)
movq %r12, -0x38(%rbp)
jmp 0x4020e
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x40213
lock
incl 0x8(%r12)
cmpb $0x0, (%rcx)
movq %rax, -0x40(%rbp)
movq %r12, -0x38(%rbp)
je 0x402ac
incl 0x8(%r12)
movq (%rbx), %rax
movq %rax, -0x68(%rbp)
movq 0x8(%rbx), %rax
movq %rax, -0x60(%rbp)
testq %rax, %rax
je 0x4023c
movq 0x1dd42(%rip), %rcx     # 0x5df70
cmpb $0x0, (%rcx)
je 0x40238
incl 0x8(%rax)
jmp 0x4023c
lock
incl 0x8(%rax)
movq %r13, %rdi
movq -0x58(%rbp), %rsi
leaq -0x40(%rbp), %rdx
leaq -0x68(%rbp), %rcx
callq 0x400c6
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x4025e
callq 0x123fc
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x4026c
callq 0x123fc
movq (%rbx), %rdi
movl $0xc0, %eax
addq %rax, %rdi
movq %r13, %rsi
callq 0x406c8
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x4028d
callq 0x123fc
testq %r12, %r12
je 0x4029a
movq %r12, %rdi
callq 0x123fc
addq $0x10, %r15
cmpq %r14, %r15
jne 0x401c2
jmp 0x403f0
lock
incl 0x8(%r12)
jmp 0x40213
lock
incl 0x8(%rax)
movq (%r15), %rax
movq %rax, -0x78(%rbp)
movq 0x8(%r15), %rax
movq %rax, -0x70(%rbp)
testq %rax, %rax
je 0x402e4
movq 0x1dc9a(%rip), %rcx     # 0x5df70
cmpb $0x0, (%rcx)
je 0x402e0
incl 0x8(%rax)
jmp 0x402e4
lock
incl 0x8(%rax)
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rdx
leaq -0x78(%rbp), %rcx
movq -0x58(%rbp), %rsi
callq 0x400c6
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x4030a
callq 0x123fc
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x40318
callq 0x123fc
movq -0x50(%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 0x40716
addq $0x20, %rsp
movq (%rbx), %rax
movq 0xc0(%rax), %r12
movq 0xc8(%rax), %r13
cmpq %r13, %r12
je 0x403e2
movq (%r12), %rdi
movq 0x8(%r12), %r15
testq %r15, %r15
je 0x4039b
movq 0x1dbe0(%rip), %rax     # 0x5df70
cmpb $0x0, (%rax)
je 0x403b6
incl 0x8(%r15)
jmp 0x403bb
movq (%rbx), %rax
movq %rax, 0xd8(%rdi)
addq $0xe0, %rdi
movq %r14, %rsi
callq 0x2b902
jmp 0x403dc
lock
incl 0x8(%r15)
movq (%rbx), %rax
movq %rax, 0xd8(%rdi)
addq $0xe0, %rdi
movq %r14, %rsi
callq 0x2b902
movq %r15, %rdi
callq 0x123fc
addq $0x10, %r12
jmp 0x40376
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x403f0
callq 0x123fc
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x48(%rbp), %rdi
jmp 0x40420
movq %rax, %rbx
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x4041c
callq 0x123fc
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x40470
jmp 0x4046b
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x40438
callq 0x123fc
movq -0x38(%rbp), %rdi
jmp 0x40445
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x4044f
callq 0x123fc
testq %r12, %r12
je 0x4045c
movq %r12, %rdi
callq 0x123fc
movq -0x90(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x40470
callq 0x123fc
movq %rbx, %rdi
callq 0x8420