#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*/ isst_display_error_info_message(int, char *, int, int);
scalar_t__ isst_get_config_tdp_lock_status(int);
int isst_send_mbox_command(int, int, int, int /*<<< orphan*/, int,
                           unsigned int *);
int isst_set_tdp_level(int cpu, int tdp_level) {
  unsigned int resp;
  int ret;
  if (isst_get_config_tdp_lock_status(cpu)) {
    isst_display_error_info_message(1, "TDP is locked", 0, 0);
    return -1;
  }
  ret = isst_send_mbox_command(cpu, 0x7f, 0x08, 0, tdp_level, &resp);
  if (ret) {
    isst_display_error_info_message(1, "Set TDP level failed for level", 1,
                                    tdp_level);
    return ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<isst_set_tdp_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <isst_get_config_tdp_lock_status@plt>
cmp    $0x0,%rax
je     1171 <isst_set_tdp_level+0x41>
mov    $0x1,%edi
lea    0xea4(%rip),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <isst_display_error_info_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <isst_set_tdp_level+0x92>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%r8d
mov    $0x7f,%esi
mov    $0x8,%edx
xor    %ecx,%ecx
lea    -0x10(%rbp),%r9
call   1040 <isst_send_mbox_command@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11bb <isst_set_tdp_level+0x8b>
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
lea    0xe65(%rip),%rsi
mov    %edx,%edi
call   1050 <isst_display_error_info_message@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <isst_set_tdp_level+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isst_set_tdp_level>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebx
call   1030 <isst_get_config_tdp_lock_status@plt>
test   %rax,%rax
je     1162 <isst_set_tdp_level+0x32>
lea    0xeb3(%rip),%rsi
mov    $0x1,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <isst_display_error_info_message@plt>
mov    $0xffffffff,%ebp
jmp    11a2 <isst_set_tdp_level+0x72>
xor    %ebp,%ebp
lea    0x4(%rsp),%r9
mov    %ebx,%edi
mov    $0x7f,%esi
mov    $0x8,%edx
xor    %ecx,%ecx
mov    %r15d,%r8d
call   1040 <isst_send_mbox_command@plt>
test   %eax,%eax
je     11a2 <isst_set_tdp_level+0x72>
mov    %eax,%r14d
lea    0xe81(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
mov    %r15d,%ecx
call   1050 <isst_display_error_info_message@plt>
mov    %r14d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"TDP is locked\00"
@.str.1 = [31 x i8] c"Set TDP level failed for level\00"
define i32 @isst_set_tdp_level(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = call i64 @isst_get_config_tdp_lock_status(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @isst_display_error_info_message(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
store i32 -1, i32* %3
br label %24
13: ; preds = %2
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = call i32 @isst_send_mbox_command(i32 %14, i32 127, i32 8, i32 0, i32 %15, i32* %6)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32, i32* %5
%21 = call i32 @isst_display_error_info_message(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %20)
%22 = load i32, i32* %7
store i32 %22, i32* %3
br label %24
23: ; preds = %13
store i32 0, i32* %3
br label %24
24: ; preds = %23, %19, %11
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [14 x i8] c"TDP is locked\00"
@.str.1 = [31 x i8] c"Set TDP level failed for level\00"
define i32 @isst_set_tdp_level(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 @isst_get_config_tdp_lock_status(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @isst_display_error_info_message(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
br label %14
9: ; preds = %2
%10 = call i32 @isst_send_mbox_command(i32 %0, i32 127, i32 8, i32 0, i32 %1, i32* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @isst_display_error_info_message(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %1)
br label %14
14: ; preds = %9, %12, %7
%15 = phi i32 [ -1, %7 ], [ %10, %12 ], [ 0, %9 ]
ret i32 %15
}