// File: /workspace/github_cpp_makefile_star2_O3/joakimkistowski[P]amd-disable-c6/amd-disable-c6.cpp
// Function: read_msr(long, unsigned int)
uint64_t read_msr(long int msr_addr, unsigned int cpu_id = 0) {
    std::string path = std::string("/dev/cpu/") + std::to_string(cpu_id) + std::string("/msr");
    FILE * f = fopen(path.c_str(), "r");
    if (!f) {
        std::cerr << "Failed reading of C6 state; msr module is not loaded in kernel" << std::endl;
        return 0;
    }
    int err = fseek (f, msr_addr, SEEK_SET);
    if (err) {
        std::cerr << "Failed reading of C6 state; error reading msr" << std::endl;
        fclose(f);
        return 0;
    }
    uint64_t msr_value = 0;
    fread(&msr_value, 8, 1, f);
    fclose(f);
    return msr_value;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x20ce(%rip), %rsi      # 0x5048
leaq 0x20d0(%rip), %rdx      # 0x5051
leaq 0x88(%rsp), %rdi
callq 0x3f94
movl $0x1, %eax
cmpl $0xa, %ebp
jb 0x2fdc
movl $0x4, %eax
movl $0xd1b71759, %ecx       # imm = 0xD1B71759
movl %ebp, %edx
cmpl $0x63, %edx
jbe 0x2fd5
cmpl $0x3e7, %edx            # imm = 0x3E7
jbe 0x2fda
cmpl $0x2710, %edx           # imm = 0x2710
jb 0x2fdc
movl %edx, %esi
imulq %rcx, %rsi
shrq $0x2d, %rsi
addl $0x4, %eax
cmpl $0x1869f, %edx          # imm = 0x1869F
movl %esi, %edx
ja 0x2fa4
addl $-0x3, %eax
jmp 0x2fdc
addl $-0x2, %eax
jmp 0x2fdc
decl %eax
movl %eax, %esi
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x48(%rsp), %rdi
xorl %edx, %edx
callq 0x21f0
movq 0x48(%rsp), %rdi
movl 0x50(%rsp), %esi
movl %ebp, %edx
callq 0x3f26
movq 0x88(%rsp), %rcx
movq 0x90(%rsp), %r8
movq 0x50(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
cmpq %r14, %rcx
je 0x302e
movq 0x98(%rsp), %rdi
movq 0x48(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x304c
movl $0xf, %edi
cmpq %r15, %rsi
je 0x3047
movq 0x58(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x305b
leaq 0x88(%rsp), %rdi
callq 0x2090
jmp 0x3069
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21d0
leaq 0x18(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x308d
movq %rsi, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x3093
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x78(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1fb9(%rip), %rsi      # 0x507a
leaq 0x1fb6(%rip), %rdx      # 0x507e
leaq 0x68(%rsp), %rdi
callq 0x3f94
leaq 0x18(%rsp), %r13
movq -0x10(%r13), %rcx
movq -0x8(%r13), %r8
movq 0x70(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
cmpq %r13, %rcx
je 0x30f7
movq 0x18(%rsp), %rdi
movq 0x68(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x3115
movl $0xf, %edi
cmpq %r12, %rsi
je 0x3110
movq 0x78(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x3121
leaq 0x8(%rsp), %rdi
callq 0x2090
jmp 0x312f
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21d0
leaq 0x38(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x3153
movq %rsi, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0x3159
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x68(%rsp), %rdi
cmpq %r12, %rdi
je 0x318d
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x31a4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x31bb
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x31d8
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x28(%rsp), %rdi
leaq 0x1f78(%rip), %rsi      # 0x515c
callq 0x2200
testq %rax, %rax
je 0x3256
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x21c0
testl %eax, %eax
je 0x32a0
movq 0x3de3(%rip), %rbx      # 0x6ff0
leaq 0x1f1c(%rip), %rsi      # 0x5130
movl $0x2d, %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 0x3db1(%rip), %rdi      # 0x6ff0
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %r14, %rdi
callq 0x2180
jmp 0x329c
movq 0x3d93(%rip), %rbx      # 0x6ff0
leaq 0x1e8d(%rip), %rsi      # 0x50f1
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 0x3d61(%rip), %rdi      # 0x6ff0
callq 0x2030
movq %rax, %rdi
callq 0x2110
xorl %ebx, %ebx
jmp 0x32cc
leaq 0x8(%rsp), %rbx
movq $0x0, (%rbx)
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x2240
movq %r14, %rdi
callq 0x2180
movq (%rbx), %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x32e7
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r12, %rdi
je 0x331b
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x331b
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x333b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x333b
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x3357
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x3357
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x3393
movq 0x98(%rsp), %rsi
jmp 0x338b
movq %rax, %rbx
jmp 0x3393
jmp 0x3375
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3393
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x22c0