// File: 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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6e30
movq -0xd8(%rbp), %rdi
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x20(%rbp)
addq $0x48, %rdi
callq 0x73e0
movq -0xd8(%rbp), %rdi
addq $0x48, %rdi
movq -0x18(%rbp), %rsi
callq 0x7400
movq -0xd8(%rbp), %rdi
callq 0x7500
movq -0xd8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x7520
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x2ff1
leaq -0x68(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x29a0
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x7620
jmp 0x2fc0
leaq -0x68(%rbp), %rdi
callq 0x7650
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x2f91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x7650
jmp 0x319b
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
callq 0x7670
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
movq -0x20(%rbp), %rsi
callq 0x7690
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x30af
leaq -0xa8(%rbp), %rdi
callq 0x29f0
movq $0x0, -0xb0(%rbp)
cmpq $0x3, -0xb0(%rbp)
jae 0x3087
movq -0x10(%rbp), %rdi
imulq $0x3, -0x80(%rbp), %rsi
addq -0xb0(%rbp), %rsi
callq 0x6e50
movq (%rax), %rcx
movq -0xb0(%rbp), %rax
movq %rcx, -0xa0(%rbp,%rax,8)
movq -0xb0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb0(%rbp)
jmp 0x3042
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x7790
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x301d
movq -0xd8(%rbp), %rdi
addq $0x30, %rdi
callq 0x73e0
movq -0xd8(%rbp), %rax
addq $0x30, %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6e30
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
callq 0x7400
movq -0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x6f00
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x7800
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x7830
testb $0x1, %al
jne 0x3133
jmp 0x316b
leaq -0xc0(%rbp), %rdi
callq 0x7870
movq -0xd8(%rbp), %rdi
movq %rax, -0xd0(%rbp)
addq $0x30, %rdi
movq -0xd0(%rbp), %rsi
callq 0x6fb0
leaq -0xc0(%rbp), %rdi
callq 0x7890
jmp 0x311a
movq -0xd8(%rbp), %rdi
addq $0x60, %rdi
callq 0x2b80
movq -0xd8(%rbp), %rdi
movq $-0x1, 0x1a8(%rdi)
callq 0x34d0
addq $0xf0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x2330
nopw %cs:(%rax,%rax)