#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, unsigned int);
int isst_send_mbox_command(int, int, int, int /*<<< orphan*/,
                           int /*<<< orphan*/, unsigned int *);
int isst_read_pm_config(int cpu, int *cp_state, int *cp_cap) {
  unsigned int resp;
  int ret;
  ret = isst_send_mbox_command(cpu, 0x94, 0x03, 0, 0, &resp);
  if (ret)
    return ret;
  debug_printf("cpu:%d READ_PM_CONFIG resp:%x\n", cpu, resp);
  *cp_state = resp & (1 << (16));
  *cp_cap = resp & (1 << (0)) ? 1 : 0;
  return 0;
}


x86 assembly (clang, -O0):
<isst_read_pm_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x94,%esi
mov    $0x3,%edx
xor    %r8d,%r8d
lea    -0x1c(%rbp),%r9
mov    %r8d,%ecx
call   1040 <isst_send_mbox_command@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1167 <isst_read_pm_config+0x47>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <isst_read_pm_config+0x88>
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe8c(%rip),%rdi
call   1030 <debug_printf@plt>
mov    -0x1c(%rbp),%ecx
and    $0x10000,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%edx
and    $0x1,%edx
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    $0x0,%edx
cmovne %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isst_read_pm_config>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
lea    0x4(%rsp),%r9
mov    $0x94,%esi
mov    $0x3,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <isst_send_mbox_command@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1175 <isst_read_pm_config+0x55>
mov    0x4(%rsp),%edx
lea    0xea7(%rip),%rdi
mov    %ebp,%esi
call   1030 <debug_printf@plt>
mov    0x4(%rsp),%eax
mov    %eax,%ecx
and    $0x10000,%ecx
mov    %ecx,(%r15)
and    $0x1,%eax
mov    %eax,(%r14)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"cpu:%d READ_PM_CONFIG resp:%x\0A\00"
define i32 @isst_read_pm_config(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%10 = load i32, i32* %5
%11 = call i32 @isst_send_mbox_command(i32 %10, i32 148, i32 3, i32 0, i32 0, i32* %8)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i32, i32* %9
store i32 %15, i32* %4
br label %29
16: ; preds = %3
%17 = load i32, i32* %5
%18 = load i32, i32* %8
%19 = call i32 @debug_printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
%20 = load i32, i32* %8
%21 = and i32 %20, 65536
%22 = load i32*, i32** %6
store i32 %21, i32* %22
%23 = load i32, i32* %8
%24 = and i32 %23, 1
%25 = icmp ne i32 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 1, i32 0
%28 = load i32*, i32** %7
store i32 %27, i32* %28
store i32 0, i32* %4
br label %29
29: ; preds = %16, %14
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@.str = [31 x i8] c"cpu:%d READ_PM_CONFIG resp:%x\0A\00"
define i32 @isst_read_pm_config(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 @isst_send_mbox_command(i32 %0, i32 148, i32 3, i32 0, i32 0, i32* %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %3
%9 = load i32, i32* %4
%10 = call i32 @debug_printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %9)
%11 = load i32, i32* %4
%12 = and i32 %11, 65536
store i32 %12, i32* %1
%13 = and i32 %11, 1
store i32 %13, i32* %2
br label %14
14: ; preds = %3, %8
ret i32 %6
}