; 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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @solve_fabrik_f3d(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %8 = call noalias ptr @malloc(i64 noundef 48) #5
  store ptr %8, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.point3D, ptr %9, i32 0, i32 0
  store double 0.000000e+00, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.point3D, ptr %11, i32 0, i32 1
  store double 0.000000e+00, ptr %12, align 8, !tbaa !13
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.point3D, ptr %13, i32 0, i32 2
  store double 0.000000e+00, ptr %14, align 8, !tbaa !14
  br label %15

15:                                               ; preds = %69, %1
  br label %16

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

50:                                               ; preds = %16
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.point3D, ptr %51, i32 0, i32 0
  %53 = load double, ptr %52, align 8, !tbaa !9
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.point3D, ptr %54, i32 0, i32 0
  store double %53, ptr %55, align 8, !tbaa !9
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.point3D, ptr %56, i32 0, i32 1
  %58 = load double, ptr %57, align 8, !tbaa !13
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.point3D, ptr %59, i32 0, i32 1
  store double %58, ptr %60, align 8, !tbaa !13
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.point3D, ptr %61, i32 0, i32 2
  %63 = load double, ptr %62, align 8, !tbaa !14
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.point3D, ptr %64, i32 0, i32 2
  store double %63, ptr %65, align 8, !tbaa !14
  store i32 3, ptr %6, align 4
  br label %67

66:                                               ; preds = %16
  store i32 0, ptr %6, align 4
  br label %67

67:                                               ; preds = %66, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %68 = load i32, ptr %6, align 4
  switch i32 %68, label %71 [
    i32 0, label %69
    i32 3, label %70
  ]

69:                                               ; preds = %67
  br label %15

70:                                               ; preds = %67
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void

71:                                               ; preds = %67
  unreachable
}

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 = { "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 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 }
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 24}
!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"

; 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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @solve_fabrik_f3d(ptr noundef %0) local_unnamed_addr #2 {
  %2 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #4
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %2, i8 0, i64 24, i1 false)
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !5
  br label %3

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

17:                                               ; preds = %3
  %18 = load <2 x double>, ptr %12, align 8, !tbaa !12
  store <2 x double> %18, ptr %13, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %12, i64 16
  %20 = load double, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %13, i64 16
  store double %20, ptr %21, align 8, !tbaa !13
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind allocsize(0) }
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, !10, i64 24}
!6 = !{!"point3D", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !11, i64 41, !11, i64 42}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 16}


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