// File: yuansliu[P]HiRGC/hirgc.cpp
// Function: readTarFile(char*)
void readTarFile(char *tarFile) {// processing target file; recording all auxiliary information  
	
	FILE *fp = fopen(tarFile, "r");
	if (NULL == fp) {
		printf("fail to open file %s\n", tarFile);
		return;
	}
	char ch[1024], chr;
	
	int _tar_seq_len = 0;
	other_char_len = 0, n_vec_len = 0;
	pos_vec_len = line_break_len = 0;

	int letters_len = 0, n_letters_len = 0, index, ch_len;
	bool flag = true, n_flag = false; // first is upper case //first is not N

	// fscanf(fp, "%s", meta_data); //meta_data
	fgets(meta_data, 1024, fp);

	while (fscanf(fp, "%s", ch) != EOF) {
		ch_len = strlen(ch);

		for (int i = 0; i < ch_len; i++) {
			chr = ch[i];
			if (islower(chr)) {
				if (flag) { //previous is upper case
					flag = false; //change status of switch
					pos_vec[pos_vec_len].begin = (letters_len);
					letters_len = 0;
				}
				chr = toupper(chr);
			} else {
				if (isupper(chr)) {
					if (!flag) {
						flag = true;
						pos_vec[pos_vec_len].length = (letters_len);
						pos_vec_len++;
						letters_len = 0;
					}
				}
			}
			letters_len++;

			//ch is an upper letter
			if (chr != 'N') {
				index = agctIndex(chr);
				if (index^4) {
					// tar_seq_code[tar_seq_len++] = code_rule[index];
					tar_seq_code[_tar_seq_len++] = index;
				} else {
					other_char_vec[other_char_len].pos = _tar_seq_len;
					other_char_vec[other_char_len].ch = chr-'A';
					other_char_len++;
				}
			}

			if (!n_flag) {
				if (chr == 'N') {
					n_vec[n_vec_len].begin = n_letters_len;
					n_letters_len = 0;
					n_flag = true;
				}
			} else {//n_flag = true
				if (chr != 'N'){
					n_vec[n_vec_len].length = n_letters_len;
					n_vec_len++;
					n_letters_len = 0;
					n_flag = false;
				}
			}
			n_letters_len++;

		}
		line_break_vec[line_break_len++] = ch_len;
	}

	if (!flag) {
		pos_vec[pos_vec_len].length = (letters_len);
		pos_vec_len++;
	}
	
	if (n_flag) {
		n_vec[n_vec_len].length = (n_letters_len);
		n_vec_len++;
	}

	for (int i = other_char_len-1; i > 0; i--) {
		other_char_vec[i].pos -= other_char_vec[i-1].pos;
	}
	fclose(fp);
	tar_seq_len = _tar_seq_len;
}

