// File: /workspace/github_cpp_makefile_star2_O3/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 0x4b48
movq %rsi, %r15
cmpq $0x0, 0x8(%rsi)
je 0x4b48
movq %rdx, %r14
cmpq $0x0, 0x8(%rdx)
je 0x4b48
movq %rdi, %rbx
leaq 0x18(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x79f1(%rip), %rsi      # 0xc362
leaq 0x7a75(%rip), %rdx      # 0xc3ed
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x8dc8
movq (%r12), %rsi
movl 0x8(%r12), %edx
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
leaq 0xf9a2(%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 0x8dc8
leaq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x79fd(%rip), %rcx      # 0xc3ee
movl $0x41, %r8d
xorl %esi, %esi
callq 0x3420
leaq 0x38(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0xa532(%rip), %rdx      # 0xef40
leaq 0x28(%rsp), %rdi
movq %rdx, %rsi
callq 0x8dc8
movq (%r15), %rsi
movq 0x8(%r15), %rdx
leaq 0x28(%rsp), %rdi
callq 0x3100
leaq 0xa50d(%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 0x4045
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 0x4a90
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x7999(%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 0xf886(%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 0xf855(%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 0x792b(%rip), %rsi      # 0xc438
leaq 0x48(%rsp), %rdi
callq 0x30f0
testl %eax, %eax
je 0x4b85
movl $0x1, %r14d
movq 0xf798(%rip), %rdx      # 0x142c0
leaq 0xf789(%rip), %rdi      # 0x142b8
leaq 0x7936(%rip), %rcx      # 0xc46c
movl $0x25, %r8d
xorl %esi, %esi
callq 0x3420
jmp 0x4c0a
movq 0xf771(%rip), %rdx      # 0x142c0
leaq 0xf762(%rip), %rdi      # 0x142b8
leaq 0x77c4(%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 0x77cd(%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 0xf785(%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 0xf751(%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 0x4c21
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4c3d
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x4b70
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4b70
movq %rax, %rbx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4c90
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4c90
jmp 0x4c8d
jmp 0x4c81
movq %rax, %rbx
jmp 0x4ca7
jmp 0x4c88
movq %rax, %rbx
jmp 0x4cc3
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x4ca7
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4cc3
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x4cda
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
movq %rbx, %rdi
callq 0x34a0