// File: yhirose[P]fizzbuzzlang/fzbz.cc
// Function: parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::ostream&)
shared_ptr<Ast> parse(const string& source, ostream& out) {
  parser parser(R"(
    # Syntax Rules
    EXPRESSION              ← TERNARY
    TERNARY                 ← CONDITION ('?' EXPRESSION ':' EXPRESSION)?
    CONDITION               ← MULTIPLICATIVE (ConditionOperator MULTIPLICATIVE)?
    MULTIPLICATIVE          ← CALL (MultiplicativeOperator CALL)*
    CALL                    ← PRIMARY (EXPRESSION)?
    PRIMARY                 ← FOR / Identifier / '(' EXPRESSION ')' / String / Number
    FOR                     ← 'for' Identifier 'from' Number 'to' Number EXPRESSION

    # Token Rules
    ConditionOperator       ← '=='
    MultiplicativeOperator  ← '%'
    Identifier              ← !Keyword < [a-zA-Z][a-zA-Z0-9_]* >
    String                  ← "'" < ([^'] .)* > "'"
    Number                  ← < [0-9]+ >

    Keyword                 ← ('for' / 'from' / 'to') ![a-zA-Z]
    %whitespace             ← [ \t\r\n]*
  )");

  parser.enable_ast();

  parser.set_logger([&](size_t ln, size_t col, const auto& msg) {
    out << ln << ":" << col << ": " << msg << endl;
  });

  shared_ptr<Ast> ast;
  if (parser.parse_n(source.data(), source.size(), ast)) {
    return parser.optimize_ast(ast);
  }

  return nullptr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x108(%rbp)
movq %rdi, %rax
movq %rax, -0x100(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0x96fc4(%rip), %rsi     # 0xa1863
leaq -0x80(%rbp), %rdi
callq 0x12a80
leaq -0x90(%rbp), %rdi
callq 0x12ad0
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x90(%rbp), %rcx
movq -0x88(%rbp), %r8
leaq -0x70(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x12af0
movq -0xf8(%rbp), %rdi
callq 0x12bd0
jmp 0xa8e8
movq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x110(%rbp)
leaq -0xc8(%rbp), %rsi
callq 0xaab0
movq -0x110(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x12c80
jmp 0xa91f
leaq -0xc0(%rbp), %rdi
callq 0x12cf0
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x12d10
movq -0x10(%rbp), %rdi
callq 0xa4d0
movq %rax, -0x128(%rbp)
movq -0x10(%rbp), %rdi
callq 0xa2d0
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rcx
movq %rax, %rdx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x70(%rbp), %rdi
callq 0x12d30
movb %al, -0x111(%rbp)
jmp 0xa97e
movb -0x111(%rbp), %al
testb $0x1, %al
jne 0xa98d
jmp 0xaa4b
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x130(%rbp)
leaq -0xd8(%rbp), %rsi
callq 0x13010
movq -0x108(%rbp), %rdi
movq -0x130(%rbp), %rdx
leaq -0x70(%rbp), %rsi
movl $0x1, %ecx
callq 0x12ed0
jmp 0xa9c5
leaq -0xe8(%rbp), %rdi
callq 0x13040
movl $0x1, -0xec(%rbp)
jmp 0xaa65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xaa96
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x12cf0
jmp 0xaa96
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xaa8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x13040
jmp 0xaa8a
movq -0x108(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x13060
movl $0x1, -0xec(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x13040
leaq -0x70(%rbp), %rdi
callq 0x13080
movq -0x100(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0xd8(%rbp), %rdi
callq 0x13040
leaq -0x70(%rbp), %rdi
callq 0x13080
movq -0x98(%rbp), %rdi
callq 0xa650
nopl (%rax,%rax)