#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 */
struct timespec {
  int tv_sec;
  double tv_nsec;
};
typedef scalar_t__ int32_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC_RAW;
scalar_t__ calc_1();
scalar_t__ calc_2();
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *, double, ...);
int main() {
  struct timespec start, end;
  int32_t res = 0;
  double ratio, mult, single;
  ratio = 0;
  for (int i = 0; i < 100; i++) {
    clock_gettime(CLOCK_MONOTONIC_RAW, &start);
    res = calc_1();
    clock_gettime(CLOCK_MONOTONIC_RAW, &end);
    single = (end.tv_sec * 1000000000 + end.tv_nsec) -
             (start.tv_sec * 1000000000 + start.tv_nsec);
    res = 0;
    clock_gettime(CLOCK_MONOTONIC_RAW, &start);
    res = calc_2();
    clock_gettime(CLOCK_MONOTONIC_RAW, &end);
    mult = (end.tv_sec * 1000000000 + end.tv_nsec) -
           (start.tv_sec * 1000000000 + start.tv_nsec);
    printf("%d-%f\n", i, single / mult);
    ratio += single / mult;
  }
  printf("%f\n", ratio / 100);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x64,-0x4c(%rbp)
jge    1267 <main+0x127>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    $0x0,%al
call   1050 <calc_1@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
imul   $0x3b9aca00,-0x28(%rbp),%eax
cvtsi2sd %eax,%xmm0
addsd  -0x20(%rbp),%xmm0
imul   $0x3b9aca00,-0x18(%rbp),%eax
cvtsi2sd %eax,%xmm1
addsd  -0x10(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    $0x0,%al
call   1060 <calc_2@plt>
mov    %rax,-0x30(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
imul   $0x3b9aca00,-0x28(%rbp),%eax
cvtsi2sd %eax,%xmm0
addsd  -0x20(%rbp),%xmm0
imul   $0x3b9aca00,-0x18(%rbp),%eax
cvtsi2sd %eax,%xmm1
addsd  -0x10(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x4c(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
divsd  -0x40(%rbp),%xmm1
lea    0xdca(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x48(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1166 <main+0x26>
movsd  -0x38(%rbp),%xmm0
movsd  0xd8c(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd8c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x64,%ebp
mov    0x2e86(%rip),%rbx
lea    0x28(%rsp),%r14
lea    0x18(%rsp),%r12
lea    0xe9d(%rip),%r15
xorpd  %xmm0,%xmm0
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x38(%rsp)
mov    (%rbx),%edi
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
xor    %eax,%eax
call   1050 <calc_1@plt>
mov    (%rbx),%edi
mov    %r12,%rsi
call   1030 <clock_gettime@plt>
imul   $0x3b9aca00,0x18(%rsp),%eax
3b
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
addsd  0x20(%rsp),%xmm1
imul   $0x3b9aca00,0x28(%rsp),%eax
3b
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x30(%rsp),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    (%rbx),%edi
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
xor    %eax,%eax
call   1060 <calc_2@plt>
mov    (%rbx),%edi
mov    %r12,%rsi
call   1030 <clock_gettime@plt>
imul   $0x3b9aca00,0x18(%rsp),%eax
3b
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x20(%rsp),%xmm0
imul   $0x3b9aca00,0x28(%rsp),%eax
3b
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
addsd  0x30(%rsp),%xmm1
subsd  %xmm1,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %r15,%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1040 <printf@plt>
movsd  0x38(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  0xda8(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0xffffffff,%ebp
jne    1180 <main+0x40>
divsd  0xd99(%rip),%xmm0
lea    0xd9d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, double }
@CLOCK_MONOTONIC_RAW = global i32 0
@.str = [7 x i8] c"%d-%f\0A\00"
@.str.1 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca i64
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %8
br label %9
9: ; preds = %64, %0
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 100
br i1 %11, label %12, label %67
12: ; preds = %9
%13 = load i32, i32* @CLOCK_MONOTONIC_RAW
%14 = call i32 @clock_gettime(i32 %13, %struct.timespec* %2)
%15 = call i64 (...) @calc_1()
store i64 %15, i64* %4
%16 = load i32, i32* @CLOCK_MONOTONIC_RAW
%17 = call i32 @clock_gettime(i32 %16, %struct.timespec* %3)
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%19 = load i32, i32* %18
%20 = mul nsw i32 %19, 1000000000
%21 = sitofp i32 %20 to double
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%23 = load double, double* %22
%24 = fadd double %21, %23
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%26 = load i32, i32* %25
%27 = mul nsw i32 %26, 1000000000
%28 = sitofp i32 %27 to double
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%30 = load double, double* %29
%31 = fadd double %28, %30
%32 = fsub double %24, %31
store double %32, double* %7
store i64 0, i64* %4
%33 = load i32, i32* @CLOCK_MONOTONIC_RAW
%34 = call i32 @clock_gettime(i32 %33, %struct.timespec* %2)
%35 = call i64 (...) @calc_2()
store i64 %35, i64* %4
%36 = load i32, i32* @CLOCK_MONOTONIC_RAW
%37 = call i32 @clock_gettime(i32 %36, %struct.timespec* %3)
%38 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%39 = load i32, i32* %38
%40 = mul nsw i32 %39, 1000000000
%41 = sitofp i32 %40 to double
%42 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%43 = load double, double* %42
%44 = fadd double %41, %43
%45 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%46 = load i32, i32* %45
%47 = mul nsw i32 %46, 1000000000
%48 = sitofp i32 %47 to double
%49 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%50 = load double, double* %49
%51 = fadd double %48, %50
%52 = fsub double %44, %51
store double %52, double* %6
%53 = load i32, i32* %8
%54 = sitofp i32 %53 to double
%55 = load double, double* %7
%56 = load double, double* %6
%57 = fdiv double %55, %56
%58 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %54, double %57)
%59 = load double, double* %7
%60 = load double, double* %6
%61 = fdiv double %59, %60
%62 = load double, double* %5
%63 = fadd double %62, %61
store double %63, double* %5
br label %64
64: ; preds = %12
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %9
67: ; preds = %9
%68 = load double, double* %5
%69 = fdiv double %68, 1.000000e+02
%70 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %69)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, double }
@CLOCK_MONOTONIC_RAW = global i32 0
@.str = [7 x i8] c"%d-%f\0A\00"
@.str.1 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast %struct.timespec* %2 to i8*
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
br label %12
9: ; preds = %12
%10 = fdiv double %50, 1.000000e+02
%11 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %10)
ret i32 0
12: ; preds = %0, %12
%13 = phi i32 [ 0, %0 ], [ %51, %12 ]
%14 = phi double [ 0.000000e+00, %0 ], [ %50, %12 ]
%15 = load i32, i32* @CLOCK_MONOTONIC_RAW
%16 = call i32 @clock_gettime(i32 %15, %struct.timespec* %1)
%17 = call i64 (...) @calc_1()
%18 = load i32, i32* @CLOCK_MONOTONIC_RAW
%19 = call i32 @clock_gettime(i32 %18, %struct.timespec* %2)
%20 = load i32, i32* %5
%21 = mul nsw i32 %20, 1000000000
%22 = sitofp i32 %21 to double
%23 = load double, double* %6
%24 = fadd double %23, %22
%25 = load i32, i32* %7
%26 = mul nsw i32 %25, 1000000000
%27 = sitofp i32 %26 to double
%28 = load double, double* %8
%29 = fadd double %28, %27
%30 = fsub double %24, %29
%31 = load i32, i32* @CLOCK_MONOTONIC_RAW
%32 = call i32 @clock_gettime(i32 %31, %struct.timespec* %1)
%33 = call i64 (...) @calc_2()
%34 = load i32, i32* @CLOCK_MONOTONIC_RAW
%35 = call i32 @clock_gettime(i32 %34, %struct.timespec* %2)
%36 = load i32, i32* %5
%37 = mul nsw i32 %36, 1000000000
%38 = sitofp i32 %37 to double
%39 = load double, double* %6
%40 = fadd double %39, %38
%41 = load i32, i32* %7
%42 = mul nsw i32 %41, 1000000000
%43 = sitofp i32 %42 to double
%44 = load double, double* %8
%45 = fadd double %44, %43
%46 = fsub double %40, %45
%47 = sitofp i32 %13 to double
%48 = fdiv double %30, %46
%49 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %47, double %48)
%50 = fadd double %14, %48
%51 = add nuw nsw i32 %13, 1
%52 = icmp eq i32 %51, 100
br i1 %52, label %9, label %12
}