#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, unsigned int);
int isst_send_mbox_command(int, int, int, int /*<<< orphan*/, unsigned int,
                           unsigned int *);
int isst_get_get_trl(int cpu, int level, int avx_level, int *trl) {
  unsigned int req, resp;
  int ret;
  req = level | (avx_level << 16);
  ret = isst_send_mbox_command(cpu, 0x7f, 0x07, 0, req, &resp);
  if (ret)
    return ret;
  debug_printf("cpu:%d CONFIG_TDP_GET_TURBO_LIMIT_RATIOS req:%x resp:%x\n", cpu,
               req, resp);
  trl[0] = resp & (((~0UL) << (0)) & (~0UL >> (sizeof(long) * 8 - 1 - (7))));
  trl[1] =
      (resp & (((~0UL) << (8)) & (~0UL >> (sizeof(long) * 8 - 1 - (15))))) >> 8;
  trl[2] =
      (resp & (((~0UL) << (16)) & (~0UL >> (sizeof(long) * 8 - 1 - (23))))) >>
      16;
  trl[3] =
      (resp & (((~0UL) << (24)) & (~0UL >> (sizeof(long) * 8 - 1 - (31))))) >>
      24;
  req = level | (1 << (8)) | (avx_level << 16);
  ret = isst_send_mbox_command(cpu, 0x7f, 0x07, 0, req, &resp);
  if (ret)
    return ret;
  debug_printf("cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\n", cpu, req,
               resp);
  trl[4] = resp & (((~0UL) << (0)) & (~0UL >> (sizeof(long) * 8 - 1 - (7))));
  trl[5] =
      (resp & (((~0UL) << (8)) & (~0UL >> (sizeof(long) * 8 - 1 - (15))))) >> 8;
  trl[6] =
      (resp & (((~0UL) << (16)) & (~0UL >> (sizeof(long) * 8 - 1 - (23))))) >>
      16;
  trl[7] =
      (resp & (((~0UL) << (24)) & (~0UL >> (sizeof(long) * 8 - 1 - (31))))) >>
      24;
  return 0;
}


