#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 *, int *, int *);
int cpuidSerial(unsigned char *serial) {
  int a, b, c, d;
  int i;
  cpuid(1, &a, &b, &c, &d);
  for (i = 0; i < 3; i++) {
    *serial++ = (a >> 24);
    a <<= 8;
  }
  cpuid(3, &a, &b, &c, &d);
  for (i = 0; i < 3; i++) {
    *serial++ = (d >> 24);
    d <<= 8;
  }
  for (i = 0; i < 3; i++) {
    *serial++ = (c >> 24);
    c <<= 8;
  }
  return 12;
}


x86 assembly (clang, -O0):
<cpuidSerial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1,%edi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1030 <cpuid@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    1177 <cpuidSerial+0x67>
mov    -0xc(%rbp),%eax
sar    $0x18,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <cpuidSerial+0x2d>
mov    $0x3,%edi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1030 <cpuid@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    11d2 <cpuidSerial+0xc2>
mov    -0x18(%rbp),%eax
sar    $0x18,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1198 <cpuidSerial+0x88>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    1213 <cpuidSerial+0x103>
mov    -0x14(%rbp),%eax
sar    $0x18,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d9 <cpuidSerial+0xc9>
mov    $0xc,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpuidSerial>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0x4(%rsp),%r13
mov    $0x1,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1030 <cpuid@plt>
mov    (%rsp),%eax
mov    %eax,%ecx
shr    $0x18,%ecx
mov    %cl,(%rbx)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x1(%rbx)
mov    %ah,0x2(%rbx)
shl    $0x18,%eax
mov    %eax,(%rsp)
mov    $0x3,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1030 <cpuid@plt>
mov    0x4(%rsp),%eax
mov    %eax,%ecx
shr    $0x18,%ecx
mov    %cl,0x3(%rbx)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x4(%rbx)
mov    %ah,0x5(%rbx)
mov    0x8(%rsp),%eax
mov    %eax,%ecx
shr    $0x18,%ecx
mov    %cl,0x6(%rbx)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x7(%rbx)
mov    %ah,0x8(%rbx)
mov    $0xc,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @cpuidSerial(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = call i32 @cpuid(i32 1, i32* %3, i32* %4, i32* %5, i32* %6)
store i32 0, i32* %7
br label %9
9: ; preds = %20, %1
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32, i32* %3
%14 = ashr i32 %13, 24
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %2
store i8 %15, i8* %16
%18 = load i32, i32* %3
%19 = shl i32 %18, 8
store i32 %19, i32* %3
br label %20
20: ; preds = %12
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
br label %9
23: ; preds = %9
%24 = call i32 @cpuid(i32 3, i32* %3, i32* %4, i32* %5, i32* %6)
store i32 0, i32* %7
br label %25
25: ; preds = %36, %23
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 3
br i1 %27, label %28, label %39
28: ; preds = %25
%29 = load i32, i32* %6
%30 = ashr i32 %29, 24
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %2
store i8 %31, i8* %32
%34 = load i32, i32* %6
%35 = shl i32 %34, 8
store i32 %35, i32* %6
br label %36
36: ; preds = %28
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %25
39: ; preds = %25
store i32 0, i32* %7
br label %40
40: ; preds = %51, %39
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 3
br i1 %42, label %43, label %54
43: ; preds = %40
%44 = load i32, i32* %5
%45 = ashr i32 %44, 24
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %2
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %2
store i8 %46, i8* %47
%49 = load i32, i32* %5
%50 = shl i32 %49, 8
store i32 %50, i32* %5
br label %51
51: ; preds = %43
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %40
54: ; preds = %40
ret i32 12
}

LLVM IR (-O2):
define i32 @cpuidSerial(i8* nocapture writeonly %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @cpuid(i32 1, i32* %2, i32* %3, i32* %4, i32* %5)
%11 = load i32, i32* %2
%12 = lshr i32 %11, 24
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %13, i8* %0
%15 = lshr i32 %11, 16
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %16, i8* %14
%18 = lshr i32 %11, 8
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %19, i8* %17
%21 = shl i32 %11, 24
store i32 %21, i32* %2
%22 = call i32 @cpuid(i32 3, i32* %2, i32* %3, i32* %4, i32* %5)
%23 = load i32, i32* %5
%24 = lshr i32 %23, 24
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %25, i8* %20
%27 = lshr i32 %23, 16
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %28, i8* %26
%30 = lshr i32 %23, 8
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %31, i8* %29
%33 = load i32, i32* %4
%34 = lshr i32 %33, 24
%35 = trunc i32 %34 to i8
%36 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %35, i8* %32
%37 = lshr i32 %33, 16
%38 = trunc i32 %37 to i8
%39 = getelementptr inbounds i8, i8* %0, i64 8
store i8 %38, i8* %36
%40 = lshr i32 %33, 8
%41 = trunc i32 %40 to i8
store i8 %41, i8* %39
ret i32 12
}