// File: /workspace/github_c_makefile_star2_O0/lh3[P]bgt/pbwt.c
// Function: pbs_dec
void pbs_dec(int m, int r, pbs_dat_t *d, const uint8_t *u, uint8_t *a) // IMPORTANT: d MUST BE sorted by d[i].r
{
	const uint8_t *q;
	int n1;
	for (q = u, n1 = 0; *q; ++q) // count the number of 1 bits
		if (*q&1) n1 += pbr_tbl[*q>>1];
	if (n1 == 0) { // all zero
		memset(a, 0, r);
	} else if (n1 == m) { // all one
		memset(a, 1, r);
	} else {
		pbs_dat_t *p = d, *end = d + r, *d1, *x[2];
		int c[2], acc[2];
		acc[0] = 0, acc[1] = m - n1; // accumulative counts
		c[0] = c[1] = 0; // running marginal counts
		d1 = (pbs_dat_t*)malloc(r * sizeof(pbs_dat_t));
		x[0] = d, x[1] = d1;
		memset(a, 0, r);
		for (q = u; p != end && *q; ++q) {
			int l = pbr_tbl[*q>>1], b = *q&1, s = c[0] + c[1];
			if (s <= p->r && p->r < s + l) {
				int w = acc[b] + c[b] - s;
				pbs_dat_t *p0 = p;
				do {
					p->r += w; // this is a faster version of: "p->r = acc[b] + c[b] + (p->r - s);"
					++p;
				} while (p != end && s <= p->r && p->r < s + l);
				if (b == 0) {
					if (x[0] != p0) memmove(x[0], p0, (p - p0) * sizeof(pbs_dat_t));
					x[0] += p - p0;
				} else {
					memcpy(x[1], p0, (p - p0) * sizeof(pbs_dat_t));
					x[1] += p - p0;
					while (p0 < p) a[p0->i] = 1, ++p0;
				}
			}
			c[b] += l;
		}
		memcpy(x[0], d1, (x[1] - d1) * sizeof(pbs_dat_t));
		free(d1);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x28(%rbp), %rax
cmpb $0x0, (%rax)
je 0x1b0a0
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1b090
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x13359(%rip), %rax     # 0x2e3e0
movl (%rax,%rcx,4), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x1b092
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1b05c
cmpl $0x0, -0x2c(%rbp)
jne 0x1b0ba
movq -0x20(%rbp), %rdi
movslq -0x8(%rbp), %rdx
xorl %esi, %esi
callq 0x21e0
jmp 0x1b36d
movl -0x2c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jne 0x1b0d9
movq -0x20(%rbp), %rdi
movslq -0x8(%rbp), %rdx
movl $0x1, %esi
callq 0x21e0
jmp 0x1b36b
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movslq -0x8(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x4(%rbp), %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movslq -0x8(%rbp), %rdi
shlq $0x3, %rdi
callq 0x22f0
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x8(%rbp), %rdx
xorl %esi, %esi
callq 0x21e0
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x40(%rbp), %rcx
movb %al, -0x89(%rbp)
je 0x1b16f
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x1b17e
jmp 0x1b342
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x1324f(%rip), %rax     # 0x2e3e0
movl (%rax,%rcx,4), %eax
movl %eax, -0x74(%rbp)
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
andl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x68(%rbp), %eax
addl -0x64(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
ja 0x1b322
movq -0x38(%rbp), %rax
movl (%rax), %eax
movl -0x7c(%rbp), %ecx
addl -0x74(%rbp), %ecx
cmpl %ecx, %eax
jae 0x1b322
movslq -0x78(%rbp), %rax
movl -0x70(%rbp,%rax,4), %eax
movslq -0x78(%rbp), %rcx
addl -0x68(%rbp,%rcx,4), %eax
subl -0x7c(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x80(%rbp), %ecx
movq -0x38(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x40(%rbp), %rcx
movb %al, -0x8a(%rbp)
je 0x1b244
movl -0x7c(%rbp), %ecx
movq -0x38(%rbp), %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, -0x8a(%rbp)
ja 0x1b244
movq -0x38(%rbp), %rax
movl (%rax), %eax
movl -0x7c(%rbp), %ecx
addl -0x74(%rbp), %ecx
cmpl %ecx, %eax
setb %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
testb $0x1, %al
jne 0x1b1f1
cmpl $0x0, -0x78(%rbp)
jne 0x1b2a7
movq -0x60(%rbp), %rax
cmpq -0x88(%rbp), %rax
je 0x1b287
movq -0x60(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x88(%rbp), %rax
subq %rax, %rdx
sarq $0x3, %rdx
shlq $0x3, %rdx
callq 0x2370
movq -0x38(%rbp), %rax
movq -0x88(%rbp), %rcx
subq %rcx, %rax
sarq $0x3, %rax
shlq $0x3, %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x1b320
movq -0x58(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x88(%rbp), %rax
subq %rax, %rdx
sarq $0x3, %rdx
shlq $0x3, %rdx
callq 0x2290
movq -0x38(%rbp), %rax
movq -0x88(%rbp), %rcx
subq %rcx, %rax
sarq $0x3, %rax
shlq $0x3, %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x1b31e
movq -0x20(%rbp), %rax
movq -0x88(%rbp), %rcx
movl 0x4(%rcx), %ecx
movb $0x1, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x88(%rbp)
jmp 0x1b2eb
jmp 0x1b320
jmp 0x1b322
movl -0x74(%rbp), %ecx
movslq -0x78(%rbp), %rax
addl -0x68(%rbp,%rax,4), %ecx
movl %ecx, -0x68(%rbp,%rax,4)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1b14a
movq -0x60(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x48(%rbp), %rax
subq %rax, %rdx
sarq $0x3, %rdx
shlq $0x3, %rdx
callq 0x2290
movq -0x48(%rbp), %rdi
callq 0x2040
jmp 0x1b36d
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)