; LLVM IR from chrr/libECP :: src (ecp)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct._ECP = type { ptr, i32, i32 }
%struct._ECPGauss = type { i32, double, double, double }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local double @evalECP(ptr noundef %0, i32 noundef %1, double noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store double 0.000000e+00, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %14 = load double, ptr %6, align 8, !tbaa !11
  %15 = load double, ptr %6, align 8, !tbaa !11
  %16 = fmul double %14, %15
  store double %16, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._ECP, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  store ptr %19, ptr %13, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %57, %3
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._ECP, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !15
  %25 = icmp slt i32 %21, %24
  br i1 %25, label %26, label %60

26:                                               ; preds = %20
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = load ptr, ptr %13, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._ECPGauss, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !16
  %31 = icmp eq i32 %27, %30
  br i1 %31, label %32, label %54

32:                                               ; preds = %26
  %33 = load ptr, ptr %13, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._ECPGauss, ptr %33, i32 0, i32 1
  %35 = load double, ptr %34, align 8, !tbaa !18
  store double %35, ptr %8, align 8, !tbaa !11
  %36 = load ptr, ptr %13, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._ECPGauss, ptr %36, i32 0, i32 2
  %38 = load double, ptr %37, align 8, !tbaa !19
  store double %38, ptr %9, align 8, !tbaa !11
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._ECPGauss, ptr %39, i32 0, i32 3
  %41 = load double, ptr %40, align 8, !tbaa !20
  store double %41, ptr %10, align 8, !tbaa !11
  %42 = load double, ptr %6, align 8, !tbaa !11
  %43 = load double, ptr %10, align 8, !tbaa !11
  %44 = call double @pow(double noundef %42, double noundef %43) #4
  %45 = load double, ptr %9, align 8, !tbaa !11
  %46 = fmul double %44, %45
  %47 = load double, ptr %8, align 8, !tbaa !11
  %48 = fneg double %47
  %49 = load double, ptr %12, align 8, !tbaa !11
  %50 = fmul double %48, %49
  %51 = call double @exp(double noundef %50) #4
  %52 = load double, ptr %11, align 8, !tbaa !11
  %53 = call double @llvm.fmuladd.f64(double %46, double %51, double %52)
  store double %53, ptr %11, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %32, %26
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._ECPGauss, ptr %55, i32 1
  store ptr %56, ptr %13, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %54
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !21

60:                                               ; preds = %20
  %61 = load double, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret double %61
}

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #2

; Function Attrs: nounwind
declare double @exp(double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ECP", !6, i64 0, !10, i64 8, !10, i64 12}
!15 = !{!14, !10, i64 8}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ECPGauss", !10, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!18 = !{!17, !12, i64 8}
!19 = !{!17, !12, i64 16}
!20 = !{!17, !12, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nofree nounwind memory(readwrite, inaccessiblemem: write) uwtable
define dso_local double @evalECP(ptr nocapture noundef readonly %0, i32 noundef %1, double noundef %2) local_unnamed_addr #0 {
  %4 = fmul double %2, %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %8 = load ptr, ptr %0, align 8, !tbaa !11
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %25
  %9 = phi i32 [ %26, %25 ], [ %6, %.lr.ph.preheader ]
  %.022 = phi ptr [ %27, %25 ], [ %8, %.lr.ph.preheader ]
  %.01821 = phi i32 [ %28, %25 ], [ 0, %.lr.ph.preheader ]
  %.01920 = phi double [ %.1, %25 ], [ 0.000000e+00, %.lr.ph.preheader ]
  %10 = load i32, ptr %.022, align 8, !tbaa !12
  %11 = icmp eq i32 %10, %1
  br i1 %11, label %12, label %25

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds i8, ptr %.022, i64 8
  %14 = load double, ptr %13, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %.022, i64 16
  %16 = load double, ptr %15, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %.022, i64 24
  %18 = load double, ptr %17, align 8, !tbaa !17
  %19 = tail call double @pow(double noundef %2, double noundef %18) #3
  %20 = fmul double %16, %19
  %21 = fneg double %14
  %22 = fmul double %4, %21
  %23 = tail call double @exp(double noundef %22) #3
  %24 = tail call double @llvm.fmuladd.f64(double %20, double %23, double %.01920)
  %.pre = load i32, ptr %5, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %12, %.lr.ph
  %26 = phi i32 [ %.pre, %12 ], [ %9, %.lr.ph ]
  %.1 = phi double [ %24, %12 ], [ %.01920, %.lr.ph ]
  %27 = getelementptr inbounds i8, ptr %.022, i64 32
  %28 = add nuw nsw i32 %.01821, 1
  %29 = icmp slt i32 %28, %26
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %25, %3
  %.019.lcssa = phi double [ 0.000000e+00, %3 ], [ %.1, %25 ]
  ret double %.019.lcssa
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @exp(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { nofree nounwind memory(readwrite, inaccessiblemem: write) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !10, i64 8}
!6 = !{!"_ECP", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"_ECPGauss", !10, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!14 = !{!"double", !8, i64 0}
!15 = !{!13, !14, i64 8}
!16 = !{!13, !14, i64 16}
!17 = !{!13, !14, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass