#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*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ mom(double *, int, double *, double *, double *, double *,
                       double *, double *);
double calc_curt(int nhap, int *freq) {
  int chap;
  double curt, *x1, *x2, *x3, *x4, *min, *max, *dfreq;
  dfreq = (double *)malloc(nhap * sizeof(double));
  x1 = (double *)malloc(nhap * sizeof(double));
  x2 = (double *)malloc(nhap * sizeof(double));
  x3 = (double *)malloc(nhap * sizeof(double));
  x4 = (double *)malloc(nhap * sizeof(double));
  min = (double *)malloc(nhap * sizeof(double));
  max = (double *)malloc(nhap * sizeof(double));
  for (chap = 0; chap < nhap; chap++)
    dfreq[chap] = freq[chap];
  curt = 0.0;
  mom(dfreq, nhap, x1, x2, x3, x4, min, max);
  curt = *x4;
  free(dfreq);
  free(x1);
  free(x2);
  free(x3);
  free(x4);
  free(min);
  free(max);
  return curt;
}


x86 assembly (clang, -O0):
<calc_curt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x58(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ff <calc_curt+0xcf>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
mov    -0x58(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cb <calc_curt+0x9b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    -0x48(%rbp),%r10
mov    -0x50(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <mom@plt>
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_curt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %edi,%r13d
lea    0x0(,%r13,8),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,0x30(%rsp)
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,0x28(%rsp)
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %r13d,%r13d
jle    1257 <calc_curt+0x127>
mov    %r13d,%ebp
cmp    $0x4,%r13d
jae    11b0 <calc_curt+0x80>
xor    %ecx,%ecx
jmp    1240 <calc_curt+0x110>
mov    %ebp,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rsi
mov    %rsi,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     12e8 <calc_curt+0x1b8>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
cvtdq2pd (%r14,%rsi,4),%xmm0
cvtdq2pd 0x8(%r14,%rsi,4),%xmm1
movups %xmm0,(%rbx,%rsi,8)
movups %xmm1,0x10(%rbx,%rsi,8)
cvtdq2pd 0x10(%r14,%rsi,4),%xmm0
cvtdq2pd 0x18(%r14,%rsi,4),%xmm1
movupd %xmm0,0x20(%rbx,%rsi,8)
movups %xmm1,0x30(%rbx,%rsi,8)
add    $0x8,%rsi
add    $0xfffffffffffffffe,%rdi
jne    11e0 <calc_curt+0xb0>
test   $0x1,%dl
je     1235 <calc_curt+0x105>
cvtdq2pd (%r14,%rsi,4),%xmm0
cvtdq2pd 0x8(%r14,%rsi,4),%xmm1
movupd %xmm0,(%rbx,%rsi,8)
movups %xmm1,0x10(%rbx,%rsi,8)
cmp    %rbp,%rcx
je     1257 <calc_curt+0x127>
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sdl (%r14,%rcx,4),%xmm0
movsd  %xmm0,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rbp
jne    1240 <calc_curt+0x110>
mov    %rbx,%rdi
mov    %r13d,%esi
mov    0x30(%rsp),%rbp
mov    %rbp,%rdx
mov    0x28(%rsp),%r14
mov    %r14,%rcx
mov    0x20(%rsp),%r13
mov    %r13,%r8
mov    %r15,%r9
push   %rax
mov    0x20(%rsp),%r12
push   %r12
mov    %rax,0x18(%rsp)
call   1040 <mom@plt>
add    $0x10,%rsp
movsd  (%r15),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
movsd  0x10(%rsp),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %esi,%esi
test   $0x1,%dl
jne    121e <calc_curt+0xee>
jmp    1235 <calc_curt+0x105>

LLVM IR (-O0):
define double @calc_curt(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
store i32 %0, i32* %3
store i32* %1, i32** %4
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 8
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %13
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 8
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to double*
store double* %25, double** %7
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 8
%29 = trunc i64 %28 to i32
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to double*
store double* %31, double** %8
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 8
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to double*
store double* %37, double** %9
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = mul i64 %39, 8
%41 = trunc i64 %40 to i32
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to double*
store double* %43, double** %10
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 8
%47 = trunc i64 %46 to i32
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to double*
store double* %49, double** %11
%50 = load i32, i32* %3
%51 = sext i32 %50 to i64
%52 = mul i64 %51, 8
%53 = trunc i64 %52 to i32
%54 = call i64 @malloc(i32 %53)
%55 = inttoptr i64 %54 to double*
store double* %55, double** %12
store i32 0, i32* %5
br label %56
56: ; preds = %71, %2
%57 = load i32, i32* %5
%58 = load i32, i32* %3
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %74
60: ; preds = %56
%61 = load i32*, i32** %4
%62 = load i32, i32* %5
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = sitofp i32 %65 to double
%67 = load double*, double** %13
%68 = load i32, i32* %5
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %67, i64 %69
store double %66, double* %70
br label %71
71: ; preds = %60
%72 = load i32, i32* %5
%73 = add nsw i32 %72, 1
store i32 %73, i32* %5
br label %56
74: ; preds = %56
store double 0.000000e+00, double* %6
%75 = load double*, double** %13
%76 = load i32, i32* %3
%77 = load double*, double** %7
%78 = load double*, double** %8
%79 = load double*, double** %9
%80 = load double*, double** %10
%81 = load double*, double** %11
%82 = load double*, double** %12
%83 = call i32 @mom(double* %75, i32 %76, double* %77, double* %78, double* %79, double* %80, double* %81, double* %82)
%84 = load double*, double** %10
%85 = load double, double* %84
store double %85, double* %6
%86 = load double*, double** %13
%87 = call i32 @free(double* %86)
%88 = load double*, double** %7
%89 = call i32 @free(double* %88)
%90 = load double*, double** %8
%91 = call i32 @free(double* %90)
%92 = load double*, double** %9
%93 = call i32 @free(double* %92)
%94 = load double*, double** %10
%95 = call i32 @free(double* %94)
%96 = load double*, double** %11
%97 = call i32 @free(double* %96)
%98 = load double*, double** %12
%99 = call i32 @free(double* %98)
%100 = load double, double* %6
ret double %100
}

LLVM IR (-O2):
define double @calc_curt(i32 %0, i32* nocapture %1) {
%3 = shl i32 %0, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to double*
%6 = tail call i64 @malloc(i32 %3)
%7 = inttoptr i64 %6 to double*
%8 = tail call i64 @malloc(i32 %3)
%9 = inttoptr i64 %8 to double*
%10 = tail call i64 @malloc(i32 %3)
%11 = inttoptr i64 %10 to double*
%12 = tail call i64 @malloc(i32 %3)
%13 = inttoptr i64 %12 to double*
%14 = tail call i64 @malloc(i32 %3)
%15 = inttoptr i64 %14 to double*
%16 = tail call i64 @malloc(i32 %3)
%17 = inttoptr i64 %16 to double*
%18 = icmp sgt i32 %0, 0
br i1 %18, label %19, label %90
19: ; preds = %2
%20 = zext i32 %0 to i64
%21 = icmp ult i32 %0, 4
br i1 %21, label %80, label %22
22: ; preds = %19
%23 = and i64 %20, 4294967292
%24 = add nsw i64 %23, -4
%25 = lshr exact i64 %24, 2
%26 = add nuw nsw i64 %25, 1
%27 = and i64 %26, 1
%28 = icmp eq i64 %24, 0
br i1 %28, label %62, label %29
29: ; preds = %22
%30 = and i64 %26, 9223372036854775806
br label %31
31: ; preds = %31, %29
%32 = phi i64 [ 0, %29 ], [ %59, %31 ]
%33 = phi i64 [ 0, %29 ], [ %60, %31 ]
%34 = getelementptr inbounds i32, i32* %1, i64 %32
%35 = bitcast i32* %34 to <2 x i32>*
%36 = load <2 x i32>, <2 x i32>* %35
%37 = getelementptr inbounds i32, i32* %34, i64 2
%38 = bitcast i32* %37 to <2 x i32>*
%39 = load <2 x i32>, <2 x i32>* %38
%40 = sitofp <2 x i32> %36 to <2 x double>
%41 = sitofp <2 x i32> %39 to <2 x double>
%42 = getelementptr inbounds double, double* %5, i64 %32
%43 = bitcast double* %42 to <2 x double>*
store <2 x double> %40, <2 x double>* %43
%44 = getelementptr inbounds double, double* %42, i64 2
%45 = bitcast double* %44 to <2 x double>*
store <2 x double> %41, <2 x double>* %45
%46 = or i64 %32, 4
%47 = getelementptr inbounds i32, i32* %1, i64 %46
%48 = bitcast i32* %47 to <2 x i32>*
%49 = load <2 x i32>, <2 x i32>* %48
%50 = getelementptr inbounds i32, i32* %47, i64 2
%51 = bitcast i32* %50 to <2 x i32>*
%52 = load <2 x i32>, <2 x i32>* %51
%53 = sitofp <2 x i32> %49 to <2 x double>
%54 = sitofp <2 x i32> %52 to <2 x double>
%55 = getelementptr inbounds double, double* %5, i64 %46
%56 = bitcast double* %55 to <2 x double>*
store <2 x double> %53, <2 x double>* %56
%57 = getelementptr inbounds double, double* %55, i64 2
%58 = bitcast double* %57 to <2 x double>*
store <2 x double> %54, <2 x double>* %58
%59 = add nuw i64 %32, 8
%60 = add i64 %33, 2
%61 = icmp eq i64 %60, %30
br i1 %61, label %62, label %31
62: ; preds = %31, %22
%63 = phi i64 [ 0, %22 ], [ %59, %31 ]
%64 = icmp eq i64 %27, 0
br i1 %64, label %78, label %65
65: ; preds = %62
%66 = getelementptr inbounds i32, i32* %1, i64 %63
%67 = bitcast i32* %66 to <2 x i32>*
%68 = load <2 x i32>, <2 x i32>* %67
%69 = getelementptr inbounds i32, i32* %66, i64 2
%70 = bitcast i32* %69 to <2 x i32>*
%71 = load <2 x i32>, <2 x i32>* %70
%72 = sitofp <2 x i32> %68 to <2 x double>
%73 = sitofp <2 x i32> %71 to <2 x double>
%74 = getelementptr inbounds double, double* %5, i64 %63
%75 = bitcast double* %74 to <2 x double>*
store <2 x double> %72, <2 x double>* %75
%76 = getelementptr inbounds double, double* %74, i64 2
%77 = bitcast double* %76 to <2 x double>*
store <2 x double> %73, <2 x double>* %77
br label %78
78: ; preds = %62, %65
%79 = icmp eq i64 %23, %20
br i1 %79, label %90, label %80
80: ; preds = %19, %78
%81 = phi i64 [ 0, %19 ], [ %23, %78 ]
br label %82
82: ; preds = %80, %82
%83 = phi i64 [ %88, %82 ], [ %81, %80 ]
%84 = getelementptr inbounds i32, i32* %1, i64 %83
%85 = load i32, i32* %84
%86 = sitofp i32 %85 to double
%87 = getelementptr inbounds double, double* %5, i64 %83
store double %86, double* %87
%88 = add nuw nsw i64 %83, 1
%89 = icmp eq i64 %88, %20
br i1 %89, label %90, label %82
90: ; preds = %82, %78, %2
%91 = tail call i32 @mom(double* %5, i32 %0, double* %7, double* %9, double* %11, double* %13, double* %15, double* %17)
%92 = load double, double* %13
%93 = tail call i32 @free(double* %5)
%94 = tail call i32 @free(double* %7)
%95 = tail call i32 @free(double* %9)
%96 = tail call i32 @free(double* %11)
%97 = tail call i32 @free(double* %13)
%98 = tail call i32 @free(double* %15)
%99 = tail call i32 @free(double* %17)
ret double %92
}