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

; 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
@.str = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9IndexHash4initEm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = load i64, ptr %4, align 8, !tbaa !9
  %9 = getelementptr inbounds %class.IndexHash, ptr %7, i32 0, i32 2
  store i64 %8, ptr %9, align 8, !tbaa !11
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = getelementptr inbounds %class.IndexHash, ptr %7, i32 0, i32 3
  store i64 %10, ptr %11, align 8, !tbaa !14
  %12 = call noalias noundef nonnull ptr @_Znam(i64 noundef 8) #5
  %13 = getelementptr inbounds %class.IndexHash, ptr %7, i32 0, i32 1
  store ptr %12, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds %class.IndexHash, ptr %7, i32 0, i32 3
  %15 = load i64, ptr %14, align 8, !tbaa !14
  %16 = mul i64 24, %15
  %17 = call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef %16)
  %18 = getelementptr inbounds %class.IndexHash, ptr %7, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = getelementptr inbounds ptr, ptr %19, i64 0
  store ptr %17, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  store i64 0, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !16
  br label %21

21:                                               ; preds = %38, %2
  %22 = load i32, ptr %6, align 4, !tbaa !16
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds %class.IndexHash, ptr %7, i32 0, i32 3
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %26 = icmp ult i64 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %41

28:                                               ; preds = %21
  %29 = getelementptr inbounds %class.IndexHash, ptr %7, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = getelementptr inbounds ptr, ptr %30, i64 0
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !16
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds %class.BucketHeader, ptr %32, i64 %34
  call void @_ZN12BucketHeader4initEv(ptr noundef nonnull align 8 dereferenceable(24) %35)
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr %5, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %28
  %39 = load i32, ptr %6, align 4, !tbaa !16
  %40 = add i32 %39, 1
  store i32 %40, ptr %6, align 4, !tbaa !16
  br label %21, !llvm.loop !18

41:                                               ; preds = %27
  %42 = load i64, ptr %5, align 8, !tbaa !9
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %42)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  ret i32 0
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

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

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

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

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

declare i32 @printf(ptr noundef, ...) #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 = { nobuiltin 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { builtin allocsize(0) }
attributes #6 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTS9IndexHash", !13, i64 0, !6, i64 16, !10, i64 24, !10, i64 32}
!13 = !{!"_ZTS10index_base", !6, i64 8}
!14 = !{!12, !10, i64 32}
!15 = !{!12, !6, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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
@.str = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9IndexHash4initEm(ptr nocapture noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %1, ptr %4, align 8, !tbaa !12
  %5 = tail call noalias noundef nonnull dereferenceable(8) ptr @_Znam(i64 noundef 8) #5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %5, ptr %6, align 8, !tbaa !13
  %7 = mul i64 %1, 24
  %8 = tail call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef %7)
  %9 = load ptr, ptr %6, align 8, !tbaa !13
  store ptr %8, ptr %9, align 8, !tbaa !14
  %10 = load i64, ptr %4, align 8, !tbaa !12
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.07.lcssa = phi i64 [ 0, %2 ], [ %16, %.lr.ph ]
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.07.lcssa)
  ret i32 0

.lr.ph:                                           ; preds = %2, %.lr.ph
  %12 = phi i64 [ %17, %.lr.ph ], [ 0, %2 ]
  %.079 = phi i64 [ %16, %.lr.ph ], [ 0, %2 ]
  %13 = load ptr, ptr %6, align 8, !tbaa !13
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = getelementptr inbounds %class.BucketHeader, ptr %14, i64 %12
  tail call void @_ZN12BucketHeader4initEv(ptr noundef nonnull align 8 dereferenceable(24) %15)
  %16 = add i64 %.079, 1
  %17 = and i64 %16, 4294967295
  %18 = load i64, ptr %4, align 8, !tbaa !12
  %19 = icmp ugt i64 %18, %17
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !15
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

declare noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1), i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

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 = { nobuiltin 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 = { "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 = { nofree 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 #5 = { builtin 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, !11, i64 24}
!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, !11, i64 32}
!13 = !{!6, !8, i64 16}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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