#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 asum(double *, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ copyarr(double *, double *, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ vclear(double *, double, int);
int /*<<< orphan*/ vsp(double *, double *, double, int);
int /*<<< orphan*/ vst(double *, double *, double, int);
int /*<<< orphan*/ vvd(double *, double *, double *, int);
int /*<<< orphan*/ vvm(double *, double *, double *, int);
int /*<<< orphan*/ vvt(double *, double *, double *, int);
double chitest(double *a, double *p, int n) {
  double *x, *b, *pp;
  double y1 = 0.0, y2 = 0.0;
  int i;
  if ((pp = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  if (p != NULL)
    copyarr(p, pp, n);
  else
    vclear(pp, 1.0, n);
  y1 = asum(pp, n);
  y2 = asum(a, n);
  if ((y1 == 0.0) || (y2 == 0.0)) {
    free(pp);
    return 0.0;
  }
  if ((x = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  if ((b = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  vst(x, pp, y2 / y1, n);
  vsp(x, x, .0001, n);
  vvm(b, a, x, n);
  vvt(b, b, b, n);
  vvd(b, b, x, n);
  y1 = asum(b, n);
  free(x);
  free(b);
  return y1;
}


x86 assembly (clang, -O0):
<chitest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11fd <chitest+0x4d>
mov    -0x1c(%rbp),%esi
lea    0xe18(%rip),%rdi
call   1060 <fatalx@plt>
cmpq   $0x0,-0x18(%rbp)
je     121d <chitest+0x6d>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10b0 <copyarr@plt>
jmp    1231 <chitest+0x81>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
movsd  0xdd4(%rip),%xmm0
call   10d0 <vclear@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <asum@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <asum@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1270 <chitest+0xc0>
jp     1270 <chitest+0xc0>
jmp    1288 <chitest+0xd8>
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    129e <chitest+0xee>
jp     129e <chitest+0xee>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    138d <chitest+0x1dd>
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12c8 <chitest+0x118>
mov    -0x1c(%rbp),%esi
lea    0xd4d(%rip),%rdi
call   1060 <fatalx@plt>
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    12f2 <chitest+0x142>
mov    -0x1c(%rbp),%esi
lea    0xd23(%rip),%rdi
call   1060 <fatalx@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
movsd  -0x48(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
mov    -0x1c(%rbp),%edx
call   1040 <vst@plt>
mov    -0x28(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
movsd  0xce9(%rip),%xmm0
call   1050 <vsp@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   10c0 <vvm@plt>
mov    -0x30(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1090 <vvt@plt>
mov    -0x30(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1070 <vvd@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <asum@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chitest>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11ec <chitest+0x3c>
test   %rbx,%rbx
je     11ff <chitest+0x4f>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   10b0 <copyarr@plt>
jmp    1211 <chitest+0x61>
lea    0xe1d(%rip),%rdi
mov    %ebp,%esi
call   1060 <fatalx@plt>
test   %rbx,%rbx
jne    11dd <chitest+0x2d>
movsd  0xdf9(%rip),%xmm0
mov    %r15,%rdi
mov    %ebp,%esi
call   10d0 <vclear@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   10a0 <asum@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %ebp,%esi
call   10a0 <asum@plt>
xorpd  %xmm2,%xmm2
xorps  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm1
ucomisd %xmm2,%xmm1
jne    1249 <chitest+0x99>
jnp    1319 <chitest+0x169>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1259 <chitest+0xa9>
jnp    1319 <chitest+0x169>
movsd  %xmm0,(%rsp)
mov    %ebp,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1280 <chitest+0xd0>
lea    0xd97(%rip),%rdi
mov    %ebp,%esi
call   1060 <fatalx@plt>
mov    %ebp,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12a2 <chitest+0xf2>
lea    0xd75(%rip),%rdi
mov    %ebp,%esi
call   1060 <fatalx@plt>
movsd  (%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <vst@plt>
movsd  0xd46(%rip),%xmm0
mov    %r12,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <vsp@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %ebp,%ecx
call   10c0 <vvm@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1090 <vvt@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %ebp,%ecx
call   1070 <vvd@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   10a0 <asum@plt>
movsd  %xmm0,(%rsp)
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%r15
mov    %r15,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @chitest(double* %0, double* %1, i32 %2) {
%4 = alloca double
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double
%12 = alloca double
%13 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
%14 = load i32, i32* %7
%15 = call i64 @calloc(i32 %14, i32 8)
%16 = inttoptr i64 %15 to double*
store double* %16, double** %10
%17 = icmp eq double* %16, null
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i32, i32* %7
%20 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %3
%22 = load double*, double** %6
%23 = icmp ne double* %22, null
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load double*, double** %6
%26 = load double*, double** %10
%27 = load i32, i32* %7
%28 = call i32 @copyarr(double* %25, double* %26, i32 %27)
br label %33
29: ; preds = %21
%30 = load double*, double** %10
%31 = load i32, i32* %7
%32 = call i32 @vclear(double* %30, double 1.000000e+00, i32 %31)
br label %33
33: ; preds = %29, %24
%34 = load double*, double** %10
%35 = load i32, i32* %7
%36 = call double @asum(double* %34, i32 %35)
store double %36, double* %11
%37 = load double*, double** %5
%38 = load i32, i32* %7
%39 = call double @asum(double* %37, i32 %38)
store double %39, double* %12
%40 = load double, double* %11
%41 = fcmp oeq double %40, 0.000000e+00
br i1 %41, label %45, label %42
42: ; preds = %33
%43 = load double, double* %12
%44 = fcmp oeq double %43, 0.000000e+00
br i1 %44, label %45, label %48
45: ; preds = %42, %33
%46 = load double*, double** %10
%47 = call i32 @free(double* %46)
store double 0.000000e+00, double* %4
br label %99
48: ; preds = %42
%49 = load i32, i32* %7
%50 = call i64 @calloc(i32 %49, i32 8)
%51 = inttoptr i64 %50 to double*
store double* %51, double** %8
%52 = icmp eq double* %51, null
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load i32, i32* %7
%55 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %53, %48
%57 = load i32, i32* %7
%58 = call i64 @calloc(i32 %57, i32 8)
%59 = inttoptr i64 %58 to double*
store double* %59, double** %9
%60 = icmp eq double* %59, null
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i32, i32* %7
%63 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %62)
br label %64
64: ; preds = %61, %56
%65 = load double*, double** %8
%66 = load double*, double** %10
%67 = load double, double* %12
%68 = load double, double* %11
%69 = fdiv double %67, %68
%70 = load i32, i32* %7
%71 = call i32 @vst(double* %65, double* %66, double %69, i32 %70)
%72 = load double*, double** %8
%73 = load double*, double** %8
%74 = load i32, i32* %7
%75 = call i32 @vsp(double* %72, double* %73, double 1.000000e-04, i32 %74)
%76 = load double*, double** %9
%77 = load double*, double** %5
%78 = load double*, double** %8
%79 = load i32, i32* %7
%80 = call i32 @vvm(double* %76, double* %77, double* %78, i32 %79)
%81 = load double*, double** %9
%82 = load double*, double** %9
%83 = load double*, double** %9
%84 = load i32, i32* %7
%85 = call i32 @vvt(double* %81, double* %82, double* %83, i32 %84)
%86 = load double*, double** %9
%87 = load double*, double** %9
%88 = load double*, double** %8
%89 = load i32, i32* %7
%90 = call i32 @vvd(double* %86, double* %87, double* %88, i32 %89)
%91 = load double*, double** %9
%92 = load i32, i32* %7
%93 = call double @asum(double* %91, i32 %92)
store double %93, double* %11
%94 = load double*, double** %8
%95 = call i32 @free(double* %94)
%96 = load double*, double** %9
%97 = call i32 @free(double* %96)
%98 = load double, double* %11
store double %98, double* %4
br label %99
99: ; preds = %64, %45
%100 = load double, double* %4
ret double %100
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @chitest(double* %0, double* %1, i32 %2) {
%4 = tail call i64 @calloc(i32 %2, i32 8)
%5 = inttoptr i64 %4 to double*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %9
9: ; preds = %7, %3
%10 = icmp eq double* %1, null
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = tail call i32 @copyarr(double* %1, double* %5, i32 %2)
br label %15
13: ; preds = %9
%14 = tail call i32 @vclear(double* %5, double 1.000000e+00, i32 %2)
br label %15
15: ; preds = %13, %11
%16 = tail call double @asum(double* %5, i32 %2)
%17 = tail call double @asum(double* %0, i32 %2)
%18 = fcmp oeq double %16, 0.000000e+00
%19 = fcmp oeq double %17, 0.000000e+00
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %42, label %21
21: ; preds = %15
%22 = tail call i64 @calloc(i32 %2, i32 8)
%23 = inttoptr i64 %22 to double*
%24 = icmp eq i64 %22, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %27
27: ; preds = %25, %21
%28 = tail call i64 @calloc(i32 %2, i32 8)
%29 = inttoptr i64 %28 to double*
%30 = icmp eq i64 %28, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %33
33: ; preds = %31, %27
%34 = fdiv double %17, %16
%35 = tail call i32 @vst(double* %23, double* %5, double %34, i32 %2)
%36 = tail call i32 @vsp(double* %23, double* %23, double 1.000000e-04, i32 %2)
%37 = tail call i32 @vvm(double* %29, double* %0, double* %23, i32 %2)
%38 = tail call i32 @vvt(double* %29, double* %29, double* %29, i32 %2)
%39 = tail call i32 @vvd(double* %29, double* %29, double* %23, i32 %2)
%40 = tail call double @asum(double* %29, i32 %2)
%41 = tail call i32 @free(double* %23)
br label %42
42: ; preds = %15, %33
%43 = phi double* [ %29, %33 ], [ %5, %15 ]
%44 = phi double [ %40, %33 ], [ 0.000000e+00, %15 ]
%45 = tail call i32 @free(double* %43)
ret double %44
}