; LLVM IR from viplix3/BoTSORT-cpp :: botsort/src/lapjv.ll (Z9_ca_densejPPdjPiS1_S1_S_)

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

; 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
declare void @free(ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z15find_path_densejPPdiPiS_S1_(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z9_ca_densejPPdjPiS1_S1_S_(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #3 {
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  store i32 %0, ptr %9, align 4, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !9
  store i32 %2, ptr %11, align 4, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !9
  store ptr %5, ptr %14, align 8, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = mul i64 4, %24
  %26 = call noalias ptr @malloc(i64 noundef %25) #5
  store ptr %26, ptr %16, align 8, !tbaa !9
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %7
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %92

29:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %30 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %30, ptr %18, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %83, %29
  %32 = load ptr, ptr %18, align 8, !tbaa !9
  %33 = load ptr, ptr %12, align 8, !tbaa !9
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %33, i64 %35
  %37 = icmp ult ptr %32, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %31
  store i32 2, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %86

39:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  store i32 -1, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  store i32 0, ptr %21, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  %42 = load ptr, ptr %18, align 8, !tbaa !9
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load ptr, ptr %14, align 8, !tbaa !9
  %45 = load ptr, ptr %15, align 8, !tbaa !9
  %46 = load ptr, ptr %16, align 8, !tbaa !9
  %47 = call noundef i32 @_Z15find_path_densejPPdiPiS_S1_(i32 noundef %40, ptr noundef %41, i32 noundef %43, ptr noundef %44, ptr noundef %45, ptr noundef %46)
  store i32 %47, ptr %20, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %81, %39
  %49 = load i32, ptr %19, align 4, !tbaa !5
  %50 = load ptr, ptr %18, align 8, !tbaa !9
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp ne i32 %49, %51
  br i1 %52, label %53, label %82

53:                                               ; preds = %48
  %54 = load ptr, ptr %16, align 8, !tbaa !9
  %55 = load i32, ptr %20, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  store i32 %58, ptr %19, align 4, !tbaa !5
  %59 = load i32, ptr %19, align 4, !tbaa !5
  %60 = load ptr, ptr %14, align 8, !tbaa !9
  %61 = load i32, ptr %20, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i32, ptr %60, i64 %62
  store i32 %59, ptr %63, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  %64 = load i32, ptr %20, align 4, !tbaa !5
  store i32 %64, ptr %22, align 4, !tbaa !5
  %65 = load ptr, ptr %13, align 8, !tbaa !9
  %66 = load i32, ptr %19, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %65, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  store i32 %69, ptr %20, align 4, !tbaa !5
  %70 = load i32, ptr %22, align 4, !tbaa !5
  %71 = load ptr, ptr %13, align 8, !tbaa !9
  %72 = load i32, ptr %19, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i32, ptr %71, i64 %73
  store i32 %70, ptr %74, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #4
  %75 = load i32, ptr %21, align 4, !tbaa !5
  %76 = add i32 %75, 1
  store i32 %76, ptr %21, align 4, !tbaa !5
  %77 = load i32, ptr %21, align 4, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = icmp uge i32 %77, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %53
  br label %81

81:                                               ; preds = %80, %53
  br label %48, !llvm.loop !11

82:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  br label %83

83:                                               ; preds = %82
  %84 = load ptr, ptr %18, align 8, !tbaa !9
  %85 = getelementptr inbounds i32, ptr %84, i32 1
  store ptr %85, ptr %18, align 8, !tbaa !9
  br label %31, !llvm.loop !13

86:                                               ; preds = %38
  %87 = load ptr, ptr %16, align 8, !tbaa !9
  %88 = icmp ne ptr %87, null
  br i1 %88, label %89, label %91

89:                                               ; preds = %86
  %90 = load ptr, ptr %16, align 8, !tbaa !9
  call void @free(ptr noundef %90) #4
  store ptr null, ptr %16, align 8, !tbaa !9
  br label %91

91:                                               ; preds = %89, %86
  store i32 0, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %92

92:                                               ; preds = %91, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  %93 = load i32, ptr %8, align 4
  ret i32 %93
}

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 "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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z15find_path_densejPPdiPiS_S1_(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 -1, 1) i32 @_Z9_ca_densejPPdjPiS1_S1_S_(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef readonly %3, ptr nocapture noundef %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #2 {
  %8 = zext i32 %0 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #3
  %11 = icmp eq ptr %10, null
  br i1 %11, label %27, label %.preheader

.preheader:                                       ; preds = %7
  %12 = zext i32 %2 to i64
  %13 = getelementptr inbounds i32, ptr %3, i64 %12
  %.not40 = icmp eq i32 %2, 0
  br i1 %.not40, label %._crit_edge39, label %.lr.ph38

.lr.ph38:                                         ; preds = %.preheader, %._crit_edge
  %.03337 = phi ptr [ %25, %._crit_edge ], [ %3, %.preheader ]
  %14 = load i32, ptr %.03337, align 4, !tbaa !5
  %15 = tail call noundef i32 @_Z15find_path_densejPPdiPiS_S1_(i32 noundef %0, ptr noundef %1, i32 noundef %14, ptr noundef %5, ptr noundef %6, ptr noundef nonnull %10)
  %16 = load i32, ptr %.03337, align 4, !tbaa !5
  %.not35 = icmp eq i32 %16, -1
  br i1 %.not35, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph38, %.lr.ph
  %.03136 = phi i32 [ %23, %.lr.ph ], [ %15, %.lr.ph38 ]
  %17 = sext i32 %.03136 to i64
  %18 = getelementptr inbounds i32, ptr %10, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds i32, ptr %5, i64 %17
  store i32 %19, ptr %20, align 4, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds i32, ptr %4, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %.03136, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %.03337, align 4, !tbaa !5
  %.not = icmp eq i32 %19, %24
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph38
  %25 = getelementptr inbounds i8, ptr %.03337, i64 4
  %26 = icmp ult ptr %25, %13
  br i1 %26, label %.lr.ph38, label %._crit_edge39, !llvm.loop !11

._crit_edge39:                                    ; preds = %._crit_edge, %.preheader
  tail call void @free(ptr noundef %10) #4
  br label %27

27:                                               ; preds = %7, %._crit_edge39
  %.0 = phi i32 [ 0, %._crit_edge39 ], [ -1, %7 ]
  ret i32 %.0
}

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #2 = { 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 #3 = { nounwind allocsize(0) }
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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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