// File: /workspace/github_c_makefile_star2_O3/orangeduck[P]mpc/tests/grammar.c
// Function: test_grammar
void test_grammar(void) {

  mpc_parser_t *Expr, *Prod, *Value, *Maths;
  mpc_ast_t *t0, *t1, *t2;
  
  Expr  = mpc_new("expression");
  Prod  = mpc_new("product");
  Value = mpc_new("value");
  Maths = mpc_new("maths");
  
  mpc_define(Expr,  mpca_grammar(MPCA_LANG_DEFAULT, " <product> (('+' | '-') <product>)* ", Prod));
  mpc_define(Prod,  mpca_grammar(MPCA_LANG_DEFAULT, " <value>   (('*' | '/')   <value>)* ", Value));
  mpc_define(Value, mpca_grammar(MPCA_LANG_DEFAULT, " /[0-9]+/ | '(' <expression> ')' ", Expr));
  mpc_define(Maths, mpca_total(Expr));
  
  t0 = mpc_ast_new("product|value|regex", "24");
  t1 = mpc_ast_build(1, "product|>",
    mpc_ast_build(3, "value|>",
      mpc_ast_new("char", "("),
      mpc_ast_new("expression|product|value|regex", "5"),
      mpc_ast_new("char", ")")));
  
  t2 = mpc_ast_build(3, ">",
      
      mpc_ast_build(3, "product|value|>",
        mpc_ast_new("char", "("),
        mpc_ast_build(3, "expression|>",
          
          mpc_ast_build(5, "product|>", 
            mpc_ast_new("value|regex", "4"),
            mpc_ast_new("char", "*"),
            mpc_ast_new("value|regex", "2"),
            mpc_ast_new("char", "*"),
            mpc_ast_new("value|regex", "11")),
            
          mpc_ast_new("char", "+"),
          mpc_ast_new("product|value|regex", "2")),
        mpc_ast_new("char", ")")),
      
      mpc_ast_new("char", "+"),
      mpc_ast_new("product|value|regex", "5"));
  
  PT_ASSERT(mpc_test_pass(Maths, "  24 ", t0, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
  PT_ASSERT(mpc_test_pass(Maths, "(5)", t1, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
  PT_ASSERT(mpc_test_pass(Maths, "(4 * 2 * 11 + 2) + 5", t2, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
  PT_ASSERT(mpc_test_fail(Maths, "a", t0, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
  PT_ASSERT(mpc_test_fail(Maths, "2b+4", t0, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));

  mpc_ast_delete(t0);
  mpc_ast_delete(t1);
  mpc_ast_delete(t2);
  
  mpc_cleanup(4, Expr, Prod, Value, Maths);
  
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq 0xd0b1(%rip), %rdi      # 0xfbce
callq 0x71ca
movq %rax, %rbx
movq %rax, 0x30(%rsp)
leaq 0xd0a8(%rip), %rdi      # 0xfbd9
callq 0x71ca
movq %rax, %r14
leaq 0xd0a1(%rip), %rdi      # 0xfbe1
callq 0x71ca
movq %rax, %r15
leaq 0xc7ab(%rip), %rdi      # 0xf2fa
callq 0x71ca
movq %rax, %r13
movq %rax, 0x28(%rsp)
leaq 0xd084(%rip), %rsi      # 0xfbe7
xorl %edi, %edi
movq %r14, %rdx
movq %r14, 0x40(%rsp)
xorl %eax, %eax
callq 0xc3f7
movq %rbx, %rdi
movq %rax, %rsi
callq 0x747f
leaq 0xd086(%rip), %rsi      # 0xfc0c
xorl %edi, %edi
movq %r15, 0x38(%rsp)
movq %r15, %rdx
xorl %eax, %eax
callq 0xc3f7
movq %r14, %rdi
movq %rax, %rsi
callq 0x747f
leaq 0xd088(%rip), %rsi      # 0xfc31
xorl %edi, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xc3f7
movq %r15, %rdi
movq %rax, %rsi
callq 0x747f
movq %rbx, %rdi
callq 0xb8bd
movq %r13, %rdi
movq %rax, %rsi
callq 0x747f
leaq 0xd096(%rip), %rdi      # 0xfc70
leaq 0xd072(%rip), %rsi      # 0xfc53
callq 0xaa70
movq %rax, 0x20(%rsp)
leaq 0xd06e(%rip), %r15      # 0xfc60
leaq 0xf918(%rip), %r14      # 0x12511
movq %r15, %rdi
movq %r14, %rsi
callq 0xaa70
movq %rax, %rbx
leaq 0xd057(%rip), %rdi      # 0xfc65
leaq 0xd1d6(%rip), %rsi      # 0xfdeb
callq 0xaa70
movq %rax, %r13
leaq 0xeaf2(%rip), %rsi      # 0x11716
movq %r15, %rdi
callq 0xaa70
leaq 0xd059(%rip), %rsi      # 0xfc8c
movl $0x3, %edi
movq %rbx, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xaaea
leaq 0xd007(%rip), %rsi      # 0xfc56
movl $0x1, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0xaaea
movq %rax, 0x18(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0xaa70
movq %rax, 0x10(%rsp)
leaq 0xcffe(%rip), %r14      # 0xfc78
leaq 0xc7be(%rip), %rsi      # 0xf43f
movq %r14, %rdi
callq 0xaa70
movq %rax, %rbp
leaq 0xecd1(%rip), %rbx      # 0x11964
movq %r15, %rdi
movq %rbx, %rsi
callq 0xaa70
movq %rax, %r12
leaq 0xc912(%rip), %rsi      # 0xf5ba
movq %r14, %rdi
callq 0xaa70
movq %rax, %r13
movq %r15, %rdi
movq %rbx, %rsi
callq 0xaa70
movq %rax, %rbx
leaq 0xcfd9(%rip), %rsi      # 0xfca1
movq %r14, %rdi
callq 0xaa70
movq %rax, (%rsp)
movl $0x5, %edi
leaq 0xcf76(%rip), %rsi      # 0xfc56
movq %rbp, %rdx
movq %r12, %rcx
movq %r13, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0xaaea
movq %rax, %r14
leaq 0xe489(%rip), %rbx      # 0x11186
movq %r15, %rdi
movq %rbx, %rsi
callq 0xaa70
movq %rax, %r12
leaq 0xcf5e(%rip), %r13      # 0xfc70
movq %r13, %rdi
leaq 0xc89e(%rip), %rsi      # 0xf5ba
callq 0xaa70
leaq 0xcf6c(%rip), %rsi      # 0xfc94
movl $0x3, %edi
movq %r14, %rdx
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xaaea
movq %rax, %r14
movq %r15, %rdi
leaq 0xe9cc(%rip), %rsi      # 0x11716
callq 0xaa70
leaq 0xcf2e(%rip), %rsi      # 0xfc84
movl $0x3, %edi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xaaea
movq %rax, %r14
movq %r15, %rdi
movq %rbx, %rsi
callq 0xaa70
movq %rax, %rbx
movq %r13, %rdi
leaq 0xd063(%rip), %rsi      # 0xfdeb
callq 0xaa70
leaq 0xf74e(%rip), %rsi      # 0x124e2
movl $0x3, %edi
movq %r14, %rdx
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xaaea
movq %rax, %rbx
movq %rax, 0x10(%rsp)
leaq 0xceec(%rip), %rsi      # 0xfca4
leaq 0x7edb(%rip), %r15      # 0xac9a
leaq 0x7c52(%rip), %rbp      # 0xaa18
leaq 0x80aa(%rip), %r9       # 0xae77
movq 0x28(%rsp), %r12
movq %r12, %rdi
movq 0x20(%rsp), %r14
movq %r14, %rdx
movq %r15, %rcx
movq %rbp, %r8
movq %r9, %r13
callq 0xa93d
leaq 0xceb8(%rip), %rsi      # 0xfcaa
leaq 0xcf41(%rip), %rdx      # 0xfd3a
movl %eax, %edi
movl $0x2e, %ecx
callq 0x4094
leaq 0xc532(%rip), %rsi      # 0xf33e
movq %r12, %rdi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
movq %rbp, %r8
movq %r13, %rbp
movq %r13, %r9
callq 0xa93d
leaq 0xcf1e(%rip), %rsi      # 0xfd4a
movl %eax, %edi
leaq 0xcf05(%rip), %r13      # 0xfd3a
movq %r13, %rdx
movl $0x2f, %ecx
callq 0x4094
leaq 0xcf8f(%rip), %rsi      # 0xfdd8
movq %r12, %rdi
movq %rbx, %rdx
movq %r15, %rcx
leaq 0x7bbf(%rip), %r8       # 0xaa18
movq %r8, %rbx
movq %rbp, %r9
callq 0xa93d
leaq 0xcf82(%rip), %rsi      # 0xfded
movl %eax, %edi
movq %r13, %rdx
movl $0x30, %ecx
callq 0x4094
leaq 0xf62b(%rip), %rsi      # 0x124ac
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0xa8c1
leaq 0xcff0(%rip), %rsi      # 0xfe8c
movl %eax, %edi
movq %r13, %rdx
movl $0x31, %ecx
callq 0x4094
leaq 0xc58a(%rip), %rsi      # 0xf43c
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0xa8c1
leaq 0xd04b(%rip), %rsi      # 0xff18
movl %eax, %edi
movq %r13, %rdx
movl $0x32, %ecx
callq 0x4094
movq %r14, %rdi
callq 0xaa18
movq 0x18(%rsp), %rdi
callq 0xaa18
movq 0x10(%rsp), %rdi
callq 0xaa18
movl $0x4, %edi
movq 0x30(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq %r12, %r8
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x75de