x86 assembly (clang, -O0):
<isst_get_get_trl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%r8d
mov    $0x7f,%esi
mov    $0x7,%edx
xor    %ecx,%ecx
lea    -0x20(%rbp),%r9
call   1040 <isst_send_mbox_command@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1177 <isst_get_get_trl+0x57>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a4 <isst_get_get_trl+0x184>
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe79(%rip),%rdi
call   1030 <debug_printf@plt>
mov    -0x20(%rbp),%eax
and    $0xff,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
and    $0xff00,%rax
shr    $0x8,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%eax
and    $0xff0000,%rax
shr    $0x10,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x20(%rbp),%eax
movabs $0xff000000,%rcx
and    %rcx,%rax
shr    $0x18,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0xc(%rbp),%eax
or     $0x100,%eax
mov    -0x10(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%r8d
mov    $0x7f,%esi
mov    $0x7,%edx
xor    %ecx,%ecx
lea    -0x20(%rbp),%r9
call   1040 <isst_send_mbox_command@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     122d <isst_get_get_trl+0x10d>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a4 <isst_get_get_trl+0x184>
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xdfc(%rip),%rdi
call   1030 <debug_printf@plt>
mov    -0x20(%rbp),%eax
and    $0xff,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x20(%rbp),%eax
and    $0xff00,%rax
shr    $0x8,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x20(%rbp),%eax
and    $0xff0000,%rax
shr    $0x10,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x20(%rbp),%eax
movabs $0xff000000,%rcx
and    %rcx,%rax
shr    $0x18,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x1c(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isst_get_get_trl>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %edi,%ebx
shl    $0x10,%ebp
or     %esi,%ebp
lea    0xc(%rsp),%r9
mov    $0x7f,%esi
mov    $0x7,%edx
xor    %ecx,%ecx
mov    %ebp,%r8d
call   1040 <isst_send_mbox_command@plt>
test   %eax,%eax
jne    11ed <isst_get_get_trl+0xcd>
mov    0xc(%rsp),%ecx
lea    0xea0(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <debug_printf@plt>
mov    0xc(%rsp),%eax
movzbl %al,%ecx
mov    %ecx,(%r14)
movzbl %ah,%ecx
mov    %ecx,0x4(%r14)
mov    %eax,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,0x8(%r14)
shr    $0x18,%eax
mov    %eax,0xc(%r14)
or     $0x100,%ebp
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    $0x7f,%esi
mov    $0x7,%edx
xor    %ecx,%ecx
mov    %ebp,%r8d
call   1040 <isst_send_mbox_command@plt>
test   %eax,%eax
jne    11ed <isst_get_get_trl+0xcd>
mov    0xc(%rsp),%ecx
lea    0xe7c(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <debug_printf@plt>
mov    0xc(%rsp),%eax
movzbl %al,%ecx
mov    %ecx,0x10(%r14)
movzbl %ah,%ecx
mov    %ecx,0x14(%r14)
mov    %eax,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,0x18(%r14)
shr    $0x18,%eax
mov    %eax,0x1c(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"cpu:%d CONFIG_TDP_GET_TURBO_LIMIT_RATIOS req:%x resp:%x\0A\00"
@.str.1 = [50 x i8] c"cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\0A\00"
define i32 @isst_get_get_trl(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = shl i32 %14, 16
%16 = or i32 %13, %15
store i32 %16, i32* %10
%17 = load i32, i32* %6
%18 = load i32, i32* %10
%19 = call i32 @isst_send_mbox_command(i32 %17, i32 127, i32 7, i32 0, i32 %18, i32* %11)
store i32 %19, i32* %12
%20 = load i32, i32* %12
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %4
%23 = load i32, i32* %12
store i32 %23, i32* %5
br label %100
24: ; preds = %4
%25 = load i32, i32* %6
%26 = load i32, i32* %10
%27 = load i32, i32* %11
%28 = call i32 @debug_printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26, i32 %27)
%29 = load i32, i32* %11
%30 = zext i32 %29 to i64
%31 = and i64 %30, 255
%32 = trunc i64 %31 to i32
%33 = load i32*, i32** %9
%34 = getelementptr inbounds i32, i32* %33, i64 0
store i32 %32, i32* %34
%35 = load i32, i32* %11
%36 = zext i32 %35 to i64
%37 = and i64 %36, 65280
%38 = lshr i64 %37, 8
%39 = trunc i64 %38 to i32
%40 = load i32*, i32** %9
%41 = getelementptr inbounds i32, i32* %40, i64 1
store i32 %39, i32* %41
%42 = load i32, i32* %11
%43 = zext i32 %42 to i64
%44 = and i64 %43, 16711680
%45 = lshr i64 %44, 16
%46 = trunc i64 %45 to i32
%47 = load i32*, i32** %9
%48 = getelementptr inbounds i32, i32* %47, i64 2
store i32 %46, i32* %48
%49 = load i32, i32* %11
%50 = zext i32 %49 to i64
%51 = and i64 %50, 4278190080
%52 = lshr i64 %51, 24
%53 = trunc i64 %52 to i32
%54 = load i32*, i32** %9
%55 = getelementptr inbounds i32, i32* %54, i64 3
store i32 %53, i32* %55
%56 = load i32, i32* %7
%57 = or i32 %56, 256
%58 = load i32, i32* %8
%59 = shl i32 %58, 16
%60 = or i32 %57, %59
store i32 %60, i32* %10
%61 = load i32, i32* %6
%62 = load i32, i32* %10
%63 = call i32 @isst_send_mbox_command(i32 %61, i32 127, i32 7, i32 0, i32 %62, i32* %11)
store i32 %63, i32* %12
%64 = load i32, i32* %12
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %24
%67 = load i32, i32* %12
store i32 %67, i32* %5
br label %100
68: ; preds = %24
%69 = load i32, i32* %6
%70 = load i32, i32* %10
%71 = load i32, i32* %11
%72 = call i32 @debug_printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %69, i32 %70, i32 %71)
%73 = load i32, i32* %11
%74 = zext i32 %73 to i64
%75 = and i64 %74, 255
%76 = trunc i64 %75 to i32
%77 = load i32*, i32** %9
%78 = getelementptr inbounds i32, i32* %77, i64 4
store i32 %76, i32* %78
%79 = load i32, i32* %11
%80 = zext i32 %79 to i64
%81 = and i64 %80, 65280
%82 = lshr i64 %81, 8
%83 = trunc i64 %82 to i32
%84 = load i32*, i32** %9
%85 = getelementptr inbounds i32, i32* %84, i64 5
store i32 %83, i32* %85
%86 = load i32, i32* %11
%87 = zext i32 %86 to i64
%88 = and i64 %87, 16711680
%89 = lshr i64 %88, 16
%90 = trunc i64 %89 to i32
%91 = load i32*, i32** %9
%92 = getelementptr inbounds i32, i32* %91, i64 6
store i32 %90, i32* %92
%93 = load i32, i32* %11
%94 = zext i32 %93 to i64
%95 = and i64 %94, 4278190080
%96 = lshr i64 %95, 24
%97 = trunc i64 %96 to i32
%98 = load i32*, i32** %9
%99 = getelementptr inbounds i32, i32* %98, i64 7
store i32 %97, i32* %99
store i32 0, i32* %5
br label %100
100: ; preds = %68, %66, %22
%101 = load i32, i32* %5
ret i32 %101
}

LLVM IR (-O2):
@.str = [57 x i8] c"cpu:%d CONFIG_TDP_GET_TURBO_LIMIT_RATIOS req:%x resp:%x\0A\00"
@.str.1 = [50 x i8] c"cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\0A\00"
define i32 @isst_get_get_trl(i32 %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = shl i32 %2, 16
%8 = or i32 %7, %1
%9 = call i32 @isst_send_mbox_command(i32 %0, i32 127, i32 7, i32 0, i32 %8, i32* %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %41
11: ; preds = %4
%12 = load i32, i32* %5
%13 = call i32 @debug_printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %8, i32 %12)
%14 = load i32, i32* %5
%15 = and i32 %14, 255
store i32 %15, i32* %3
%16 = lshr i32 %14, 8
%17 = and i32 %16, 255
%18 = getelementptr inbounds i32, i32* %3, i64 1
store i32 %17, i32* %18
%19 = lshr i32 %14, 16
%20 = and i32 %19, 255
%21 = getelementptr inbounds i32, i32* %3, i64 2
store i32 %20, i32* %21
%22 = lshr i32 %14, 24
%23 = getelementptr inbounds i32, i32* %3, i64 3
store i32 %22, i32* %23
%24 = or i32 %8, 256
%25 = call i32 @isst_send_mbox_command(i32 %0, i32 127, i32 7, i32 0, i32 %24, i32* %5)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %41
27: ; preds = %11
%28 = load i32, i32* %5
%29 = call i32 @debug_printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %24, i32 %28)
%30 = load i32, i32* %5
%31 = and i32 %30, 255
%32 = getelementptr inbounds i32, i32* %3, i64 4
store i32 %31, i32* %32
%33 = lshr i32 %30, 8
%34 = and i32 %33, 255
%35 = getelementptr inbounds i32, i32* %3, i64 5
store i32 %34, i32* %35
%36 = lshr i32 %30, 16
%37 = and i32 %36, 255
%38 = getelementptr inbounds i32, i32* %3, i64 6
store i32 %37, i32* %38
%39 = lshr i32 %30, 24
%40 = getelementptr inbounds i32, i32* %3, i64 7
store i32 %39, i32* %40
br label %41
41: ; preds = %11, %4, %27
%42 = phi i32 [ 0, %27 ], [ %9, %4 ], [ %25, %11 ]
ret i32 %42
}