#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct kvm_cpuid_entry {
  int dummy;
};
struct kvm_cpuid2 {
  int nent;
  TYPE_1__ *entries;
};
typedef void *__u32;
struct TYPE_2__ {
  void *edx;
  void *ecx;
  void *ebx;
  void *eax;
  void *flags;
  void *index;
  void *function;
};

/* Variables and functions */
int ENOMEM;
int cpuid_set(void *data, int size, int n, __u32 function, __u32 index,
              __u32 flags, __u32 eax, __u32 ebx, __u32 ecx, __u32 edx) {
  struct kvm_cpuid2 *cpuid = (struct kvm_cpuid2 *)data;
  if ((sizeof(struct kvm_cpuid2) + (n + 1) * sizeof(struct kvm_cpuid_entry)) >
      size) {
    return ENOMEM;
  }
  cpuid->entries[n].function = function;
  cpuid->entries[n].index = index;
  cpuid->entries[n].flags = flags;
  cpuid->entries[n].eax = eax;
  cpuid->entries[n].ebx = ebx;
  cpuid->entries[n].ecx = ecx;
  cpuid->entries[n].edx = edx;
  cpuid->nent = n + 1;
  return 0;
}


x86 assembly (clang, -O0):
<cpuid_set>:
push   %rbp
mov    %rsp,%rbp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    $0x10,%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jbe    1160 <cpuid_set+0x60>
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122f <cpuid_set+0x12f>
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x18(%rbp),%rdx
imul   $0x38,%rdx,%rdx
add    %rdx,%rax
mov    %rcx,0x30(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x18(%rbp),%rdx
imul   $0x38,%rdx,%rdx
add    %rdx,%rax
mov    %rcx,0x28(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x18(%rbp),%rdx
imul   $0x38,%rdx,%rdx
add    %rdx,%rax
mov    %rcx,0x20(%rax)
mov    0x10(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x18(%rbp),%rdx
imul   $0x38,%rdx,%rdx
add    %rdx,%rax
mov    %rcx,0x18(%rax)
mov    0x18(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x18(%rbp),%rdx
imul   $0x38,%rdx,%rdx
add    %rdx,%rax
mov    %rcx,0x10(%rax)
mov    0x20(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x18(%rbp),%rdx
imul   $0x38,%rdx,%rdx
add    %rdx,%rax
mov    %rcx,0x8(%rax)
mov    0x28(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x18(%rbp),%rdx
imul   $0x38,%rdx,%rdx
add    %rdx,%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpuid_set>:
push   %r14
push   %rbx
movslq %edx,%rax
lea    0x14(,%rax,4),%rdx
movslq %esi,%rsi
cmp    %rsi,%rdx
jbe    1121 <cpuid_set+0x21>
mov    0x2ec3(%rip),%rax
mov    (%rax),%eax
jmp    1166 <cpuid_set+0x66>
mov    0x30(%rsp),%r10
mov    0x28(%rsp),%r11
mov    0x20(%rsp),%r14
mov    0x18(%rsp),%rsi
lea    0x1(%rax),%ebx
mov    0x8(%rdi),%rdx
imul   $0x38,%rax,%rax
mov    %rcx,0x30(%rdx,%rax,1)
mov    %r8,0x28(%rdx,%rax,1)
mov    %r9,0x20(%rdx,%rax,1)
mov    %rsi,0x18(%rdx,%rax,1)
mov    %r14,0x10(%rdx,%rax,1)
mov    %r11,0x8(%rdx,%rax,1)
mov    %r10,(%rdx,%rax,1)
mov    %ebx,(%rdi)
xor    %eax,%eax
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.kvm_cpuid2 = type { i32, %struct.TYPE_2__* }
%struct.TYPE_2__ = type { i8*, i8*, i8*, i8*, i8*, i8*, i8* }
@ENOMEM = global i32 0
define i32 @cpuid_set(i8* %0, i32 %1, i32 %2, i8* %3, i8* %4, i8* %5, i8* %6, i8* %7, i8* %8, i8* %9) {
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca %struct.kvm_cpuid2*
store i8* %0, i8** %12
store i32 %1, i32* %13
store i32 %2, i32* %14
store i8* %3, i8** %15
store i8* %4, i8** %16
store i8* %5, i8** %17
store i8* %6, i8** %18
store i8* %7, i8** %19
store i8* %8, i8** %20
store i8* %9, i8** %21
%23 = load i8*, i8** %12
%24 = bitcast i8* %23 to %struct.kvm_cpuid2*
store %struct.kvm_cpuid2* %24, %struct.kvm_cpuid2** %22
%25 = load i32, i32* %14
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 4
%29 = add i64 16, %28
%30 = load i32, i32* %13
%31 = sext i32 %30 to i64
%32 = icmp ugt i64 %29, %31
br i1 %32, label %33, label %35
33: ; preds = %10
%34 = load i32, i32* @ENOMEM
store i32 %34, i32* %11
br label %96
35: ; preds = %10
%36 = load i8*, i8** %15
%37 = load %struct.kvm_cpuid2*, %struct.kvm_cpuid2** %22
%38 = getelementptr inbounds %struct.kvm_cpuid2, %struct.kvm_cpuid2* %37, i32 0, i32 1
%39 = load %struct.TYPE_2__*, %struct.TYPE_2__** %38
%40 = load i32, i32* %14
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i64 %41
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 6
store i8* %36, i8** %43
%44 = load i8*, i8** %16
%45 = load %struct.kvm_cpuid2*, %struct.kvm_cpuid2** %22
%46 = getelementptr inbounds %struct.kvm_cpuid2, %struct.kvm_cpuid2* %45, i32 0, i32 1
%47 = load %struct.TYPE_2__*, %struct.TYPE_2__** %46
%48 = load i32, i32* %14
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i64 %49
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 5
store i8* %44, i8** %51
%52 = load i8*, i8** %17
%53 = load %struct.kvm_cpuid2*, %struct.kvm_cpuid2** %22
%54 = getelementptr inbounds %struct.kvm_cpuid2, %struct.kvm_cpuid2* %53, i32 0, i32 1
%55 = load %struct.TYPE_2__*, %struct.TYPE_2__** %54
%56 = load i32, i32* %14
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %55, i64 %57
%59 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %58, i32 0, i32 4
store i8* %52, i8** %59
%60 = load i8*, i8** %18
%61 = load %struct.kvm_cpuid2*, %struct.kvm_cpuid2** %22
%62 = getelementptr inbounds %struct.kvm_cpuid2, %struct.kvm_cpuid2* %61, i32 0, i32 1
%63 = load %struct.TYPE_2__*, %struct.TYPE_2__** %62
%64 = load i32, i32* %14
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %63, i64 %65
%67 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %66, i32 0, i32 3
store i8* %60, i8** %67
%68 = load i8*, i8** %19
%69 = load %struct.kvm_cpuid2*, %struct.kvm_cpuid2** %22
%70 = getelementptr inbounds %struct.kvm_cpuid2, %struct.kvm_cpuid2* %69, i32 0, i32 1
%71 = load %struct.TYPE_2__*, %struct.TYPE_2__** %70
%72 = load i32, i32* %14
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %71, i64 %73
%75 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %74, i32 0, i32 2
store i8* %68, i8** %75
%76 = load i8*, i8** %20
%77 = load %struct.kvm_cpuid2*, %struct.kvm_cpuid2** %22
%78 = getelementptr inbounds %struct.kvm_cpuid2, %struct.kvm_cpuid2* %77, i32 0, i32 1
%79 = load %struct.TYPE_2__*, %struct.TYPE_2__** %78
%80 = load i32, i32* %14
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %79, i64 %81
%83 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %82, i32 0, i32 1
store i8* %76, i8** %83
%84 = load i8*, i8** %21
%85 = load %struct.kvm_cpuid2*, %struct.kvm_cpuid2** %22
%86 = getelementptr inbounds %struct.kvm_cpuid2, %struct.kvm_cpuid2* %85, i32 0, i32 1
%87 = load %struct.TYPE_2__*, %struct.TYPE_2__** %86
%88 = load i32, i32* %14
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %87, i64 %89
%91 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %90, i32 0, i32 0
store i8* %84, i8** %91
%92 = load i32, i32* %14
%93 = add nsw i32 %92, 1
%94 = load %struct.kvm_cpuid2*, %struct.kvm_cpuid2** %22
%95 = getelementptr inbounds %struct.kvm_cpuid2, %struct.kvm_cpuid2* %94, i32 0, i32 0
store i32 %93, i32* %95
store i32 0, i32* %11
br label %96
96: ; preds = %35, %33
%97 = load i32, i32* %11
ret i32 %97
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i8*, i8*, i8*, i8*, i8*, i8*, i8* }
@ENOMEM = global i32 0
define i32 @cpuid_set(i8* nocapture %0, i32 %1, i32 %2, i8* %3, i8* %4, i8* %5, i8* %6, i8* %7, i8* %8, i8* %9) {
%11 = add nsw i32 %2, 1
%12 = sext i32 %11 to i64
%13 = shl nsw i64 %12, 2
%14 = add nsw i64 %13, 16
%15 = sext i32 %1 to i64
%16 = icmp ugt i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = load i32, i32* @ENOMEM
br label %32
19: ; preds = %10
%20 = getelementptr inbounds i8, i8* %0, i64 8
%21 = bitcast i8* %20 to %struct.TYPE_2__**
%22 = load %struct.TYPE_2__*, %struct.TYPE_2__** %21
%23 = sext i32 %2 to i64
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i64 %23, i32 6
store i8* %3, i8** %24
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i64 %23, i32 5
store i8* %4, i8** %25
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i64 %23, i32 4
store i8* %5, i8** %26
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i64 %23, i32 3
store i8* %6, i8** %27
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i64 %23, i32 2
store i8* %7, i8** %28
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i64 %23, i32 1
store i8* %8, i8** %29
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i64 %23, i32 0
store i8* %9, i8** %30
%31 = bitcast i8* %0 to i32*
store i32 %11, i32* %31
br label %32
32: ; preds = %19, %17
%33 = phi i32 [ %18, %17 ], [ 0, %19 ]
ret i32 %33
}