#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*/ FHTDoubleCombinedHelper(double *, int, int);
double sqrt(int);
int FHTDoubleCombined(double *buffer, int len, int chunk) {
  int i;
  double s;
  if (chunk < 8) {
    return -1;
  }
  if (len < 1 || len & (len - 1)) {
    return -1;
  }
  FHTDoubleCombinedHelper(buffer, len, chunk);
  s = 1.0 / sqrt(len + 0.0);
  for (i = 0; i < len; ++i) {
    buffer[i] *= s;
  }
  return 0;
}


x86 assembly (clang, -O0):
<FHTDoubleCombined>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    1148 <FHTDoubleCombined+0x28>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <FHTDoubleCombined+0xc9>
cmpl   $0x1,-0x14(%rbp)
jl     1166 <FHTDoubleCombined+0x46>
mov    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1172 <FHTDoubleCombined+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <FHTDoubleCombined+0xc9>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <FHTDoubleCombinedHelper@plt>
cvtsi2sdl -0x14(%rbp),%xmm0
xorps  %xmm1,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe5f(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e2 <FHTDoubleCombined+0xc2>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b1 <FHTDoubleCombined+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FHTDoubleCombined>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%eax
cmp    $0x8,%edx
jl     1279 <FHTDoubleCombined+0x159>
mov    %esi,%ebp
test   %esi,%esi
jle    1279 <FHTDoubleCombined+0x159>
mov    %ebp,%ecx
shr    %ecx
and    $0x55555555,%ecx
mov    %ebp,%esi
sub    %ecx,%esi
mov    %esi,%ecx
and    $0x33333333,%ecx
shr    $0x2,%esi
and    $0x33333333,%esi
add    %ecx,%esi
mov    %esi,%ecx
shr    $0x4,%ecx
add    %esi,%ecx
and    $0xf0f0f0f,%ecx
imul   $0x1010101,%ecx,%ecx
shr    $0x18,%ecx
cmp    $0x1,%ecx
ja     1279 <FHTDoubleCombined+0x159>
mov    %rdi,%rbx
mov    %ebp,%esi
call   1030 <FHTDoubleCombinedHelper@plt>
mov    %ebp,%edi
call   1040 <sqrt@plt>
movsd  0xe6c(%rip),%xmm1
divsd  %xmm0,%xmm1
mov    %ebp,%ecx
cmp    $0x4,%ebp
jae    11a6 <FHTDoubleCombined+0x86>
xor    %edx,%edx
jmp    1260 <FHTDoubleCombined+0x140>
mov    %ecx,%edx
and    $0xfffffffc,%edx
movapd %xmm1,%xmm0
unpcklpd %xmm1,%xmm0
lea    -0x4(%rdx),%rax
mov    %rax,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
test   %rax,%rax
je     1280 <FHTDoubleCombined+0x160>
mov    %rsi,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movupd (%rbx,%rax,8),%xmm2
movupd 0x10(%rbx,%rax,8),%xmm3
movupd 0x20(%rbx,%rax,8),%xmm4
movupd 0x30(%rbx,%rax,8),%xmm5
mulpd  %xmm0,%xmm2
mulpd  %xmm0,%xmm3
movupd %xmm2,(%rbx,%rax,8)
movupd %xmm3,0x10(%rbx,%rax,8)
mulpd  %xmm0,%xmm4
mulpd  %xmm0,%xmm5
movupd %xmm4,0x20(%rbx,%rax,8)
movupd %xmm5,0x30(%rbx,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%rdi
jne    11e0 <FHTDoubleCombined+0xc0>
test   $0x1,%sil
je     124c <FHTDoubleCombined+0x12c>
movupd (%rbx,%rax,8),%xmm2
movupd 0x10(%rbx,%rax,8),%xmm3
mulpd  %xmm0,%xmm2
mulpd  %xmm0,%xmm3
movupd %xmm2,(%rbx,%rax,8)
movupd %xmm3,0x10(%rbx,%rax,8)
xor    %eax,%eax
cmp    %rcx,%rdx
je     1279 <FHTDoubleCombined+0x159>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rbx,%rdx,8),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1260 <FHTDoubleCombined+0x140>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
test   $0x1,%sil
jne    122e <FHTDoubleCombined+0x10e>
jmp    124c <FHTDoubleCombined+0x12c>

LLVM IR (-O0):
define i32 @FHTDoubleCombined(double* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 8
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %50
13: ; preds = %3
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 1
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = load i32, i32* %6
%18 = load i32, i32* %6
%19 = sub nsw i32 %18, 1
%20 = and i32 %17, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16, %13
store i32 -1, i32* %4
br label %50
23: ; preds = %16
%24 = load double*, double** %5
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = call i32 @FHTDoubleCombinedHelper(double* %24, i32 %25, i32 %26)
%28 = load i32, i32* %6
%29 = sitofp i32 %28 to double
%30 = fadd double %29, 0.000000e+00
%31 = fptosi double %30 to i32
%32 = call double @sqrt(i32 %31)
%33 = fdiv double 1.000000e+00, %32
store double %33, double* %9
store i32 0, i32* %8
br label %34
34: ; preds = %46, %23
%35 = load i32, i32* %8
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = load double, double* %9
%40 = load double*, double** %5
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = fmul double %44, %39
store double %45, double* %43
br label %46
46: ; preds = %38
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %34
49: ; preds = %34
store i32 0, i32* %4
br label %50
50: ; preds = %49, %22, %12
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
define i32 @FHTDoubleCombined(double* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, 8
br i1 %4, label %81, label %5
5: ; preds = %3
%6 = icmp sgt i32 %1, 0
%7 = tail call i32 @llvm.ctpop.i32(i32 %1)
%8 = icmp ult i32 %7, 2
%9 = and i1 %6, %8
br i1 %9, label %10, label %81
10: ; preds = %5
%11 = tail call i32 @FHTDoubleCombinedHelper(double* %0, i32 %1, i32 %2)
%12 = tail call double @sqrt(i32 %1)
%13 = fdiv double 1.000000e+00, %12
%14 = zext i32 %1 to i64
%15 = icmp ult i32 %1, 4
br i1 %15, label %72, label %16
16: ; preds = %10
%17 = and i64 %14, 4294967292
%18 = insertelement <2 x double> poison, double %13, i64 0
%19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
%20 = insertelement <2 x double> poison, double %13, i64 0
%21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
%22 = add nsw i64 %17, -4
%23 = lshr exact i64 %22, 2
%24 = add nuw nsw i64 %23, 1
%25 = and i64 %24, 1
%26 = icmp eq i64 %22, 0
br i1 %26, label %56, label %27
27: ; preds = %16
%28 = and i64 %24, 9223372036854775806
br label %29
29: ; preds = %29, %27
%30 = phi i64 [ 0, %27 ], [ %53, %29 ]
%31 = phi i64 [ 0, %27 ], [ %54, %29 ]
%32 = getelementptr inbounds double, double* %0, i64 %30
%33 = bitcast double* %32 to <2 x double>*
%34 = load <2 x double>, <2 x double>* %33
%35 = getelementptr inbounds double, double* %32, i64 2
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = fmul <2 x double> %19, %34
%39 = fmul <2 x double> %21, %37
%40 = bitcast double* %32 to <2 x double>*
store <2 x double> %38, <2 x double>* %40
%41 = bitcast double* %35 to <2 x double>*
store <2 x double> %39, <2 x double>* %41
%42 = or i64 %30, 4
%43 = getelementptr inbounds double, double* %0, i64 %42
%44 = bitcast double* %43 to <2 x double>*
%45 = load <2 x double>, <2 x double>* %44
%46 = getelementptr inbounds double, double* %43, i64 2
%47 = bitcast double* %46 to <2 x double>*
%48 = load <2 x double>, <2 x double>* %47
%49 = fmul <2 x double> %19, %45
%50 = fmul <2 x double> %21, %48
%51 = bitcast double* %43 to <2 x double>*
store <2 x double> %49, <2 x double>* %51
%52 = bitcast double* %46 to <2 x double>*
store <2 x double> %50, <2 x double>* %52
%53 = add nuw i64 %30, 8
%54 = add i64 %31, 2
%55 = icmp eq i64 %54, %28
br i1 %55, label %56, label %29
56: ; preds = %29, %16
%57 = phi i64 [ 0, %16 ], [ %53, %29 ]
%58 = icmp eq i64 %25, 0
br i1 %58, label %70, label %59
59: ; preds = %56
%60 = getelementptr inbounds double, double* %0, i64 %57
%61 = bitcast double* %60 to <2 x double>*
%62 = load <2 x double>, <2 x double>* %61
%63 = getelementptr inbounds double, double* %60, i64 2
%64 = bitcast double* %63 to <2 x double>*
%65 = load <2 x double>, <2 x double>* %64
%66 = fmul <2 x double> %19, %62
%67 = fmul <2 x double> %21, %65
%68 = bitcast double* %60 to <2 x double>*
store <2 x double> %66, <2 x double>* %68
%69 = bitcast double* %63 to <2 x double>*
store <2 x double> %67, <2 x double>* %69
br label %70
70: ; preds = %56, %59
%71 = icmp eq i64 %17, %14
br i1 %71, label %81, label %72
72: ; preds = %10, %70
%73 = phi i64 [ 0, %10 ], [ %17, %70 ]
br label %74
74: ; preds = %72, %74
%75 = phi i64 [ %79, %74 ], [ %73, %72 ]
%76 = getelementptr inbounds double, double* %0, i64 %75
%77 = load double, double* %76
%78 = fmul double %13, %77
store double %78, double* %76
%79 = add nuw nsw i64 %75, 1
%80 = icmp eq i64 %79, %14
br i1 %80, label %81, label %74
81: ; preds = %74, %70, %5, %3
%82 = phi i32 [ -1, %3 ], [ -1, %5 ], [ 0, %70 ], [ 0, %74 ]
ret i32 %82
}