; 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 }

@.str = external hidden unnamed_addr constant [27 x i8], align 1

; 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
declare dso_local void @solve_fabrik_b3d(ptr noundef, ptr noundef byval(%struct.point3D) align 8) #2

declare ptr @find_last3d(ptr noundef) #3

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

; Function Attrs: nounwind uwtable
declare dso_local void @solve_fabrik_f3d(ptr noundef) #2

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

21:                                               ; preds = %28, %3
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call ptr @find_last3d(ptr noundef %22)
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call double @find_dist3d(ptr noundef %23, ptr noundef %24)
  %26 = load double, ptr %5, align 8, !tbaa !9
  %27 = fcmp ogt double %25, %26
  br i1 %27, label %28, label %34

28:                                               ; preds = %21
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  call void @solve_fabrik_b3d(ptr noundef %29, ptr noundef byval(%struct.point3D) align 8 %1)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  call void @solve_fabrik_f3d(ptr noundef %30)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  call void @print_all3d(ptr noundef %31)
  %32 = load i64, ptr %7, align 8, !tbaa !16
  %33 = add i64 %32, 1
  store i64 %33, ptr %7, align 8, !tbaa !16
  br label %21, !llvm.loop !18

34:                                               ; preds = %21
  %35 = load i64, ptr %7, align 8, !tbaa !16
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %35)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  ret void
}

declare void @print_all3d(ptr noundef) #3

declare i32 @printf(ptr 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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"point3D", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !13, i64 41, !13, i64 42}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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 }

@.str = external hidden unnamed_addr constant [27 x i8], align 1

; 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
declare dso_local void @solve_fabrik_b3d(ptr noundef, ptr noundef byval(%struct.point3D) align 8) local_unnamed_addr #1

declare ptr @find_last3d(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @solve_fabrik_f3d(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @solve_fabrik3d(ptr noundef %0, ptr noundef byval(%struct.point3D) align 8 %1, double noundef %2) local_unnamed_addr #1 {
  %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
  %9 = tail call ptr @find_last3d(ptr noundef %0) #5
  %10 = tail call double @find_dist3d(ptr noundef %9, ptr noundef nonnull %4) #5
  %11 = fcmp ogt double %10, %2
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.010 = phi i64 [ %12, %.lr.ph ], [ 0, %3 ]
  tail call void @solve_fabrik_b3d(ptr noundef %0, ptr noundef nonnull byval(%struct.point3D) align 8 %1)
  tail call void @solve_fabrik_f3d(ptr noundef %0)
  tail call void @print_all3d(ptr noundef %0) #5
  %12 = add i64 %.010, 1
  %13 = tail call ptr @find_last3d(ptr noundef %0) #5
  %14 = tail call double @find_dist3d(ptr noundef %13, ptr noundef nonnull %4) #5
  %15 = fcmp ogt double %14, %2
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.0.lcssa = phi i64 [ 0, %3 ], [ %12, %.lr.ph ]
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.0.lcssa)
  ret void
}

declare void @print_all3d(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 = { nofree 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 #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, !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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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