// File: eniac[P]Mantis/src/compile/compile_p4.cpp
// Function: generateArgRegistersForIng(std::vector<AstNode*, std::allocator<AstNode*>>*, std::vector<std::pair<std::vector<std::pair<ReactionArgNode*, int>, std::allocator<std::pair<ReactionArgNode*, int>>>, int>, std::allocator<std::pair<std::vector<std::pair<ReactionArgNode*, int>, std::allocator<std::pair<ReactionArgNode*, int>>>, int>>> const&, int, bool)
static void generateArgRegistersForIng(vector<AstNode*>* newNodes,
                          const vector<ReactionArgBin>& bins, int ing_iso_opt, bool forIng) {
    string p4rArgHdrName;
    string p4rMetaName;
    string p4rSetArgsTableNameBase;
    string p4rSetArgsActionNameBase;
    string p4rSetArgsBlackboxNameBase;
    string p4rSetArgsRegNameBase;
    if(forIng) {
        p4rArgHdrName = std::string(kP4rIngArghdrName);
        p4rMetaName = std::string(kP4rIngMetadataName);
        p4rSetArgsTableNameBase = "__tiSetArgs";
        p4rSetArgsActionNameBase = "__aiSetArgs";
        p4rSetArgsBlackboxNameBase = "__biSetArgs";
        p4rSetArgsRegNameBase = "__riSetArgs";
    } else {
        p4rArgHdrName = std::string(kP4rEgrArghdrName);
        p4rMetaName = std::string(kP4rEgrMetadataName);
        p4rSetArgsTableNameBase = "__teSetArgs";
        p4rSetArgsActionNameBase = "__aeSetArgs";
        p4rSetArgsBlackboxNameBase = "__beSetArgs";
        p4rSetArgsRegNameBase = "__reSetArgs";
    }

    for (int i = 0; i < bins.size(); ++i) {
        ostringstream oss;
        oss << "table " << p4rSetArgsTableNameBase << i << " {\n"
            << "  actions { " << p4rSetArgsActionNameBase << i << "; }\n"
            << "  default_action : " << p4rSetArgsActionNameBase << i << "();\n"
            << "}\n\n"
            << "action " << p4rSetArgsActionNameBase << i << "() {\n";
        if (((unsigned int)ing_iso_opt) & 0b1) {
            oss << "  " << p4rSetArgsBlackboxNameBase << i << ".execute_stateful_alu("<< p4rMetaName << ".__mv);\n";
        } else {
            oss << "  " << p4rSetArgsBlackboxNameBase << i << ".execute_stateful_alu(0);\n";
        }
        oss << "}\n\n"
            << "blackbox stateful_alu " << p4rSetArgsBlackboxNameBase << i << " {\n"
            << "  reg : " << p4rSetArgsRegNameBase << i << ";\n"
            << "  update_lo_1_value : " << p4rArgHdrName
                                       << ".reg" << i << ";\n"
            << "}\n\n"
            << "register " << p4rSetArgsRegNameBase << i << " {\n"
            << "  width : " << bins[i].second << ";\n"
            << "  instance_count : 2;\n"
            << "}\n\n";

        auto newSetArgsNode = new UnanchoredNode(new string(oss.str()),
                                                 new string("table"),
                                                 new string("__tiSetArgs"));
        newNodes->push_back(newSetArgsNode);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x510, %rsp            # imm = 0x510
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
andb $0x1, %al
movb %al, -0x15(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xaa7f0
leaq -0x58(%rbp), %rdi
callq 0xaa7f0
leaq -0x78(%rbp), %rdi
callq 0xaa7f0
leaq -0x98(%rbp), %rdi
callq 0xaa7f0
leaq -0xb8(%rbp), %rdi
callq 0xaa7f0
leaq -0xd8(%rbp), %rdi
callq 0xaa7f0
testb $0x1, -0x15(%rbp)
je 0x122665
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0xaaa70
movq -0x320(%rbp), %rdx
leaq 0x1be05(%rip), %rsi     # 0x13e31c
leaq -0xf8(%rbp), %rdi
callq 0xaa7d0
jmp 0x122525
leaq -0x38(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
movq %rsi, -0x330(%rbp)
callq 0xaa6d0
movq -0x330(%rbp), %rdi
callq 0xaabe8
leaq -0xf9(%rbp), %rdi
callq 0xaa5f0
leaq -0x131(%rbp), %rdi
movq %rdi, -0x328(%rbp)
callq 0xaaa70
movq -0x328(%rbp), %rdx
leaq 0x1994e(%rip), %rsi     # 0x13bec3
leaq -0x130(%rbp), %rdi
callq 0xaa7d0
jmp 0x122583
leaq -0x58(%rbp), %rdi
leaq -0x130(%rbp), %rsi
movq %rsi, -0x338(%rbp)
callq 0xaa6d0
movq -0x338(%rbp), %rdi
callq 0xaabe8
leaq -0x131(%rbp), %rdi
callq 0xaa5f0
leaq 0x1b992(%rip), %rsi     # 0x13df4b
leaq -0x78(%rbp), %rdi
callq 0xaa7c0
jmp 0x1225c4
leaq 0x1bf1b(%rip), %rsi     # 0x13e4e6
leaq -0x98(%rbp), %rdi
callq 0xaa7c0
jmp 0x1225d9
leaq 0x1bf12(%rip), %rsi     # 0x13e4f2
leaq -0xb8(%rbp), %rdi
callq 0xaa7c0
jmp 0x1225ee
leaq 0x1bf09(%rip), %rsi     # 0x13e4fe
leaq -0xd8(%rbp), %rdi
callq 0xaa7c0
jmp 0x122603
jmp 0x1227ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
leaq -0xf9(%rbp), %rdi
callq 0xaa5f0
jmp 0x123022
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
leaq -0x131(%rbp), %rdi
callq 0xaa5f0
jmp 0x123022
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0x123022
leaq -0x159(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0xaaa70
movq -0x340(%rbp), %rdx
leaq 0x1bcec(%rip), %rsi     # 0x13e372
leaq -0x158(%rbp), %rdi
callq 0xaa7d0
jmp 0x122694
leaq -0x38(%rbp), %rdi
leaq -0x158(%rbp), %rsi
movq %rsi, -0x350(%rbp)
callq 0xaa6d0
movq -0x350(%rbp), %rdi
callq 0xaabe8
leaq -0x159(%rbp), %rdi
callq 0xaa5f0
leaq -0x181(%rbp), %rdi
movq %rdi, -0x348(%rbp)
callq 0xaaa70
movq -0x348(%rbp), %rdx
leaq 0x197fd(%rip), %rsi     # 0x13bee1
leaq -0x180(%rbp), %rdi
callq 0xaa7d0
jmp 0x1226f2
leaq -0x58(%rbp), %rdi
leaq -0x180(%rbp), %rsi
movq %rsi, -0x358(%rbp)
callq 0xaa6d0
movq -0x358(%rbp), %rdi
callq 0xaabe8
leaq -0x181(%rbp), %rdi
callq 0xaa5f0
leaq 0x1b850(%rip), %rsi     # 0x13df78
leaq -0x78(%rbp), %rdi
callq 0xaa7c0
jmp 0x122733
leaq 0x1bdd0(%rip), %rsi     # 0x13e50a
leaq -0x98(%rbp), %rdi
callq 0xaa7c0
jmp 0x122748
leaq 0x1bdc7(%rip), %rsi     # 0x13e516
leaq -0xb8(%rbp), %rdi
callq 0xaa7c0
jmp 0x12275d
leaq 0x1bdbe(%rip), %rsi     # 0x13e522
leaq -0xd8(%rbp), %rdi
callq 0xaa7c0
jmp 0x122772
jmp 0x1227ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
leaq -0x159(%rbp), %rdi
callq 0xaa5f0
jmp 0x123022
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
leaq -0x181(%rbp), %rdi
callq 0xaa5f0
jmp 0x123022
movl $0x0, -0x188(%rbp)
movslq -0x188(%rbp), %rax
movq %rax, -0x360(%rbp)
movq -0x10(%rbp), %rdi
callq 0xd1800
movq %rax, %rcx
movq -0x360(%rbp), %rax
cmpq %rcx, %rax
jae 0x122fda
leaq -0x300(%rbp), %rdi
callq 0xaa7b0
jmp 0x1227fc
leaq 0x175d3(%rip), %rsi     # 0x139dd6
leaq -0x300(%rbp), %rdi
callq 0xaa540
movq %rax, -0x368(%rbp)
jmp 0x122818
movq -0x368(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x370(%rbp)
jmp 0x122831
movq -0x370(%rbp), %rdi
movl -0x188(%rbp), %esi
callq 0xaaa20
movq %rax, -0x378(%rbp)
jmp 0x12284c
movq -0x378(%rbp), %rdi
leaq 0x1b73d(%rip), %rsi     # 0x13df97
callq 0xaa540
movq %rax, -0x380(%rbp)
jmp 0x122868
movq -0x380(%rbp), %rdi
leaq 0x1bcb8(%rip), %rsi     # 0x13e52e
callq 0xaa540
movq %rax, -0x388(%rbp)
jmp 0x122884
movq -0x388(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x390(%rbp)
jmp 0x1228a0
movq -0x390(%rbp), %rdi
movl -0x188(%rbp), %esi
callq 0xaaa20
movq %rax, -0x398(%rbp)
jmp 0x1228bb
movq -0x398(%rbp), %rdi
leaq 0x1bc72(%rip), %rsi     # 0x13e53b
callq 0xaa540
movq %rax, -0x3a0(%rbp)
jmp 0x1228d7
movq -0x3a0(%rbp), %rdi
leaq 0x1bad7(%rip), %rsi     # 0x13e3bc
callq 0xaa540
movq %rax, -0x3a8(%rbp)
jmp 0x1228f3
movq -0x3a8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x3b0(%rbp)
jmp 0x12290f
movq -0x3b0(%rbp), %rdi
movl -0x188(%rbp), %esi
callq 0xaaa20
movq %rax, -0x3b8(%rbp)
jmp 0x12292a
movq -0x3b8(%rbp), %rdi
leaq 0x1b478(%rip), %rsi     # 0x13ddb0
callq 0xaa540
movq %rax, -0x3c0(%rbp)
jmp 0x122946
movq -0x3c0(%rbp), %rdi
leaq 0x1bb01(%rip), %rsi     # 0x13e455
callq 0xaa540
movq %rax, -0x3c8(%rbp)
jmp 0x122962
movq -0x3c8(%rbp), %rdi
leaq 0x1798b(%rip), %rsi     # 0x13a2fb
callq 0xaa540
movq %rax, -0x3d0(%rbp)
jmp 0x12297e
movq -0x3d0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x3d8(%rbp)
jmp 0x12299a
movq -0x3d8(%rbp), %rdi
movl -0x188(%rbp), %esi
callq 0xaaa20
movq %rax, -0x3e0(%rbp)
jmp 0x1229b5
movq -0x3e0(%rbp), %rdi
leaq 0x1bb7d(%rip), %rsi     # 0x13e540
callq 0xaa540
jmp 0x1229ca
movl -0x14(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x122a92
leaq 0x19958(%rip), %rsi     # 0x13c338
leaq -0x300(%rbp), %rdi
callq 0xaa540
movq %rax, -0x3e8(%rbp)
jmp 0x1229f5
movq -0x3e8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x3f0(%rbp)
jmp 0x122a11
movq -0x3f0(%rbp), %rdi
movl -0x188(%rbp), %esi
callq 0xaaa20
movq %rax, -0x3f8(%rbp)
jmp 0x122a2c
movq -0x3f8(%rbp), %rdi
leaq 0x1b65d(%rip), %rsi     # 0x13e097
callq 0xaa540
movq %rax, -0x400(%rbp)
jmp 0x122a48
movq -0x400(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x408(%rbp)
jmp 0x122a61
movq -0x408(%rbp), %rdi
leaq 0x1bad7(%rip), %rsi     # 0x13e546
callq 0xaa540
jmp 0x122a76
jmp 0x122afc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0x122fcc
leaq 0x1989f(%rip), %rsi     # 0x13c338
leaq -0x300(%rbp), %rdi
callq 0xaa540
movq %rax, -0x410(%rbp)
jmp 0x122aae
movq -0x410(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x418(%rbp)
jmp 0x122aca
movq -0x418(%rbp), %rdi
movl -0x188(%rbp), %esi
callq 0xaaa20
movq %rax, -0x420(%rbp)
jmp 0x122ae5
movq -0x420(%rbp), %rdi
leaq 0x1ba5c(%rip), %rsi     # 0x13e54f
callq 0xaa540
jmp 0x122afa
jmp 0x122afc
leaq 0x1b952(%rip), %rsi     # 0x13e455
leaq -0x300(%rbp), %rdi
callq 0xaa540
movq %rax, -0x428(%rbp)
jmp 0x122b18
movq -0x428(%rbp), %rdi
leaq 0x1b4dd(%rip), %rsi     # 0x13e003
callq 0xaa540
movq %rax, -0x430(%rbp)
jmp 0x122b34
movq -0x430(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x438(%rbp)
jmp 0x122b50
movq -0x438(%rbp), %rdi
movl -0x188(%rbp), %esi
callq 0xaaa20
movq %rax, -0x440(%rbp)
jmp 0x122b6b
movq -0x440(%rbp), %rdi
leaq 0x1b41e(%rip), %rsi     # 0x13df97
callq 0xaa540
movq %rax, -0x448(%rbp)
jmp 0x122b87
movq -0x448(%rbp), %rdi
leaq 0x1b48c(%rip), %rsi     # 0x13e021
callq 0xaa540
movq %rax, -0x450(%rbp)
jmp 0x122ba3
movq -0x450(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x458(%rbp)
jmp 0x122bbf
movq -0x458(%rbp), %rdi
movl -0x188(%rbp), %esi
callq 0xaaa20
movq %rax, -0x460(%rbp)
jmp 0x122bda
movq -0x460(%rbp), %rdi
leaq 0x1724d(%rip), %rsi     # 0x139e35
callq 0xaa540
movq %rax, -0x468(%rbp)
jmp 0x122bf6
movq -0x468(%rbp), %rdi
leaq 0x1b44e(%rip), %rsi     # 0x13e052
callq 0xaa540
movq %rax, -0x470(%rbp)
jmp 0x122c12
movq -0x470(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x478(%rbp)
jmp 0x122c2b
movq -0x478(%rbp), %rdi
leaq 0x1b931(%rip), %rsi     # 0x13e56a
callq 0xaa540
movq %rax, -0x480(%rbp)
jmp 0x122c47
movq -0x480(%rbp), %rdi
movl -0x188(%rbp), %esi
callq 0xaaa20
movq %rax, -0x488(%rbp)
jmp 0x122c62
movq -0x488(%rbp), %rdi
leaq 0x171c5(%rip), %rsi     # 0x139e35
callq 0xaa540
movq %rax, -0x490(%rbp)
jmp 0x122c7e
movq -0x490(%rbp), %rdi
leaq 0x1b7c9(%rip), %rsi     # 0x13e455
callq 0xaa540
movq %rax, -0x498(%rbp)
jmp 0x122c9a
movq -0x498(%rbp), %rdi
leaq 0x170f8(%rip), %rsi     # 0x139da0
callq 0xaa540
movq %rax, -0x4a0(%rbp)
jmp 0x122cb6
movq -0x4a0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x4a8(%rbp)
jmp 0x122cd2
movq -0x4a8(%rbp), %rdi
movl -0x188(%rbp), %esi
callq 0xaaa20
movq %rax, -0x4b0(%rbp)
jmp 0x122ced
movq -0x4b0(%rbp), %rdi
leaq 0x1b29c(%rip), %rsi     # 0x13df97
callq 0xaa540
movq %rax, -0x4b8(%rbp)
jmp 0x122d09
movq -0x4b8(%rbp), %rdi
leaq 0x1b858(%rip), %rsi     # 0x13e56f
callq 0xaa540
movq %rax, -0x4c0(%rbp)
jmp 0x122d25
movq -0x10(%rbp), %rdi
movslq -0x188(%rbp), %rsi
callq 0x129df0
movq -0x4c0(%rbp), %rdi
movl 0x18(%rax), %esi
callq 0xaaa20
movq %rax, -0x4c8(%rbp)
jmp 0x122d4d
movq -0x4c8(%rbp), %rdi
leaq 0x170da(%rip), %rsi     # 0x139e35
callq 0xaa540
movq %rax, -0x4d0(%rbp)
jmp 0x122d69
movq -0x4d0(%rbp), %rdi
leaq 0x1b803(%rip), %rsi     # 0x13e57a
callq 0xaa540
movq %rax, -0x4d8(%rbp)
jmp 0x122d85
movq -0x4d8(%rbp), %rdi
leaq 0x1b6c2(%rip), %rsi     # 0x13e455
callq 0xaa540
jmp 0x122d9a
movl $0x58, %edi
callq 0xaa560
movq %rax, -0x4e0(%rbp)
jmp 0x122dad
movb $0x1, -0x30d(%rbp)
movl $0x20, %edi
callq 0xaa560
movq %rax, -0x4e8(%rbp)
jmp 0x122dc7
movq -0x4e8(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0xaa580
jmp 0x122ddc
movl $0x20, %edi
callq 0xaa560
movq %rax, -0x4f0(%rbp)
jmp 0x122def
movb $0x1, -0x30a(%rbp)
leaq -0x309(%rbp), %rdi
movq %rdi, -0x4f8(%rbp)
callq 0xaaa70
movq -0x4f0(%rbp), %rdi
movq -0x4f8(%rbp), %rdx
leaq 0x1b2ab(%rip), %rsi     # 0x13e0c9
callq 0xaa7d0
jmp 0x122e25
movb $0x0, -0x30a(%rbp)
movl $0x20, %edi
callq 0xaa560
movq %rax, -0x500(%rbp)
jmp 0x122e3f
movb $0x1, -0x30c(%rbp)
leaq -0x30b(%rbp), %rdi
movq %rdi, -0x508(%rbp)
callq 0xaaa70
movq -0x500(%rbp), %rdi
movq -0x508(%rbp), %rdx
leaq 0x1b0dd(%rip), %rsi     # 0x13df4b
callq 0xaa7d0
jmp 0x122e75
movq -0x500(%rbp), %rcx
movq -0x4f0(%rbp), %rdx
movq -0x4e8(%rbp), %rsi
movq -0x4e0(%rbp), %rdi
movb $0x0, -0x30c(%rbp)
callq 0xcaee0
jmp 0x122e9f
movb $0x0, -0x30d(%rbp)
leaq -0x30b(%rbp), %rdi
callq 0xaa5f0
leaq -0x309(%rbp), %rdi
callq 0xaa5f0
movq -0x4e0(%rbp), %rax
movq %rax, -0x308(%rbp)
movq -0x8(%rbp), %rdi
movq -0x308(%rbp), %rax
movq %rax, -0x318(%rbp)
leaq -0x318(%rbp), %rsi
callq 0xb2540
jmp 0x122eec
leaq -0x300(%rbp), %rdi
callq 0xaa130
movl -0x188(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x188(%rbp)
jmp 0x1227c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0x122fb3
movq -0x4e8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
callq 0xaa4e0
jmp 0x122fb3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0x122f8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
leaq -0x30b(%rbp), %rdi
callq 0xaa5f0
testb $0x1, -0x30c(%rbp)
jne 0x122f80
jmp 0x122f8c
movq -0x500(%rbp), %rdi
callq 0xaa4e0
jmp 0x122f8e
leaq -0x309(%rbp), %rdi
callq 0xaa5f0
testb $0x1, -0x30a(%rbp)
jne 0x122fa5
jmp 0x122fb1
movq -0x4f0(%rbp), %rdi
callq 0xaa4e0
jmp 0x122fb3
testb $0x1, -0x30d(%rbp)
jne 0x122fbe
jmp 0x122fca
movq -0x4e0(%rbp), %rdi
callq 0xaa4e0
jmp 0x122fcc
leaq -0x300(%rbp), %rdi
callq 0xaa130
jmp 0x123022
leaq -0xd8(%rbp), %rdi
callq 0xaabe8
leaq -0xb8(%rbp), %rdi
callq 0xaabe8
leaq -0x98(%rbp), %rdi
callq 0xaabe8
leaq -0x78(%rbp), %rdi
callq 0xaabe8
leaq -0x58(%rbp), %rdi
callq 0xaabe8
leaq -0x38(%rbp), %rdi
callq 0xaabe8
addq $0x510, %rsp            # imm = 0x510
popq %rbp
retq
leaq -0xd8(%rbp), %rdi
callq 0xaabe8
leaq -0xb8(%rbp), %rdi
callq 0xaabe8
leaq -0x98(%rbp), %rdi
callq 0xaabe8
leaq -0x78(%rbp), %rdi
callq 0xaabe8
leaq -0x58(%rbp), %rdi
callq 0xaabe8
leaq -0x38(%rbp), %rdi
callq 0xaabe8
movq -0x108(%rbp), %rdi
callq 0xaaa60
nopl (%rax)