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

; 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.ChainLink = type { ptr, ptr, double }
%class.ChainElement = type { double, double, double, double, double, double, double, double, i8, ptr, ptr }

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9ChainLink17refreshLinkLengthEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %class.ChainLink, ptr %3, i32 0, i32 0
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %52

7:                                                ; preds = %1
  %8 = getelementptr inbounds %class.ChainLink, ptr %3, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %52

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

52:                                               ; preds = %7, %1
  %53 = getelementptr inbounds %class.ChainLink, ptr %3, i32 0, i32 2
  store double 0.000000e+00, ptr %53, align 8, !tbaa !17
  br label %54

54:                                               ; preds = %52, %11
  ret void
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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, !6, i64 0}
!10 = !{!"_ZTS9ChainLink", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !11, i64 0}
!14 = !{!"_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, !15, i64 64, !6, i64 72, !6, i64 80}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !11, i64 8}
!17 = !{!10, !11, i64 16}


; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN9ChainLink17refreshLinkLengthEv(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #1 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %17, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %.not2 = icmp eq ptr %5, null
  br i1 %.not2, label %17, label %6

6:                                                ; preds = %3
  %7 = load double, ptr %2, align 8, !tbaa !12
  %8 = load double, ptr %5, align 8, !tbaa !12
  %9 = fsub double %7, %8
  %10 = getelementptr inbounds i8, ptr %2, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %5, i64 8
  %13 = load double, ptr %12, align 8, !tbaa !15
  %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 = %1, %3, %6
  %.sink = phi double [ %sqrt, %6 ], [ 0.000000e+00, %3 ], [ 0.000000e+00, %1 ]
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store double %.sink, ptr %18, align 8, !tbaa !16
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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 = { 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 = !{!"_ZTS9ChainLink", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!13, !10, i64 0}
!13 = !{!"_ZTS12ChainElement", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !14, i64 64, !7, i64 72, !7, i64 80}
!14 = !{!"bool", !8, i64 0}
!15 = !{!13, !10, i64 8}
!16 = !{!6, !10, i64 16}


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