#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 */
double calcAw(int, double);
double calcXT(int, double);
int pow(int, double);
double calcAv(int n, double T) {
  double N = n;
  double Xt = calcXT(n, T);
  double Aw = calcAw(n, T);
  return (1 / (1 - pow(1 - 1 / (N - 1.0), Xt))) + Aw;
}


x86 assembly (clang, -O0):
<calcAv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
call   1030 <calcXT@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
call   1040 <calcAw@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe85(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe79(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe6d(%rip),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  -0x20(%rbp),%xmm0
call   1050 <pow@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
addsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcAv>:
push   %rbx
sub    $0x20,%rsp
movaps %xmm0,%xmm1
movsd  %xmm0,0x8(%rsp)
mov    %edi,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
movsd  %xmm0,0x10(%rsp)
movaps %xmm1,%xmm0
call   1030 <calcXT@plt>
movsd  %xmm0,0x18(%rsp)
mov    %ebx,%edi
movsd  0x8(%rsp),%xmm0
call   1040 <calcAw@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe8a(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm0
addsd  0xe7c(%rip),%xmm0
cvttsd2si %xmm0,%edi
movsd  0x18(%rsp),%xmm0
call   1050 <pow@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
xor    %edx,%edx
cmp    $0x3,%eax
cmovb  %ecx,%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @calcAv(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 %0, i32* %3
store double %1, double* %4
%8 = load i32, i32* %3
%9 = sitofp i32 %8 to double
store double %9, double* %5
%10 = load i32, i32* %3
%11 = load double, double* %4
%12 = call double @calcXT(i32 %10, double %11)
store double %12, double* %6
%13 = load i32, i32* %3
%14 = load double, double* %4
%15 = call double @calcAw(i32 %13, double %14)
store double %15, double* %7
%16 = load double, double* %5
%17 = fsub double %16, 1.000000e+00
%18 = fdiv double 1.000000e+00, %17
%19 = fsub double 1.000000e+00, %18
%20 = fptosi double %19 to i32
%21 = load double, double* %6
%22 = call i32 @pow(i32 %20, double %21)
%23 = sub nsw i32 1, %22
%24 = sdiv i32 1, %23
%25 = sitofp i32 %24 to double
%26 = load double, double* %7
%27 = fadd double %25, %26
ret double %27
}

LLVM IR (-O2):
define double @calcAv(i32 %0, double %1) {
%3 = sitofp i32 %0 to double
%4 = tail call double @calcXT(i32 %0, double %1)
%5 = tail call double @calcAw(i32 %0, double %1)
%6 = fadd double %3, -1.000000e+00
%7 = fdiv double 1.000000e+00, %6
%8 = fsub double 1.000000e+00, %7
%9 = fptosi double %8 to i32
%10 = tail call i32 @pow(i32 %9, double %4)
%11 = sub nsw i32 1, %10
%12 = icmp ult i32 %10, 3
%13 = select i1 %12, i32 %11, i32 0
%14 = sitofp i32 %13 to double
%15 = fadd double %5, %14
ret double %15
}