; LLVM IR from mitdbg/deneva :: storage/index_hash.ll (ZN9IndexHash12index_deleteEv)

; 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.mem_alloc = type { i8 }
%class.IndexHash = type { %class.index_base, ptr, i64, i64 }
%class.index_base = type { ptr, ptr }
%class.BucketHeader = type { ptr, i64, i8 }

@mem_allocator = external global %class.mem_alloc, align 1

; 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: mustprogress uwtable
define dso_local void @_ZN9IndexHash12index_deleteEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %20, %1
  %6 = load i32, ptr %3, align 4, !tbaa !9
  %7 = zext i32 %6 to i64
  %8 = getelementptr inbounds %class.IndexHash, ptr %4, i32 0, i32 3
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = icmp ult i64 %7, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %23

12:                                               ; preds = %5
  %13 = getelementptr inbounds %class.IndexHash, ptr %4, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = getelementptr inbounds ptr, ptr %14, i64 0
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds %class.BucketHeader, ptr %16, i64 %18
  call void @_ZN12BucketHeader13delete_bucketEv(ptr noundef nonnull align 8 dereferenceable(24) %19)
  br label %20

20:                                               ; preds = %12
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = add i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !9
  br label %5, !llvm.loop !16

23:                                               ; preds = %11
  %24 = getelementptr inbounds %class.IndexHash, ptr %4, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = getelementptr inbounds ptr, ptr %25, i64 0
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.IndexHash, ptr %4, i32 0, i32 3
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = mul i64 24, %29
  call void @_ZN9mem_alloc4freeEPvm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, ptr noundef %27, i64 noundef %30)
  %31 = getelementptr inbounds %class.IndexHash, ptr %4, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = icmp eq ptr %32, null
  br i1 %33, label %35, label %34

34:                                               ; preds = %23
  call void @_ZdlPvm(ptr noundef %32, i64 noundef 8) #5
  br label %35

35:                                               ; preds = %34, %23
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12BucketHeader13delete_bucketEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

declare void @_ZN9mem_alloc4freeEPvm(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef, i64 noundef) #2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nobuiltin 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 #4 = { nounwind }
attributes #5 = { builtin 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !14, i64 32}
!12 = !{!"_ZTS9IndexHash", !13, i64 0, !6, i64 16, !14, i64 24, !14, i64 32}
!13 = !{!"_ZTS10index_base", !6, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%class.mem_alloc = type { i8 }
%class.BucketHeader = type { ptr, i64, i8 }

@mem_allocator = external global %class.mem_alloc, align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9IndexHash12index_deleteEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  br label %11

._crit_edge.loopexit:                             ; preds = %11
  %5 = mul nuw nsw i64 %18, 24
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.lcssa = phi i64 [ 0, %1 ], [ %5, %._crit_edge.loopexit ]
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  tail call void @_ZN9mem_alloc4freeEPvm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, ptr noundef %8, i64 noundef %.lcssa)
  %9 = load ptr, ptr %6, align 8, !tbaa !12
  %10 = icmp eq ptr %9, null
  br i1 %10, label %21, label %20

11:                                               ; preds = %.lr.ph, %11
  %12 = phi i64 [ 0, %.lr.ph ], [ %17, %11 ]
  %.06 = phi i32 [ 0, %.lr.ph ], [ %16, %11 ]
  %13 = load ptr, ptr %4, align 8, !tbaa !12
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds %class.BucketHeader, ptr %14, i64 %12
  tail call void @_ZN12BucketHeader13delete_bucketEv(ptr noundef nonnull align 8 dereferenceable(24) %15)
  %16 = add i32 %.06, 1
  %17 = zext i32 %16 to i64
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = icmp ugt i64 %18, %17
  br i1 %19, label %11, label %._crit_edge.loopexit, !llvm.loop !14

20:                                               ; preds = %._crit_edge
  tail call void @_ZdlPvm(ptr noundef nonnull %9, i64 noundef 8) #3
  br label %21

21:                                               ; preds = %20, %._crit_edge
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12BucketHeader13delete_bucketEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

declare void @_ZN9mem_alloc4freeEPvm(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 #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 = { nobuiltin 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 = { builtin 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, !11, i64 32}
!6 = !{!"_ZTS9IndexHash", !7, i64 0, !8, i64 16, !11, i64 24, !11, i64 32}
!7 = !{!"_ZTS10index_base", !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!6, !8, i64 16}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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