; LLVM IR from robotic-vision-lab/Cloud-Object-Recognition-Engine :: 3rdparty/libsvm/svm.ll (ZN5Cache8get_dataEiPPfi)

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

%class.Cache = type { i32, i64, ptr, %"struct.Cache::head_t" }
%"struct.Cache::head_t" = type { ptr, ptr, 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: nounwind
declare void @free(ptr 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: mustprogress nounwind uwtable
declare dso_local void @_ZN5Cache10lru_deleteEPNS_6head_tE(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Cache10lru_insertEPNS_6head_tE(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5Cache8get_dataEiPPfi(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #3 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %13 = getelementptr inbounds %class.Cache, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds %"struct.Cache::head_t", ptr %14, i64 %16
  store ptr %17, ptr %9, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.Cache::head_t", ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %4
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZN5Cache10lru_deleteEPNS_6head_tE(ptr noundef nonnull align 8 dereferenceable(56) %12, ptr noundef %23)
  br label %24

24:                                               ; preds = %22, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.Cache::head_t", ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 8, !tbaa !15
  %29 = sub nsw i32 %25, %28
  store i32 %29, ptr %10, align 4, !tbaa !9
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %32, label %75

32:                                               ; preds = %24
  br label %33

33:                                               ; preds = %39, %32
  %34 = getelementptr inbounds %class.Cache, ptr %12, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !16
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %35, %37
  br i1 %38, label %39, label %58

39:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %40 = getelementptr inbounds %class.Cache, ptr %12, i32 0, i32 3
  %41 = getelementptr inbounds %"struct.Cache::head_t", ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  store ptr %42, ptr %11, align 8, !tbaa !5
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  call void @_ZN5Cache10lru_deleteEPNS_6head_tE(ptr noundef nonnull align 8 dereferenceable(56) %12, ptr noundef %43)
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.Cache::head_t", ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  call void @free(ptr noundef %46) #6
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.Cache::head_t", ptr %47, i32 0, i32 3
  %49 = load i32, ptr %48, align 8, !tbaa !15
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %class.Cache, ptr %12, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !16
  %53 = add nsw i64 %52, %50
  store i64 %53, ptr %51, align 8, !tbaa !16
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.Cache::head_t", ptr %54, i32 0, i32 2
  store ptr null, ptr %55, align 8, !tbaa !18
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.Cache::head_t", ptr %56, i32 0, i32 3
  store i32 0, ptr %57, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %33, !llvm.loop !19

58:                                               ; preds = %33
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.Cache::head_t", ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !18
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = mul i64 4, %63
  %65 = call ptr @realloc(ptr noundef %61, i64 noundef %64) #7
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %"struct.Cache::head_t", ptr %66, i32 0, i32 2
  store ptr %65, ptr %67, align 8, !tbaa !18
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds %class.Cache, ptr %12, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !16
  %72 = sub nsw i64 %71, %69
  store i64 %72, ptr %70, align 8, !tbaa !16
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds %"struct.Cache::head_t", ptr %73, i32 0, i32 3
  call void @_ZL4swapIiEvRT_S1_(ptr noundef nonnull align 4 dereferenceable(4) %74, ptr noundef nonnull align 4 dereferenceable(4) %8)
  br label %75

75:                                               ; preds = %58, %24
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZN5Cache10lru_insertEPNS_6head_tE(ptr noundef nonnull align 8 dereferenceable(56) %12, ptr noundef %76)
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = getelementptr inbounds %"struct.Cache::head_t", ptr %77, i32 0, i32 2
  %79 = load ptr, ptr %78, align 8, !tbaa !18
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %79, ptr %80, align 8, !tbaa !5
  %81 = load i32, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  ret i32 %81
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL4swapIiEvRT_S1_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #5

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

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS5Cache", !10, i64 0, !13, i64 8, !6, i64 16, !14, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTSN5Cache6head_tE", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!15 = !{!14, !10, i64 24}
!16 = !{!12, !13, i64 8}
!17 = !{!12, !6, i64 32}
!18 = !{!14, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"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.Cache::head_t" = type { ptr, ptr, ptr, i32 }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Cache10lru_deleteEPNS_6head_tE(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Cache10lru_insertEPNS_6head_tE(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN5Cache8get_dataEiPPfi(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, ptr nocapture noundef writeonly %2, i32 noundef %3) local_unnamed_addr #1 align 2 {
  %5 = alloca i32, align 4
  store i32 %3, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = sext i32 %1 to i64
  %9 = getelementptr inbounds %"struct.Cache::head_t", ptr %7, i64 %8
  %10 = getelementptr inbounds i8, ptr %9, i64 24
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %13, label %12

12:                                               ; preds = %4
  tail call void @_ZN5Cache10lru_deleteEPNS_6head_tE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull %9)
  %.pre = load i32, ptr %10, align 8, !tbaa !14
  br label %13

13:                                               ; preds = %12, %4
  %14 = phi i32 [ %.pre, %12 ], [ 0, %4 ]
  %15 = sub nsw i32 %3, %14
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.preheader, label %39

.preheader:                                       ; preds = %13
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = zext nneg i32 %15 to i64
  %19 = load i64, ptr %17, align 8, !tbaa !15
  %20 = icmp slt i64 %19, %18
  br i1 %20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  br label %22

22:                                               ; preds = %.lr.ph, %22
  %23 = load ptr, ptr %21, align 8, !tbaa !16
  tail call void @_ZN5Cache10lru_deleteEPNS_6head_tE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %23)
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  tail call void @free(ptr noundef %25) #4
  %26 = getelementptr inbounds i8, ptr %23, i64 24
  %27 = load i32, ptr %26, align 8, !tbaa !14
  %28 = sext i32 %27 to i64
  %29 = load i64, ptr %17, align 8, !tbaa !15
  %30 = add nsw i64 %29, %28
  store i64 %30, ptr %17, align 8, !tbaa !15
  store ptr null, ptr %24, align 8, !tbaa !17
  store i32 0, ptr %26, align 8, !tbaa !14
  %31 = icmp slt i64 %30, %18
  br i1 %31, label %22, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %22, %.preheader
  %32 = getelementptr inbounds i8, ptr %9, i64 16
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = sext i32 %3 to i64
  %35 = shl nsw i64 %34, 2
  %36 = tail call ptr @realloc(ptr noundef %33, i64 noundef %35) #5
  store ptr %36, ptr %32, align 8, !tbaa !17
  %37 = load i64, ptr %17, align 8, !tbaa !15
  %38 = sub nsw i64 %37, %18
  store i64 %38, ptr %17, align 8, !tbaa !15
  call void @_ZL4swapIiEvRT_S1_(ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %5)
  br label %39

39:                                               ; preds = %._crit_edge, %13
  call void @_ZN5Cache10lru_insertEPNS_6head_tE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull %9)
  %40 = getelementptr inbounds i8, ptr %9, i64 16
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  store ptr %41, ptr %2, align 8, !tbaa !20
  %42 = load i32, ptr %5, align 4, !tbaa !5
  ret i32 %42
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL4swapIiEvRT_S1_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 #3 = { inlinehint 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(1) }

!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, !12, i64 16}
!10 = !{!"_ZTS5Cache", !6, i64 0, !11, i64 8, !12, i64 16, !13, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"_ZTSN5Cache6head_tE", !12, i64 0, !12, i64 8, !12, i64 16, !6, i64 24}
!14 = !{!13, !6, i64 24}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !12, i64 32}
!17 = !{!13, !12, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !12, i64 0}


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