; 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._VlKDForestSearcher = type { ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64, i64 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare ptr @vl_calloc(i64 noundef, 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
define dso_local ptr @vl_kdforest_new_searcher(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, 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
  %5 = call ptr @vl_calloc(i64 noundef 80, i64 noundef 1)
  store ptr %5, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._VlKDForest, ptr %6, i32 0, i32 15
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %18

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._VlKDForest, ptr %12, i32 0, i32 16
  store ptr %11, ptr %13, align 8, !tbaa !13
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._VlKDForestSearcher, ptr %14, i32 0, i32 1
  store ptr null, ptr %15, align 8, !tbaa !14
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._VlKDForestSearcher, ptr %16, i32 0, i32 0
  store ptr null, ptr %17, align 8, !tbaa !16
  br label %43

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._VlKDForest, ptr %19, i32 0, i32 16
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  store ptr %21, ptr %4, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %41, %18
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._VlKDForestSearcher, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %32

28:                                               ; preds = %23
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._VlKDForestSearcher, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  store ptr %31, ptr %4, align 8, !tbaa !5
  br label %41

32:                                               ; preds = %23
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._VlKDForestSearcher, ptr %34, i32 0, i32 0
  store ptr %33, ptr %35, align 8, !tbaa !16
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._VlKDForestSearcher, ptr %37, i32 0, i32 1
  store ptr %36, ptr %38, align 8, !tbaa !14
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._VlKDForestSearcher, ptr %39, i32 0, i32 0
  store ptr null, ptr %40, align 8, !tbaa !16
  br label %42

41:                                               ; preds = %28
  br label %22

42:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %43

43:                                               ; preds = %42, %10
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._VlKDForest, ptr %44, i32 0, i32 15
  %46 = load i64, ptr %45, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %45, align 8, !tbaa !9
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._VlKDForestSearcher, ptr %49, i32 0, i32 4
  store ptr %48, ptr %50, align 8, !tbaa !17
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._VlKDForest, ptr %51, i32 0, i32 13
  %53 = load i64, ptr %52, align 8, !tbaa !18
  %54 = mul i64 24, %53
  %55 = call ptr @vl_malloc(i64 noundef %54)
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._VlKDForestSearcher, ptr %56, i32 0, i32 3
  store ptr %55, ptr %57, align 8, !tbaa !19
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._VlKDForest, ptr %58, i32 0, i32 4
  %60 = load i64, ptr %59, align 8, !tbaa !20
  %61 = call ptr @vl_calloc(i64 noundef 8, i64 noundef %60)
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._VlKDForestSearcher, ptr %62, i32 0, i32 2
  store ptr %61, ptr %63, align 8, !tbaa !21
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %64
}

declare ptr @vl_malloc(i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!10, !11, i64 232}
!10 = !{!"_VlKDForest", !11, i64 0, !6, i64 8, !12, i64 16, !6, i64 24, !11, i64 32, !12, i64 40, !6, i64 48, !6, i64 56, !11, i64 64, !12, i64 72, !7, i64 80, !11, i64 200, !11, i64 208, !11, i64 216, !11, i64 224, !11, i64 232, !6, i64 240}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 240}
!14 = !{!15, !6, i64 8}
!15 = !{!"_VlKDForestSearcher", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72}
!16 = !{!15, !6, i64 0}
!17 = !{!15, !6, i64 32}
!18 = !{!10, !11, i64 216}
!19 = !{!15, !6, i64 24}
!20 = !{!10, !11, i64 32}
!21 = !{!15, !6, i64 16}


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

declare ptr @vl_calloc(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @vl_kdforest_new_searcher(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call ptr @vl_calloc(i64 noundef 80, i64 noundef 1) #2
  %3 = getelementptr inbounds i8, ptr %0, i64 232
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i64 %4, 0
  %6 = getelementptr inbounds i8, ptr %0, i64 240
  br i1 %5, label %.loopexit, label %7

7:                                                ; preds = %1
  %8 = load ptr, ptr %6, align 8, !tbaa !12
  br label %9

9:                                                ; preds = %9, %7
  %.0 = phi ptr [ %8, %7 ], [ %10, %9 ]
  %10 = load ptr, ptr %.0, align 8, !tbaa !13
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %.loopexit, label %9

.loopexit:                                        ; preds = %9, %1
  %.0.lcssa.sink22 = phi ptr [ %6, %1 ], [ %.0, %9 ]
  %.0.lcssa.sink = phi ptr [ null, %1 ], [ %.0, %9 ]
  store ptr %2, ptr %.0.lcssa.sink22, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %.0.lcssa.sink, ptr %11, align 8, !tbaa !16
  store ptr null, ptr %2, align 8, !tbaa !13
  %12 = add i64 %4, 1
  store i64 %12, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr %0, ptr %13, align 8, !tbaa !17
  %14 = getelementptr inbounds i8, ptr %0, i64 216
  %15 = load i64, ptr %14, align 8, !tbaa !18
  %16 = mul i64 %15, 24
  %17 = tail call ptr @vl_malloc(i64 noundef %16) #2
  %18 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %17, ptr %18, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load i64, ptr %19, align 8, !tbaa !20
  %21 = tail call ptr @vl_calloc(i64 noundef 8, i64 noundef %20) #2
  %22 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %21, ptr %22, align 8, !tbaa !21
  ret ptr %2
}

declare ptr @vl_malloc(i64 noundef) local_unnamed_addr #0

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

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


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