#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 isst_send_mbox_command(int, int, int, int, unsigned int, unsigned int *);
int isst_pm_qos_config(int cpu, int enable_clos, int priority_type) {
  unsigned int req, resp;
  int ret;
  ret = isst_send_mbox_command(cpu, 0xd0, 0x02, 0, 0, &resp);
  if (ret)
    return ret;
  debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", cpu, resp);
  req = resp;
  if (enable_clos)
    req = req | (1 << (1));
  else
    req = req & ~(1 << (1));
  if (priority_type)
    req = req | (1 << (2));
  else
    req = req & ~(1 << (2));
  ret = isst_send_mbox_command(cpu, 0xd0, 0x02, (1 << (0x08)), req, &resp);
  if (ret)
    return ret;
  debug_printf("cpu:%d CLOS_PM_QOS_CONFIG priority type:%d req:%x\n", cpu,
               priority_type, req);
  return 0;
}


x86 assembly (clang, -O0):
<isst_pm_qos_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xd0,%esi
mov    $0x2,%edx
xor    %r8d,%r8d
lea    -0x18(%rbp),%r9
mov    %r8d,%ecx
call   1040 <isst_send_mbox_command@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1165 <isst_pm_qos_config+0x45>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1216 <isst_pm_qos_config+0xf6>
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <debug_printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1197 <isst_pm_qos_config+0x77>
mov    -0x14(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    11a0 <isst_pm_qos_config+0x80>
mov    -0x14(%rbp),%eax
and    $0xfffffffd,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11b8 <isst_pm_qos_config+0x98>
mov    -0x14(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    11c1 <isst_pm_qos_config+0xa1>
mov    -0x14(%rbp),%eax
and    $0xfffffffb,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%r8d
mov    $0xd0,%esi
mov    $0x2,%edx
mov    $0x100,%ecx
lea    -0x18(%rbp),%r9
call   1040 <isst_send_mbox_command@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11f8 <isst_pm_qos_config+0xd8>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1216 <isst_pm_qos_config+0xf6>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe1b(%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_pm_qos_config>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xc(%rsp),%r9
mov    $0xd0,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <isst_send_mbox_command@plt>
test   %eax,%eax
jne    11b6 <isst_pm_qos_config+0x96>
mov    0xc(%rsp),%edx
lea    0xea9(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <debug_printf@plt>
mov    0xc(%rsp),%eax
xor    %ecx,%ecx
test   %ebx,%ebx
setne  %cl
and    $0xfffffff9,%eax
add    %ecx,%ecx
xor    %edx,%edx
test   %r14d,%r14d
setne  %dl
lea    (%rcx,%rdx,4),%ebx
or     %eax,%ebx
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    $0xd0,%esi
mov    $0x2,%edx
mov    $0x100,%ecx
mov    %ebx,%r8d
call   1040 <isst_send_mbox_command@plt>
test   %eax,%eax
jne    11b6 <isst_pm_qos_config+0x96>
lea    0xe7d(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <debug_printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"cpu:%d CLOS_PM_QOS_CONFIG resp:%x\0A\00"
@.str.1 = [51 x i8] c"cpu:%d CLOS_PM_QOS_CONFIG priority type:%d req:%x\0A\00"
define i32 @isst_pm_qos_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
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* %5
%12 = call i32 @isst_send_mbox_command(i32 %11, i32 208, i32 2, i32 0, i32 0, i32* %9)
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %10
store i32 %16, i32* %4
br label %52
17: ; preds = %3
%18 = load i32, i32* %5
%19 = load i32, i32* %9
%20 = call i32 (i8*, i32, i32, ...) @debug_printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
%21 = load i32, i32* %9
store i32 %21, i32* %8
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32, i32* %8
%26 = or i32 %25, 2
store i32 %26, i32* %8
br label %30
27: ; preds = %17
%28 = load i32, i32* %8
%29 = and i32 %28, -3
store i32 %29, i32* %8
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %7
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %8
%35 = or i32 %34, 4
store i32 %35, i32* %8
br label %39
36: ; preds = %30
%37 = load i32, i32* %8
%38 = and i32 %37, -5
store i32 %38, i32* %8
br label %39
39: ; preds = %36, %33
%40 = load i32, i32* %5
%41 = load i32, i32* %8
%42 = call i32 @isst_send_mbox_command(i32 %40, i32 208, i32 2, i32 256, i32 %41, i32* %9)
store i32 %42, i32* %10
%43 = load i32, i32* %10
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = load i32, i32* %10
store i32 %46, i32* %4
br label %52
47: ; preds = %39
%48 = load i32, i32* %5
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = call i32 (i8*, i32, i32, ...) @debug_printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %48, i32 %49, i32 %50)
store i32 0, i32* %4
br label %52
52: ; preds = %47, %45, %15
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
@.str = [35 x i8] c"cpu:%d CLOS_PM_QOS_CONFIG resp:%x\0A\00"
@.str.1 = [51 x i8] c"cpu:%d CLOS_PM_QOS_CONFIG priority type:%d req:%x\0A\00"
define i32 @isst_pm_qos_config(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 @isst_send_mbox_command(i32 %0, i32 208, i32 2, i32 0, i32 0, i32* %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %3
%9 = load i32, i32* %4
%10 = call i32 (i8*, i32, i32, ...) @debug_printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %9)
%11 = load i32, i32* %4
%12 = icmp eq i32 %1, 0
%13 = and i32 %11, -7
%14 = select i1 %12, i32 0, i32 2
%15 = icmp eq i32 %2, 0
%16 = select i1 %15, i32 0, i32 4
%17 = or i32 %16, %14
%18 = or i32 %17, %13
%19 = call i32 @isst_send_mbox_command(i32 %0, i32 208, i32 2, i32 256, i32 %18, i32* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %8
%22 = call i32 (i8*, i32, i32, ...) @debug_printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %2, i32 %18)
br label %23
23: ; preds = %8, %3, %21
%24 = phi i32 [ 0, %21 ], [ %6, %3 ], [ %19, %8 ]
ret i32 %24
}