; LLVM IR from junhyeokahn/PyPnC :: pnc/planner/dubins/dubins.ll (Z22dubins_extract_subpathP10DubinsPathdS0_)

; 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.DubinsPath = type { [3 x double], [3 x double], double, 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: mustprogress nounwind uwtable
declare dso_local noundef double @_Z18dubins_path_lengthP10DubinsPath(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z22dubins_extract_subpathP10DubinsPathdS0_(ptr noundef %0, double noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load double, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.DubinsPath, ptr %11, i32 0, i32 2
  %13 = load double, ptr %12, align 8, !tbaa !11
  %14 = fdiv double %10, %13
  store double %14, ptr %8, align 8, !tbaa !9
  %15 = load double, ptr %6, align 8, !tbaa !9
  %16 = fcmp olt double %15, 0.000000e+00
  br i1 %16, label %22, label %17

17:                                               ; preds = %3
  %18 = load double, ptr %6, align 8, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call noundef double @_Z18dubins_path_lengthP10DubinsPath(ptr noundef %19)
  %21 = fcmp ogt double %18, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %17, %3
  store i32 2, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %97

23:                                               ; preds = %17
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.DubinsPath, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [3 x double], ptr %25, i64 0, i64 0
  %27 = load double, ptr %26, align 8, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.DubinsPath, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds [3 x double], ptr %29, i64 0, i64 0
  store double %27, ptr %30, align 8, !tbaa !9
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.DubinsPath, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [3 x double], ptr %32, i64 0, i64 1
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.DubinsPath, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [3 x double], ptr %36, i64 0, i64 1
  store double %34, ptr %37, align 8, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.DubinsPath, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds [3 x double], ptr %39, i64 0, i64 2
  %41 = load double, ptr %40, align 8, !tbaa !9
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.DubinsPath, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds [3 x double], ptr %43, i64 0, i64 2
  store double %41, ptr %44, align 8, !tbaa !9
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.DubinsPath, ptr %45, i32 0, i32 2
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.DubinsPath, ptr %48, i32 0, i32 2
  store double %47, ptr %49, align 8, !tbaa !11
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.DubinsPath, ptr %50, i32 0, i32 3
  %52 = load i32, ptr %51, align 8, !tbaa !14
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.DubinsPath, ptr %53, i32 0, i32 3
  store i32 %52, ptr %54, align 8, !tbaa !14
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.DubinsPath, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds [3 x double], ptr %56, i64 0, i64 0
  %58 = load double, ptr %57, align 8, !tbaa !9
  %59 = load double, ptr %8, align 8, !tbaa !9
  %60 = call double @llvm.minnum.f64(double %58, double %59)
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.DubinsPath, ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds [3 x double], ptr %62, i64 0, i64 0
  store double %60, ptr %63, align 8, !tbaa !9
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.DubinsPath, ptr %64, i32 0, i32 1
  %66 = getelementptr inbounds [3 x double], ptr %65, i64 0, i64 1
  %67 = load double, ptr %66, align 8, !tbaa !9
  %68 = load double, ptr %8, align 8, !tbaa !9
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.DubinsPath, ptr %69, i32 0, i32 1
  %71 = getelementptr inbounds [3 x double], ptr %70, i64 0, i64 0
  %72 = load double, ptr %71, align 8, !tbaa !9
  %73 = fsub double %68, %72
  %74 = call double @llvm.minnum.f64(double %67, double %73)
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.DubinsPath, ptr %75, i32 0, i32 1
  %77 = getelementptr inbounds [3 x double], ptr %76, i64 0, i64 1
  store double %74, ptr %77, align 8, !tbaa !9
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.DubinsPath, ptr %78, i32 0, i32 1
  %80 = getelementptr inbounds [3 x double], ptr %79, i64 0, i64 2
  %81 = load double, ptr %80, align 8, !tbaa !9
  %82 = load double, ptr %8, align 8, !tbaa !9
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.DubinsPath, ptr %83, i32 0, i32 1
  %85 = getelementptr inbounds [3 x double], ptr %84, i64 0, i64 0
  %86 = load double, ptr %85, align 8, !tbaa !9
  %87 = fsub double %82, %86
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.DubinsPath, ptr %88, i32 0, i32 1
  %90 = getelementptr inbounds [3 x double], ptr %89, i64 0, i64 1
  %91 = load double, ptr %90, align 8, !tbaa !9
  %92 = fsub double %87, %91
  %93 = call double @llvm.minnum.f64(double %81, double %92)
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.DubinsPath, ptr %94, i32 0, i32 1
  %96 = getelementptr inbounds [3 x double], ptr %95, i64 0, i64 2
  store double %93, ptr %96, align 8, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %97

97:                                               ; preds = %23, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %98 = load i32, ptr %4, align 4
  ret i32 %98
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 48}
!12 = !{!"_ZTS10DubinsPath", !7, i64 0, !7, i64 24, !10, i64 48, !13, i64 56}
!13 = !{!"_ZTS14DubinsPathType", !7, i64 0}
!14 = !{!12, !13, 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 nounwind uwtable
declare dso_local noundef double @_Z18dubins_path_lengthP10DubinsPath(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 3) i32 @_Z22dubins_extract_subpathP10DubinsPathdS0_(ptr noundef %0, double noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = fdiv double %1, %5
  %7 = fcmp olt double %1, 0.000000e+00
  br i1 %7, label %38, label %8

8:                                                ; preds = %3
  %9 = tail call noundef double @_Z18dubins_path_lengthP10DubinsPath(ptr noundef nonnull %0)
  %10 = fcmp olt double %9, %1
  br i1 %10, label %38, label %11

11:                                               ; preds = %8
  %12 = load double, ptr %0, align 8, !tbaa !11
  store double %12, ptr %2, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load double, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %2, i64 8
  store double %14, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load double, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %2, i64 16
  store double %17, ptr %18, align 8, !tbaa !11
  %19 = load double, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %2, i64 48
  store double %19, ptr %20, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 56
  %22 = load i32, ptr %21, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %2, i64 56
  store i32 %22, ptr %23, align 8, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  %25 = load double, ptr %24, align 8, !tbaa !11
  %26 = tail call double @llvm.minnum.f64(double %25, double %6)
  %27 = getelementptr inbounds i8, ptr %2, i64 24
  store double %26, ptr %27, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = fsub double %6, %26
  %31 = tail call double @llvm.minnum.f64(double %29, double %30)
  %32 = getelementptr inbounds i8, ptr %2, i64 32
  store double %31, ptr %32, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %0, i64 40
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = fsub double %30, %31
  %36 = tail call double @llvm.minnum.f64(double %34, double %35)
  %37 = getelementptr inbounds i8, ptr %2, i64 40
  store double %36, ptr %37, align 8, !tbaa !11
  br label %38

38:                                               ; preds = %3, %8, %11
  %.0 = phi i32 [ 0, %11 ], [ 2, %8 ], [ 2, %3 ]
  ret i32 %.0
}

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !9, i64 48}
!6 = !{!"_ZTS10DubinsPath", !7, i64 0, !7, i64 24, !9, i64 48, !10, i64 56}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"double", !7, i64 0}
!10 = !{!"_ZTS14DubinsPathType", !7, i64 0}
!11 = !{!9, !9, i64 0}
!12 = !{!6, !10, i64 56}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass