// File: fhirschman[P]CANF-gp/source/general_functions.cc
// Function: calcRandomPolynomial()
void calcRandomPolynomial(){
	int rand_n_terms = (rand() % (MAX_RANDOM_N_TERMS + 1 - 3)) + 3;
	for (int i = 0; i < MAX_RANDOM_N_TERMS; i++ ){
		double randExponent = (-1+2*((double)rand())/RAND_MAX)*RAND_EXPONENT_RANGE;
		double randCoeff = (-1+2*((double)rand())/RAND_MAX)*RAND_COEFF_RANGE;
		if(i>= rand_n_terms){
			randCoeff=0;
			randExponent=0;
		}
		#ifdef GPU_MODE
		POLY_COEFFS_GPU[i] = randCoeff;
		POLY_EXPONS_GPU[i] = randExponent;
		#endif

		POLY_COEFFS[i] = randCoeff;
		POLY_EXPONS[i] = randExponent;
	}

	cout << endl << " RAND_N_TERMS " << rand_n_terms << endl;
	cout << " RAND COEFFS ";

	if(FRAC_DER_MODE==0){
		for (int i = 0; i < MAX_RANDOM_N_TERMS; i++ ){
			cout << setprecision(16) << POLY_COEFFS[i]<< " " ;
		}
		cout << endl;
		cout << " RAND EXPONS ";
		for (int i = 0; i < MAX_RANDOM_N_TERMS; i++ ){
			cout << setprecision(16) << POLY_EXPONS[i] << " ";
		}
	}
	else{
		for (int i = 0; i < MAX_RANDOM_N_TERMS; i++ ){
			cout << setprecision(16) << POLY_COEFFS[i]<< " " ;
		}
		cout << endl;
		cout << " RAND EXPONS ";
		for (int i = 0; i < MAX_RANDOM_N_TERMS; i++ ){
			cout << setprecision(16) << POLY_EXPONS[i] << " ";
		}
		cout << endl << " FRAC_DER_MODE " << FRAC_DER_MODE << "\n";
		cout << " ALPHA_FRAC_DER " << ALPHA_FRAC_DER ;
	}

	int rand_color_ind = (rand() % (N_RAND_COLORS + 1 - 0)) + 0;
	cout << endl << " RAND_COLOR " << rand_color_ind << "\n";
	stream << "set palette rgbformulae " << colorMatrix[rand_color_ind][0]  << "," <<  colorMatrix[rand_color_ind][1]   << "," << colorMatrix[rand_color_ind][2] << ";";
	gp << stream.str();
	stream.str("");

	return;
}

