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

; 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::ConstantSpeedMotor" = type { %"class.atg_scs::ForceGenerator.base", double, double, double, double, ptr, ptr }
%"class.atg_scs::ForceGenerator.base" = type <{ ptr, i32 }>
%"struct.atg_scs::RigidBody" = type <{ double, double, double, double, double, double, double, double, i32, [4 x i8] }>
%"class.atg_scs::SystemState" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, double }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7atg_scs18ConstantSpeedMotor5applyEPNS_11SystemStateE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, 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
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 5
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %"struct.atg_scs::RigidBody", ptr %16, i32 0, i32 8
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %21

20:                                               ; preds = %2
  store double 0.000000e+00, ptr %6, align 8, !tbaa !16
  store double 0.000000e+00, ptr %5, align 8, !tbaa !16
  br label %42

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.atg_scs::SystemState", ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 5
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds %"struct.atg_scs::RigidBody", ptr %26, i32 0, i32 8
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %24, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !16
  store double %31, ptr %5, align 8, !tbaa !16
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.atg_scs::SystemState", ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  %35 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 5
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %"struct.atg_scs::RigidBody", ptr %36, i32 0, i32 8
  %38 = load i32, ptr %37, align 8, !tbaa !14
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %34, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !16
  store double %41, ptr %6, align 8, !tbaa !16
  br label %42

42:                                               ; preds = %21, %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.atg_scs::SystemState", ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 6
  %47 = load ptr, ptr %46, align 8, !tbaa !20
  %48 = getelementptr inbounds %"struct.atg_scs::RigidBody", ptr %47, i32 0, i32 8
  %49 = load i32, ptr %48, align 8, !tbaa !14
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %45, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !16
  %53 = load double, ptr %5, align 8, !tbaa !16
  %54 = fsub double %52, %53
  store double %54, ptr %7, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %"class.atg_scs::SystemState", ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !19
  %58 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 6
  %59 = load ptr, ptr %58, align 8, !tbaa !20
  %60 = getelementptr inbounds %"struct.atg_scs::RigidBody", ptr %59, i32 0, i32 8
  %61 = load i32, ptr %60, align 8, !tbaa !14
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %57, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !16
  %65 = load double, ptr %6, align 8, !tbaa !16
  %66 = fsub double %64, %65
  store double %66, ptr %8, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %67 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 4
  %68 = load double, ptr %67, align 8, !tbaa !21
  %69 = load double, ptr %7, align 8, !tbaa !16
  %70 = fsub double %68, %69
  store double %70, ptr %9, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %71 = load double, ptr %9, align 8, !tbaa !16
  %72 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 1
  %73 = load double, ptr %72, align 8, !tbaa !22
  %74 = fmul double %71, %73
  store double %74, ptr %10, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %75 = load double, ptr %8, align 8, !tbaa !16
  %76 = fneg double %75
  %77 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 2
  %78 = load double, ptr %77, align 8, !tbaa !23
  %79 = fmul double %76, %78
  store double %79, ptr %11, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %80 = load double, ptr %10, align 8, !tbaa !16
  %81 = load double, ptr %11, align 8, !tbaa !16
  %82 = fadd double %80, %81
  store double %82, ptr %12, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %83 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 3
  %84 = load double, ptr %83, align 8, !tbaa !24
  %85 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 3
  %86 = load double, ptr %85, align 8, !tbaa !24
  %87 = fneg double %86
  %88 = load double, ptr %12, align 8, !tbaa !16
  %89 = call double @llvm.maxnum.f64(double %87, double %88)
  %90 = call double @llvm.minnum.f64(double %84, double %89)
  store double %90, ptr %13, align 8, !tbaa !16
  %91 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 5
  %92 = load ptr, ptr %91, align 8, !tbaa !9
  %93 = getelementptr inbounds %"struct.atg_scs::RigidBody", ptr %92, i32 0, i32 8
  %94 = load i32, ptr %93, align 8, !tbaa !14
  %95 = icmp ne i32 %94, -1
  br i1 %95, label %96, label %109

96:                                               ; preds = %42
  %97 = load double, ptr %13, align 8, !tbaa !16
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %"class.atg_scs::SystemState", ptr %98, i32 0, i32 12
  %100 = load ptr, ptr %99, align 8, !tbaa !25
  %101 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 5
  %102 = load ptr, ptr %101, align 8, !tbaa !9
  %103 = getelementptr inbounds %"struct.atg_scs::RigidBody", ptr %102, i32 0, i32 8
  %104 = load i32, ptr %103, align 8, !tbaa !14
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds double, ptr %100, i64 %105
  %107 = load double, ptr %106, align 8, !tbaa !16
  %108 = fsub double %107, %97
  store double %108, ptr %106, align 8, !tbaa !16
  br label %109

109:                                              ; preds = %96, %42
  %110 = load double, ptr %13, align 8, !tbaa !16
  %111 = load ptr, ptr %4, align 8, !tbaa !5
  %112 = getelementptr inbounds %"class.atg_scs::SystemState", ptr %111, i32 0, i32 12
  %113 = load ptr, ptr %112, align 8, !tbaa !25
  %114 = getelementptr inbounds %"class.atg_scs::ConstantSpeedMotor", ptr %14, i32 0, i32 6
  %115 = load ptr, ptr %114, align 8, !tbaa !20
  %116 = getelementptr inbounds %"struct.atg_scs::RigidBody", ptr %115, i32 0, i32 8
  %117 = load i32, ptr %116, align 8, !tbaa !14
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds double, ptr %113, i64 %118
  %120 = load double, ptr %119, align 8, !tbaa !16
  %121 = fadd double %120, %110
  store double %121, ptr %119, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 48}
