#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 timeval {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ reset_timer(struct timeval *);
int /*<<< orphan*/ start_timer(struct timeval *);
int /*<<< orphan*/ stop_timer(struct timeval *, struct timeval *);
int timer_value(struct timeval *);
double soar_cDetermineTimerResolution(double *min, double *max) {
  double delta, max_delta, min_delta, min_nz_delta;
  float q;
  int i, j, top;
  struct timeval start, end, total;
  top = (1000000);
  min_delta = (1000000);
  min_nz_delta = (1000000);
  max_delta = -1;
  reset_timer(&total);
  for (i = 0; i < (1000000); i = (i + 1) * 2) {
    reset_timer(&end);
    start_timer(&start);
    for (j = 0; j < i * top; j++) {
      q = (float)(j * i);
    }
    stop_timer(&start, &end);
    stop_timer(&start, &total);
    delta = timer_value(&end);
    if (delta < min_delta)
      min_delta = delta;
    if (delta && delta < min_nz_delta)
      min_nz_delta = delta;
    if (delta > max_delta)
      max_delta = delta;
    if (timer_value(&total) >= 2) {
      break;
    }
  }
  if (min_nz_delta == (1000000))
    min_nz_delta = -1;
  if (min_delta == (1000000))
    min_delta = -1;
  if (min != NULL)
    *min = min_delta;
  if (max != NULL)
    *max = max_delta;
  return min_nz_delta;
}


