; LLVM IR from ange-yaghi/simple-2d-constraint-solver :: src/spring.ll (ZNK7atg_scs6Spring6energyEv)

; 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.atg_scs::Spring" = type { %"class.atg_scs::ForceGenerator.base", double, double, double, double, double, double, double, ptr, ptr }
%"class.atg_scs::ForceGenerator.base" = type <{ ptr, i32 }>

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

declare void @_ZN7atg_scs9RigidBody12localToWorldEddPdS1_(ptr noundef nonnull align 8 dereferenceable(68), double noundef, double noundef, ptr noundef, ptr noundef) #1

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK7atg_scs6Spring6energyEv(ptr noundef nonnull align 8 dereferenceable(88) %0) #4 align 2 {
  %2 = alloca double, align 8
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8
  %12 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 8
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp eq ptr %13, null
  br i1 %14, label %19, label %15

15:                                               ; preds = %1
  %16 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 9
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %15, %1
  store double 0.000000e+00, ptr %2, align 8
  br label %59

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %21 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 8
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 4
  %24 = load double, ptr %23, align 8, !tbaa !15
  %25 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 5
  %26 = load double, ptr %25, align 8, !tbaa !16
  call void @_ZN7atg_scs9RigidBody12localToWorldEddPdS1_(ptr noundef nonnull align 8 dereferenceable(68) %22, double noundef %24, double noundef %26, ptr noundef %4, ptr noundef %5)
  %27 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 9
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 6
  %30 = load double, ptr %29, align 8, !tbaa !17
  %31 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 7
  %32 = load double, ptr %31, align 8, !tbaa !18
  call void @_ZN7atg_scs9RigidBody12localToWorldEddPdS1_(ptr noundef nonnull align 8 dereferenceable(68) %28, double noundef %30, double noundef %32, ptr noundef %6, ptr noundef %7)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %33 = load double, ptr %6, align 8, !tbaa !19
  %34 = load double, ptr %4, align 8, !tbaa !19
  %35 = fsub double %33, %34
  store double %35, ptr %8, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %36 = load double, ptr %7, align 8, !tbaa !19
  %37 = load double, ptr %5, align 8, !tbaa !19
  %38 = fsub double %36, %37
  store double %38, ptr %9, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %39 = load double, ptr %8, align 8, !tbaa !19
  %40 = load double, ptr %8, align 8, !tbaa !19
  %41 = load double, ptr %9, align 8, !tbaa !19
  %42 = load double, ptr %9, align 8, !tbaa !19
  %43 = fmul double %41, %42
  %44 = call double @llvm.fmuladd.f64(double %39, double %40, double %43)
  %45 = call double @sqrt(double noundef %44) #5
  store double %45, ptr %10, align 8, !tbaa !19
  %46 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 2
  %47 = load double, ptr %46, align 8, !tbaa !20
  %48 = fmul double 5.000000e-01, %47
  %49 = load double, ptr %10, align 8, !tbaa !19
  %50 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 1
  %51 = load double, ptr %50, align 8, !tbaa !21
  %52 = fsub double %49, %51
  %53 = fmul double %48, %52
  %54 = load double, ptr %10, align 8, !tbaa !19
  %55 = getelementptr inbounds %"class.atg_scs::Spring", ptr %11, i32 0, i32 1
  %56 = load double, ptr %55, align 8, !tbaa !21
  %57 = fsub double %54, %56
  %58 = fmul double %53, %57
  store double %58, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %59

59:                                               ; preds = %20, %19
  %60 = load double, ptr %2, align 8
  ret double %60
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { mustprogress 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 #5 = { 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 72}
!10 = !{!"_ZTSN7atg_scs6SpringE", !11, i64 0, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !6, i64 72, !6, i64 80}
!11 = !{!"_ZTSN7atg_scs14ForceGeneratorE", !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!10, !6, i64 80}
!15 = !{!10, !13, i64 40}
!16 = !{!10, !13, i64 48}
!17 = !{!10, !13, i64 56}
!18 = !{!10, !13, i64 64}
!19 = !{!13, !13, i64 0}
!20 = !{!10, !13, i64 24}
!21 = !{!10, !13, 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @_ZN7atg_scs9RigidBody12localToWorldEddPdS1_(ptr noundef nonnull align 8 dereferenceable(68), double noundef, double noundef, ptr noundef, ptr 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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK7atg_scs6Spring6energyEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(88) %0) local_unnamed_addr #3 align 2 {
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %39, label %9

9:                                                ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 80
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = icmp eq ptr %11, null
  br i1 %12, label %39, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %14 = getelementptr inbounds i8, ptr %0, i64 40
  %15 = load double, ptr %14, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 48
  %17 = load double, ptr %16, align 8, !tbaa !15
  call void @_ZN7atg_scs9RigidBody12localToWorldEddPdS1_(ptr noundef nonnull align 8 dereferenceable(68) %7, double noundef %15, double noundef %17, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %18 = load ptr, ptr %10, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %20 = load double, ptr %19, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %0, i64 64
  %22 = load double, ptr %21, align 8, !tbaa !17
  call void @_ZN7atg_scs9RigidBody12localToWorldEddPdS1_(ptr noundef nonnull align 8 dereferenceable(68) %18, double noundef %20, double noundef %22, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %23 = load double, ptr %4, align 8, !tbaa !18
  %24 = load double, ptr %2, align 8, !tbaa !18
  %25 = fsub double %23, %24
  %26 = load double, ptr %5, align 8, !tbaa !18
  %27 = load double, ptr %3, align 8, !tbaa !18
  %28 = fsub double %26, %27
  %29 = fmul double %28, %28
  %30 = call double @llvm.fmuladd.f64(double %25, double %25, double %29)
  %sqrt = call double @llvm.sqrt.f64(double %30)
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  %32 = load double, ptr %31, align 8, !tbaa !19
  %33 = fmul double %32, 5.000000e-01
  %34 = getelementptr inbounds i8, ptr %0, i64 16
  %35 = load double, ptr %34, align 8, !tbaa !20
  %36 = fsub double %sqrt, %35
  %37 = fmul double %33, %36
  %38 = fmul double %36, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  br label %39

39:                                               ; preds = %1, %9, %13
  %.0 = phi double [ %38, %13 ], [ 0.000000e+00, %9 ], [ 0.000000e+00, %1 ]
  ret double %.0
}

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

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


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