; LLVM IR from RichtersFinger/ChainSimulation :: ChainLink.ll (ZN9ChainLinkC2EP12ChainElementS1_)

; 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"

%class.ChainElement = type { double, double, double, double, double, double, double, double, i8, ptr, ptr }
%class.ChainLink = type { ptr, ptr, double }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9ChainLinkC2EP12ChainElementS1_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %46

10:                                               ; preds = %3
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %46

13:                                               ; preds = %10
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.ChainElement, ptr %14, i32 0, i32 0
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.ChainElement, ptr %17, i32 0, i32 0
  %19 = load double, ptr %18, align 8, !tbaa !9
  %20 = fsub double %16, %19
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %class.ChainElement, ptr %21, i32 0, i32 0
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %class.ChainElement, ptr %24, i32 0, i32 0
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = fsub double %23, %26
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %class.ChainElement, ptr %28, i32 0, i32 1
  %30 = load double, ptr %29, align 8, !tbaa !13
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.ChainElement, ptr %31, i32 0, i32 1
  %33 = load double, ptr %32, align 8, !tbaa !13
  %34 = fsub double %30, %33
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %class.ChainElement, ptr %35, i32 0, i32 1
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %class.ChainElement, ptr %38, i32 0, i32 1
  %40 = load double, ptr %39, align 8, !tbaa !13
  %41 = fsub double %37, %40
  %42 = fmul double %34, %41
  %43 = call double @llvm.fmuladd.f64(double %20, double %27, double %42)
  %44 = call double @sqrt(double noundef %43) #3
  %45 = getelementptr inbounds %class.ChainLink, ptr %7, i32 0, i32 2
  store double %44, ptr %45, align 8, !tbaa !14
  br label %48

46:                                               ; preds = %10, %3
  %47 = getelementptr inbounds %class.ChainLink, ptr %7, i32 0, i32 2
  store double 0.000000e+00, ptr %47, align 8, !tbaa !14
  br label %48

48:                                               ; preds = %46, %13
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %class.ChainLink, ptr %7, i32 0, i32 0
  store ptr %49, ptr %50, align 8, !tbaa !16
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %class.ChainLink, ptr %7, i32 0, i32 1
  store ptr %51, ptr %52, align 8, !tbaa !17
  ret void
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #1

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

attributes #0 = { mustprogress 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 #1 = { 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 #2 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS12ChainElement", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !12, i64 64, !6, i64 72, !6, i64 80}
!11 = !{!"double", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!15, !11, i64 16}
!15 = !{!"_ZTS9ChainLink", !6, i64 0, !6, i64 8, !11, i64 16}
!16 = !{!15, !6, i64 0}
!17 = !{!15, !6, i64 8}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN9ChainLinkC2EP12ChainElementS1_(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2) unnamed_addr #0 align 2 {
  %4 = icmp ne ptr %1, null
  %5 = icmp ne ptr %2, null
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %6, label %17

6:                                                ; preds = %3
  %7 = load double, ptr %1, align 8, !tbaa !5
  %8 = load double, ptr %2, align 8, !tbaa !5
  %9 = fsub double %7, %8
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %2, i64 8
  %13 = load double, ptr %12, align 8, !tbaa !12
  %14 = fsub double %11, %13
  %15 = fmul double %14, %14
  %16 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %15)
  %sqrt = tail call double @llvm.sqrt.f64(double %16)
  br label %17

17:                                               ; preds = %3, %6
  %.sink = phi double [ %sqrt, %6 ], [ 0.000000e+00, %3 ]
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store double %.sink, ptr %18, align 8
  store ptr %1, ptr %0, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %2, ptr %19, align 8, !tbaa !15
  ret void
}

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

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !7, i64 0}
!6 = !{!"_ZTS12ChainElement", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !10, i64 64, !11, i64 72, !11, i64 80}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !11, i64 0}
!14 = !{!"_ZTS9ChainLink", !11, i64 0, !11, i64 8, !7, i64 16}
!15 = !{!14, !11, i64 8}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass