; LLVM IR from Discngine/fpocket :: src (clusterlib)

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

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @cuttree_distance(i32 noundef %0, ptr noundef %1, float noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store float %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = mul i64 8, %11
  %13 = call noalias ptr @malloc(i64 noundef %12) #4
  store ptr %13, ptr %8, align 8, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %36, %3
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %39

18:                                               ; preds = %14
  %19 = call noalias ptr @malloc(i64 noundef 8) #4
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds ptr, ptr %20, i64 %22
  store ptr %19, ptr %23, align 8, !tbaa !9
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds ptr, ptr %24, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds i32, ptr %28, i64 0
  store i32 -1, ptr %29, align 4, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds ptr, ptr %30, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds i32, ptr %34, i64 1
  store i32 0, ptr %35, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %18
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %7, align 4, !tbaa !5
  br label %14, !llvm.loop !13

39:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sub nsw i32 %40, 2
  store i32 %41, ptr %7, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %118, %39
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = icmp sge i32 %43, 0
  br i1 %44, label %45, label %121

45:                                               ; preds = %42
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds %struct.Node, ptr %46, i64 %48
  %50 = getelementptr inbounds %struct.Node, ptr %49, i32 0, i32 2
  %51 = load double, ptr %50, align 8, !tbaa !15
  %52 = load float, ptr %6, align 4, !tbaa !11
  %53 = fpext float %52 to double
  %54 = fcmp ogt double %51, %53
  br i1 %54, label %55, label %96

55:                                               ; preds = %45
  %56 = load ptr, ptr %5, align 8, !tbaa !9
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds %struct.Node, ptr %56, i64 %58
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !18
  %62 = icmp sge i32 %61, 0
  br i1 %62, label %63, label %73

63:                                               ; preds = %55
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds %struct.Node, ptr %65, i64 %67
  %69 = getelementptr inbounds %struct.Node, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !18
  %71 = load ptr, ptr %5, align 8, !tbaa !9
  %72 = load ptr, ptr %8, align 8, !tbaa !9
  call void @assign_cluster_to_children(i32 noundef %64, i32 noundef %70, ptr noundef %71, ptr noundef %72)
  br label %73

73:                                               ; preds = %63, %55
  %74 = load i32, ptr %9, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %9, align 4, !tbaa !5
  %76 = load ptr, ptr %5, align 8, !tbaa !9
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds %struct.Node, ptr %76, i64 %78
  %80 = getelementptr inbounds %struct.Node, ptr %79, i32 0, i32 1
  %81 = load i32, ptr %80, align 4, !tbaa !19
  %82 = icmp sge i32 %81, 0
  br i1 %82, label %83, label %93

83:                                               ; preds = %73
  %84 = load i32, ptr %9, align 4, !tbaa !5
  %85 = load ptr, ptr %5, align 8, !tbaa !9
  %86 = load i32, ptr %7, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds %struct.Node, ptr %85, i64 %87
  %89 = getelementptr inbounds %struct.Node, ptr %88, i32 0, i32 1
  %90 = load i32, ptr %89, align 4, !tbaa !19
  %91 = load ptr, ptr %5, align 8, !tbaa !9
  %92 = load ptr, ptr %8, align 8, !tbaa !9
  call void @assign_cluster_to_children(i32 noundef %84, i32 noundef %90, ptr noundef %91, ptr noundef %92)
  br label %93

93:                                               ; preds = %83, %73
  %94 = load i32, ptr %9, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %9, align 4, !tbaa !5
  br label %117

96:                                               ; preds = %45
  %97 = load i32, ptr %9, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %9, align 4, !tbaa !5
  %99 = load i32, ptr %9, align 4, !tbaa !5
  %100 = load ptr, ptr %5, align 8, !tbaa !9
  %101 = load i32, ptr %7, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds %struct.Node, ptr %100, i64 %102
  %104 = getelementptr inbounds %struct.Node, ptr %103, i32 0, i32 0
  %105 = load i32, ptr %104, align 8, !tbaa !18
  %106 = load ptr, ptr %5, align 8, !tbaa !9
  %107 = load ptr, ptr %8, align 8, !tbaa !9
  call void @assign_cluster_to_children(i32 noundef %99, i32 noundef %105, ptr noundef %106, ptr noundef %107)
  %108 = load i32, ptr %9, align 4, !tbaa !5
  %109 = load ptr, ptr %5, align 8, !tbaa !9
  %110 = load i32, ptr %7, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds %struct.Node, ptr %109, i64 %111
  %113 = getelementptr inbounds %struct.Node, ptr %112, i32 0, i32 1
  %114 = load i32, ptr %113, align 4, !tbaa !19
  %115 = load ptr, ptr %5, align 8, !tbaa !9
  %116 = load ptr, ptr %8, align 8, !tbaa !9
  call void @assign_cluster_to_children(i32 noundef %108, i32 noundef %114, ptr noundef %115, ptr noundef %116)
  br label %117

117:                                              ; preds = %96, %93
  br label %118

118:                                              ; preds = %117
  %119 = load i32, ptr %7, align 4, !tbaa !5
  %120 = add nsw i32 %119, -1
  store i32 %120, ptr %7, align 4, !tbaa !5
  br label %42, !llvm.loop !20

121:                                              ; preds = %42
  %122 = load ptr, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret ptr %122
}

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

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !17, i64 8}
!16 = !{!"", !6, i64 0, !6, i64 4, !17, i64 8}
!17 = !{!"double", !7, i64 0}
!18 = !{!16, !6, i64 0}
!19 = !{!16, !6, i64 4}
!20 = distinct !{!20, !14}


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

