#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 scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
double double_time_it(double f()) {
  clock_t begin, end;
  double time_spent;
  begin = clock();
  double output = f();
  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("=> Result: %f\n", output);
  printf("=> Time: %fs\n", time_spent);
  return 0.0;
}


x86 assembly (clang, -O0):
<double_time_it>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   *-0x8(%rbp)
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e88(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<double_time_it>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
xor    %eax,%eax
call   *%rbx
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2e91(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe98(%rip),%rdi
movsd  0x10(%rsp),%xmm0
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [15 x i8] c"=> Result: %f\0A\00"
@.str.1 = [14 x i8] c"=> Time: %fs\0A\00"
define double @double_time_it(double (...)* %0) {
%2 = alloca double (...)*
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
%6 = alloca double
store double (...)* %0, double (...)** %2
%7 = call i64 (...) @clock()
store i64 %7, i64* %3
%8 = load double (...)*, double (...)** %2
%9 = call double (...) %8()
store double %9, double* %6
%10 = call i64 (...) @clock()
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = load i64, i64* %3
%13 = sub nsw i64 %11, %12
%14 = sitofp i64 %13 to double
%15 = load double, double* @CLOCKS_PER_SEC
%16 = fdiv double %14, %15
store double %16, double* %5
%17 = load double, double* %6
%18 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %17)
%19 = load double, double* %5
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %19)
ret double 0.000000e+00
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [15 x i8] c"=> Result: %f\0A\00"
@.str.1 = [14 x i8] c"=> Time: %fs\0A\00"
define double @double_time_it(double (...)* nocapture %0) {
%2 = tail call i64 (...) @clock()
%3 = tail call double (...) %0()
%4 = tail call i64 (...) @clock()
%5 = sub nsw i64 %4, %2
%6 = sitofp i64 %5 to double
%7 = load double, double* @CLOCKS_PER_SEC
%8 = fdiv double %6, %7
%9 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %3)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %8)
ret double 0.000000e+00
}