#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*/ write_msr_single_core(int, int, int /*<<< orphan*/,
                                         int /*<<< orphan*/);
void write_msr_all_cores_v(int socket, off_t msr, uint64_t *val) {
  int j;
  for (j = 0; j < 8; j++) {
    write_msr_single_core(socket, j, msr, val[j]);
  }
}


x86 assembly (clang, -O0):
<write_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    115a <write_msr_all_cores_v+0x4a>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
call   1030 <write_msr_single_core@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <write_msr_all_cores_v+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_msr_all_cores_v>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    (%rdx),%ecx
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <write_msr_single_core@plt>
mov    0x4(%rbx),%ecx
mov    %ebp,%edi
mov    $0x1,%esi
mov    %r14d,%edx
call   1030 <write_msr_single_core@plt>
mov    0x8(%rbx),%ecx
mov    %ebp,%edi
mov    $0x2,%esi
mov    %r14d,%edx
call   1030 <write_msr_single_core@plt>
mov    0xc(%rbx),%ecx
mov    %ebp,%edi
mov    $0x3,%esi
mov    %r14d,%edx
call   1030 <write_msr_single_core@plt>
mov    0x10(%rbx),%ecx
mov    %ebp,%edi
mov    $0x4,%esi
mov    %r14d,%edx
call   1030 <write_msr_single_core@plt>
mov    0x14(%rbx),%ecx
mov    %ebp,%edi
mov    $0x5,%esi
mov    %r14d,%edx
call   1030 <write_msr_single_core@plt>
mov    0x18(%rbx),%ecx
mov    %ebp,%edi
mov    $0x6,%esi
mov    %r14d,%edx
call   1030 <write_msr_single_core@plt>
mov    0x1c(%rbx),%ecx
mov    %ebp,%edi
mov    $0x7,%esi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <write_msr_single_core@plt>

LLVM IR (-O0):
define void @write_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 = %21, %3
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 8
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i32, i32* %7
%14 = load i32, i32* %5
%15 = load i32*, i32** %6
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @write_msr_single_core(i32 %12, i32 %13, i32 %14, i32 %19)
br label %21
21: ; preds = %11
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %8
24: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @write_msr_all_cores_v(i32 %0, i32 %1, i32* nocapture %2) {
%4 = load i32, i32* %2
%5 = tail call i32 @write_msr_single_core(i32 %0, i32 0, i32 %1, i32 %4)
%6 = getelementptr inbounds i32, i32* %2, i64 1
%7 = load i32, i32* %6
%8 = tail call i32 @write_msr_single_core(i32 %0, i32 1, i32 %1, i32 %7)
%9 = getelementptr inbounds i32, i32* %2, i64 2
%10 = load i32, i32* %9
%11 = tail call i32 @write_msr_single_core(i32 %0, i32 2, i32 %1, i32 %10)
%12 = getelementptr inbounds i32, i32* %2, i64 3
%13 = load i32, i32* %12
%14 = tail call i32 @write_msr_single_core(i32 %0, i32 3, i32 %1, i32 %13)
%15 = getelementptr inbounds i32, i32* %2, i64 4
%16 = load i32, i32* %15
%17 = tail call i32 @write_msr_single_core(i32 %0, i32 4, i32 %1, i32 %16)
%18 = getelementptr inbounds i32, i32* %2, i64 5
%19 = load i32, i32* %18
%20 = tail call i32 @write_msr_single_core(i32 %0, i32 5, i32 %1, i32 %19)
%21 = getelementptr inbounds i32, i32* %2, i64 6
%22 = load i32, i32* %21
%23 = tail call i32 @write_msr_single_core(i32 %0, i32 6, i32 %1, i32 %22)
%24 = getelementptr inbounds i32, i32* %2, i64 7
%25 = load i32, i32* %24
%26 = tail call i32 @write_msr_single_core(i32 %0, i32 7, i32 %1, i32 %25)
ret void
}