#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__ time_t;

/* Variables and functions */
double DBL_MAX;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ time(int /*<<< orphan*/ *);
void test_time() {
  const int timeitr = 5;
  time_t t1, t2, cur;
  double min, max, avg, ncavg;
  long ncalls = 0;
  int i;
  printf("Testing time()\n");
  max = avg = 0;
  min = DBL_MAX;
  for (i = 0; i < timeitr; i++) {
    t1 = t2 = time(NULL);
    while (t1 == t2) {
      t2 = time(NULL);
      ncalls++;
    }
    cur = t2 - t1;
    if (cur < min)
      min = cur;
    if (cur > max)
      max = cur;
    avg += cur;
  }
  avg /= timeitr;
  ncavg = (double)ncalls / timeitr;
  printf("avg/min/max: %g/%g/%g s.\n", avg, min, max);
  printf("On average %g time() calls before value changed.\n", ncavg);
  printf("Thus, %g time() calls per second.\n\n", ncavg / avg);
}


x86 assembly (clang, -O0):
<test_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x5,-0x4(%rbp)
movq   $0x0,-0x48(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    0x2e84(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x5,-0x4c(%rbp)
jge    1219 <test_time+0xf9>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11b3 <test_time+0x93>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x18(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1187 <test_time+0x67>
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11df <test_time+0xbf>
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    11fb <test_time+0xdb>
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    116c <test_time+0x4c>
movsd  -0x38(%rbp),%xmm0
movsd  0xdda(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdq -0x48(%rbp),%xmm0
movsd  0xdc3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
lea    0xdbc(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xdc3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x40(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
lea    0xddd(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_time>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xf42(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e96(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x20(%rsp)
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1050 <time@plt>
add    $0x1,%rbx
sub    %r14,%rax
je     1160 <test_time+0x30>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd %xmm0,0x30(%rsp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,%r14
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1050 <time@plt>
add    $0x1,%rbx
sub    %r14,%rax
je     1190 <test_time+0x60>
movapd 0x30(%rsp),%xmm1
movapd %xmm1,%xmm0
minsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
maxsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x20(%rsp)
maxsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1050 <time@plt>
add    $0x1,%rbx
sub    %r14,%rax
je     11e0 <test_time+0xb0>
movsd  0x20(%rsp),%xmm0
minsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x10(%rsp)
maxsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
call   1050 <time@plt>
add    $0x1,%rbx
sub    %r14,%rax
je     1230 <test_time+0x100>
movsd  0x10(%rsp),%xmm0
minsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x40(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x18(%rsp)
maxsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
call   1050 <time@plt>
add    $0x1,%rbx
sub    %r14,%rax
je     1280 <test_time+0x150>
movapd 0x30(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm3
addsd  %xmm3,%xmm0
minsd  0x40(%rsp),%xmm3
cvtsi2sd %rax,%xmm2
movapd %xmm2,%xmm1
minsd  %xmm3,%xmm1
addsd  %xmm2,%xmm0
maxsd  0x8(%rsp),%xmm2
xorps  %xmm3,%xmm3
cvtsi2sd %rbx,%xmm3
unpcklpd %xmm0,%xmm3
divpd  0xd23(%rip),%xmm3
movapd %xmm3,0x30(%rsp)
movapd %xmm3,%xmm0
unpckhpd %xmm3,%xmm0
movapd %xmm0,0x20(%rsp)
lea    0xd18(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
lea    0xd24(%rip),%rdi
movaps 0x30(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
movapd 0x30(%rsp),%xmm0
divsd  0x20(%rsp),%xmm0
lea    0xd37(%rip),%rdi
mov    $0x1,%al
add    $0x48,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"Testing time()\0A\00"
@DBL_MAX = global double 0.000000e+00
@.str.1 = [26 x i8] c"avg/min/max: %g/%g/%g s.\0A\00"
@.str.2 = [50 x i8] c"On average %g time() calls before value changed.\0A\00"
@.str.3 = [36 x i8] c"Thus, %g time() calls per second.\0A\0A\00"
define void @test_time() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i64
%10 = alloca i32
store i32 5, i32* %1
store i64 0, i64* %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %6
%12 = load double, double* @DBL_MAX
store double %12, double* %5
store i32 0, i32* %10
br label %13
13: ; preds = %50, %0
%14 = load i32, i32* %10
%15 = icmp slt i32 %14, 5
br i1 %15, label %16, label %53
16: ; preds = %13
%17 = call i64 @time(i32* null)
store i64 %17, i64* %3
store i64 %17, i64* %2
br label %18
18: ; preds = %22, %16
%19 = load i64, i64* %2
%20 = load i64, i64* %3
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = call i64 @time(i32* null)
store i64 %23, i64* %3
%24 = load i64, i64* %9
%25 = add nsw i64 %24, 1
store i64 %25, i64* %9
br label %18
26: ; preds = %18
%27 = load i64, i64* %3
%28 = load i64, i64* %2
%29 = sub nsw i64 %27, %28
store i64 %29, i64* %4
%30 = load i64, i64* %4
%31 = sitofp i64 %30 to double
%32 = load double, double* %5
%33 = fcmp olt double %31, %32
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = load i64, i64* %4
%36 = sitofp i64 %35 to double
store double %36, double* %5
br label %37
37: ; preds = %34, %26
%38 = load i64, i64* %4
%39 = sitofp i64 %38 to double
%40 = load double, double* %6
%41 = fcmp ogt double %39, %40
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i64, i64* %4
%44 = sitofp i64 %43 to double
store double %44, double* %6
br label %45
45: ; preds = %42, %37
%46 = load i64, i64* %4
%47 = sitofp i64 %46 to double
%48 = load double, double* %7
%49 = fadd double %48, %47
store double %49, double* %7
br label %50
50: ; preds = %45
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %13
53: ; preds = %13
%54 = load double, double* %7
%55 = fdiv double %54, 5.000000e+00
store double %55, double* %7
%56 = load i64, i64* %9
%57 = sitofp i64 %56 to double
%58 = fdiv double %57, 5.000000e+00
store double %58, double* %8
%59 = load double, double* %7
%60 = load double, double* %5
%61 = load double, double* %6
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %59, double %60, double %61)
%63 = load double, double* %8
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), double %63)
%65 = load double, double* %8
%66 = load double, double* %7
%67 = fdiv double %65, %66
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double %67)
ret void
}

LLVM IR (-O2):
@DBL_MAX = global double 0.000000e+00
@.str.1 = [26 x i8] c"avg/min/max: %g/%g/%g s.\0A\00"
@.str.2 = [50 x i8] c"On average %g time() calls before value changed.\0A\00"
@.str.3 = [36 x i8] c"Thus, %g time() calls per second.\0A\0A\00"
@str = [15 x i8] c"Testing time()\00"
define void @test_time() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%2 = load double, double* @DBL_MAX
%3 = tail call i64 @time(i32* null)
br label %4
4: ; preds = %0, %4
%5 = phi i64 [ 0, %0 ], [ %7, %4 ]
%6 = tail call i64 @time(i32* null)
%7 = add nuw nsw i64 %5, 1
%8 = icmp eq i64 %6, %3
br i1 %8, label %4, label %9
9: ; preds = %4
%10 = sub nsw i64 %6, %3
%11 = sitofp i64 %10 to double
%12 = fcmp ogt double %2, %11
%13 = fcmp ogt double %11, 0.000000e+00
%14 = tail call i64 @time(i32* null)
br label %15
15: ; preds = %15, %9
%16 = phi i64 [ %7, %9 ], [ %18, %15 ]
%17 = tail call i64 @time(i32* null)
%18 = add nuw nsw i64 %16, 1
%19 = icmp eq i64 %17, %14
br i1 %19, label %15, label %20
20: ; preds = %15
%21 = select i1 %12, double %11, double %2
%22 = select i1 %13, double %11, double 0.000000e+00
%23 = sub nsw i64 %17, %14
%24 = sitofp i64 %23 to double
%25 = fcmp ogt double %21, %24
%26 = fcmp olt double %22, %24
%27 = select i1 %26, double %24, double %22
%28 = tail call i64 @time(i32* null)
br label %29
29: ; preds = %29, %20
%30 = phi i64 [ %18, %20 ], [ %32, %29 ]
%31 = tail call i64 @time(i32* null)
%32 = add nuw nsw i64 %30, 1
%33 = icmp eq i64 %31, %28
br i1 %33, label %29, label %34
34: ; preds = %29
%35 = select i1 %25, double %24, double %21
%36 = sub nsw i64 %31, %28
%37 = sitofp i64 %36 to double
%38 = fcmp ogt double %35, %37
%39 = fcmp olt double %27, %37
%40 = select i1 %39, double %37, double %27
%41 = tail call i64 @time(i32* null)
br label %42
42: ; preds = %42, %34
%43 = phi i64 [ %32, %34 ], [ %45, %42 ]
%44 = tail call i64 @time(i32* null)
%45 = add nsw i64 %43, 1
%46 = icmp eq i64 %44, %41
br i1 %46, label %42, label %47
47: ; preds = %42
%48 = select i1 %38, double %37, double %35
%49 = sub nsw i64 %44, %41
%50 = sitofp i64 %49 to double
%51 = fcmp olt double %40, %50
%52 = select i1 %51, double %50, double %40
%53 = tail call i64 @time(i32* null)
br label %54
54: ; preds = %54, %47
%55 = phi i64 [ %45, %47 ], [ %57, %54 ]
%56 = tail call i64 @time(i32* null)
%57 = add nsw i64 %55, 1
%58 = icmp eq i64 %56, %53
br i1 %58, label %54, label %59
59: ; preds = %54
%60 = fcmp ogt double %48, %50
%61 = fadd double %11, %24
%62 = fadd double %61, %37
%63 = select i1 %60, double %50, double %48
%64 = fadd double %62, %50
%65 = sub nsw i64 %56, %53
%66 = sitofp i64 %65 to double
%67 = fcmp ogt double %63, %66
%68 = select i1 %67, double %66, double %63
%69 = fcmp olt double %52, %66
%70 = select i1 %69, double %66, double %52
%71 = fadd double %64, %66
%72 = sitofp i64 %57 to double
%73 = insertelement <2 x double> poison, double %72, i64 0
%74 = insertelement <2 x double> %73, double %71, i64 1
%75 = fdiv <2 x double> %74, <double 5.000000e+00, double 5.000000e+00>
%76 = extractelement <2 x double> %75, i64 1
%77 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %76, double %68, double %70)
%78 = extractelement <2 x double> %75, i64 0
%79 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), double %78)
%80 = fdiv double %78, %76
%81 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double %80)
ret void
}