; 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 noundef ptr @cuttree_distance(i32 noundef %0, ptr noundef %1, float noundef %2) local_unnamed_addr #1 {
  %4 = sext i32 %0 to i64
  %5 = shl nsw i64 %4, 3
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #2
  %7 = icmp sgt i32 %0, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge53

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %8 = tail call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #2
  %9 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv
  store ptr %8, ptr %9, align 8, !tbaa !5
  store i32 -1, ptr %8, align 4, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 0, ptr %10, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph
  %.not = icmp eq i32 %0, 1
  br i1 %.not, label %._crit_edge53, label %.lr.ph52

.lr.ph52:                                         ; preds = %._crit_edge
  %11 = add nsw i32 %0, -2
  %12 = fpext float %2 to double
  %13 = zext nneg i32 %11 to i64
  br label %14

14:                                               ; preds = %.lr.ph52, %36
  %indvars.iv55 = phi i64 [ %13, %.lr.ph52 ], [ %indvars.iv.next56, %36 ]
  %.050 = phi i32 [ 1, %.lr.ph52 ], [ %.1, %36 ]
  %15 = getelementptr inbounds %struct.Node, ptr %1, i64 %indvars.iv55
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load double, ptr %16, align 8, !tbaa !13
  %18 = fcmp ogt double %17, %12
  br i1 %18, label %19, label %31

19:                                               ; preds = %14
  %20 = load i32, ptr %15, align 8, !tbaa !16
  %21 = icmp sgt i32 %20, -1
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  tail call void @assign_cluster_to_children(i32 noundef %.050, i32 noundef %20, ptr noundef nonnull %1, ptr noundef %6)
  br label %23

23:                                               ; preds = %22, %19
  %24 = getelementptr inbounds i8, ptr %15, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !17
  %26 = icmp sgt i32 %25, -1
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = add nsw i32 %.050, 1
  tail call void @assign_cluster_to_children(i32 noundef %28, i32 noundef %25, ptr noundef nonnull %1, ptr noundef %6)
  br label %29

29:                                               ; preds = %27, %23
  %30 = add nsw i32 %.050, 2
  br label %36

31:                                               ; preds = %14
  %32 = add nsw i32 %.050, 1
  %33 = load i32, ptr %15, align 8, !tbaa !16
  tail call void @assign_cluster_to_children(i32 noundef %32, i32 noundef %33, ptr noundef nonnull %1, ptr noundef %6)
  %34 = getelementptr inbounds i8, ptr %15, i64 4
  %35 = load i32, ptr %34, align 4, !tbaa !17
  tail call void @assign_cluster_to_children(i32 noundef %32, i32 noundef %35, ptr noundef nonnull %1, ptr noundef %6)
  br label %36

36:                                               ; preds = %29, %31
  %.1 = phi i32 [ %30, %29 ], [ %32, %31 ]
  %indvars.iv.next56 = add nsw i64 %indvars.iv55, -1
  %37 = icmp sgt i64 %indvars.iv55, 0
  br i1 %37, label %14, label %._crit_edge53, !llvm.loop !18

._crit_edge53:                                    ; preds = %36, %3, %._crit_edge
  ret ptr %6
}

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

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 = { 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !15, i64 8}
!14 = !{!"", !10, i64 0, !10, i64 4, !15, i64 8}
!15 = !{!"double", !7, i64 0}
!16 = !{!14, !10, i64 0}
!17 = !{!14, !10, i64 4}
!18 = distinct !{!18, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass