// File: /workspace/github_c_makefile_star2_O0/lh3[P]minimap2/hit.c
// Function: mm_seg_gen
mm_seg_t *mm_seg_gen(void *km, uint32_t hash, int n_segs, const int *qlens, int n_regs0, const mm_reg1_t *regs0, int *n_regs, mm_reg1_t **regs, const mm128_t *a)
{
	int s, i, j, acc_qlen[MM_MAX_SEG+1], qlen_sum = 0;
	mm_seg_t *seg;

	assert(n_segs <= MM_MAX_SEG);
	for (s = 1, acc_qlen[0] = 0; s < n_segs; ++s)
		acc_qlen[s] = acc_qlen[s-1] + qlens[s-1];
	qlen_sum = acc_qlen[n_segs - 1] + qlens[n_segs - 1];

	seg = (mm_seg_t*)kcalloc(km, n_segs, sizeof(mm_seg_t));
	for (s = 0; s < n_segs; ++s) {
		seg[s].u = (uint64_t*)kmalloc(km, n_regs0 * 8);
		for (i = 0; i < n_regs0; ++i)
			seg[s].u[i] = (uint64_t)regs0[i].score << 32;
	}
	for (i = 0; i < n_regs0; ++i) {
		const mm_reg1_t *r = &regs0[i];
		for (j = 0; j < r->cnt; ++j) {
			int sid = (a[r->as + j].y&MM_SEED_SEG_MASK)>>MM_SEED_SEG_SHIFT;
			++seg[sid].u[i];
			++seg[sid].n_a;
		}
	}
	for (s = 0; s < n_segs; ++s) {
		mm_seg_t *sr = &seg[s];
		for (i = 0, sr->n_u = 0; i < n_regs0; ++i) // squeeze out zero-length per-segment chains
			if ((int32_t)sr->u[i] != 0)
				sr->u[sr->n_u++] = sr->u[i];
		sr->a = (mm128_t*)kmalloc(km, sr->n_a * sizeof(mm128_t));
		sr->n_a = 0;
	}

	for (i = 0; i < n_regs0; ++i) {
		const mm_reg1_t *r = &regs0[i];
		for (j = 0; j < r->cnt; ++j) {
			int sid = (a[r->as + j].y&MM_SEED_SEG_MASK)>>MM_SEED_SEG_SHIFT;
			mm128_t a1 = a[r->as + j];
			// on reverse strand, the segment position is:
			//   x_for_cat = qlen_sum - 1 - (int32_t)a1.y - 1 + q_span
			//   (int32_t)new_a1.y = qlens[sid] - (x_for_cat - acc_qlen[sid] + 1 - q_span) - 1 = (int32_t)a1.y - (qlen_sum - (qlens[sid] + acc_qlen[sid]))
			a1.y -= a1.x>>63? qlen_sum - (qlens[sid] + acc_qlen[sid]) : acc_qlen[sid];
			seg[sid].a[seg[sid].n_a++] = a1;
		}
	}
	for (s = 0; s < n_segs; ++s) {
		regs[s] = mm_gen_regs(km, hash, qlens[s], seg[s].n_u, seg[s].u, seg[s].a, 0);
		n_regs[s] = seg[s].n_u;
		for (i = 0; i < n_regs[s]; ++i) {
			regs[s][i].seg_split = 1;
			regs[s][i].seg_id = s;
		}
	}
	return seg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4a0, %rsp            # imm = 0x4A0
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq %r9, -0x28(%rbp)
movl $0x0, -0x444(%rbp)
cmpl $0xff, -0x10(%rbp)
jg 0x2b802
jmp 0x2b821
leaq 0x2cda3(%rip), %rdi     # 0x585ac
leaq 0x2cd62(%rip), %rsi     # 0x58572
movl $0x150, %edx            # imm = 0x150
leaq 0x2cda5(%rip), %rcx     # 0x585c1
callq 0x21a0
movl $0x1, -0x2c(%rbp)
movl $0x0, -0x440(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x2b86f
movl -0x2c(%rbp), %eax
subl $0x1, %eax
cltq
movl -0x440(%rbp,%rax,4), %ecx
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
addl (%rax,%rdx,4), %ecx
movslq -0x2c(%rbp), %rax
movl %ecx, -0x440(%rbp,%rax,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2b832
movl -0x10(%rbp), %eax
subl $0x1, %eax
cltq
movl -0x440(%rbp,%rax,4), %eax
movq -0x18(%rbp), %rcx
movl -0x10(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, -0x444(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x10(%rbp), %rsi
movl $0x18, %edx
callq 0x1a790
movq %rax, -0x450(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x2b94a
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0x1aae0
movq %rax, %rcx
movq -0x450(%rbp), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2b93a
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movslq 0xc(%rax), %rdx
shlq $0x20, %rdx
movq -0x450(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2b8f2
jmp 0x2b93c
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2b8b4
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2ba24
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x458(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x458(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x2ba14
movq 0x20(%rbp), %rcx
movq -0x458(%rbp), %rax
movl 0x28(%rax), %eax
addl -0x34(%rbp), %eax
cltq
shlq $0x4, %rax
addq %rax, %rcx
movabsq $0xff000000000000, %rax # imm = 0xFF000000000000
andq 0x8(%rcx), %rax
shrq $0x30, %rax
movl %eax, -0x45c(%rbp)
movq -0x450(%rbp), %rax
movslq -0x45c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x450(%rbp), %rax
movslq -0x45c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2b97a
jmp 0x2ba16
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2b951
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x2bb08
movq -0x450(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x468(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x468(%rbp), %rax
movl $0x0, (%rax)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2bac6
movq -0x468(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, %eax
je 0x2bab9
movq -0x468(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x468(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x468(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x2babb
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2ba64
movq -0x8(%rbp), %rdi
movq -0x468(%rbp), %rax
movslq 0x4(%rax), %rsi
shlq $0x4, %rsi
callq 0x1aae0
movq %rax, %rcx
movq -0x468(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x468(%rbp), %rax
movl $0x0, 0x4(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2ba2b
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2bc8e
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x470(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x470(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x2bc7e
movq 0x20(%rbp), %rcx
movq -0x470(%rbp), %rax
movl 0x28(%rax), %eax
addl -0x34(%rbp), %eax
cltq
shlq $0x4, %rax
addq %rax, %rcx
movabsq $0xff000000000000, %rax # imm = 0xFF000000000000
andq 0x8(%rcx), %rax
shrq $0x30, %rax
movl %eax, -0x474(%rbp)
movq 0x20(%rbp), %rax
movq -0x470(%rbp), %rcx
movl 0x28(%rcx), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x488(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x480(%rbp)
movq -0x488(%rbp), %rax
shrq $0x3f, %rax
cmpq $0x0, %rax
je 0x2bbea
movl -0x444(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq -0x474(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movslq -0x474(%rbp), %rdx
addl -0x440(%rbp,%rdx,4), %ecx
subl %ecx, %eax
movl %eax, -0x48c(%rbp)
jmp 0x2bbfe
movslq -0x474(%rbp), %rax
movl -0x440(%rbp,%rax,4), %eax
movl %eax, -0x48c(%rbp)
movl -0x48c(%rbp), %eax
movslq %eax, %rcx
movq -0x480(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x480(%rbp)
movq -0x450(%rbp), %rax
movslq -0x474(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq -0x450(%rbp), %rdx
movslq -0x474(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rdx
movl 0x4(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x4(%rdx)
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x488(%rbp), %rcx
movq %rcx, (%rax)
movq -0x480(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2bb38
jmp 0x2bc80
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2bb0f
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x2bdbb
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x450(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
movq -0x450(%rbp), %rax
movslq -0x2c(%rbp), %r8
imulq $0x18, %r8, %r8
addq %r8, %rax
movq 0x8(%rax), %r8
movq -0x450(%rbp), %rax
movslq -0x2c(%rbp), %r9
imulq $0x18, %r9, %r9
addq %r9, %rax
movq 0x10(%rax), %r9
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x29c00
movq %rax, %rdx
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x450(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
movq 0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq 0x10(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x2bdab
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movl 0x3c(%rax), %ecx
andl $0xffff7fff, %ecx       # imm = 0xFFFF7FFF
orl $0x8000, %ecx           # imm = 0x8000
movl %ecx, 0x3c(%rax)
movl -0x2c(%rbp), %edx
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movl 0x3c(%rax), %ecx
andl $0xff, %edx
shll $0x10, %edx
andl $0xff00ffff, %ecx       # imm = 0xFF00FFFF
orl %edx, %ecx
movl %ecx, 0x3c(%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2bd36
jmp 0x2bdad
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2bc95
movq -0x450(%rbp), %rax
addq $0x4a0, %rsp            # imm = 0x4A0
popq %rbp
retq
nopl (%rax,%rax)