// File: NovaGL[P]HarmonyHubControl/HarmonyHubControl.cpp
// Function: submitCommand(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>>, 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::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int submitCommand(csocket* commandcsocket, std::string& strAuthorizationToken, std::string strCommand, std::string strCommandParameterPrimary, std::string strCommandParameterSecondary,std::string strCommandParameterThird,std::string strCommandParameterFourth ){

  if(commandcsocket== NULL || strAuthorizationToken.length() == 0)
    {
        errorString = "submitCommand : NULL csocket or empty authorization token provided";
        return 1;
    }

    std::string lstrCommand = strCommand;
    if(lstrCommand.length() == 0)
    {
        // No command provided, return query for the current activity
        lstrCommand = "get_current_activity_id";
        return 0;
    }

    std::string strData;

    std::string sendData;
    
    sendData = "<iq type=\"get\" id=\"";
    sendData.append(CONNECTION_ID);
    sendData.append("\"><oa xmlns=\"connect.logitech.com\" mime=\"vnd.logitech.harmony/vnd.logitech.harmony.engine?");

    // Issue the provided command
    if(lstrCommand == "get_current_activity_id" || lstrCommand == "get_current_activity_id_raw")
    {
        sendData.append("getCurrentActivity\" /></iq>");
    }
    if(lstrCommand == "get_config_raw")
    {
        sendData.append("config\"></oa></iq>");        
    }
    else if (lstrCommand == "start_activity" || strCommand == "start_activity_raw")
    {
        sendData.append("startactivity\">activityId=");
        sendData.append(strCommandParameterPrimary.c_str());
        sendData.append(":timestamp=0</oa></iq>");
    }
    else if (lstrCommand == "issue_device_command")
    {
        sendData.append("holdAction\">action={\"type\"::\"IRCommand\",\"deviceId\"::\"");
        sendData.append(strCommandParameterPrimary.c_str());
        sendData.append("\",\"command\"::\"");
        sendData.append(strCommandParameterSecondary.c_str());
        sendData.append("\"}:status=press</oa></iq>");
    }

    commandcsocket->write(sendData.c_str(), static_cast<unsigned int>(sendData.length()));
    
 if (strCommandParameterThird != "") 
   {
        sendData = "<iq type=\"get\" id=\"";
        sendData.append(CONNECTION_ID);
        sendData.append("\"><oa xmlns=\"connect.logitech.com\" mime=\"vnd.logitech.harmony/vnd.logitech.harmony.engine?");

    sendData.append("holdAction\">action={\"type\"::\"IRCommand\",\"deviceId\"::\"");
        sendData.append(strCommandParameterPrimary.c_str());
        sendData.append("\",\"command\"::\"");
        sendData.append(strCommandParameterThird.c_str());
        sendData.append("\"}:status=press</oa></iq>");
    
    commandcsocket->write(sendData.c_str(), sendData.length());
    }

  if (strCommandParameterFourth != "") 
   {
        sendData = "<iq type=\"get\" id=\"";
        sendData.append(CONNECTION_ID);
        sendData.append("\"><oa xmlns=\"connect.logitech.com\" mime=\"vnd.logitech.harmony/vnd.logitech.harmony.engine?");

    sendData.append("holdAction\">action={\"type\"::\"IRCommand\",\"deviceId\"::\"");
        sendData.append(strCommandParameterPrimary.c_str());
        sendData.append("\",\"command\"::\"");
        sendData.append(strCommandParameterFourth.c_str());
        sendData.append("\"}:status=press</oa></iq>");
    
    commandcsocket->write(sendData.c_str(), sendData.length());
    }

    memset(databuffer, 0, 1000000);
    commandcsocket->read(databuffer, 1000000, false);
    strData = databuffer; /* <- Expect: strData  == <iq/> */
    
    std::string iqTag = "<iq/>";
    std::string::size_type pos = strData.find(iqTag);

    if(pos != 0)
    {
        errorString = "submitCommand: Invalid Harmony response";
        return 1;  
    }

    bool bIsDataReadable = false;
    commandcsocket->canRead(&bIsDataReadable, 0.6f);

    if(bIsDataReadable == false && strData == "<iq/>")
    {
        bIsDataReadable = true;
    }

    if(strCommand != "issue_device_command")
    {
        while(bIsDataReadable)
        {
            memset(databuffer, 0, 1000000);
            commandcsocket->read(databuffer, 1000000, false);
            strData.append(databuffer);
            commandcsocket->canRead(&bIsDataReadable, 0.3f);
        }
    }
    
    resultString = strData;

    if(strCommand == "get_current_activity_id" || strCommand == "get_current_activity_id_raw")
    {
         std::string::size_type resultStartPos = resultString.find("result=");
        std::string::size_type resultEndPos = resultString.find("]]>");

        if(resultStartPos != std::string::npos && resultEndPos != std::string::npos)
        {
            resultString = resultString.substr(resultStartPos + 7, resultEndPos - resultStartPos - 7);
	resultString.insert(0, "{\"current activity\":");
            if(strCommand == "get_current_activity_id")
            {

            }
		resultString.append("}");	
		ofstream current("current.json");
		current << ("%s\n\n", resultString.c_str());
        }

    }
    else if(strCommand == "get_config" || strCommand == "get_config_raw")
    {
        commandcsocket->canRead(&bIsDataReadable, 0.3f);

#ifndef _WIN32
        bIsDataReadable = true;
#endif

        while(bIsDataReadable)
        {
            memset(databuffer, 0, 1000000);
            commandcsocket->read(databuffer, 1000000, false);
            strData.append(databuffer);
            commandcsocket->canRead(&bIsDataReadable, 0.3f);
        }
        
        pos = strData.find("![CDATA[{");
        if(pos != std::string::npos)
        {
            size_t endpos = strData.rfind("}]]");
            if (pos != std::string::npos)
            {
                rawConfig = strData.substr(pos + 8, endpos - pos - 7);
            }
            
            resultString = "Logitech Harmony Configuration : \n" + strData.substr(pos + 9);
        }
        if (rawConfig.empty())
        {
            errorString = "Invalid Logitech Harmony Configuration : \n" + strData;
            return 1;
        }
    }
    else if (strCommand == "start_activity" || strCommand == "start_activity_raw")
    {
		
        resultString ="{\"current activity\":" + strCommandParameterPrimary + "}";
        ofstream current("current.json");
        current << ("%s\n\n", resultString.c_str());
    }
	else if (strCommand == "issue_device_command")
	{
		resultString ="";
	}	
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x6e0, %rsp            # imm = 0x6E0
movq %r9, -0x600(%rbp)
movq %r8, -0x5f8(%rbp)
movq %rcx, -0x5f0(%rbp)
movq %rdx, -0x5e8(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x5e0(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x50c0
movq -0x18(%rbp), %rdi
callq 0x3540
cmpq $0x0, %rax
jne 0x50df
leaq 0x1d2b1(%rip), %rdi     # 0x22378
leaq 0x1165c(%rip), %rsi     # 0x1672a
callq 0x34c0
movl $0x1, -0x4(%rbp)
jmp 0x5e92
movq -0x5e8(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x31d0
leaq -0x58(%rbp), %rdi
callq 0x3540
cmpq $0x0, %rax
jne 0x5134
leaq 0x11668(%rip), %rsi     # 0x1676d
leaq -0x58(%rbp), %rdi
callq 0x34c0
jmp 0x5110
movl $0x0, -0x4(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0x5e7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x5e87
leaq -0x88(%rbp), %rdi
callq 0x34e0
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x608(%rbp)
callq 0x34e0
movq -0x608(%rbp), %rdi
leaq 0x113f4(%rip), %rsi     # 0x16555
callq 0x34c0
jmp 0x5168
leaq 0x113fa(%rip), %rsi     # 0x16569
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x517d
leaq 0x11601(%rip), %rsi     # 0x16785
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x5192
leaq 0x115d4(%rip), %rsi     # 0x1676d
leaq -0x58(%rbp), %rdi
callq 0x8cc0
movb %al, -0x609(%rbp)
jmp 0x51aa
movb -0x609(%rbp), %al
testb $0x1, %al
jne 0x51da
jmp 0x51b6
leaq 0x11623(%rip), %rsi     # 0x167e0
leaq -0x58(%rbp), %rdi
callq 0x8cc0
movb %al, -0x60a(%rbp)
jmp 0x51ce
movb -0x60a(%rbp), %al
testb $0x1, %al
jne 0x51da
jmp 0x5202
leaq 0x1161b(%rip), %rsi     # 0x167fc
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x51ef
jmp 0x5202
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x5e62
leaq 0x1160f(%rip), %rsi     # 0x16818
leaq -0x58(%rbp), %rdi
callq 0x8cc0
movb %al, -0x60b(%rbp)
jmp 0x521a
movb -0x60b(%rbp), %al
testb $0x1, %al
jne 0x5226
jmp 0x5240
leaq 0x115fa(%rip), %rsi     # 0x16827
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x523b
jmp 0x537a
leaq 0x115f3(%rip), %rsi     # 0x1683a
leaq -0x58(%rbp), %rdi
callq 0x8cc0
movb %al, -0x60c(%rbp)
jmp 0x5258
movb -0x60c(%rbp), %al
testb $0x1, %al
jne 0x528b
jmp 0x5264
movq -0x5e8(%rbp), %rdi
leaq 0x115d7(%rip), %rsi     # 0x16849
callq 0x8cc0
movb %al, -0x60d(%rbp)
jmp 0x527f
movb -0x60d(%rbp), %al
testb $0x1, %al
jne 0x528b
jmp 0x52d7
leaq 0x115ca(%rip), %rsi     # 0x1685c
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x52a0
movq -0x5f0(%rbp), %rdi
callq 0x31c0
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x52bd
leaq 0x115b3(%rip), %rsi     # 0x16877
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x52d2
jmp 0x5378
leaq 0x115b0(%rip), %rsi     # 0x1688e
leaq -0x58(%rbp), %rdi
callq 0x8cc0
movb %al, -0x60e(%rbp)
jmp 0x52ef
movb -0x60e(%rbp), %al
testb $0x1, %al
jne 0x52fb
jmp 0x5376
leaq 0x115a1(%rip), %rsi     # 0x168a3
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x5310
movq -0x5f0(%rbp), %rdi
callq 0x31c0
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x532d
leaq 0x115a5(%rip), %rsi     # 0x168d9
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x5342
movq -0x5f8(%rbp), %rdi
callq 0x31c0
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x535f
leaq 0x11582(%rip), %rsi     # 0x168e8
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x5374
jmp 0x5376
jmp 0x5378
jmp 0x537a
movq -0x10(%rbp), %rax
movq %rax, -0x620(%rbp)
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x628(%rbp)
callq 0x31c0
movq -0x628(%rbp), %rdi
movq %rax, -0x618(%rbp)
callq 0x3540
movq -0x620(%rbp), %rdi
movq -0x618(%rbp), %rsi
movl %eax, %edx
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0x53c6
movq -0x600(%rbp), %rdi
leaq 0x11e22(%rip), %rsi     # 0x171f6
callq 0x8c90
movb %al, -0x629(%rbp)
jmp 0x53e1
movb -0x629(%rbp), %al
testb $0x1, %al
jne 0x53f0
jmp 0x54f6
leaq 0x1115e(%rip), %rsi     # 0x16555
leaq -0xa8(%rbp), %rdi
callq 0x34c0
jmp 0x5405
leaq 0x1115d(%rip), %rsi     # 0x16569
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x541a
leaq 0x11364(%rip), %rsi     # 0x16785
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x542f
leaq 0x1146d(%rip), %rsi     # 0x168a3
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x5444
movq -0x5f0(%rbp), %rdi
callq 0x31c0
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x5461
leaq 0x11471(%rip), %rsi     # 0x168d9
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x5476
movq -0x600(%rbp), %rdi
callq 0x31c0
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x5493
leaq 0x1144e(%rip), %rsi     # 0x168e8
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x54a8
movq -0x10(%rbp), %rax
movq %rax, -0x640(%rbp)
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x648(%rbp)
callq 0x31c0
movq -0x648(%rbp), %rdi
movq %rax, -0x638(%rbp)
callq 0x3540
movq -0x640(%rbp), %rdi
movq -0x638(%rbp), %rsi
movl %eax, %edx
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0x54f4
jmp 0x54f6
movq -0x5e0(%rbp), %rdi
leaq 0x11cf2(%rip), %rsi     # 0x171f6
callq 0x8c90
movb %al, -0x649(%rbp)
jmp 0x5511
movb -0x649(%rbp), %al
testb $0x1, %al
jne 0x5520
jmp 0x5626
leaq 0x1102e(%rip), %rsi     # 0x16555
leaq -0xa8(%rbp), %rdi
callq 0x34c0
jmp 0x5535
leaq 0x1102d(%rip), %rsi     # 0x16569
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x554a
leaq 0x11234(%rip), %rsi     # 0x16785
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x555f
leaq 0x1133d(%rip), %rsi     # 0x168a3
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x5574
movq -0x5f0(%rbp), %rdi
callq 0x31c0
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x5591
leaq 0x11341(%rip), %rsi     # 0x168d9
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x55a6
movq -0x5e0(%rbp), %rdi
callq 0x31c0
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x55c3
leaq 0x1131e(%rip), %rsi     # 0x168e8
leaq -0xa8(%rbp), %rdi
callq 0x3630
jmp 0x55d8
movq -0x10(%rbp), %rax
movq %rax, -0x660(%rbp)
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x668(%rbp)
callq 0x31c0
movq -0x668(%rbp), %rdi
movq %rax, -0x658(%rbp)
callq 0x3540
movq -0x660(%rbp), %rdi
movq -0x658(%rbp), %rsi
movl %eax, %edx
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0x5624
jmp 0x5626
leaq 0x1cdd3(%rip), %rdi     # 0x22400
movq %rdi, -0x678(%rbp)
xorl %esi, %esi
movl %esi, -0x66c(%rbp)
movl $0xf4240, %edx          # imm = 0xF4240
callq 0x3210
movq -0x678(%rbp), %rsi
movl -0x66c(%rbp), %ecx
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
movl $0xf4240, %edx          # imm = 0xF4240
callq *%rax
jmp 0x5666
leaq 0x1cd93(%rip), %rsi     # 0x22400
leaq -0x88(%rbp), %rdi
callq 0x34c0
jmp 0x567b
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x680(%rbp)
callq 0x35f0
movq -0x680(%rbp), %rdx
leaq 0x10f7a(%rip), %rsi     # 0x16616
leaq -0xc8(%rbp), %rdi
callq 0x8b50
jmp 0x56aa
leaq -0xc9(%rbp), %rdi
callq 0x33f0
leaq -0x88(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x3680
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
je 0x5734
leaq 0x1cc93(%rip), %rdi     # 0x22378
leaq 0x11216(%rip), %rsi     # 0x16902
callq 0x34c0
jmp 0x56f3
movl $0x1, -0x4(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0x5e30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xc9(%rbp), %rdi
callq 0x33f0
jmp 0x5e62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x5e56
movb $0x0, -0xd9(%rbp)
movq -0x10(%rbp), %rdi
leaq -0xd9(%rbp), %rsi
movss 0x108ba(%rip), %xmm0    # 0x16008
callq 0x14e60
jmp 0x5755
movb -0xd9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5793
leaq 0x10eaa(%rip), %rsi     # 0x16616
leaq -0x88(%rbp), %rdi
callq 0x8cc0
movb %al, -0x681(%rbp)
jmp 0x5780
movb -0x681(%rbp), %al
testb $0x1, %al
jne 0x578c
jmp 0x5793
movb $0x1, -0xd9(%rbp)
movq -0x5e8(%rbp), %rdi
leaq 0x110ed(%rip), %rsi     # 0x1688e
callq 0x8c90
movb %al, -0x682(%rbp)
jmp 0x57ae
movb -0x682(%rbp), %al
testb $0x1, %al
jne 0x57ba
jmp 0x5838
jmp 0x57bc
testb $0x1, -0xd9(%rbp)
je 0x5836
leaq 0x1cc34(%rip), %rdi     # 0x22400
movq %rdi, -0x690(%rbp)
xorl %esi, %esi
movl %esi, -0x688(%rbp)
movl $0xf4240, %edx          # imm = 0xF4240
callq 0x3210
movq -0x690(%rbp), %rsi
movl -0x688(%rbp), %ecx
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
movl $0xf4240, %edx          # imm = 0xF4240
callq *%rax
jmp 0x5805
leaq 0x1cbf4(%rip), %rsi     # 0x22400
leaq -0x88(%rbp), %rdi
callq 0x3630
jmp 0x581a
movq -0x10(%rbp), %rdi
leaq -0xd9(%rbp), %rsi
movss 0x107d7(%rip), %xmm0    # 0x16004
callq 0x14e60
jmp 0x5834
jmp 0x57bc
jmp 0x5838
leaq 0x1cb59(%rip), %rdi     # 0x22398
leaq -0x88(%rbp), %rsi
callq 0x3050
jmp 0x584d
movq -0x5e8(%rbp), %rdi
leaq 0x10f12(%rip), %rsi     # 0x1676d
callq 0x8cc0
movb %al, -0x691(%rbp)
jmp 0x5868
movb -0x691(%rbp), %al
testb $0x1, %al
jne 0x589e
jmp 0x5874
movq -0x5e8(%rbp), %rdi
leaq 0x10f5e(%rip), %rsi     # 0x167e0
callq 0x8cc0
movb %al, -0x692(%rbp)
jmp 0x588f
movb -0x692(%rbp), %al
testb $0x1, %al
jne 0x589e
jmp 0x5a12
leaq 0x1caf3(%rip), %rdi     # 0x22398
leaq 0x1107e(%rip), %rsi     # 0x1692a
xorl %eax, %eax
movl %eax, %edx
callq 0x3670
movq %rax, -0xe8(%rbp)
leaq 0x1cad5(%rip), %rdi     # 0x22398
leaq 0x11068(%rip), %rsi     # 0x16932
xorl %eax, %eax
movl %eax, %edx
callq 0x3670
movq %rax, -0xf0(%rbp)
cmpq $-0x1, -0xe8(%rbp)
je 0x5a0d
cmpq $-0x1, -0xf0(%rbp)
je 0x5a0d
movq -0xe8(%rbp), %rax
movq %rax, %rdx
addq $0x7, %rdx
movq -0xf0(%rbp), %rcx
subq %rax, %rcx
addq $-0x7, %rcx
leaq 0x1ca7f(%rip), %rsi     # 0x22398
leaq -0x110(%rbp), %rdi
callq 0x33c0
jmp 0x5927
leaq 0x1ca6a(%rip), %rdi     # 0x22398
movq %rdi, -0x6a0(%rbp)
leaq -0x110(%rbp), %rsi
movq %rsi, -0x6a8(%rbp)
callq 0x3460
movq -0x6a8(%rbp), %rdi
callq 0x3698
movq -0x6a0(%rbp), %rdi
leaq 0x10fd4(%rip), %rdx     # 0x16936
xorl %eax, %eax
movl %eax, %esi
callq 0x3140
jmp 0x596d
movq -0x5e8(%rbp), %rdi
leaq 0x10df2(%rip), %rsi     # 0x1676d
callq 0x8cc0
movb %al, -0x6a9(%rbp)
jmp 0x5988
movb -0x6a9(%rbp), %al
testb $0x1, %al
jne 0x5994
jmp 0x5996
jmp 0x5996
leaq 0x1c9fb(%rip), %rdi     # 0x22398
leaq 0x10792(%rip), %rsi     # 0x16136
callq 0x3630
jmp 0x59ab
leaq 0x10f99(%rip), %rsi     # 0x1694b
leaq -0x310(%rbp), %rdi
movl $0x10, %edx
callq 0x3400
jmp 0x59c5
leaq 0x1c9cc(%rip), %rdi     # 0x22398
callq 0x31c0
movq %rax, %rsi
leaq -0x310(%rbp), %rdi
callq 0x3360
jmp 0x59e2
leaq -0x310(%rbp), %rdi
callq 0x3530
jmp 0x5a0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x310(%rbp), %rdi
callq 0x3530
jmp 0x5e56
jmp 0x5e22
movq -0x5e8(%rbp), %rdi
leaq 0x10f3d(%rip), %rsi     # 0x1695d
callq 0x8cc0
movb %al, -0x6aa(%rbp)
jmp 0x5a2d
movb -0x6aa(%rbp), %al
testb $0x1, %al
jne 0x5a63
jmp 0x5a39
movq -0x5e8(%rbp), %rdi
leaq 0x10dd1(%rip), %rsi     # 0x16818
callq 0x8cc0
movb %al, -0x6ab(%rbp)
jmp 0x5a54
movb -0x6ab(%rbp), %al
testb $0x1, %al
jne 0x5a63
jmp 0x5ca7
movq -0x10(%rbp), %rdi
leaq -0xd9(%rbp), %rsi
movss 0x1058e(%rip), %xmm0    # 0x16004
callq 0x14e60
jmp 0x5a7d
movb $0x1, -0xd9(%rbp)
testb $0x1, -0xd9(%rbp)
je 0x5afe
leaq 0x1c96c(%rip), %rdi     # 0x22400
movq %rdi, -0x6b8(%rbp)
xorl %esi, %esi
movl %esi, -0x6b0(%rbp)
movl $0xf4240, %edx          # imm = 0xF4240
callq 0x3210
movq -0x6b8(%rbp), %rsi
movl -0x6b0(%rbp), %ecx
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
movl $0xf4240, %edx          # imm = 0xF4240
callq *%rax
jmp 0x5acd
leaq 0x1c92c(%rip), %rsi     # 0x22400
leaq -0x88(%rbp), %rdi
callq 0x3630
jmp 0x5ae2
movq -0x10(%rbp), %rdi
leaq -0xd9(%rbp), %rsi
movss 0x1050f(%rip), %xmm0    # 0x16004
callq 0x14e60
jmp 0x5afc
jmp 0x5a84
leaq -0x88(%rbp), %rdi
leaq 0x10e5c(%rip), %rsi     # 0x16968
xorl %eax, %eax
movl %eax, %edx
callq 0x3670
movq %rax, -0xd8(%rbp)
cmpq $-0x1, -0xd8(%rbp)
je 0x5c42
leaq 0x10e41(%rip), %rsi     # 0x16972
leaq -0x88(%rbp), %rdi
movq $-0x1, %rdx
callq 0x35b0
movq %rax, -0x6c0(%rbp)
jmp 0x5b4d
movq -0x6c0(%rbp), %rax
movq %rax, -0x318(%rbp)
cmpq $-0x1, -0xd8(%rbp)
je 0x5bb5
movq -0xd8(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq -0x318(%rbp), %rcx
subq %rax, %rcx
addq $-0x7, %rcx
leaq -0x338(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x33c0
jmp 0x5b96
leaq 0x1c81b(%rip), %rdi     # 0x223b8
leaq -0x338(%rbp), %rsi
callq 0x3460
leaq -0x338(%rbp), %rdi
callq 0x3698
movq -0xd8(%rbp), %rdx
addq $0x9, %rdx
leaq -0x378(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movq $-0x1, %rcx
callq 0x33c0
jmp 0x5bdc
leaq 0x10d9b(%rip), %rsi     # 0x1697e
leaq -0x358(%rbp), %rdi
leaq -0x378(%rbp), %rdx
callq 0x8cf0
jmp 0x5bf8
leaq 0x1c799(%rip), %rdi     # 0x22398
leaq -0x358(%rbp), %rsi
callq 0x3460
leaq -0x358(%rbp), %rdi
callq 0x3698
leaq -0x378(%rbp), %rdi
callq 0x3698
jmp 0x5c42
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x3698
jmp 0x5e56
leaq 0x1c76f(%rip), %rdi     # 0x223b8
callq 0x35a0
testb $0x1, %al
jne 0x5c54
jmp 0x5ca2
leaq 0x10d1b(%rip), %rsi     # 0x16976
leaq -0x398(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x8d40
jmp 0x5c70
leaq 0x1c701(%rip), %rdi     # 0x22378
leaq -0x398(%rbp), %rsi
callq 0x3460
leaq -0x398(%rbp), %rdi
callq 0x3698
movl $0x1, -0x4(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0x5e30
jmp 0x5e20
movq -0x5e8(%rbp), %rdi
leaq 0x10b85(%rip), %rsi     # 0x1683a
callq 0x8cc0
movb %al, -0x6c1(%rbp)
jmp 0x5cc2
movb -0x6c1(%rbp), %al
testb $0x1, %al
jne 0x5cf8
jmp 0x5cce
movq -0x5e8(%rbp), %rdi
leaq 0x10b6d(%rip), %rsi     # 0x16849
callq 0x8cc0
movb %al, -0x6c2(%rbp)
jmp 0x5ce9
movb -0x6c2(%rbp), %al
testb $0x1, %al
jne 0x5cf8
jmp 0x5dde
movq -0x5f0(%rbp), %rdx
leaq 0x10c30(%rip), %rsi     # 0x16936
leaq -0x3d8(%rbp), %rdi
callq 0x8d40
jmp 0x5d14
leaq 0x1041b(%rip), %rdx     # 0x16136
leaq -0x3b8(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x8e50
jmp 0x5d30
leaq 0x1c661(%rip), %rdi     # 0x22398
leaq -0x3b8(%rbp), %rsi
movq %rsi, -0x6d0(%rbp)
callq 0x3460
movq -0x6d0(%rbp), %rdi
callq 0x3698
leaq -0x3d8(%rbp), %rdi
callq 0x3698
leaq 0x10be2(%rip), %rsi     # 0x1694b
leaq -0x5d8(%rbp), %rdi
movl $0x10, %edx
callq 0x3400
jmp 0x5d7c
leaq 0x1c615(%rip), %rdi     # 0x22398
callq 0x31c0
movq %rax, %rsi
leaq -0x5d8(%rbp), %rdi
callq 0x3360
jmp 0x5d99
leaq -0x5d8(%rbp), %rdi
callq 0x3530
jmp 0x5e1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x3d8(%rbp), %rdi
callq 0x3698
jmp 0x5e56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x5d8(%rbp), %rdi
callq 0x3530
jmp 0x5e56
movq -0x5e8(%rbp), %rdi
leaq 0x10aa2(%rip), %rsi     # 0x1688e
callq 0x8cc0
movb %al, -0x6d1(%rbp)
jmp 0x5df9
movb -0x6d1(%rbp), %al
testb $0x1, %al
jne 0x5e05
jmp 0x5e1c
leaq 0x1c58c(%rip), %rdi     # 0x22398
leaq 0x113e3(%rip), %rsi     # 0x171f6
callq 0x34c0
jmp 0x5e1a
jmp 0x5e1c
jmp 0x5e1e
jmp 0x5e20
jmp 0x5e22
movl $0x0, -0x4(%rbp)
movl $0x1, -0x68(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3698
leaq -0xa8(%rbp), %rdi
callq 0x3698
leaq -0x88(%rbp), %rdi
callq 0x3698
jmp 0x5e7c
leaq -0xc8(%rbp), %rdi
callq 0x3698
leaq -0xa8(%rbp), %rdi
callq 0x3698
leaq -0x88(%rbp), %rdi
callq 0x3698
jmp 0x5e87
leaq -0x58(%rbp), %rdi
callq 0x3698
jmp 0x5e92
leaq -0x58(%rbp), %rdi
callq 0x3698
jmp 0x5e9e
movl -0x4(%rbp), %eax
addq $0x6e0, %rsp            # imm = 0x6E0
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x35e0
nopw (%rax,%rax)