#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*/ add1(int, int);
int /*<<< orphan*/ assert(int);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double time_delta(struct timeval *, struct timeval *);
double measure(void) {
  long long i, iterations;
  int result;
  struct timeval start, stop;
  double elapsed;
  add1(0, 0);
  i = 0;
  iterations = 1000;
  result = gettimeofday(&start, NULL);
  assert(result == 0);
  while (1) {
    for (; i < iterations; i++) {
      add1(((int)i) & 0xaaaaaa, ((int)i) & 0x555555);
    }
    result = gettimeofday(&stop, NULL);
    assert(result == 0);
    elapsed = time_delta(&stop, &start);
    assert(elapsed >= 0.0);
    if (elapsed > 2.5)
      break;
    iterations = iterations * 3 / 2;
  }
  return elapsed / (double)iterations;
}


x86 assembly (clang, -O0):
<measure>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xor    %esi,%esi
mov    %esi,%edi
call   1060 <add1@plt>
movq   $0x0,-0x8(%rbp)
movq   $0x3e8,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
jmp    1187 <measure+0x47>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11c3 <measure+0x83>
mov    -0x8(%rbp),%rax
mov    %eax,%edi
and    $0xaaaaaa,%edi
mov    -0x8(%rbp),%rax
mov    %eax,%esi
and    $0x555555,%esi
call   1060 <add1@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1187 <measure+0x47>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <time_delta@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movsd  -0x28(%rbp),%xmm0
movsd  0xde4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    122b <measure+0xeb>
jmp    1243 <measure+0x103>
imul   $0x3,-0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    1182 <measure+0x42>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<measure>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
xor    %edi,%edi
xor    %esi,%esi
call   1060 <add1@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    $0x3e8,%r12d
lea    0x8(%rsp),%r15
cmp    %r12,%rbx
jge    11b1 <measure+0x71>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
and    $0xaaaaaa,%edi
mov    %ebx,%esi
and    $0x555555,%esi
call   1060 <add1@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <measure+0x50>
mov    %r12,%rbx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <time_delta@plt>
movsd  %xmm0,(%rsp)
xor    %edi,%edi
ucomisd 0xe26(%rip),%xmm0
setae  %dil
call   1050 <assert@plt>
movsd  (%rsp),%xmm0
ucomisd 0xe08(%rip),%xmm0
ja     1212 <measure+0xd2>
lea    (%r12,%r12,2),%rax
mov    %rax,%r12
shr    $0x3f,%r12
add    %rax,%r12
sar    %r12
cmp    %r12,%rbx
jl     1190 <measure+0x50>
jmp    11b1 <measure+0x71>
cvtsi2sd %r12,%xmm1
divsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
define double @measure() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca double
%7 = call i32 @add1(i32 0, i32 0)
store i64 0, i64* %1
store i64 1000, i64* %2
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
br label %13
13: ; preds = %0, %43
br label %14
14: ; preds = %26, %13
%15 = load i64, i64* %1
%16 = load i64, i64* %2
%17 = icmp slt i64 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i64, i64* %1
%20 = trunc i64 %19 to i32
%21 = and i32 %20, 11184810
%22 = load i64, i64* %1
%23 = trunc i64 %22 to i32
%24 = and i32 %23, 5592405
%25 = call i32 @add1(i32 %21, i32 %24)
br label %26
26: ; preds = %18
%27 = load i64, i64* %1
%28 = add nsw i64 %27, 1
store i64 %28, i64* %1
br label %14
29: ; preds = %14
%30 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i32 %30, i32* %3
%31 = load i32, i32* %3
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call double @time_delta(%struct.timeval* %5, %struct.timeval* %4)
store double %35, double* %6
%36 = load double, double* %6
%37 = fcmp oge double %36, 0.000000e+00
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load double, double* %6
%41 = fcmp ogt double %40, 2.500000e+00
br i1 %41, label %42, label %43
42: ; preds = %29
br label %47
43: ; preds = %29
%44 = load i64, i64* %2
%45 = mul nsw i64 %44, 3
%46 = sdiv i64 %45, 2
store i64 %46, i64* %2
br label %13
47: ; preds = %42
%48 = load double, double* %6
%49 = load i64, i64* %2
%50 = sitofp i64 %49 to double
%51 = fdiv double %48, %50
ret double %51
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
define double @measure() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = tail call i32 @add1(i32 0, i32 0)
%6 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
br label %10
10: ; preds = %33, %0
%11 = phi i64 [ 1000, %0 ], [ %35, %33 ]
%12 = phi i64 [ 0, %0 ], [ %23, %33 ]
%13 = icmp slt i64 %12, %11
br i1 %13, label %14, label %22
14: ; preds = %10, %14
%15 = phi i64 [ %20, %14 ], [ %12, %10 ]
%16 = trunc i64 %15 to i32
%17 = and i32 %16, 11184810
%18 = and i32 %16, 5592405
%19 = call i32 @add1(i32 %17, i32 %18)
%20 = add i64 %15, 1
%21 = icmp eq i64 %20, %11
br i1 %21, label %22, label %14
22: ; preds = %14, %10
%23 = phi i64 [ %12, %10 ], [ %11, %14 ]
%24 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call double @time_delta(%struct.timeval* %2, %struct.timeval* %1)
%29 = fcmp oge double %28, 0.000000e+00
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = fcmp ogt double %28, 2.500000e+00
br i1 %32, label %36, label %33
33: ; preds = %22
%34 = mul nsw i64 %11, 3
%35 = sdiv i64 %34, 2
br label %10
36: ; preds = %22
%37 = sitofp i64 %11 to double
%38 = fdiv double %28, %37
ret double %38
}