; LLVM IR from karlkurzer/path_planner :: src/dubins.ll (ZN11HybridAStar11dubins_initEPdS0_dPNS_10DubinsPathE)

; 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.HybridAStar::DubinsPath" = type { [3 x double], [3 x double], double, i32 }

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN11HybridAStar6mod2piEd(double noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11HybridAStar22dubins_init_normalisedEdddPNS_10DubinsPathE(double noundef, double noundef, double noundef, ptr noundef) #2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11HybridAStar11dubins_initEPdS0_dPNS_10DubinsPathE(ptr noundef %0, ptr noundef %1, double noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca i32, align 4
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = 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 ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %19, i64 0
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds double, ptr %22, i64 0
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = fsub double %21, %24
  store double %25, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %26, i64 1
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %29, i64 1
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = fsub double %28, %31
  store double %32, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %33 = load double, ptr %11, align 8, !tbaa !9
  %34 = load double, ptr %11, align 8, !tbaa !9
  %35 = load double, ptr %12, align 8, !tbaa !9
  %36 = load double, ptr %12, align 8, !tbaa !9
  %37 = fmul double %35, %36
  %38 = call double @llvm.fmuladd.f64(double %33, double %34, double %37)
  %39 = call double @sqrt(double noundef %38) #5
  store double %39, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %40 = load double, ptr %13, align 8, !tbaa !9
  %41 = load double, ptr %8, align 8, !tbaa !9
  %42 = fdiv double %40, %41
  store double %42, ptr %14, align 8, !tbaa !9
  %43 = load double, ptr %8, align 8, !tbaa !9
  %44 = fcmp ole double %43, 0.000000e+00
  br i1 %44, label %45, label %46

45:                                               ; preds = %4
  store i32 3, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %89

46:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %47 = load double, ptr %12, align 8, !tbaa !9
  %48 = load double, ptr %11, align 8, !tbaa !9
  %49 = call double @atan2(double noundef %47, double noundef %48) #5
  %50 = call noundef double @_ZN11HybridAStar6mod2piEd(double noundef %49)
  store double %50, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds double, ptr %51, i64 2
  %53 = load double, ptr %52, align 8, !tbaa !9
  %54 = load double, ptr %16, align 8, !tbaa !9
  %55 = fsub double %53, %54
  %56 = call noundef double @_ZN11HybridAStar6mod2piEd(double noundef %55)
  store double %56, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds double, ptr %57, i64 2
  %59 = load double, ptr %58, align 8, !tbaa !9
  %60 = load double, ptr %16, align 8, !tbaa !9
  %61 = fsub double %59, %60
  %62 = call noundef double @_ZN11HybridAStar6mod2piEd(double noundef %61)
  store double %62, ptr %18, align 8, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %63

63:                                               ; preds = %77, %46
  %64 = load i32, ptr %10, align 4, !tbaa !11
  %65 = icmp slt i32 %64, 3
  br i1 %65, label %66, label %80

66:                                               ; preds = %63
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load i32, ptr %10, align 4, !tbaa !11
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds double, ptr %67, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !9
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.HybridAStar::DubinsPath", ptr %72, i32 0, i32 0
  %74 = load i32, ptr %10, align 4, !tbaa !11
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [3 x double], ptr %73, i64 0, i64 %75
  store double %71, ptr %76, align 8, !tbaa !9
  br label %77

77:                                               ; preds = %66
  %78 = load i32, ptr %10, align 4, !tbaa !11
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %10, align 4, !tbaa !11
  br label %63, !llvm.loop !13

80:                                               ; preds = %63
  %81 = load double, ptr %8, align 8, !tbaa !9
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = getelementptr inbounds %"struct.HybridAStar::DubinsPath", ptr %82, i32 0, i32 2
  store double %81, ptr %83, align 8, !tbaa !15
  %84 = load double, ptr %17, align 8, !tbaa !9
  %85 = load double, ptr %18, align 8, !tbaa !9
  %86 = load double, ptr %14, align 8, !tbaa !9
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  %88 = call noundef i32 @_ZN11HybridAStar22dubins_init_normalisedEdddPNS_10DubinsPathE(double noundef %84, double noundef %85, double noundef %86, ptr noundef %87)
  store i32 %88, ptr %5, align 4
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %89

89:                                               ; preds = %80, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %90 = load i32, ptr %5, align 4
  ret i32 %90
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #4

; Function Attrs: nounwind
declare double @atan2(double noundef, double noundef) #4

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress 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 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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"}
!15 = !{!16, !10, i64 48}
!16 = !{!"_ZTSN11HybridAStar10DubinsPathE", !7, i64 0, !7, i64 24, !10, i64 48, !12, i64 56}


; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN11HybridAStar6mod2piEd(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11HybridAStar22dubins_init_normalisedEdddPNS_10DubinsPathE(double noundef, double noundef, double noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11HybridAStar11dubins_initEPdS0_dPNS_10DubinsPathE(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, double noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = fcmp ugt double %2, 0.000000e+00
  br i1 %5, label %6, label %35

6:                                                ; preds = %4
  %7 = load double, ptr %1, align 8, !tbaa !5
  %8 = load double, ptr %0, align 8, !tbaa !5
  %9 = fsub double %7, %8
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = fsub double %11, %13
  %15 = fmul double %14, %14
  %16 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %15)
  %sqrt = tail call double @llvm.sqrt.f64(double %16)
  %17 = fdiv double %sqrt, %2
  %18 = tail call double @atan2(double noundef %14, double noundef %9) #5
  %19 = tail call noundef double @_ZN11HybridAStar6mod2piEd(double noundef %18)
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fsub double %21, %19
  %23 = tail call noundef double @_ZN11HybridAStar6mod2piEd(double noundef %22)
  %24 = getelementptr inbounds i8, ptr %1, i64 16
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = fsub double %25, %19
  %27 = tail call noundef double @_ZN11HybridAStar6mod2piEd(double noundef %26)
  %28 = load double, ptr %0, align 8, !tbaa !5
  store double %28, ptr %3, align 8, !tbaa !5
  %29 = load double, ptr %12, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %3, i64 8
  store double %29, ptr %30, align 8, !tbaa !5
  %31 = load double, ptr %20, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %3, i64 16
  store double %31, ptr %32, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %3, i64 48
  store double %2, ptr %33, align 8, !tbaa !9
  %34 = tail call noundef i32 @_ZN11HybridAStar22dubins_init_normalisedEdddPNS_10DubinsPathE(double noundef %23, double noundef %27, double noundef %17, ptr noundef nonnull %3)
  br label %35

35:                                               ; preds = %4, %6
  %.0 = phi i32 [ %34, %6 ], [ 3, %4 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @atan2(double noundef, double noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress 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 = { 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 #3 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!10, !6, i64 48}
!10 = !{!"_ZTSN11HybridAStar10DubinsPathE", !7, i64 0, !7, i64 24, !6, i64 48, !11, i64 56}
!11 = !{!"int", !7, i64 0}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass