#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 *);
double kernel(int, double *, double, double, double *);
scalar_t__ malloc(int);
double sqrt(double);
int find_discontinuities(int n, double *t, double *chi, double dt, double Q,
                         double thresh) {
  int i, ind = -1;
  double tmid, val, maxv = 0.0;
  double *softr = (double *)malloc(n * sizeof(double));
  for (i = 0; i < n; ++i)
    softr[i] = chi[i] * sqrt(Q / (Q + chi[i] * chi[i]));
  for (i = 0; i < n - 1; ++i) {
    tmid = 0.5 * (t[i] + t[i + 1]);
    val = kernel(n, t, tmid, dt, softr);
    if (val >= thresh && val >= maxv) {
      ind = i;
      maxv = val;
    }
  }
  free(softr);
  return ind;
}


x86 assembly (clang, -O0):
<find_discontinuities>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movsd  %xmm2,-0x30(%rbp)
movl   $0xffffffff,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1205 <find_discontinuities+0xc5>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x58(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118b <find_discontinuities+0x4b>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12af <find_discontinuities+0x16f>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm1
movsd  0xdbc(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movsd  -0x40(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x58(%rbp),%rdx
call   1040 <kernel@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jb     129c <find_discontinuities+0x15c>
movsd  -0x48(%rbp),%xmm0
ucomisd -0x50(%rbp),%xmm0
jb     129c <find_discontinuities+0x15c>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    12a1 <find_discontinuities+0x161>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    120c <find_discontinuities+0xcc>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_discontinuities>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm2,0x30(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x28(%rsp)
mov    %rdx,%r13
mov    %rsi,%r15
mov    %edi,%ebx
lea    0x0(,%rbx,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    $0xffffffff,%r14d
test   %ebx,%ebx
jle    135c <find_discontinuities+0x21c>
mov    %ebx,%eax
cmp    $0x1,%ebx
mov    %rbx,0x18(%rsp)
mov    %rax,0x20(%rsp)
jne    11df <find_discontinuities+0x9f>
xor    %ebp,%ebp
movsd  0x8(%rsp),%xmm2
testb  $0x1,0x20(%rsp)
mov    0x18(%rsp),%rbx
je     12d2 <find_discontinuities+0x192>
movsd  0x0(%r13,%rbp,8),%xmm1
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jb     12b3 <find_discontinuities+0x173>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    12c8 <find_discontinuities+0x188>
mov    %eax,%ebx
and    $0xfffffffe,%ebx
xor    %ebp,%ebp
xorpd  %xmm3,%xmm3
movsd  0x8(%rsp),%xmm2
jmp    1233 <find_discontinuities+0xf3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm4,0x10(%rsp)
call   1060 <sqrt@plt>
movsd  0x10(%rsp),%xmm4
xorpd  %xmm3,%xmm3
movsd  0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm4
movsd  %xmm4,0x8(%r12,%rbp,8)
add    $0x2,%rbp
cmp    %rbp,%rbx
je     119e <find_discontinuities+0x5e>
movsd  0x0(%r13,%rbp,8),%xmm4
movapd %xmm4,%xmm1
mulsd  %xmm4,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm2,%xmm0
divsd  %xmm1,%xmm0
ucomisd %xmm3,%xmm0
jb     1260 <find_discontinuities+0x120>
sqrtsd %xmm0,%xmm0
jmp    127b <find_discontinuities+0x13b>
nopw   0x0(%rax,%rax,1)
movsd  %xmm4,0x10(%rsp)
call   1060 <sqrt@plt>
movsd  0x10(%rsp),%xmm4
xorpd  %xmm3,%xmm3
movsd  0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm4
movsd  %xmm4,(%r12,%rbp,8)
movsd  0x8(%r13,%rbp,8),%xmm4
movapd %xmm4,%xmm1
mulsd  %xmm4,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm2,%xmm0
divsd  %xmm1,%xmm0
ucomisd %xmm3,%xmm0
jb     1200 <find_discontinuities+0xc0>
sqrtsd %xmm0,%xmm0
jmp    121b <find_discontinuities+0xdb>
movapd %xmm2,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1060 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%rbp,8)
cmp    $0x2,%ebx
jl     135c <find_discontinuities+0x21c>
mov    0x18(%rsp),%rax
lea    -0x1(%rax),%r13d
mov    $0xffffffff,%r14d
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
jmp    1305 <find_discontinuities+0x1c5>
nopl   0x0(%rax,%rax,1)
cmp    %rbx,%r13
je     135c <find_discontinuities+0x21c>
mov    %r14d,%ebp
mov    %rbx,%r14
movsd  (%r15,%rbx,8),%xmm0
add    $0x1,%rbx
addsd  0x8(%r15,%r14,8),%xmm0
mulsd  0xcdc(%rip),%xmm0
mov    0x18(%rsp),%rdi
mov    %r15,%rsi
movsd  0x28(%rsp),%xmm1
mov    %r12,%rdx
call   1040 <kernel@plt>
ucomisd 0x30(%rsp),%xmm0
setb   %al
ucomisd 0x8(%rsp),%xmm0
setb   %cl
or     %al,%cl
cmovne %ebp,%r14d
jne    1300 <find_discontinuities+0x1c0>
movsd  %xmm0,0x8(%rsp)
jmp    1300 <find_discontinuities+0x1c0>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @find_discontinuities(i32 %0, double* %1, double* nocapture %2, double %3, double %4, double %5) {
%7 = shl i32 %0, 3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %73
11: ; preds = %6
%12 = zext i32 %0 to i64
%13 = and i64 %12, 1
%14 = icmp eq i32 %0, 1
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = and i64 %12, 4294967294
br label %33
17: ; preds = %33, %11
%18 = phi i64 [ 0, %11 ], [ %51, %33 ]
%19 = icmp eq i64 %13, 0
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = getelementptr inbounds double, double* %2, i64 %18
%22 = load double, double* %21
%23 = tail call double @llvm.fmuladd.f64(double %22, double %22, double %4)
%24 = fdiv double %4, %23
%25 = tail call double @sqrt(double %24)
%26 = fmul double %22, %25
%27 = getelementptr inbounds double, double* %9, i64 %18
store double %26, double* %27
br label %28
28: ; preds = %17, %20
%29 = icmp sgt i32 %0, 1
br i1 %29, label %30, label %73
30: ; preds = %28
%31 = add nsw i32 %0, -1
%32 = zext i32 %31 to i64
br label %54
33: ; preds = %33, %15
%34 = phi i64 [ 0, %15 ], [ %51, %33 ]
%35 = phi i64 [ 0, %15 ], [ %52, %33 ]
%36 = getelementptr inbounds double, double* %2, i64 %34
%37 = load double, double* %36
%38 = tail call double @llvm.fmuladd.f64(double %37, double %37, double %4)
%39 = fdiv double %4, %38
%40 = tail call double @sqrt(double %39)
%41 = fmul double %37, %40
%42 = getelementptr inbounds double, double* %9, i64 %34
store double %41, double* %42
%43 = or i64 %34, 1
%44 = getelementptr inbounds double, double* %2, i64 %43
%45 = load double, double* %44
%46 = tail call double @llvm.fmuladd.f64(double %45, double %45, double %4)
%47 = fdiv double %4, %46
%48 = tail call double @sqrt(double %47)
%49 = fmul double %45, %48
%50 = getelementptr inbounds double, double* %9, i64 %43
store double %49, double* %50
%51 = add nuw nsw i64 %34, 2
%52 = add i64 %35, 2
%53 = icmp eq i64 %52, %16
br i1 %53, label %17, label %33
54: ; preds = %30, %54
%55 = phi i64 [ 0, %30 ], [ %60, %54 ]
%56 = phi double [ 0.000000e+00, %30 ], [ %71, %54 ]
%57 = phi i32 [ -1, %30 ], [ %70, %54 ]
%58 = getelementptr inbounds double, double* %1, i64 %55
%59 = load double, double* %58
%60 = add nuw nsw i64 %55, 1
%61 = getelementptr inbounds double, double* %1, i64 %60
%62 = load double, double* %61
%63 = fadd double %59, %62
%64 = fmul double %63, 5.000000e-01
%65 = tail call double @kernel(i32 %0, double* %1, double %64, double %3, double* %9)
%66 = fcmp ult double %65, %5
%67 = fcmp ult double %65, %56
%68 = select i1 %66, i1 true, i1 %67
%69 = trunc i64 %55 to i32
%70 = select i1 %68, i32 %57, i32 %69
%71 = select i1 %68, double %56, double %65
%72 = icmp eq i64 %60, %32
br i1 %72, label %73, label %54
73: ; preds = %54, %6, %28
%74 = phi i32 [ -1, %28 ], [ -1, %6 ], [ %70, %54 ]
%75 = tail call i32 @free(double* %9)
ret i32 %74
}