#include <stdio.h>
#include <stdint.h>
#include <time.h>
#define N 200000000L
static double now(void){ struct timespec t; clock_gettime(CLOCK_MONOTONIC,&t); return t.tv_sec*1e9+t.tv_nsec; }
int main(void){
    uint64_t a=3,b=5,c=7,d=9;
    double best_dep=1e30, best_ind=1e30;
    for (int rep=0; rep<3; rep++){
        double t0=now();
        for (long i=0;i<N;i++)   /* 4 imul, her biri evvelkinin neticesini gozleyir */
            __asm__ volatile("imul %0,%0\n\timul %0,%0\n\timul %0,%0\n\timul %0,%0" : "+r"(a));
        double t1=now();
        for (long i=0;i<N;i++)   /* 4 imul, 4 ayri zencir: bir-birini gozlemir */
            __asm__ volatile("imul %0,%0\n\timul %1,%1\n\timul %2,%2\n\timul %3,%3" : "+r"(a),"+r"(b),"+r"(c),"+r"(d));
        double t2=now();
        if ((t1-t0)/N < best_dep) best_dep=(t1-t0)/N;
        if ((t2-t1)/N < best_ind) best_ind=(t2-t1)/N;
    }
    printf("asili zencir:    %.2f ns / 4 imul = %.3f ns bir imul\n", best_dep, best_dep/4);
    printf("musteqil zencir: %.2f ns / 4 imul = %.3f ns bir imul\n", best_ind, best_ind/4);
    printf("ferq: %.1f defe\n", best_dep/best_ind);
    printf("(%lu)\n",(unsigned long)((a^b^c^d)&1));
    return 0;
}