!10 = !{!"_ZTSN7atg_scs18ConstantSpeedMotorE", !11, i64 0, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !6, i64 48, !6, i64 56}
!11 = !{!"_ZTSN7atg_scs14ForceGeneratorE", !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!15, !12, i64 64}
!15 = !{!"_ZTSN7atg_scs9RigidBodyE", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !12, i64 64}
!16 = !{!13, !13, i64 0}
!17 = !{!18, !6, i64 16}
!18 = !{!"_ZTSN7atg_scs11SystemStateE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !12, i64 136, !12, i64 140, !13, i64 144}
!19 = !{!18, !6, i64 8}
!20 = !{!10, !6, i64 56}
!21 = !{!10, !13, i64 40}
!22 = !{!10, !13, i64 16}
!23 = !{!10, !13, i64 24}
!24 = !{!10, !13, i64 32}
!25 = !{!18, !6, i64 96}


; 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(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN7atg_scs18ConstantSpeedMotor5applyEPNS_11SystemStateE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(64) %0, ptr nocapture noundef readonly %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 64
  %6 = load i32, ptr %5, align 8, !tbaa !13
  %7 = icmp eq i32 %6, -1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 16
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !15
  br i1 %7, label %._crit_edge, label %8

._crit_edge:                                      ; preds = %2
  %.phi.trans.insert20 = getelementptr inbounds i8, ptr %1, i64 8
  %.pre21 = load ptr, ptr %.phi.trans.insert20, align 8, !tbaa !17
  br label %16

8:                                                ; preds = %2
  %9 = sext i32 %6 to i64
  %10 = getelementptr inbounds double, ptr %.pre, i64 %9
  %11 = load double, ptr %10, align 8, !tbaa !18
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !17
  %14 = getelementptr inbounds double, ptr %13, i64 %9
  %15 = load double, ptr %14, align 8, !tbaa !18
  br label %16

16:                                               ; preds = %._crit_edge, %8
  %17 = phi ptr [ %13, %8 ], [ %.pre21, %._crit_edge ]
  %.017 = phi double [ %15, %8 ], [ 0.000000e+00, %._crit_edge ]
  %.0 = phi double [ %11, %8 ], [ 0.000000e+00, %._crit_edge ]
  %18 = getelementptr inbounds i8, ptr %0, i64 56
  %19 = load ptr, ptr %18, align 8, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %19, i64 64
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds double, ptr %.pre, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !18
  %25 = fsub double %24, %.0
  %26 = getelementptr inbounds double, ptr %17, i64 %22
  %27 = load double, ptr %26, align 8, !tbaa !18
  %28 = fsub double %27, %.017
  %29 = getelementptr inbounds i8, ptr %0, i64 40
  %30 = load double, ptr %29, align 8, !tbaa !20
  %31 = fsub double %30, %25
  %32 = getelementptr inbounds i8, ptr %0, i64 16
  %33 = load double, ptr %32, align 8, !tbaa !21
  %34 = fmul double %31, %33
  %35 = getelementptr inbounds i8, ptr %0, i64 24
  %36 = load double, ptr %35, align 8, !tbaa !22
  %37 = fmul double %28, %36
  %38 = fsub double %34, %37
  %39 = getelementptr inbounds i8, ptr %0, i64 32
  %40 = load double, ptr %39, align 8, !tbaa !23
  %41 = fneg double %40
  %42 = tail call double @llvm.maxnum.f64(double %41, double %38)
  %43 = tail call double @llvm.minnum.f64(double %40, double %42)
  %.phi.trans.insert23 = getelementptr inbounds i8, ptr %1, i64 96
  %.pre24 = load ptr, ptr %.phi.trans.insert23, align 8, !tbaa !24
  br i1 %7, label %._crit_edge22, label %44

44:                                               ; preds = %16
  %45 = sext i32 %6 to i64
  %46 = getelementptr inbounds double, ptr %.pre24, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !18
  %48 = fsub double %47, %43
  store double %48, ptr %46, align 8, !tbaa !18
  br label %._crit_edge22

._crit_edge22:                                    ; preds = %16, %44
  %49 = getelementptr inbounds double, ptr %.pre24, i64 %22
  %50 = load double, ptr %49, align 8, !tbaa !18
  %51 = fadd double %43, %50
  store double %51, ptr %49, align 8, !tbaa !18
  ret void
}

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

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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 #1 = { mustprogress 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, !12, i64 48}
!6 = !{!"_ZTSN7atg_scs18ConstantSpeedMotorE", !7, i64 0, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !12, i64 48, !12, i64 56}
!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 = !{!14, !8, i64 64}
!14 = !{!"_ZTSN7atg_scs9RigidBodyE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !8, i64 64}
!15 = !{!16, !12, i64 16}
!16 = !{!"_ZTSN7atg_scs11SystemStateE", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !8, i64 136, !8, i64 140, !11, i64 144}
!17 = !{!16, !12, i64 8}
!18 = !{!11, !11, i64 0}
!19 = !{!6, !12, i64 56}
!20 = !{!6, !11, i64 40}
!21 = !{!6, !11, i64 16}
!22 = !{!6, !11, i64 24}
!23 = !{!6, !11, i64 32}
!24 = !{!16, !12, i64 96}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass