// File: /workspace/github_cpp_makefile_star2_O1/NovaGL[P]HarmonyHubControl/HarmonyHubControl.cpp
// Function: startCommunication(csocket*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int startCommunication(csocket* communicationcsocket, std::string strUserName, std::string strPassword)
{
    if(communicationcsocket == NULL || strUserName.length() == 0 || strPassword.length() == 0)
    {
        errorString = "startCommunication : Invalid communication parameter(s) provided";
        return 1;
    } 

    // Start communication
    std::string data = "<stream:stream to='connect.logitech.com' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en' version='1.0'>";
     communicationcsocket->write(data.c_str(), static_cast<unsigned int>(data.length()));
     memset(databuffer, 0, 1000000);
    memset(databuffer, 0, 1000000);
    communicationcsocket->read(databuffer, 1000000, false);
    
    std::string strData = databuffer;/* <- Expect: <?xml version='1.0' encoding='iso-8859-1'?><stream:stream from='' id='XXXXXXXX' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'><stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism></mechanisms></stream:features> */

    data = "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">";
    std::string tmp = "\0";
    tmp.append(strUserName);
    tmp.append("\0");
    tmp.append(strPassword);
    data.append(base64_encode(tmp.c_str(), static_cast<unsigned int>(tmp.length())));
    data.append("</auth>");
    communicationcsocket->write(data.c_str(), static_cast<unsigned int>(data.length())); 
   
    memset(databuffer, 0, 1000000);
    communicationcsocket->read(databuffer, 1000000, false);
    
    strData = databuffer; /* <- Expect: <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/> */
    if(strData != "<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>")
    {
        errorString = "startCommunication : connection error";
        return 1;
    } 

    data = "<stream:stream to='connect.logitech.com' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en' version='1.0'>";
    communicationcsocket->write(data.c_str(), static_cast<unsigned int>(data.length()));
    
    memset(databuffer, 0, 1000000);
    communicationcsocket->read(databuffer, 1000000, false);

    strData = databuffer; /* <- Expect: <?xml version='1.0' encoding='iso-8859-1'?><stream:stream from='' id='057a30bd' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'><stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism></mechanisms></stream:features> */

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
testq %rdi, %rdi
je 0x4552
movq %rsi, %r15
cmpq $0x0, 0x8(%rsi)
je 0x4552
movq %rdx, %r14
cmpq $0x0, 0x8(%rdx)
je 0x4552
movq %rdi, %rbx
leaq 0x18(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x7fe7(%rip), %rsi      # 0xc362
leaq 0x806b(%rip), %rdx      # 0xc3ed
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x8846
movq (%r12), %rsi
movl 0x8(%r12), %edx
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
leaq 0xff98(%rip), %r12      # 0x14340
movl $0xf4240, %edx          # imm = 0xF4240
movq %r12, %rdi
xorl %esi, %esi
callq 0x3190
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
movl $0xf4240, %edx          # imm = 0xF4240
xorl %ecx, %ecx
callq *(%rax)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r12, %rdi
callq 0x3150
leaq (%rax,%r12), %rdx
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x8846
leaq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x7ff3(%rip), %rcx      # 0xc3ee
movl $0x41, %r8d
xorl %esi, %esi
callq 0x3420
leaq 0x38(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0xab28(%rip), %rdx      # 0xef40
leaq 0x28(%rsp), %rdi
movq %rdx, %rsi
callq 0x8846
movq (%r15), %rsi
movq 0x8(%r15), %rdx
leaq 0x28(%rsp), %rdi
callq 0x3100
leaq 0xab03(%rip), %rsi      # 0xef40
leaq 0x28(%rsp), %rdi
callq 0x34f0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
leaq 0x28(%rsp), %rdi
callq 0x3100
movq 0x28(%rsp), %rsi
movl 0x30(%rsp), %edx
leaq 0x68(%rsp), %rdi
callq 0x3a45
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
leaq 0x8(%rsp), %rdi
callq 0x3100
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x449a
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x7f8f(%rip), %rsi      # 0xc430
leaq 0x8(%rsp), %rdi
callq 0x34f0
movq 0x8(%rsp), %rsi
movl 0x10(%rsp), %edx
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
leaq 0xfe7c(%rip), %r14      # 0x14340
movl $0xf4240, %edx          # imm = 0xF4240
movq %r14, %rdi
xorl %esi, %esi
callq 0x3190
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
movl $0xf4240, %edx          # imm = 0xF4240
xorl %ecx, %ecx
callq *(%rax)
leaq 0x48(%rsp), %r14
movq 0x8(%r14), %r15
leaq 0xfe4b(%rip), %r12      # 0x14340
movq %r12, %rdi
callq 0x3150
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x3420
leaq 0x7f21(%rip), %rsi      # 0xc438
leaq 0x48(%rsp), %rdi
callq 0x30f0
testl %eax, %eax
je 0x458f
movl $0x1, %r14d
movq 0xfd8e(%rip), %rdx      # 0x142c0
leaq 0xfd7f(%rip), %rdi      # 0x142b8
leaq 0x7f2c(%rip), %rcx      # 0xc46c
movl $0x25, %r8d
xorl %esi, %esi
callq 0x3420
jmp 0x4614
movq 0xfd67(%rip), %rdx      # 0x142c0
leaq 0xfd58(%rip), %rdi      # 0x142b8
leaq 0x7dba(%rip), %rcx      # 0xc321
movl $0x40, %r8d
xorl %esi, %esi
callq 0x3420
movl $0x1, %r14d
movl %r14d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x7dc3(%rip), %rcx      # 0xc362
movl $0x8b, %r8d
xorl %esi, %esi
callq 0x3420
movq 0x8(%rsp), %rsi
movl 0x10(%rsp), %edx
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
leaq 0xfd7b(%rip), %r15      # 0x14340
xorl %r14d, %r14d
movl $0xf4240, %edx          # imm = 0xF4240
movq %r15, %rdi
xorl %esi, %esi
callq 0x3190
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
movl $0xf4240, %edx          # imm = 0xF4240
xorl %ecx, %ecx
callq *(%rax)
leaq 0x48(%rsp), %rbx
movq 0x8(%rbx), %r15
leaq 0xfd47(%rip), %r12      # 0x14340
movq %r12, %rdi
callq 0x3150
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x3420
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x462b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4647
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x457a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x457a
movq %rax, %rbx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x469a
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x469a
jmp 0x4697
jmp 0x468b
movq %rax, %rbx
jmp 0x46b1
jmp 0x4692
movq %rax, %rbx
jmp 0x46cd
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x46b1
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x46cd
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x46e4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
movq %rbx, %rdi
callq 0x34a0