// File: FreeSlave[P]vhlt/hlrad/sparse.cpp
// Function: SetVisColumn(int, bool*)
static void		SetVisColumn (int patchnum, bool uncompressedcolumn[MAX_SPARSE_VISMATRIX_PATCHES])
{
	sparse_column_t *column;
	int mbegin;
	int m;
	int i;
	unsigned int bits;
	
	column = &s_vismatrix[patchnum];
	if (column->count || column->row)
	{
		Error ("SetVisColumn: column has been set");
	}

	for (mbegin = 0; mbegin < g_num_patches; mbegin += 8)
	{
		bits = 0;
		for (m = mbegin; m < mbegin + 8; m++)
		{
			if (m >= g_num_patches)
			{
				break;
			}
			if (uncompressedcolumn[m]) // visible
			{
				if (m < patchnum)
				{
					Error ("SetVisColumn: invalid parameter: m < patchnum");
				}
				bits |= (1 << (m - mbegin));
			}
		}
		if (bits)
		{
			column->count++;
		}
	}

	if (!column->count)
	{
		return;
	}
	column->row = (sparse_row_t *)malloc (column->count * sizeof (sparse_row_t));
	hlassume (column->row != NULL, assume_NoMemory);
	
	i = 0;
	for (mbegin = 0; mbegin < g_num_patches; mbegin += 8)
	{
		bits = 0;
		for (m = mbegin; m < mbegin + 8; m++)
		{
			if (m >= g_num_patches)
			{
				break;
			}
			if (uncompressedcolumn[m]) // visible
			{
				bits |= (1 << (m - mbegin));
			}
		}
		if (bits)
		{
			column->row[i].offset = mbegin / 8;
			column->row[i].values = bits;
			i++;
		}
	}
	if (i != column->count)
	{
		Error ("SetVisColumn: internal error");
	}
}

// Assembly:
subq $0x28, %rsp
movl %edi, 0x24(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x66cda8c(%rip), %rax   # 0x672fae0
movslq 0x24(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x6207b
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
je 0x62089
leaq 0xfa8d(%rip), %rdi      # 0x71b0f
movb $0x0, %al
callq 0xb580
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
leaq 0x540b96c(%rip), %rcx   # 0x546da08
cmpl (%rcx), %eax
jae 0x62145
movl $0x0, (%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
addl $0x8, %ecx
cmpl %ecx, %eax
jge 0x6211f
movl 0x8(%rsp), %eax
leaq 0x540b93b(%rip), %rcx   # 0x546da08
cmpl (%rcx), %eax
jb 0x620d3
jmp 0x6211f
movq 0x18(%rsp), %rax
movslq 0x8(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x62110
movl 0x8(%rsp), %eax
cmpl 0x24(%rsp), %eax
jge 0x620fb
leaq 0xfa3d(%rip), %rdi      # 0x71b31
movb $0x0, %al
callq 0xb580
movl 0x8(%rsp), %ecx
subl 0xc(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
orl (%rsp), %eax
movl %eax, (%rsp)
jmp 0x62112
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x620b3
cmpl $0x0, (%rsp)
je 0x62133
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x62135
movl 0xc(%rsp), %eax
addl $0x8, %eax
movl %eax, 0xc(%rsp)
jmp 0x62091
movq 0x10(%rsp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x62155
jmp 0x622a9
movq 0x10(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x4430
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
setne %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbf00
movl $0x0, 0x4(%rsp)
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
leaq 0x540b85f(%rip), %rcx   # 0x546da08
cmpl (%rcx), %eax
jae 0x6228d
movl $0x0, (%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
addl $0x8, %ecx
cmpl %ecx, %eax
jge 0x62214
movl 0x8(%rsp), %eax
leaq 0x540b82e(%rip), %rcx   # 0x546da08
cmpl (%rcx), %eax
jb 0x621e0
jmp 0x62214
movq 0x18(%rsp), %rax
movslq 0x8(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x62205
movl 0x8(%rsp), %ecx
subl 0xc(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
orl (%rsp), %eax
movl %eax, (%rsp)
jmp 0x62207
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x621c0
cmpl $0x0, (%rsp)
je 0x6227b
movl 0xc(%rsp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %esi
movq 0x10(%rsp), %rax
movq (%rax), %rax
movslq 0x4(%rsp), %rcx
movl (%rax,%rcx,4), %edx
andl $0xffffff, %esi         # imm = 0xFFFFFF
andl $0xff000000, %edx       # imm = 0xFF000000
orl %esi, %edx
movl %edx, (%rax,%rcx,4)
movl (%rsp), %esi
movq 0x10(%rsp), %rax
movq (%rax), %rax
movslq 0x4(%rsp), %rcx
movl (%rax,%rcx,4), %edx
andl $0xff, %esi
shll $0x18, %esi
andl $0xffffff, %edx         # imm = 0xFFFFFF
orl %esi, %edx
movl %edx, (%rax,%rcx,4)
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x6227d
movl 0xc(%rsp), %eax
addl $0x8, %eax
movl %eax, 0xc(%rsp)
jmp 0x6219e
movl 0x4(%rsp), %eax
movq 0x10(%rsp), %rcx
cmpl 0x8(%rcx), %eax
je 0x622a9
leaq 0xf8bd(%rip), %rdi      # 0x71b5f
movb $0x0, %al
callq 0xb580
addq $0x28, %rsp
retq
nop