// File: /workspace/github_cpp_makefile_star2_O3/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 0xb81bf(%rip), %r15     # 0x175fa8
leaq 0x63bdb(%rip), %rsi     # 0x1219cb
movl $0x20, %edx
movq %r15, %rdi
callq 0x22ab0
movq %r15, %rdi
movq %r12, 0xc0(%rsp)
movl %r12d, %esi
callq 0x231e0
movq %rax, %r15
leaq 0x63bd2(%rip), %rsi     # 0x1219ec
movl $0x1a, %edx
movq %rax, %rdi
callq 0x22ab0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r15, %rdi
callq 0x22ab0
movq %rax, %r15
leaq 0x3ad64(%rip), %rsi     # 0xf8ba4
movl $0xe, %edx
movq %rax, %rdi
callq 0x22ab0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r15, %rdi
callq 0x22ab0
leaq 0x410e9(%rip), %rsi     # 0xfef4c
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 0x59a20(%rip), %rsi     # 0x1178fc
leaq 0x4d0(%rsp), %rdi
callq 0xa7120
leaq 0x340(%rsp), %rdi
callq 0x221e0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testb %al, %al
je 0xbe38b
leaq 0x138(%rsp), %rdi
callq 0x221e0
testb %al, %al
je 0xbe38b
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 0xbe35a
cmpq $0x0, 0x88(%rsp)
je 0xbdf25
movq 0x80(%rsp), %rax
cmpb $0x23, (%rax)
jne 0xbdf95
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x22500
jmp 0xbe314
movq 0x48(%rsp), %rdx
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
leaq 0x38cc9(%rip), %rcx     # 0xf6c71
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 0x3213c
movq %rbx, %rdi
leaq 0x38c91(%rip), %rsi     # 0xf6c70
callq 0x233b0
movq %r15, %rdi
movq %rbx, %rsi
callq 0x22bb0
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xbe006
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 0x38c44(%rip), %rsi     # 0xf6c70
xorl %edx, %edx
callq 0x231f0
cmpq $-0x1, %rax
je 0xbe314
movq %rax, %r12
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r12, %rcx
subq %rbx, %rcx
je 0xbe2ea
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 0xbe08b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x229c0
testl %r13d, %r13d
je 0xbe15e
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 0x3213c
movq %rbp, %rdi
leaq 0x38b79(%rip), %rsi     # 0xf6c70
callq 0x233b0
leaq 0x60(%rsp), %rdi
movl %ebx, %esi
callq 0xbe584
movq (%rsp), %rcx
movl $0xf, %edi
leaq 0x10(%rsp), %rax
cmpq %rax, %rcx
je 0xbe120
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r8
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0xbe151
movl $0xf, %edi
leaq 0x70(%rsp), %r9
cmpq %r9, %rsi
je 0xbe14c
movq 0x70(%rsp), %rdi
cmpq %rdi, %rax
jbe 0xbe1d0
movq %rsp, %rdi
callq 0x222b0
jmp 0xbe1de
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 0x3213c
movq %rbx, %rdi
leaq 0x38ae7(%rip), %rsi     # 0xf6c70
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 0xbe284
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0xbe28b
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 0xbe1fe
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0xbe205
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 0xbe248
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0xbe264
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x229c0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xbe27f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x229c0
incl %r13d
jmp 0xbe2ea
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 0xbe2c9
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x229c0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xbe2e4
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x229c0
movl $0x1, %r13d
movq %r12, %rbx
incq %rbx
movl $0x1, %ecx
movq %r15, %rdi
leaq 0x38971(%rip), %rsi     # 0xf6c70
movq %rbx, %rdx
callq 0x231f0
movq %rax, %r12
cmpq $-0x1, %rax
jne 0xbe045
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 0xbdf25
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 0xbe3a8
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0xbe3bf
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0xbe3dc
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0xb7ba5(%rip), %rax     # 0x175f88
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 0xbe532
movq %rdx, %r15
movq %rax, %rbx
jmp 0xbe53f
jmp 0xbe4b9
movq %rdx, %r15
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xbe4bf
movq 0x30(%rsp), %rsi
jmp 0xbe4ab
jmp 0xbe4b9
jmp 0xbe492
jmp 0xbe4b9
jmp 0xbe492
movq %rdx, %r15
movq %rax, %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0xbe498
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0xbe498
jmp 0xbe492
movq %rdx, %r15
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xbe4bf
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0xbe4bf
jmp 0xbe4b9
jmp 0xbe4b9
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 0xbe4f1
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0xbe508
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0xbe525
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0xc8(%rsp), %rdi
callq 0x22ea0
leaq 0x2c8(%rsp), %rdi
callq 0x22200
cmpl $0x1, %r15d
jne 0xbe57c
movq %rbx, %rdi
callq 0x22360
movq 0xb7a54(%rip), %rdi     # 0x175fa8
leaq 0x634ac(%rip), %rsi     # 0x121a07
movl $0x3a, %edx
callq 0x22ab0
callq 0x230b0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xbe421
movq %rax, %rbx
callq 0x230b0
movq %rbx, %rdi
callq 0x23240