// File: /workspace/github_cpp_makefile_star2_O2/NovaGL[P]HarmonyHubControl/HarmonyHubControl.cpp
// Function: main
int main(int argc, char * argv[])
{

     ifstream myFile("HarmonyHub.AuthorizationToken");
	if (myFile.fail()) {
		ofstream auth("HarmonyHub.AuthorizationToken");
		auth << ("KsRE6VVA3xrhtbqFbh0jWn8YTiweDeB/b94Qeqf3ofWGM79zLSr62XQh8geJxw/V");
	}
	
    if (argc < 2)
    {
	      const char *suffix = "";
	#if _WIN32
        	suffix = ".exe";
	#endif
        printf("Syntax:\n");
        printf("HarmonyHubControl%s [harmony_ip] [command (optional)]\n", suffix);        
	printf("    where command can be any of the following:\n");
        printf("        list_activities\n");
        printf("        list_activities_raw\n");
        printf("        get_current_activity_id\n");
        printf("        get_current_activity_id_raw\n");
        printf("        start_activity [ID]\n");
        printf("        list_devices\n");
        printf("        list_devices_raw\n");
        printf("        list_device_commands [deviceId]\n");
        printf("        list_device_commands_raw [deviceId]\n");
        printf("        issue_device_command [deviceId] [command]\n");
        printf("        get_config\n");
        printf("        get_config_raw\n");
        printf("\n");
        return 0;
    }

    std::string strUserEmail = "guest@x.com";
    std::string strUserPassword = "guest";
    std::string strHarmonyIP = argv[1];
    std::string strCommand;
    std::string strCommandParameterPrimary;
    std::string strCommandParameterSecondary;
    std::string strCommandParameterThird;
    std::string strCommandParameterFourth;
    
    int harmonyPortNumber = HARMONY_COMMUNICATION_PORT;

    // User requested an action to be performed
    if(argc >= 3)
    {
        strCommand = argv[2];
    }
    if(argc>=4)
    {
        strCommandParameterPrimary = argv[3];
    }

    if(argc>=5)
    {
        strCommandParameterSecondary = argv[4];
    }

    if(argc>=6)
    {
        strCommandParameterThird = argv[5];
    }

    if(argc==7)
    {
        strCommandParameterFourth = argv[6];
    }

    bool bQuietMode = false;

    if(strCommand.length())
    {
        if( strCommand.find("_raw") != std::string::npos)
        {
            bQuietMode = true;
        }
    }

    // Read the token
    std::string strAuthorizationToken = ReadAuthorizationTokenFile();

    //printf("\nLogin Authorization Token is: %s\n\n", strAuthorizationToken.c_str());

    bool bAuthorizationComplete = false;

    if(strAuthorizationToken.length() > 0)
    {
        csocket authorizationcsocket;
        if(connectToHarmony(strHarmonyIP, harmonyPortNumber, authorizationcsocket) == 1)
        {
            log("HARMONY COMMUNICATION LOGIN    : FAILURE", false);
            printf("ERROR : %s\n", errorString.c_str());
            return 1;
        }

        if(swapAuthorizationToken(&authorizationcsocket, strAuthorizationToken) == 0)
        {
            // Authorization Token found in the file worked.  
            // Bypass authorization through Logitech's servers.
            log("LOGITECH WEB SERVICE LOGIN     : BYPASSED", bQuietMode);

            bAuthorizationComplete = true;
        }
        
    }

    
    if(bAuthorizationComplete == false)
    {
        // Log into the Logitech Web Service to retrieve the login authorization token
        if(harmonyWebServiceLogin(strUserEmail, strUserPassword, strAuthorizationToken) == 1)
        {
            log("LOGITECH WEB SERVICE LOGIN     : FAILURE", false);
            printf("ERROR : %s\n", errorString.c_str());
            return 1;
        }
        log("LOGITECH WEB SERVICE LOGIN     : SUCCESS", bQuietMode);

        //printf("\nLogin Authorization Token is: %s\n\n", strAuthorizationToken.c_str());

        // Write the Authorization Token to an Authorization Token file to bypass this step
        // on future sessions
        WriteAuthorizationTokenFile(strAuthorizationToken);

        // Log into the harmony hub to convert the login authorization token for a 
        // session authorization token
    
        csocket authorizationcsocket;
        if(connectToHarmony(strHarmonyIP, harmonyPortNumber, authorizationcsocket) == 1)
        {
            log("HARMONY COMMUNICATION LOGIN    : FAILURE", false);
            printf("ERROR : %s\n", errorString.c_str());
            return 1;
        }


        if(swapAuthorizationToken(&authorizationcsocket, strAuthorizationToken) == 1)
        {
            log("HARMONY COMMUNICATION LOGIN    : FAILURE", false);
            printf("ERROR : %s\n", errorString.c_str());
            return 1;
        }
    }

    log("HARMONY COMMUNICATION LOGIN    : SUCCESS", bQuietMode);


    //printf("\nSession Authorization Token is: %s\n\n", strAuthorizationToken.c_str());

    // We've successfully obtained our session authorization token from the harmony hub 
    // using the login authorization token we received earlier from the Logitech web service.
    // Now, disconnect from the harmony and reconnect using the mangled session token 
    // as our username and password to issue a command.


    csocket commandcsocket;
    if(connectToHarmony(strHarmonyIP, harmonyPortNumber, commandcsocket) == 1)
    {
        log("HARMONY COMMAND SUBMISSION     : FAILURE", false);
        printf("ERROR : %s\n", errorString.c_str());
        return 1;
    }

    std::string strUserName = strAuthorizationToken;
    //strUserName.append("@connect.logitech.com/gatorade.");
    std::string strPassword = strAuthorizationToken;
    
    if(startCommunication(&commandcsocket, strUserName, strPassword) == 1)
    {
        errorString = "Communication failure";
        return 1;
    }

    std::string lstrCommand = strCommand;

    if(strCommand == "list_activities"              || 
        strCommand == "list_activities_raw"         || 
        strCommand == "list_devices"                || 
        strCommand == "list_devices_raw"            || 
        strCommand == "list_commands"               || 
        strCommand == "list_device_commands"        || 
        strCommand == "list_device_commands_raw"    || 
        strCommand == "get_config")
    {
        lstrCommand = "get_config_raw";
    }

    if(submitCommand(&commandcsocket, strAuthorizationToken, lstrCommand, strCommandParameterPrimary, strCommandParameterSecondary, strCommandParameterThird, strCommandParameterFourth) == 1)
    {
        log("HARMONY COMMAND SUBMISSION     : FAILURE", false);
        printf("ERROR : %s\n", errorString.c_str());
        return 1;
    }

    log("HARMONY COMMAND SUBMISSION     : SUCCESS", bQuietMode);
    
    if(lstrCommand == "get_config_raw")
    {
        std::map< std::string, std::string> mapActivities;
        std::vector< Device > vecDevices;
        if(parseConfiguration(rawConfig, mapActivities, vecDevices) == 1)
        {
            log("PARSE ACTIVITIES AND DEVICES   : FAILURE", false);
            printf("ERROR : %s\n", errorString.c_str());		
            return 1;
        }

        if(strCommand == "list_activities" || strCommand == "list_activities_raw" )
        {
            resultString = "{";

            if(strCommand == "list_activities")
            {
                resultString = "Activities Available via Harmony : \n\n";
            }
        
            std::map< std::string, std::string>::iterator it = mapActivities.begin();
            std::map< std::string, std::string>::iterator ite = mapActivities.end();
            for(; it != ite; ++it)
            {
                resultString.append("\"");
                resultString.append(it->second);
                resultString.append("\":\"");
                resultString.append(it->first);
                resultString.append("\",");
            }
            resultString = resultString.substr(0, resultString.size() - 1);
            resultString.append("}");
            ofstream activities("activities.json");
            activities << ("%s\n\n", resultString.c_str());
        }

        if( strCommand == "list_devices" || strCommand == "list_devices_raw" )
        {
            
	        resultString ="{";
            if( strCommand == "list_devices" )
            {
                resultString = "Devices Controllable via Harmony : \n\n";
            }

            std::vector< Device >::iterator it = vecDevices.begin();
            std::vector< Device >::iterator ite = vecDevices.end();
            for(; it != ite; ++it)
            {
                resultString.append("\"");
		        resultString.append(it->m_strLabel );
                resultString.append("\":\"");
                resultString.append(it->m_strID );
		        resultString.append("\",");
            }
            resultString=resultString.substr(0, resultString.size()-1);
	        resultString.append("}");
		    ofstream devices("devices.json");
		    devices << ("%s\n\n", resultString.c_str());
        }

        if(strCommand == "list_commands" || strCommand == "list_commands_raw" )
        {
            resultString = "";
            
            if(strCommand == "list_commands")
            {
                resultString = "Devices Controllable via Harmony with Commands : \n\n";
            }
            std::vector< Device >::iterator it = vecDevices.begin();
            std::vector< Device >::iterator ite = vecDevices.end();
            for(; it != ite; ++it)
            {  
                resultString.append(it->toString());
                resultString.append("\n\n\n");
            }
        }

        if(strCommand == "list_device_commands" || strCommand == "list_device_commands_raw")
        {
            resultString = "{";
            
            if(strCommand == "list_device_commands")
            {
                resultString = "Harmony Commands for Device: \n\n";
            }
            
            std::vector< Device >::iterator it = vecDevices.begin();
            std::vector< Device >::iterator ite = vecDevices.end();
            for(; it != ite; ++it)
            {
                if(it->m_strID == strCommandParameterPrimary)
                {
                    if(strCommandParameterSecondary.length())
                    {
                        if(strCommandParameterSecondary == it->m_strID)
                        {
                            resultString.append("\"");    
			    resultString.append(it->toString());                         
                        }
                    }
                    else
                    {
     			  resultString.append("\"");                                 
			  resultString.append(it->toString()); 
                    }
                          resultString=resultString.substr(0, resultString.size()-1);
                          resultString.append("}" );
                    break;
                }
            }
			string filename;	
			filename = strCommandParameterPrimary;
			filename.append(".json"); 
			ofstream myfile( filename.c_str() );
			myfile << ("%s\n\n", resultString.c_str());
        }
        log("PARSE ACTIVITIES AND DEVICES   : SUCCESS", bQuietMode);
		ofstream config("config.json");
		config << rawConfig;
    }
	

    printf("%s\n\n", resultString.c_str());
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x7d8, %rsp            # imm = 0x7D8
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x6297(%rip), %rsi      # 0xb989
leaq 0x5d0(%rsp), %r14
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x34a0
movq (%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x5f0(%rsp,%rax)
je 0x574e
leaq 0x626c(%rip), %rsi      # 0xb989
leaq 0x358(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x32f0
leaq 0x6273(%rip), %rsi      # 0xb9a7
leaq 0x358(%rsp), %rdi
callq 0x3270
leaq 0x358(%rsp), %rdi
callq 0x33e0
cmpl $0x1, %ebp
jg 0x5823
leaq 0x88b5(%rip), %rdi      # 0xe013
callq 0x3400
leaq 0x627e(%rip), %rdi      # 0xb9e8
leaq 0x6806(%rip), %rsi      # 0xbf77
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x3040
leaq 0x889a(%rip), %rdi      # 0xe01b
callq 0x3400
leaq 0x88bd(%rip), %rdi      # 0xe04a
callq 0x3400
leaq 0x88c9(%rip), %rdi      # 0xe062
callq 0x3400
leaq 0x88d9(%rip), %rdi      # 0xe07e
callq 0x3400
leaq 0x88ed(%rip), %rdi      # 0xe09e
callq 0x3400
leaq 0x8905(%rip), %rdi      # 0xe0c2
callq 0x3400
leaq 0x8915(%rip), %rdi      # 0xe0de
callq 0x3400
leaq 0x891e(%rip), %rdi      # 0xe0f3
callq 0x3400
leaq 0x892b(%rip), %rdi      # 0xe10c
callq 0x3400
leaq 0x8947(%rip), %rdi      # 0xe134
callq 0x3400
leaq 0x8967(%rip), %rdi      # 0xe160
callq 0x3400
leaq 0x898d(%rip), %rdi      # 0xe192
callq 0x3400
leaq 0x8994(%rip), %rdi      # 0xe1a5
callq 0x3400
pushq $0xa
popq %rdi
callq 0x3390
jmp 0x65f9
leaq 0x61f5(%rip), %rsi      # 0xba1f
leaq 0x338(%rsp), %rdi
leaq 0x358(%rsp), %rdx
callq 0x68b8
leaq 0x5c98(%rip), %rsi      # 0xb4de
leaq 0x318(%rsp), %rdi
leaq 0x358(%rsp), %rdx
callq 0x68b8
movq 0x8(%rbx), %rsi
leaq 0xe8(%rsp), %rdi
leaq 0x358(%rsp), %rdx
callq 0x68b8
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq 0x98(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
leaq 0x78(%rsp), %rsi
movq %rsi, -0x10(%rsi)
andq $0x0, -0x8(%rsi)
movb %cl, (%rax)
movb %cl, (%rdx)
leaq 0x138(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0x118(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rsi)
movb %cl, (%rax)
movb %cl, (%rdx)
cmpl $0x2, %ebp
je 0x5937
movq 0x10(%rbx), %rsi
leaq 0x8(%rsp), %rdi
callq 0x34c0
cmpl $0x4, %ebp
jb 0x5937
movq 0x18(%rbx), %rsi
leaq 0x88(%rsp), %rdi
callq 0x34c0
cmpl $0x4, %ebp
je 0x5937
movq 0x20(%rbx), %rsi
leaq 0x68(%rsp), %rdi
callq 0x34c0
cmpl $0x6, %ebp
jb 0x5937
movq 0x28(%rbx), %rsi
leaq 0x128(%rsp), %rdi
callq 0x34c0
cmpl $0x7, %ebp
jne 0x5937
movq 0x30(%rbx), %rsi
leaq 0x108(%rsp), %rdi
callq 0x34c0
cmpq $0x0, 0x10(%rsp)
je 0x595c
leaq 0x8777(%rip), %rsi      # 0xe0bd
leaq 0x8(%rsp), %rdi
xorl %edx, %edx
callq 0x34f0
cmpq $-0x1, %rax
setne %r13b
jmp 0x595f
xorl %r13d, %r13d
leaq 0x48(%rsp), %rdi
callq 0x55cb
cmpq $0x0, 0x50(%rsp)
je 0x59e9
leaq 0x358(%rsp), %rdi
callq 0xa1e8
leaq 0x2f8(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x3380
leaq 0x2f8(%rsp), %rdi
leaq 0x358(%rsp), %rdx
movl $0x1466, %esi           # imm = 0x1466
callq 0x3e0d
movl %eax, %ebp
leaq 0x2f8(%rsp), %rdi
callq 0x3518
testl %ebp, %ebp
je 0x59ed
pushq $0x1
popq %rbx
leaq 0x6061(%rip), %rdi      # 0xba2b
callq 0x3400
movq 0xd8e2(%rip), %rsi      # 0x132b8
leaq 0x6077(%rip), %rdi      # 0xba54
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3040
jmp 0x5a1d
xorl %ebx, %ebx
jmp 0x5a3b
leaq 0x358(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x40e6
testl %eax, %eax
sete %r14b
xorl %ebx, %ebx
movl %r13d, %ecx
orb %al, %cl
jne 0x5a1d
leaq 0x604b(%rip), %rdi      # 0xba60
callq 0x3400
movb $0x1, %r14b
leaq 0x358(%rsp), %rdi
callq 0xa210
testl %ebp, %ebp
jne 0x658d
testb %r14b, %r14b
jne 0x5b88
leaq 0x2d8(%rsp), %rdi
leaq 0x338(%rsp), %rsi
callq 0x3380
leaq 0x2b8(%rsp), %rdi
leaq 0x318(%rsp), %rsi
callq 0x3380
leaq 0x2d8(%rsp), %rdi
leaq 0x2b8(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x3a56
movl %eax, %ebp
leaq 0x2b8(%rsp), %rdi
callq 0x3518
leaq 0x2d8(%rsp), %rdi
callq 0x3518
testl %ebp, %ebp
je 0x5ac8
leaq 0x5fe4(%rip), %rdi      # 0xba8a
callq 0x3400
movq 0xd806(%rip), %rsi      # 0x132b8
leaq 0x5f9b(%rip), %rdi      # 0xba54
xorl %eax, %eax
callq 0x3040
pushq $0x1
popq %rbx
jmp 0x658d
testb %r13b, %r13b
jne 0x5ad9
leaq 0x5fdf(%rip), %rdi      # 0xbab3
callq 0x3400
leaq 0x48(%rsp), %rdi
callq 0x5651
leaq 0x358(%rsp), %rdi
callq 0xa1e8
leaq 0x298(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x3380
leaq 0x298(%rsp), %rdi
leaq 0x358(%rsp), %rdx
movl $0x1466, %esi           # imm = 0x1466
callq 0x3e0d
movl %eax, %ebp
leaq 0x298(%rsp), %rdi
callq 0x3518
testl %ebp, %ebp
jne 0x5b4c
leaq 0x358(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x40e6
testl %eax, %eax
je 0x5e91
leaq 0x5ed8(%rip), %rdi      # 0xba2b
callq 0x3400
movq 0xd759(%rip), %rsi      # 0x132b8
leaq 0x5eee(%rip), %rdi      # 0xba54
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x3040
pushq $0x1
popq %rbx
leaq 0x358(%rsp), %rdi
callq 0xa210
testb %bpl, %bpl
je 0x658d
testb %r13b, %r13b
jne 0x5b99
leaq 0x5f48(%rip), %rdi      # 0xbadc
callq 0x3400
leaq 0x578(%rsp), %rdi
callq 0xa1e8
leaq 0x278(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x3380
leaq 0x278(%rsp), %rdi
leaq 0x578(%rsp), %rdx
movl $0x1466, %esi           # imm = 0x1466
callq 0x3e0d
movl %eax, %ebp
leaq 0x278(%rsp), %rdi
callq 0x3518
testl %ebp, %ebp
je 0x5c11
leaq 0x5f16(%rip), %rdi      # 0xbb05
callq 0x3400
movq 0xd6bd(%rip), %rsi      # 0x132b8
leaq 0x5e52(%rip), %rdi      # 0xba54
xorl %eax, %eax
callq 0x3040
pushq $0x1
popq %rbx
jmp 0x6580
leaq 0x258(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x3380
leaq 0x238(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x3380
leaq 0x218(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x3380
leaq 0x1f8(%rsp), %rdi
leaq 0x238(%rsp), %rsi
callq 0x3380
leaq 0x578(%rsp), %rdi
leaq 0x218(%rsp), %rsi
leaq 0x1f8(%rsp), %rdx
callq 0x3e61
movl %eax, %ebp
leaq 0x1f8(%rsp), %rdi
callq 0x3518
leaq 0x218(%rsp), %rdi
callq 0x3518
testl %ebp, %ebp
je 0x5cb7
leaq 0xd615(%rip), %rdi      # 0x132b8
leaq 0x585d(%rip), %rsi      # 0xb507
callq 0x34c0
pushq $0x1
popq %rbx
jmp 0x6566
leaq 0xc8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3380
leaq 0x8382(%rip), %rsi      # 0xe052
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x5d75
leaq 0x8381(%rip), %rsi      # 0xe06a
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x5d75
leaq 0x83e8(%rip), %rsi      # 0xe0e6
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x5d75
leaq 0x83e8(%rip), %rsi      # 0xe0fb
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x5d75
leaq 0x5e06(%rip), %rsi      # 0xbb2e
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x5d75
leaq 0x5dff(%rip), %rsi      # 0xbb3c
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x5d75
leaq 0x5dff(%rip), %rsi      # 0xbb51
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x5d75
leaq 0x8433(%rip), %rsi      # 0xe19a
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
je 0x5d89
leaq 0x8431(%rip), %rsi      # 0xe1ad
leaq 0xc8(%rsp), %rdi
callq 0x34c0
leaq 0x1d8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x3380
leaq 0x1b8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3380
leaq 0x198(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3380
leaq 0x178(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x3380
leaq 0x558(%rsp), %r14
leaq 0x108(%rsp), %rsi
movq %r14, %rdi
callq 0x3380
movq %r14, (%rsp)
leaq 0x578(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x1d8(%rsp), %rdx
leaq 0x1b8(%rsp), %rcx
leaq 0x198(%rsp), %r8
leaq 0x178(%rsp), %r9
callq 0x4485
movl %eax, %ebp
leaq 0x558(%rsp), %rdi
callq 0x3518
leaq 0x178(%rsp), %rdi
callq 0x3518
leaq 0x198(%rsp), %rdi
callq 0x3518
leaq 0x1b8(%rsp), %rdi
callq 0x3518
leaq 0x1d8(%rsp), %rdi
callq 0x3518
testl %ebp, %ebp
je 0x5e99
leaq 0x5c8f(%rip), %rdi      # 0xbb05
callq 0x3400
pushq $0x1
popq %rbp
leaq 0x5bcf(%rip), %rdi      # 0xba54
leaq 0xd42c(%rip), %rcx      # 0x132b8
jmp 0x654d
movb $0x1, %bpl
jmp 0x5b72
testb %r13b, %r13b
jne 0x5eaa
leaq 0x5cc5(%rip), %rdi      # 0xbb6a
callq 0x3400
leaq 0x82fc(%rip), %rsi      # 0xe1ad
leaq 0xc8(%rsp), %rdi
callq 0x68fd
leaq 0x5a18(%rip), %rdi      # 0xb8dd
leaq 0xd40c(%rip), %rcx      # 0x132d8
testb %al, %al
je 0x5f47
leaq 0x150(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0xd3f4(%rip), %rdi      # 0x132f8
leaq 0x148(%rsp), %rsi
callq 0x5142
movl %eax, 0x2c(%rsp)
cmpl $0x1, 0x2c(%rsp)
jne 0x5f4e
leaq 0x5c70(%rip), %rdi      # 0xbb93
callq 0x3400
movq 0xd389(%rip), %rsi      # 0x132b8
leaq 0x5b1e(%rip), %rdi      # 0xba54
xorl %eax, %eax
callq 0x3040
pushq $0x1
popq %rbx
xorl %ebp, %ebp
jmp 0x6521
xorl %ebp, %ebp
jmp 0x654d
leaq 0x80fd(%rip), %rsi      # 0xe052
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x5f7c
leaq 0x8100(%rip), %rsi      # 0xe06a
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
je 0x60b4
leaq 0xd355(%rip), %rdi      # 0x132d8
leaq 0x5960(%rip), %rsi      # 0xb8ea
callq 0x34c0
leaq 0x80bc(%rip), %rsi      # 0xe052
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
je 0x5fb7
leaq 0xd32d(%rip), %rdi      # 0x132d8
leaq 0x5c0a(%rip), %rsi      # 0xbbbc
callq 0x34c0
movq 0x160(%rsp), %rbp
leaq 0xd312(%rip), %r15      # 0x132d8
leaq 0x512c(%rip), %r12      # 0xb0f9
leaq 0x5c0e(%rip), %r14      # 0xbbe2
leaq 0x150(%rsp), %rax
cmpq %rax, %rbp
je 0x602b
movq %r15, %rdi
leaq 0x5f6e(%rip), %rsi      # 0xbf59
callq 0x34b0
leaq 0x40(%rbp), %rsi
movq %r15, %rdi
callq 0x34d0
movq %r15, %rdi
movq %r12, %rsi
callq 0x34b0
leaq 0x20(%rbp), %rsi
movq %r15, %rdi
callq 0x34d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x34b0
movq %rbp, %rdi
callq 0x31e0
movq %rax, %rbp
jmp 0x5fd4
leaq 0xd2a6(%rip), %rsi      # 0x132d8
movq 0xd2a7(%rip), %rcx      # 0x132e0
decq %rcx
leaq 0x358(%rsp), %rdi
xorl %edx, %edx
callq 0x32d0
leaq 0xd286(%rip), %r14      # 0x132d8
leaq 0x358(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3320
movq %r15, %rdi
callq 0x3518
leaq 0x508a(%rip), %rsi      # 0xb0fe
movq %r14, %rdi
callq 0x34b0
leaq 0x5b62(%rip), %rsi      # 0xbbe5
leaq 0x358(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x32f0
movq 0xd23e(%rip), %rsi      # 0x132d8
leaq 0x358(%rsp), %rdi
callq 0x3270
leaq 0x358(%rsp), %rdi
callq 0x33e0
leaq 0x802b(%rip), %rsi      # 0xe0e6
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x60e2
leaq 0x802b(%rip), %rsi      # 0xe0fb
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
je 0x6213
leaq 0xd1ef(%rip), %rdi      # 0x132d8
leaq 0x57fa(%rip), %rsi      # 0xb8ea
callq 0x34c0
leaq 0x7fea(%rip), %rsi      # 0xe0e6
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
je 0x611d
leaq 0xd1c7(%rip), %rdi      # 0x132d8
leaq 0x5add(%rip), %rsi      # 0xbbf5
callq 0x34c0
movq 0x30(%rsp), %r15
movq 0x38(%rsp), %r14
leaq 0xd1aa(%rip), %r12      # 0x132d8
leaq 0x5aad(%rip), %rbp      # 0xbbe2
cmpq %r14, %r15
je 0x618a
movq %r12, %rdi
leaq 0x5e15(%rip), %rsi      # 0xbf59
callq 0x34b0
addq $0x20, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x34d0
movq %r12, %rdi
leaq 0x4f97(%rip), %rsi      # 0xb0f9
callq 0x34b0
addq $-0x20, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x34d0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x34b0
addq $0xb8, %r15
jmp 0x6135
leaq 0xd147(%rip), %rsi      # 0x132d8
movq 0xd148(%rip), %rcx      # 0x132e0
decq %rcx
leaq 0x358(%rsp), %rdi
xorl %edx, %edx
callq 0x32d0
leaq 0xd127(%rip), %r14      # 0x132d8
leaq 0x358(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3320
movq %r15, %rdi
callq 0x3518
leaq 0x4f2b(%rip), %rsi      # 0xb0fe
movq %r14, %rdi
callq 0x34b0
leaq 0x5a39(%rip), %rsi      # 0xbc1b
leaq 0x358(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x32f0
movq 0xd0df(%rip), %rsi      # 0x132d8
leaq 0x358(%rsp), %rdi
callq 0x3270
leaq 0x358(%rsp), %rdi
callq 0x33e0
leaq 0x5914(%rip), %rsi      # 0xbb2e
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x6241
leaq 0x59f9(%rip), %rsi      # 0xbc28
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
je 0x62d0
leaq 0xd090(%rip), %rdi      # 0x132d8
leaq 0x5d28(%rip), %rsi      # 0xbf77
callq 0x34c0
leaq 0x58d3(%rip), %rsi      # 0xbb2e
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
je 0x627c
leaq 0xd068(%rip), %rdi      # 0x132d8
leaq 0x59c3(%rip), %rsi      # 0xbc3a
callq 0x34c0
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rbp
leaq 0x358(%rsp), %r15
leaq 0xd043(%rip), %r12      # 0x132d8
cmpq %rbp, %r14
je 0x62d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6d36
movq %r12, %rdi
movq %r15, %rsi
callq 0x34d0
movq %r15, %rdi
callq 0x3518
movq %r12, %rdi
leaq 0x59ac(%rip), %rsi      # 0xbc6e
callq 0x34b0
addq $0xb8, %r14
jmp 0x6295
leaq 0x5865(%rip), %rsi      # 0xbb3c
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
jne 0x62fe
leaq 0x5865(%rip), %rsi      # 0xbb51
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
je 0x64d6
leaq 0xcfd3(%rip), %rdi      # 0x132d8
leaq 0x55de(%rip), %rsi      # 0xb8ea
callq 0x34c0
leaq 0x5824(%rip), %rsi      # 0xbb3c
leaq 0x8(%rsp), %rdi
callq 0x68fd
testb %al, %al
je 0x6339
leaq 0xcfab(%rip), %rdi      # 0x132d8
leaq 0x593e(%rip), %rsi      # 0xbc72
callq 0x34c0
movq 0x30(%rsp), %r15
movq 0x38(%rsp), %r12
leaq 0x88(%rsp), %r14
cmpq %r12, %r15
je 0x6453
movq %r15, %rdi
movq %r14, %rsi
callq 0x6e9c
testb %al, %al
jne 0x636c
addq $0xb8, %r15
jmp 0x634b
cmpq $0x0, 0x70(%rsp)
je 0x63be
leaq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x6e9c
testb %al, %al
je 0x6402
leaq 0xcf4c(%rip), %rdi      # 0x132d8
leaq 0x5bc6(%rip), %rsi      # 0xbf59
callq 0x34b0
leaq 0x358(%rsp), %rdi
movq %r15, %rsi
callq 0x6d36
leaq 0xcf29(%rip), %rdi      # 0x132d8
leaq 0x358(%rsp), %rsi
callq 0x34d0
jmp 0x63f5
leaq 0xcf13(%rip), %rdi      # 0x132d8
leaq 0x5b8d(%rip), %rsi      # 0xbf59
callq 0x34b0
leaq 0x358(%rsp), %rdi
movq %r15, %rsi
callq 0x6d36
leaq 0xcef0(%rip), %rdi      # 0x132d8
leaq 0x358(%rsp), %rsi
callq 0x34d0
leaq 0x358(%rsp), %rdi
callq 0x3518
leaq 0xcecf(%rip), %rsi      # 0x132d8
movq 0xced0(%rip), %rcx      # 0x132e0
decq %rcx
leaq 0x358(%rsp), %rdi
xorl %edx, %edx
callq 0x32d0
leaq 0xceaf(%rip), %r14      # 0x132d8
leaq 0x358(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3320
movq %r15, %rdi
callq 0x3518
leaq 0x4cb3(%rip), %rsi      # 0xb0fe
movq %r14, %rdi
callq 0x34b0
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x31a0
leaq 0x583e(%rip), %rsi      # 0xbcc1
leaq 0xa8(%rsp), %rdi
callq 0x34b0
movq 0xa8(%rsp), %rsi
leaq 0x358(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x32f0
movq 0xce29(%rip), %rsi      # 0x132d8
leaq 0x358(%rsp), %rdi
callq 0x3270
leaq 0x358(%rsp), %rdi
callq 0x33e0
leaq 0xa8(%rsp), %rdi
callq 0x3518
testb %r13b, %r13b
jne 0x64e7
leaq 0x57b0(%rip), %rdi      # 0xbc92
callq 0x3400
leaq 0x57cd(%rip), %rsi      # 0xbcbb
leaq 0x358(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x32f0
xorl %ebp, %ebp
leaq 0xcdf1(%rip), %rsi      # 0x132f8
leaq 0x358(%rsp), %rdi
callq 0x3250
leaq 0x358(%rsp), %rdi
callq 0x33e0
leaq 0x30(%rsp), %rdi
callq 0x6ec6
leaq 0x148(%rsp), %rdi
callq 0x711c
cmpl $0x1, 0x2c(%rsp)
leaq 0x5399(%rip), %rdi      # 0xb8dd
leaq 0xcd8d(%rip), %rcx      # 0x132d8
je 0x6559
movq (%rcx), %rsi
xorl %eax, %eax
callq 0x3040
movl %ebp, %ebx
leaq 0xc8(%rsp), %rdi
callq 0x3518
leaq 0x238(%rsp), %rdi
callq 0x3518
leaq 0x258(%rsp), %rdi
callq 0x3518
leaq 0x578(%rsp), %rdi
callq 0xa210
leaq 0x48(%rsp), %rdi
callq 0x3518
leaq 0x108(%rsp), %rdi
callq 0x3518
leaq 0x128(%rsp), %rdi
callq 0x3518
leaq 0x68(%rsp), %rdi
callq 0x3518
leaq 0x88(%rsp), %rdi
callq 0x3518
leaq 0x8(%rsp), %rdi
callq 0x3518
leaq 0xe8(%rsp), %rdi
callq 0x3518
leaq 0x318(%rsp), %rdi
callq 0x3518
leaq 0x338(%rsp), %rdi
callq 0x3518
leaq 0x5d0(%rsp), %rdi
callq 0x3110
movl %ebx, %eax
addq $0x7d8, %rsp            # imm = 0x7D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6703
jmp 0x6775
jmp 0x6703
jmp 0x6775
jmp 0x6775
jmp 0x6775
movq %rax, %rbx
leaq 0x358(%rsp), %rdi
callq 0x33e0
jmp 0x668b
jmp 0x6688
jmp 0x666e
jmp 0x6775
jmp 0x6775
jmp 0x6775
jmp 0x666e
jmp 0x6775
jmp 0x6775
jmp 0x6775
movq %rax, %rbx
leaq 0x358(%rsp), %rdi
callq 0x33e0
jmp 0x6778
jmp 0x6775
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x670e
jmp 0x6775
movq %rax, %rbx
leaq 0x558(%rsp), %rdi
callq 0x3518
jmp 0x66af
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x3518
jmp 0x66c1
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x3518
jmp 0x66d3
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x3518
jmp 0x66e5
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
callq 0x3518
jmp 0x678f
jmp 0x673d
movq %rax, %rbx
jmp 0x678f
jmp 0x6775
movq %rax, %rbx
leaq 0x358(%rsp), %rdi
callq 0x3518
jmp 0x6778
jmp 0x6775
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x3518
jmp 0x672c
movq %rax, %rbx
leaq 0x218(%rsp), %rdi
jmp 0x6797
movq %rax, %rbx
jmp 0x67a9
jmp 0x6764
movq %rax, %rbx
jmp 0x679c
movq %rax, %rbx
leaq 0x298(%rsp), %rdi
jmp 0x67ef
jmp 0x67f8
movq %rax, %rbx
leaq 0x278(%rsp), %rdi
jmp 0x67b1
movq %rax, %rbx
jmp 0x67b6
jmp 0x67f8
jmp 0x67fd
jmp 0x6775
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x6ec6
leaq 0x148(%rsp), %rdi
callq 0x711c
leaq 0xc8(%rsp), %rdi
callq 0x3518
leaq 0x238(%rsp), %rdi
callq 0x3518
leaq 0x258(%rsp), %rdi
callq 0x3518
leaq 0x578(%rsp), %rdi
jmp 0x6808
movq %rax, %rbx
leaq 0x2b8(%rsp), %rdi
callq 0x3518
jmp 0x67d5
movq %rax, %rbx
leaq 0x2d8(%rsp), %rdi
callq 0x3518
jmp 0x680d
movq %rax, %rbx
leaq 0x2f8(%rsp), %rdi
callq 0x3518
jmp 0x6800
jmp 0x67f8
movq %rax, %rbx
jmp 0x680d
movq %rax, %rbx
leaq 0x358(%rsp), %rdi
callq 0xa210
leaq 0x48(%rsp), %rdi
callq 0x3518
jmp 0x681e
jmp 0x681b
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3518
leaq 0x128(%rsp), %rdi
callq 0x3518
leaq 0x68(%rsp), %rdi
callq 0x3518
leaq 0x88(%rsp), %rdi
callq 0x3518
leaq 0x8(%rsp), %rdi
callq 0x3518
leaq 0xe8(%rsp), %rdi
callq 0x3518
leaq 0x318(%rsp), %rdi
callq 0x3518
leaq 0x338(%rsp), %rdi
callq 0x3518
leaq 0x5d0(%rsp), %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x3470
movq %rax, %rbx
jmp 0x6866
movq %rax, %rbx
jmp 0x6873
jmp 0x68b3
movq %rax, %rbx
leaq 0x358(%rsp), %rdi
callq 0x33e0
jmp 0x6880
movq %rax, %rbx
jmp 0x6880