#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 */
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ read_msr_single_core(int, int /*<<< orphan*/,
                                        int /*<<< orphan*/,
                                        int /*<<< orphan*/ *);
void read_msr_all_cores_v(int socket, off_t msr, uint64_t *val) {
  int j;
  for (j = 0; j < 8; j++) {
    read_msr_single_core(socket, 0, msr, &val[j]);
  }
}


x86 assembly (clang, -O0):
<read_msr_all_cores_v>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    115d <read_msr_all_cores_v+0x4d>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
xor    %esi,%esi
call   1030 <read_msr_single_core@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <read_msr_all_cores_v+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_msr_all_cores_v>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
xor    %esi,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1030 <read_msr_single_core@plt>
lea    0x4(%rbx),%rcx
mov    %ebp,%edi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <read_msr_single_core@plt>
lea    0x8(%rbx),%rcx
mov    %ebp,%edi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <read_msr_single_core@plt>
lea    0xc(%rbx),%rcx
mov    %ebp,%edi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <read_msr_single_core@plt>
lea    0x10(%rbx),%rcx
mov    %ebp,%edi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <read_msr_single_core@plt>
lea    0x14(%rbx),%rcx
mov    %ebp,%edi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <read_msr_single_core@plt>
lea    0x18(%rbx),%rcx
mov    %ebp,%edi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <read_msr_single_core@plt>
add    $0x1c,%rbx
mov    %ebp,%edi
xor    %esi,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <read_msr_single_core@plt>

LLVM IR (-O0):
define void @read_msr_all_cores_v(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %8
8: ; preds = %19, %3
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 8
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = load i32*, i32** %6
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = call i32 @read_msr_single_core(i32 %12, i32 0, i32 %13, i32* %17)
br label %19
19: ; preds = %11
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
br label %8
22: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @read_msr_all_cores_v(i32 %0, i32 %1, i32* %2) {
%4 = tail call i32 @read_msr_single_core(i32 %0, i32 0, i32 %1, i32* %2)
%5 = getelementptr inbounds i32, i32* %2, i64 1
%6 = tail call i32 @read_msr_single_core(i32 %0, i32 0, i32 %1, i32* %5)
%7 = getelementptr inbounds i32, i32* %2, i64 2
%8 = tail call i32 @read_msr_single_core(i32 %0, i32 0, i32 %1, i32* %7)
%9 = getelementptr inbounds i32, i32* %2, i64 3
%10 = tail call i32 @read_msr_single_core(i32 %0, i32 0, i32 %1, i32* %9)
%11 = getelementptr inbounds i32, i32* %2, i64 4
%12 = tail call i32 @read_msr_single_core(i32 %0, i32 0, i32 %1, i32* %11)
%13 = getelementptr inbounds i32, i32* %2, i64 5
%14 = tail call i32 @read_msr_single_core(i32 %0, i32 0, i32 %1, i32* %13)
%15 = getelementptr inbounds i32, i32* %2, i64 6
%16 = tail call i32 @read_msr_single_core(i32 %0, i32 0, i32 %1, i32* %15)
%17 = getelementptr inbounds i32, i32* %2, i64 7
%18 = tail call i32 @read_msr_single_core(i32 %0, i32 0, i32 %1, i32* %17)
ret void
}