; LLVM IR from ShahjalalShohag/code-library :: Geometry/Geometry 3D.ll (Z28tangent_from_point_to_sphere2p36sphere)

; 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.p3 = type { double, double, double }
%struct.sphere = type { %struct.p3, double }

; Function Attrs: nounwind
declare double @acos(double noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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
declare dso_local noundef double @_Z3abs2p3(ptr noundef) #4

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK2p3miERKS_(ptr dead_on_unwind noalias writable sret(%struct.p3) align 8, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z28tangent_from_point_to_sphere2p36sphere(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca %struct.p3, align 8
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %11 = getelementptr inbounds %struct.sphere, ptr %1, i32 0, i32 0
  call void @_ZNK2p3miERKS_(ptr dead_on_unwind writable sret(%struct.p3) align 8 %7, ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %11)
  %12 = call noundef double @_Z3abs2p3(ptr noundef %7)
  store double %12, ptr %6, align 8, !tbaa !9
  %13 = load double, ptr %6, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.sphere, ptr %1, i32 0, i32 1
  %15 = load double, ptr %14, align 8, !tbaa !11
  %16 = fsub double %13, %15
  %17 = call noundef i32 @_Z4signd(double noundef %16)
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  store double -1.000000e+00, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %45

20:                                               ; preds = %2
  %21 = load double, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.sphere, ptr %1, i32 0, i32 1
  %23 = load double, ptr %22, align 8, !tbaa !11
  %24 = fsub double %21, %23
  %25 = call noundef i32 @_Z4signd(double noundef %24)
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %20
  store double -2.000000e+00, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %45

28:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %29 = load double, ptr %6, align 8, !tbaa !9
  %30 = load double, ptr %6, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.sphere, ptr %1, i32 0, i32 1
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds %struct.sphere, ptr %1, i32 0, i32 1
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = fmul double %32, %34
  %36 = fneg double %35
  %37 = call double @llvm.fmuladd.f64(double %29, double %30, double %36)
  %38 = call double @sqrt(double noundef %37) #5
  store double %38, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %39 = getelementptr inbounds %struct.sphere, ptr %1, i32 0, i32 1
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = load double, ptr %6, align 8, !tbaa !9
  %42 = fdiv double %40, %41
  %43 = call double @acos(double noundef %42) #5
  store double %43, ptr %10, align 8, !tbaa !9
  %44 = load double, ptr %10, align 8, !tbaa !9
  store double %44, ptr %3, align 8
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %45

45:                                               ; preds = %28, %27, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %46 = load double, ptr %3, align 8
  ret double %46
}

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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, !10, i64 24}
!12 = !{!"_ZTS6sphere", !13, i64 0, !10, i64 24}
!13 = !{!"_ZTS2p3", !10, i64 0, !10, i64 8, !10, i64 16}


; 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.p3 = type { double, double, double }

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @acos(double noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z3abs2p3(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK2p3miERKS_(ptr dead_on_unwind noalias writable sret(%struct.p3) align 8, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z28tangent_from_point_to_sphere2p36sphere(ptr noundef nonnull %0, ptr noundef nonnull %1) local_unnamed_addr #3 {
  %3 = alloca %struct.p3, align 8
  call void @_ZNK2p3miERKS_(ptr dead_on_unwind nonnull writable sret(%struct.p3) align 8 %3, ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1)
  %4 = call noundef double @_Z3abs2p3(ptr noundef nonnull %3)
  %5 = getelementptr inbounds i8, ptr %1, i64 24
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = fsub double %4, %6
  %8 = call noundef i32 @_Z4signd(double noundef %7)
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %25, label %10

10:                                               ; preds = %2
  %11 = load double, ptr %5, align 8, !tbaa !5
  %12 = fsub double %4, %11
  %13 = call noundef i32 @_Z4signd(double noundef %12)
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %25, label %15

15:                                               ; preds = %10
  %16 = load double, ptr %5, align 8, !tbaa !5
  %17 = fneg double %16
  %18 = fmul double %16, %17
  %19 = call double @llvm.fmuladd.f64(double %4, double %4, double %18)
  %20 = fcmp olt double %19, 0.000000e+00
  br i1 %20, label %cdce.call, label %cdce.end, !prof !11

cdce.call:                                        ; preds = %15
  %21 = call double @sqrt(double noundef %19) #4
  %.pre = load double, ptr %5, align 8, !tbaa !5
  br label %cdce.end

cdce.end:                                         ; preds = %15, %cdce.call
  %22 = phi double [ %16, %15 ], [ %.pre, %cdce.call ]
  %23 = fdiv double %22, %4
  %24 = call double @acos(double noundef %23) #4
  br label %25

25:                                               ; preds = %10, %2, %cdce.end
  %.0 = phi double [ %24, %cdce.end ], [ -1.000000e+00, %2 ], [ -2.000000e+00, %10 ]
  ret double %.0
}

attributes #0 = { 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 #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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !8, i64 24}
!6 = !{!"_ZTS6sphere", !7, i64 0, !8, i64 24}
!7 = !{!"_ZTS2p3", !8, i64 0, !8, i64 8, !8, i64 16}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"branch_weights", i32 1, i32 1048575}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LibCallsShrinkWrapPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass