// File: FreeSlave[P]vhlt/hlbsp/tjunc.cpp
// Function: FixFaceEdges(face_s*)
static void     FixFaceEdges(face_t* f)
{
    int             i;
    int             j;
    int             k;
    wedge_t*        w;
    wvert_t*        v;
    vec_t           t1;
    vec_t           t2;

    *superface = *f;

restart:
    for (i = 0; i < superface->numpoints; i++)
    {
        j = (i + 1) % superface->numpoints;

        w = FindEdge(superface->pts[i], superface->pts[j], &t1, &t2);

        for (v = w->head.next; v->t < t1 + T_EPSILON; v = v->next)
        {
        }

        if (v->t < t2 - T_EPSILON)
        {
            tjuncs++;
            // insert a new vertex here
            for (k = superface->numpoints; k > j; k--)
            {
                VectorCopy(superface->pts[k - 1], superface->pts[k]);
            }
            VectorMA(w->origin, v->t, w->dir, superface->pts[j]);
            superface->numpoints++;
            hlassume(superface->numpoints < MAX_SUPERFACEEDGES, assume_MAX_SUPERFACEEDGES);
            goto restart;
        }
    }

    if (superface->numpoints <= MAXPOINTS)
    {
        *f = *superface;
        f->next = newlist;
        newlist = f;
        return;
    }

    // the face needs to be split into multiple faces because of too many edges

    SplitFaceForTjunc(superface, f);

}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rsi
movq 0x15ab3(%rip), %rdi     # 0x47408
movl $0x4b8, %edx            # imm = 0x4B8
callq 0x4260
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movq 0x15a96(%rip), %rcx     # 0x47408
cmpl 0x2c(%rcx), %eax
jge 0x31c2e
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movq 0x15a7f(%rip), %rcx     # 0x47408
cltd
idivl 0x2c(%rcx)
movl %edx, 0x28(%rsp)
movq 0x15a70(%rip), %rdi     # 0x47408
addq $0x38, %rdi
movslq 0x2c(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq 0x15a59(%rip), %rsi     # 0x47408
addq $0x38, %rsi
movslq 0x28(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
leaq 0x8(%rsp), %rdx
movq %rsp, %rcx
callq 0x30e00
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x7c10(%rip), %xmm0     # 0x39600
addsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x31a0e
jmp 0x319fe
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x319df
movq 0x10(%rsp), %rax
movsd (%rax), %xmm1
movsd (%rsp), %xmm0
movsd 0x7bdc(%rip), %xmm2     # 0x39600
subsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x31c1c
movl 0x3a360a4(%rip), %eax   # 0x3a67adc
addl $0x1, %eax
movl %eax, 0x3a3609b(%rip)   # 0x3a67adc
movq 0x159c0(%rip), %rax     # 0x47408
movl 0x2c(%rax), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x28(%rsp), %eax
jle 0x31b22
movq 0x159a4(%rip), %rax     # 0x47408
addq $0x38, %rax
movl 0x24(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq 0x15984(%rip), %rax     # 0x47408
addq $0x38, %rax
movslq 0x24(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq 0x15969(%rip), %rax     # 0x47408
addq $0x38, %rax
movl 0x24(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq 0x15948(%rip), %rax     # 0x47408
addq $0x38, %rax
movslq 0x24(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movq 0x1592c(%rip), %rax     # 0x47408
addq $0x38, %rax
movl 0x24(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movq 0x1590b(%rip), %rax     # 0x47408
addq $0x38, %rax
movslq 0x24(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movl 0x24(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x31a4f
movq 0x18(%rsp), %rax
movsd 0x20(%rax), %xmm1
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
movq 0x18(%rsp), %rax
movsd 0x8(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x158ba(%rip), %rax     # 0x47408
addq $0x38, %rax
movslq 0x28(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq 0x18(%rsp), %rax
movsd 0x28(%rax), %xmm1
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
movq 0x18(%rsp), %rax
movsd 0x10(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x1587a(%rip), %rax     # 0x47408
addq $0x38, %rax
movslq 0x28(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movq 0x18(%rsp), %rax
movsd 0x30(%rax), %xmm1
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
movq 0x18(%rsp), %rax
movsd 0x18(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x15839(%rip), %rax     # 0x47408
addq $0x38, %rax
movslq 0x28(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movq 0x1581d(%rip), %rax     # 0x47408
movl 0x2c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x2c(%rax)
movq 0x1580d(%rip), %rax     # 0x47408
movl 0x2c(%rax), %eax
cmpl 0x1580c(%rip), %eax     # 0x47410
setl %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x15, %esi
callq 0xbe90
jmp 0x3195f
jmp 0x31c1e
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x31967
movq 0x157d3(%rip), %rax     # 0x47408
cmpl $0x1c, 0x2c(%rax)
jg 0x31c6e
movq 0x157c6(%rip), %rsi     # 0x47408
movq 0x30(%rsp), %rdi
movl $0x4b8, %edx            # imm = 0x4B8
callq 0x4260
movq 0x4a35ed8(%rip), %rcx   # 0x4a67b30
movq 0x30(%rsp), %rax
movq %rcx, (%rax)
movq 0x30(%rsp), %rax
movq %rax, 0x4a35ec4(%rip)   # 0x4a67b30
jmp 0x31c7f
movq 0x15793(%rip), %rdi     # 0x47408
movq 0x30(%rsp), %rsi
callq 0x31c90
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)