// File: /workspace/github_cpp_makefile_star2_O3/graphitemaster[P]smbf/smbf.cpp
// Function: vertexCacheOptimizer::init(std::vector<unsigned long, std::allocator<unsigned long>>&, unsigned long)
vertexCacheOptimizer::result vertexCacheOptimizer::init(u::vector<size_t> &indices, size_t maxVertex) {
    const size_t triangleCount = indices.size() / 3;

    // Reset draw list
    m_drawList.clear();
    m_drawList.reserve(maxVertex);

    // Reset and initialize vertices and triangles
    m_vertices.clear();
    m_vertices.reserve(maxVertex);
    for (size_t i = 0; i < maxVertex; i++)
        m_vertices.push_back(vertexCacheData());

    m_triangles.clear();
    m_triangles.reserve(triangleCount);
    for (size_t i = 0; i < triangleCount; i++) {
        triangleCacheData data;
        for (size_t j = 0; j < 3; j++)
            data.vertices[j] = indices[i * 3 + j];
        m_triangles.push_back(data);
    }

    // Copy the indices
    m_indices.clear();
    m_indices.reserve(indices.size());
    for (auto &it : indices)
        m_indices.push_back(it);

    // Run the initial pass
    m_vertexCache.clear();
    m_bestTriangle = (size_t)-1;

    return initialPass();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r13
movq %rdi, %rbx
movq 0x8(%rsi), %r12
movq %rsi, 0x8(%rsp)
subq (%rsi), %r12
sarq $0x3, %r12
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
movq %r12, %rax
mulq %rcx
movq %rdx, %r15
addq $0x48, %rdi
movq 0x48(%rbx), %rax
cmpq %rax, 0x50(%rbx)
je 0x2a6d
movq %rax, 0x50(%rbx)
movq %r13, %rsi
callq 0x4e56
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x5e2e
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4ef2
testq %r13, %r13
je 0x2aec
leaq 0x38(%rsp), %r14
leaq 0x10(%rsp), %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq $-0x1, 0x28(%rsp)
movl $0x0, 0x30(%rsp)
movups %xmm0, (%r14)
movb $0x0, 0x10(%r14)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x5e94
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2ae7
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
decq %r13
jne 0x2a9a
shrq %r15
leaq 0x18(%rbx), %rax
movq %rax, (%rsp)
movq 0x18(%rbx), %rax
cmpq %rax, 0x20(%rbx)
je 0x2b05
movq %rax, 0x20(%rbx)
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x4fd8
cmpq $0x3, %r12
movq 0x8(%rsp), %rdi
jb 0x2bc1
leaq 0x18(%rsp), %rbp
xorl %r12d, %r12d
pcmpeqd %xmm2, %xmm2
xorl %r13d, %r13d
xorl %r14d, %r14d
movb %r12b, 0x10(%rsp)
movl $0x0, 0x14(%rsp)
movb %r12b, 0x30(%rsp)
movdqu %xmm2, (%rbp)
movq $-0x1, 0x10(%rbp)
movq (%rdi), %rax
addq %r13, %rax
movl $0x1, %ecx
movq -0x8(%rax,%rcx,8), %rdx
movq %rdx, 0x10(%rsp,%rcx,8)
incq %rcx
cmpq $0x4, %rcx
jne 0x2b5c
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x2b9a
movq 0x30(%rsp), %rax
movq %rax, 0x20(%rsi)
movups 0x10(%rsp), %xmm0
movups 0x20(%rsp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x28, 0x20(%rbx)
jmp 0x2bb1
movq (%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x60d4
pcmpeqd %xmm2, %xmm2
movq 0x8(%rsp), %rdi
incq %r14
addq $0x18, %r13
cmpq %r15, %r14
jne 0x2b32
leaq 0x30(%rbx), %r15
movq 0x30(%rbx), %rax
cmpq %rax, 0x38(%rbx)
je 0x2bd3
movq %rax, 0x38(%rbx)
movq 0x8(%rdi), %rsi
subq (%rdi), %rsi
sarq $0x3, %rsi
movq %rdi, %r14
movq %r15, %rdi
callq 0x4e56
movq (%r14), %r12
movq 0x8(%r14), %r14
cmpq %r14, %r12
je 0x2c21
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x2c10
movq (%r12), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x2c1b
movq %r15, %rdi
movq %r12, %rdx
callq 0x5c16
addq $0x8, %r12
jmp 0x2bf0
leaq 0x60(%rbx), %rdi
movl $0x140, %edx            # imm = 0x140
movl $0xff, %esi
callq 0x20a0
movq $0x0, 0x1a0(%rbx)
movq $-0x1, 0x1a8(%rbx)
movq %rbx, %rdi
callq 0x2e50
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2c7b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x2200
nop