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

10:                                               ; preds = %70, %3
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %73

14:                                               ; preds = %10
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %66, %14
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.phase_t, ptr %17, i64 0
  %19 = getelementptr inbounds %struct.phase_t, ptr %18, i32 0, i32 5
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = icmp slt i32 %16, %20
  br i1 %21, label %22, label %69

22:                                               ; preds = %15
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %62, %22
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.phase_t, ptr %25, i64 0
  %27 = getelementptr inbounds %struct.phase_t, ptr %26, i32 0, i32 4
  %28 = load i32, ptr %27, align 8, !tbaa !13
  %29 = icmp slt i32 %24, %28
  br i1 %29, label %30, label %65

30:                                               ; preds = %23
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sub nsw i32 %32, %33
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = add nsw i32 %34, %35
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds %struct.phase_t, ptr %31, i64 %37
  %39 = getelementptr inbounds %struct.phase_t, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds ptr, ptr %40, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !15
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds %struct.phase_t, ptr %49, i64 %51
  %53 = getelementptr inbounds %struct.phase_t, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds ptr, ptr %54, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds double, ptr %58, i64 %60
  store double %48, ptr %61, align 8, !tbaa !15
  br label %62

62:                                               ; preds = %30
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %9, align 4, !tbaa !9
  br label %23, !llvm.loop !17

65:                                               ; preds = %23
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %8, align 4, !tbaa !9
  br label %15, !llvm.loop !19

69:                                               ; preds = %15
  br label %70

70:                                               ; preds = %69
  %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 %10, !llvm.loop !20

73:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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


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

%struct.phase_t = type { ptr, ptr, ptr, ptr, i32, i32 }

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @ShiftInnerStateDataLine(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.preheader21.lr.ph, label %._crit_edge

.preheader21.lr.ph:                               ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 36
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  %8 = sub i32 %1, %2
  br i1 %7, label %.preheader21.lr.ph.split.us, label %._crit_edge

.preheader21.lr.ph.split.us:                      ; preds = %.preheader21.lr.ph
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.preheader21.us.us.preheader, label %._crit_edge

.preheader21.us.us.preheader:                     ; preds = %.preheader21.lr.ph.split.us
  %12 = sext i32 %8 to i64
  %wide.trip.count41 = zext nneg i32 %2 to i64
  %wide.trip.count36 = zext nneg i32 %6 to i64
  %wide.trip.count = zext nneg i32 %10 to i64
  %min.iters.check = icmp ult i32 %10, 4
  %n.vec = and i64 %wide.trip.count, 2147483644
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader21.us.us

.preheader21.us.us:                               ; preds = %.preheader21.us.us.preheader, %._crit_edge24.split.us.us.us
  %indvars.iv38 = phi i64 [ 0, %.preheader21.us.us.preheader ], [ %indvars.iv.next39, %._crit_edge24.split.us.us.us ]
  %13 = add nsw i64 %indvars.iv38, %12
  %14 = getelementptr inbounds %struct.phase_t, ptr %0, i64 %13, i32 2
  %15 = getelementptr inbounds %struct.phase_t, ptr %0, i64 %indvars.iv38, i32 2
  %16 = load ptr, ptr %14, align 8, !tbaa !12
  %17 = load ptr, ptr %15, align 8, !tbaa !12
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader21.us.us
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %._crit_edge.us.us.us ], [ 0, %.preheader21.us.us ]
  %18 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv33
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = getelementptr inbounds ptr, ptr %17, i64 %indvars.iv33
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = ptrtoint ptr %21 to i64
  %23 = ptrtoint ptr %19 to i64
  %24 = sub i64 %22, %23
  %diff.check = icmp ult i64 %24, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us.us.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us.us.us ]
  %25 = getelementptr inbounds double, ptr %19, i64 %index
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %wide.load = load <2 x double>, ptr %25, align 8, !tbaa !14
  %wide.load43 = load <2 x double>, ptr %26, align 8, !tbaa !14
  %27 = getelementptr inbounds double, ptr %21, i64 %index
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  store <2 x double> %wide.load, ptr %27, align 8, !tbaa !14
  store <2 x double> %wide.load43, ptr %28, align 8, !tbaa !14
  %index.next = add nuw i64 %index, 4
  %29 = icmp eq i64 %index.next, %n.vec
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us.us.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us.us.us
  %indvars.iv.ph = phi i64 [ 0, %.preheader.us.us.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %30 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.prol
  %31 = load double, ptr %30, align 8, !tbaa !14
  %32 = getelementptr inbounds double, ptr %21, i64 %indvars.iv.prol
  store double %31, ptr %32, align 8, !tbaa !14
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !20

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %33 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %34 = icmp ugt i64 %33, -4
  br i1 %34, label %._crit_edge.us.us.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %35 = getelementptr inbounds double, ptr %19, i64 %indvars.iv
  %36 = load double, ptr %35, align 8, !tbaa !14
  %37 = getelementptr inbounds double, ptr %21, i64 %indvars.iv
  store double %36, ptr %37, align 8, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %38 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next
  %39 = load double, ptr %38, align 8, !tbaa !14
  %40 = getelementptr inbounds double, ptr %21, i64 %indvars.iv.next
  store double %39, ptr %40, align 8, !tbaa !14
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %41 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next.1
  %42 = load double, ptr %41, align 8, !tbaa !14
  %43 = getelementptr inbounds double, ptr %21, i64 %indvars.iv.next.1
  store double %42, ptr %43, align 8, !tbaa !14
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %44 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next.2
  %45 = load double, ptr %44, align 8, !tbaa !14
  %46 = getelementptr inbounds double, ptr %21, i64 %indvars.iv.next.2
  store double %45, ptr %46, align 8, !tbaa !14
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge.us.us.us, label %scalar.ph, !llvm.loop !22

._crit_edge.us.us.us:                             ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count36
  br i1 %exitcond37.not, label %._crit_edge24.split.us.us.us, label %.preheader.us.us.us, !llvm.loop !23

._crit_edge24.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count41
  br i1 %exitcond42.not, label %._crit_edge, label %.preheader21.us.us, !llvm.loop !24

._crit_edge:                                      ; preds = %._crit_edge24.split.us.us.us, %.preheader21.lr.ph.split.us, %.preheader21.lr.ph, %3
  ret void
}

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, !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 = !{!6, !10, i64 32}
!12 = !{!6, !7, i64 16}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !17, !18}
!23 = distinct !{!23, !17}
!24 = distinct !{!24, !17}


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