; LLVM IR from csviragh/robotsim :: src/utilities (dynamics_utils)

; 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.phase_t = type { ptr, ptr, ptr, ptr, i32, i32 }

@GetAgentSpecificLocalCoM.HowManyAgents = external hidden global i32, align 4
@GetAgentSpecificLocalCoM.CoordinateDifference = external hidden global [3 x double], align 16
@GetAgentSpecificLocalCoM.IsItAnException = external hidden global i8, align 1

; 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
declare double @pow(double noundef, double noundef) #1

declare void @VectDifference(ptr noundef, ptr noundef, ptr noundef) #2

declare double @VectAbs(ptr noundef) #2

declare void @NullVect(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @GetAgentSpecificLocalCoM(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, double noundef %4) #3 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store double %4, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr @GetAgentSpecificLocalCoM.HowManyAgents, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @NullVect(ptr noundef @GetAgentSpecificLocalCoM.CoordinateDifference, i32 noundef 3)
  store i8 0, ptr @GetAgentSpecificLocalCoM.IsItAnException, align 1, !tbaa !13
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.phase_t, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds ptr, ptr %17, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %21, ptr %13, align 8, !tbaa !5
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %95, %5
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.phase_t, ptr %24, i32 0, i32 5
  %26 = load i32, ptr %25, align 4, !tbaa !17
  %27 = icmp slt i32 %23, %26
  br i1 %27, label %28, label %98

28:                                               ; preds = %22
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.phase_t, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds ptr, ptr %31, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  store ptr %35, ptr %14, align 8, !tbaa !5
  %36 = load ptr, ptr %13, align 8, !tbaa !5
  %37 = load ptr, ptr %14, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @GetAgentSpecificLocalCoM.CoordinateDifference, ptr noundef %36, ptr noundef %37)
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %60, %28
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.phase_t, ptr %40, i32 0, i32 5
  %42 = load i32, ptr %41, align 4, !tbaa !17
  %43 = icmp slt i32 %39, %42
  br i1 %43, label %44, label %49

44:                                               ; preds = %38
  %45 = load i8, ptr @GetAgentSpecificLocalCoM.IsItAnException, align 1, !tbaa !13, !range !18, !noundef !19
  %46 = trunc i8 %45 to i1
  %47 = zext i1 %46 to i32
  %48 = icmp eq i32 %47, 0
  br label %49

49:                                               ; preds = %44, %38
  %50 = phi i1 [ false, %38 ], [ %48, %44 ]
  br i1 %50, label %51, label %63

51:                                               ; preds = %49
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = load i32, ptr %12, align 4, !tbaa !9
  %58 = icmp eq i32 %56, %57
  br i1 %58, label %59, label %60

59:                                               ; preds = %51
  store i8 1, ptr @GetAgentSpecificLocalCoM.IsItAnException, align 1, !tbaa !13
  br label %60

60:                                               ; preds = %59, %51
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %11, align 4, !tbaa !9
  br label %38, !llvm.loop !20

63:                                               ; preds = %49
  %64 = call double @VectAbs(ptr noundef @GetAgentSpecificLocalCoM.CoordinateDifference)
  %65 = load double, ptr %10, align 8, !tbaa !11
  %66 = fcmp ole double %64, %65
  br i1 %66, label %67, label %94

67:                                               ; preds = %63
  %68 = load i8, ptr @GetAgentSpecificLocalCoM.IsItAnException, align 1, !tbaa !13, !range !18, !noundef !19
  %69 = trunc i8 %68 to i1
  %70 = zext i1 %69 to i32
  %71 = icmp eq i32 %70, 0
  br i1 %71, label %72, label %94

72:                                               ; preds = %67
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %73

73:                                               ; preds = %88, %72
  %74 = load i32, ptr %11, align 4, !tbaa !9
  %75 = icmp slt i32 %74, 3
  br i1 %75, label %76, label %91

