#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*/ __cpuid(int *, int);
int /*<<< orphan*/ memcpy(char *, int *, int);
long cpuid(char *p, int i) {
  int a[4];
  __cpuid(a, i);
  memcpy(p, &(a[1]), 4);
  memcpy(p + 4, &(a[3]), 4);
  memcpy(p + 8, &(a[2]), 4);
  return a[0];
}


x86 assembly (clang, -O0):
<cpuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <__cpuid@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
lea    -0x20(%rbp),%rsi
add    $0xc,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x8,%rdi
lea    -0x20(%rbp),%rsi
add    $0x8,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movslq -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpuid>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1040 <__cpuid@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
lea    0x4(%rbx),%rdi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
add    $0x8,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movslq (%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @cpuid(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [4 x i32]
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%7 = load i32, i32* %4
%8 = call i32 @__cpuid(i32* %6, i32 %7)
%9 = load i8*, i8** %3
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%11 = call i32 @memcpy(i8* %9, i32* %10, i32 4)
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 4
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%15 = call i32 @memcpy(i8* %13, i32* %14, i32 4)
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 8
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%19 = call i32 @memcpy(i8* %17, i32* %18, i32 4)
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
ret i64 %22
}

LLVM IR (-O2):
define i64 @cpuid(i8* %0, i32 %1) {
%3 = alloca [4 x i32]
%4 = bitcast [4 x i32]* %3 to i8*
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%6 = call i32 @__cpuid(i32* %5, i32 %1)
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%8 = call i32 @memcpy(i8* %0, i32* %7, i32 4)
%9 = getelementptr inbounds i8, i8* %0, i64 4
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%11 = call i32 @memcpy(i8* %9, i32* %10, i32 4)
%12 = getelementptr inbounds i8, i8* %0, i64 8
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%14 = call i32 @memcpy(i8* %12, i32* %13, i32 4)
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
ret i64 %16
}