// File: /workspace/github_cpp_makefile_star2_O1/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 0x20d0(%rip), %rsi      # 0x5048
leaq 0x20d2(%rip), %rdx      # 0x5051
leaq 0x88(%rsp), %rdi
callq 0x3fac
movl $0x1, %eax
cmpl $0xa, %ebp
jb 0x2fda
movl $0x4, %eax
movl $0xd1b71759, %ecx       # imm = 0xD1B71759
movl %ebp, %edx
cmpl $0x63, %edx
jbe 0x2fd3
cmpl $0x3e7, %edx            # imm = 0x3E7
jbe 0x2fd8
cmpl $0x2710, %edx           # imm = 0x2710
jb 0x2fda
movl %edx, %esi
imulq %rcx, %rsi
shrq $0x2d, %rsi
addl $0x4, %eax
cmpl $0x1869f, %edx          # imm = 0x1869F
movl %esi, %edx
ja 0x2fa2
addl $-0x3, %eax
jmp 0x2fda
addl $-0x2, %eax
jmp 0x2fda
decl %eax
movl %eax, %esi
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x28(%rsp), %rdi
xorl %edx, %edx
callq 0x21f0
movq 0x28(%rsp), %rdi
movl 0x30(%rsp), %esi
movl %ebp, %edx
callq 0x3f3e
movq 0x88(%rsp), %rcx
movq 0x90(%rsp), %r8
movq 0x30(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r14, %rcx
je 0x302c
movq 0x98(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x3047
movl $0xf, %esi
cmpq %r15, 0x28(%rsp)
je 0x3042
movq 0x38(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x305b
movq 0x28(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0x2090
jmp 0x3069
leaq 0x28(%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 0x3fac
leaq 0x18(%rsp), %r13
movq -0x10(%r13), %rcx
movq -0x8(%r13), %r8
movq 0x70(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r13, %rcx
je 0x30f7
movq 0x18(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x3112
movl $0xf, %esi
cmpq %r12, 0x68(%rsp)
je 0x310d
movq 0x78(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x3123
movq 0x68(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x2090
jmp 0x3131
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21d0
leaq 0x58(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x3155
movq %rsi, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
jmp 0x315b
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x50(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x68(%rsp), %rdi
cmpq %r12, %rdi
je 0x318f
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x31a6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x31bd
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x31da
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x48(%rsp), %rdi
leaq 0x1f76(%rip), %rsi      # 0x515c
callq 0x2200
testq %rax, %rax
je 0x3258
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x21c0
testl %eax, %eax
je 0x32a2
movq 0x3de1(%rip), %rbx      # 0x6ff0
leaq 0x1f1a(%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 0x3daf(%rip), %rdi      # 0x6ff0
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %r14, %rdi
callq 0x2180
jmp 0x329e
movq 0x3d91(%rip), %rbx      # 0x6ff0
leaq 0x1e8b(%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 0x3d5f(%rip), %rdi      # 0x6ff0
callq 0x2030
movq %rax, %rdi
callq 0x2110
xorl %ebx, %ebx
jmp 0x32ce
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 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x32e9
movq 0x58(%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 0x331d
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x331d
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x333d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x333d
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x3359
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x3359
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x3395
movq 0x98(%rsp), %rsi
jmp 0x338d
movq %rax, %rbx
jmp 0x3395
jmp 0x3377
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3395
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x22c0