#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 /*<<< orphan*/ debug_printf(char *, int, int);
int /*<<< orphan*/ isst_display_error_info_message(int, char *,
                                                   int /*<<< orphan*/,
                                                   int /*<<< orphan*/);
scalar_t__ isst_get_config_tdp_lock_status(int);
int isst_send_msr_command(int, int, int, unsigned long long *);
int isst_set_tdp_level_msr(int cpu, int tdp_level) {
  unsigned long long level = tdp_level;
  int ret;
  debug_printf("cpu: tdp_level via MSR %d\n", cpu, tdp_level);
  if (isst_get_config_tdp_lock_status(cpu)) {
    isst_display_error_info_message(1, "tdp_locked", 0, 0);
    return -1;
  }
  if (tdp_level > 2)
    return -1;
  ret = isst_send_msr_command(cpu, 0x64b, 1, &level);
  if (ret)
    return ret;
  debug_printf("cpu: tdp_level via MSR successful %d\n", cpu, tdp_level);
  return 0;
}


x86 assembly (clang, -O0):
<isst_set_tdp_level_msr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe9d(%rip),%rdi
call   1030 <debug_printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <isst_get_config_tdp_lock_status@plt>
cmp    $0x0,%rax
je     119b <isst_set_tdp_level_msr+0x5b>
mov    $0x1,%edi
lea    0xe95(%rip),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <isst_display_error_info_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <isst_set_tdp_level_msr+0xb8>
cmpl   $0x2,-0xc(%rbp)
jle    11b1 <isst_set_tdp_level_msr+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <isst_set_tdp_level_msr+0xb8>
mov    -0x8(%rbp),%edi
mov    $0x64b,%esi
mov    $0x1,%edx
lea    -0x18(%rbp),%rcx
call   1040 <isst_send_msr_command@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11df <isst_set_tdp_level_msr+0x9f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f8 <isst_set_tdp_level_msr+0xb8>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe3a(%rip),%rdi
call   1030 <debug_printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isst_set_tdp_level_msr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
movslq %esi,%rdx
mov    %rdx,(%rsp)
lea    0xeab(%rip),%rdi
mov    %ebp,%esi
call   1030 <debug_printf@plt>
mov    %ebp,%edi
call   1050 <isst_get_config_tdp_lock_status@plt>
test   %rax,%rax
je     1184 <isst_set_tdp_level_msr+0x44>
lea    0xeac(%rip),%rsi
mov    $0x1,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <isst_display_error_info_message@plt>
mov    $0xffffffff,%eax
jmp    11b8 <isst_set_tdp_level_msr+0x78>
mov    $0xffffffff,%eax
cmp    $0x2,%ebx
jg     11b8 <isst_set_tdp_level_msr+0x78>
mov    %rsp,%rcx
mov    %ebp,%edi
mov    $0x64b,%esi
mov    $0x1,%edx
call   1040 <isst_send_msr_command@plt>
test   %eax,%eax
jne    11b8 <isst_set_tdp_level_msr+0x78>
lea    0xe79(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <debug_printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"cpu: tdp_level via MSR %d\0A\00"
@.str.1 = [11 x i8] c"tdp_locked\00"
@.str.2 = [38 x i8] c"cpu: tdp_level via MSR successful %d\0A\00"
define i32 @isst_set_tdp_level_msr(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
store i64 %9, i64* %6
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = call i32 @debug_printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
%13 = load i32, i32* %4
%14 = call i64 @isst_get_config_tdp_lock_status(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @isst_display_error_info_message(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0)
store i32 -1, i32* %3
br label %33
18: ; preds = %2
%19 = load i32, i32* %5
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 -1, i32* %3
br label %33
22: ; preds = %18
%23 = load i32, i32* %4
%24 = call i32 @isst_send_msr_command(i32 %23, i32 1611, i32 1, i64* %6)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = load i32, i32* %7
store i32 %28, i32* %3
br label %33
29: ; preds = %22
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = call i32 @debug_printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %31)
store i32 0, i32* %3
br label %33
33: ; preds = %29, %27, %21, %16
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [27 x i8] c"cpu: tdp_level via MSR %d\0A\00"
@.str.1 = [11 x i8] c"tdp_locked\00"
@.str.2 = [38 x i8] c"cpu: tdp_level via MSR successful %d\0A\00"
define i32 @isst_set_tdp_level_msr(i32 %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = sext i32 %1 to i64
store i64 %5, i64* %3
%6 = tail call i32 @debug_printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%7 = tail call i64 @isst_get_config_tdp_lock_status(i32 %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @isst_display_error_info_message(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0)
br label %18
11: ; preds = %2
%12 = icmp sgt i32 %1, 2
br i1 %12, label %18, label %13
13: ; preds = %11
%14 = call i32 @isst_send_msr_command(i32 %0, i32 1611, i32 1, i64* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @debug_printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %1)
br label %18
18: ; preds = %13, %11, %16, %9
%19 = phi i32 [ -1, %9 ], [ 0, %16 ], [ -1, %11 ], [ %14, %13 ]
ret i32 %19
}