// File: /workspace/github_c_makefile_star2_O0/fmadio[P]pcap_flow/./fTypes.h
// Function: CycleCalibration
static inline void CycleCalibration(void)
{
    fprintf(stderr, "calibrating...\n");
    u64 StartTS[16];
    u64 EndTS[16];

    u64 CyclesSum   = 0;
    u64 CyclesSum2  = 0;
    u64 CyclesCnt   = 0;
    for (int i=0; i < 1; i++)
    {
        u64 NextTS = clock_ns() + 1e9;
        u64 StartTS = rdtsc();
        while (clock_ns() < NextTS)
        {
        }
        u64 EndTS  = rdtsc();

        u64 Cycles = EndTS - StartTS;
        CyclesSum += Cycles;
        CyclesSum2 += Cycles*Cycles;
        CyclesCnt++;

        fprintf(stderr, "%i : %016llx %16.4f cycles/nsec\n", i, Cycles, Cycles / 1e9);
    }

    double CyclesSec = CyclesSum / CyclesCnt;
    double CyclesStd = sqrt(CyclesCnt *CyclesSum2 - CyclesSum *CyclesSum) / CyclesCnt;
    fprintf(stderr, "Cycles/Sec %12.4f Std:%8.fcycle std(%12.8f)\n", CyclesSec, CyclesStd, CyclesStd / CyclesSec);

	// set global

	TSC2Nano = 1e9 / CyclesSec;
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq 0x8dca(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x6584(%rip), %rsi      # 0xd7bc
movb $0x0, %al
callq 0x1150
movq $0x0, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
cmpl $0x1, 0x54(%rsp)
jge 0x739d
callq 0x8640
movq %rax, %xmm0
movaps 0x4da2(%rip), %xmm1     # 0xc020
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x4da6(%rip), %xmm1     # 0xc030
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x541f(%rip), %xmm1     # 0xc6c0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x541c(%rip), %xmm1     # 0xc6d8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x48(%rsp)
callq 0x77c0
movq %rax, 0x40(%rsp)
callq 0x8640
cmpq 0x48(%rsp), %rax
jae 0x72e8
jmp 0x72da
callq 0x77c0
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
subq %rcx, %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rcx
movq 0x68(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x68(%rsp)
movq 0x30(%rsp), %rcx
imulq %rcx, %rcx
movq 0x60(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x60(%rsp)
movq 0x58(%rsp), %rax
incq %rax
movq %rax, 0x58(%rsp)
movq 0x8cb8(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movl 0x54(%rsp), %edx
movq 0x30(%rsp), %rcx
movq %rcx, %xmm0
movaps 0x4cc8(%rip), %xmm1     # 0xc020
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x4ccc(%rip), %xmm1     # 0xc030
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x5345(%rip), %xmm1     # 0xc6c0
divsd %xmm1, %xmm0
leaq 0x6446(%rip), %rsi      # 0xd7cc
movb $0x1, %al
callq 0x1150
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x7262
movq 0x68(%rsp), %rax
movq 0x58(%rsp), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %xmm0
movaps 0x4c68(%rip), %xmm2     # 0xc020
movaps %xmm2, (%rsp)
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x4c68(%rip), %xmm1     # 0xc030
movaps %xmm1, 0x10(%rsp)
subpd %xmm1, %xmm0
movaps %xmm0, %xmm3
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm3, %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x58(%rsp), %rax
movq 0x60(%rsp), %rcx
imulq %rcx, %rax
movq 0x68(%rsp), %rcx
imulq %rcx, %rcx
subq %rcx, %rax
movq %rax, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
callq 0x1230
movaps (%rsp), %xmm3
movaps 0x10(%rsp), %xmm2
movq 0x58(%rsp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x8bac(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movsd 0x28(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
divsd 0x28(%rsp), %xmm2
leaq 0x637f(%rip), %rsi      # 0xd7ed
movb $0x3, %al
callq 0x1150
movsd 0x5243(%rip), %xmm0     # 0xc6c0
divsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x9d65(%rip)     # 0x111f0
addq $0x178, %rsp            # imm = 0x178
retq
nopw %cs:(%rax,%rax)