// File: eniac[P]Mantis/src/compile/compile_p4.cpp
// Function: generateEgrDigestPacking(std::vector<AstNode*, std::allocator<AstNode*>>*, std::vector<ReactionArgNode*, std::allocator<ReactionArgNode*>> const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<FieldDecNode*, std::allocator<FieldDecNode*>>*, 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, std::vector<FieldDecNode*, std::allocator<FieldDecNode*>>*>>> const&, 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&, std::vector<AstNode*, std::allocator<AstNode*>> const&, int*)
vector<ReactionArgBin> generateEgrDigestPacking(
            vector<AstNode*>* newNodes,
            const vector<ReactionArgNode*>& reaction_args,
            const HeaderDecsMap& headerDecsMap,
            const unordered_map<string, P4RMalleableValueNode*>& mblValues,
            const unordered_map<string, P4RMalleableFieldNode*>& mblFields,
            const vector<AstNode*>& astNodes, int* egr_iso_opt) {
    if (reaction_args.size() == 0) {
        return vector<ReactionArgBin>();
    }

    // Get all reaction argument sizes
    vector<pair<ReactionArgNode*, int> > argSizes =
            findAllReactionArgSizes(reaction_args, headerDecsMap, mblValues,
                                    mblFields);

    vector<ReactionArgBin> argBins = runBinPackForIng(&argSizes, astNodes, false);
    vector<MblRefNode*> mblRefs = generatePackingTablesForIng(newNodes, argBins, false);

    // Update meas isolation
    if(argBins.size()<=1) {
        vector<ReactionArgNode*> reaction_args = findReactionArgs(astNodes);
        bool has_regarg = false;
        for (auto ra : reaction_args) {    
            if (ra->argType_==ReactionArgNode::REGISTER) {
                if(findRegargInIng(ra, astNodes)) {
                    has_regarg = true;
                }
            }    
        }
        if(!has_regarg) {
            if((*egr_iso_opt)==1) {
                *egr_iso_opt = 0;
            } else if ((*egr_iso_opt)==3) {
                *egr_iso_opt = 2;
            }
            PRINT_VERBOSE("Update ing isolation opt to %d\n", *egr_iso_opt);
        }
    }

    generateArgRegistersForIng(newNodes, argBins, *egr_iso_opt, false);

    PRINT_VERBOSE("Found %d generated malleable refs for egr\n", mblRefs.size());
    transformMalleableRefs(&mblRefs, mblValues, mblFields, newNodes);

    return argBins;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0xf8(%rbp)
movq %rdi, %rax
movq %rax, -0xf0(%rbp)
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0xb7500
cmpq $0x0, %rax
jne 0x1230df
movq -0xf8(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0xaa330
movq -0xf8(%rbp), %rdi
callq 0xcc7d0
jmp 0x1233ac
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
leaq -0x48(%rbp), %rdi
callq 0x12e0c0
movb $0x0, -0x49(%rbp)
movq 0x10(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0xb2bc0
jmp 0x12310b
movq -0xf8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
xorl %ecx, %ecx
callq 0x120000
jmp 0x123123
leaq -0x68(%rbp), %rdi
callq 0xb22f0
movq -0xf8(%rbp), %rdx
movq -0x10(%rbp), %rsi
leaq -0x90(%rbp), %rdi
xorl %ecx, %ecx
callq 0x120290
jmp 0x123147
movq -0xf8(%rbp), %rdi
callq 0xd1800
cmpq $0x1, %rax
ja 0x123324
movq 0x10(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x12dc10
jmp 0x12316f
movb $0x0, -0xa9(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
callq 0xb73b0
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
callq 0xb7240
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xcb210
testb $0x1, %al
jne 0x1231c6
jmp 0x1232d3
leaq -0xc0(%rbp), %rdi
callq 0xcb250
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
cmpl $0x4, 0x3c(%rax)
jne 0x1232c0
movq -0xd0(%rbp), %rax
movq %rax, -0x100(%rbp)
movq 0x10(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0xb2bc0
jmp 0x12320d
movq -0x100(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x12e7f0
movb %al, -0x101(%rbp)
jmp 0x123228
leaq -0xe8(%rbp), %rdi
callq 0xb22f0
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0x123240
jmp 0x1232be
movb $0x1, -0xa9(%rbp)
jmp 0x1232be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1233a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xb22f0
jmp 0x1233a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x123395
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x123370
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x123316
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0xb22f0
jmp 0x123316
jmp 0x1232c0
jmp 0x1232c2
leaq -0xc0(%rbp), %rdi
callq 0xcb270
jmp 0x1231aa
testb $0x1, -0xa9(%rbp)
jne 0x123308
movq 0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x1232f1
movq 0x18(%rbp), %rax
movl $0x0, (%rax)
jmp 0x123306
movq 0x18(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x123304
movq 0x18(%rbp), %rax
movl $0x2, (%rax)
jmp 0x123306
jmp 0x123308
leaq -0xa8(%rbp), %rdi
callq 0xccb90
jmp 0x123324
leaq -0xa8(%rbp), %rdi
callq 0xccb90
jmp 0x123370
movq -0xf8(%rbp), %rsi
movq -0x10(%rbp), %rdi
movq 0x18(%rbp), %rax
movl (%rax), %edx
xorl %ecx, %ecx
callq 0x122490
jmp 0x12333e
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq -0x90(%rbp), %rdi
callq 0x119120
jmp 0x123358
movb $0x1, -0x49(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xccb00
testb $0x1, -0x49(%rbp)
jne 0x12338a
jmp 0x12337e
leaq -0x90(%rbp), %rdi
callq 0xccb00
jmp 0x123395
movq -0xf8(%rbp), %rdi
callq 0xcc7f0
leaq -0x48(%rbp), %rdi
callq 0xd09b0
jmp 0x1233ac
movq -0xf8(%rbp), %rdi
callq 0xcc7f0
leaq -0x48(%rbp), %rdi
callq 0xd09b0
jmp 0x1233bc
movq -0xf0(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0xaaa60
nopw %cs:(%rax,%rax)