// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/hlrad/transparency.cpp
// Function: CreateFinalTransparencyArrays(char const*)
void	CreateFinalTransparencyArrays(const char *print_name)
{
	if( s_raw_count == 0 )
	{
		s_raw_list = NULL;
		s_raw_count = s_max_raw_count = 0;
		return;
	}

	//double sized (faster find function for sorted list)
	s_sorted_count = s_raw_count * 2;
	s_sorted_list = (transList_t *)malloc( sizeof(transList_t) * s_sorted_count );
#ifdef HLRAD_HLASSUMENOMEMORY
	hlassume (s_sorted_list != NULL, assume_NoMemory);
#endif
	
	//First half have p1>p2
	for( unsigned int i = 0; i < s_raw_count; i++ )
	{
		s_sorted_list[i].p1 		= s_raw_list[i].p2;
		s_sorted_list[i].p2 		= s_raw_list[i].p1;
		s_sorted_list[i].data_index	= s_raw_list[i].data_index;
	}
	//Second half have p1<p2
	memcpy( &s_sorted_list[s_raw_count], s_raw_list, sizeof(transList_t) * s_raw_count );
	
	//free old array
	free( s_raw_list );
	s_raw_list = NULL;
	s_raw_count = s_max_raw_count = 0;
	
	//need to sorted for fast search function
	qsort( s_sorted_list, s_sorted_count, sizeof(transList_t), SortList );
	
#ifdef ZHLT_64BIT_FIX
	size_t size = s_sorted_count * sizeof(transList_t) + s_max_trans_count * sizeof(vec3_t);
#else
	unsigned size = s_sorted_count * sizeof(transList_t) + s_max_trans_count * sizeof(vec3_t);
#endif
	if ( size > 1024 * 1024 )
        	Log("%-20s: %5.1f megs \n", print_name, (double)size / (1024.0 * 1024.0));
        else if ( size > 1024 )
        	Log("%-20s: %5.1f kilos\n", print_name, (double)size / 1024.0);
        else
        	Log("%-20s: %5.1f bytes\n", print_name, (double)size); //--vluzacn
	Developer (DEVELOPER_LEVEL_MESSAGE, "\ts_trans_count=%d\ts_sorted_count=%d\n", s_trans_count, s_sorted_count); //--vluzacn
        	
#if 0
        int total_1 = 0;
        for(int i = 0; i < s_sorted_count; i++)
        {
        	Log("a: %7i b: %7i di: %10i r: %3.1f g: %3.1f b: %3.1f\n", 
        		s_sorted_list[i].p1, 
        		s_sorted_list[i].p2, 
        		s_sorted_list[i].data_index,
        		s_trans_list[s_sorted_list[i].data_index][0],
        		s_trans_list[s_sorted_list[i].data_index][1],
        		s_trans_list[s_sorted_list[i].data_index][2]
        	);
        	total_1++;
        }
        
        vec3_t rgb;
        int total_2 = 0;
        for(unsigned int next_index = 0, a = 0; a < g_num_patches; a++)
        {
        	for(unsigned int b = 0; b < g_num_patches; b++)
        	{
        		GetTransparency(a, b, rgb, next_index);
        		
        		if(!VectorCompare(rgb,vec3_one))
        		{
        			Log("a: %7i b: %7i ni: %10i r: %3.1f g: %3.1f b: %3.1f\n", 
        				a, 
        				b, 
        				next_index,
        				rgb[0],
        				rgb[1],
        				rgb[2]
        			);
        			total_2++;
        		}
        	}
        }
        
        Log("total1: %i\ntotal2: %i\n",total_1,total_2);
#endif
}

// Assembly:
movl 0x66c56ba(%rip), %eax   # 0x66faaf0
testl %eax, %eax
je 0x35557
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
addl %eax, %eax
movl %eax, 0x66c56b2(%rip)   # 0x66fab00
shlq $0x2, %rax
leaq (%rax,%rax,2), %rdi
callq 0x4410
movq %rax, 0x66c56a6(%rip)   # 0x66fab08
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa7c9
movl 0x66c5675(%rip), %eax   # 0x66faaf0
testq %rax, %rax
je 0x354c1
movq 0x66c5671(%rip), %rcx   # 0x66faaf8
movq 0x66c567a(%rip), %rdx   # 0x66fab08
leaq (,%rax,4), %rsi
leaq (%rsi,%rsi,2), %rsi
xorl %edi, %edi
movl 0x4(%rcx,%rdi), %r8d
movl %r8d, (%rdx,%rdi)
movl (%rcx,%rdi), %r8d
movl %r8d, 0x4(%rdx,%rdi)
movl 0x8(%rcx,%rdi), %r8d
movl %r8d, 0x8(%rdx,%rdi)
addq $0xc, %rdi
cmpq %rdi, %rsi
jne 0x3549c
movq 0x66c5640(%rip), %r14   # 0x66fab08
shlq $0x2, %rax
leaq (%rax,%rax,2), %rdx
leaq (%r14,%rdx), %rdi
movq 0x66c561d(%rip), %r15   # 0x66faaf8
movq %r15, %rsi
callq 0x4250
movq %r15, %rdi
callq 0x4380
movq $0x0, 0x66c5602(%rip) # 0x66faaf8
xorl %eax, %eax
movl %eax, 0x66c55f6(%rip)   # 0x66faaf4
movl %eax, 0x66c55ec(%rip)   # 0x66faaf0
movl 0x66c55f6(%rip), %esi   # 0x66fab00
leaq 0xac(%rip), %rcx        # 0x355bd
movl $0xc, %edx
movq %r14, %rdi
callq 0x4610
movl 0x66c55dc(%rip), %ecx   # 0x66fab00
movl 0x66c55e6(%rip), %eax   # 0x66fab10
addq %rcx, %rax
leaq (,%rax,4), %rcx
leaq (%rcx,%rcx,2), %rcx
cvtsi2sd %rcx, %xmm0
cmpq $0x15555, %rax          # imm = 0x15555
jbe 0x35571
mulsd 0x43c2(%rip), %xmm0     # 0x39910
leaq 0xa97e(%rip), %rdi      # 0x3fed3
jmp 0x3558f
movq $0x0, 0x66c5596(%rip) # 0x66faaf8
xorl %eax, %eax
movl %eax, 0x66c558a(%rip)   # 0x66faaf4
movl %eax, 0x66c5580(%rip)   # 0x66faaf0
retq
cmpq $0x56, %rax
jb 0x35588
mulsd 0xa909(%rip), %xmm0     # 0x3fe88
leaq 0xa961(%rip), %rdi      # 0x3fee7
jmp 0x3558f
leaq 0xa96c(%rip), %rdi      # 0x3fefb
movq %rbx, %rsi
movb $0x1, %al
callq 0x9d2e
movl 0x66c5575(%rip), %edx   # 0x66fab14
movl 0x66c555b(%rip), %ecx   # 0x66fab00
leaq 0xa963(%rip), %rsi      # 0x3ff0f
movl $0x3, %edi
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0xa52e