// File: /workspace/github_cpp_makefile_star2_O2/eniac[P]Mantis/src/compile/compile_p4.cpp
// Function: generateMetadata(std::vector<AstNode*, std::allocator<AstNode*>>*, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, P4RMalleableValueNode*, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, P4RMalleableValueNode*>>> const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, P4RMalleableFieldNode*, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, P4RMalleableFieldNode*>>> const&, int, int)
void generateMetadata(vector<AstNode*>* newNodes,
                      const unordered_map<string,
                                          P4RMalleableValueNode*>& mblValues,
                      const unordered_map<string,
                                          P4RMalleableFieldNode*>& mblFields,
                      int ing_iso_opt, int egr_iso_opt) {
    ostringstream oss;
    // Ing
    oss << "header_type "<< kP4rIngMetadataType << " {\n"
        << "  fields {\n";
    if (((unsigned int)ing_iso_opt) & 0b1) {
        oss << "  __mv : 1;\n";
    } 
    if (((unsigned int)ing_iso_opt) & 0b10) {
        oss << "  __vv : 1;\n";        
    }

    // Presume malleables at ing
    for (auto kv : mblValues){
        // Values need to be as wide as specified
        VarWidthNode* widthNode =
                dynamic_cast<VarWidthNode*>(kv.second->varWidth_);
        string varWidth = widthNode->val_->toString();
        oss << "  " << kv.first << " : " << varWidth << ";" << endl;
    }
    for (auto kv : mblFields){
        // Ref-vars only need to be wide enough to store an index
        auto alts = findAllAlts(*kv.second);
        int indexWidth = 1;
        if(alts.size()!=1) {
            indexWidth = int(ceil(log2(alts.size())));
        }
        oss << "  " << kv.first << kP4rIndexSuffix << " : "
            << indexWidth << ";" << endl;
    }

    oss << " }" << endl;
    oss << "}" << endl;
    oss << "metadata " << kP4rIngMetadataType << " "
                       << kP4rIngMetadataName << ";\n\n";

    newNodes->push_back(new UnanchoredNode(new string(oss.str()),
                                           new string("metadata"),
                                           new string(kP4rIngMetadataName)));
    // Egr
    oss.str("");
    oss << "header_type "<< kP4rEgrMetadataType << " {\n"
        << "  fields {\n";
    if (((unsigned int)egr_iso_opt) & 0b1) {
        oss << "  __mv : 1;\n";
    }

    oss << "  }" << endl;
    oss << "}" << endl;
    oss << "metadata " << kP4rEgrMetadataType << " "
                       << kP4rEgrMetadataName << ";\n\n";

    newNodes->push_back(new UnanchoredNode(new string(oss.str()),
                                           new string("metadata"),
                                           new string(kP4rEgrMetadataName)));    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movl %r8d, -0x30(%rbp)
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, -0x38(%rbp)
leaq -0x1f8(%rbp), %r14
movq %r14, %rdi
callq 0x415a0
leaq 0x9129(%rip), %rsi      # 0x78dc5
movq %r14, %rdi
callq 0x413d0
leaq 0xd176(%rip), %rsi      # 0x7ce21
movq %rax, %rdi
callq 0x413d0
leaq 0xcfa5(%rip), %rsi      # 0x7cc5f
movq %rax, %rdi
callq 0x413d0
leaq 0x9109(%rip), %rsi      # 0x78dd2
movq %rax, %rdi
callq 0x413d0
testb $0x1, %bl
je 0x6fce9
leaq 0xd153(%rip), %rsi      # 0x7ce30
leaq -0x1f8(%rbp), %rdi
callq 0x413d0
testb $0x2, %bl
je 0x6fd01
leaq 0xd148(%rip), %rsi      # 0x7ce3d
leaq -0x1f8(%rbp), %rdi
callq 0x413d0
addq $0x10, %r12
leaq -0x60(%rbp), %rbx
leaq -0x80(%rbp), %r14
leaq 0x99f9(%rip), %r13      # 0x7970d
movq (%r12), %r12
testq %r12, %r12
je 0x6fda2
leaq 0x8(%r12), %rsi
movq %rbx, %rdi
callq 0x4f432
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x40(%rax), %rsi
movq (%rsi), %rax
movq %r14, %rdi
callq *(%rax)
leaq -0x1f8(%rbp), %rdi
leaq 0xb300(%rip), %rsi      # 0x7b050
callq 0x413d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x41380
movq %rax, %rdi
leaq 0xd062(%rip), %rsi      # 0x7cdcc
callq 0x413d0
movq %rax, %rdi
movq %r14, %rsi
callq 0x41380
movq %rax, %rdi
movq %r13, %rsi
callq 0x413d0
movq %rax, %rdi
callq 0x41240
movq %r14, %rdi
callq 0x418c8
movq %rbx, %rdi
callq 0x418c8
jmp 0x6fd14
addq $0x10, %r15
leaq -0x60(%rbp), %r12
leaq -0x80(%rbp), %r13
leaq 0x9958(%rip), %r14      # 0x7970d
movq (%r15), %r15
testq %r15, %r15
je 0x6fe6a
leaq 0x8(%r15), %rsi
movq %r12, %rdi
callq 0x4f6a2
movq -0x40(%rbp), %rsi
movq %r13, %rdi
callq 0x72552
movq -0x78(%rbp), %rdi
subq -0x80(%rbp), %rdi
pushq $0x1
popq %rbx
cmpq $0x8, %rdi
je 0x6fdfc
sarq $0x3, %rdi
callq 0x710d9
callq 0x41090
cvttsd2si %xmm0, %ebx
leaq -0x1f8(%rbp), %rdi
leaq 0xb246(%rip), %rsi      # 0x7b050
callq 0x413d0
movq %rax, %rdi
movq %r12, %rsi
callq 0x41380
movq %rax, %rdi
leaq 0xb0fa(%rip), %rsi      # 0x7af1e
callq 0x413d0
movq %rax, %rdi
leaq 0xcf99(%rip), %rsi      # 0x7cdcc
callq 0x413d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x41760
movq %rax, %rdi
movq %r14, %rsi
callq 0x413d0
movq %rax, %rdi
callq 0x41240
movq %r13, %rdi
callq 0x71770
movq %r12, %rdi
callq 0x418c8
jmp 0x6fdb5
leaq 0xcfe9(%rip), %rsi      # 0x7ce5a
leaq -0x1f8(%rbp), %rdi
callq 0x413d0
movq %rax, %rdi
callq 0x41240
leaq 0xae24(%rip), %rsi      # 0x7acb0
leaq -0x1f8(%rbp), %rdi
callq 0x413d0
movq %rax, %rdi
callq 0x41240
leaq 0x8f3f(%rip), %rsi      # 0x78de6
leaq -0x1f8(%rbp), %rdi
callq 0x413d0
leaq 0xcf67(%rip), %rsi      # 0x7ce21
movq %rax, %rdi
callq 0x413d0
leaq 0xb188(%rip), %rsi      # 0x7b051
movq %rax, %rdi
callq 0x413d0
leaq 0xad03(%rip), %rsi      # 0x7abdb
movq %rax, %rdi
callq 0x413d0
leaq 0xa2cd(%rip), %rsi      # 0x7a1b4
movq %rax, %rdi
callq 0x413d0
pushq $0x58
popq %rdi
callq 0x413f0
movq %rax, %r14
pushq $0x20
popq %rdi
callq 0x413f0
movq %rax, %r12
leaq -0x1f0(%rbp), %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x416b0
pushq $0x20
popq %rdi
callq 0x413f0
movq %rax, %r13
leaq 0xcea7(%rip), %rsi      # 0x7cdd0
leaq -0x80(%rbp), %rdx
movq %rax, %rdi
callq 0x411c0
pushq $0x20
popq %rdi
callq 0x413f0
movq %rax, %rbx
leaq 0xac94(%rip), %rsi      # 0x7abdb
leaq -0x29(%rbp), %rdx
movq %rax, %rdi
callq 0x411c0
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x4dd8e
leaq -0x60(%rbp), %rsi
movq %r14, (%rsi)
movq -0x38(%rbp), %rdi
callq 0x44d46
leaq 0xa940(%rip), %rsi      # 0x7a8bb
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x411c0
leaq -0x60(%rbp), %rsi
movq %r15, %rdi
callq 0x41670
leaq -0x60(%rbp), %rdi
callq 0x418c8
leaq 0x8e21(%rip), %rsi      # 0x78dc5
leaq -0x1f8(%rbp), %rdi
callq 0x413d0
leaq 0xce93(%rip), %rsi      # 0x7ce4a
movq %rax, %rdi
callq 0x413d0
leaq 0xcc99(%rip), %rsi      # 0x7cc5f
movq %rax, %rdi
callq 0x413d0
leaq 0x8dfd(%rip), %rsi      # 0x78dd2
movq %rax, %rdi
callq 0x413d0
testb $0x1, -0x30(%rbp)
je 0x6fff6
leaq 0xce46(%rip), %rsi      # 0x7ce30
leaq -0x1f8(%rbp), %rdi
callq 0x413d0
leaq 0xce5c(%rip), %rsi      # 0x7ce59
leaq -0x1f8(%rbp), %rdi
callq 0x413d0
movq %rax, %rdi
callq 0x41240
leaq 0xac98(%rip), %rsi      # 0x7acb0
leaq -0x1f8(%rbp), %rdi
callq 0x413d0
movq %rax, %rdi
callq 0x41240
leaq 0x8db3(%rip), %rsi      # 0x78de6
leaq -0x1f8(%rbp), %rdi
callq 0x413d0
leaq 0xce04(%rip), %rsi      # 0x7ce4a
movq %rax, %rdi
callq 0x413d0
leaq 0xaffc(%rip), %rsi      # 0x7b051
movq %rax, %rdi
callq 0x413d0
leaq 0xab95(%rip), %rsi      # 0x7abf9
movq %rax, %rdi
callq 0x413d0
leaq 0xa141(%rip), %rsi      # 0x7a1b4
movq %rax, %rdi
callq 0x413d0
pushq $0x58
popq %rdi
callq 0x413f0
movq %rax, %r14
pushq $0x20
popq %rdi
callq 0x413f0
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0x416b0
pushq $0x20
popq %rdi
callq 0x413f0
movq %rax, %r15
leaq 0xcd22(%rip), %rsi      # 0x7cdd0
leaq -0x80(%rbp), %rdx
movq %rax, %rdi
callq 0x411c0
pushq $0x20
popq %rdi
callq 0x413f0
movq %rax, %rbx
leaq 0xab2d(%rip), %rsi      # 0x7abf9
leaq -0x29(%rbp), %rdx
movq %rax, %rdi
callq 0x411c0
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x4dd8e
leaq -0x60(%rbp), %rsi
movq %r14, (%rsi)
movq -0x38(%rbp), %rdi
callq 0x44d46
leaq -0x1f8(%rbp), %rdi
callq 0x410e0
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x70188
jmp 0x70165
movq %rax, %r13
movq %rbx, %rdi
jmp 0x70133
jmp 0x70165
movq %rax, %r13
movq %r15, %rdi
jmp 0x70133
movq %rax, %r13
movq %r12, %rdi
callq 0x413a0
jmp 0x70168
jmp 0x70188
jmp 0x7018d
jmp 0x70188
jmp 0x70188
jmp 0x70172
movq %rax, %r15
movq %rbx, %rdi
jmp 0x7015c
jmp 0x70172
movq %rax, %r15
movq %r13, %rdi
jmp 0x7015c
movq %rax, %r15
movq %r12, %rdi
callq 0x413a0
jmp 0x70175
jmp 0x70188
movq %rax, %r13
movq %r14, %rdi
callq 0x413a0
jmp 0x701b5
movq %rax, %r15
movq %r14, %rdi
callq 0x413a0
movq %r15, %r13
jmp 0x701b5
jmp 0x70188
jmp 0x70188
jmp 0x7018d
movq %rax, %r13
jmp 0x701b5
movq %rax, %r13
jmp 0x701ac
movq %rax, %r13
leaq -0x80(%rbp), %rdi
callq 0x418c8
jmp 0x701ac
movq %rax, %r13
leaq -0x80(%rbp), %rdi
callq 0x71770
leaq -0x60(%rbp), %rdi
callq 0x418c8
leaq -0x1f8(%rbp), %rdi
callq 0x410e0
movq %r13, %rdi
callq 0x41790