#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_fn(int, unsigned int *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, unsigned int, unsigned int, unsigned int,
                          unsigned int);
int /*<<< orphan*/ stdin;
int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
void cpuid_print() {
  char buff[64];
  unsigned int results[4];
  int index;
  while (fgets(buff, 63, stdin) != NULL) {
    index = strtoul(buff, NULL, 0);
    cpuid_fn(index, results);
    printf("cpuid\t (0x%x) eax:0x%x ebx:0x%x ecx:0x%x edx:0x%x\n", index,
           results[0], results[1], results[2], results[3]);
  }
}


x86 assembly (clang, -O0):
<cpuid_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x40(%rbp),%rdi
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
mov    $0x3f,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11a9 <cpuid_print+0x69>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1030 <cpuid_fn@plt>
mov    -0x54(%rbp),%esi
mov    -0x50(%rbp),%edx
mov    -0x4c(%rbp),%ecx
mov    -0x48(%rbp),%r8d
mov    -0x44(%rbp),%r9d
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
jmp    1148 <cpuid_print+0x8>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpuid_print>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    0x2e95(%rip),%r12
mov    (%r12),%edx
lea    0x10(%rsp),%rdi
mov    $0x3f,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11c9 <cpuid_print+0x89>
lea    0x10(%rsp),%rbx
mov    %rsp,%r14
lea    0xe86(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <cpuid_fn@plt>
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%r9d
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x3f,%esi
call   1050 <fgets@plt>
test   %rax,%rax
jne    1180 <cpuid_print+0x40>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [51 x i8] c"cpuid\09 (0x%x) eax:0x%x ebx:0x%x ecx:0x%x edx:0x%x\0A\00"
define void @cpuid_print() {
%1 = alloca [64 x i8]
%2 = alloca [4 x i32]
%3 = alloca i32
br label %4
4: ; preds = %9, %0
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %5, i32 63, i32 %6)
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %25
9: ; preds = %4
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%11 = call i32 @strtoul(i8* %10, i32* null, i32 0)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%14 = call i32 @cpuid_fn(i32 %12, i32* %13)
%15 = load i32, i32* %3
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%21 = load i32, i32* %20
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%23 = load i32, i32* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %17, i32 %19, i32 %21, i32 %23)
br label %4
25: ; preds = %4
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [51 x i8] c"cpuid\09 (0x%x) eax:0x%x ebx:0x%x ecx:0x%x edx:0x%x\0A\00"
define void @cpuid_print() {
%1 = alloca [64 x i8]
%2 = alloca [4 x i32]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = bitcast [4 x i32]* %2 to i8*
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %3, i32 63, i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %24, label %8
8: ; preds = %0
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
br label %13
13: ; preds = %8, %13
%14 = call i32 @strtoul(i8* nocapture %3, i32* null, i32 0)
%15 = call i32 @cpuid_fn(i32 %14, i32* %9)
%16 = load i32, i32* %9
%17 = load i32, i32* %10
%18 = load i32, i32* %11
%19 = load i32, i32* %12
%20 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %16, i32 %17, i32 %18, i32 %19)
%21 = load i32, i32* @stdin
%22 = call i32* @fgets(i8* %3, i32 63, i32 %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %13
24: ; preds = %13, %0
ret void
}