// File: /workspace/github_cpp_makefile_star2_O1/richardposner[P]BioNetFit2/src/code/Utils.cpp
// Function: generate_gdat_file(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)
int generate_gdat_file(string exp_file, string gdat_path, int seed){ //razi added to generate artificial gdat files
	//read exp-file
	//copy to gdat file
cout<<"\nUtils::generate_gdat_file: PiD["<<seed <<"] Starts generating file: "<< gdat_path << "   from file :" << exp_file<<"\n.";
try{
	std::ifstream ifs(exp_file);
	std::ofstream ofs(gdat_path);
	std::string line, oline;
	std::string word;
	int wcnt, linecnt;
	int val, rnd1; //Raquel removed unused, rnd;
	std::string::size_type pos = 0;
	std::string::size_type prev = 0;
	boost::random::mt19937 generalRand;

//cout<<"Utils:g-1   try to generate file:" <<gdat_path << " from file: " << exp_file<< endl;
	if ((ifs.is_open()) && (ofs.is_open())) {


		linecnt=0;
		while (getline(ifs, line)) {
			if (line.length() > 0){
				linecnt++;
				if (line.at(0) == '#'){
					oline=line;
//cout<<"Utils:g-2   A header line is read:" <<line << endl;
				}else{

//cout<<"Utils:g-3   A valid line is read:" <<line << endl;
					//data line break line into smaller pieces

					pos = 0; prev = 0; wcnt=0; oline=""; line=line+"\t"; //add tab to the end

					srand(time(0)+seed);
					while ((pos = line.find("\t", prev)) != std::string::npos)
					{
						if (pos != prev) //otherwise, most likely the first tab
						{
							wcnt++;
							word = line.substr(prev, pos - prev);


//cout<<"Utils:g-4   A word is read:" <<word << endl;
							if (wcnt == 1){  //the first word is time, don't touch it
								oline=oline + "\t" + word;
							}else{
								//for all pieces, if numerical value , change all of it except the first one
								val = atoi(word.c_str());


								rnd1 = rand()%100;
								val = val + (int) (rnd1);
								if (val < 0){ val=-val;}

//cout<<"Utils:g-6  the new value is :" <<val<< endl;
								oline = oline +"\t" + toString(val);
//cout<<"Utils:g-7  output line is :" <<oline <<endl;

							}
						}
						prev = pos + 1;
					}
					//write the output line into the output file
				}
//cout<<"Utils:g-9  try to dump output line:" <<oline <<endl;
				ofs << oline << std::endl;
			}
		}
		ifs.close();
		ofs.close();
//cout<<"Utils:g-10   finished generating file:" <<gdat_path << " from file: " << exp_file<< " successfully." <<endl;
		return 0;  //successful
	}else{
//cout<<"Utils:g-11   try to generate file:" <<gdat_path << " from file: " << exp_file<< ", Can't open input or output file !!!" <<endl;
		return -1;
	}
}
catch(int err){
	cout<< "Error occurred when generating artificial gdata file....\n\n"; return -1;
}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe98, %rsp            # imm = 0xE98
movl %edx, %r12d
movq %rsi, %rbx
movq %rdi, %r14
movq 0xb7893(%rip), %r15     # 0x175f90
leaq 0x632e7(%rip), %rsi     # 0x1219eb
movl $0x20, %edx
movq %r15, %rdi
callq 0x22ab0
movq %r15, %rdi
movq %r12, 0xc0(%rsp)
movl %r12d, %esi
callq 0x231e0
movq %rax, %r15
leaq 0x632de(%rip), %rsi     # 0x121a0c
movl $0x1a, %edx
movq %rax, %rdi
callq 0x22ab0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r15, %rdi
callq 0x22ab0
movq %rax, %r15
leaq 0x3a470(%rip), %rsi     # 0xf8bc4
movl $0xe, %edx
movq %rax, %rdi
callq 0x22ab0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r15, %rdi
callq 0x22ab0
leaq 0x40765(%rip), %rsi     # 0xfeedc
movl $0x2, %edx
movq %rax, %rdi
callq 0x22ab0
leaq 0x2c8(%rsp), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x23070
leaq 0xc8(%rsp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x233d0
leaq 0x90(%rsp), %r14
movq %r14, -0x10(%r14)
xorl %eax, %eax
movq %rax, -0x8(%r14)
movb %al, (%r14)
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
movq %rax, -0x8(%r15)
movb %al, (%r15)
leaq 0xb0(%rsp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb %al, (%r12)
leaq 0x59124(%rip), %rsi     # 0x117914
leaq 0x4d0(%rsp), %rdi
callq 0xa7b7e
leaq 0x340(%rsp), %rdi
callq 0x221e0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testb %al, %al
je 0xbeca5
leaq 0x138(%rsp), %rdi
callq 0x221e0
testb %al, %al
je 0xbeca5
leaq 0x30(%rsp), %r14
leaq 0x80(%rsp), %r15
movq 0x2c8(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0x2c8(%rsp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %edx
leaq 0x2c8(%rsp), %rdi
movq %r15, %rsi
callq 0x23300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xbec74
cmpq $0x0, 0x88(%rsp)
je 0xbe839
movq 0x80(%rsp), %rax
cmpb $0x23, (%rax)
jne 0xbe8a9
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x22500
jmp 0xbec2e
movq 0x48(%rsp), %rdx
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
leaq 0x38405(%rip), %rcx     # 0xf6cc1
xorl %r8d, %r8d
callq 0x22fb0
movq %r14, 0x20(%rsp)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x32180
movq %rbx, %rdi
leaq 0x383cd(%rip), %rsi     # 0xf6cc0
callq 0x233b0
movq %r15, %rdi
movq %rbx, %rsi
callq 0x22bb0
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xbe91a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x229c0
xorl %edi, %edi
callq 0x22900
movq 0xc0(%rsp), %rcx
leal (%rax,%rcx), %edi
callq 0x22930
movl $0x1, %ecx
movq %r15, %rdi
leaq 0x38380(%rip), %rsi     # 0xf6cc0
xorl %edx, %edx
callq 0x231f0
cmpq $-0x1, %rax
je 0xbec2e
movq %rax, %r12
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r12, %rcx
subq %rbx, %rcx
je 0xbec04
leaq 0x20(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x22a00
leaq 0xa0(%rsp), %rdi
movq %rbp, %rsi
callq 0x22bb0
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xbe99f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x229c0
testl %r13d, %r13d
je 0xbea78
movq 0xa0(%rsp), %rdi
callq 0x22fe0
movl %eax, %ebx
callq 0x22230
cltq
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rcx
addl %edx, %ecx
imull $0x64, %ecx, %ecx
subl %ecx, %eax
addl %ebx, %eax
movl %eax, %ebx
negl %ebx
cmovsl %eax, %ebx
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rbp
movq %rbp, %rdi
callq 0x32180
movq %rbp, %rdi
leaq 0x382b5(%rip), %rsi     # 0xf6cc0
callq 0x233b0
leaq 0x60(%rsp), %rdi
movl %ebx, %esi
callq 0xbee9e
movq (%rsp), %rcx
movl $0xf, %esi
leaq 0x10(%rsp), %rax
cmpq %rax, %rcx
je 0xbea34
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %r8
movq 0x68(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0xbea66
movl $0xf, %esi
leaq 0x70(%rsp), %rdi
cmpq %rdi, 0x60(%rsp)
je 0xbea5d
movq 0x70(%rsp), %rsi
cmpq %rsi, %rax
jbe 0xbeaea
movq 0x60(%rsp), %rsi
movq %rsp, %rdi
callq 0x222b0
jmp 0xbeaf8
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x32180
movq %rbx, %rdi
leaq 0x3821d(%rip), %rsi     # 0xf6cc0
callq 0x233b0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rbx, %rdi
callq 0x222b0
movq %r14, 0x20(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xbeb9e
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0xbeba5
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22a80
movq %r14, 0x20(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0xbeb18
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0xbeb1f
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x28(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x22bb0
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xbeb62
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0xbeb7e
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x229c0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xbeb99
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x229c0
incl %r13d
jmp 0xbec04
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, 0x28(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x22bb0
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xbebe3
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x229c0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xbebfe
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x229c0
movl $0x1, %r13d
movq %r12, %rbx
incq %rbx
movl $0x1, %ecx
movq %r15, %rdi
leaq 0x380a7(%rip), %rsi     # 0xf6cc0
movq %rbx, %rdx
callq 0x231f0
movq %rax, %r12
cmpq $-0x1, %rax
jne 0xbe959
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
leaq 0xc8(%rsp), %rdi
callq 0x22ab0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %rbx, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
jmp 0xbe839
leaq 0x2c8(%rsp), %rdi
leaq 0x90(%rsp), %r14
leaq 0x50(%rsp), %r15
leaq 0xb0(%rsp), %r12
callq 0x221b0
xorl %ebx, %ebx
leaq 0xc8(%rsp), %rdi
callq 0x22de0
movq 0xa0(%rsp), %rdi
cmpq %r12, %rdi
je 0xbecc2
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0xbecd9
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0xbecf6
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0xb7273(%rip), %rax     # 0x175f70
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0xd0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0xc8(%rsp,%rcx)
callq 0x227d0
leaq 0x1c0(%rsp), %rdi
callq 0x222d0
leaq 0x2c8(%rsp), %rdi
callq 0x22200
movl %ebx, %eax
addq $0xe98, %rsp            # imm = 0xE98
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r15
movq %rax, %rbx
jmp 0xbee4c
movq %rdx, %r15
movq %rax, %rbx
jmp 0xbee59
jmp 0xbedd3
movq %rdx, %r15
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xbedd9
movq 0x30(%rsp), %rsi
jmp 0xbedc5
jmp 0xbedd3
jmp 0xbedac
jmp 0xbedd3
jmp 0xbedac
movq %rdx, %r15
movq %rax, %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0xbedb2
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0xbedb2
jmp 0xbedac
movq %rdx, %r15
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xbedd9
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0xbedd9
jmp 0xbedd3
jmp 0xbedd3
movq %rdx, %r15
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
leaq 0x90(%rsp), %r14
leaq 0x50(%rsp), %r12
je 0xbee0b
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0xbee22
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0xbee3f
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0xc8(%rsp), %rdi
callq 0x22ea0
leaq 0x2c8(%rsp), %rdi
callq 0x22200
cmpl $0x1, %r15d
jne 0xbee96
movq %rbx, %rdi
callq 0x22360
movq 0xb7122(%rip), %rdi     # 0x175f90
leaq 0x62bb2(%rip), %rsi     # 0x121a27
movl $0x3a, %edx
callq 0x22ab0
callq 0x230b0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xbed3b
movq %rax, %rbx
callq 0x230b0
movq %rbx, %rdi
callq 0x23240