#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*/ exit(int /*<<< orphan*/);
double thetah(int nsam, int segsites, char **list) {
  int s, frequency(char, int, int, char **);
  double pi, p1, nd, nnm1;
  pi = 0.0;
  nd = nsam;
  nnm1 = nd / (nd - 1.0);
  for (s = 0; s < segsites; s++) {
    p1 = frequency('1', s, nsam, list);
    pi += p1 * p1;
    if (s == 1 && 0)
      exit(0);
  }
  return (pi * 2.0 / (nd * (nd - 1.0)));
}


x86 assembly (clang, -O0):
<thetah>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xeaa(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e2 <thetah+0xc2>
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x31,%edi
call   1030 <frequency@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11cf <thetah+0xaf>
xor    %eax,%eax
test   $0x1,%al
jne    11c8 <thetah+0xa8>
jmp    11cf <thetah+0xaf>
xor    %edi,%edi
call   1040 <exit@plt>
jmp    11d4 <thetah+0xb4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116a <thetah+0x4a>
movsd  0xe1e(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  0xdff(%rip),%xmm3
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thetah>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cvtsi2sd %edi,%xmm1
test   %esi,%esi
jle    1180 <thetah+0x70>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebx
movsd  %xmm1,0x8(%rsp)
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
mov    $0x31,%edi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r14,%rcx
call   1030 <frequency@plt>
movsd  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1140 <thetah+0x30>
addsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
jmp    1184 <thetah+0x74>
xorpd  %xmm0,%xmm0
movsd  0xe74(%rip),%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @thetah(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
store double 0.000000e+00, double* %8
%12 = load i32, i32* %4
%13 = sitofp i32 %12 to double
store double %13, double* %10
%14 = load double, double* %10
%15 = load double, double* %10
%16 = fsub double %15, 1.000000e+00
%17 = fdiv double %14, %16
store double %17, double* %11
store i32 0, i32* %7
br label %18
18: ; preds = %38, %3
%19 = load i32, i32* %7
%20 = load i32, i32* %5
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %41
22: ; preds = %18
%23 = load i32, i32* %7
%24 = load i32, i32* %4
%25 = load i8**, i8*** %6
%26 = call i32 @frequency(i8 signext 49, i32 %23, i32 %24, i8** %25)
%27 = sitofp i32 %26 to double
store double %27, double* %9
%28 = load double, double* %9
%29 = load double, double* %9
%30 = load double, double* %8
%31 = call double @llvm.fmuladd.f64(double %28, double %29, double %30)
store double %31, double* %8
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %22
br i1 false, label %35, label %37
35: ; preds = %34
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %34, %22
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %18
41: ; preds = %18
%42 = load double, double* %8
%43 = fmul double %42, 2.000000e+00
%44 = load double, double* %10
%45 = load double, double* %10
%46 = fsub double %45, 1.000000e+00
%47 = fmul double %44, %46
%48 = fdiv double %43, %47
ret double %48
}

LLVM IR (-O2):
define double @thetah(i32 %0, i32 %1, i8** %2) {
%4 = sitofp i32 %0 to double
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %16
6: ; preds = %3, %6
%7 = phi i32 [ %12, %6 ], [ 0, %3 ]
%8 = phi double [ %11, %6 ], [ 0.000000e+00, %3 ]
%9 = tail call i32 @frequency(i8 signext 49, i32 %7, i32 %0, i8** %2)
%10 = sitofp i32 %9 to double
%11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %8)
%12 = add nuw nsw i32 %7, 1
%13 = icmp eq i32 %12, %1
br i1 %13, label %14, label %6
14: ; preds = %6
%15 = fmul double %11, 2.000000e+00
br label %16
16: ; preds = %14, %3
%17 = phi double [ 0.000000e+00, %3 ], [ %15, %14 ]
%18 = fadd double %4, -1.000000e+00
%19 = fmul double %18, %4
%20 = fdiv double %17, %19
ret double %20
}