#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, ...);
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)) {
    debug_printf("cpu: tdp_locked %d\n", cpu);
    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    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <debug_printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <isst_get_config_tdp_lock_status@plt>
cmp    $0x0,%rax
je     1189 <isst_set_tdp_level_msr+0x59>
mov    -0x8(%rbp),%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <debug_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <isst_set_tdp_level_msr+0xb8>
cmpl   $0x2,-0xc(%rbp)
jle    119f <isst_set_tdp_level_msr+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <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     11cd <isst_set_tdp_level_msr+0x9d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <isst_set_tdp_level_msr+0xb8>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
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   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
movslq %esi,%rdx
mov    %rdx,0x8(%rsp)
lea    0xeb4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <debug_printf@plt>
mov    %ebx,%edi
call   1050 <isst_get_config_tdp_lock_status@plt>
test   %rax,%rax
je     1178 <isst_set_tdp_level_msr+0x48>
lea    0xeb3(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <debug_printf@plt>
mov    $0xffffffff,%ebp
jmp    11b4 <isst_set_tdp_level_msr+0x84>
mov    $0xffffffff,%ebp
cmp    $0x2,%r14d
jg     11b4 <isst_set_tdp_level_msr+0x84>
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    $0x64b,%esi
mov    $0x1,%edx
call   1040 <isst_send_msr_command@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11b4 <isst_set_tdp_level_msr+0x84>
lea    0xe89(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <debug_printf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"cpu: tdp_level via MSR %d\0A\00"
@.str.1 = [20 x i8] c"cpu: tdp_locked %d\0A\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 (i8*, 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 %19
16: ; preds = %2
%17 = load i32, i32* %4
%18 = call i32 (i8*, i32, ...) @debug_printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %17)
store i32 -1, i32* %3
br label %34
19: ; preds = %2
%20 = load i32, i32* %5
%21 = icmp sgt i32 %20, 2
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 -1, i32* %3
br label %34
23: ; preds = %19
%24 = load i32, i32* %4
%25 = call i32 @isst_send_msr_command(i32 %24, i32 1611, i32 1, i64* %6)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = load i32, i32* %7
store i32 %29, i32* %3
br label %34
30: ; preds = %23
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = call i32 (i8*, i32, ...) @debug_printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %32)
store i32 0, i32* %3
br label %34
34: ; preds = %30, %28, %22, %16
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [27 x i8] c"cpu: tdp_level via MSR %d\0A\00"
@.str.1 = [20 x i8] c"cpu: tdp_locked %d\0A\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 (i8*, 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 (i8*, i32, ...) @debug_printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 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 (i8*, 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
}