// Assembly:
subq $0xf8, %rsp
callq 0x8120
leaq 0x2020d(%rip), %rcx     # 0x298f0
movl (%rcx), %ecx
addl $0x1, %ecx
subl $0x3, %ecx
cltd
idivl %ecx
addl $0x3, %edx
movl %edx, 0xf4(%rsp)
movl $0x0, 0xf0(%rsp)
movl 0xf0(%rsp), %eax
leaq 0x201df(%rip), %rcx     # 0x298f0
cmpl (%rcx), %eax
jge 0x9833
callq 0x8120
cvtsi2sd %eax, %xmm0
movsd 0x1490e(%rip), %xmm1    # 0x1e038
mulsd %xmm0, %xmm1
movsd 0x148fa(%rip), %xmm0    # 0x1e030
divsd %xmm0, %xmm1
movsd 0x148e6(%rip), %xmm0    # 0x1e028
addsd %xmm1, %xmm0
leaq 0x2025b(%rip), %rax     # 0x299a8
mulsd (%rax), %xmm0
movsd %xmm0, 0xe8(%rsp)
callq 0x8120
cvtsi2sd %eax, %xmm0
movsd 0x148cd(%rip), %xmm1    # 0x1e038
mulsd %xmm0, %xmm1
movsd 0x148b9(%rip), %xmm0    # 0x1e030
divsd %xmm0, %xmm1
movsd 0x148a5(%rip), %xmm0    # 0x1e028
addsd %xmm1, %xmm0
leaq 0x20222(%rip), %rax     # 0x299b0
mulsd (%rax), %xmm0
movsd %xmm0, 0xe0(%rsp)
movl 0xf0(%rsp), %eax
cmpl 0xf4(%rsp), %eax
jl 0x97c3
xorps %xmm0, %xmm0
movsd %xmm0, 0xe0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movslq 0xf0(%rsp), %rsi
leaq 0x201f7(%rip), %rdi     # 0x299d8
callq 0xbe70
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movslq 0xf0(%rsp), %rsi
leaq 0x201e2(%rip), %rdi     # 0x299f0
callq 0xbe70
movsd 0x58(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0xf0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf0(%rsp)
jmp 0x9703
movq 0x1f76e(%rip), %rdi     # 0x28fa8
movq 0x1f72f(%rip), %rsi     # 0x28f70
callq 0x8560
movq %rax, %rdi
leaq 0x149db(%rip), %rsi     # 0x1e22b
callq 0x84e0
movq %rax, %rdi
movl 0xf4(%rsp), %esi
callq 0x8940
movq %rax, %rdi
movq 0x1f702(%rip), %rsi     # 0x28f70
callq 0x8560
movq 0x1f72e(%rip), %rdi     # 0x28fa8
leaq 0x149b9(%rip), %rsi     # 0x1e23a
callq 0x84e0
leaq 0x2007b(%rip), %rax     # 0x29908
cmpl $0x0, (%rax)
jne 0x99d5
movl $0x0, 0xdc(%rsp)
movl 0xdc(%rsp), %eax
leaq 0x20041(%rip), %rcx     # 0x298f0
cmpl (%rcx), %eax
jge 0x9920
movl $0x10, %edi
callq 0xbe90
movl %eax, 0xd8(%rsp)
movl 0xd8(%rsp), %esi
movq 0x1f6d6(%rip), %rdi     # 0x28fa8
callq 0x8890
movq %rax, 0x48(%rsp)
movslq 0xdc(%rsp), %rsi
leaq 0x200ed(%rip), %rdi     # 0x299d8
callq 0xbe70
movq 0x48(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x8a10
movq %rax, %rdi
leaq 0x15846(%rip), %rsi     # 0x1f14e
callq 0x84e0
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x98a1
movq 0x1f681(%rip), %rdi     # 0x28fa8
movq 0x1f642(%rip), %rsi     # 0x28f70
callq 0x8560
movq 0x1f66e(%rip), %rdi     # 0x28fa8
leaq 0x14907(%rip), %rsi     # 0x1e248
callq 0x84e0
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
leaq 0x1ff91(%rip), %rcx     # 0x298f0
cmpl (%rcx), %eax
jge 0x99d0
movl $0x10, %edi
callq 0xbe90
movl %eax, 0xd0(%rsp)
movl 0xd0(%rsp), %esi
movq 0x1f626(%rip), %rdi     # 0x28fa8
callq 0x8890
movq %rax, 0x40(%rsp)
movslq 0xd4(%rsp), %rsi
leaq 0x20055(%rip), %rdi     # 0x299f0
callq 0xbe70
movq 0x40(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x8a10
movq %rax, %rdi
leaq 0x15796(%rip), %rsi     # 0x1f14e
callq 0x84e0
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x9951
jmp 0x9b77
movl $0x0, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
leaq 0x1ff02(%rip), %rcx     # 0x298f0
cmpl (%rcx), %eax
jge 0x9a5f
movl $0x10, %edi
callq 0xbe90
movl %eax, 0xc8(%rsp)
movl 0xc8(%rsp), %esi
movq 0x1f597(%rip), %rdi     # 0x28fa8
callq 0x8890
movq %rax, 0x38(%rsp)
movslq 0xcc(%rsp), %rsi
leaq 0x1ffae(%rip), %rdi     # 0x299d8
callq 0xbe70
movq 0x38(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x8a10
movq %rax, %rdi
leaq 0x15707(%rip), %rsi     # 0x1f14e
callq 0x84e0
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x99e0
movq 0x1f542(%rip), %rdi     # 0x28fa8
movq 0x1f503(%rip), %rsi     # 0x28f70
callq 0x8560
movq 0x1f52f(%rip), %rdi     # 0x28fa8
leaq 0x147c8(%rip), %rsi     # 0x1e248
callq 0x84e0
movl $0x0, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
leaq 0x1fe52(%rip), %rcx     # 0x298f0
cmpl (%rcx), %eax
jge 0x9b0f
movl $0x10, %edi
callq 0xbe90
movl %eax, 0xc0(%rsp)
movl 0xc0(%rsp), %esi
movq 0x1f4e7(%rip), %rdi     # 0x28fa8
callq 0x8890
movq %rax, 0x30(%rsp)
movslq 0xc4(%rsp), %rsi
leaq 0x1ff16(%rip), %rdi     # 0x299f0
callq 0xbe70
movq 0x30(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x8a10
movq %rax, %rdi
leaq 0x15657(%rip), %rsi     # 0x1f14e
callq 0x84e0
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x9a90
movq 0x1f492(%rip), %rdi     # 0x28fa8
movq 0x1f453(%rip), %rsi     # 0x28f70
callq 0x8560
movq %rax, %rdi
leaq 0x1472a(%rip), %rsi     # 0x1e256
callq 0x84e0
movq %rax, %rdi
leaq 0x1fdcd(%rip), %rax     # 0x29908
movl (%rax), %esi
callq 0x8940
movq %rax, %rdi
leaq 0x147a3(%rip), %rsi     # 0x1e2ef
callq 0x84e0
movq 0x1f450(%rip), %rdi     # 0x28fa8
leaq 0x14707(%rip), %rsi     # 0x1e266
callq 0x84e0
movq %rax, %rdi
leaq 0x1fe62(%rip), %rax     # 0x299d0
movsd (%rax), %xmm0
callq 0x8a10
callq 0x8120
leaq 0x1fd7d(%rip), %rcx     # 0x29900
movl (%rcx), %ecx
incl %ecx
cltd
idivl %ecx
movl %edx, 0xbc(%rsp)
movq 0x1f410(%rip), %rdi     # 0x28fa8
movq 0x1f3d1(%rip), %rsi     # 0x28f70
callq 0x8560
movq %rax, %rdi
leaq 0x146c9(%rip), %rsi     # 0x1e277
callq 0x84e0
movq %rax, %rdi
movl 0xbc(%rsp), %esi
callq 0x8940
movq %rax, %rdi
leaq 0x14723(%rip), %rsi     # 0x1e2ef
callq 0x84e0
leaq 0x20078(%rip), %rdi     # 0x29c50
movq %rdi, 0x20(%rsp)
leaq 0x14551(%rip), %rsi     # 0x1e135
callq 0x84e0
movq %rax, %rdi
movslq 0xbc(%rsp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x1f9c1(%rip), %rax     # 0x295c0
movq %rax, 0x18(%rsp)
movl (%rax,%rcx,4), %esi
callq 0x8940
movq %rax, %rdi
leaq 0x14538(%rip), %rsi     # 0x1e14e
movq %rsi, 0x10(%rsp)
callq 0x84e0
movq %rax, %rdi
movq 0x18(%rsp), %rax
movslq 0xbc(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x4(%rax,%rcx,4), %esi
callq 0x8940
movq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x84e0
movq %rax, %rdi
movq 0x18(%rsp), %rax
movslq 0xbc(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,4), %esi
callq 0x8940
movq %rax, %rdi
leaq 0x14742(%rip), %rsi     # 0x1e3b3
callq 0x84e0
movq 0x20(%rsp), %rsi
leaq 0x98(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x8530
movq 0x28(%rsp), %rsi
leaq 0x1fde7(%rip), %rdi     # 0x29a80
callq 0x8450
jmp 0x9ca0
leaq 0x98(%rsp), %rdi
callq 0x8330
leaq 0x67(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x8970
movq 0x8(%rsp), %rdx
leaq 0x14628(%rip), %rsi     # 0x1e2f0
leaq 0x68(%rsp), %rdi
callq 0xbd90
jmp 0x9cd4
leaq 0x1ff75(%rip), %rdi     # 0x29c50
leaq 0x68(%rsp), %rsi
callq 0x8250
jmp 0x9ce7
leaq 0x68(%rsp), %rdi
callq 0x8330
leaq 0x67(%rsp), %rdi
callq 0x85a0
addq $0xf8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x8330
jmp 0x9d64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0x9d5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x8330
leaq 0x67(%rsp), %rdi
callq 0x85a0
movq 0x90(%rsp), %rdi
callq 0x8960
nopw %cs:(%rax,%rax)