// File: NovaGL[P]HarmonyHubControl/HarmonyHubControl.cpp
// Function: parseConfiguration(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<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::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>&, std::vector<Device, std::allocator<Device>>&)
int parseConfiguration(const std::string& strConfiguration, std::map< std::string, std::string >& mapActivities, std::vector< Device >& vecDevices)
{
    rapidjson::Document doc;
    doc.Parse(strConfiguration.c_str());
    if(doc.HasParseError())
    {
        std::ostringstream stringStream;
        stringStream << "parseConfiguration : Error(offset " << doc.GetErrorOffset() << "): " <<
            GetParseError_En(doc.GetParseError());
        errorString = stringStream.str();
        return 1;
    }
    
    // Search for activities
    rapidjson::Value::ConstMemberIterator itr = doc.FindMember("activity");
    if (itr != doc.MemberEnd() && itr->value.IsArray())
    {
        for (const auto& activity : itr->value.GetArray())
        {
            mapActivities.insert(std::map< std::string, std::string>::value_type(TryGetMemberString(activity,"id"), TryGetMemberString(activity,"label")));
        }
    }
    
    // Search for devices and commands
    itr = doc.FindMember("device");
    if (itr != doc.MemberEnd() && itr->value.IsArray())
    {
        for (const auto& device : itr->value.GetArray())
        {
            Device d;
            d.m_strID = TryGetMemberString(device, "id");
            d.m_strLabel = TryGetMemberString(device, "label");
            d.m_strType = TryGetMemberString(device, "type");
            d.m_strManufacturer = TryGetMemberString(device, "manufacturer");
            d.m_strModel = TryGetMemberString(device, "model");

            if (parseControlGroup(device, d.m_vecFunctions) != 0)
            {
                return 1;
            }

            vecDevices.push_back(d);
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x570, %rsp            # imm = 0x570
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
xorl %eax, %eax
movl %eax, %ecx
leaq -0x80(%rbp), %rdi
movq %rdi, -0x498(%rbp)
movl $0x400, %edx            # imm = 0x400
movq %rcx, %rsi
callq 0x9050
movq -0x10(%rbp), %rdi
callq 0x31c0
movq -0x498(%rbp), %rdi
movq %rax, %rsi
callq 0x9150
jmp 0x65dd
leaq -0x80(%rbp), %rdi
callq 0x9180
movb %al, -0x499(%rbp)
jmp 0x65ee
movb -0x499(%rbp), %al
testb $0x1, %al
jne 0x65fd
jmp 0x673b
leaq -0x208(%rbp), %rdi
callq 0x34b0
jmp 0x660b
leaq 0x103b7(%rip), %rsi     # 0x169c9
leaq -0x208(%rbp), %rdi
callq 0x3360
movq %rax, -0x4a8(%rbp)
jmp 0x6627
leaq -0x80(%rbp), %rdi
callq 0x9470
movq %rax, -0x4b0(%rbp)
jmp 0x6639
movq -0x4b0(%rbp), %rsi
movq -0x4a8(%rbp), %rdi
callq 0x3110
movq %rax, -0x4b8(%rbp)
jmp 0x6655
movq -0x4b8(%rbp), %rdi
leaq 0x10389(%rip), %rsi     # 0x169ec
callq 0x3360
movq %rax, -0x4c0(%rbp)
jmp 0x6671
leaq -0x80(%rbp), %rdi
callq 0x95e0
movl %eax, -0x4c4(%rbp)
jmp 0x6682
movl -0x4c4(%rbp), %edi
callq 0x9490
movq %rax, -0x4d0(%rbp)
jmp 0x6696
movq -0x4d0(%rbp), %rsi
movq -0x4c0(%rbp), %rdi
callq 0x3360
jmp 0x66ab
leaq -0x228(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x33a0
jmp 0x66c0
leaq 0x1bcb1(%rip), %rdi     # 0x22378
leaq -0x228(%rbp), %rsi
callq 0x3460
leaq -0x228(%rbp), %rdi
callq 0x3698
movl $0x1, -0x4(%rbp)
movl $0x1, -0x22c(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x3120
jmp 0x6dc4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x6dd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x3120
jmp 0x6dd9
leaq 0x100fe(%rip), %rdx     # 0x16840
leaq -0x240(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x9600
jmp 0x6754
leaq -0x238(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x9690
jmp 0x6769
leaq -0x248(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x96e0
jmp 0x677b
leaq -0x238(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x96b0
movb %al, -0x4d1(%rbp)
jmp 0x6796
movb -0x4d1(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x4d2(%rbp)
jne 0x67ab
jmp 0x67e6
leaq -0x238(%rbp), %rdi
callq 0x8f80
movq %rax, -0x4e0(%rbp)
jmp 0x67c0
movq -0x4e0(%rbp), %rdi
addq $0x10, %rdi
callq 0x92c0
movb %al, -0x4e1(%rbp)
jmp 0x67d8
movb -0x4e1(%rbp), %al
movb %al, -0x4d2(%rbp)
jmp 0x67e6
movb -0x4d2(%rbp), %al
testb $0x1, %al
jne 0x67f5
jmp 0x6a0e
leaq -0x238(%rbp), %rdi
callq 0x8f80
movq %rax, -0x4f0(%rbp)
jmp 0x680a
movq -0x4f0(%rbp), %rsi
addq $0x10, %rsi
leaq -0x258(%rbp), %rdi
callq 0x9310
jmp 0x6823
leaq -0x258(%rbp), %rax
movq %rax, -0x250(%rbp)
movq -0x250(%rbp), %rdi
callq 0x9380
movq %rax, -0x4f8(%rbp)
jmp 0x6846
movq -0x4f8(%rbp), %rax
movq %rax, -0x260(%rbp)
movq -0x250(%rbp), %rdi
callq 0x93a0
movq %rax, -0x500(%rbp)
jmp 0x6869
movq -0x500(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x260(%rbp), %rax
cmpq -0x268(%rbp), %rax
jne 0x68b9
movl $0x2, -0x22c(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x93c0
jmp 0x6a0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x69fb
movq -0x260(%rbp), %rax
movq %rax, -0x270(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x508(%rbp)
movq -0x270(%rbp), %rsi
leaq 0xfea2(%rip), %rdx      # 0x16782
leaq -0x2d0(%rbp), %rdi
callq 0x5eb0
jmp 0x68ee
movq -0x270(%rbp), %rsi
leaq 0x100b1(%rip), %rdx     # 0x169ad
leaq -0x2f0(%rbp), %rdi
callq 0x5eb0
jmp 0x690a
leaq -0x2b0(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
leaq -0x2f0(%rbp), %rdx
callq 0x97a0
jmp 0x6926
movq -0x508(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x9760
movb %dl, -0x511(%rbp)
movq %rax, -0x510(%rbp)
jmp 0x6948
movb -0x511(%rbp), %al
movq -0x510(%rbp), %rcx
movq %rcx, -0x300(%rbp)
movb %al, -0x2f8(%rbp)
leaq -0x2b0(%rbp), %rdi
callq 0x97e0
leaq -0x2f0(%rbp), %rdi
callq 0x3698
leaq -0x2d0(%rbp), %rdi
callq 0x3698
movq -0x260(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x260(%rbp)
jmp 0x6877
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x69ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x69e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x2b0(%rbp), %rdi
callq 0x97e0
leaq -0x2f0(%rbp), %rdi
callq 0x3698
leaq -0x2d0(%rbp), %rdi
callq 0x3698
leaq -0x258(%rbp), %rdi
callq 0x93c0
jmp 0x6dd9
jmp 0x6a0e
leaq 0xffdb(%rip), %rdx      # 0x169f0
leaq -0x308(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x9600
jmp 0x6a27
leaq -0x238(%rbp), %rdi
leaq -0x308(%rbp), %rsi
callq 0x9810
jmp 0x6a3c
leaq -0x310(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x96e0
jmp 0x6a4e
leaq -0x238(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x96b0
movb %al, -0x512(%rbp)
jmp 0x6a69
movb -0x512(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x513(%rbp)
jne 0x6a7e
jmp 0x6ab9
leaq -0x238(%rbp), %rdi
callq 0x8f80
movq %rax, -0x520(%rbp)
jmp 0x6a93
movq -0x520(%rbp), %rdi
addq $0x10, %rdi
callq 0x92c0
movb %al, -0x521(%rbp)
jmp 0x6aab
movb -0x521(%rbp), %al
movb %al, -0x513(%rbp)
jmp 0x6ab9
movb -0x513(%rbp), %al
testb $0x1, %al
jne 0x6ac8
jmp 0x6db3
leaq -0x238(%rbp), %rdi
callq 0x8f80
movq %rax, -0x530(%rbp)
jmp 0x6add
movq -0x530(%rbp), %rsi
addq $0x10, %rsi
leaq -0x320(%rbp), %rdi
callq 0x9310
jmp 0x6af6
leaq -0x320(%rbp), %rax
movq %rax, -0x318(%rbp)
movq -0x318(%rbp), %rdi
callq 0x9380
movq %rax, -0x538(%rbp)
jmp 0x6b19
movq -0x538(%rbp), %rax
movq %rax, -0x328(%rbp)
movq -0x318(%rbp), %rdi
callq 0x93a0
movq %rax, -0x540(%rbp)
jmp 0x6b3c
movq -0x540(%rbp), %rax
movq %rax, -0x330(%rbp)
movq -0x328(%rbp), %rax
cmpq -0x330(%rbp), %rax
jne 0x6b80
movl $0x4, -0x22c(%rbp)
jmp 0x6d8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x6da3
movq -0x328(%rbp), %rax
movq %rax, -0x338(%rbp)
leaq -0x3f0(%rbp), %rdi
callq 0x9830
movq -0x338(%rbp), %rsi
leaq 0xfbda(%rip), %rdx      # 0x16782
leaq -0x410(%rbp), %rdi
callq 0x5eb0
jmp 0x6bb6
leaq -0x3f0(%rbp), %rdi
leaq -0x410(%rbp), %rsi
movq %rsi, -0x548(%rbp)
callq 0x3460
movq -0x548(%rbp), %rdi
callq 0x3698
movq -0x338(%rbp), %rsi
leaq 0xfdc3(%rip), %rdx      # 0x169ad
leaq -0x430(%rbp), %rdi
callq 0x5eb0
jmp 0x6bf8
leaq -0x3d0(%rbp), %rdi
leaq -0x430(%rbp), %rsi
movq %rsi, -0x550(%rbp)
callq 0x3460
movq -0x550(%rbp), %rdi
callq 0x3698
movq -0x338(%rbp), %rsi
leaq 0xfdcb(%rip), %rdx      # 0x169f7
leaq -0x450(%rbp), %rdi
callq 0x5eb0
jmp 0x6c3a
leaq -0x370(%rbp), %rdi
leaq -0x450(%rbp), %rsi
movq %rsi, -0x558(%rbp)
callq 0x3460
movq -0x558(%rbp), %rdi
callq 0x3698
movq -0x338(%rbp), %rsi
leaq 0xfd8e(%rip), %rdx      # 0x169fc
leaq -0x470(%rbp), %rdi
callq 0x5eb0
jmp 0x6c7c
leaq -0x3b0(%rbp), %rdi
leaq -0x470(%rbp), %rsi
movq %rsi, -0x560(%rbp)
callq 0x3460
movq -0x560(%rbp), %rdi
callq 0x3698
movq -0x338(%rbp), %rsi
leaq 0xfd59(%rip), %rdx      # 0x16a09
leaq -0x490(%rbp), %rdi
callq 0x5eb0
jmp 0x6cbe
leaq -0x390(%rbp), %rdi
leaq -0x490(%rbp), %rsi
movq %rsi, -0x570(%rbp)
callq 0x3460
movq -0x570(%rbp), %rdi
callq 0x3698
movq -0x338(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x6420
movl %eax, -0x564(%rbp)
jmp 0x6cff
movl -0x564(%rbp), %eax
cmpl $0x0, %eax
je 0x6d3d
movl $0x1, -0x4(%rbp)
movl $0x1, -0x22c(%rbp)
jmp 0x6d59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x3f0(%rbp), %rdi
callq 0x9910
jmp 0x6da3
movq -0x20(%rbp), %rdi
leaq -0x3f0(%rbp), %rsi
callq 0x98a0
jmp 0x6d4f
movl $0x0, -0x22c(%rbp)
leaq -0x3f0(%rbp), %rdi
callq 0x9910
movl -0x22c(%rbp), %eax
testl %eax, %eax
jne 0x6d8a
jmp 0x6d71
jmp 0x6d73
movq -0x328(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x328(%rbp)
jmp 0x6b4a
leaq -0x320(%rbp), %rdi
callq 0x93c0
movl -0x22c(%rbp), %eax
subl $0x4, %eax
je 0x6db1
jmp 0x6dc4
leaq -0x320(%rbp), %rdi
callq 0x93c0
jmp 0x6dd9
jmp 0x6db3
movl $0x0, -0x4(%rbp)
movl $0x1, -0x22c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x9220
movl -0x4(%rbp), %eax
addq $0x570, %rsp            # imm = 0x570
popq %rbp
retq
leaq -0x80(%rbp), %rdi
callq 0x9220
movq -0x88(%rbp), %rdi
callq 0x35e0
nop