#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 */

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ printf(char *);
unsigned long long timing(int /*<<< orphan*/, unsigned long long);
unsigned long long calibrate(void) {
  unsigned long long i;
  printf("Calibrating reasonable sample size...\n");
  for (i = 5;; i++) {
    unsigned long long samples = 1 << i;
    if (timing(CLOCK_REALTIME, samples) / 1000000000ULL > 5)
      return samples;
  }
}


x86 assembly (clang, -O0):
<calibrate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1040 <printf@plt>
movq   $0x5,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1030 <timing@plt>
mov    $0x3b9aca00,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x5,%rax
jbe    117f <calibrate+0x5f>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret
jmp    1184 <calibrate+0x64>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113c <calibrate+0x1c>

x86 assembly (clang, -O2):
<calibrate>:
push   %r15
push   %r14
push   %rbx
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%ebx
mov    0x2ea3(%rip),%r15
nopl   (%rax)
mov    $0x1,%eax
mov    %ebx,%ecx
shl    %cl,%eax
movslq %eax,%r14
mov    (%r15),%edi
mov    %r14,%rsi
call   1040 <timing@plt>
shr    $0xa,%rax
add    $0x1,%ebx
cmp    $0x59682f,%rax
jb     1140 <calibrate+0x20>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Calibrating reasonable sample size...\0A\00"
@CLOCK_REALTIME = global i32 0
define i64 @calibrate() {
%1 = alloca i64
%2 = alloca i64
%3 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i64 5, i64* %1
br label %4
4: ; preds = %17, %0
%5 = load i64, i64* %1
%6 = trunc i64 %5 to i32
%7 = shl i32 1, %6
%8 = sext i32 %7 to i64
store i64 %8, i64* %2
%9 = load i32, i32* @CLOCK_REALTIME
%10 = load i64, i64* %2
%11 = call i64 @timing(i32 %9, i64 %10)
%12 = udiv i64 %11, 1000000000
%13 = icmp ugt i64 %12, 5
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = load i64, i64* %2
ret i64 %15
16: ; preds = %4
br label %17
17: ; preds = %16
%18 = load i64, i64* %1
%19 = add i64 %18, 1
store i64 %19, i64* %1
br label %4
}

LLVM IR (-O2):
@CLOCK_REALTIME = global i32 0
@str = [38 x i8] c"Calibrating reasonable sample size...\00"
define i64 @calibrate() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 5, %0 ], [ %10, %2 ]
%4 = trunc i64 %3 to i32
%5 = shl nuw i32 1, %4
%6 = sext i32 %5 to i64
%7 = load i32, i32* @CLOCK_REALTIME
%8 = tail call i64 @timing(i32 %7, i64 %6)
%9 = icmp ugt i64 %8, 5999999999
%10 = add i64 %3, 1
br i1 %9, label %11, label %2
11: ; preds = %2
ret i64 %6
}