// File: /workspace/github_cpp_makefile_star2_O3/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 0x66c57a2(%rip), %eax   # 0x66f9af0
testl %eax, %eax
je 0x343e1
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
addl %eax, %eax
movl %eax, 0x66c5797(%rip)   # 0x66f9b00
shlq $0x2, %rax
leaq (%rax,%rax,2), %rdi
callq 0x4400
movq %rax, 0x66c578b(%rip)   # 0x66f9b08
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa6ed
movl 0x66c575a(%rip), %eax   # 0x66f9af0
xorl %r12d, %r12d
movq 0x66c5768(%rip), %r14   # 0x66f9b08
movq 0x66c5751(%rip), %r15   # 0x66f9af8
testq %rax, %rax
je 0x343f7
leaq (,%rax,4), %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
movl 0x4(%r15,%rdx), %esi
movl %esi, (%r14,%rdx)
movl (%r15,%rdx), %esi
movl %esi, 0x4(%r14,%rdx)
movl 0x8(%r15,%rdx), %esi
movl %esi, 0x8(%r14,%rdx)
addq $0xc, %rdx
cmpq %rdx, %rcx
jne 0x343ba
jmp 0x343f9
movq $0x0, 0x66c570c(%rip) # 0x66f9af8
movl $0x0, 0x66c56fe(%rip)   # 0x66f9af4
retq
xorl %eax, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rdx
leaq (%r14,%rdx), %rdi
movq %r15, %rsi
callq 0x4240
movq %r15, %rdi
callq 0x4370
movq $0x0, 0x66c56d8(%rip) # 0x66f9af8
movl %r12d, 0x66c56cd(%rip)  # 0x66f9af4
movl %r12d, 0x66c56c2(%rip)  # 0x66f9af0
movl 0x66c56cc(%rip), %esi   # 0x66f9b00
leaq 0x98(%rip), %rcx        # 0x344d3
movl $0xc, %edx
movq %r14, %rdi
callq 0x4600
movl 0x66c56b2(%rip), %ecx   # 0x66f9b00
movl 0x66c56bc(%rip), %eax   # 0x66f9b10
addq %rcx, %rax
leaq (,%rax,4), %rcx
leaq (%rcx,%rcx,2), %rcx
cvtsi2sd %rcx, %xmm0
cmpq $0x15555, %rax          # imm = 0x15555
jbe 0x34481
mulsd 0x4498(%rip), %xmm0     # 0x38910
leaq 0xa9d4(%rip), %rdi      # 0x3ee53
jmp 0x3449f
cmpq $0x56, %rax
jb 0x34498
mulsd 0xa979(%rip), %xmm0     # 0x3ee08
leaq 0xa9d1(%rip), %rdi      # 0x3ee67
jmp 0x3449f
leaq 0xa9dc(%rip), %rdi      # 0x3ee7b
movq %rbx, %rsi
movb $0x1, %al
callq 0x9c46
movl 0x66c5665(%rip), %edx   # 0x66f9b14
movl 0x66c564b(%rip), %ecx   # 0x66f9b00
leaq 0xa9d3(%rip), %rsi      # 0x3ee8f
movl $0x3, %edi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xa446