x86 assembly (clang, -O0):
<soar_cDetermineTimerResolution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xf4240,-0x40(%rbp)
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe9c(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe87(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    -0x58(%rbp),%rdi
call   1030 <reset_timer@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0xf4240,-0x38(%rbp)
jge    12b0 <soar_cDetermineTimerResolution+0x170>
lea    -0x50(%rbp),%rdi
call   1030 <reset_timer@plt>
lea    -0x48(%rbp),%rdi
call   1050 <start_timer@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x38(%rbp),%ecx
imul   -0x40(%rbp),%ecx
cmp    %ecx,%eax
jge    11e4 <soar_cDetermineTimerResolution+0xa4>
mov    -0x3c(%rbp),%eax
imul   -0x38(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11b4 <soar_cDetermineTimerResolution+0x74>
lea    -0x48(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1060 <stop_timer@plt>
lea    -0x48(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1060 <stop_timer@plt>
lea    -0x50(%rbp),%rdi
call   1040 <timer_value@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    122e <soar_cDetermineTimerResolution+0xee>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    124b <soar_cDetermineTimerResolution+0x10b>
jp     124b <soar_cDetermineTimerResolution+0x10b>
jmp    1269 <soar_cDetermineTimerResolution+0x129>
movsd  -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1269 <soar_cDetermineTimerResolution+0x129>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1283 <soar_cDetermineTimerResolution+0x143>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    -0x58(%rbp),%rdi
call   1040 <timer_value@plt>
cmp    $0x2,%eax
jl     129a <soar_cDetermineTimerResolution+0x15a>
jmp    12b0 <soar_cDetermineTimerResolution+0x170>
jmp    129f <soar_cDetermineTimerResolution+0x15f>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
shl    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    118e <soar_cDetermineTimerResolution+0x4e>
movsd  -0x30(%rbp),%xmm0
movsd  0xd4b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    12da <soar_cDetermineTimerResolution+0x19a>
jp     12da <soar_cDetermineTimerResolution+0x19a>
movsd  0xd2b(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xd21(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1304 <soar_cDetermineTimerResolution+0x1c4>
jp     1304 <soar_cDetermineTimerResolution+0x1c4>
movsd  0xd01(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     131c <soar_cDetermineTimerResolution+0x1dc>
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     1334 <soar_cDetermineTimerResolution+0x1f4>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<soar_cDetermineTimerResolution>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x30(%rsp),%r12
mov    %r12,%rdi
call   1030 <reset_timer@plt>
movsd  0xe97(%rip),%xmm3
xor    %ebp,%ebp
movsd  0xe95(%rip),%xmm1
lea    0x38(%rsp),%r13
lea    0x40(%rsp),%rbx
movapd %xmm3,%xmm0
movapd %xmm3,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm3,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
mov    %r13,%rdi
call   1030 <reset_timer@plt>
mov    %rbx,%rdi
call   1050 <start_timer@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <stop_timer@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <stop_timer@plt>
mov    %r13,%rdi
call   1040 <timer_value@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
test   %eax,%eax
je     11e5 <soar_cDetermineTimerResolution+0xa5>
movapd %xmm1,%xmm0
minsd  0x20(%rsp),%xmm0
movapd %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
movapd %xmm1,%xmm2
minsd  %xmm0,%xmm2
movapd %xmm2,0x10(%rsp)
maxsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %r12,%rdi
call   1040 <timer_value@plt>
movapd 0x10(%rsp),%xmm4
movsd  0x8(%rsp),%xmm2
cmp    $0x1,%eax
jg     1237 <soar_cDetermineTimerResolution+0xf7>
add    %ebp,%ebp
or     $0x2,%ebp
movapd %xmm2,%xmm1
movapd %xmm4,%xmm3
cmp    $0xf4240,%ebp
jl     1190 <soar_cDetermineTimerResolution+0x50>
test   %r15,%r15
je     1262 <soar_cDetermineTimerResolution+0x122>
movsd  0xdbc(%rip),%xmm0
cmpeqsd %xmm4,%xmm0
movsd  0xdb7(%rip),%xmm1
andpd  %xmm0,%xmm1
andnpd %xmm4,%xmm0
orpd   %xmm1,%xmm0
movlpd %xmm0,(%r15)
test   %r14,%r14
je     126c <soar_cDetermineTimerResolution+0x12c>
movsd  %xmm2,(%r14)
movsd  0xd8c(%rip),%xmm0
movapd 0x20(%rsp),%xmm2
cmpeqsd %xmm2,%xmm0
movsd  0xd81(%rip),%xmm1
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
define double @soar_cDetermineTimerResolution(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca float
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.timeval
%14 = alloca %struct.timeval
%15 = alloca %struct.timeval
store double* %0, double** %3
store double* %1, double** %4
store i32 1000000, i32* %12
store double 1.000000e+06, double* %7
store double 1.000000e+06, double* %8
store double -1.000000e+00, double* %6
%16 = call i32 @reset_timer(%struct.timeval* %15)
store i32 0, i32* %10
br label %17
17: ; preds = %67, %2
%18 = load i32, i32* %10
%19 = icmp slt i32 %18, 1000000
br i1 %19, label %20, label %71
20: ; preds = %17
%21 = call i32 @reset_timer(%struct.timeval* %14)
%22 = call i32 @start_timer(%struct.timeval* %13)
store i32 0, i32* %11
br label %23
23: ; preds = %34, %20
%24 = load i32, i32* %11
%25 = load i32, i32* %10
%26 = load i32, i32* %12
%27 = mul nsw i32 %25, %26
%28 = icmp slt i32 %24, %27
br i1 %28, label %29, label %37
29: ; preds = %23
%30 = load i32, i32* %11
%31 = load i32, i32* %10
%32 = mul nsw i32 %30, %31
%33 = sitofp i32 %32 to float
store float %33, float* %9
br label %34
34: ; preds = %29
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %23
37: ; preds = %23
%38 = call i32 @stop_timer(%struct.timeval* %13, %struct.timeval* %14)
%39 = call i32 @stop_timer(%struct.timeval* %13, %struct.timeval* %15)
%40 = call i32 @timer_value(%struct.timeval* %14)
%41 = sitofp i32 %40 to double
store double %41, double* %5
%42 = load double, double* %5
%43 = load double, double* %7
%44 = fcmp olt double %42, %43
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = load double, double* %5
store double %46, double* %7
br label %47
47: ; preds = %45, %37
%48 = load double, double* %5
%49 = fcmp une double %48, 0.000000e+00
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load double, double* %5
%52 = load double, double* %8
%53 = fcmp olt double %51, %52
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = load double, double* %5
store double %55, double* %8
br label %56
56: ; preds = %54, %50, %47
%57 = load double, double* %5
%58 = load double, double* %6
%59 = fcmp ogt double %57, %58
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = load double, double* %5
store double %61, double* %6
br label %62
62: ; preds = %60, %56
%63 = call i32 @timer_value(%struct.timeval* %15)
%64 = icmp sge i32 %63, 2
br i1 %64, label %65, label %66
65: ; preds = %62
br label %71
66: ; preds = %62
br label %67
67: ; preds = %66
%68 = load i32, i32* %10
%69 = add nsw i32 %68, 1
%70 = mul nsw i32 %69, 2
store i32 %70, i32* %10
br label %17
71: ; preds = %65, %17
%72 = load double, double* %8
%73 = fcmp oeq double %72, 1.000000e+06
br i1 %73, label %74, label %75
74: ; preds = %71
store double -1.000000e+00, double* %8
br label %75
75: ; preds = %74, %71
%76 = load double, double* %7
%77 = fcmp oeq double %76, 1.000000e+06
br i1 %77, label %78, label %79
78: ; preds = %75
store double -1.000000e+00, double* %7
br label %79
79: ; preds = %78, %75
%80 = load double*, double** %3
%81 = icmp ne double* %80, null
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = load double, double* %7
%84 = load double*, double** %3
store double %83, double* %84
br label %85
85: ; preds = %82, %79
%86 = load double*, double** %4
%87 = icmp ne double* %86, null
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load double, double* %6
%90 = load double*, double** %4
store double %89, double* %90
br label %91
91: ; preds = %88, %85
%92 = load double, double* %8
ret double %92
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
define double @soar_cDetermineTimerResolution(double* writeonly %0, double* writeonly %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = call i32 @reset_timer(%struct.timeval* %5)
br label %10
10: ; preds = %2, %31
%11 = phi double [ -1.000000e+00, %2 ], [ %28, %31 ]
%12 = phi i32 [ 0, %2 ], [ %33, %31 ]
%13 = phi double [ 1.000000e+06, %2 ], [ %22, %31 ]
%14 = phi double [ 1.000000e+06, %2 ], [ %26, %31 ]
%15 = call i32 @reset_timer(%struct.timeval* %4)
%16 = call i32 @start_timer(%struct.timeval* %3)
%17 = call i32 @stop_timer(%struct.timeval* %3, %struct.timeval* %4)
%18 = call i32 @stop_timer(%struct.timeval* %3, %struct.timeval* %5)
%19 = call i32 @timer_value(%struct.timeval* %4)
%20 = sitofp i32 %19 to double
%21 = fcmp ogt double %13, %20
%22 = select i1 %21, double %20, double %13
%23 = icmp ne i32 %19, 0
%24 = fcmp ogt double %14, %20
%25 = select i1 %23, i1 %24, i1 false
%26 = select i1 %25, double %20, double %14
%27 = fcmp olt double %11, %20
%28 = select i1 %27, double %20, double %11
%29 = call i32 @timer_value(%struct.timeval* %5)
%30 = icmp sgt i32 %29, 1
br i1 %30, label %35, label %31
31: ; preds = %10
%32 = shl i32 %12, 1
%33 = or i32 %32, 2
%34 = icmp slt i32 %33, 1000000
br i1 %34, label %10, label %35
35: ; preds = %10, %31
%36 = icmp eq double* %0, null
br i1 %36, label %40, label %37
37: ; preds = %35
%38 = fcmp oeq double %22, 1.000000e+06
%39 = select i1 %38, double -1.000000e+00, double %22
store double %39, double* %0
br label %40
40: ; preds = %37, %35
%41 = icmp eq double* %1, null
br i1 %41, label %43, label %42
42: ; preds = %40
store double %28, double* %1
br label %43
43: ; preds = %42, %40
%44 = fcmp oeq double %26, 1.000000e+06
%45 = select i1 %44, double -1.000000e+00, double %26
ret double %45
}