; LLVM IR from Kashery/fabrik-solver :: src (fabrik)

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; 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 @solve_fabrik_b3d(ptr noundef %0, ptr noundef byval(%struct.point3D) align 8 %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call ptr @find_last3d(ptr noundef %8)
  store ptr %9, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = call noalias ptr @malloc(i64 noundef 48) #5
  store ptr %10, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.point3D, ptr %1, i32 0, i32 0
  %12 = load double, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.point3D, ptr %13, i32 0, i32 0
  store double %12, ptr %14, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.point3D, ptr %1, i32 0, i32 1
  %16 = load double, ptr %15, align 8, !tbaa !13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.point3D, ptr %17, i32 0, i32 1
  store double %16, ptr %18, align 8, !tbaa !13
  %19 = getelementptr inbounds %struct.point3D, ptr %1, i32 0, i32 2
  %20 = load double, ptr %19, align 8, !tbaa !14
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.point3D, ptr %21, i32 0, i32 2
  store double %20, ptr %22, align 8, !tbaa !14
  br label %23

23:                                               ; preds = %77, %2
  br label %24

24:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.point3D, ptr %26, i32 0, i32 4
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = call double @find_dist3d(ptr noundef %25, ptr noundef %28)
  store double %29, ptr %6, align 8, !tbaa !16
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.point3D, ptr %30, i32 0, i32 0
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.point3D, ptr %33, i32 0, i32 0
  store double %32, ptr %34, align 8, !tbaa !9
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.point3D, ptr %35, i32 0, i32 1
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.point3D, ptr %38, i32 0, i32 1
  store double %37, ptr %39, align 8, !tbaa !13
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.point3D, ptr %40, i32 0, i32 2
  %42 = load double, ptr %41, align 8, !tbaa !14
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.point3D, ptr %43, i32 0, i32 2
  store double %42, ptr %44, align 8, !tbaa !14
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.point3D, ptr %46, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = load double, ptr %6, align 8, !tbaa !16
  %50 = call ptr @find_bet3d(ptr noundef %45, ptr noundef %48, double noundef %49)
  store ptr %50, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.point3D, ptr %51, i32 0, i32 4
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  store ptr %53, ptr %4, align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.point3D, ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = icmp eq ptr %56, null
  br i1 %57, label %58, label %74

58:                                               ; preds = %24
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.point3D, ptr %59, i32 0, i32 0
  %61 = load double, ptr %60, align 8, !tbaa !9
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.point3D, ptr %62, i32 0, i32 0
  store double %61, ptr %63, align 8, !tbaa !9
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.point3D, ptr %64, i32 0, i32 1
  %66 = load double, ptr %65, align 8, !tbaa !13
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.point3D, ptr %67, i32 0, i32 1
  store double %66, ptr %68, align 8, !tbaa !13
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.point3D, ptr %69, i32 0, i32 2
  %71 = load double, ptr %70, align 8, !tbaa !14
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.point3D, ptr %72, i32 0, i32 2
  store double %71, ptr %73, align 8, !tbaa !14
  store i32 3, ptr %7, align 4
  br label %75

74:                                               ; preds = %24
  store i32 0, ptr %7, align 4
  br label %75

75:                                               ; preds = %74, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %76 = load i32, ptr %7, align 4
  switch i32 %76, label %79 [
    i32 0, label %77
    i32 3, label %78
  ]

77:                                               ; preds = %75
  br label %23

78:                                               ; preds = %75
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  ret void

79:                                               ; preds = %75
  unreachable
}

declare ptr @find_last3d(ptr noundef) #3

declare double @find_dist3d(ptr noundef, ptr noundef) #3

declare ptr @find_bet3d(ptr noundef, ptr noundef, double noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 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 = { "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 }
attributes #5 = { nounwind allocsize(0) }

!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, !11, i64 0}
!10 = !{!"point3D", !11, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !12, i64 41, !12, i64 42}
!11 = !{!"double", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 16}
!15 = !{!10, !6, i64 32}
!16 = !{!11, !11, i64 0}


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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @solve_fabrik_b3d(ptr noundef %0, ptr nocapture noundef readonly byval(%struct.point3D) align 8 %1) local_unnamed_addr #1 {
  %3 = tail call ptr @find_last3d(ptr noundef %0) #3
  %4 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #4
  %5 = load <2 x double>, ptr %1, align 8, !tbaa !5
  store <2 x double> %5, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load double, ptr %6, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  store double %7, ptr %8, align 8, !tbaa !9
  %.phi.trans.insert = getelementptr inbounds i8, ptr %3, i64 32
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !13
  br label %9

9:                                                ; preds = %9, %2
  %10 = phi ptr [ %.pre, %2 ], [ %21, %9 ]
  %.024 = phi ptr [ %4, %2 ], [ %18, %9 ]
  %.023 = phi ptr [ %3, %2 ], [ %19, %9 ]
  %11 = getelementptr inbounds i8, ptr %.023, i64 32
  %12 = tail call double @find_dist3d(ptr noundef nonnull %.023, ptr noundef %10) #3
  %13 = load <2 x double>, ptr %.024, align 8, !tbaa !5
  store <2 x double> %13, ptr %.023, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %.024, i64 16
  %15 = load double, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %.023, i64 16
  store double %15, ptr %16, align 8, !tbaa !9
  %17 = load ptr, ptr %11, align 8, !tbaa !13
  %18 = tail call ptr @find_bet3d(ptr noundef nonnull %.023, ptr noundef %17, double noundef %12) #3
  %19 = load ptr, ptr %11, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %19, i64 32
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %9

23:                                               ; preds = %9
  %24 = load <2 x double>, ptr %18, align 8, !tbaa !5
  store <2 x double> %24, ptr %19, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %18, i64 16
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %19, i64 16
  store double %26, ptr %27, align 8, !tbaa !9
  ret void
}

declare ptr @find_last3d(ptr noundef) local_unnamed_addr #2

declare double @find_dist3d(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @find_bet3d(ptr noundef, ptr noundef, double noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 = { "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 = { nounwind }
attributes #4 = { nounwind allocsize(0) }

!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/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"point3D", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 32, !12, i64 40, !12, i64 41, !12, i64 42}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !11, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass