// File: /workspace/github_cpp_makefile_star2_O3/eniac[P]Mantis/src/compile/compile_c.cpp
// Function: generateDialogueNode(std::vector<AstNode*, std::allocator<AstNode*>>, std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char>>&)
UnanchoredNode* generateDialogueNode(std::vector<AstNode*> nodeArray, ostringstream& oss_reaction_mirror, ostringstream& oss_reaction_update) {

	// Assume single global reaction and initialization node (if any)
	P4RReactionNode * react_node = findReaction(nodeArray);
    string * dialogue_str = NULL;
    string p4r_reaction_user_str = "";
    if (react_node != 0) {
        p4r_reaction_user_str = react_node->body_->toString();
    }

    // Translate mantis style variable assignment to macros to be further processed by C preprocessor
    // regrex matching ${var} = <alter>;
    std::regex e_val ("\\$\\{([^ ]*)\\}\\s*[=]\\s*([^\\; ]*)\\s*\\;");
    p4r_reaction_user_str = std::regex_replace (p4r_reaction_user_str, e_val, "__mantis__mod_var_$1($2);");
    // regrex matching ${var} = <header>.<field>;
    std::regex e_field ("\\$\\{([^ ]*)\\}\\s*[=]\\s*([^\\. ]*)\\s*\\.\\s*([^\\; ]*)\\s*\\;");
    p4r_reaction_user_str = std::regex_replace (p4r_reaction_user_str, e_field, "__mantis__mod_var_$1_$2_$3;");

    // Change field arg format to C compatible variable
    vector<ReactionArgNode*> reaction_args = findReactionArgs(nodeArray);
    for (auto ra : reaction_args) {    
        if (ra->argType_==ReactionArgNode::INGRESS_FIELD) {
            FieldNode* fieldnode = dynamic_cast<FieldNode*>(ra->arg_);
            std::regex e_fieldarg (fieldnode->headerName_->toString()+"\\s*([^\\. ]*)\\s*\\.\\s*"+fieldnode->fieldName_->toString());
            p4r_reaction_user_str = std::regex_replace (p4r_reaction_user_str, e_fieldarg, fieldnode->headerName_->toString()+"_"+fieldnode->fieldName_->toString());
        }    
    }

    if (react_node != 0) {
        dialogue_str = new string(
            str(boost::format(kDialogueT) % oss_reaction_mirror.str() % p4r_reaction_user_str % oss_reaction_update.str()));
    } else {
        dialogue_str = new string(
            str(boost::format(kDialogueT) % oss_reaction_mirror.str() % "" % oss_reaction_update.str()));
    }

    UnanchoredNode * dialogue_cnode = new UnanchoredNode(dialogue_str, new string ("dialogue"), new string("pd_dialogue"));
    return dialogue_cnode;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
leaq -0x258(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x32ac0
movq %r14, %rdi
callq 0x6f412
movq %rax, %r14
movq -0x258(%rbp), %rdi
testq %rdi, %rdi
je 0x408dd
callq 0x2e360
leaq -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x36fec(%rip), %rdx     # 0x778db
leaq -0xa8(%rbp), %rdi
movq %rdx, %rsi
callq 0x32e40
testq %r14, %r14
je 0x40943
movq %r14, %r15
movq 0x50(%r14), %rsi
movq (%rsi), %rax
leaq -0x200(%rbp), %rdi
callq *(%rax)
leaq -0xa8(%rbp), %rdi
leaq -0x200(%rbp), %r14
movq %r14, %rsi
callq 0x2e4c0
movq (%r14), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0x40940
callq 0x2e360
movq %r15, %r14
leaq 0x35da6(%rip), %rsi     # 0x766f0
leaq -0x240(%rbp), %rdi
movl $0x10, %edx
callq 0x50658
movq %r14, -0x100(%rbp)
leaq -0x1f0(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
addq %rsi, %rdx
movl $0x0, (%rsp)
leaq 0x35d7d(%rip), %r8      # 0x76715
leaq -0x200(%rbp), %rdi
leaq -0x240(%rbp), %rcx
movl $0x19, %r9d
callq 0x6040a
leaq -0xa8(%rbp), %rdi
leaq -0x200(%rbp), %r14
movq %r14, %rsi
callq 0x2e4c0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x409d4
callq 0x2e360
leaq 0x35d54(%rip), %rsi     # 0x7672f
leaq -0x220(%rbp), %rdi
movl $0x10, %edx
callq 0x50658
leaq -0x200(%rbp), %rdi
movq %r15, (%rdi)
movq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
addq %rsi, %rdx
movl $0x0, (%rsp)
leaq 0x35d44(%rip), %r8      # 0x76765
leaq -0x220(%rbp), %rcx
movl $0x1b, %r9d
callq 0x6040a
leaq -0xa8(%rbp), %rdi
movq %r14, %rsi
callq 0x2e4c0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x40a4f
callq 0x2e360
movq %r13, -0xd8(%rbp)
movq %r12, -0xd0(%rbp)
leaq -0x120(%rbp), %rdi
movq %rbx, %rsi
callq 0x6f575
movq -0x120(%rbp), %rbx
movq -0x118(%rbp), %rdx
cmpq %rdx, %rbx
je 0x40e41
leaq -0x58(%rbp), %r14
leaq -0x88(%rbp), %rcx
leaq -0xc8(%rbp), %r12
movq %rdx, -0x108(%rbp)
movq (%rbx), %rax
cmpl $0x0, 0x3c(%rax)
jne 0x40e34
movq 0x40(%rax), %rdi
testq %rdi, %rdi
je 0x40ad3
leaq 0x4bbf7(%rip), %rsi     # 0x8c6b0
leaq 0x4c960(%rip), %rdx     # 0x8d420
xorl %ecx, %ecx
callq 0x2e430
leaq -0x88(%rbp), %rcx
movq %rax, %r15
jmp 0x40ad6
xorl %r15d, %r15d
movq 0x40(%r15), %rsi
movq (%rsi), %rax
movq %rcx, %rdi
movq %rcx, %r13
callq *(%rax)
movq %r13, %rdi
leaq 0x35c92(%rip), %rsi     # 0x76781
callq 0x2e7e0
leaq -0x38(%rbp), %rsi
movq %rsi, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x40b18
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x40b1e
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x48(%r15), %rsi
movq (%rsi), %rax
movq %r12, %rdi
callq *(%rax)
movq -0x48(%rbp), %rcx
movl $0xf, %edi
leaq -0x38(%rbp), %rax
cmpq %rax, %rcx
je 0x40b57
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %r8
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x40b8f
movl $0xf, %edi
leaq -0xb8(%rbp), %r9
cmpq %r9, %rsi
je 0x40b8a
movq -0xb8(%rbp), %rdi
cmpq %rdi, %rax
jbe 0x40b9a
leaq -0x48(%rbp), %rdi
callq 0x2e130
jmp 0x40ba6
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2e420
movq %r14, -0x68(%rbp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x40bc3
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x40bca
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, -0x60(%rbp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq -0x200(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl $0x10, %edx
callq 0x506c4
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x40c09
callq 0x2e360
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x40c21
callq 0x2e360
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x40c33
callq 0x2e360
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x40c48
callq 0x2e360
movq 0x40(%r15), %rsi
movq (%rsi), %rax
movq %r12, %r13
movq %r12, %rdi
callq *(%rax)
movq %r13, %rdi
leaq 0x36ca9(%rip), %rsi     # 0x7790a
callq 0x2e7e0
leaq -0x78(%rbp), %rsi
movq %rsi, -0x88(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x40c90
movq %rdx, -0x88(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x78(%rbp)
jmp 0x40c96
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x80(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x48(%r15), %rsi
movq (%rsi), %rax
leaq -0xf8(%rbp), %rdi
callq *(%rax)
movq -0x88(%rbp), %rcx
movl $0xf, %edi
leaq -0x78(%rbp), %r15
cmpq %r15, %rcx
je 0x40cd6
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %r8
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x40d0e
movl $0xf, %edi
leaq -0xe8(%rbp), %r9
cmpq %r9, %rsi
je 0x40d09
movq -0xe8(%rbp), %rdi
cmpq %rdi, %rax
jbe 0x40d1c
leaq -0x88(%rbp), %rdi
callq 0x2e130
jmp 0x40d2c
leaq -0xf8(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2e420
leaq -0x38(%rbp), %rsi
movq %rsi, -0x48(%rbp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x40d4d
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x40d53
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, -0x40(%rbp)
movq %rcx, (%rax)
xorl %eax, %eax
movq %rax, (%rdx)
movb %al, (%rcx)
movq %r14, -0x68(%rbp)
movq %rax, -0x60(%rbp)
movb %al, -0x58(%rbp)
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
addq %rsi, %rdx
movq -0x48(%rbp), %r8
movq -0x40(%rbp), %r9
movl $0x0, (%rsp)
leaq -0x68(%rbp), %r13
movq %r13, %rdi
leaq -0x200(%rbp), %rcx
callq 0x6040a
leaq -0xa8(%rbp), %rdi
movq %r13, %rsi
callq 0x2e4c0
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x40dc7
callq 0x2e360
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x40dd9
callq 0x2e360
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x40df1
callq 0x2e360
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x40e02
callq 0x2e360
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x40e1a
callq 0x2e360
leaq -0x200(%rbp), %rdi
callq 0x5072e
leaq -0x88(%rbp), %rcx
movq -0x108(%rbp), %rdx
addq $0x8, %rbx
cmpq %rdx, %rbx
jne 0x40a9c
cmpq $0x0, -0x100(%rbp)
je 0x40f22
movl $0x20, %edi
callq 0x2e3a0
movq -0xd8(%rbp), %r14
movq %rax, %r12
leaq 0x3592c(%rip), %rsi     # 0x76796
leaq -0x200(%rbp), %rdi
callq 0x50494
addq $0x8, %r14
leaq -0x68(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2e660
leaq -0x48(%rbp), %rsi
movq %rbx, (%rsi)
leaq 0x13a73(%rip), %r15     # 0x5490a
movq %r15, 0x8(%rsi)
leaq 0x13a6e(%rip), %r13     # 0x54910
movq %r13, 0x10(%rsi)
leaq -0x200(%rbp), %rdi
callq 0x537b3
leaq -0x48(%rbp), %rsi
leaq -0xa8(%rbp), %rcx
movq %rcx, (%rsi)
leaq 0x22109(%rip), %rcx     # 0x62fd0
movq %rcx, 0x8(%rsi)
leaq 0x22104(%rip), %rcx     # 0x62fd6
movq %rcx, 0x10(%rsi)
movq %rax, %rdi
callq 0x537b3
movq %rax, %rbx
movq -0xd0(%rbp), %rsi
addq $0x8, %rsi
leaq -0x48(%rbp), %r14
movq %r14, %rdi
callq 0x2e660
leaq -0x88(%rbp), %rsi
movq %r14, (%rsi)
movq %r15, 0x8(%rsi)
movq %r13, 0x10(%rsi)
movq %rbx, %rdi
callq 0x537b3
movq %r12, %rdi
movq %rax, %rsi
callq 0x54924
jmp 0x40ff0
movl $0x20, %edi
callq 0x2e3a0
movq -0xd8(%rbp), %r14
movq %rax, %r12
leaq 0x35859(%rip), %rsi     # 0x76796
leaq -0x200(%rbp), %rdi
callq 0x50494
addq $0x8, %r14
leaq -0x68(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2e660
leaq -0x48(%rbp), %rsi
movq %rbx, (%rsi)
leaq 0x139a0(%rip), %r15     # 0x5490a
movq %r15, 0x8(%rsi)
leaq 0x1399b(%rip), %r13     # 0x54910
movq %r13, 0x10(%rsi)
leaq -0x200(%rbp), %rdi
callq 0x537b3
leaq -0x48(%rbp), %rsi
leaq 0x3694b(%rip), %rcx     # 0x778db
movq %rcx, (%rsi)
leaq 0x13f3f(%rip), %rcx     # 0x54ed9
movq %rcx, 0x8(%rsi)
leaq 0x13f3a(%rip), %rcx     # 0x54edf
movq %rcx, 0x10(%rsi)
movq %rax, %rdi
callq 0x537b3
movq %rax, %rbx
movq -0xd0(%rbp), %rsi
addq $0x8, %rsi
leaq -0x48(%rbp), %r14
movq %r14, %rdi
callq 0x2e660
leaq -0x88(%rbp), %rsi
movq %r14, (%rsi)
movq %r15, 0x8(%rsi)
movq %r13, 0x10(%rsi)
movq %rbx, %rdi
callq 0x537b3
movq %r12, %rdi
movq %rax, %rsi
callq 0x54924
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x41002
callq 0x2e360
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x41014
callq 0x2e360
cmpb $0x1, -0x130(%rbp)
jne 0x41030
leaq -0x128(%rbp), %rbx
movq %rbx, %rdi
callq 0x2e580
movb $0x0, -0x8(%rbx)
leaq -0x188(%rbp), %rbx
movq %rbx, %rdi
callq 0x507e2
movq -0x28(%rbx), %rdi
leaq -0x1a0(%rbp), %rax
cmpq %rax, %rdi
je 0x41054
callq 0x2e360
movq -0x1e8(%rbp), %rdi
testq %rdi, %rdi
je 0x41088
callq 0x2e360
xorl %eax, %eax
movq %rax, -0x1e8(%rbp)
movl %eax, -0x1e0(%rbp)
movq %rax, -0x1d8(%rbp)
movl %eax, -0x1d0(%rbp)
movq %rax, -0x1c8(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x50840
movl $0x58, %edi
callq 0x2e3a0
movq %rax, %r14
movl $0x20, %edi
callq 0x2e3a0
movq %rax, %r15
addq $0x10, %rax
movq %rax, (%r15)
leaq 0x3577a(%rip), %rsi     # 0x76836
leaq 0x3577b(%rip), %rdx     # 0x7683e
movq %r15, %rdi
callq 0x32e40
movl $0x20, %edi
callq 0x2e3a0
movq %rax, %r13
addq $0x10, %rax
movq %rax, (%r13)
leaq 0x3574c(%rip), %rsi     # 0x76833
leaq 0x35750(%rip), %rdx     # 0x7683e
movq %r13, %rdi
callq 0x32e40
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x3e120
movq -0x120(%rbp), %rdi
testq %rdi, %rdi
je 0x41118
callq 0x2e360
leaq -0x220(%rbp), %rdi
callq 0x5072e
leaq -0x240(%rbp), %rdi
callq 0x5072e
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x41148
callq 0x2e360
movq %r14, %rax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x41239
jmp 0x4116b
jmp 0x41173
jmp 0x41239
movq %rax, %rbx
jmp 0x4124e
movq %rax, %rbx
jmp 0x4125a
jmp 0x411fa
jmp 0x41222
jmp 0x41239
jmp 0x411a0
movq %rax, %rbx
movq %r13, %rdi
jmp 0x41199
jmp 0x411a0
movq %rax, %rbx
movq %r15, %rdi
callq 0x2e360
jmp 0x411a3
movq %rax, %rbx
movq %r14, %rdi
jmp 0x412fe
jmp 0x41275
jmp 0x41275
movq %rax, %rbx
jmp 0x4136a
movq %rax, %rbx
movq -0x200(%rbp), %rdi
cmpq %r15, %rdi
jne 0x41365
jmp 0x4136a
movq %rax, %rbx
jmp 0x41376
movq %rax, %rbx
movq -0x200(%rbp), %rdi
cmpq %r15, %rdi
je 0x41376
callq 0x2e360
jmp 0x41376
movq %rax, %rbx
jmp 0x41382
movq %rax, %rbx
jmp 0x4139a
movq %rax, %rbx
movq -0x258(%rbp), %rdi
testq %rdi, %rdi
jne 0x41395
jmp 0x4139a
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4123c
callq 0x2e360
jmp 0x4123c
movq %rax, %rbx
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4124e
callq 0x2e360
leaq -0x200(%rbp), %rdi
callq 0x505f8
movq %r12, %rdi
jmp 0x412fe
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x41288
callq 0x2e360
jmp 0x41288
movq %rax, %rbx
jmp 0x41359
movq %rax, %rbx
jmp 0x41320
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x412ad
callq 0x2e360
jmp 0x412ad
movq %rax, %rbx
jmp 0x41335
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x412ee
callq 0x2e360
jmp 0x412ee
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x412d2
callq 0x2e360
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x41308
callq 0x2e360
jmp 0x41308
movq %rax, %rbx
jmp 0x4134d
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x41359
callq 0x2e360
jmp 0x41359
movq %rax, %rbx
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x41320
callq 0x2e360
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x41335
callq 0x2e360
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x4134d
callq 0x2e360
leaq -0x200(%rbp), %rdi
callq 0x5072e
movq -0x120(%rbp), %rdi
testq %rdi, %rdi
je 0x4136a
callq 0x2e360
leaq -0x220(%rbp), %rdi
callq 0x5072e
leaq -0x240(%rbp), %rdi
callq 0x5072e
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x4139a
callq 0x2e360
movq %rbx, %rdi
callq 0x2e730