// Assembly:
subq $0x448, %rsp            # imm = 0x448
movq %rdi, 0x440(%rsp)
movq 0x440(%rsp), %rdi
leaq 0x4d12(%rip), %rsi      # 0x8040
callq 0x21b0
movq %rax, 0x438(%rsp)
xorl %eax, %eax
cmpq 0x438(%rsp), %rax
jne 0x3362
movq 0x440(%rsp), %rsi
leaq 0x4d06(%rip), %rdi      # 0x805c
movb $0x0, %al
callq 0x2040
jmp 0x36aa
movl $0x0, 0x28(%rsp)
movl $0x0, 0x7e4c(%rip)      # 0xb1c0
movl $0x0, 0x7e56(%rip)      # 0xb1d4
movl $0x0, 0x7e50(%rip)      # 0xb1d8
movl $0x0, 0x7e3e(%rip)      # 0xb1d0
movl $0x0, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
movb $0x1, 0x17(%rsp)
movb $0x0, 0x16(%rsp)
movq 0x7dd5(%rip), %rdi      # 0xb188
movq 0x438(%rsp), %rdx
movl $0x400, %esi            # imm = 0x400
callq 0x2230
movq 0x438(%rsp), %rdi
leaq 0x30(%rsp), %rdx
leaq 0x4cc7(%rip), %rsi      # 0x80a0
movb $0x0, %al
callq 0x22a0
cmpl $-0x1, %eax
je 0x35f2
leaq 0x30(%rsp), %rdi
callq 0x20d0
movl %eax, 0x18(%rsp)
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
cmpl 0x18(%rsp), %eax
jge 0x35cb
movslq 0x10(%rsp), %rax
movb 0x30(%rsp,%rax), %al
movb %al, 0x2f(%rsp)
movsbl 0x2f(%rsp), %edi
callq 0x21d0
cmpl $0x0, %eax
je 0x3462
testb $0x1, 0x17(%rsp)
je 0x3452
movb $0x0, 0x17(%rsp)
movl 0x24(%rsp), %edx
movq 0x7d50(%rip), %rax      # 0xb190
movslq 0x7d89(%rip), %rcx      # 0xb1d0
movl %edx, (%rax,%rcx,8)
movl $0x0, 0x24(%rsp)
movsbl 0x2f(%rsp), %edi
callq 0x22b0
movb %al, 0x2f(%rsp)
jmp 0x34ae
movsbl 0x2f(%rsp), %edi
callq 0x2110
cmpl $0x0, %eax
je 0x34ac
testb $0x1, 0x17(%rsp)
jne 0x34aa
movb $0x1, 0x17(%rsp)
movl 0x24(%rsp), %edx
movq 0x7d08(%rip), %rax      # 0xb190
movslq 0x7d41(%rip), %rcx      # 0xb1d0
movl %edx, 0x4(%rax,%rcx,8)
movl 0x7d37(%rip), %eax      # 0xb1d0
addl $0x1, %eax
movl %eax, 0x7d2e(%rip)      # 0xb1d0
movl $0x0, 0x24(%rsp)
jmp 0x34ac
jmp 0x34ae
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
movsbl 0x2f(%rsp), %eax
cmpl $0x4e, %eax
je 0x353d
movsbl 0x2f(%rsp), %edi
callq 0x3150
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
xorl $0x4, %eax
cmpl $0x0, %eax
je 0x34fd
movl 0x1c(%rsp), %edx
movq 0x7cc8(%rip), %rax      # 0xb1b0
movl 0x28(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x28(%rsp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x353b
movl 0x28(%rsp), %edx
movq 0x7c98(%rip), %rax      # 0xb1a0
movslq 0x7cb1(%rip), %rcx      # 0xb1c0
movl %edx, (%rax,%rcx,8)
movsbl 0x2f(%rsp), %edx
subl $0x41, %edx
movq 0x7c7f(%rip), %rax      # 0xb1a0
movslq 0x7c98(%rip), %rcx      # 0xb1c0
movl %edx, 0x4(%rax,%rcx,8)
movl 0x7c8e(%rip), %eax      # 0xb1c0
addl $0x1, %eax
movl %eax, 0x7c85(%rip)      # 0xb1c0
jmp 0x353d
testb $0x1, 0x16(%rsp)
jne 0x3572
movsbl 0x2f(%rsp), %eax
cmpl $0x4e, %eax
jne 0x3570
movl 0x20(%rsp), %edx
movq 0x7c3f(%rip), %rax      # 0xb198
movslq 0x7c74(%rip), %rcx      # 0xb1d4
movl %edx, (%rax,%rcx,8)
movl $0x0, 0x20(%rsp)
movb $0x1, 0x16(%rsp)
jmp 0x35b0
movsbl 0x2f(%rsp), %eax
cmpl $0x4e, %eax
je 0x35ae
movl 0x20(%rsp), %edx
movq 0x7c11(%rip), %rax      # 0xb198
movslq 0x7c46(%rip), %rcx      # 0xb1d4
movl %edx, 0x4(%rax,%rcx,8)
movl 0x7c3c(%rip), %eax      # 0xb1d4
addl $0x1, %eax
movl %eax, 0x7c33(%rip)      # 0xb1d4
movl $0x0, 0x20(%rsp)
movb $0x0, 0x16(%rsp)
jmp 0x35b0
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x33ff
movl 0x18(%rsp), %edx
movq 0x7bd2(%rip), %rax      # 0xb1a8
movl 0x7bfc(%rip), %ecx      # 0xb1d8
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x7bf1(%rip)      # 0xb1d8
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x33c5
testb $0x1, 0x17(%rsp)
jne 0x361e
movl 0x24(%rsp), %edx
movq 0x7b8c(%rip), %rax      # 0xb190
movslq 0x7bc5(%rip), %rcx      # 0xb1d0
movl %edx, 0x4(%rax,%rcx,8)
movl 0x7bbb(%rip), %eax      # 0xb1d0
addl $0x1, %eax
movl %eax, 0x7bb2(%rip)      # 0xb1d0
testb $0x1, 0x16(%rsp)
je 0x364a
movl 0x20(%rsp), %edx
movq 0x7b68(%rip), %rax      # 0xb198
movslq 0x7b9d(%rip), %rcx      # 0xb1d4
movl %edx, 0x4(%rax,%rcx,8)
movl 0x7b93(%rip), %eax      # 0xb1d4
addl $0x1, %eax
movl %eax, 0x7b8a(%rip)      # 0xb1d4
movl 0x7b70(%rip), %eax      # 0xb1c0
subl $0x1, %eax
movl %eax, 0xc(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x3693
movq 0x7b3b(%rip), %rax      # 0xb1a0
movl 0xc(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,8), %esi
movq 0x7b27(%rip), %rax      # 0xb1a0
movslq 0xc(%rsp), %rcx
movl (%rax,%rcx,8), %edx
subl %esi, %edx
movl %edx, (%rax,%rcx,8)
movl 0xc(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3657
movq 0x438(%rsp), %rdi
callq 0x2180
movl 0x28(%rsp), %eax
movl %eax, 0x7b1e(%rip)      # 0xb1c8
addq $0x448, %rsp            # imm = 0x448
retq
nopw %cs:(%rax,%rax)