// File: /workspace/github_c_makefile_star2_O3/lh3[P]bgt/bgt.c
// Function: bgt_add_group_core
int bgt_add_group_core(bgt_t *bgt, int n, char *const* samples, const char *expr)
{
	int i, size = 0;
	const fmf_t *f = bgt->f->f;

	if (n == BGT_SET_ALL_SAMPLES) {
		for (i = 0; i < f->n_rows; ++i)
			bgt->gtag[i] = 1;
		size = f->n_rows;
		bgt->n_groups = 1;
	} else if (n > 0 || expr != 0) {
		int err, absent;
		khash_t(s2i) *h;
		kexpr_t *ke = 0;

		if (expr) {
			ke = ke_parse(expr, &err);
			if (err && ke) {
				ke_destroy(ke);
				ke = 0;
			}
			if (ke == 0) return -1;
		}
		h = kh_init(s2i);
		for (i = 0; i < n; ++i)
			kh_put(s2i, h, samples[i], &absent);
		for (i = 0, size = 0; i < f->n_rows; ++i) {
			int to_add = 0;
			if (ke && fmf_test(f, i, ke)) to_add = 1;
			if (kh_get(s2i, h, f->rows[i].name) != kh_end(h)) {
				int mgs = bgt->f->mgs[i] >= 0? bgt->f->mgs[i] : bgt->mgs_def;
				if (mgs == 1 || mgs == 0) to_add = 1;
			}
			if (to_add) ++size, bgt->gtag[i] = bgt->n_groups + 1;
		}
		kh_destroy(s2i, h);
		ke_destroy(ke);
		++bgt->n_groups;
	} else return -1;
	return size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, (%rsp)
movq (%rdi), %rax
movq 0x8(%rax), %r15
cmpl $-0x1, %esi
je 0x1659b
movq %rdx, %rbx
movl %esi, %ebp
testl %esi, %esi
setle %al
testq %rcx, %rcx
sete %dl
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testb %dl, %al
jne 0x166c9
testq %rcx, %rcx
je 0x165d1
leaq 0x14(%rsp), %r12
movq %rcx, %rdi
movq %r12, %rsi
callq 0x1bb84
movq %rax, %rdi
cmpl $0x0, (%r12)
setne %al
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x165d5
callq 0x1d0fd
jmp 0x166c9
movl 0x20(%r15), %r14d
testl %r14d, %r14d
jle 0x165c1
movq (%rsp), %rax
movq 0x50(%rax), %rax
xorl %ecx, %ecx
movl $0x1, (%rax,%rcx,4)
incq %rcx
movslq 0x20(%r15), %r14
cmpq %r14, %rcx
jl 0x165ae
movq (%rsp), %rax
movl $0x1, 0x38(%rax)
jmp 0x166c9
xorl %edi, %edi
jmp 0x165de
testq %rdi, %rdi
je 0x166c9
movq %rdi, 0x8(%rsp)
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x5f54
movq %rax, %r13
testl %ebp, %ebp
jle 0x16614
movq %rbx, %r12
movl %ebp, %ebx
xorl %ebp, %ebp
movq (%r12,%rbp,8), %rsi
movq %r13, %rdi
leaq 0x10(%rsp), %rdx
callq 0x6320
incq %rbp
cmpq %rbp, %rbx
jne 0x165fb
cmpl $0x0, 0x20(%r15)
movq 0x8(%rsp), %rbx
jle 0x166b2
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %r14d, %r14d
testq %rbx, %rbx
je 0x16645
movq %r15, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0xa785
testl %eax, %eax
sete %bl
jmp 0x16647
movb $0x1, %bl
movq 0x28(%r15), %rax
movq (%rax,%r12), %rsi
movq %r13, %rdi
callq 0x5fcc
cmpl (%r13), %eax
jne 0x16663
testb %bl, %bl
je 0x16686
jmp 0x16699
movq (%rsp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%rbp,4), %eax
testl %eax, %eax
jns 0x1667c
movq (%rsp), %rax
movl 0x3c(%rax), %eax
cmpl $0x2, %eax
setae %al
testb %bl, %al
jne 0x16699
incl %r14d
movq (%rsp), %rcx
movl 0x38(%rcx), %eax
incl %eax
movq 0x50(%rcx), %rcx
movl %eax, (%rcx,%rbp,4)
movq 0x8(%rsp), %rbx
incq %rbp
movslq 0x20(%r15), %rax
addq $0x18, %r12
cmpq %rax, %rbp
jl 0x1662c
movq %r13, %rdi
callq 0x5f63
movq %rbx, %rdi
callq 0x1d0fd
movq (%rsp), %rax
incl 0x38(%rax)
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq