// File: /workspace/github_cpp_makefile_star2_O2/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 $0x158, %rsp            # imm = 0x158
movq %rsi, %r14
movq %rdi, %rbx
callq 0x134a2
cmpl $-0x1, %eax
je 0x88c9
movl %eax, %ebp
leaq 0xd8(%rsp), %rdx
movl $0x80, %esi
xorl %edi, %edi
callq 0x6500
testl %eax, %eax
jne 0x8916
andq $0x0, 0x10(%rbx)
leaq 0x28(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
xorps %xmm0, %xmm0
movq %rbx, 0x10(%rsp)
movups %xmm0, (%rbx)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq (%r14), %rbx
movq 0x8(%r14), %r14
pushq $0xb
popq %r15
leaq 0x20(%rsp), %r13
leaq 0x1c(%rsp), %r12
cmpq %r14, %rbx
je 0x88a4
movl (%rbx), %ecx
movl %ecx, 0xc(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xc0(%rsp)
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)
cmpq $0x3ff, %rcx            # imm = 0x3FF
ja 0x8830
pushq $0x1
popq %rax
shlq %cl, %rax
shrl $0x6, %ecx
orq %rax, 0x50(%rsp,%rcx,8)
movl $0x80, %esi
xorl %edi, %edi
leaq 0x50(%rsp), %rdx
callq 0x62c0
testl %eax, %eax
jne 0x8905
movl %r15d, %edi
callq 0x13230
shrq $0x20, %rdx
movl %edx, %eax
movl %ebp, %ecx
shrl %cl, %eax
movl %eax, 0x1c(%rsp)
cmpb $0x1, 0x1f9d2(%rip)     # 0x28238
jne 0x887c
movl 0xc(%rsp), %esi
leaq 0x12fa6(%rip), %rdi     # 0x1b819
movl %eax, %ecx
xorl %eax, %eax
callq 0x6050
movq %r13, %rdi
movq %r12, %rsi
callq 0x11812
testb $0x1, %dl
je 0x889b
movq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0xa598
addq $0x4, %rbx
jmp 0x87d0
leaq 0xd8(%rsp), %rdx
movl $0x80, %esi
xorl %edi, %edi
callq 0x62c0
leaq 0x20(%rsp), %rdi
callq 0xd95a
movq 0x10(%rsp), %rax
jmp 0x88f3
leaq 0x14114(%rip), %rdi     # 0x1c9e4
callq 0x6520
movups (%r14), %xmm0
movups %xmm0, (%rbx)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
andq $0x0, 0x10(%r14)
movq %rbx, %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12ee2(%rip), %rsi     # 0x1b7ee
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x6310
leaq 0x12eaf(%rip), %rsi     # 0x1b7cc
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x6310
jmp 0x892d
jmp 0x892d
jmp 0x892d
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0xd95a
movq 0x10(%rsp), %rdi
callq 0x115da
movq %r14, %rdi
callq 0x65f0