76:                                               ; preds = %73
  %77 = load ptr, ptr %14, align 8, !tbaa !5
  %78 = load i32, ptr %11, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %77, i64 %79
  %81 = load double, ptr %80, align 8, !tbaa !11
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load i32, ptr %11, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds double, ptr %82, i64 %84
  %86 = load double, ptr %85, align 8, !tbaa !11
  %87 = fadd double %86, %81
  store double %87, ptr %85, align 8, !tbaa !11
  br label %88

88:                                               ; preds = %76
  %89 = load i32, ptr %11, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %11, align 4, !tbaa !9
  br label %73, !llvm.loop !22

91:                                               ; preds = %73
  %92 = load i32, ptr @GetAgentSpecificLocalCoM.HowManyAgents, align 4, !tbaa !9
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr @GetAgentSpecificLocalCoM.HowManyAgents, align 4, !tbaa !9
  br label %94

94:                                               ; preds = %91, %67, %63
  store i8 0, ptr @GetAgentSpecificLocalCoM.IsItAnException, align 1, !tbaa !13
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %12, align 4, !tbaa !9
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %12, align 4, !tbaa !9
  br label %22, !llvm.loop !23

98:                                               ; preds = %22
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %99

99:                                               ; preds = %116, %98
  %100 = load i32, ptr %11, align 4, !tbaa !9
  %101 = icmp slt i32 %100, 3
  br i1 %101, label %102, label %119

102:                                              ; preds = %99
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = load i32, ptr %11, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds double, ptr %103, i64 %105
  %107 = load double, ptr %106, align 8, !tbaa !11
  %108 = load i32, ptr @GetAgentSpecificLocalCoM.HowManyAgents, align 4, !tbaa !9
  %109 = sitofp i32 %108 to double
  %110 = call double @pow(double noundef %109, double noundef -1.000000e+00) #4
  %111 = fmul double %107, %110
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  %113 = load i32, ptr %11, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds double, ptr %112, i64 %114
  store double %111, ptr %115, align 8, !tbaa !11
  br label %116

116:                                              ; preds = %102
  %117 = load i32, ptr %11, align 4, !tbaa !9
  %118 = add nsw i32 %117, 1
  store i32 %118, ptr %11, align 4, !tbaa !9
  br label %99, !llvm.loop !24

119:                                              ; preds = %99
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 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 = { 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, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!17 = !{!16, !10, i64 36}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}
!23 = distinct !{!23, !21}
!24 = distinct !{!24, !21}


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

@GetAgentSpecificLocalCoM.HowManyAgents = external hidden local_unnamed_addr global i32, align 4
@GetAgentSpecificLocalCoM.CoordinateDifference = external hidden global [3 x double], align 16
@GetAgentSpecificLocalCoM.IsItAnException = external hidden local_unnamed_addr global i8, align 1

declare void @VectDifference(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare double @VectAbs(ptr noundef) local_unnamed_addr #0

declare void @NullVect(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @GetAgentSpecificLocalCoM(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef readonly %3, double noundef %4) local_unnamed_addr #1 {
  store i32 0, ptr @GetAgentSpecificLocalCoM.HowManyAgents, align 4, !tbaa !5
  tail call void @NullVect(ptr noundef nonnull @GetAgentSpecificLocalCoM.CoordinateDifference, i32 noundef 3) #2
  store i8 0, ptr @GetAgentSpecificLocalCoM.IsItAnException, align 1, !tbaa !9
  %6 = load ptr, ptr %1, align 8, !tbaa !11
  %7 = sext i32 %2 to i64
  %8 = getelementptr inbounds ptr, ptr %6, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %1, i64 36
  %11 = load i32, ptr %10, align 4, !tbaa !15
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph34.preheader, label %.preheader

.lr.ph34.preheader:                               ; preds = %5
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  br label %.lr.ph34

.preheader:                                       ; preds = %56, %5
  %15 = load i32, ptr @GetAgentSpecificLocalCoM.HowManyAgents, align 4, !tbaa !5
  %16 = sitofp i32 %15 to double
  %reciprocal = fdiv double 1.000000e+00, %16
  %17 = load <2 x double>, ptr %0, align 8, !tbaa !16
  %18 = insertelement <2 x double> poison, double %reciprocal, i64 0
  %19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
  %20 = fmul <2 x double> %17, %19
  store <2 x double> %20, ptr %0, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load double, ptr %21, align 8, !tbaa !16
  %23 = fmul double %22, %reciprocal
  store double %23, ptr %21, align 8, !tbaa !16
  ret void

.lr.ph34:                                         ; preds = %.lr.ph34.preheader, %56
  %indvars.iv39 = phi i64 [ 0, %.lr.ph34.preheader ], [ %indvars.iv.next40, %56 ]
  %24 = load ptr, ptr %1, align 8, !tbaa !11
  %25 = getelementptr inbounds ptr, ptr %24, i64 %indvars.iv39
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  tail call void @VectDifference(ptr noundef nonnull @GetAgentSpecificLocalCoM.CoordinateDifference, ptr noundef %9, ptr noundef %26) #2
  %27 = load i32, ptr %10, align 4, !tbaa !15
  %GetAgentSpecificLocalCoM.IsItAnException.promoted = load i8, ptr @GetAgentSpecificLocalCoM.IsItAnException, align 1
  %28 = icmp sgt i32 %27, 0
  %29 = icmp eq i8 %GetAgentSpecificLocalCoM.IsItAnException.promoted, 0
  %30 = select i1 %28, i1 %29, i1 false
  br i1 %30, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph34
  %31 = zext nneg i32 %27 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %36
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %36 ]
  %32 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = zext i32 %33 to i64
  %35 = icmp ne i64 %indvars.iv39, %34
  br i1 %35, label %36, label %.thread

.thread:                                          ; preds = %.lr.ph
  store i8 1, ptr @GetAgentSpecificLocalCoM.IsItAnException, align 1, !tbaa !9
  br label %._crit_edge

36:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = icmp ult i64 %indvars.iv.next, %31
  %38 = and i1 %37, %35
  br i1 %38, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %36, %.thread, %.lr.ph34
  %39 = tail call double @VectAbs(ptr noundef nonnull @GetAgentSpecificLocalCoM.CoordinateDifference) #2
  %40 = fcmp ole double %39, %4
  %41 = load i8, ptr @GetAgentSpecificLocalCoM.IsItAnException, align 1, !range !20
  %42 = icmp eq i8 %41, 0
  %or.cond = select i1 %40, i1 %42, i1 false
  br i1 %or.cond, label %.preheader29.preheader, label %56

.preheader29.preheader:                           ; preds = %._crit_edge
  %43 = load double, ptr %26, align 8, !tbaa !16
  %44 = load double, ptr %0, align 8, !tbaa !16
  %45 = fadd double %43, %44
  store double %45, ptr %0, align 8, !tbaa !16
  %46 = getelementptr inbounds i8, ptr %26, i64 8
  %47 = load double, ptr %46, align 8, !tbaa !16
  %48 = load double, ptr %13, align 8, !tbaa !16
  %49 = fadd double %47, %48
  store double %49, ptr %13, align 8, !tbaa !16
  %50 = getelementptr inbounds i8, ptr %26, i64 16
  %51 = load double, ptr %50, align 8, !tbaa !16
  %52 = load double, ptr %14, align 8, !tbaa !16
  %53 = fadd double %51, %52
  store double %53, ptr %14, align 8, !tbaa !16
  %54 = load i32, ptr @GetAgentSpecificLocalCoM.HowManyAgents, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr @GetAgentSpecificLocalCoM.HowManyAgents, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %.preheader29.preheader, %._crit_edge
  store i8 0, ptr @GetAgentSpecificLocalCoM.IsItAnException, align 1, !tbaa !9
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %57 = load i32, ptr %10, align 4, !tbaa !15
  %58 = sext i32 %57 to i64
  %59 = icmp slt i64 %indvars.iv.next40, %58
  br i1 %59, label %.lr.ph34, label %.preheader, !llvm.loop !21
}

attributes #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 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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !6, i64 32, !6, i64 36}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 36}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{i8 0, i8 2}
!21 = distinct !{!21, !19}


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