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

; 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 @GetAvgOfVelocity(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %41, %2
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.phase_t, ptr %10, i32 0, i32 5
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp slt i32 %9, %12
  br i1 %13, label %14, label %44

14:                                               ; preds = %8
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.phase_t, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load i32, ptr %6, 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 %7, align 8, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %37, %14
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 3
  br i1 %24, label %25, label %40

25:                                               ; preds = %22
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %26, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !14
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %31, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !14
  %36 = fadd double %35, %30
  store double %36, ptr %34, align 8, !tbaa !14
  br label %37

37:                                               ; preds = %25
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !9
  br label %22, !llvm.loop !16

40:                                               ; preds = %22
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %6, align 4, !tbaa !9
  br label %8, !llvm.loop !18

44:                                               ; preds = %8
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %64, %44
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = icmp slt i32 %46, 3
  br i1 %47, label %48, label %67

48:                                               ; preds = %45
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds double, ptr %49, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !14
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.phase_t, ptr %54, i32 0, i32 5
  %56 = load i32, ptr %55, align 4, !tbaa !11
  %57 = sitofp i32 %56 to double
  %58 = call double @pow(double noundef %57, double noundef -1.000000e+00) #3
  %59 = fmul double %53, %58
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %60, i64 %62
  store double %59, ptr %63, align 8, !tbaa !14
  br label %64

64:                                               ; preds = %48
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %5, align 4, !tbaa !9
  br label %45, !llvm.loop !19

67:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #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, !10, i64 36}
!12 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}


; 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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @GetAvgOfVelocity(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 36
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  %.pre30 = load double, ptr %0, align 8, !tbaa !11
  br i1 %5, label %.lr.ph, label %..preheader_crit_edge

..preheader_crit_edge:                            ; preds = %2
  %.phi.trans.insert31 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load <2 x double>, ptr %.phi.trans.insert31, align 8, !tbaa !11
  br label %.preheader

.lr.ph:                                           ; preds = %2
  %7 = load ptr, ptr %1, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %4 to i64
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 8
  %.pre27 = load double, ptr %.phi.trans.insert, align 8, !tbaa !11
  %.phi.trans.insert28 = getelementptr inbounds i8, ptr %0, i64 16
  %.pre29 = load double, ptr %.phi.trans.insert28, align 8, !tbaa !11
  %xtraiter = and i64 %wide.trip.count, 1
  %8 = icmp eq i32 %4, 1
  br i1 %8, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %31

.preheader.loopexit.unr-lcssa.loopexit:           ; preds = %31
  %9 = insertelement <2 x double> poison, double %52, i64 0
  %10 = insertelement <2 x double> %9, double %54, i64 1
  br label %.preheader.loopexit.unr-lcssa

.preheader.loopexit.unr-lcssa:                    ; preds = %.preheader.loopexit.unr-lcssa.loopexit, %.lr.ph
  %.lcssa38.ph = phi double [ poison, %.lr.ph ], [ %48, %.preheader.loopexit.unr-lcssa.loopexit ]
  %.lcssa.ph = phi <2 x double> [ poison, %.lr.ph ], [ %10, %.preheader.loopexit.unr-lcssa.loopexit ]
  %.unr = phi double [ %.pre29, %.lr.ph ], [ %54, %.preheader.loopexit.unr-lcssa.loopexit ]
  %.unr39 = phi double [ %.pre27, %.lr.ph ], [ %52, %.preheader.loopexit.unr-lcssa.loopexit ]
  %.unr40 = phi double [ %.pre30, %.lr.ph ], [ %48, %.preheader.loopexit.unr-lcssa.loopexit ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %.preheader.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.preheader.loopexit.epilog-lcssa

.preheader.loopexit.epilog-lcssa:                 ; preds = %.preheader.loopexit.unr-lcssa
  %11 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.unr
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = load double, ptr %12, align 8, !tbaa !11
  %14 = fadd double %13, %.unr40
  store double %14, ptr %0, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %12, i64 8
  %16 = load double, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %12, i64 16
  %18 = fadd double %16, %.unr39
  store double %18, ptr %.phi.trans.insert, align 8, !tbaa !11
  %19 = load double, ptr %17, align 8, !tbaa !11
  %20 = fadd double %19, %.unr
  store double %20, ptr %.phi.trans.insert28, align 8, !tbaa !11
  %21 = insertelement <2 x double> poison, double %18, i64 0
  %22 = insertelement <2 x double> %21, double %20, i64 1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit.epilog-lcssa, %.preheader.loopexit.unr-lcssa, %..preheader_crit_edge
  %23 = phi double [ %.pre30, %..preheader_crit_edge ], [ %.lcssa38.ph, %.preheader.loopexit.unr-lcssa ], [ %14, %.preheader.loopexit.epilog-lcssa ]
  %24 = phi <2 x double> [ %6, %..preheader_crit_edge ], [ %.lcssa.ph, %.preheader.loopexit.unr-lcssa ], [ %22, %.preheader.loopexit.epilog-lcssa ]
  %25 = sitofp i32 %4 to double
  %reciprocal = fdiv double 1.000000e+00, %25
  %26 = fmul double %reciprocal, %23
  store double %26, ptr %0, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = insertelement <2 x double> poison, double %reciprocal, i64 0
  %29 = shufflevector <2 x double> %28, <2 x double> poison, <2 x i32> zeroinitializer
  %30 = fmul <2 x double> %29, %24
  store <2 x double> %30, ptr %27, align 8, !tbaa !11
  ret void

31:                                               ; preds = %31, %.lr.ph.new
  %32 = phi double [ %.pre29, %.lr.ph.new ], [ %54, %31 ]
  %33 = phi double [ %.pre27, %.lr.ph.new ], [ %52, %31 ]
  %34 = phi double [ %.pre30, %.lr.ph.new ], [ %48, %31 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %31 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %31 ]
  %35 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = fadd double %37, %34
  store double %38, ptr %0, align 8, !tbaa !11
  %39 = getelementptr inbounds i8, ptr %36, i64 8
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds i8, ptr %36, i64 16
  %42 = fadd double %40, %33
  store double %42, ptr %.phi.trans.insert, align 8, !tbaa !11
  %43 = load double, ptr %41, align 8, !tbaa !11
  %44 = fadd double %43, %32
  store double %44, ptr %.phi.trans.insert28, align 8, !tbaa !11
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %45 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.next
  %46 = load ptr, ptr %45, align 8, !tbaa !14
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = fadd double %47, %38
  store double %48, ptr %0, align 8, !tbaa !11
  %49 = getelementptr inbounds i8, ptr %46, i64 8
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds i8, ptr %46, i64 16
  %52 = fadd double %50, %42
  store double %52, ptr %.phi.trans.insert, align 8, !tbaa !11
  %53 = load double, ptr %51, align 8, !tbaa !11
  %54 = fadd double %53, %44
  store double %54, ptr %.phi.trans.insert28, align 8, !tbaa !11
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.loopexit.unr-lcssa.loopexit, label %31, !llvm.loop !15
}

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

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


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