#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 */
unsigned int atoi(char *);
unsigned int collatzLen(unsigned int);
int /*<<< orphan*/ printf(char *, double);
double sqrt(double);
int main(int argc, char **argv) {
  if (argc < 2)
    return -1;
  unsigned n = atoi(argv[1]);
  unsigned long long sum = 0;
  int count = 0;
  for (unsigned int i = 1;; ++i) {
    unsigned int len = collatzLen(i);
    if (len >= n)
      break;
    sum += len * len;
    ++count;
  }
  double res = sqrt((double)(sum) / (double)(count));
  printf("%f\n", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    116c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1228 <main+0xe8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1060 <collatzLen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jb     11ae <main+0x6e>
jmp    11d6 <main+0x96>
mov    -0x2c(%rbp),%eax
imul   -0x2c(%rbp),%eax
mov    %eax,%eax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1192 <main+0x52>
movaps 0xe23(%rip),%xmm1
movq   -0x20(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe22(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xe04(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0xffffffff,%eax
cmp    $0x2,%edi
jl     11f5 <main+0xb5>
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
call   1040 <atoi@plt>
mov    %eax,%r14d
mov    $0x1,%edi
call   1060 <collatzLen@plt>
cmp    %r14d,%eax
jae    11c6 <main+0x86>
mov    $0x2,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
imul   %eax,%eax
add    %rax,%rbp
mov    %ebx,%edi
call   1060 <collatzLen@plt>
add    $0x1,%ebx
cmp    %r14d,%eax
jb     1180 <main+0x40>
movq   %rbp,%xmm1
punpckldq 0xe6e(%rip),%xmm1
subpd  0xe76(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
add    $0xfffffffe,%ebx
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
divsd  %xmm1,%xmm0
jmp    11ce <main+0x8e>
movsd  0xe32(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11de <main+0x9e>
sqrtsd %xmm0,%xmm0
jmp    11e3 <main+0xa3>
call   1050 <sqrt@plt>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %48
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
store i64 0, i64* %7
store i32 0, i32* %8
store i32 1, i32* %9
br label %20
20: ; preds = %36, %15
%21 = load i32, i32* %9
%22 = call i32 @collatzLen(i32 %21)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = load i32, i32* %6
%25 = icmp uge i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %20
br label %39
27: ; preds = %20
%28 = load i32, i32* %10
%29 = load i32, i32* %10
%30 = mul i32 %28, %29
%31 = zext i32 %30 to i64
%32 = load i64, i64* %7
%33 = add i64 %32, %31
store i64 %33, i64* %7
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %36
36: ; preds = %27
%37 = load i32, i32* %9
%38 = add i32 %37, 1
store i32 %38, i32* %9
br label %20
39: ; preds = %26
%40 = load i64, i64* %7
%41 = uitofp i64 %40 to double
%42 = load i32, i32* %8
%43 = sitofp i32 %42 to double
%44 = fdiv double %41, %43
%45 = call double @sqrt(double %44)
store double %45, double* %11
%46 = load double, double* %11
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %46)
store i32 0, i32* %3
br label %48
48: ; preds = %39, %14
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %30, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = tail call i32 @collatzLen(i32 1)
%9 = icmp ult i32 %8, %7
br i1 %9, label %10, label %26
10: ; preds = %4, %10
%11 = phi i32 [ %20, %10 ], [ %8, %4 ]
%12 = phi i64 [ %17, %10 ], [ 0, %4 ]
%13 = phi i32 [ %19, %10 ], [ 1, %4 ]
%14 = phi i32 [ %18, %10 ], [ 0, %4 ]
%15 = mul i32 %11, %11
%16 = zext i32 %15 to i64
%17 = add i64 %12, %16
%18 = add nuw nsw i32 %14, 1
%19 = add nuw i32 %13, 1
%20 = tail call i32 @collatzLen(i32 %19)
%21 = icmp ult i32 %20, %7
br i1 %21, label %10, label %22
22: ; preds = %10
%23 = uitofp i64 %17 to double
%24 = sitofp i32 %18 to double
%25 = fdiv double %23, %24
br label %26
26: ; preds = %22, %4
%27 = phi double [ %25, %22 ], [ 0x7FF8000000000000, %4 ]
%28 = tail call double @sqrt(double %27)
%29 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %28)
br label %30
30: ; preds = %2, %26
%31 = phi i32 [ 0, %26 ], [ -1, %2 ]
ret i32 %31
}