// File: /workspace/github_c_makefile_star2_O1/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), %r14
cmpl $-0x1, %esi
je 0x15f74
movq %rdx, %rbx
movl %esi, %ebp
testl %esi, %esi
setle %al
testq %rcx, %rcx
sete %dl
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testb %dl, %al
jne 0x16093
testq %rcx, %rcx
je 0x15faa
leaq 0x14(%rsp), %r15
movq %rcx, %rdi
movq %r15, %rsi
callq 0x1b574
movq %rax, %rdi
cmpl $0x0, (%r15)
setne %al
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x15f64
callq 0x1ced4
xorl %edi, %edi
testq %rdi, %rdi
jne 0x15fac
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x16093
movl 0x20(%r14), %r12d
testl %r12d, %r12d
jle 0x15f9a
movq (%rsp), %rax
movq 0x50(%rax), %rax
xorl %ecx, %ecx
movl $0x1, (%rax,%rcx,4)
incq %rcx
movslq 0x20(%r14), %r12
cmpq %r12, %rcx
jl 0x15f87
movq (%rsp), %rax
movl $0x1, 0x38(%rax)
jmp 0x16093
xorl %edi, %edi
movq %rdi, 0x8(%rsp)
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x5e1f
movq %rax, %r13
testl %ebp, %ebp
jle 0x15fe2
movq %rbx, %r15
movl %ebp, %ebx
xorl %ebp, %ebp
movq (%r15,%rbp,8), %rsi
movq %r13, %rdi
leaq 0x10(%rsp), %rdx
callq 0x61f9
incq %rbp
cmpq %rbp, %rbx
jne 0x15fc9
cmpl $0x0, 0x20(%r14)
jle 0x1607a
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r12d, %r12d
movl $0x0, %ebx
movq 0x8(%rsp), %rdx
testq %rdx, %rdx
je 0x16015
movq %r14, %rdi
movl %ebp, %esi
callq 0xa504
xorl %ebx, %ebx
testl %eax, %eax
setne %bl
movq 0x28(%r14), %rax
movq (%rax,%r15), %rsi
movq %r13, %rdi
callq 0x5e97
cmpl (%r13), %eax
je 0x1604f
movq (%rsp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%rbp,4), %eax
testl %eax, %eax
jns 0x16044
movq (%rsp), %rax
movl 0x3c(%rax), %eax
cmpl $0x2, %eax
movl $0x1, %eax
cmovbl %eax, %ebx
testl %ebx, %ebx
je 0x16066
incl %r12d
movq (%rsp), %rcx
movl 0x38(%rcx), %eax
incl %eax
movq 0x50(%rcx), %rcx
movl %eax, (%rcx,%rbp,4)
incq %rbp
movslq 0x20(%r14), %rax
addq $0x18, %r15
cmpq %rax, %rbp
jl 0x15ff5
movq %r13, %rdi
callq 0x5e2e
movq 0x8(%rsp), %rdi
callq 0x1ced4
movq (%rsp), %rax
incl 0x38(%rax)
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq