// File: FreeSlave[P]vhlt/hlcsg/qcsg.cpp
// Function: SetModelCenters(int)
static void     SetModelCenters(int entitynum)
{
    int             i;
    int             last;
    char            string[MAXTOKEN];
    entity_t*       e = &g_entities[entitynum];
    BoundingBox     bounds;
    vec3_t          center;

    if ((entitynum == 0) || (e->numbrushes == 0)) // skip worldspawn and point entities
        return;

    if (!*ValueForKey(e, "light_origin")) // skip if its not a zhlt_flags light_origin
        return;

    for (i = e->firstbrush, last = e->firstbrush + e->numbrushes; i < last; i++)
    {
        if (g_mapbrushes[i].contents != CONTENTS_ORIGIN
#ifdef HLCSG_HLBSP_CUSTOMBOUNDINGBOX
			&& g_mapbrushes[i].contents != CONTENTS_BOUNDINGBOX
#endif
			)
        {
            bounds.add(g_mapbrushes[i].hulls->bounds);
        }
    }

    VectorAdd(bounds.m_Mins, bounds.m_Maxs, center);
    VectorScale(center, 0.5, center);

    safe_snprintf(string, MAXTOKEN, "%i %i %i", (int)center[0], (int)center[1], (int)center[2]);
    SetKeyValue(e, "model_center", string);
}

// Assembly:
subq $0x1088, %rsp           # imm = 0x1088
movl %edi, 0x1084(%rsp)
movslq 0x1084(%rsp), %rcx
leaq 0x2009fb3(%rip), %rax   # 0x202d4b0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x68(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x122c0
cmpl $0x0, 0x1084(%rsp)
je 0x23528
movq 0x68(%rsp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x23535
movl $0x1, 0x1c(%rsp)
jmp 0x23701
movq 0x68(%rsp), %rdi
leaq 0xc679(%rip), %rsi      # 0x2fbba
callq 0x7ff0
movq %rax, (%rsp)
jmp 0x2354c
movq (%rsp), %rax
cmpb $0x0, (%rax)
jne 0x2357f
movl $0x1, 0x1c(%rsp)
jmp 0x23701
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10(%rsp)
movl %eax, 0xc(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x12480
jmp 0x23713
movq 0x68(%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, 0x1080(%rsp)
movq 0x68(%rsp), %rax
movl 0x18(%rax), %eax
movq 0x68(%rsp), %rcx
addl 0x1c(%rcx), %eax
movl %eax, 0x107c(%rsp)
movl 0x1080(%rsp), %eax
cmpl 0x107c(%rsp), %eax
jge 0x23639
movslq 0x1080(%rsp), %rcx
leaq 0x30b8078(%rip), %rax   # 0x30db640
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
cmpl $-0x7, 0x58(%rax)
je 0x23621
movslq 0x1080(%rsp), %rcx
leaq 0x30b8059(%rip), %rax   # 0x30db640
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
cmpl $-0x13, 0x58(%rax)
je 0x23621
movslq 0x1080(%rsp), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x6, %rcx
leaq 0x30b8032(%rip), %rax   # 0x30db640
leaq 0x60(%rax,%rcx), %rsi
leaq 0x38(%rsp), %rdi
callq 0x25a90
jmp 0x2361f
jmp 0x23621
jmp 0x23623
movl 0x1080(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1080(%rsp)
jmp 0x235a5
movsd 0x38(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x40(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x48(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x20(%rsp), %xmm0
movsd 0x9df7(%rip), %xmm1     # 0x2d480
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x30(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
cvttsd2si 0x20(%rsp), %ecx
cvttsd2si 0x28(%rsp), %r8d
cvttsd2si 0x30(%rsp), %r9d
leaq 0xae1c(%rip), %rdx      # 0x2e4ea
xorl %eax, %eax
leaq 0x70(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x99e0
jmp 0x236e1
movq 0x68(%rsp), %rdi
leaq 0xc4da(%rip), %rsi      # 0x2fbc7
leaq 0x70(%rsp), %rdx
callq 0x8070
jmp 0x236f9
movl $0x0, 0x1c(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x12480
addq $0x1088, %rsp           # imm = 0x1088
retq
movq 0x10(%rsp), %rdi
callq 0x4650
nopl (%rax)