#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 aitkenExtrapolate(double *, double *, int);
int /*<<< orphan*/ free(double *);
double *malloc(int);
double extrapolateSum(double x, int n) {
  double *seq1, *seq2, sum, prod, sign;
  int i;
  seq1 = malloc(sizeof(double) * n);
  seq2 = malloc(sizeof(double) * (n - 2));
  sum = 0;
  prod = 1;
  for (i = 1; i <= n; i++) {
    prod *= x;
    sign = (i % 2 == 0) ? -1 : 1;
    sum += sign * prod / i;
    seq1[i - 1] = sum;
  }
  sum = aitkenExtrapolate(seq1, seq2, n);
  free(seq1);
  free(seq2);
  return sum;
}


x86 assembly (clang, -O0):
<extrapolateSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe86(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1207 <extrapolateSum+0xd7>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1186 <extrapolateSum+0x56>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <aitkenExtrapolate@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extrapolateSum>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
movsd  %xmm0,0x8(%rsp)
lea    0x0(,%r14,8),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    -0x10(,%r14,8),%edi
ff
call   1050 <malloc@plt>
movsd  0x8(%rsp),%xmm4
mov    %rax,%r15
test   %r14d,%r14d
jle    11ca <extrapolateSum+0x9a>
lea    0x1(%r14),%eax
movsd  0xe87(%rip),%xmm0
xorpd  %xmm1,%xmm1
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mulsd  %xmm4,%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
mov    %ecx,%edx
and    $0x1,%edx
cmp    $0x1,%edx
sbb    %edx,%edx
or     $0x1,%edx
xorps  %xmm3,%xmm3
cvtsi2sd %edx,%xmm3
mulsd  %xmm0,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm3,%xmm1
movsd  %xmm1,-0x8(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1190 <extrapolateSum+0x60>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <aitkenExtrapolate@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @extrapolateSum(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = mul i64 8, %12
%14 = trunc i64 %13 to i32
%15 = call double* @malloc(i32 %14)
store double* %15, double** %5
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 2
%18 = sext i32 %17 to i64
%19 = mul i64 8, %18
%20 = trunc i64 %19 to i32
%21 = call double* @malloc(i32 %20)
store double* %21, double** %6
store double 0.000000e+00, double* %7
store double 1.000000e+00, double* %8
store i32 1, i32* %10
br label %22
22: ; preds = %50, %2
%23 = load i32, i32* %10
%24 = load i32, i32* %4
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %53
26: ; preds = %22
%27 = load double, double* %3
%28 = load double, double* %8
%29 = fmul double %28, %27
store double %29, double* %8
%30 = load i32, i32* %10
%31 = srem i32 %30, 2
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 -1, i32 1
%35 = sitofp i32 %34 to double
store double %35, double* %9
%36 = load double, double* %9
%37 = load double, double* %8
%38 = fmul double %36, %37
%39 = load i32, i32* %10
%40 = sitofp i32 %39 to double
%41 = fdiv double %38, %40
%42 = load double, double* %7
%43 = fadd double %42, %41
store double %43, double* %7
%44 = load double, double* %7
%45 = load double*, double** %5
%46 = load i32, i32* %10
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %45, i64 %48
store double %44, double* %49
br label %50
50: ; preds = %26
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %22
53: ; preds = %22
%54 = load double*, double** %5
%55 = load double*, double** %6
%56 = load i32, i32* %4
%57 = call double @aitkenExtrapolate(double* %54, double* %55, i32 %56)
store double %57, double* %7
%58 = load double*, double** %5
%59 = call i32 @free(double* %58)
%60 = load double*, double** %6
%61 = call i32 @free(double* %60)
%62 = load double, double* %7
ret double %62
}

LLVM IR (-O2):
define double @extrapolateSum(double %0, i32 %1) {
%3 = shl i32 %1, 3
%4 = tail call double* @malloc(i32 %3)
%5 = add i32 %3, -16
%6 = tail call double* @malloc(i32 %5)
%7 = icmp slt i32 %1, 1
br i1 %7, label %29, label %8
8: ; preds = %2
%9 = add nuw i32 %1, 1
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ 1, %8 ], [ %27, %11 ]
%13 = phi double [ 0.000000e+00, %8 ], [ %24, %11 ]
%14 = phi double [ 1.000000e+00, %8 ], [ %15, %11 ]
%15 = fmul double %14, %0
%16 = trunc i64 %12 to i32
%17 = and i32 %16, 1
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i32 -1, i32 1
%20 = sitofp i32 %19 to double
%21 = fmul double %15, %20
%22 = sitofp i32 %16 to double
%23 = fdiv double %21, %22
%24 = fadd double %13, %23
%25 = add nsw i64 %12, -1
%26 = getelementptr inbounds double, double* %4, i64 %25
store double %24, double* %26
%27 = add nuw nsw i64 %12, 1
%28 = icmp eq i64 %27, %10
br i1 %28, label %29, label %11
29: ; preds = %11, %2
%30 = tail call double @aitkenExtrapolate(double* %4, double* %6, i32 %1)
%31 = tail call i32 @free(double* %4)
%32 = tail call i32 @free(double* %6)
ret double %30
}