// File: EmbeddedPaul166[P]SNMP-Agent/src/main.cpp
// Function: encodeASequenceInsideASequence(Manager&)
void encodeASequenceInsideASequence(Manager & manager)
{
    std::vector<std::byte> beginVector;
    std::vector<std::byte> endVector;
    int lengthInBytes = 0;
    
    DataType dataType;
    dataType.m_baseType = BaseDataType::SEQUENCE_OF;
    dataType.m_complexity = EncodingComplexity::CONSTRUCTED;
    dataType.m_visibility = DataVisibility::UNIVERSAL;
    manager.startASequence(dataType, beginVector);
    
    int x = 5;
    dataType.m_baseType = BaseDataType::INTEGER;
    dataType.m_complexity = EncodingComplexity::PRIMITIVE;
    manager.addInteger(dataType, x, lengthInBytes, endVector);
    
    std::string y = "kupa";
    dataType.m_baseType = BaseDataType::OCTET_STRING;
    manager.addOctetString(dataType, y, lengthInBytes, endVector);
    
    std::vector<std::byte> beginVector2;
    std::vector<std::byte> endVector2;
    int lengthInBytes2 = 0;
    
    dataType.m_baseType = BaseDataType::SEQUENCE_OF;
    dataType.m_complexity = EncodingComplexity::CONSTRUCTED;
    dataType.m_visibility = DataVisibility::UNIVERSAL;
    manager.startASequence(dataType, beginVector2);
    
    int l = 5;
    dataType.m_baseType = BaseDataType::INTEGER;
    dataType.m_complexity = EncodingComplexity::PRIMITIVE;
    manager.addInteger(dataType, l, lengthInBytes2, endVector2);
    
    int k = 10;
    dataType.m_baseType = BaseDataType::INTEGER;
    dataType.m_complexity = EncodingComplexity::PRIMITIVE;
    manager.addInteger(dataType, k, lengthInBytes2, endVector2);
    
    manager.endSubSequence(lengthInBytes, lengthInBytes2, beginVector2);
    manager.getEncodedSubSequence(beginVector2, endVector2, endVector);
    
    int j = 5;
    dataType.m_baseType = BaseDataType::INTEGER;
    dataType.m_complexity = EncodingComplexity::PRIMITIVE;
    manager.addInteger(dataType, j, lengthInBytes, endVector);

    manager.endASequence(lengthInBytes, beginVector);
    manager.getEncodedSequence(beginVector, endVector);
    
    for (std::vector<std::byte>::size_type i = 0; i < beginVector.size(); i++)
    {
        std::bitset<8> x(std::to_integer<uint8_t>(beginVector[i]));
        std::cout << x << std::endl;
    }
    
    std::cout << std::endl;
    std::cout << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x8110
leaq -0x40(%rbp), %rdi
callq 0x8110
movl $0x0, -0x44(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x44a20
jmp 0x79e6
movl $0x6, -0x98(%rbp)
movl $0x1, -0x94(%rbp)
movl $0x0, -0x8c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0xacd0
jmp 0x7a1a
movl $0x5, -0xa8(%rbp)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x94(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
leaq -0x44(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0xad10
jmp 0x7a59
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x67a0
movq -0x160(%rbp), %rdx
leaq 0x4066c(%rip), %rsi     # 0x480e6
leaq -0xc8(%rbp), %rdi
callq 0x8130
jmp 0x7a88
leaq -0xc9(%rbp), %rdi
callq 0x64d0
movl $0x1, -0x98(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
leaq -0x44(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0xad60
jmp 0x7abf
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x8110
leaq -0x100(%rbp), %rdi
callq 0x8110
movq -0x168(%rbp), %rdx
movl $0x0, -0x104(%rbp)
movl $0x6, -0x98(%rbp)
movl $0x1, -0x94(%rbp)
movl $0x0, -0x8c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xacd0
jmp 0x7b1f
movl $0x5, -0x108(%rbp)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x94(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x108(%rbp), %rdx
leaq -0x104(%rbp), %rcx
leaq -0x100(%rbp), %r8
callq 0xad10
jmp 0x7b64
movl $0xa, -0x10c(%rbp)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x94(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x10c(%rbp), %rdx
leaq -0x104(%rbp), %rcx
leaq -0x100(%rbp), %r8
callq 0xad10
jmp 0x7ba9
movq -0x10(%rbp), %rdi
leaq -0x44(%rbp), %rsi
leaq -0x104(%rbp), %rdx
leaq -0xe8(%rbp), %rcx
callq 0xaf40
jmp 0x7bc6
movq -0x10(%rbp), %rsi
leaq -0x128(%rbp), %rdi
leaq -0xe8(%rbp), %rdx
leaq -0x100(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0xaf80
jmp 0x7bea
leaq -0x128(%rbp), %rdi
callq 0x8320
movl $0x5, -0x12c(%rbp)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x94(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x12c(%rbp), %rdx
leaq -0x44(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0xad10
jmp 0x7c35
movq -0x10(%rbp), %rdi
leaq -0x44(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0xae90
jmp 0x7c48
movq -0x10(%rbp), %rsi
leaq -0x148(%rbp), %rdi
leaq -0x28(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0xaed0
jmp 0x7c62
leaq -0x148(%rbp), %rdi
callq 0x8320
movq $0x0, -0x150(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x8380
movq %rax, %rcx
movq -0x170(%rbp), %rax
cmpq %rcx, %rax
jae 0x7daf
movq -0x150(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x83a0
movb (%rax), %al
movb %al, -0x1(%rbp)
movzbl -0x1(%rbp), %eax
movl %eax, %esi
leaq -0x158(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x83c0
movq -0x180(%rbp), %rsi
movq 0x612c9(%rip), %rdi     # 0x68fa8
callq 0x8410
movq %rax, -0x178(%rbp)
jmp 0x7ced
movq -0x178(%rbp), %rdi
movq 0x61285(%rip), %rsi     # 0x68f80
callq 0x64b0
jmp 0x7d02
jmp 0x7d04
movq -0x150(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x150(%rbp)
jmp 0x7c79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x7e3c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x7e30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0xc9(%rbp), %rdi
callq 0x64d0
jmp 0x7e30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x7e24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x8320
leaq -0xe8(%rbp), %rdi
callq 0x8320
jmp 0x7e24
movq 0x611f2(%rip), %rdi     # 0x68fa8
movq 0x611c3(%rip), %rsi     # 0x68f80
callq 0x64b0
jmp 0x7dc4
movq 0x611dd(%rip), %rdi     # 0x68fa8
movq 0x611ae(%rip), %rsi     # 0x68f80
callq 0x64b0
jmp 0x7dd9
leaq -0x100(%rbp), %rdi
callq 0x8320
leaq -0xe8(%rbp), %rdi
callq 0x8320
leaq -0xc8(%rbp), %rdi
callq 0x62e0
leaq -0x98(%rbp), %rdi
callq 0x44a90
leaq -0x40(%rbp), %rdi
callq 0x8320
leaq -0x28(%rbp), %rdi
callq 0x8320
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0xc8(%rbp), %rdi
callq 0x62e0
leaq -0x98(%rbp), %rdi
callq 0x44a90
leaq -0x40(%rbp), %rdi
callq 0x8320
leaq -0x28(%rbp), %rdi
callq 0x8320
movq -0xa0(%rbp), %rdi
callq 0x6790
nopw (%rax,%rax)