// File: joakimkistowski[P]amd-disable-c6/amd-disable-c6.cpp
// Function: get_cpu_ids(std::vector<int, std::allocator<int>>&)
void get_cpu_ids(std::vector<int> &ids) {
    const std::string DOT = std::string(".");
    const std::string MICROCODE = std::string("microcode");
    DIR * dir = opendir("/dev/cpu/");
    if (!dir) {
        std::cerr << "Failed reading CPU ids" << std::endl;
        return;
    }
    struct dirent * ent;
    while ((ent = readdir(dir)) != NULL) {
            std::string name(ent->d_name);
            if (!name.compare(0, DOT.length(), DOT) == 0 && name != MICROCODE) {
                try {
                    ids.push_back(std::stoi(std::string(ent->d_name)));
                } catch (const std::invalid_argument& ia) {
                    std::cerr << "Invalid CPU ID: " << ent->d_name << std::endl;
                }
            }
            
    }
    closedir(dir);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x23a0
movq -0xe0(%rbp), %rdx
leaq 0x38a1(%rip), %rsi      # 0x61ce
leaq -0x28(%rbp), %rdi
callq 0x3ed0
jmp 0x2938
leaq -0x29(%rbp), %rdi
callq 0x2210
leaq -0x61(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x23a0
movq -0xe8(%rbp), %rdx
leaq 0x36e5(%rip), %rsi      # 0x6044
leaq -0x60(%rbp), %rdi
callq 0x3ed0
jmp 0x296a
leaq -0x61(%rbp), %rdi
callq 0x2210
leaq 0x36d4(%rip), %rdi      # 0x604e
callq 0x2310
movq %rax, -0xf0(%rbp)
jmp 0x2988
movq -0xf0(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x2a20
movq 0x664b(%rip), %rdi      # 0x8ff0
leaq 0x36ac(%rip), %rsi      # 0x6058
callq 0x21b0
movq %rax, -0xf8(%rbp)
jmp 0x29ba
movq -0xf8(%rbp), %rdi
movq 0x65e8(%rip), %rsi      # 0x8fb0
callq 0x21f0
jmp 0x29cf
movl $0x1, -0x74(%rbp)
jmp 0x2cbd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x2210
jmp 0x2cea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x2210
jmp 0x2ce1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2cd8
jmp 0x2a22
movq -0x70(%rbp), %rdi
callq 0x2320
movq %rax, -0x100(%rbp)
jmp 0x2a34
movq -0x100(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0x2cab
movq -0x80(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x110(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x23a0
movq -0x110(%rbp), %rsi
movq -0x108(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x3ed0
jmp 0x2a87
leaq -0xa1(%rbp), %rdi
callq 0x2210
leaq -0x28(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x2300
movq -0x120(%rbp), %rcx
movq %rax, %rdx
xorl %eax, %eax
movl %eax, %esi
leaq -0xa0(%rbp), %rdi
callq 0x22a0
movl %eax, -0x114(%rbp)
jmp 0x2ac5
movl -0x114(%rbp), %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2c8c
leaq -0xa0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x3f80
testb $0x1, %al
jne 0x2afa
jmp 0x2c8c
movq -0x8(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x80(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x130(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x23a0
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
callq 0x3ed0
jmp 0x2b43
xorl %eax, %eax
movl %eax, %esi
leaq -0xc8(%rbp), %rdi
movl $0xa, %edx
callq 0x3fe0
movl %eax, -0x13c(%rbp)
jmp 0x2b60
movq -0x138(%rbp), %rdi
movl -0x13c(%rbp), %eax
movl %eax, -0xa8(%rbp)
leaq -0xa8(%rbp), %rsi
callq 0x3fb0
jmp 0x2b81
leaq -0xc8(%rbp), %rdi
callq 0x2428
leaq -0xc9(%rbp), %rdi
callq 0x2210
jmp 0x2c75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xa1(%rbp), %rdi
callq 0x2210
jmp 0x2cd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2c9d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2bf2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x2428
leaq -0xc9(%rbp), %rdi
callq 0x2210
movl -0x3c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2c9d
movq -0x38(%rbp), %rdi
callq 0x20b0
movq %rax, -0xd8(%rbp)
movq 0x63cb(%rip), %rdi      # 0x8ff0
leaq 0x3443(%rip), %rsi      # 0x606f
callq 0x21b0
movq %rax, -0x148(%rbp)
jmp 0x2c3a
movq -0x148(%rbp), %rdi
movq -0x80(%rbp), %rsi
addq $0x13, %rsi
callq 0x21b0
movq %rax, -0x150(%rbp)
jmp 0x2c57
movq -0x150(%rbp), %rdi
movq 0x634b(%rip), %rsi      # 0x8fb0
callq 0x21f0
jmp 0x2c6c
callq 0x2380
jmp 0x2c73
jmp 0x2c75
jmp 0x2c8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x2380
jmp 0x2c8a
jmp 0x2c9d
leaq -0xa0(%rbp), %rdi
callq 0x2428
jmp 0x2a22
leaq -0xa0(%rbp), %rdi
callq 0x2428
jmp 0x2cd8
movq -0x70(%rbp), %rdi
callq 0x2360
jmp 0x2cb6
movl $0x0, -0x74(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x2428
leaq -0x28(%rbp), %rdi
callq 0x2428
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x2428
leaq -0x28(%rbp), %rdi
callq 0x2428
movq -0x38(%rbp), %rdi
callq 0x2390
movq %rax, %rdi
callq 0x4020
nopl (%rax,%rax)