; LLVM IR from QiaoLiuHit/LSOTB-TIR :: vlfeat-0.9.19/vl (kdtree)

; 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._VlKDForest = type { i64, ptr, i32, ptr, i64, i32, ptr, ptr, i64, i32, [5 x %struct._VlKDTreeSplitDimension], i64, i64, i64, i64, i64, ptr }
%struct._VlKDTreeSplitDimension = type { i32, double, double }
%struct._VlKDTree = type { ptr, i64, i64, ptr, i32 }

; 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 uwtable
declare dso_local void @vl_kdforestsearcher_delete(ptr noundef) #1

declare void @vl_free(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @vl_kdforest_get_searcher(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @vl_kdforest_delete(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  br label %5

5:                                                ; preds = %9, %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call ptr @vl_kdforest_get_searcher(ptr noundef %6, i64 noundef 0)
  store ptr %7, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %11

9:                                                ; preds = %5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  call void @vl_kdforestsearcher_delete(ptr noundef %10)
  br label %5, !llvm.loop !9

11:                                               ; preds = %5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._VlKDForest, ptr %12, i32 0, i32 7
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %84

16:                                               ; preds = %11
  store i64 0, ptr %3, align 8, !tbaa !15
  br label %17

17:                                               ; preds = %77, %16
  %18 = load i64, ptr %3, align 8, !tbaa !15
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._VlKDForest, ptr %19, i32 0, i32 8
  %21 = load i64, ptr %20, align 8, !tbaa !16
  %22 = icmp ult i64 %18, %21
  br i1 %22, label %23, label %80

23:                                               ; preds = %17
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._VlKDForest, ptr %24, i32 0, i32 7
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = load i64, ptr %3, align 8, !tbaa !15
  %28 = getelementptr inbounds ptr, ptr %26, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %76

31:                                               ; preds = %23
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._VlKDForest, ptr %32, i32 0, i32 7
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = load i64, ptr %3, align 8, !tbaa !15
  %36 = getelementptr inbounds ptr, ptr %34, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._VlKDTree, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %50

41:                                               ; preds = %31
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._VlKDForest, ptr %42, i32 0, i32 7
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = load i64, ptr %3, align 8, !tbaa !15
  %46 = getelementptr inbounds ptr, ptr %44, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._VlKDTree, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  call void @vl_free(ptr noundef %49)
  br label %50

50:                                               ; preds = %41, %31
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._VlKDForest, ptr %51, i32 0, i32 7
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = load i64, ptr %3, align 8, !tbaa !15
  %55 = getelementptr inbounds ptr, ptr %53, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._VlKDTree, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !19
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %69

60:                                               ; preds = %50
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._VlKDForest, ptr %61, i32 0, i32 7
  %63 = load ptr, ptr %62, align 8, !tbaa !11
  %64 = load i64, ptr %3, align 8, !tbaa !15
  %65 = getelementptr inbounds ptr, ptr %63, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._VlKDTree, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !19
  call void @vl_free(ptr noundef %68)
  br label %69

69:                                               ; preds = %60, %50
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._VlKDForest, ptr %70, i32 0, i32 7
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  %73 = load i64, ptr %3, align 8, !tbaa !15
  %74 = getelementptr inbounds ptr, ptr %72, i64 %73
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  call void @vl_free(ptr noundef %75)
  br label %76

76:                                               ; preds = %69, %23
  br label %77

77:                                               ; preds = %76
  %78 = load i64, ptr %3, align 8, !tbaa !15
  %79 = add i64 %78, 1
  store i64 %79, ptr %3, align 8, !tbaa !15
  br label %17, !llvm.loop !20

80:                                               ; preds = %17
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._VlKDForest, ptr %81, i32 0, i32 7
  %83 = load ptr, ptr %82, align 8, !tbaa !11
  call void @vl_free(ptr noundef %83)
  br label %84

84:                                               ; preds = %80, %11
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  call void @vl_free(ptr noundef %85)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 56}
!12 = !{!"_VlKDForest", !13, i64 0, !6, i64 8, !14, i64 16, !6, i64 24, !13, i64 32, !14, i64 40, !6, i64 48, !6, i64 56, !13, i64 64, !14, i64 72, !7, i64 80, !13, i64 200, !13, i64 208, !13, i64 216, !13, i64 224, !13, i64 232, !6, i64 240}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !13, i64 64}
!17 = !{!18, !6, i64 0}
!18 = !{!"_VlKDTree", !6, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !14, i64 32}
!19 = !{!18, !6, i64 24}
!20 = distinct !{!20, !10}


; 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: nounwind uwtable
declare dso_local void @vl_kdforestsearcher_delete(ptr noundef) local_unnamed_addr #0

declare void @vl_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @vl_kdforest_get_searcher(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @vl_kdforest_delete(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @vl_kdforest_get_searcher(ptr noundef %0, i64 noundef 0)
  %.not27 = icmp eq ptr %2, null
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %3 = phi ptr [ %4, %.lr.ph ], [ %2, %1 ]
  tail call void @vl_kdforestsearcher_delete(ptr noundef nonnull %3)
  %4 = tail call ptr @vl_kdforest_get_searcher(ptr noundef %0, i64 noundef 0)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %1
  %5 = getelementptr inbounds i8, ptr %0, i64 56
  %6 = load ptr, ptr %5, align 8, !tbaa !7
  %.not23 = icmp eq ptr %6, null
  br i1 %.not23, label %28, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  %8 = load i64, ptr %7, align 8, !tbaa !14
  %.not31 = icmp eq i64 %8, 0
  br i1 %.not31, label %._crit_edge30, label %.lr.ph29

.lr.ph29:                                         ; preds = %.preheader, %23
  %9 = phi i64 [ %24, %23 ], [ %8, %.preheader ]
  %.028 = phi i64 [ %25, %23 ], [ 0, %.preheader ]
  %10 = load ptr, ptr %5, align 8, !tbaa !7
  %11 = getelementptr inbounds ptr, ptr %10, i64 %.028
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %.not24 = icmp eq ptr %12, null
  br i1 %.not24, label %23, label %13

13:                                               ; preds = %.lr.ph29
  %14 = load ptr, ptr %12, align 8, !tbaa !16
  %.not25 = icmp eq ptr %14, null
  br i1 %.not25, label %16, label %15

15:                                               ; preds = %13
  tail call void @vl_free(ptr noundef nonnull %14) #2
  %.pre = load ptr, ptr %5, align 8, !tbaa !7
  %.phi.trans.insert = getelementptr inbounds ptr, ptr %.pre, i64 %.028
  %.pre32 = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !15
  br label %16

16:                                               ; preds = %15, %13
  %17 = phi ptr [ %.pre32, %15 ], [ %12, %13 ]
  %18 = getelementptr inbounds i8, ptr %17, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %.not26 = icmp eq ptr %19, null
  br i1 %.not26, label %21, label %20

20:                                               ; preds = %16
  tail call void @vl_free(ptr noundef nonnull %19) #2
  %.pre33 = load ptr, ptr %5, align 8, !tbaa !7
  %.phi.trans.insert34 = getelementptr inbounds ptr, ptr %.pre33, i64 %.028
  %.pre35 = load ptr, ptr %.phi.trans.insert34, align 8, !tbaa !15
  br label %21

21:                                               ; preds = %20, %16
  %22 = phi ptr [ %.pre35, %20 ], [ %17, %16 ]
  tail call void @vl_free(ptr noundef %22) #2
  %.pre36 = load i64, ptr %7, align 8, !tbaa !14
  br label %23

23:                                               ; preds = %.lr.ph29, %21
  %24 = phi i64 [ %9, %.lr.ph29 ], [ %.pre36, %21 ]
  %25 = add nuw i64 %.028, 1
  %26 = icmp ult i64 %25, %24
  br i1 %26, label %.lr.ph29, label %._crit_edge30.loopexit, !llvm.loop !19

._crit_edge30.loopexit:                           ; preds = %23
  %.pre37 = load ptr, ptr %5, align 8, !tbaa !7
  br label %._crit_edge30

._crit_edge30:                                    ; preds = %._crit_edge30.loopexit, %.preheader
  %27 = phi ptr [ %.pre37, %._crit_edge30.loopexit ], [ %6, %.preheader ]
  tail call void @vl_free(ptr noundef %27) #2
  br label %28

28:                                               ; preds = %._crit_edge30, %._crit_edge
  tail call void @vl_free(ptr noundef nonnull %0) #2
  ret void
}

attributes #0 = { 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 #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 }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !12, i64 56}
!8 = !{!"_VlKDForest", !9, i64 0, !12, i64 8, !13, i64 16, !12, i64 24, !9, i64 32, !13, i64 40, !12, i64 48, !12, i64 56, !9, i64 64, !13, i64 72, !10, i64 80, !9, i64 200, !9, i64 208, !9, i64 216, !9, i64 224, !9, i64 232, !12, i64 240}
!9 = !{!"long long", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"any pointer", !10, i64 0}
!13 = !{!"int", !10, i64 0}
!14 = !{!8, !9, i64 64}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !12, i64 0}
!17 = !{!"_VlKDTree", !12, i64 0, !9, i64 8, !9, i64 16, !12, i64 24, !13, i64 32}
!18 = !{!17, !12, i64 24}
!19 = distinct !{!19, !6}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass