; LLVM IR from HRI-EU/Rcs :: src/RcsCore/ViaPointSequence.ll (ZNK3Rcs16ViaPointSequence17computeTrajectoryEP6_MatNdddd)

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

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

; Function Attrs: nounwind
declare i64 @lround(double noundef) #1

declare void @MatNd_set(ptr noundef, i32 noundef, i32 noundef, double noundef) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3Rcs16ViaPointSequence22computeTrajectoryPointERdS1_S1_d(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), double noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3Rcs16ViaPointSequence17computeTrajectoryEP6_MatNdddd(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, double noundef %2, double noundef %3, double noundef %4) #3 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store double %2, ptr %8, align 8, !tbaa !9
  store double %3, ptr %9, align 8, !tbaa !9
  store double %4, ptr %10, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %18 = load double, ptr %9, align 8, !tbaa !9
  %19 = load double, ptr %8, align 8, !tbaa !9
  %20 = fsub double %18, %19
  %21 = load double, ptr %10, align 8, !tbaa !9
  %22 = fdiv double %20, %21
  %23 = call i64 @lround(double noundef %22) #4
  %24 = trunc i64 %23 to i32
  store i32 %24, ptr %11, align 4, !tbaa !11
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !11
  %27 = add nsw i32 %26, 1
  call void @MatNd_reshape(ptr noundef %25, i32 noundef 4, i32 noundef %27)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %59, %5
  %29 = load i32, ptr %12, align 4, !tbaa !11
  %30 = load i32, ptr %11, align 4, !tbaa !11
  %31 = add nsw i32 %30, 1
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %62

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %35 = load double, ptr %9, align 8, !tbaa !9
  %36 = load double, ptr %8, align 8, !tbaa !9
  %37 = fsub double %35, %36
  %38 = load i32, ptr %12, align 4, !tbaa !11
  %39 = sitofp i32 %38 to double
  %40 = fmul double %37, %39
  %41 = load i32, ptr %11, align 4, !tbaa !11
  %42 = sitofp i32 %41 to double
  %43 = fdiv double %40, %42
  %44 = load double, ptr %8, align 8, !tbaa !9
  %45 = fadd double %43, %44
  store double %45, ptr %13, align 8, !tbaa !9
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i32, ptr %12, align 4, !tbaa !11
  %48 = load double, ptr %13, align 8, !tbaa !9
  call void @MatNd_set(ptr noundef %46, i32 noundef 0, i32 noundef %47, double noundef %48)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %49 = load double, ptr %13, align 8, !tbaa !9
  call void @_ZNK3Rcs16ViaPointSequence22computeTrajectoryPointERdS1_S1_d(ptr noundef nonnull align 8 dereferenceable(104) %17, ptr noundef nonnull align 8 dereferenceable(8) %14, ptr noundef nonnull align 8 dereferenceable(8) %15, ptr noundef nonnull align 8 dereferenceable(8) %16, double noundef %49)
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i32, ptr %12, align 4, !tbaa !11
  %52 = load double, ptr %14, align 8, !tbaa !9
  call void @MatNd_set(ptr noundef %50, i32 noundef 1, i32 noundef %51, double noundef %52)
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load i32, ptr %12, align 4, !tbaa !11
  %55 = load double, ptr %15, align 8, !tbaa !9
  call void @MatNd_set(ptr noundef %53, i32 noundef 2, i32 noundef %54, double noundef %55)
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load i32, ptr %12, align 4, !tbaa !11
  %58 = load double, ptr %16, align 8, !tbaa !9
  call void @MatNd_set(ptr noundef %56, i32 noundef 3, i32 noundef %57, double noundef %58)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %59

59:                                               ; preds = %34
  %60 = load i32, ptr %12, align 4, !tbaa !11
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %12, align 4, !tbaa !11
  br label %28, !llvm.loop !13

62:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  ret void
}

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

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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare i64 @lround(double noundef) local_unnamed_addr #1

declare void @MatNd_set(ptr noundef, i32 noundef, i32 noundef, double noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3Rcs16ViaPointSequence22computeTrajectoryPointERdS1_S1_d(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), double noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3Rcs16ViaPointSequence17computeTrajectoryEP6_MatNdddd(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, double noundef %2, double noundef %3, double noundef %4) local_unnamed_addr #3 align 2 {
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = fsub double %3, %2
  %10 = fdiv double %9, %4
  %11 = tail call i64 @lround(double noundef %10) #4
  %12 = trunc i64 %11 to i32
  %13 = add i32 %12, 1
  tail call void @MatNd_reshape(ptr noundef %1, i32 noundef 4, i32 noundef %13)
  %.not23 = icmp slt i32 %12, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %14 = uitofp nneg i32 %12 to double
  br label %15

._crit_edge:                                      ; preds = %15, %5
  ret void

15:                                               ; preds = %.lr.ph, %15
  %.024 = phi i32 [ 0, %.lr.ph ], [ %23, %15 ]
  %16 = uitofp nneg i32 %.024 to double
  %17 = fmul double %9, %16
  %18 = fdiv double %17, %14
  %19 = fadd double %18, %2
  call void @MatNd_set(ptr noundef %1, i32 noundef 0, i32 noundef %.024, double noundef %19)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  call void @_ZNK3Rcs16ViaPointSequence22computeTrajectoryPointERdS1_S1_d(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %8, double noundef %19)
  %20 = load double, ptr %6, align 8, !tbaa !5
  call void @MatNd_set(ptr noundef %1, i32 noundef 1, i32 noundef %.024, double noundef %20)
  %21 = load double, ptr %7, align 8, !tbaa !5
  call void @MatNd_set(ptr noundef %1, i32 noundef 2, i32 noundef %.024, double noundef %21)
  %22 = load double, ptr %8, align 8, !tbaa !5
  call void @MatNd_set(ptr noundef %1, i32 noundef 3, i32 noundef %.024, double noundef %22)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  %23 = add nuw i32 %.024, 1
  %exitcond.not = icmp eq i32 %.024, %12
  br i1 %exitcond.not, label %._crit_edge, label %15, !llvm.loop !9
}

declare void @MatNd_reshape(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { mustprogress 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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