#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 uint64_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int cpuid_extended();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rdtscp_presence();
scalar_t__ tsc_invariant();
scalar_t__ tsc_presence();
int main(int argc, char **argv) {
  printf("Checking tsc presence...");
  if (tsc_presence())
    printf(" present!\n");
  else
    printf(" not present :(\n");
  printf("Checking maximun param for cpuid...");
  uint64_t max_ex = cpuid_extended();
  printf("is %lX\n", max_ex);
  printf("Checking for rdtscp...");
  if ((max_ex >= 0x80000001)) {
    if (rdtscp_presence())
      printf("present!\n");
    else
      printf(" not present :(\n");
  }
  printf("Checking for invariant tsc...");
  if ((max_ex >= 0x8000007)) {
    if (tsc_invariant())
      printf("present!\n");
    else
      printf(" not present :(\n");
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <tsc_presence@plt>
cmp    $0x0,%rax
je     11a8 <main+0x48>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b6 <main+0x56>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <cpuid_extended@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x80000001,-0x14(%rbp)
jb     1231 <main+0xd1>
mov    $0x0,%al
call   1050 <rdtscp_presence@plt>
cmp    $0x0,%rax
je     121e <main+0xbe>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122c <main+0xcc>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1231 <main+0xd1>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x8000007,-0x14(%rbp)
jl     1283 <main+0x123>
mov    $0x0,%al
call   1030 <tsc_invariant@plt>
cmp    $0x0,%rax
je     1270 <main+0x110>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127e <main+0x11e>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1283 <main+0x123>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <tsc_presence@plt>
test   %rax,%rax
lea    0xee7(%rip),%r14
lea    0xef0(%rip),%rdi
cmove  %r14,%rdi
call   1030 <puts@plt>
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <cpuid_extended@plt>
mov    %eax,%ebx
lea    0xe7c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x80000001,%ebx
jb     120a <main+0x9a>
xor    %eax,%eax
call   1060 <rdtscp_presence@plt>
test   %rax,%rax
lea    0xe9a(%rip),%rdi
cmove  %r14,%rdi
call   1030 <puts@plt>
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1241 <main+0xd1>
lea    0xe4b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x8000007,%ebx
jl     1241 <main+0xd1>
xor    %eax,%eax
call   1040 <tsc_invariant@plt>
test   %rax,%rax
jne    1235 <main+0xc5>
lea    0xe47(%rip),%rdi
jmp    123c <main+0xcc>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Checking tsc presence...\00"
@.str.1 = [11 x i8] c" present!\0A\00"
@.str.2 = [17 x i8] c" not present :(\0A\00"
@.str.3 = [36 x i8] c"Checking maximun param for cpuid...\00"
@.str.4 = [8 x i8] c"is %lX\0A\00"
@.str.5 = [23 x i8] c"Checking for rdtscp...\00"
@.str.6 = [10 x i8] c"present!\0A\00"
@.str.7 = [30 x i8] c"Checking for invariant tsc...\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = call i64 (...) @tsc_presence()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 (...) @cpuid_extended()
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%20 = load i32, i32* %6
%21 = icmp uge i32 %20, -2147483647
br i1 %21, label %22, label %30
22: ; preds = %14
%23 = call i64 (...) @rdtscp_presence()
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %29
27: ; preds = %22
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %25
br label %30
30: ; preds = %29, %14
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%32 = load i32, i32* %6
%33 = icmp sge i32 %32, 134217735
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = call i64 (...) @tsc_invariant()
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %41
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
br label %42
42: ; preds = %41, %30
%43 = load i32, i32* @EXIT_SUCCESS
%44 = call i32 @exit(i32 %43)
unreachable
}

LLVM IR (-O2):
@.str = [25 x i8] c"Checking tsc presence...\00"
@.str.3 = [36 x i8] c"Checking maximun param for cpuid...\00"
@.str.4 = [8 x i8] c"is %lX\0A\00"
@.str.5 = [23 x i8] c"Checking for rdtscp...\00"
@.str.7 = [30 x i8] c"Checking for invariant tsc...\00"
@EXIT_SUCCESS = global i32 0
@str.10 = [16 x i8] c" not present :(\00"
@str.11 = [9 x i8] c"present!\00"
@str.12 = [10 x i8] c" present!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 (...) @tsc_presence()
%5 = icmp eq i64 %4, 0
%6 = select i1 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.12, i64 0, i64 0)
%7 = tail call i32 @puts(i8* dereferenceable(1) %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 (...) @cpuid_extended()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%12 = icmp ugt i32 %9, -2147483648
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = tail call i64 (...) @rdtscp_presence()
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.11, i64 0, i64 0)
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
br label %29
19: ; preds = %2
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%21 = icmp sgt i32 %9, 134217734
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = tail call i64 (...) @tsc_invariant()
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.11, i64 0, i64 0))
br label %29
27: ; preds = %22
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0))
br label %29
29: ; preds = %13, %25, %27, %19
%30 = load i32, i32* @EXIT_SUCCESS
%31 = tail call i32 @exit(i32 %30)
unreachable
}