// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlrad/sparse.cpp
// Function: MakeScalesSparseVismatrix()
void            MakeScalesSparseVismatrix()
{
    char            transferfile[_MAX_PATH];

    hlassume(g_num_patches < MAX_SPARSE_VISMATRIX_PATCHES, assume_MAX_PATCHES);

#ifdef ZHLT_DEFAULTEXTENSION_FIX
	safe_snprintf(transferfile, _MAX_PATH, "%s.inc", g_Mapname);
#else
    safe_strncpy(transferfile, g_source, _MAX_PATH);
    StripExtension(transferfile);
    DefaultExtension(transferfile, ".inc");
#endif

    if (!g_incremental || !readtransfers(transferfile, g_num_patches))
    {
        // determine visibility between g_patches
        BuildVisMatrix();
        DumpVismatrixInfo();
        g_CheckVisBit = CheckVisBitSparse;

#ifdef HLRAD_HULLU
	#ifdef HLRAD_TRANSPARENCY_CPP
        CreateFinalTransparencyArrays("custom shadow array");
	#else
        if((s_max_transparency_count*sizeof(transparency_t))>=(1024 * 1024))
        	Log("%-20s: %5.1f megs\n", "custom shadow array", (s_max_transparency_count*sizeof(transparency_t)) / (1024 * 1024.0));
        else if(s_transparency_count)
        	Log("%-20s: %5.1f kilos\n", "custom shadow array", (s_max_transparency_count*sizeof(transparency_t)) / 1024.0);
	#endif
#endif
        
#ifndef HLRAD_HULLU
        NamedRunThreadsOn(g_num_patches, g_estimate, MakeScales);
#else
	if(g_rgb_transfers)
		{NamedRunThreadsOn(g_num_patches, g_estimate, MakeRGBScales);}
	else
		{NamedRunThreadsOn(g_num_patches, g_estimate, MakeScales);}
#endif
        FreeVisMatrix();
#ifdef HLRAD_HULLU
	#ifdef HLRAD_TRANSPARENCY_CPP
        FreeTransparencyArrays();
	#endif
#endif

#ifndef HLRAD_NOSWAP
        // invert the transfers for gather vs scatter
#ifndef HLRAD_HULLU
        NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapTransfers);
#else
	if(g_rgb_transfers)
		{NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapRGBTransfers);}
	else
		{NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapTransfers);}
#endif
#endif /*HLRAD_NOSWAP*/
        if (g_incremental)
        {
            writetransfers(transferfile, g_num_patches);
        }
        else
        {
            _unlink(transferfile);
        }
        // release visibility matrix
        DumpTransfersMemoryUsage();
#ifdef HLRAD_OPAQUE_STYLE_BOUNCE
		CreateFinalStyleArrays ("dynamic shadow array");
#endif
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1000, %rsp           # imm = 0x1000
leaq 0x54064f6(%rip), %r14   # 0x54379e8
xorl %edi, %edi
cmpl $0xffff0, (%r14)        # imm = 0xFFFF0
setb %dil
movl $0x1b, %esi
callq 0xa6ed
leaq 0x74ee(%rip), %rdx      # 0x389fe
leaq 0x15e39(%rip), %rcx     # 0x47350
movq %rsp, %rdi
movl $0x1000, %esi           # imm = 0x1000
xorl %eax, %eax
callq 0x8817
leaq 0x54c84d3(%rip), %r15   # 0x54f9a00
cmpb $0x1, (%r15)
jne 0x31546
movl (%r14), %esi
movq %rsp, %rdi
callq 0x33e18
testb %al, %al
jne 0x31728
movl (%r14), %edi
shlq $0x4, %rdi
callq 0x491c
movq %rax, 0x66c8567(%rip)   # 0x66f9ac0
testq %rax, %rax
jne 0x31584
leaq 0xd56f(%rip), %rdi      # 0x3ead4
xorl %eax, %eax
callq 0x9c46
xorl %edi, %edi
cmpq $0x0, 0x66c854a(%rip)   # 0x66f9ac0
setne %dil
movl $0x1, %esi
callq 0xa6ed
leaq 0xd566(%rip), %rdi      # 0x3eaf1
callq 0x9d92
leaq 0xa128(%rip), %rdi      # 0x3b6bf
movq %rax, %rsi
xorl %eax, %eax
callq 0x9c46
leaq 0x16ec8(%rip), %rax     # 0x48470
movl 0x34(%rax), %edi
leaq 0x16e72(%rip), %r12     # 0x48424
movzbl (%r12), %esi
leaq 0x2a6(%rip), %rdx       # 0x31864
callq 0xb356
movl (%r14), %ecx
movq %rcx, %rax
shlq $0x4, %rax
testq %rcx, %rcx
je 0x315ee
movq 0x66c84e7(%rip), %rcx   # 0x66f9ac0
leaq (%rcx,%rax), %rdx
movslq 0x8(%rcx), %rsi
leaq (%rax,%rsi,4), %rax
addq $0x10, %rcx
cmpq %rdx, %rcx
jb 0x315dd
movq %rax, %xmm1
punpckldq 0xd4a5(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xd4ad(%rip), %xmm1     # 0x3eab0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x72f9(%rip), %xmm0     # 0x38910
leaq 0xd56e(%rip), %rdi      # 0x3eb8c
leaq 0xd57a(%rip), %rsi      # 0x3eb9f
movb $0x1, %al
callq 0x9c46
leaq 0x105(%rip), %rax       # 0x31738
leaq 0x66c84fe(%rip), %rcx   # 0x66f9b38
movq %rax, (%rcx)
leaq 0xd47c(%rip), %rdi      # 0x3eac0
callq 0x34348
leaq 0x54c83d9(%rip), %rax   # 0x54f9a29
leaq 0xa4e5(%rip), %rcx      # 0x3bb3c
leaq 0xa4ed(%rip), %rdi      # 0x3bb4b
cmpb $0x0, (%rax)
cmovneq %rcx, %rdi
leaq 0x3a77(%rip), %rbx      # 0x350e3
cmovneq 0x1590c(%rip), %rbx     # 0x46f80
callq 0x9d92
leaq 0xa03f(%rip), %rdi      # 0x3b6bf
movq %rax, %rsi
xorl %eax, %eax
callq 0x9c46
movl (%r14), %edi
movzbl (%r12), %esi
movq %rbx, %rdx
callq 0xb356
movq 0x66c841f(%rip), %rbx   # 0x66f9ac0
testq %rbx, %rbx
je 0x316f7
movl (%r14), %eax
testl %eax, %eax
je 0x316d0
xorl %ebp, %ebp
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x316bf
callq 0x4370
movl (%r14), %eax
incl %ebp
addq $0x10, %rbx
cmpl %eax, %ebp
jb 0x316af
movq 0x66c83f0(%rip), %rbx   # 0x66f9ac0
movq %rbx, %rdi
callq 0x4941
testb %al, %al
je 0x316e9
movq $0x0, 0x66c83d9(%rip) # 0x66f9ac0
jmp 0x316f7
leaq 0xd505(%rip), %rdi      # 0x3ebf5
xorl %eax, %eax
callq 0xa2a6
callq 0x344e0
cmpb $0x1, (%r15)
jne 0x3170f
movl (%r14), %esi
movq %rsp, %rdi
callq 0x33c7c
jmp 0x31717
movq %rsp, %rdi
callq 0x4160
callq 0x36392
leaq 0xa434(%rip), %rdi      # 0x3bb57
callq 0x346ee
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq