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

@GetAgentSpecificCoM.HowManyAgents = external hidden global i32, align 4
@GetAgentSpecificCoM.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

; Function Attrs: nounwind uwtable
define dso_local void @GetAgentSpecificCoM(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr @GetAgentSpecificCoM.HowManyAgents, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i8 0, ptr @GetAgentSpecificCoM.IsItAnException, align 1, !tbaa !11
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %77, %3
  %11 = load i32, ptr %8, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.phase_t, ptr %12, i32 0, i32 5
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = icmp slt i32 %11, %14
  br i1 %15, label %16, label %80

16:                                               ; preds = %10
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.phase_t, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds ptr, ptr %19, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %46, %16
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.phase_t, ptr %26, i32 0, i32 5
  %28 = load i32, ptr %27, align 4, !tbaa !13
  %29 = icmp slt i32 %25, %28
  br i1 %29, label %30, label %35

30:                                               ; preds = %24
  %31 = load i8, ptr @GetAgentSpecificCoM.IsItAnException, align 1, !tbaa !11, !range !16, !noundef !17
  %32 = trunc i8 %31 to i1
  %33 = zext i1 %32 to i32
  %34 = icmp eq i32 %33, 0
  br label %35

35:                                               ; preds = %30, %24
  %36 = phi i1 [ false, %24 ], [ %34, %30 ]
  br i1 %36, label %37, label %49

37:                                               ; preds = %35
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr %38, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = icmp eq i32 %42, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %37
  store i8 1, ptr @GetAgentSpecificCoM.IsItAnException, align 1, !tbaa !11
  br label %46

46:                                               ; preds = %45, %37
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %7, align 4, !tbaa !9
  br label %24, !llvm.loop !18

49:                                               ; preds = %35
  %50 = load i8, ptr @GetAgentSpecificCoM.IsItAnException, align 1, !tbaa !11, !range !16, !noundef !17
  %51 = trunc i8 %50 to i1
  %52 = zext i1 %51 to i32
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %76

54:                                               ; preds = %49
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %70, %54
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = icmp slt i32 %56, 3
  br i1 %57, label %58, label %73

58:                                               ; preds = %55
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds double, ptr %59, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !20
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %64, i64 %66
  %68 = load double, ptr %67, align 8, !tbaa !20
  %69 = fadd double %68, %63
  store double %69, ptr %67, align 8, !tbaa !20
  br label %70

70:                                               ; preds = %58
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %7, align 4, !tbaa !9
  br label %55, !llvm.loop !22

73:                                               ; preds = %55
  %74 = load i32, ptr @GetAgentSpecificCoM.HowManyAgents, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr @GetAgentSpecificCoM.HowManyAgents, align 4, !tbaa !9
  br label %76

76:                                               ; preds = %73, %49
  store i8 0, ptr @GetAgentSpecificCoM.IsItAnException, align 1, !tbaa !11
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %8, align 4, !tbaa !9
  br label %10, !llvm.loop !23

80:                                               ; preds = %10
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %98, %80
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = icmp slt i32 %82, 3
  br i1 %83, label %84, label %101

84:                                               ; preds = %81
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = load i32, ptr %7, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds double, ptr %85, i64 %87
  %89 = load double, ptr %88, align 8, !tbaa !20
  %90 = load i32, ptr @GetAgentSpecificCoM.HowManyAgents, align 4, !tbaa !9
  %91 = sitofp i32 %90 to double
  %92 = call double @pow(double noundef %91, double noundef -1.000000e+00) #3
  %93 = fmul double %89, %92
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = load i32, ptr %7, align 4, !tbaa !9
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds double, ptr %94, i64 %96
  store double %93, ptr %97, align 8, !tbaa !20
  br label %98

98:                                               ; preds = %84
  %99 = load i32, ptr %7, align 4, !tbaa !9
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %7, align 4, !tbaa !9
  br label %81, !llvm.loop !24

101:                                              ; preds = %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !10, i64 36}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!15 = !{!14, !6, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !7, i64 0}
!22 = distinct !{!22, !19}
!23 = distinct !{!23, !19}
!24 = distinct !{!24, !19}


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

@GetAgentSpecificCoM.HowManyAgents = external hidden local_unnamed_addr global i32, align 4
@GetAgentSpecificCoM.IsItAnException = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @GetAgentSpecificCoM(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  store i32 0, ptr @GetAgentSpecificCoM.HowManyAgents, align 4, !tbaa !5
  store i8 0, ptr @GetAgentSpecificCoM.IsItAnException, align 1, !tbaa !9
  %4 = getelementptr inbounds i8, ptr %1, i64 36
  %5 = load i32, ptr %4, align 4, !tbaa !11
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph28.split.preheader, label %.preheader

.lr.ph28.split.preheader:                         ; preds = %3
  %7 = load ptr, ptr %1, align 8, !tbaa !14
  %8 = zext nneg i32 %5 to i64
  %wide.trip.count = zext nneg i32 %5 to i64
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  br label %.lr.ph.preheader

.preheader.loopexit:                              ; preds = %._crit_edge
  store i8 0, ptr @GetAgentSpecificCoM.IsItAnException, align 1, !tbaa !9
  %11 = sitofp i32 %42 to double
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %3
  %12 = phi double [ %11, %.preheader.loopexit ], [ 0.000000e+00, %3 ]
  %reciprocal = fdiv double 1.000000e+00, %12
  %13 = load <2 x double>, ptr %0, align 8, !tbaa !15
  %14 = insertelement <2 x double> poison, double %reciprocal, i64 0
  %15 = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> zeroinitializer
  %16 = fmul <2 x double> %13, %15
  store <2 x double> %16, ptr %0, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load double, ptr %17, align 8, !tbaa !15
  %19 = fmul double %18, %reciprocal
  store double %19, ptr %17, align 8, !tbaa !15
  ret void

.lr.ph.preheader:                                 ; preds = %._crit_edge, %.lr.ph28.split.preheader
  %indvars.iv35 = phi i64 [ 0, %.lr.ph28.split.preheader ], [ %indvars.iv.next36, %._crit_edge ]
  %20 = phi i32 [ 0, %.lr.ph28.split.preheader ], [ %42, %._crit_edge ]
  %21 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv35
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %27
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %27 ]
  %23 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = zext i32 %24 to i64
  %26 = icmp ne i64 %indvars.iv35, %25
  br i1 %26, label %27, label %._crit_edge

27:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %28 = icmp ult i64 %indvars.iv.next, %8
  %29 = and i1 %28, %26
  br i1 %29, label %.lr.ph, label %.preheader23.preheader, !llvm.loop !18

.preheader23.preheader:                           ; preds = %27
  %30 = load double, ptr %22, align 8, !tbaa !15
  %31 = load double, ptr %0, align 8, !tbaa !15
  %32 = fadd double %30, %31
  store double %32, ptr %0, align 8, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %22, i64 8
  %34 = load double, ptr %33, align 8, !tbaa !15
  %35 = load double, ptr %9, align 8, !tbaa !15
  %36 = fadd double %34, %35
  store double %36, ptr %9, align 8, !tbaa !15
  %37 = getelementptr inbounds i8, ptr %22, i64 16
  %38 = load double, ptr %37, align 8, !tbaa !15
  %39 = load double, ptr %10, align 8, !tbaa !15
  %40 = fadd double %38, %39
  store double %40, ptr %10, align 8, !tbaa !15
  %41 = add nsw i32 %20, 1
  store i32 %41, ptr @GetAgentSpecificCoM.HowManyAgents, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.preheader23.preheader
  %42 = phi i32 [ %41, %.preheader23.preheader ], [ %20, %.lr.ph ]
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count
  br i1 %exitcond.not, label %.preheader.loopexit, label %.lr.ph.preheader, !llvm.loop !20
}

attributes #0 = { nofree norecurse nosync nounwind 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" }

!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, !6, i64 36}
!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 = !{!12, !13, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass