// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %rdi, %r14
leaq 0x2703(%rip), %rsi      # 0x5050
callq 0x2190
testq %rax, %rax
je 0x2bc2
movq %rax, %r12
xorl %eax, %eax
movl %eax, 0x584a(%rip)      # 0x81b0
movl %eax, 0x5858(%rip)      # 0x81c4
movl %eax, 0x5856(%rip)      # 0x81c8
movl %eax, 0x5848(%rip)      # 0x81c0
movq 0x57f9(%rip), %rdi      # 0x8178
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdx
callq 0x2210
leaq 0x271b(%rip), %rsi      # 0x50ae
leaq 0x40(%rsp), %rdx
movq %r12, %rdi
xorl %eax, %eax
callq 0x2280
cmpl $-0x1, %eax
je 0x2be4
movb $0x1, %al
movl %eax, 0x4(%rsp)
leaq 0x40(%rsp), %r13
xorl %r15d, %r15d
xorl %ebx, %ebx
xorl %r14d, %r14d
movl $0x0, (%rsp)
movq %r12, 0x18(%rsp)
movq %r13, %rdi
callq 0x20b0
testl %eax, %eax
movq %rax, 0x20(%rsp)
jle 0x2b76
movq 0x579a(%rip), %rcx      # 0x8180
movq %rcx, 0x8(%rsp)
movq 0x57ae(%rip), %rcx      # 0x81a0
movq %rcx, 0x30(%rsp)
movq 0x5792(%rip), %rcx      # 0x8190
movq %rcx, 0x28(%rsp)
movq 0x577e(%rip), %rcx      # 0x8188
movq %rcx, 0x10(%rsp)
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x38(%rsp)
xorl %r12d, %r12d
movb 0x40(%rsp,%r12), %bpl
movsbl %bpl, %r13d
movl %r13d, %edi
callq 0x21c0
testl %eax, %eax
je 0x2a81
testb $0x1, 0x4(%rsp)
je 0x2a53
movslq 0x5781(%rip), %rax      # 0x81c0
movq 0x8(%rsp), %rcx
movl %r14d, (%rcx,%rax,8)
xorl %r14d, %r14d
movl $0x0, 0x4(%rsp)
movl %r13d, %edi
callq 0x2290
movl %eax, %ebp
cmpb $0x4e, %bpl
je 0x2b20
movzbl %bpl, %eax
cmpl $0x46, %eax
jg 0x2ab6
cmpl $0x41, %eax
je 0x2ad0
cmpl $0x43, %eax
jne 0x2ac7
movl $0x1, %eax
jmp 0x2adb
movl %r13d, %edi
callq 0x20f0
testl %eax, %eax
je 0x2a5d
testb $0x1, 0x4(%rsp)
jne 0x2a5d
movslq 0x5725(%rip), %rax      # 0x81c0
movq 0x8(%rsp), %rcx
movl %r14d, 0x4(%rcx,%rax,8)
incl 0x5715(%rip)            # 0x81c0
movb $0x1, %al
movl %eax, 0x4(%rsp)
xorl %r14d, %r14d
jmp 0x2a5d
cmpl $0x47, %eax
je 0x2ad6
cmpl $0x54, %eax
jne 0x2ac7
movl $0x3, %eax
jmp 0x2adb
movl $0x4, %eax
movb $0x1, %cl
jmp 0x2add
xorl %ecx, %ecx
xorl %eax, %eax
jmp 0x2add
movl $0x2, %eax
xorl %ecx, %ecx
testb %cl, %cl
je 0x2b0d
movsbl %bpl, %eax
movslq 0x56c4(%rip), %rcx      # 0x81b0
movl (%rsp), %edx
movq 0x28(%rsp), %rsi
movl %edx, (%rsi,%rcx,8)
addl $-0x41, %eax
movslq 0x56af(%rip), %rcx      # 0x81b0
movl %eax, 0x4(%rsi,%rcx,8)
incl 0x56a5(%rip)            # 0x81b0
jmp 0x2b20
movl (%rsp), %edx
movslq %edx, %rcx
incl %edx
movl %edx, (%rsp)
movq 0x30(%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
testb $0x1, %r15b
je 0x2b49
cmpb $0x4e, %bpl
je 0x2b63
movslq 0x5691(%rip), %rax      # 0x81c4
movq 0x10(%rsp), %rcx
movl %ebx, 0x4(%rcx,%rax,8)
incl 0x5682(%rip)            # 0x81c4
xorl %ebx, %ebx
xorl %r15d, %r15d
jmp 0x2b63
cmpb $0x4e, %bpl
jne 0x2b63
movslq 0x566e(%rip), %rax      # 0x81c4
movq 0x10(%rsp), %rcx
movl %ebx, (%rcx,%rax,8)
movb $0x1, %r15b
xorl %ebx, %ebx
incl %r14d
incl %ebx
incq %r12
cmpq %r12, 0x38(%rsp)
jne 0x2a1c
movq 0x561b(%rip), %rax      # 0x8198
movslq 0x5644(%rip), %rcx      # 0x81c8
leal 0x1(%rcx), %edx
movl %edx, 0x563b(%rip)      # 0x81c8
movq 0x20(%rsp), %rdx
movl %edx, (%rax,%rcx,4)
movq 0x18(%rsp), %r12
movq %r12, %rdi
leaq 0x250a(%rip), %rsi      # 0x50ae
leaq 0x40(%rsp), %r13
movq %r13, %rdx
xorl %eax, %eax
callq 0x2280
cmpl $-0x1, %eax
jne 0x29ca
movl 0x4(%rsp), %eax
jmp 0x2bf5
leaq 0x24a1(%rip), %rdi      # 0x506a
movq %r14, %rsi
xorl %eax, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
movl $0x0, (%rsp)
movb $0x1, %al
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %r15d, %r15d
testb $0x1, %al
jne 0x2c12
movq 0x5580(%rip), %rax      # 0x8180
movslq 0x55b9(%rip), %rcx      # 0x81c0
movl %r14d, 0x4(%rax,%rcx,8)
incl 0x55ae(%rip)            # 0x81c0
testb $0x1, %r15b
je 0x2c30
movq 0x5569(%rip), %rax      # 0x8188
movslq 0x559e(%rip), %rcx      # 0x81c4
movl %ebx, 0x4(%rax,%rcx,8)
incl 0x5594(%rip)            # 0x81c4
movslq 0x5579(%rip), %rax      # 0x81b0
cmpq $0x2, %rax
jl 0x2c58
movq 0x554c(%rip), %rcx      # 0x8190
incq %rax
movl -0x18(%rcx,%rax,8), %edx
subl %edx, -0x10(%rcx,%rax,8)
decq %rax
cmpq $0x2, %rax
jg 0x2c47
movq %r12, %rdi
callq 0x2160
movl (%rsp), %eax
movl %eax, 0x554f(%rip)      # 0x81b8
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq