#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 */

/* Variables and functions */
int Get_Bits_Value(unsigned long, int, int);
unsigned long get_msr_value(int, int, int, int /*<<< orphan*/, int *);
int Read_Thermal_Status_CPU(int cpu_num) {
  int error_indx;
  unsigned long val = get_msr_value(cpu_num, 0x19C, 63, 0, &error_indx);
  int digital_readout = Get_Bits_Value(val, 23, 16);
  int thermal_status = Get_Bits_Value(val, 32, 31);
  val = get_msr_value(cpu_num, 0x1a2, 63, 0, &error_indx);
  int PROCHOT_temp = Get_Bits_Value(val, 23, 16);
  if (thermal_status)
    return (PROCHOT_temp - digital_readout);
  else
    return (-1);
}


x86 assembly (clang, -O0):
<Read_Thermal_Status_CPU>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x19c,%esi
mov    $0x3f,%edx
xor    %ecx,%ecx
lea    -0xc(%rbp),%r8
call   1030 <get_msr_value@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x17,%esi
mov    $0x10,%edx
call   1040 <Get_Bits_Value@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
mov    $0x1f,%edx
call   1040 <Get_Bits_Value@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1a2,%esi
mov    $0x3f,%edx
xor    %ecx,%ecx
lea    -0xc(%rbp),%r8
call   1030 <get_msr_value@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x17,%esi
mov    $0x10,%edx
call   1040 <Get_Bits_Value@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11bd <Read_Thermal_Status_CPU+0x9d>
mov    -0x24(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <Read_Thermal_Status_CPU+0xa4>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Read_Thermal_Status_CPU>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0x4(%rsp),%r14
mov    $0x19c,%esi
mov    $0x3f,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1030 <get_msr_value@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x17,%esi
mov    $0x10,%edx
call   1040 <Get_Bits_Value@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    $0x20,%esi
mov    $0x1f,%edx
call   1040 <Get_Bits_Value@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    $0x1a2,%esi
mov    $0x3f,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1030 <get_msr_value@plt>
mov    %rax,%rdi
mov    $0x17,%esi
mov    $0x10,%edx
call   1040 <Get_Bits_Value@plt>
sub    %r15d,%eax
cmp    $0x1,%ebx
sbb    %ecx,%ecx
or     %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Read_Thermal_Status_CPU(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
%9 = load i32, i32* %3
%10 = call i64 @get_msr_value(i32 %9, i32 412, i32 63, i32 0, i32* %4)
store i64 %10, i64* %5
%11 = load i64, i64* %5
%12 = call i32 @Get_Bits_Value(i64 %11, i32 23, i32 16)
store i32 %12, i32* %6
%13 = load i64, i64* %5
%14 = call i32 @Get_Bits_Value(i64 %13, i32 32, i32 31)
store i32 %14, i32* %7
%15 = load i32, i32* %3
%16 = call i64 @get_msr_value(i32 %15, i32 418, i32 63, i32 0, i32* %4)
store i64 %16, i64* %5
%17 = load i64, i64* %5
%18 = call i32 @Get_Bits_Value(i64 %17, i32 23, i32 16)
store i32 %18, i32* %8
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %1
%22 = load i32, i32* %8
%23 = load i32, i32* %6
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %2
br label %26
25: ; preds = %1
store i32 -1, i32* %2
br label %26
26: ; preds = %25, %21
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @Read_Thermal_Status_CPU(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i64 @get_msr_value(i32 %0, i32 412, i32 63, i32 0, i32* %2)
%5 = call i32 @Get_Bits_Value(i64 %4, i32 23, i32 16)
%6 = call i32 @Get_Bits_Value(i64 %4, i32 32, i32 31)
%7 = call i64 @get_msr_value(i32 %0, i32 418, i32 63, i32 0, i32* %2)
%8 = call i32 @Get_Bits_Value(i64 %7, i32 23, i32 16)
%9 = icmp eq i32 %6, 0
%10 = sub nsw i32 %8, %5
%11 = select i1 %9, i32 -1, i32 %10
ret i32 %11
}