// File: /workspace/github_cpp_makefile_star2_O3/travisdowns[P]avx-turbo/avx-turbo.cpp
// Function: filter_cpus(std::vector<int, std::allocator<int>>)
std::vector<int> filter_cpus(std::vector<int> cpus) {
    int shift = get_smt_shift();
    if (shift == -1) {
        printf("Can't use cpuid leaf 0xb to filter out hyperthreads, CPU too old or AMD\n");
        return cpus;
    }
    cpu_set_t original_set;
    if (sched_getaffinity(0, sizeof(original_set), &original_set)) {
        err(EXIT_FAILURE, "failed while getting cpu affinity");
    }
    std::vector<int> filtered_cpus;
    std::set<uint32_t> coreid_set;
    for (int cpu : cpus) {
        cpu_set_t cpuset;
        CPU_ZERO(&cpuset);
        CPU_SET(cpu, &cpuset);
        if (sched_setaffinity(0, sizeof(cpu_set_t), &cpuset)) {
            err(EXIT_FAILURE, "failed to sched_setaffinity in filter_cpus");
        }
        cpuid_result leafb = cpuid(0xb);
        uint32_t apicid = leafb.edx, coreid = apicid >> shift;
        if (verbose) printf("cpu %d has x2apic ID %u, coreid %u\n", cpu, apicid, coreid);
        if (coreid_set.insert(coreid).second) {
            filtered_cpus.push_back(cpu);
        }
    }
    // restore original affinity
    sched_setaffinity(0, sizeof(cpu_set_t), &original_set);
    return filtered_cpus;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %r14
movq %rdi, %rbx
callq 0x15fc9
cmpl $-0x1, %eax
je 0x98cc
movl %eax, %ebp
leaq 0xc8(%rsp), %rdx
movl $0x80, %esi
xorl %edi, %edi
callq 0x64e0
testl %eax, %eax
jne 0x991e
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
leaq 0x18(%rsp), %rcx
movl $0x0, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq (%r14), %r15
movq 0x8(%r14), %r14
cmpq %r14, %r15
je 0x98ac
leaq 0x10(%rsp), %r12
leaq 0xc(%rsp), %r13
movl (%r15), %ecx
movl %ecx, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
cmpq $0x3ff, %rcx            # imm = 0x3FF
ja 0x981a
movl $0x1, %eax
shlq %cl, %rax
shrl $0x6, %ecx
orq %rax, 0x40(%rsp,%rcx,8)
movl $0x80, %esi
xorl %edi, %edi
leaq 0x40(%rsp), %rdx
callq 0x62b0
testl %eax, %eax
jne 0x990b
movl $0xb, %edi
callq 0x15c18
shrq $0x20, %rdx
movl %edx, %eax
movl %ebp, %ecx
shrl %cl, %eax
movl %eax, 0xc(%rsp)
cmpb $0x1, 0x1f9c6(%rip)     # 0x29218
jne 0x9868
movl 0x8(%rsp), %esi
leaq 0x14f9b(%rip), %rdi     # 0x1e7fa
movl %eax, %ecx
xorl %eax, %eax
callq 0x6050
movq %r12, %rdi
movq %r13, %rsi
callq 0x1402e
testb $0x1, %dl
je 0x989f
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x9892
movl 0x8(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x989f
movq %rbx, %rdi
leaq 0x8(%rsp), %rdx
callq 0x13f16
addq $0x4, %r15
cmpq %r14, %r15
jne 0x97c3
leaq 0xc8(%rsp), %rdx
movl $0x80, %esi
xorl %edi, %edi
callq 0x62b0
leaq 0x10(%rsp), %rdi
callq 0xf256
jmp 0x98f6
leaq 0x160f2(%rip), %rdi     # 0x1f9c5
callq 0x6500
movups (%r14), %xmm0
movups %xmm0, (%rbx)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movq %rbx, %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14ebd(%rip), %rsi     # 0x1e7cf
movl $0x1, %edi
xorl %eax, %eax
callq 0x62f0
leaq 0x14e88(%rip), %rsi     # 0x1e7ad
movl $0x1, %edi
xorl %eax, %eax
callq 0x62f0
jmp 0x9937
jmp 0x9937
jmp 0x9937
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0xf256
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x9951
callq 0x6320
movq %r14, %rdi
callq 0x65f0