// File: FreeSlave[P]vhlt/hlrad/qrad.cpp
// Function: BounceLight()
static void     BounceLight()
{
    unsigned        i;
    char            name[64];

#ifdef ZHLT_TEXLIGHT
    unsigned        j; //LRC
#endif

    for (i = 0; i < g_num_patches; i++)
    {
#ifdef HLRAD_AUTOCORING
		patch_t *patch = &g_patches[i];
		for (j = 0; j < MAXLIGHTMAPS && patch->totalstyle[j] != 255; j++)
		{
			VectorCopy (patch->totallight[j], emitlight[i][j]);
#ifdef ZHLT_XASH
			VectorCopy (patch->totallight_direction[j], emitlight_direction[i][j]);
#endif
		}
#else
#ifdef ZHLT_TEXLIGHT
        //LRC
		for (j = 0; j < MAXLIGHTMAPS && g_patches[i].totalstyle[j] != 255; j++)
		{
	#ifdef HLRAD_TRANSFERDATA_COMPRESS
	        VectorCopy(g_patches[i].totallight[j], emitlight[i][j]);
	#else
	        VectorScale(g_patches[i].totallight[j], TRANSFER_SCALE, emitlight[i][j]);
	#endif
		}
#else
	#ifdef HLRAD_TRANSFERDATA_COMPRESS
        VectorCopy(g_patches[i].totallight, emitlight[i]);
	#else
        VectorScale(g_patches[i].totallight, TRANSFER_SCALE, emitlight[i]);
	#endif
#endif
#endif
    }

    for (i = 0; i < g_numbounce; i++)
    {
#ifdef ZHLT_CONSOLE
        Log("Bounce %u ", i + 1);
#else
        printf("Bounce %u ", i + 1);
#endif
#ifdef HLRAD_HULLU
	if(g_rgb_transfers)
	       	{NamedRunThreadsOn(g_num_patches, g_estimate, GatherRGBLight);}
        else
        	{NamedRunThreadsOn(g_num_patches, g_estimate, GatherLight);}
#else
	NamedRunThreadsOn(g_num_patches, g_estimate, GatherLight);
#endif
        CollectLight();

        if (g_dumppatches)
        {
            sprintf(name, "bounce%u.txt", i);
            WriteWorld(name);
        }
    }
#ifdef HLRAD_AUTOCORING
	for (i = 0; i < g_num_patches; i++)
	{
		patch_t *patch = &g_patches[i];
		for (j = 0; j < MAXLIGHTMAPS && patch->totalstyle[j] != 255; j++)
		{
			VectorCopy (emitlight[i][j], patch->totallight[j]);
#ifdef ZHLT_XASH
			VectorCopy (emitlight_direction[i][j], patch->totallight_direction[j]);
#endif
		}
	}
#endif
}

// Assembly:
subq $0x68, %rsp
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0x5418a72(%rip), %eax   # 0x546da08
jae 0x550cc
movq 0x5398a5d(%rip), %rax   # 0x53eda00
movl 0x64(%rsp), %ecx
imulq $0x138, %rcx, %rcx      # imm = 0x138
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movl $0x0, 0x1c(%rsp)
xorl %eax, %eax
cmpl $0x4, 0x1c(%rsp)
movb %al, 0x7(%rsp)
jae 0x54fe8
movq 0x10(%rsp), %rax
movl 0x1c(%rsp), %ecx
movzbl 0x88(%rax,%rcx), %eax
cmpl $0xff, %eax
setne %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x54ff5
jmp 0x550ba
movq 0x10(%rsp), %rax
addq $0x90, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss (%rax), %xmm0
movq 0x551aba2(%rip), %rax   # 0x556fbb8
movl 0x64(%rsp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss %xmm0, (%rax)
movq 0x10(%rsp), %rax
addq $0x90, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss 0x4(%rax), %xmm0
movq 0x551ab66(%rip), %rax   # 0x556fbb8
movl 0x64(%rsp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
movq 0x10(%rsp), %rax
addq $0x90, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss 0x8(%rax), %xmm0
movq 0x551ab29(%rip), %rax   # 0x556fbb8
movl 0x64(%rsp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x54fbe
jmp 0x550bc
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x54f8c
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0x292f6(%rip), %eax     # 0x7e3d4
jae 0x551b9
movl 0x64(%rsp), %esi
addl $0x1, %esi
leaq 0x1c6fa(%rip), %rdi     # 0x717ec
movb $0x0, %al
callq 0xb0d0
testb $0x1, 0x54da949(%rip)   # 0x552fa49
je 0x5513e
leaq 0x1c6ee(%rip), %rdi     # 0x717f7
callq 0xb2f0
movq %rax, %rsi
leaq 0x19585(%rip), %rdi     # 0x6e69d
movb $0x0, %al
callq 0xb0d0
movl 0x54188e3(%rip), %edi   # 0x546da08
movb 0x29309(%rip), %al      # 0x7e434
leaq 0x425e(%rip), %rdx      # 0x59390
andb $0x1, %al
movzbl %al, %esi
callq 0xd2a0
jmp 0x55178
leaq 0x1c6c2(%rip), %rdi     # 0x71807
callq 0xb2f0
movq %rax, %rsi
leaq 0x19549(%rip), %rdi     # 0x6e69d
movb $0x0, %al
callq 0xb0d0
movl 0x54188a7(%rip), %edi   # 0x546da08
movb 0x292cd(%rip), %al      # 0x7e434
leaq 0x50e2(%rip), %rdx      # 0x5a250
andb $0x1, %al
movzbl %al, %esi
callq 0xd2a0
callq 0x5b0f0
testb $0x1, 0x551aa2c(%rip)   # 0x556fbb0
je 0x551a7
leaq 0x20(%rsp), %rdi
movl 0x64(%rsp), %edx
leaq 0x1c67e(%rip), %rsi     # 0x71814
movb $0x0, %al
callq 0x40a0
leaq 0x20(%rsp), %rdi
callq 0x5b4f0
jmp 0x551a9
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x550d4
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0x541883d(%rip), %eax   # 0x546da08
jae 0x55301
movq 0x5398828(%rip), %rax   # 0x53eda00
movl 0x64(%rsp), %ecx
imulq $0x138, %rcx, %rcx      # imm = 0x138
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x1c(%rsp)
xorl %eax, %eax
cmpl $0x4, 0x1c(%rsp)
movb %al, 0x6(%rsp)
jae 0x5521d
movq 0x8(%rsp), %rax
movl 0x1c(%rsp), %ecx
movzbl 0x88(%rax,%rcx), %eax
cmpl $0xff, %eax
setne %al
movb %al, 0x6(%rsp)
movb 0x6(%rsp), %al
testb $0x1, %al
jne 0x5522a
jmp 0x552ef
movq 0x551a987(%rip), %rax   # 0x556fbb8
movl 0x64(%rsp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss (%rax), %xmm0
movq 0x8(%rsp), %rax
addq $0x90, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss %xmm0, (%rax)
movq 0x551a94c(%rip), %rax   # 0x556fbb8
movl 0x64(%rsp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss 0x4(%rax), %xmm0
movq 0x8(%rsp), %rax
addq $0x90, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
movq 0x551a90f(%rip), %rax   # 0x556fbb8
movl 0x64(%rsp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss 0x8(%rax), %xmm0
movq 0x8(%rsp), %rax
addq $0x90, %rax
movl 0x1c(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x551f3
jmp 0x552f1
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x551c1
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)