// File: luigix25[P]SSLP/server_files/server.cpp
// Function: initial_protocol(NetSocket&)
bool initial_protocol(NetSocket &client_socket){

	int cert_size;

	if(!client_socket.recvInt(cert_size)) 		return false;

	if(cert_size < 0 || cert_size > MAX_CERT_LENGTH)
		return false;

	char *client_cert_data = client_socket.recvData(cert_size);
	if(client_cert_data == NULL)
		return false;

	char *old_ptr = client_cert_data;

	X509 *client_cert = d2i_X509(NULL,(const unsigned char **)&client_cert_data,cert_size);
	delete[] old_ptr;

	if(!client_cert)
		return false;

	CertificateManager cm(CERT_CA_PATH,CERT_CA_CRL_PATH);
	if(!cm.verifyCertificate(client_cert)){
		X509_free(client_cert);
		return false;
	}

	string name;

	if(!cm.extractCommonName(client_cert,name)){
		X509_free(client_cert);
		return false;
	}


	public_key_rsa.setKey(cm.extractPubKey(client_cert));

	if(!isClientAuthorized(name,CLIENTS_LIST)){
		cout<<"Client not authorized"<<endl;
		X509_free(client_cert);
		return false;
	}

	cout<<"Connection established with: "<<name<<endl;

	X509_free(client_cert);

	//read my certificate from file
	FILE* cacert_file = fopen(CERT_SERVER_PATH, "r");
	if(!cacert_file){ cerr << "Error: cannot open file '" << CERT_SERVER_PATH << "' (missing?)\n"; exit(1); }
	X509* server_cert = PEM_read_X509(cacert_file, NULL, NULL, NULL);
	fclose(cacert_file);
	if(!server_cert){ cerr << "Error: PEM_read_X509 returned NULL\n"; exit(1); }

	//serialize it

	unsigned char* cert_buf= NULL; 
	cert_size = i2d_X509(server_cert, &cert_buf); 
	if(cert_size< 0) { /* handle error */ } 
	
	//send through the socket

	if(!client_socket.sendInt(cert_size)){
		delete[] cert_buf;
		return false;					
	}

	if(!client_socket.sendData((const char*)cert_buf,cert_size)){
		delete[] cert_buf;
		return false;
	}

	OPENSSL_free(cert_buf);
	X509_free(server_cert);

	RSAVerifyManager verify(public_key_rsa);

	DHManager dh(DH_PARAMS_PATH);
	int len;
	char *pub_key = dh.generatePublicKey(len);
	if(pub_key == NULL){
		exit(-1);
	}

	if(!verify.RSAUpdate((const char*)&len,sizeof(int32_t)))		return false; //check

	if(!client_socket.sendInt(len)){
		delete[] pub_key;
		return false;
	}

	if(!verify.RSAUpdate(pub_key,len))		return false; //check

	if(!client_socket.sendData(pub_key,len)){
		delete[] pub_key; 	
		return false;
	}

	delete[] pub_key;
		
	char *opponent_pub_key;
	int opponent_pub_key_len;


	if(!client_socket.recvInt(opponent_pub_key_len))	return false;			//add check to int received
	if(!verify.RSAUpdate((const char*)&opponent_pub_key_len,sizeof(int32_t)))		return false; //check

	opponent_pub_key = client_socket.recvData(opponent_pub_key_len);
	if(!verify.RSAUpdate(opponent_pub_key,opponent_pub_key_len))		return false; //check


	if(opponent_pub_key == NULL)
		return false;


	int key_length;

	char *simmetric_key = dh.computeSimmetricKey(opponent_pub_key,opponent_pub_key_len,key_length);
	delete[] opponent_pub_key;

	if(simmetric_key == NULL){
		return false;
	}

  	HashManager keys;
  	if(!keys.HashUpdate(simmetric_key,key_length)){
  		memset_s(simmetric_key,0,key_length);
  		delete[] simmetric_key;
  		return false;
  	}

	char* digest_keys = keys.HashFinal();

	memset_s(simmetric_key,0,key_length);
	delete[] simmetric_key;

	if(digest_keys == NULL)								return false;


	char AES_symmetric_key[AES_KEY_SIZE];
	memcpy(AES_symmetric_key,digest_keys,AES_KEY_SIZE);

	char HMAC_key[HMAC_KEY_SIZE];
	memcpy(HMAC_key,&digest_keys[HMAC_KEY_SIZE],HMAC_KEY_SIZE);


	memset_s(digest_keys,0,HASH_SIZE);

	delete[] digest_keys;

	char IV[AES_BLOCK];

	RAND_poll();
	RAND_bytes((unsigned char*)&IV,AES_BLOCK);

	uint32_t local_nonce = 0;
	RAND_bytes((unsigned char*)&local_nonce,sizeof(uint32_t));


	KeyManager::setAESKey(AES_symmetric_key);
	KeyManager::setAESIV(IV);

	KeyManager::setHMACKey(HMAC_key);

	if(!verify.RSAUpdate(IV,AES_BLOCK))		return false; //check

	if(!client_socket.sendData(IV,AES_BLOCK))	return false;

	Chunk c;
 	c.setInt(local_nonce);
	c.size = sizeof(uint32_t);


	EncryptedChunk ec;

	EncryptManager em;
	if(!em.EncryptUpdate(ec,c)){
		return false;
	}

	if(!em.EncryptFinal(ec)){ 
		return false;
	}

	if(!verify.RSAUpdate((const char*)&ec.size,sizeof(int32_t)))		return false; //check

	if(!client_socket.sendInt(ec.size)){
		return false;
	} 

	if(!verify.RSAUpdate((const char*)&local_nonce,sizeof(int32_t)))		return false; //check


	if(!client_socket.sendData(ec.getCipherText(),ec.size)){
		return false;
	}


	int nonce_cipher_size;

	if(!client_socket.recvInt(nonce_cipher_size)) return false;
	if(!verify.RSAUpdate((const char*)&nonce_cipher_size,sizeof(int32_t)))		return false; //check

	char *recv_data = client_socket.recvData(nonce_cipher_size);
	if(recv_data == NULL)	return false;

	ec.setCipherText(recv_data);
	ec.size = nonce_cipher_size;

	DecryptManager dm;
	if(!dm.DecryptUpdate(c,ec)){			
		return false;
	}

	if(!dm.DecryptFinal(c)){				
		return false;
	}

	int remote_nonce = c.getInt();
	if(!verify.RSAUpdate((const char*)&remote_nonce,sizeof(int32_t)))		return false; //check

	HMACManager::setRemoteNonce(remote_nonce);
	HMACManager::setLocalNonce(local_nonce);

	memset_s(AES_symmetric_key,0,AES_KEY_SIZE);
	memset_s(HMAC_key,0,HMAC_KEY_SIZE);


	int received_signature_len;
	char *received_signature = recvDataHMAC(client_socket,received_signature_len);

	int value = verify.RSAFinal(received_signature);

	RSASignManager sign(SERVER_PRIVKEY_PATH);
	if(!sign.RSAUpdate(received_signature,received_signature_len)){
		delete[] received_signature;
		return false;
	}

	delete[] received_signature;


	uint32_t sign_final_len;
	char* sign_final = sign.RSAFinal(sign_final_len);
	if(sign_final == NULL){
		return false;
	}

	if(!sendDataHMAC(client_socket,sign_final,sign_final_len)){
		delete[] sign_final;
		return false;
	}

	delete[] sign_final;

    return value;


	//mancano free
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x9470
testb $0x1, %al
jne 0x6ff9
movb $0x0, -0x1(%rbp)
jmp 0x8025
cmpl $0x0, -0x14(%rbp)
jl 0x7008
cmpl $0xbb8, -0x14(%rbp)     # imm = 0xBB8
jle 0x7011
movb $0x0, -0x1(%rbp)
jmp 0x8025
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x9400
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x7031
movb $0x0, -0x1(%rbp)
jmp 0x8025
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movslq -0x14(%rbp), %rdx
xorl %eax, %eax
movl %eax, %edi
leaq -0x20(%rbp), %rsi
callq 0x5110
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x1c8(%rbp)
cmpq $0x0, %rax
je 0x706b
movq -0x1c8(%rbp), %rdi
callq 0x5720
cmpq $0x0, -0x30(%rbp)
jne 0x707b
movb $0x0, -0x1(%rbp)
jmp 0x8025
leaq 0x807a(%rip), %rsi      # 0xf0fc
leaq 0x8090(%rip), %rdx      # 0xf119
leaq -0x38(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0xd850
movq -0x1d8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xdbd0
movb %al, -0x1c9(%rbp)
jmp 0x70b1
movb -0x1c9(%rbp), %al
testb $0x1, %al
jne 0x70e9
jmp 0x70bd
movq -0x30(%rbp), %rdi
callq 0x52c0
jmp 0x70c8
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x800f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x801a
leaq -0x68(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x57e0
movq -0x1e8(%rbp), %rdx
movq -0x30(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xdd70
movb %al, -0x1d9(%rbp)
jmp 0x7115
movb -0x1d9(%rbp), %al
testb $0x1, %al
jne 0x714d
jmp 0x7121
movq -0x30(%rbp), %rdi
callq 0x52c0
jmp 0x712c
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7ff9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x8004
movq -0x30(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xdea0
movq %rax, -0x1f0(%rbp)
jmp 0x7163
movq -0x1f0(%rbp), %rsi
leaq 0xd4ef(%rip), %rdi      # 0x14660
callq 0xe970
jmp 0x7178
leaq 0x7fb6(%rip), %rsi      # 0xf135
leaq -0x68(%rbp), %rdi
callq 0x6150
movb %al, -0x1f1(%rbp)
jmp 0x7190
movb -0x1f1(%rbp), %al
testb $0x1, %al
jne 0x71e8
jmp 0x719c
movq 0xce25(%rip), %rdi      # 0x13fc8
leaq 0x7fa4(%rip), %rsi      # 0xf14e
callq 0x5500
movq %rax, -0x200(%rbp)
jmp 0x71b8
movq -0x200(%rbp), %rdi
movq 0xcdf2(%rip), %rsi      # 0x13fb8
callq 0x5550
jmp 0x71cd
movq -0x30(%rbp), %rdi
callq 0x52c0
jmp 0x71d8
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7ff9
movq 0xcdd9(%rip), %rdi      # 0x13fc8
leaq 0x7f6e(%rip), %rsi      # 0xf164
callq 0x5500
movq %rax, -0x208(%rbp)
jmp 0x7204
movq -0x208(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x54d0
movq %rax, -0x210(%rbp)
jmp 0x721d
movq -0x210(%rbp), %rdi
movq 0xcd8d(%rip), %rsi      # 0x13fb8
callq 0x5550
jmp 0x7232
movq -0x30(%rbp), %rdi
callq 0x52c0
jmp 0x723d
leaq 0x7f3e(%rip), %rdi      # 0xf182
leaq 0x83b1(%rip), %rsi      # 0xf5fc
callq 0x5640
movq %rax, -0x218(%rbp)
jmp 0x7259
movq -0x218(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x72c2
movq 0xcd7e(%rip), %rdi      # 0x13ff0
leaq 0x7f2a(%rip), %rsi      # 0xf1a3
callq 0x5500
movq %rax, -0x220(%rbp)
jmp 0x7287
movq -0x220(%rbp), %rdi
leaq 0x7eed(%rip), %rsi      # 0xf182
callq 0x5500
movq %rax, -0x228(%rbp)
jmp 0x72a3
movq -0x228(%rbp), %rdi
leaq 0x7f0c(%rip), %rsi      # 0xf1bd
callq 0x5500
jmp 0x72b8
movl $0x1, %edi
callq 0x5690
movq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x5790
movq %rax, -0x230(%rbp)
jmp 0x72de
movq -0x230(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
callq 0x5510
jmp 0x72f4
cmpq $0x0, -0x78(%rbp)
jne 0x731a
movq 0xccee(%rip), %rdi      # 0x13ff0
leaq 0x7ec2(%rip), %rsi      # 0xf1cb
callq 0x5500
jmp 0x7310
movl $0x1, %edi
callq 0x5690
movq $0x0, -0x80(%rbp)
movq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5410
movl %eax, -0x234(%rbp)
jmp 0x7337
movl -0x234(%rbp), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x7348
jmp 0x7348
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x9200
movb %al, -0x235(%rbp)
jmp 0x735c
movb -0x235(%rbp), %al
testb $0x1, %al
jne 0x7395
jmp 0x7368
movq -0x80(%rbp), %rax
movq %rax, -0x240(%rbp)
cmpq $0x0, %rax
je 0x7385
movq -0x240(%rbp), %rdi
callq 0x5720
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7ff9
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x93d0
movb %al, -0x241(%rbp)
jmp 0x73ad
movb -0x241(%rbp), %al
testb $0x1, %al
jne 0x73e6
jmp 0x73b9
movq -0x80(%rbp), %rax
movq %rax, -0x250(%rbp)
cmpq $0x0, %rax
je 0x73d6
movq -0x250(%rbp), %rdi
callq 0x5720
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7ff9
movq -0x80(%rbp), %rdi
leaq 0x7dfe(%rip), %rsi      # 0xf1ef
movl $0x13c, %edx            # imm = 0x13C
callq 0x53a0
jmp 0x73fd
movq -0x78(%rbp), %rdi
callq 0x52c0
jmp 0x7408
leaq 0xd251(%rip), %rsi      # 0x14660
leaq -0x98(%rbp), %rdi
callq 0xc130
jmp 0x741d
leaq 0x7de3(%rip), %rsi      # 0xf207
leaq -0xa0(%rbp), %rdi
callq 0xe3e0
jmp 0x7432
leaq -0xa0(%rbp), %rdi
leaq -0xa4(%rbp), %rsi
callq 0xe510
movq %rax, -0x258(%rbp)
jmp 0x744e
movq -0x258(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jne 0x7492
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x5690
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7feb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7fdf
leaq -0x98(%rbp), %rdi
leaq -0xa4(%rbp), %rsi
movl $0x4, %edx
callq 0xc220
movb %al, -0x259(%rbp)
jmp 0x74b2
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x74ce
jmp 0x74be
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fc5
movq -0x10(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x9200
movb %al, -0x25a(%rbp)
jmp 0x74e5
movb -0x25a(%rbp), %al
testb $0x1, %al
jne 0x7521
jmp 0x74f1
movq -0xb0(%rbp), %rax
movq %rax, -0x268(%rbp)
cmpq $0x0, %rax
je 0x7511
movq -0x268(%rbp), %rdi
callq 0x5720
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fc5
movq -0xb0(%rbp), %rsi
movl -0xa4(%rbp), %edx
leaq -0x98(%rbp), %rdi
callq 0xc220
movb %al, -0x269(%rbp)
jmp 0x7542
movb -0x269(%rbp), %al
testb $0x1, %al
jne 0x755e
jmp 0x754e
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fc5
movq -0x10(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movl -0xa4(%rbp), %edx
callq 0x93d0
movb %al, -0x26a(%rbp)
jmp 0x757c
movb -0x26a(%rbp), %al
testb $0x1, %al
jne 0x75b8
jmp 0x7588
movq -0xb0(%rbp), %rax
movq %rax, -0x278(%rbp)
cmpq $0x0, %rax
je 0x75a8
movq -0x278(%rbp), %rdi
callq 0x5720
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fc5
movq -0xb0(%rbp), %rax
movq %rax, -0x280(%rbp)
cmpq $0x0, %rax
je 0x75d8
movq -0x280(%rbp), %rdi
callq 0x5720
movq -0x10(%rbp), %rdi
leaq -0xbc(%rbp), %rsi
callq 0x9470
movb %al, -0x281(%rbp)
jmp 0x75f0
movb -0x281(%rbp), %al
testb $0x1, %al
jne 0x760c
jmp 0x75fc
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fc5
leaq -0x98(%rbp), %rdi
leaq -0xbc(%rbp), %rsi
movl $0x4, %edx
callq 0xc220
movb %al, -0x282(%rbp)
jmp 0x762c
movb -0x282(%rbp), %al
testb $0x1, %al
jne 0x7648
jmp 0x7638
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fc5
movq -0x10(%rbp), %rdi
movl -0xbc(%rbp), %esi
callq 0x9400
movq %rax, -0x290(%rbp)
jmp 0x7660
movq -0x290(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rsi
movl -0xbc(%rbp), %edx
leaq -0x98(%rbp), %rdi
callq 0xc220
movb %al, -0x291(%rbp)
jmp 0x768f
movb -0x291(%rbp), %al
testb $0x1, %al
jne 0x76ab
jmp 0x769b
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fc5
cmpq $0x0, -0xb8(%rbp)
jne 0x76c5
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fc5
movq -0xb8(%rbp), %rsi
movl -0xbc(%rbp), %edx
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rcx
callq 0xe5f0
movq %rax, -0x2a0(%rbp)
jmp 0x76ee
movq -0x2a0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x2a8(%rbp)
cmpq $0x0, %rax
je 0x771c
movq -0x2a8(%rbp), %rdi
callq 0x5720
cmpq $0x0, -0xc8(%rbp)
jne 0x7736
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fc5
leaq -0xd0(%rbp), %rdi
callq 0xe7d0
jmp 0x7744
movq -0xc8(%rbp), %rsi
movl -0xc0(%rbp), %edx
leaq -0xd0(%rbp), %rdi
callq 0xe830
movb %al, -0x2a9(%rbp)
jmp 0x7765
movb -0x2a9(%rbp), %al
testb $0x1, %al
jne 0x77c8
jmp 0x7771
movq -0xc8(%rbp), %rdi
movl -0xc0(%rbp), %edx
xorl %esi, %esi
callq 0x9e60
jmp 0x7787
movq -0xc8(%rbp), %rax
movq %rax, -0x2b8(%rbp)
cmpq $0x0, %rax
je 0x77a7
movq -0x2b8(%rbp), %rdi
callq 0x5720
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7fb7
leaq -0xd0(%rbp), %rdi
callq 0xe880
movq %rax, -0x2c0(%rbp)
jmp 0x77dd
movq -0x2c0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xc8(%rbp), %rdi
movl -0xc0(%rbp), %edx
xorl %esi, %esi
callq 0x9e60
jmp 0x7801
movq -0xc8(%rbp), %rax
movq %rax, -0x2c8(%rbp)
cmpq $0x0, %rax
je 0x7821
movq -0x2c8(%rbp), %rdi
callq 0x5720
cmpq $0x0, -0xd8(%rbp)
jne 0x783b
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fa9
movq -0xd8(%rbp), %rax
movups (%rax), %xmm0
movaps %xmm0, -0xf0(%rbp)
movq -0xd8(%rbp), %rax
movups 0x10(%rax), %xmm0
movaps %xmm0, -0x100(%rbp)
movq -0xd8(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x9e60
jmp 0x7873
movq -0xd8(%rbp), %rax
movq %rax, -0x2d0(%rbp)
cmpq $0x0, %rax
je 0x7893
movq -0x2d0(%rbp), %rdi
callq 0x5720
callq 0x5810
jmp 0x789a
leaq -0x110(%rbp), %rdi
movl $0x10, %esi
callq 0x5830
jmp 0x78ad
movl $0x0, -0x114(%rbp)
leaq -0x114(%rbp), %rdi
movl $0x4, %esi
callq 0x5830
jmp 0x78ca
leaq -0xf0(%rbp), %rdi
callq 0xe6c0
jmp 0x78d8
leaq -0x110(%rbp), %rdi
callq 0xe6f0
jmp 0x78e6
leaq -0x100(%rbp), %rdi
callq 0xe720
jmp 0x78f4
leaq -0x98(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0x10, %edx
callq 0xc220
movb %al, -0x2d1(%rbp)
jmp 0x7914
movb -0x2d1(%rbp), %al
testb $0x1, %al
jne 0x7930
jmp 0x7920
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fa9
movq -0x10(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0x10, %edx
callq 0x93d0
movb %al, -0x2d2(%rbp)
jmp 0x794d
movb -0x2d2(%rbp), %al
testb $0x1, %al
jne 0x7969
jmp 0x7959
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7fa9
leaq -0x130(%rbp), %rdi
callq 0xea40
jmp 0x7977
leaq -0x130(%rbp), %rdi
leaq -0x114(%rbp), %rsi
callq 0xeb90
jmp 0x798c
movl $0x4, -0x120(%rbp)
leaq -0x148(%rbp), %rdi
callq 0xebf0
jmp 0x79a4
leaq -0x150(%rbp), %rdi
callq 0xb690
jmp 0x79b2
leaq -0x150(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0x130(%rbp), %rdx
callq 0xb820
movb %al, -0x2d3(%rbp)
jmp 0x79d4
movb -0x2d3(%rbp), %al
testb $0x1, %al
jne 0x7a23
jmp 0x79e0
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7f9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7f8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7f83
leaq -0x150(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0xb8e0
movb %al, -0x2d4(%rbp)
jmp 0x7a3e
movb -0x2d4(%rbp), %al
testb $0x1, %al
jne 0x7a5a
jmp 0x7a4a
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f5d
leaq -0x138(%rbp), %rsi
leaq -0x98(%rbp), %rdi
movl $0x4, %edx
callq 0xc220
movb %al, -0x2d5(%rbp)
jmp 0x7a7a
movb -0x2d5(%rbp), %al
testb $0x1, %al
jne 0x7a96
jmp 0x7a86
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f5d
movq -0x10(%rbp), %rdi
movl -0x138(%rbp), %esi
callq 0x9200
movb %al, -0x2d6(%rbp)
jmp 0x7aad
movb -0x2d6(%rbp), %al
testb $0x1, %al
jne 0x7ac9
jmp 0x7ab9
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f5d
leaq -0x98(%rbp), %rdi
leaq -0x114(%rbp), %rsi
movl $0x4, %edx
callq 0xc220
movb %al, -0x2d7(%rbp)
jmp 0x7ae9
movb -0x2d7(%rbp), %al
testb $0x1, %al
jne 0x7b05
jmp 0x7af5
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f5d
movq -0x10(%rbp), %rax
movq %rax, -0x2e8(%rbp)
leaq -0x148(%rbp), %rdi
callq 0xed00
movq %rax, -0x2e0(%rbp)
jmp 0x7b25
movq -0x2e0(%rbp), %rsi
movq -0x2e8(%rbp), %rdi
movl -0x138(%rbp), %edx
callq 0x93d0
movb %al, -0x2e9(%rbp)
jmp 0x7b46
movb -0x2e9(%rbp), %al
testb $0x1, %al
jne 0x7b62
jmp 0x7b52
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f5d
movq -0x10(%rbp), %rdi
leaq -0x154(%rbp), %rsi
callq 0x9470
movb %al, -0x2ea(%rbp)
jmp 0x7b7a
movb -0x2ea(%rbp), %al
testb $0x1, %al
jne 0x7b96
jmp 0x7b86
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f5d
leaq -0x98(%rbp), %rdi
leaq -0x154(%rbp), %rsi
movl $0x4, %edx
callq 0xc220
movb %al, -0x2eb(%rbp)
jmp 0x7bb6
movb -0x2eb(%rbp), %al
testb $0x1, %al
jne 0x7bd2
jmp 0x7bc2
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f5d
movq -0x10(%rbp), %rdi
movl -0x154(%rbp), %esi
callq 0x9400
movq %rax, -0x2f8(%rbp)
jmp 0x7bea
movq -0x2f8(%rbp), %rax
movq %rax, -0x160(%rbp)
cmpq $0x0, -0x160(%rbp)
jne 0x7c12
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f5d
movq -0x160(%rbp), %rsi
leaq -0x148(%rbp), %rdi
callq 0xecc0
jmp 0x7c27
movl -0x154(%rbp), %eax
movl %eax, -0x138(%rbp)
leaq -0x168(%rbp), %rdi
callq 0xb990
jmp 0x7c41
leaq -0x168(%rbp), %rdi
leaq -0x130(%rbp), %rsi
leaq -0x148(%rbp), %rdx
callq 0xba90
movb %al, -0x2f9(%rbp)
jmp 0x7c63
movb -0x2f9(%rbp), %al
testb $0x1, %al
jne 0x7c90
jmp 0x7c6f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7f4f
leaq -0x168(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0xbc50
movb %al, -0x2fa(%rbp)
jmp 0x7cab
movb -0x2fa(%rbp), %al
testb $0x1, %al
jne 0x7cc7
jmp 0x7cb7
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f41
leaq -0x130(%rbp), %rdi
callq 0xebd0
movl %eax, -0x300(%rbp)
jmp 0x7cdb
movl -0x300(%rbp), %eax
movl %eax, -0x16c(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x16c(%rbp), %rsi
movl $0x4, %edx
callq 0xc220
movb %al, -0x301(%rbp)
jmp 0x7d07
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0x7d23
jmp 0x7d13
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f41
movl -0x16c(%rbp), %edi
callq 0xbfe0
jmp 0x7d30
movl -0x114(%rbp), %edi
callq 0xbfb0
jmp 0x7d3d
leaq -0xf0(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x9e60
jmp 0x7d52
leaq -0x100(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x9e60
jmp 0x7d67
movq -0x10(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x9c30
movq %rax, -0x310(%rbp)
jmp 0x7d80
movq -0x310(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0xc2d0
movl %eax, -0x314(%rbp)
jmp 0x7da9
movl -0x314(%rbp), %eax
movl %eax, -0x17c(%rbp)
leaq 0x7299(%rip), %rsi      # 0xf055
leaq -0x1b0(%rbp), %rdi
callq 0xc380
jmp 0x7dca
movq -0x178(%rbp), %rsi
movl -0x170(%rbp), %edx
leaq -0x1b0(%rbp), %rdi
callq 0xc4b0
movb %al, -0x315(%rbp)
jmp 0x7deb
movb -0x315(%rbp), %al
testb $0x1, %al
jne 0x7e44
jmp 0x7df7
movq -0x178(%rbp), %rax
movq %rax, -0x320(%rbp)
cmpq $0x0, %rax
je 0x7e17
movq -0x320(%rbp), %rdi
callq 0x5720
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xc700
jmp 0x7f4f
movq -0x178(%rbp), %rax
movq %rax, -0x328(%rbp)
cmpq $0x0, %rax
je 0x7e64
movq -0x328(%rbp), %rdi
callq 0x5720
leaq -0x1b0(%rbp), %rdi
leaq -0x1b4(%rbp), %rsi
callq 0xc580
movq %rax, -0x330(%rbp)
jmp 0x7e80
movq -0x330(%rbp), %rax
movq %rax, -0x1c0(%rbp)
cmpq $0x0, -0x1c0(%rbp)
jne 0x7ea8
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f35
movq -0x10(%rbp), %rdi
movq -0x1c0(%rbp), %rsi
movl -0x1b4(%rbp), %edx
callq 0x9b10
movb %al, -0x331(%rbp)
jmp 0x7ec6
movb -0x331(%rbp), %al
testb $0x1, %al
jne 0x7eff
jmp 0x7ed2
movq -0x1c0(%rbp), %rax
movq %rax, -0x340(%rbp)
cmpq $0x0, %rax
je 0x7ef2
movq -0x340(%rbp), %rdi
callq 0x5720
movb $0x0, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x7f35
movq -0x1c0(%rbp), %rax
movq %rax, -0x348(%rbp)
cmpq $0x0, %rax
je 0x7f1f
movq -0x348(%rbp), %rdi
callq 0x5720
cmpl $0x0, -0x17c(%rbp)
setne %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x1, -0x48(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xc700
leaq -0x168(%rbp), %rdi
callq 0xba60
jmp 0x7f5d
leaq -0x168(%rbp), %rdi
callq 0xba60
jmp 0x7f83
leaq -0x150(%rbp), %rdi
callq 0xb760
leaq -0x148(%rbp), %rdi
callq 0xec10
leaq -0x130(%rbp), %rdi
callq 0xea60
jmp 0x7fa9
leaq -0x150(%rbp), %rdi
callq 0xb760
leaq -0x148(%rbp), %rdi
callq 0xec10
leaq -0x130(%rbp), %rdi
callq 0xea60
jmp 0x7fb7
leaq -0xd0(%rbp), %rdi
callq 0xe900
jmp 0x7fc5
leaq -0xd0(%rbp), %rdi
callq 0xe900
jmp 0x7fdf
leaq -0xa0(%rbp), %rdi
callq 0xe690
leaq -0x98(%rbp), %rdi
callq 0xc320
jmp 0x7ff9
leaq -0xa0(%rbp), %rdi
callq 0xe690
leaq -0x98(%rbp), %rdi
callq 0xc320
jmp 0x8004
leaq -0x68(%rbp), %rdi
callq 0x5330
jmp 0x800f
leaq -0x68(%rbp), %rdi
callq 0x5330
jmp 0x801a
leaq -0x38(%rbp), %rdi
callq 0xdba0
jmp 0x8025
leaq -0x38(%rbp), %rdi
callq 0xdba0
jmp 0x8033
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x5980
nopl (%rax)