#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef scalar_t__ uint64_t;
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, int,
                           int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__,
                           scalar_t__);
int /*<<< orphan*/ read_msr(int, int /*<<< orphan*/, scalar_t__ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write_msr(int, int /*<<< orphan*/, scalar_t__);
void write_and_validate_msr(int core, off_t msr, uint64_t val) {
  uint64_t val2 = val;
  write_msr(core, msr, val);
  read_msr(core, msr, &val2);
  if (val != val2) {
    fprintf(stderr,
            "%s::%d  write_and_validate_msr failed.  core=%d, msr=%ld (0x%lx), "
            "val=0x%lx, val2=0x%lx.\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/pyrovski/powertools/refs/heads/master/"
            "msr_core.c",
            129, core, msr, msr, val, val2);
  }
}


x86 assembly (clang, -O0):
<write_and_validate_msr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1050 <write_msr@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1030 <read_msr@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11b9 <write_and_validate_msr+0x89>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%r8d
mov    -0x8(%rbp),%r9d
mov    -0x8(%rbp),%r11d
mov    -0x10(%rbp),%r10
mov    -0x18(%rbp),%rax
lea    0xe66(%rip),%rsi
lea    0xeb9(%rip),%rdx
mov    $0x81,%ecx
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_and_validate_msr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rdx,0x8(%rsp)
call   1050 <write_msr@plt>
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <read_msr@plt>
mov    0x8(%rsp),%rax
cmp    %rbx,%rax
je     1196 <write_and_validate_msr+0x66>
mov    0x2e76(%rip),%rcx
mov    (%rcx),%edi
sub    $0x8,%rsp
lea    0xe89(%rip),%rsi
lea    0xedc(%rip),%rdx
mov    $0x81,%ecx
mov    %ebp,%r8d
mov    %r14d,%r9d
push   %rax
push   %rbx
push   %r14
call   1040 <fprintf@plt>
add    $0x20,%rsp
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [90 x i8] c"%s::%d write_and_validate_msr failed. core=%d, msr=%ld (0x%lx), val=0x%lx, val2=0x%lx.\0A\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pyrovski/powertools/refs/heads/master/msr_core.c\00"
define void @write_and_validate_msr(i32 %0, i32 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
store i64 %8, i64* %7
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = load i64, i64* %6
%12 = call i32 @write_msr(i32 %9, i32 %10, i64 %11)
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call i32 @read_msr(i32 %13, i32 %14, i64* %7)
%16 = load i64, i64* %6
%17 = load i64, i64* %7
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = load i32, i32* %5
%24 = load i64, i64* %6
%25 = load i64, i64* %7
%26 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 129, i32 %21, i32 %22, i32 %23, i64 %24, i64 %25)
br label %27
27: ; preds = %19, %3
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [90 x i8] c"%s::%d write_and_validate_msr failed. core=%d, msr=%ld (0x%lx), val=0x%lx, val2=0x%lx.\0A\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pyrovski/powertools/refs/heads/master/msr_core.c\00"
define void @write_and_validate_msr(i32 %0, i32 %1, i64 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
store i64 %2, i64* %4
%6 = tail call i32 @write_msr(i32 %0, i32 %1, i64 %2)
%7 = call i32 @read_msr(i32 %0, i32 %1, i64* %4)
%8 = load i64, i64* %4
%9 = icmp eq i64 %8, %2
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 129, i32 %0, i32 %1, i32 %1, i64 %2, i64 %8)
br label %13
13: ; preds = %10, %3
ret void
}