// File: /workspace/github_cpp_makefile_star2_O1/joakimkistowski[P]amd-disable-c6/amd-disable-c6.cpp
// Function: write_msr(long, unsigned long, int)
unsigned int write_msr(long int msr_addr, uint64_t value, int cpu_id = -1) {
    if (cpu_id < 0) {
        unsigned int ret = 0;
        std::vector<int> ids;
        get_cpu_ids(ids);
        for (const int& id : ids) {
            if (id > 0) {
                ret = ret | write_msr(msr_addr, value, id);
            }
        }
        return ret;
    } else {
        std::string path = std::string("/dev/cpu/") + std::to_string(cpu_id) + std::string("/msr");
        FILE * f = fopen(path.c_str(), "w");
        if (!f) {
            std::cerr << "Failed writing of C6 state; msr module is not loaded in kernel" << std::endl;
            return 1;
        }
        int err = fseek (f, msr_addr, SEEK_SET);
        if (err) {
            std::cerr << "Failed writing of C6 state; error writing to msr" << std::endl;
            fclose(f);
            return 1;
        }
        fwrite(&value, 8, 1, f);
        fclose(f);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
movq %rsi, 0xa0(%rsp)
testl %edx, %edx
js 0x2b13
movl %edx, %ebp
leaq 0x90(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25a4(%rip), %rsi      # 0x5048
leaq 0x25a6(%rip), %rdx      # 0x5051
leaq 0x80(%rsp), %rdi
callq 0x3fac
movl $0x1, %r14d
cmpl $0xa, %ebp
jb 0x2b79
movl $0x4, %r14d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0x2b70
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x2b76
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x2b79
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r14d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x2ad4
addl $-0x3, %r14d
jmp 0x2b79
movq %rsi, %r14
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x267c
movq (%rsp), %r15
movq 0x8(%rsp), %r12
xorl %ebp, %ebp
cmpq %r12, %r15
je 0x2b56
movl (%r15), %edx
testl %edx, %edx
jle 0x2b50
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2a6b
orl %eax, %ebp
addq $0x4, %r15
jmp 0x2b37
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2e81
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
jmp 0x2e7c
addl $-0x2, %r14d
jmp 0x2b79
decl %r14d
movl %r14d, %esi
leaq 0x50(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x40(%rsp), %rdi
movl $0x2d, %edx
callq 0x21f0
movq 0x40(%rsp), %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x3f3e
movq 0x80(%rsp), %rcx
movq 0x88(%rsp), %r8
movq 0x48(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r15, %rcx
je 0x2bcf
movq 0x90(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x2bea
movl $0xf, %esi
cmpq %r12, 0x40(%rsp)
je 0x2be5
movq 0x50(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x2bfe
movq 0x40(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x2090
jmp 0x2c0c
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21d0
leaq 0x30(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x2c30
movq %rsi, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x2c36
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x28(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x70(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2417(%rip), %rsi      # 0x507a
leaq 0x2414(%rip), %rdx      # 0x507e
leaq 0x60(%rsp), %rdi
callq 0x3fac
leaq 0x30(%rsp), %r13
movq -0x10(%r13), %rcx
movq -0x8(%r13), %r8
movq 0x68(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r13, %rcx
je 0x2c99
movq 0x30(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x2cb4
movl $0xf, %esi
cmpq %r14, 0x60(%rsp)
je 0x2caf
movq 0x70(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x2cc5
movq 0x60(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x2090
jmp 0x2cd3
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21d0
leaq 0x10(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x2cf6
movq %rsi, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x2cfc
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x60(%rsp), %rdi
cmpq %r14, %rdi
je 0x2d30
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x2d47
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x2d5e
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x80(%rsp), %rdi
cmpq %r15, %rdi
je 0x2d7b
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x21a0
movq (%rsp), %rdi
leaq 0x22f9(%rip), %rsi      # 0x507f
callq 0x2200
testq %rax, %rax
je 0x2df7
movq %rax, %r14
xorl %ebp, %ebp
movq %rax, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x21c0
testl %eax, %eax
je 0x2e44
movq 0x423f(%rip), %rbx      # 0x6ff0
leaq 0x2308(%rip), %rsi      # 0x50c0
movl $0x30, %edx
movq %rbx, %rdi
callq 0x21e0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0x420d(%rip), %rdi      # 0x6ff0
callq 0x2030
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2110
jmp 0x2e5e
movq 0x41f2(%rip), %rbx      # 0x6ff0
leaq 0x227c(%rip), %rsi      # 0x5081
movl $0x3e, %edx
movq %rbx, %rdi
callq 0x21e0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0x41c0(%rip), %rdi      # 0x6ff0
callq 0x2030
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2110
jmp 0x2e66
leaq 0xa0(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2300
movq %r14, %rdi
callq 0x2180
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2e81
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f2e
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r14, %rdi
je 0x2eb9
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x2eb9
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ed9
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x2ed9
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x2ef5
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x2ef5
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r15, %rdi
je 0x2f47
movq 0x90(%rsp), %rsi
jmp 0x2f29
movq %rax, %rbx
jmp 0x2f47
jmp 0x2f13
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f47
movq 0x10(%rsp), %rsi
incq %rsi
jmp 0x2f42
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2f47
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x22c0