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

/* Variables and functions */
scalar_t__ arch__cpuinfo_freq(double *, char *);
int /*<<< orphan*/ debug_print(int /*<<< orphan*/ *, int, char *, double,
                               double);
double fabsl(double);
int calibrate_cpuinfo(double *nsofclk, uint64_t *clkofsec) {
  char unit[11] = {0};
  double freq = 0.0;
  if (arch__cpuinfo_freq(&freq, unit)) {
    return -1;
  }
  if (fabsl(freq) < 1.0E-6) {
    return (-1);
  }
  *clkofsec = freq;
  *nsofclk = (double)1000000000 / *clkofsec;
  debug_print(NULL, 2,
              "calibrate_cpuinfo: nsofclk = %.4f, "
              "clkofsec = %lu\n",
              *nsofclk, *clkofsec);
  return (0);
}


x86 assembly (clang, -O0):
<calibrate_cpuinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x23(%rbp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1050 <memset@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    -0x23(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   1040 <arch__cpuinfo_freq@plt>
cmp    $0x0,%rax
je     118b <calibrate_cpuinfo+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <calibrate_cpuinfo+0xc7>
movsd  -0x30(%rbp),%xmm0
call   1030 <fabsl@plt>
movaps %xmm0,%xmm1
movsd  0xe60(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b6 <calibrate_cpuinfo+0x76>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <calibrate_cpuinfo+0xc7>
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  0xe39(%rip),%xmm0
divsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
xor    %eax,%eax
mov    %eax,%edi
mov    $0x2,%esi
lea    0xe15(%rip),%rdx
call   1060 <debug_print@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calibrate_cpuinfo>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
movl   $0x0,0x17(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <arch__cpuinfo_freq@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    11b2 <calibrate_cpuinfo+0x92>
movsd  0x8(%rsp),%xmm1
movapd 0xe90(%rip),%xmm0
andpd  %xmm1,%xmm0
movsd  0xe94(%rip),%xmm2
ucomisd %xmm0,%xmm2
ja     11b2 <calibrate_cpuinfo+0x92>
movsd  %xmm1,(%r15)
movsd  0xe89(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
movsd  (%r15),%xmm1
lea    0xe7c(%rip),%rdx
xor    %ebx,%ebx
xor    %edi,%edi
mov    $0x2,%esi
call   1040 <debug_print@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [51 x i8] c"calibrate_cpuinfo: nsofclk = %.4f, clkofsec = %lu\0A\00"
define i32 @calibrate_cpuinfo(double* %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca double*
%6 = alloca [11 x i8]
%7 = alloca double
store double* %0, double** %4
store double* %1, double** %5
%8 = bitcast [11 x i8]* %6 to i8*
store double 0.000000e+00, double* %7
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%10 = call i64 @arch__cpuinfo_freq(double* %7, i8* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %30
13: ; preds = %2
%14 = load double, double* %7
%15 = call double @fabsl(double %14)
%16 = fcmp olt double %15, 0x3EB0C6F7A0B5ED8D
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %3
br label %30
18: ; preds = %13
%19 = load double, double* %7
%20 = load double*, double** %5
store double %19, double* %20
%21 = load double*, double** %5
%22 = load double, double* %21
%23 = fdiv double 1.000000e+09, %22
%24 = load double*, double** %4
store double %23, double* %24
%25 = load double*, double** %4
%26 = load double, double* %25
%27 = load double*, double** %5
%28 = load double, double* %27
%29 = call i32 @debug_print(i32* null, i32 2, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), double %26, double %28)
store i32 0, i32* %3
br label %30
30: ; preds = %18, %17, %12
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [51 x i8] c"calibrate_cpuinfo: nsofclk = %.4f, clkofsec = %lu\0A\00"
define i32 @calibrate_cpuinfo(double* nocapture writeonly %0, double* nocapture %1) {
%3 = alloca [11 x i8]
%4 = alloca double
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%6 = bitcast double* %4 to i8*
store double 0.000000e+00, double* %4
%7 = call i64 @arch__cpuinfo_freq(double* %4, i8* %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = load double, double* %4
%11 = call double @llvm.fabs.f64(double %10)
%12 = fcmp olt double %11, 0x3EB0C6F7A0B5ED8D
br i1 %12, label %17, label %13
13: ; preds = %9
store double %10, double* %1
%14 = fdiv double 1.000000e+09, %10
store double %14, double* %0
%15 = load double, double* %1
%16 = call i32 @debug_print(i32* null, i32 2, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), double %14, double %15)
br label %17
17: ; preds = %9, %2, %13
%18 = phi i32 [ 0, %13 ], [ -1, %2 ], [ -1, %9 ]
ret i32 %18
}